1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416
|
<?xml version='1.0' ?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
<!ENTITY % myents SYSTEM "entities.inc">
%myents;
]>
<reference id="clsql">
<title><symbol>CLSQL</symbol></title>
<partintro>
<para>This part gives a reference to the symbols exported from the
<symbol>CLSQL</symbol> package. These symbols constitute
the normal user-interface of &clsql;. Currently, the symbols of
the &commonsql;-API are not documented here.</para>
</partintro>
<!-- Conditions -->
<refentry id="sql-condition">
<refnamediv>
<refname>SQL-CONDITION</refname>
<refpurpose>the super-type of all
&clsql;-specific
conditions</refpurpose>
<refclass>Condition Type</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><errortype>sql-condition</errortype></member>
<member><errortype>condition</errortype></member>
<member><errortype>t</errortype></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This is the super-type of all
&clsql;-specific conditions
defined by &clsql;, or any of it's
database-specific interfaces. There are no defined
initialization arguments nor any accessors.</para>
</refsect1>
</refentry>
<refentry id="sql-error">
<refnamediv>
<refname>SQL-ERROR</refname>
<refpurpose>the super-type of all
&clsql;-specific
errors</refpurpose>
<refclass>Condition Type</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><errortype>sql-error</errortype></member>
<member><errortype>error</errortype></member>
<member><errortype>serious-condition</errortype></member>
<member><errortype>sql-condition</errortype></member>
<member><errortype>condition</errortype></member>
<member><errortype>t</errortype></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This is the super-type of all
&clsql;-specific conditions that
represent errors, as defined by
&clsql;, or any of it's
database-specific interfaces. There are no defined
initialization arguments nor any accessors.</para>
</refsect1>
</refentry>
<refentry id="sql-warning">
<refnamediv>
<refname>SQL-WARNING</refname>
<refpurpose>the super-type of all
&clsql;-specific
warnings</refpurpose>
<refclass>Condition Type</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><errortype>sql-warning</errortype></member>
<member><errortype>warning</errortype></member>
<member><errortype>sql-condition</errortype></member>
<member><errortype>condition</errortype></member>
<member><errortype>t</errortype></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This is the super-type of all
&clsql;-specific conditions that
represent warnings, as defined by
&clsql;, or any of it's
database-specific interfaces. There are no defined
initialization arguments nor any accessors.</para>
</refsect1>
</refentry>
<!-- Specifc Conditions -->
<refentry id="sql-user-error">
<refnamediv>
<refname>CLSQL-USER-ERROR</refname>
<refpurpose>condition representing errors because of invalid
parameters from the library user.</refpurpose>
<refclass>Condition Type</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><errortype>sql-error</errortype></member>
<member><errortype>sql-condition</errortype></member>
<member><errortype>condition</errortype></member>
<member><errortype>t</errortype></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This condition represents errors that occur because the
user supplies invalid data to &clsql;. This includes errors such as
an invalid format connection specification or an error in the syntax
for the <function>LOOP</function> macro extensions.</para>
</refsect1>
</refentry>
<refentry id="sql-connection-error">
<refnamediv>
<refname>SQL-CONNECTION-ERROR</refname>
<refpurpose>condition representing errors during
connection</refpurpose>
<refclass>Condition Type</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><errortype>sql-connection-error</errortype></member>
<member><errortype>sql-database-error</errortype></member>
<member><errortype>sql-error</errortype></member>
<member><errortype>sql-condition</errortype></member>
<member><errortype>condition</errortype></member>
<member><errortype>t</errortype></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This condition represents errors that occur while trying
to connect to a database. The following initialization
arguments and accessors exist:</para>
<segmentedlist>
<segtitle>Initarg</segtitle>
<segtitle>Accessor</segtitle>
<segtitle>Description</segtitle>
<seglistitem>
<seg><symbol>:database-type</symbol></seg>
<seg><function>sql-connection-error-database-type</function></seg>
<seg>Database type for the connection attempt</seg>
</seglistitem>
<seglistitem>
<seg><symbol>:connection-spec</symbol></seg>
<seg><function>sql-connection-error-connection-spec</function></seg>
<seg>The connection specification used in the
connection attempt.</seg>
</seglistitem>
<seglistitem>
<seg><symbol>:errno</symbol></seg>
<seg><function>sql-connection-error-errno</function></seg>
<seg>The numeric or symbolic error specification
returned by the database back-end. The values and
semantics of this are interface specific.</seg>
</seglistitem>
<seglistitem>
<seg><symbol>:error</symbol></seg>
<seg><function>sql-connection-error-error</function></seg>
<seg>A string describing the problem that occurred,
possibly one returned by the database back-end.</seg>
</seglistitem>
</segmentedlist>
</refsect1>
</refentry>
<refentry id="sql-database-error">
<refnamediv>
<refname>SQL-DATABASE-ERROR</refname>
<refpurpose>condition representing errors during query or
command execution</refpurpose>
<refclass>Condition Type</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><errortype>sql-database-error</errortype></member>
<member><errortype>sql-error</errortype></member>
<member><errortype>error</errortype></member>
<member><errortype>serious-condition</errortype></member>
<member><errortype>sql-condition</errortype></member>
<member><errortype>condition</errortype></member>
<member><errortype>t</errortype></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This condition represents errors that occur while
executing SQL statements, either as part of query operations
or command execution, either explicitly or implicitly, as
caused e.g. by <function>with-transaction</function>.
The following initialization arguments and accessors exist:</para>
<segmentedlist>
<segtitle>Initarg</segtitle>
<segtitle>Accessor</segtitle>
<segtitle>Description</segtitle>
<seglistitem>
<seg><symbol>:database</symbol></seg>
<seg><function>sql-database-error-database</function></seg>
<seg>The database object that was involved in the
incident.</seg>
</seglistitem>
<seglistitem>
<seg><symbol>:expression</symbol></seg>
<seg><function>sql-database-error-expression</function></seg>
<seg>The SQL expression whose execution caused the error.</seg>
</seglistitem>
<seglistitem>
<seg><symbol>:errno</symbol></seg>
<seg><function>sql-database-error-errno</function></seg>
<seg>The numeric or symbolic error specification
returned by the database back-end. The values and
semantics of this are interface specific.</seg>
</seglistitem>
<seglistitem>
<seg><symbol>:error</symbol></seg>
<seg><function>sql-database-error-error</function></seg>
<seg>A string describing the problem that occurred,
possibly one returned by the database back-end.</seg>
</seglistitem>
</segmentedlist>
</refsect1>
</refentry>
<!-- Database Types -->
<refentry id="default-database-type">
<refnamediv>
<refname>*DEFAULT-DATABASE-TYPE*</refname>
<refpurpose>The default database type to use</refpurpose>
<refclass>Variable</refclass>
</refnamediv>
<refsect1>
<title>Value Type</title>
<para>Any keyword representing a valid database back-end of
&clsql;, or
<symbol>nil</symbol>.</para>
</refsect1>
<refsect1>
<title>Initial Value</title>
<para><symbol>nil</symbol></para>
</refsect1>
<refsect1>
<title>Description</title>
<para>The value of this variable is used in calls to
<function>initialize-database-type</function> and
<function>connect</function> as the default
value of the <parameter>database-type</parameter>
parameter.</para>
<caution>
<para>If the value of this variable is <symbol>nil</symbol>,
then all calls to
<function>initialize-database-type</function> or
<function>connect</function> will have to specify the
<parameter>database-type</parameter> to use, or a
general-purpose error will be signalled.</para>
</caution>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(setf *default-database-type* :mysql)
=> :mysql
(initialize-database-type)
=> t
</screen>
</refsect1>
<refsect1>
<title>Affected By</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="initialized-database-types">
<refnamediv>
<refname>*INITIALIZED-DATABASE-TYPES*</refname>
<refpurpose>List of all initialized database types</refpurpose>
<refclass>Variable</refclass>
</refnamediv>
<refsect1>
<title>Value Type</title>
<para>A list of all initialized database types, each of which
represented by it's corresponding keyword.</para>
</refsect1>
<refsect1>
<title>Initial Value</title>
<para><symbol>nil</symbol></para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This variable is updated whenever
<function>initialize-database-type</function> is called for a
database type which hasn't already been initialized before,
as determined by this variable. In that case the keyword
representing the database type is pushed onto the list
stored in
<symbol>*INITIALIZED-DATABASE-TYPES*</symbol>.</para>
<caution>
<para>Attempts to modify the value of this variable will
result in undefined behaviour.</para>
</caution>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(setf *default-database-type* :mysql)
=> :mysql
(initialize-database-type)
=> t
*initialized-database-types*
=> (:MYSQL)
</screen>
</refsect1>
<refsect1>
<title>Affected By</title>
<para>
<simplelist>
<member><function>initialize-database-type</function></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>Direct access to this variable is primarily provided
because of compatibility with Harlequin's <application>Common
SQL</application>.</para>
</refsect1>
</refentry>
<refentry id="initialize-database-type">
<refnamediv>
<refname>INITIALIZE-DATABASE-TYPE</refname>
<refpurpose>Initializes a database type</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>initialize-database-type</function> &key <replaceable>database-type</replaceable> => <returnvalue>result</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>database-type</parameter></term>
<listitem>
<para>The database type to initialize, i.e. a keyword
symbol denoting a known database back-end. Defaults to
the value of
<symbol>*default-database-type*</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><returnvalue>result</returnvalue></term>
<listitem>
<para>Either <symbol>nil</symbol> if the initialization
attempt fails, or <symbol>t</symbol> otherwise.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>If the back-end specified by
<parameter>database-type</parameter> has not already been
initialized, as seen from
<symbol>*initialized-database-types*</symbol>, an attempt is
made to initialize the database. If this attempt succeeds,
or the back-end has already been initialized, the function
returns t, and places the keyword denoting the database type
onto the list stored in
<symbol>*initialized-database-types*</symbol>, if not
already present.</para>
<para>If initialization fails, the function returns
<symbol>nil</symbol>, and/or signals an error of type
<errortype>clsql-error</errortype>. The kind of action
taken depends on the back-end and the cause of the
problem.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
*initialized-database-types*
=> NIL
(setf *default-database-type* :mysql)
=> :MYSQL
(initialize-database-type)
>> Compiling LAMBDA (#:G897 #:G898 #:G901 #:G902):
>> Compiling Top-Level Form:
>>
=> T
*initialized-database-types*
=> (:MYSQL)
(initialize-database-type)
=> T
*initialized-database-types*
=> (:MYSQL)
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>The database back-end corresponding to the database type
specified is initialized, unless it has already been
initialized. This can involve any number of other side
effects, as determined by the back-end implementation (like
e.g. loading of foreign code, calling of foreign code,
networking operations, etc.). If initialization is
attempted and succeeds, the
<parameter>database-type</parameter> is pushed onto the list
stored in
<symbol>*initialized-database-types*</symbol>.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>
<simplelist>
<member><symbol>*default-database-type*</symbol></member>
<member><symbol>*initialized-database-types*</symbol></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If an error is encountered during the initialization
attempt, the back-end may signal errors of kind
<errortype>clsql-error</errortype>.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<!-- Databases Connection and Disconnection -->
<refentry id="connect-if-exists">
<refnamediv>
<refname>*CONNECT-IF-EXISTS*</refname>
<refpurpose>Default value for the
<parameter>if-exists</parameter> parameter of
<function>connect</function>.</refpurpose>
<refclass>Variable</refclass>
</refnamediv>
<refsect1>
<title>Value Type</title>
<para>A valid argument to the <parameter>if-exists</parameter>
parameter of <function>connect</function>, i.e. one of
<simplelist type="inline">
<member><symbol>:new</symbol></member>
<member><symbol>:warn-new</symbol></member>
<member><symbol>:error</symbol></member>
<member><symbol>:warn-old</symbol></member>
<member><symbol>:old</symbol></member>
</simplelist>.
</para>
</refsect1>
<refsect1>
<title>Initial Value</title>
<para><symbol>:error</symbol></para>
</refsect1>
<refsect1>
<title>Description</title>
<para>The value of this variable is used in calls to
<function>connect</function> as the default
value of the <parameter>if-exists</parameter>
parameter. See <link
linkend="connect"><function>connect</function></link> for
the semantics of the valid values for this variable.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Affected By</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link
linkend="connect"><function>connect</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="connected-databases">
<refnamediv>
<refname>CONNECTED-DATABASES</refname>
<refpurpose>Return the list of active database
objects.</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>connected-databases</function> => <returnvalue>databases</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><returnvalue>databases</returnvalue></term>
<listitem>
<para>The list of active database objects.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function returns the list of active database
objects, i.e. all those database objects created by calls to
<function>connect</function>, which have not been closed by
calling <function>disconnect</function> on them.</para>
<caution>
<para>The consequences of modifying the list returned by
<function>connected-databases</function> are
undefined.</para>
</caution>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(connected-databases)
=> NIL
(connect '(nil "template1" "dent" nil) :database-type :postgresql)
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {4830BC65}>
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql)
=> #<CLSQL-MYSQL:MYSQL-DATABASE {4830C5AD}>
(connected-databases)
=> (#<CLSQL-MYSQL:MYSQL-DATABASE {4830C5AD}>
#<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {4830BC65}>)
(disconnect)
=> T
(connected-databases)
=> (#<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {4830BC65}>)
(disconnect)
=> T
(connected-databases)
=> NIL
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Affected By</title>
<para>
<simplelist>
<member><function>connect</function></member>
<member><function>disconnect</function></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="default-database">
<refnamediv>
<refname>*DEFAULT-DATABASE*</refname>
<refpurpose>The default database object to use</refpurpose>
<refclass>Variable</refclass>
</refnamediv>
<refsect1>
<title>Value Type</title>
<para>Any object of type <type>database</type>, or nil to
indicate no default database.</para>
</refsect1>
<refsect1>
<title>Initial Value</title>
<para><symbol>nil</symbol></para>
</refsect1>
<refsect1>
<title>Description</title>
<para>Any function or macro in
&clsql; that operates on a
database uses the value of this variable as the default
value for it's <parameter>database</parameter>
parameter.</para>
<para>The value of this parameter is changed by calls to
<function>connect</function>, which sets
<symbol>*default-database*</symbol> to the database object
it returns. It is also changed by calls to
<function>disconnect</function>, when the database object
being disconnected is the same as the value of
<symbol>*default-database*</symbol>. In this case
<function>disconnect</function> sets
<symbol>*default-database*</symbol> to the first database
that remains in the list of active databases as returned by
<function>connected-databases</function>, or
<symbol>nil</symbol> if no further active databases
exist.</para>
<para>The user may change <symbol>*default-database*</symbol>
at any time to a valid value of his choice.</para>
<caution>
<para>If the value of <symbol>*default-database*</symbol> is
<symbol>nil</symbol>, then all calls to
&clsql; functions on databases
must provide a suitable <parameter>database</parameter>
parameter, or an error will be signalled.</para>
</caution>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(connected-databases)
=> NIL
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql)
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48385F55}>
(connect '(nil "template1" "dent" nil) :database-type :postgresql)
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {483868FD}>
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql :if-exists :new)
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48387265}>
*default-database*
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48387265}>
(disconnect)
=> T
*default-database*
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {483868FD}>
(disconnect)
=> T
*default-database*
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48385F55}>
(disconnect)
=> T
*default-database*
=> NIL
(connected-databases)
=> NIL
</screen>
</refsect1>
<refsect1>
<title>Affected By</title>
<para>
<simplelist>
<member><link linkend="connect"><function>connect</function></link></member>
<member><link linkend="disconnect"><function>disconnect</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="connected-databases"><function>connected-databases</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<note>
<para>This variable is intended to facilitate working with
&clsql; in an interactive
fashion at the top-level loop, and because of this,
<function>connect</function> and
<function>disconnect</function> provide some fairly
complex behaviour to keep
<symbol>*default-database*</symbol> set to useful values.
Programmatic use of &clsql;
should never depend on the value of
<symbol>*default-database*</symbol> and should provide
correct database objects via the
<parameter>database</parameter> parameter to functions
called.</para>
</note>
</refsect1>
</refentry>
<!-- Classes -->
<refentry id="database">
<refnamediv>
<refname>DATABASE</refname>
<refpurpose>The super-type of all
&clsql; databases</refpurpose>
<refclass>Class</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><type>database</type></member>
<member><type>standard-object</type></member>
<member><type>t</type></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>This class is the superclass of all
&clsql; databases. The different
database back-ends derive subclasses of this class to
implement their databases. No instances of this class are
ever created by &clsql;.</para>
</refsect1>
</refentry>
<refentry id="closed-database">
<refnamediv>
<refname>CLOSED-DATABASE</refname>
<refpurpose>The class representing all closed
&clsql; databases</refpurpose>
<refclass>Class</refclass>
</refnamediv>
<refsect1>
<title>Class Precedence List</title>
<para>
<simplelist type="inline">
<member><type>closed-database</type></member>
<member><type>standard-object</type></member>
<member><type>t</type></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Description</title>
<para>&clsql; <type>database</type>
instances are changed to this class via
<function>change-class</function> after they are closed via
<function>disconnect</function>. All functions and generic
functions that take database objects as arguments will
signal errors of type
<errortype>clsql-closed-error</errortype> when they are
called on instances of <type>closed-database</type>, with
the exception of <function>database-name</function>, which
will continue to work as for instances of
<type>database</type>.</para>
</refsect1>
</refentry>
<!-- Functions -->
<refentry id="database-name">
<refnamediv>
<refname>DATABASE-NAME</refname>
<refpurpose>Get the name of a database object</refpurpose>
<refclass>Generic Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>database-name</function> <replaceable>database</replaceable> => <returnvalue>name</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>A database object, either of type
<type>database</type> or of type
<type>closed-database</type>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><returnvalue>name</returnvalue></term>
<listitem>
<para>A string describing the identity of the database
to which this database object is connected to.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function returns the database name of the given
database. The database name is a string which somehow
describes the identity of the database to which this
database object is or has been connected. The database name
of a database object is determined at
<function>connect</function> time, when a call to
<function>database-name-from-spec</function> derives the
database name from the connection specification passed to
<function>connect</function> in the
<parameter>connection-spec</parameter> parameter.</para>
<para>The database name is used via
<function>find-database</function> in
<function>connect</function> to determine whether database
connections to the specified database exist already.</para>
<para>Usually the database name string will include
indications of the host, database name, user, or port that
where used during the connection attempt. The only
important thing is that this string shall try to identify
the database at the other end of the connection. Connection
specifications parts like passwords and credentials shall
not be used as part of the database name.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(database-name-from-spec '("dent" "newesim" "dent" "dent") :mysql)
=> "dent/newesim/dent"
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql)
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48391DCD}>
(database-name *default-database*)
=> "dent/newesim/dent"
(database-name-from-spec '(nil "template1" "dent" nil) :postgresql)
=> "/template1/dent"
(connect '(nil "template1" "dent" nil) :database-type :postgresql)
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {48392D2D}>
(database-name *default-database*)
=> "/template1/dent"
(database-name-from-spec '("www.pmsf.de" "template1" "dent" nil) :postgresql)
=> "www.pmsf.de/template1/dent"
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Affected By</title>
<para>
<simplelist>
<member><link linkend="database-name-from-spec"><function>database-name-from-spec</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>Will signal an error if the object passed as the
<parameter>database</parameter> parameter is neither of type
<type>database</type> nor of type
<type>closed-database</type>.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link
linkend="connect"><function>connect</function></link></member>
<member><link
linkend="find-database"><function>find-database</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="find-database">
<refnamediv>
<refname>FIND-DATABASE</refname>
<refpurpose>Locate a database object through it's
name.</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>find-database</function> <replaceable>database</replaceable> &optional <replaceable>errorp</replaceable> => <returnvalue>result</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>A database object or a string, denoting a database
name.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>errorp</parameter></term>
<listitem>
<para>A generalized boolean. Defaults to
<symbol>t</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><returnvalue>result</returnvalue></term>
<listitem>
<para>Either a database object, or, if
<parameter>errorp</parameter> is <symbol>nil</symbol>,
possibly <symbol>nil</symbol>.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para><function>find-database</function> locates an active
database object given the specification in
<parameter>database</parameter>. If
<parameter>database</parameter> is an object of type
<type>database</type>, <function>find-database</function>
returns this. Otherwise it will search the active databases
as indicated by the list returned by
<function>connected-databases</function> for a database
whose name (as returned by
<function>database-name</function> is equal as per
<function>string=</function> to the string passed as
<parameter>database</parameter>. If it succeeds, it returns
the first database found.</para>
<para>If it fails to find a matching database, it will signal
an error of type <errortype>clsql-error</errortype> if
<parameter>errorp</parameter> is true. If
<parameter>errorp</parameter> is <symbol>nil</symbol>, it
will return <symbol>nil</symbol> instead.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(database-name-from-spec '("dent" "newesim" "dent" "dent") :mysql)
=> "dent/newesim/dent"
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql)
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48391DCD}>
(database-name *default-database*)
=> "dent/newesim/dent"
(database-name-from-spec '(nil "template1" "dent" nil) :postgresql)
=> "/template1/dent"
(connect '(nil "template1" "dent" nil) :database-type :postgresql)
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {48392D2D}>
(database-name *default-database*)
=> "/template1/dent"
(database-name-from-spec '("www.pmsf.de" "template1" "dent" nil) :postgresql)
=> "www.pmsf.de/template1/dent"
(find-database "dent/newesim/dent")
=> #<CLSQL-MYSQL:MYSQL-DATABASE {484E91C5}>
(find-database "/template1/dent")
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {48392D2D}>
(find-database "www.pmsf.de/template1/dent" nil)
=> NIL
(find-database **)
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {48392D2D}>
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Affected By</title>
<para>
<simplelist>
<member><link linkend="connected-databases"><function>connected-databases</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>Will signal an error of type
<errortype>clsql-error</errortype> if no matching database
can be found, and <parameter>errorp</parameter> is true.
Will signal an error if the value of
<parameter>database</parameter> is neither an object of type
<type>database</type> nor a string.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link
linkend="database-name"><function>database-name</function></link></member>
<member><link
linkend="database-name-from-spec"><function>database-name-from-spec</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="connect">
<refnamediv>
<refname>CONNECT</refname>
<refpurpose>create a connection to a database</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>connect</function> <replaceable>connection-spec</replaceable> &key <replaceable>if-exists</replaceable> <replaceable>database-type</replaceable> <replaceable>pool</replaceable> => <returnvalue>database</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>connection-spec</parameter></term>
<listitem>
<para>A connection specification</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>if-exists</parameter></term>
<listitem>
<para>This indicates the action to take if a connection
to the same database exists already. See below for the
legal values and actions. It defaults to the value of
<symbol>*connect-if-exists*</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database-type</parameter></term>
<listitem>
<para>A database type specifier, i.e. a keyword.
This defaults to the value of
<symbol>*default-database-type*</symbol></para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>pool</parameter></term>
<listitem>
<para>A boolean flag. If &t;, acquire connection from a
pool of open connections. If the pool is empty, a new
connection is created. The default is &nil;.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><returnvalue>database</returnvalue></term>
<listitem>
<para>The database object representing the connection.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function takes a connection specification and
a database type and creates a connection to the database
specified by those. The type and structure of the
connection specification depend on the database type.</para>
<para>The parameter <parameter>if-exists</parameter> specifies
what to do if a connection to the database specified exists
already, which is checked by calling
<function>find-database</function> on the database name
returned by <function>database-name-from-spec</function>
when called with the <parameter>connection-spec</parameter>
and <parameter>database-type</parameter> parameters. The
possible values of <parameter>if-exists</parameter> are:
<variablelist>
<varlistentry>
<term><symbol>:new</symbol></term>
<listitem>
<para>Go ahead and create a new connection.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><symbol>:warn-new</symbol></term>
<listitem>
<para>This is just like <symbol>:new</symbol>, but
also signals a warning of type
<errortype>clsql-exists-warning</errortype>,
indicating the old and newly created
databases.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><symbol>:error</symbol></term>
<listitem>
<para>This will cause <function>connect</function> to
signal a correctable error of type
<errortype>clsql-exists-error</errortype>. The
user may choose to proceed, either by indicating
that a new connection shall be created, via the
restart <symbol>create-new</symbol>, or by
indicating that the existing connection shall be
used, via the restart
<symbol>use-old</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><symbol>:old</symbol></term>
<listitem>
<para>This will cause <function>connect</function> to
use an old connection if one exists.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><symbol>:warn-old</symbol></term>
<listitem>
<para>This is just like <symbol>:old</symbol>, but
also signals a warning of type
<errortype>clsql-exists-warning</errortype>,
indicating the old database used, via the slots
<symbol>old-db</symbol> and
<symbol>new-db</symbol></para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>The database name of the returned database object will
be the same under <function>string=</function> as that which
would be returned by a call to
<function>database-name-from-spec</function> with the given
<parameter>connection-spec</parameter> and
<parameter>database-type</parameter> parameters.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(database-name-from-spec '("dent" "newesim" "dent" "dent") :mysql)
=> "dent/newesim/dent"
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql)
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48036F6D}>
(database-name *)
=> "dent/newesim/dent"
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql)
>> In call to CONNECT:
>> There is an existing connection #<CLSQL-MYSQL:MYSQL-DATABASE {48036F6D}> to database dent/newesim/dent.
>>
>> Restarts:
>> 0: [CREATE-NEW] Create a new connection.
>> 1: [USE-OLD ] Use the existing connection.
>> 2: [ABORT ] Return to Top-Level.
>>
>> Debug (type H for help)
>>
>> (CONNECT ("dent" "newesim" "dent" "dent") :IF-EXISTS NIL :DATABASE-TYPE ...)
>> Source:
>> ; File: /prj/CLSQL/sql/sql.cl
>> (RESTART-CASE (ERROR 'CLSQL-EXISTS-ERROR :OLD-DB OLD-DB)
>> (CREATE-NEW NIL :REPORT "Create a new connection."
>> (SETQ RESULT #))
>> (USE-OLD NIL :REPORT "Use the existing connection."
>> (SETQ RESULT OLD-DB)))
>> 0] 0
=> #<CLSQL-MYSQL:MYSQL-DATABASE {480451F5}>
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>A database connection is established, and the resultant
database object is registered, so as to appear in the list
returned by <function>connected-databases</function>.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>
<simplelist>
<member><symbol>*default-database-type*</symbol></member>
<member><symbol>*connect-if-exists*</symbol></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If the connection specification is not syntactically or
semantically correct for the given database type, an error
of type <errortype>clsql-invalid-spec-error</errortype> is
signalled. If during the connection attempt an error is
detected (e.g. because of permission problems, network
trouble or any other cause), an error of type
<errortype>sql-connection-error</errortype> is
signalled.</para>
<para>If a connection to the database specified by
<parameter>connection-spec</parameter> exists already,
conditions are signalled according to the
<parameter>if-exists</parameter> parameter, as described
above.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><function>connected-databases</function></member>
<member><link linkend="disconnect"><function>disconnect</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="disconnect">
<refnamediv>
<refname>DISCONNECT</refname>
<refpurpose>close a database connection</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>disconnect</function> &key <replaceable>database</replaceable> <replaceable>pool</replaceable> => <returnvalue>t</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>pool</parameter></term>
<listitem>
<para>A boolean flag indicating whether to put the database into a
pool of opened databases. If &t;, rather than terminating the database connection, the
connection is left open and the connection is placed into a pool of connections. Subsequent
calls to <link linkend="connect"><function>connect</function></link> can then reuse this connection.
The default is &nil;.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>The database to disconnect, which defaults to the
database indicated by
<symbol>*default-database*</symbol>.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function takes a <type>database</type> object as
returned by <function>connect</function>, and closes the
connection. The class of the object passed is changed to
<type>closed-database</type> after the disconnection
succeeds, thereby preventing further use of the object as
an argument to &clsql; functions,
with the exception of <function>database-name</function>.
If the user does pass a closed database object to any other
&clsql; function, an error of type
<errortype>clsql-closed-error</errortype> is
signalled.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(disconnect :database (find-database "dent/newesim/dent"))
=> T
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>The database connection is closed, and the database
object is removed from the list of connected databases as
returned by <function>connected-databases</function>.</para>
<para>The class of the database object is changed to
<type>closed-database</type>.</para>
<para>If the database object passed is the same under
<function>eq</function> as the value of
<symbol>*default-database*</symbol>, then
<symbol>*default-database*</symbol> is set to the first
remaining database from
<function>connected-databases</function> or to nil if no
further active database exists.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>
<simplelist>
<member><symbol>*default-database*</symbol></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If during the disconnection attempt an error is
detected (e.g. because of network trouble or any other
cause), an error of type <errortype>clsql-error</errortype>
might be signalled.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="connect"><function>connect</function></link></member>
<member><link linkend="connect"><function>closed-database</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="disconnect-pooled">
<refnamediv>
<refname>DISCONNECT-POOLED</refname>
<refpurpose>closes all pooled database connections</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>disconnect-pool</function> => <returnvalue>t</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function disconnects all database connections
that have been placed into the pool. Connections are placed
in the pool by calling <link
linkend="disconnect"><function>disconnection</function></link>.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(disconnect-pool)
=> T
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>Database connections will be closed and entries in the pool are removed.
</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>
<simplelist>
<member><function>disconnect</function></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If during the disconnection attempt an error is
detected (e.g. because of network trouble or any other
cause), an error of type <errortype>clsql-error</errortype>
might be signalled.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="connect"><function>connect</function></link></member>
<member><link linkend="connect"><function>closed-database</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="create_db">
<refnamediv>
<refname>CREATE-DATABASE</refname>
<refpurpose>create a database</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>create-database</function> <replaceable>connection-spec</replaceable> &key <replaceable>database-type</replaceable> => <returnvalue>success</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>connection-spec</parameter></term>
<listitem>
<para>A connection specification</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database-type</parameter></term>
<listitem>
<para>A database type specifier, i.e. a keyword.
This defaults to the value of
<symbol>*default-database-type*</symbol></para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>success</parameter></term>
<listitem>
<para>A boolean flag. If &t;, a new database was
successfully created.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function creates a database in the database system
specified by <parameter>database-type</parameter>.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(create-database '("localhost" "new" "dent" "dent") :database-type :mysql)
=> T
(create-database '("localhost" "new" "dent" "badpasswd") :database-type :mysql)
=>
Error: While trying to access database localhost/new/dent
using database-type MYSQL:
Error database-create failed: mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user: 'root@localhost' (Using password: YES)'
has occurred.
[condition type: CLSQL-ACCESS-ERROR]
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>A database will be created on the filesystem of the host.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>An exception will be thrown if the database system does
not allow new databases to be created or if database creation
fails.</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>This function may invoke the operating systems
functions. Thus, some database systems may require the
administration functions to be available in the current
<symbol>PATH</symbol>. At this time, the
<symbol>:mysql</symbol> backend requires
<filename>mysqladmin</filename> and the
<symbol>:postgresql</symbol> backend requires
<filename>createdb</filename>.</para>
</refsect1>
</refentry>
<refentry id="destroy_db">
<refnamediv>
<refname>DESTROY-DATABASE</refname>
<refpurpose>destroys a database</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>destroy-database</function> <replaceable>connection-spec</replaceable> &key <replaceable>database-type</replaceable> => <returnvalue>success</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>connection-spec</parameter></term>
<listitem>
<para>A connection specification</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database-type</parameter></term>
<listitem>
<para>A database type specifier, i.e. a keyword.
This defaults to the value of
<symbol>*default-database-type*</symbol></para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>success</parameter></term>
<listitem>
<para>A boolean flag. If &t;, the database was
successfully destroyed.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function destroy a database in the database system
specified by <parameter>database-type</parameter>.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(destroy-database '("localhost" "new" "dent" "dent") :database-type :postgresql)
=> T
(destroy-database '("localhost" "new" "dent" "dent") :database-type :postgresql)
=>
Error: While trying to access database localhost/test2/root
using database-type POSTGRESQL:
Error database-destroy failed: dropdb: database removal failed: ERROR: database "test2" does not exist
has occurred.
[condition type: CLSQL-ACCESS-ERROR]
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>A database will be removed from the filesystem of the host.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>An exception will be thrown if the database system does not
allow databases to be removed, the database does not exist, or
if database removal fails.</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>This function may invoke the operating systems
functions. Thus, some database systems may require the
administration functions to be available in the current
<symbol>PATH</symbol>. At this time, the
<symbol>:mysql</symbol> backend requires
<filename>mysqladmin</filename> and the
<symbol>:postgresql</symbol> backend requires
<filename>dropdb</filename>.</para>
</refsect1>
</refentry>
<refentry id="probe_db">
<refnamediv>
<refname>PROBE-DATABASE</refname>
<refpurpose>tests for existence of a database</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>probe-database</function> <replaceable>connection-spec</replaceable> &key <replaceable>database-type</replaceable> => <returnvalue>success</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>connection-spec</parameter></term>
<listitem>
<para>A connection specification</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database-type</parameter></term>
<listitem>
<para>A database type specifier, i.e. a keyword.
This defaults to the value of
<symbol>*default-database-type*</symbol></para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>success</parameter></term>
<listitem>
<para>A boolean flag. If &t;, the database exists
in the database system.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This function tests for the existence of a database in
the database system specified by
<parameter>database-type</parameter>.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(probe-database '("localhost" "new" "dent" "dent") :database-type :postgresql)
=> T
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>None</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>An exception maybe thrown if the database system does
not receive administrator-level authentication since function
may need to read the administrative database of the database
system.</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="database-name-from-spec">
<refnamediv>
<refname>DATABASE-NAME-FROM-SPEC</refname>
<refpurpose>Return the database name string corresponding to
the given connection specification.</refpurpose>
<refclass>Generic Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis>
<function>database-name-from-spec</function> <replaceable>connection-spec</replaceable> <replaceable>database-type</replaceable> => <returnvalue>name</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>connection-spec</parameter></term>
<listitem>
<para>A connection specification, whose structure and
interpretation are dependent on the
<parameter>database-type</parameter>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database-type</parameter></term>
<listitem>
<para>A database type specifier, i.e. a keyword.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><returnvalue>name</returnvalue></term>
<listitem>
<para>A string denoting a database name.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This generic function takes a connection specification
and a database type and returns the database name of the
database object that would be created had
<function>connect</function> been called with the given
connection specification and database types.</para>
<para>This function is useful in determining a database name
from the connection specification, since the way the
connection specification is converted into a database name
is dependent on the database type.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(database-name-from-spec '("dent" "newesim" "dent" "dent") :mysql)
=> "dent/newesim/dent"
(connect '("dent" "newesim" "dent" "dent") :database-type :mysql)
=> #<CLSQL-MYSQL:MYSQL-DATABASE {48391DCD}>
(database-name *default-database*)
=> "dent/newesim/dent"
(database-name-from-spec '(nil "template1" "dent" nil) :postgresql)
=> "/template1/dent"
(connect '(nil "template1" "dent" nil) :database-type :postgresql)
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {48392D2D}>
(database-name *default-database*)
=> "/template1/dent"
(database-name-from-spec '("www.pmsf.de" "template1" "dent" nil) :postgresql)
=> "www.pmsf.de/template1/dent"
(find-database "dent/newesim/dent")
=> #<CLSQL-MYSQL:MYSQL-DATABASE {484E91C5}>
(find-database "/template1/dent")
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {48392D2D}>
(find-database "www.pmsf.de/template1/dent" nil)
=> NIL
(find-database **)
=> #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {48392D2D}>
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If the value of <parameter>connection-spec</parameter>
is not a valid connection specification for the given
database type, an error of type
<errortype>clsql-invalid-spec-error</errortype> might be
signalled.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="connect"><function>connect</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<!-- Querying Operations -->
<refentry id="execute-command">
<refnamediv>
<refname>EXECUTE-COMMAND</refname>
<refpurpose>Execute an SQL command which returns no
values.</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>execute-command</function> <replaceable>sql-expression</replaceable> &key <replaceable>database</replaceable> => <returnvalue>t</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>sql-expression</parameter></term>
<listitem>
<para>An <glossterm linkend="gloss-sql-expression">sql
expression</glossterm> that represents an SQL
statement which will return no values.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>A
<glossterm linkend="gloss-database-object">database
object</glossterm>. This will default to the value
of <symbol>*default-database*</symbol>.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This will execute the command given by
<parameter>sql-expression</parameter> in the
<parameter>database</parameter> specified. If the execution
succeeds it will return <symbol>t</symbol>, otherwise an
error of type <errortype>sql-database-error</errortype> will
be signalled.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(execute-command "create table eventlog (time char(30),event char(70))")
=> T
(execute-command "create table eventlog (time char(30),event char(70))")
>>
>> While accessing database #<CLSQL-POSTGRESQL:POSTGRESQL-DATABASE {480B2B6D}>
>> with expression "create table eventlog (time char(30),event char(70))":
>> Error NIL: ERROR: amcreate: eventlog relation already exists
>> has occurred.
>>
>> Restarts:
>> 0: [ABORT] Return to Top-Level.
>>
>> Debug (type H for help)
>>
>> (CLSQL-POSTGRESQL::|(PCL::FAST-METHOD DATABASE-EXECUTE-COMMAND (T POSTGRESQL-DATABASE))|
>> #<unused-arg>
>> #<unused-arg>
>> #<unavailable-arg>
>> #<unavailable-arg>)
>> Source: (ERROR 'SQL-DATABASE-ERROR :DATABASE DATABASE :EXPRESSION ...)
>> 0] 0
(execute-command "drop table eventlog")
=> T
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>Whatever effects the execution of the SQL statement has
on the underlying database, if any.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If the execution of the SQL statement leads to any
errors, an error of type
<errortype>sql-database-error</errortype> is signalled.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="query"><function>query</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="query">
<refnamediv>
<refname>QUERY</refname>
<refpurpose>Execute an SQL query and return the tuples as a
list</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>query</function> <replaceable>query-expression</replaceable> &key <replaceable>database</replaceable> <replaceable>result-types</replaceable> <replaceable>field-names</replaceable> => <returnvalue>result</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>query-expression</parameter></term>
<listitem>
<para>An <glossterm linkend="gloss-sql-expression">sql
expression</glossterm> that represents an SQL
query which is expected to return a (possibly empty)
result set.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>A
<glossterm linkend="gloss-database-object">database
object</glossterm>. This will default to the value
of <symbol>*default-database*</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>result-types</parameter></term>
<listitem>
<para>A
<glossterm linkend="gloss-field-types">field type
specifier</glossterm>. The default is &nil;.
</para>
<para>
The purpose of this argument is cause &clsql; to
import SQL numeric fields into numeric Lisp objects
rather than strings. This reduces the cost of
allocating a temporary string and the &clsql; users'
inconvenience of converting number strings into number
objects.
</para>
<para>
A value of <symbol>:auto</symbol> causes &clsql;
to automatically convert SQL fields into a
numeric format where applicable. The default value of
&nil; causes all fields to be returned as strings
regardless of the SQL type. Otherwise a list is expected
which has a element for each field that specifies the
conversion. If the list is shorter than the number
of fields, the a value of <symbol>t</symbol> is
assumed for the field. If the list is longer than
the number of fields, the extra elements are
ignored.
<simplelist type="vert">
<member><symbol>:int</symbol> Field is imported as a
signed integer, from 8-bits to 64-bits depending
upon the field type.
</member>
<member><symbol>:double</symbol> Field is imported as a
double-float number.
</member>
<member><symbol>t</symbol> Field is imported as a
string.
</member>
</simplelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>field-names</parameter></term>
<listitem>
<para>
A boolean with a default value of &t;. When &t;, this
function results a second value of a list of field
names. When &nil;, this function only returns one value
- the list of rows.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><returnvalue>result</returnvalue></term>
<listitem>
<para>A list representing the result set obtained. For
each tuple in the result set, there is an element in
this list, which is itself a list of all the attribute
values in the tuple.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This will execute the query given by
<parameter>query-expression</parameter> in the
<parameter>database</parameter> specified. If the execution
succeeds it will return the result set returned by the
database, otherwise an error of type
<errortype>sql-database-error</errortype> will
be signalled.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(execute-command "create table simple (name char(50), salary numeric(10,2))")
=> T
(execute-command "insert into simple values ('Mai, Pierre',10000)")
=> T
(execute-command "insert into simple values ('Hacker, Random J.',8000.50)")
=> T
(query "select * from simple")
=> (("Mai, Pierre" "10000.00") ("Hacker, Random J." "8000.50"))
(query "select salary from simple")
=> (("10000.00") ("8000.50"))
(query "select salary from simple where salary > 10000")
=> NIL
(query "select salary,name from simple where salary > 10000")
=> NIL
(query "select salary,name from simple where salary > 9000")
=> (("10000.00" "Mai, Pierre"))
(query "select salary,name from simple where salary > 8000")
=> (("10000.00" "Mai, Pierre") ("8000.50" "Hacker, Random J."))
;; MySQL-specific:
(query "show tables")
=> (("demo") ("log") ("newlog") ("simple") ("spacetrial"))
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>Whatever effects the execution of the SQL query has
on the underlying database, if any.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If the execution of the SQL query leads to any
errors, an error of type
<errortype>sql-database-error</errortype> is signalled.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="execute-command"><function>execute-command</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<!-- Iteration -->
<refentry id="map-query">
<refnamediv>
<refname>MAP-QUERY</refname>
<refpurpose>Map a function over all the tuples from a
query</refpurpose>
<refclass>Function</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>map-query</function> <replaceable>output-type-spec</replaceable> <replaceable>function</replaceable> <replaceable>query-expression</replaceable> &key <replaceable>database</replaceable> <replaceable>result-types</replaceable> => <returnvalue>result</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>output-type-spec</parameter></term>
<listitem>
<para>A sequence type specifier or <symbol>nil</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>function</parameter></term>
<listitem>
<para>A function designator.
<parameter>function</parameter> takes a single argument which
is the atom value for a query single with a single column
or is a list of values for a multi-column query.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>query-expression</parameter></term>
<listitem>
<para>An <glossterm linkend="gloss-sql-expression">sql
expression</glossterm> that represents an SQL
query which is expected to return a (possibly empty)
result set.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>A
<glossterm linkend="gloss-database-object">database
object</glossterm>. This will default to the value
of <symbol>*default-database*</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>result-types</parameter></term>
<listitem>
<para>
A <glossterm linkend="gloss-field-types">field type specifier</glossterm>.
The default is &nil;. See <link
linkend="query"><function>query</function></link>
for the semantics of this argument.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><returnvalue>result</returnvalue></term>
<listitem>
<para>If <parameter>output-type-spec</parameter> is a
type specifier other than <symbol>nil</symbol>, then a
sequence of the type it denotes. Otherwise
<symbol>nil</symbol> is returned.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>Applies <parameter>function</parameter> to the
successive tuples in the result set returned
by executing the SQL
<parameter>query-expression</parameter>. If the
<parameter>output-type-spec</parameter> is
<symbol>nil</symbol>, then the result of each application
of <parameter>function</parameter> is discarded, and
<function>map-query</function> returns
<symbol>nil</symbol>. Otherwise the result of each
successive application of <parameter>function</parameter> is
collected in a sequence of type
<parameter>output-type-spec</parameter>, where the jths
element is the result of applying
<parameter>function</parameter> to the attributes of the
jths tuple in the result set. The collected sequence is the
result of the call to <function>map-query</function>.
</para>
<para>If the <parameter>output-type-spec</parameter> is a
subtype of <type>list</type>, the result will be a
<type>list</type>.</para>
<para>If the <parameter>result-type</parameter> is a subtype
of <type>vector</type>, then if the implementation can
determine the element type specified for the
<parameter>result-type</parameter>, the element type of the
resulting array is the result of
<emphasis>upgrading</emphasis> that element type; or, if the
implementation can determine that the element type is
unspecified (or <symbol>*</symbol>), the element type of the
resulting array is <type>t</type>; otherwise, an error is
signaled.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(map-query 'list #'(lambda (tuple)
(multiple-value-bind (salary name) tuple
(declare (ignorable name))
(read-from-string salary)))
"select salary,name from simple where salary > 8000")
=> (10000.0 8000.5)
(map-query '(vector double-float)
#'(lambda (tuple)
(multiple-value-bind (salary name) tuple
(declare (ignorable name))
(let ((*read-default-float-format* 'double-float))
(coerce (read-from-string salary) 'double-float))
"select salary,name from simple where salary > 8000")))
=> #(10000.0d0 8000.5d0)
(type-of *)
=> (SIMPLE-ARRAY DOUBLE-FLOAT (2))
(let (list)
(values (map-query nil #'(lambda (tuple)
(multiple-value-bind (salary name) tuple
(push (cons name (read-from-string salary)) list))
"select salary,name from simple where salary > 8000")
list))
=> NIL
=> (("Hacker, Random J." . 8000.5) ("Mai, Pierre" . 10000.0))
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>Whatever effects the execution of the SQL query has
on the underlying database, if any.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If the execution of the SQL query leads to any
errors, an error of type
<errortype>sql-database-error</errortype> is signalled.</para>
<para>An error of type <errortype>type-error</errortype> must
be signaled if the <parameter>output-type-spec</parameter> is
not a recognizable subtype of <type>list</type>, not a
recognizable subtype of <type>vector</type>, and not
<symbol>nil</symbol>.</para>
<para>An error of type <errortype>type-error</errortype>
should be signaled if
<parameter>output-type-spec</parameter> specifies the number
of elements and the size of the result set is different from
that number.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="query"><function>query</function></link></member>
<member><link linkend="do-query"><function>do-query</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="do-query">
<refnamediv>
<refname>DO-QUERY</refname>
<refpurpose>Iterate over all the tuples of a
query</refpurpose>
<refclass>Macro</refclass>
</refnamediv>
<refsect1>
<title>Syntax</title>
<synopsis><function>do-query</function> ((&rest <replaceable>args</replaceable>) <replaceable>query-expression</replaceable> &key <replaceable>database</replaceable> <replaceable>result-types</replaceable>) &body <replaceable>body</replaceable> => <returnvalue>nil</returnvalue></synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>args</parameter></term>
<listitem>
<para>A list of variable names.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>query-expression</parameter></term>
<listitem>
<para>An <glossterm linkend="gloss-sql-expression">sql
expression</glossterm> that represents an SQL
query which is expected to return a (possibly empty)
result set, where each tuple has as many attributes as
<parameter>function</parameter> takes arguments.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>A
<glossterm linkend="gloss-database-object">database
object</glossterm>. This will default to
<symbol>*default-database*</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>result-types</parameter></term>
<listitem>
<para>
A <glossterm linkend="gloss-field-types">field type specifier</glossterm>.
The default is &nil;. See <link
linkend="query"><function>query</function></link>
for the semantics of this argument.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>body</parameter></term>
<listitem>
<para>A body of Lisp code, like in a
<function>destructuring-bind</function> form.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>Executes the <parameter>body</parameter> of code
repeatedly with the variable names in
<parameter>args</parameter> bound to the attributes of each
tuple in the result set returned by executing the SQL
<parameter>query-expression</parameter> on the
<parameter>database</parameter> specified.</para>
<para>The body of code is executed in a block named
<symbol>nil</symbol> which may be returned from prematurely
via <function>return</function> or
<function>return-from</function>. In this case the result
of evaluating the <function>do-query</function> form will be
the one supplied to <function>return</function> or
<function>return-from</function>. Otherwise the result will
be <symbol>nil</symbol>.</para>
<para>The body of code appears also is if wrapped in a
<function>destructuring-bind</function> form, thus allowing
declarations at the start of the body, especially those
pertaining to the bindings of the variables named in
<parameter>args</parameter>.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(do-query ((salary name) "select salary,name from simple")
(format t "~30A gets $~2,5$~%" name (read-from-string salary)))
>> Mai, Pierre gets $10000.00
>> Hacker, Random J. gets $08000.50
=> NIL
(do-query ((salary name) "select salary,name from simple")
(return (cons salary name)))
=> ("10000.00" . "Mai, Pierre")
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>Whatever effects the execution of the SQL query has
on the underlying database, if any.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If the execution of the SQL query leads to any
errors, an error of type
<errortype>sql-database-error</errortype> is signalled.</para>
<para>If the number of variable names in
<parameter>args</parameter> and the number of attributes in
the tuples in the result set don't match up, an error is
signalled.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="query"><function>query</function></link></member>
<member><link linkend="map-query"><function>map-query</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
<refentry id="loop-tuples">
<refnamediv>
<refname>LOOP-FOR-AS-TUPLES</refname>
<refpurpose>Iterate over all the tuples of a
query via a loop clause</refpurpose>
<refclass>Loop Clause</refclass>
</refnamediv>
<refsect1>
<title>Compatibility</title>
<caution><para><function>loop-for-as-tuples</function> only works with &cmucl;.</para></caution>
</refsect1>
<refsect1>
<title>Syntax</title>
<synopsis><replaceable>var</replaceable> [<replaceable>type-spec</replaceable>] being {each | the} {record | records | tuple | tuples} {in | of} <replaceable>query</replaceable> [from <replaceable>database</replaceable>]</synopsis>
</refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
<varlistentry>
<term><parameter>var</parameter></term>
<listitem>
<para>A <literal>d-var-spec</literal>, as defined in the
grammar for <function>loop</function>-clauses in the
ANSI Standard for Common Lisp. This allows for the
usual loop-style destructuring.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>type-spec</parameter></term>
<listitem>
<para>An optional <literal>type-spec</literal> either
simple or destructured, as defined in the grammar for
<function>loop</function>-clauses in the ANSI Standard
for Common Lisp.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>query</parameter></term>
<listitem>
<para>An <glossterm linkend="gloss-sql-expression">sql
expression</glossterm> that represents an SQL
query which is expected to return a (possibly empty)
result set, where each tuple has as many attributes as
<parameter>function</parameter> takes arguments.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>An optional
<glossterm linkend="gloss-database-object">database
object</glossterm>. This will default to the value
of <symbol>*default-database*</symbol>.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>This clause is an iteration driver for
<function>loop</function>, that binds the given variable
(possibly destructured) to the consecutive tuples (which are
represented as lists of attribute values) in the result set
returned by executing the SQL <parameter>query</parameter>
expression on the <parameter>database</parameter>
specified.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<screen>
(defvar *my-db* (connect '("dent" "newesim" "dent" "dent"))
"My database"
=> *MY-DB*
(loop with time-graph = (make-hash-table :test #'equal)
with event-graph = (make-hash-table :test #'equal)
for (time event) being the tuples of "select time,event from log"
from *my-db*
do
(incf (gethash time time-graph 0))
(incf (gethash event event-graph 0))
finally
(flet ((show-graph (k v) (format t "~40A => ~5D~%" k v)))
(format t "~&Time-Graph:~%===========~%")
(maphash #'show-graph time-graph)
(format t "~&~%Event-Graph:~%============~%")
(maphash #'show-graph event-graph))
(return (values time-graph event-graph)))
>> Time-Graph:
>> ===========
>> D => 53000
>> X => 3
>> test-me => 3000
>>
>> Event-Graph:
>> ============
>> CLOS Benchmark entry. => 9000
>> Demo Text... => 3
>> doit-text => 3000
>> C Benchmark entry. => 12000
>> CLOS Benchmark entry => 32000
=> #<EQUAL hash table, 3 entries {48350A1D}>
=> #<EQUAL hash table, 5 entries {48350FCD}>
</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<para>Whatever effects the execution of the SQL query has
on the underlying database, if any.</para>
</refsect1>
<refsect1>
<title>Affected by</title>
<para>None.</para>
</refsect1>
<refsect1>
<title>Exceptional Situations</title>
<para>If the execution of the SQL query leads to any
errors, an error of type
<errortype>sql-database-error</errortype> is signalled.</para>
<para>Otherwise, any of the exceptional situations of
<function>loop</function> applies.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<simplelist>
<member><link linkend="query"><function>query</function></link></member>
<member><link linkend="map-query"><function>map-query</function></link></member>
<member><link linkend="do-query"><function>do-query</function></link></member>
</simplelist>
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>None.</para>
</refsect1>
</refentry>
</reference>
|