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 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473
|
//
// This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
// project.
//
// Copyright (C) 1998-2012 OpenLink Software
//
// This project is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; only version 2 of the License, dated June 1991.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
//
//
// $Id$
//
using System;
using System.Collections;
using System.Data;
#if ADONET2
using System.Data.Common;
using System.Text;
#endif
using System.Diagnostics;
//using System.EnterpriseServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.ComponentModel;
#if ODBC_CLIENT
namespace OpenLink.Data.VirtuosoOdbcClient
#elif CLIENT
namespace OpenLink.Data.VirtuosoClient
#else
namespace OpenLink.Data.Virtuoso
#endif
{
#if (!MONO) // for now Mono doesn't have an IDE
[System.Drawing.ToolboxBitmapAttribute(typeof(VirtuosoConnection), "OpenLink.Data.VirtuosoClient.VirtuosoConnection.bmp") ]
#endif
public sealed class VirtuosoConnection :
#if ADONET2
DbConnection, ICloneable
#else
System.ComponentModel.Component, ICloneable, IDbConnection
#endif
{
/// <summary>
/// Constants relating to SpecialColumns metadata restrictions
/// </summary>
public sealed class SpecialColumnsRestrictions
{
// IDENTIFIER_TYPE restriction values
public static readonly string IDENTIFIER_TYPE_BEST_ROWID = "BEST_ROWID";
public static readonly string IDENTIFIER_TYPE_ROWVER = "ROWVER";
// SCOPE restriction values
public static readonly string SCOPE_CURROW = "CURROW";
public static readonly string SCOPE_TRANSACTION = "TRANSACTION";
public static readonly string SCOPE_SESSION = "SESSION";
// NULLABLE restriction values
public static readonly string NO_NULLS = "NO NULLS";
public static readonly string NULLABLE = "NULLABLE";
}
internal const string VARCHAR_UNSPEC_SIZE = "4070";
internal static VirtuosoPermission permission = new VirtuosoPermission ();
/// <summary>
/// The state of the connection.
/// </summary>
internal ConnectionState state;
/// <summary>
/// The field to keep connection string options.
/// </summary>
internal ConnectionOptions options;
internal IInnerConnection innerConnection = null;
internal ConnectionPool pool;
private bool autocommit;
private VirtuosoTransaction transactionStrongRef;
private bool disposed = false;
#if ADONET2 || ADONET1_SCHEMA_EXTS
private static string SqlReservedWords =
"ABSOLUTE,ACTION,ADA,ADD,ALL,ALLOCATE,ALTER,AND,ANY,ARE,AS," +
"ASC,ASSERTION,AT,AUTHORIZATION,AVG,BEGIN,BETWEEN,BIT," +
"BIT_LENGTH,BIGINT,BOTH,BY,CASCADE,CASCADED,CASE,CAST,CATALOG," +
"CHAR," +
"CHAR_LENGTH,CHARACTER,CHARACTER_LENGTH,CHECK,CLOSE,COALESCE," +
"COLLATE,COLLATION,COLUMN,COMMIT,CONNECT,CONNECTION,CONSTRAINT," +
"CONSTRAINTS,CONTINUE,CONVERT,CORRESPONDING,COUNT,CREATE,CROSS," +
"CURRENT,CURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP," +
"CURRENT_USER,CURSOR,DATE,DAY,DEALLOCATE,DEC,DECIMAL,DECLARE," +
"DEFAULT,DEFERRABLE,DEFERRED,DELETE,DESC,DESCRIBE,DESCRIPTOR," +
"DIAGNOSTICS,DISCONNECT,DISTINCT,DOMAIN,DOUBLE,DROP,ELSE,END," +
"END-EXEC,ESCAPE,EXCEPT,EXCEPTION,EXEC,EXECUTE,EXISTS,EXTERNAL," +
"EXTRACT,FALSE,FETCH,FIRST,FLOAT,FOR,FOREIGN,FORTRAN,FOUND,FROM," +
"FULL,GET,GLOBAL,GO,GOTO,GRANT,GROUP,HAVING,HOUR,IDENTITY," +
"IMMEDIATE,IN,INCLUDE,INDEX,INDICATOR,INITIALLY,INNER,INPUT," +
"INSENSITIVE,INSERT,INT,INTEGER,INTERSECT,INTERVAL,INTO,IS," +
"ISOLATION,JOIN,KEY,LANGUAGE,LAST,LEADING,LEFT,LEVEL,LIKE,LOCAL," +
"LOWER,MATCH,MAX,MIN,MINUTE,MODULE,MONTH,NAMES,NATIONAL,NATURAL," +
"NCHAR,NEXT,NO,NONE,NOT,NULL,NULLIF,NUMERIC,OCTET_LENGTH,OF,ON," +
"ONLY,OPEN,OPTION,OR,ORDER,OUTER,OUTPUT,OVERLAPS,PAD,PARTIAL," +
"PASCAL,POSITION,PRECISION,PREPARE,PRESERVE,PRIMARY,PRIOR," +
"PRIVILEGES,PROCEDURE,PUBLIC,READ,REAL,REFERENCES,RELATIVE," +
"RESTRICT,REVOKE,RIGHT,ROLLBACK,ROWS,SCHEMA,SCROLL,SECOND," +
"SECTION,SELECT,SESSION,SESSION_USER,SET,SIZE,SMALLINT,SOME," +
"SPACE,SQL,SQLCA,SQLCODE,SQLERROR,SQLSTATE,SQLWARNING,SUBSTRING," +
"SUM,SYSTEM_USER,TABLE,TEMPORARY,THEN,TIME,TIMESTAMP," +
"TIMEZONE_HOUR,TIMEZONE_MINUTE,TO,TRAILING,TRANSACTION,TRANSLATE," +
"TRANSLATION,TRIM,TRUE,UNION,UNIQUE,UNKNOWN,UPDATE,UPPER,USAGE," +
"USER,USING,VALUE,VALUES,VARCHAR,VARYING,VIEW,WHEN,WHENEVER," +
"WHERE,WITH,WORK,WRITE,YEAR,ZONE," +
// Virtuoso specific
"CHAR,INT,LONG,OBJECT_ID,REPLACING,SMALLINT,SOFT,VALUES"
;
#endif
// Always have a default constructor.
public VirtuosoConnection ()
: this (null)
{
}
// Have a constructor that takes a connection string.
public VirtuosoConnection (string connectionString)
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.ctor()");
// Initialize the connection object into a closed state.
state = ConnectionState.Closed;
autocommit = true;
if (connectionString != null)
options = ParseConnectionString (connectionString);
else
options = new ConnectionOptions ();
}
/*
* Now inherited from the System.ComponentModel.Component
*
~VirtuosoConnection ()
{
Dispose (false);
}
*/
/*
* Now inherited from the System.ComponentModel.Component
*
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
*/
object ICloneable.Clone ()
{
VirtuosoConnection conn = new VirtuosoConnection ();
conn.options = this.options;
return conn;
}
#if !MONO
[Editor(
VirtuosoConstants.VirtuosoDesignNSPrefix + ".VirtuosoConnectionStringEditor, " +
VirtuosoConstants.VirtuosoDesignSN,
typeof (System.Drawing.Design.UITypeEditor))]
// [Description ("hahaahha")]
[Category("Data")]
#endif
#if ADONET2
public override string ConnectionString
#else
public string ConnectionString
#endif
{
get
{
return options.ConnectionString;
}
set
{
if (state != ConnectionState.Closed)
throw new InvalidOperationException ("The connection is open.");
try
{
options = ParseConnectionString (value);
}
catch
{
throw;
}
}
}
#if !MONO
// [Description ("hahaahha")]
[Category("Data")]
#endif
#if ADONET2
public override int ConnectionTimeout
#else
public int ConnectionTimeout
#endif
{
get
{
// Returns the connection time-out value set in the connection
// string. Zero indicates an indefinite time-out period.
return options.ConnectionTimeout;
}
}
#if !MONO
// [Description ("hahaahha")]
[Category("Data")]
#endif
#if ADONET2
public override string Database
#else
public string Database
#endif
{
get
{
// Returns an initial database as set in the connection string.
// An empty string indicates not set - do not return a null reference.
String database;
if (state == ConnectionState.Closed)
database = options.Database;
else
database = innerConnection.GetCurrentCatalog ();
return database == null ? "" : database;
}
}
#if ADONET2
public string UserName
{
get
{
String username;
if (state == ConnectionState.Closed)
username = options.UserId;
else
username = innerConnection.UserName;
return username;
}
}
#endif
#if !MONO
// [Description ("hahaahha")]
[Category("Data")]
#endif
#if ADONET2
public override ConnectionState State
#else
public ConnectionState State
#endif
{
get { return state; }
}
#if ADONET2
public new VirtuosoTransaction BeginTransaction ()
#else
public VirtuosoTransaction BeginTransaction ()
#endif
{
return BeginTransaction (IsolationLevel.ReadCommitted);
}
#if ADONET2
public new VirtuosoTransaction BeginTransaction (IsolationLevel level)
#else
public VirtuosoTransaction BeginTransaction (IsolationLevel level)
#endif
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.BeginTransaction (level = " + level + ")");
if (state == ConnectionState.Closed)
throw new InvalidOperationException ("The connection is closed");
CLI.IsolationLevel isolation;
switch (level)
{
case IsolationLevel.ReadUncommitted:
isolation = CLI.IsolationLevel.SQL_TXN_READ_UNCOMMITTED;
break;
case IsolationLevel.ReadCommitted:
isolation = CLI.IsolationLevel.SQL_TXN_READ_COMMITED;
break;
case IsolationLevel.RepeatableRead:
isolation = CLI.IsolationLevel.SQL_TXN_REPEATABLE_READ;
break;
case IsolationLevel.Serializable:
isolation = CLI.IsolationLevel.SQL_TXN_SERIALIZABLE;
break;
case IsolationLevel.Unspecified:
isolation = CLI.IsolationLevel.SQL_TXN_READ_COMMITED;
break;
default:
throw new Exception ("Unknown or unsupported isolation level");
}
VirtuosoTransaction transaction = null;
if (!autocommit && transactionStrongRef != null)
{
transaction = (VirtuosoTransaction) transactionStrongRef;
if (transaction != null)
throw new InvalidOperationException ("Another transaction is running.");
EndTransaction (false);
}
innerConnection.BeginTransaction (isolation);
autocommit = false;
transaction = new VirtuosoTransaction (this, level);
transactionStrongRef = transaction;
return transaction;
}
#if ADONET2
protected override DbTransaction BeginDbTransaction (IsolationLevel level)
#else
IDbTransaction IDbConnection.BeginTransaction(IsolationLevel level)
#endif
{
return BeginTransaction (level);
}
#if !ADONET2
IDbTransaction IDbConnection.BeginTransaction ()
{
return BeginTransaction ();
}
#endif
#if ADONET2
public override void ChangeDatabase (string dbName)
#else
public void ChangeDatabase (string dbName)
#endif
{
/*
* Change the database setting on the back-end. Note that it is a method
* and not a property because the operation requires an expensive
* round trip.
*/
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.ChangeDatabase (dbName = '" + dbName + "')");
if (dbName == null || dbName.Trim () == "")
throw new ArgumentException ("Invalid database name");
if (state == ConnectionState.Closed)
throw new InvalidOperationException ("The connection is closed");
innerConnection.SetCurrentCatalog (dbName);
}
#if ADONET2
public override void Close ()
#else
public void Close ()
#endif
{
/*
* Close the database connection and set the ConnectionState
* property. If the underlying connection to the server is
* being pooled, Close() will release it back to the pool.
*/
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.Close ()");
if (state != ConnectionState.Closed)
{
if (!autocommit && transactionStrongRef != null)
{
VirtuosoTransaction transaction = (VirtuosoTransaction) transactionStrongRef;
if (transaction != null)
transaction.Dispose ();
else
EndTransaction (false);
}
if (pool != null)
pool.PutConnection (innerConnection);
else
innerConnection.Close ();
innerConnection = null;
state = ConnectionState.Closed;
OnClose ();
}
}
#if ADONET2
protected override DbCommand CreateDbCommand ()
#else
IDbCommand IDbConnection.CreateCommand ()
#endif
{
return CreateCommand ();
}
#if ADONET2
public new VirtuosoCommand CreateCommand ()
#else
public VirtuosoCommand CreateCommand ()
#endif
{
// Return a new instance of a command object.
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.CreateCommand()");
VirtuosoCommand command = new VirtuosoCommand ();
command.Connection = this;
return command;
}
public void EnlistDistributedTransaction (System.EnterpriseServices.ITransaction transaction)
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.EnlistDistributedTransaction ();");
if (state == ConnectionState.Closed)
throw new InvalidOperationException ("The connection is closed");
if (!Platform.HasDtc ())
throw new InvalidOperationException ("Transaction enlistment is not supported on this platform.");
if (transactionStrongRef != null)
throw new InvalidOperationException ("A local transaction is active");
innerConnection.Enlist (transaction);
autocommit = false;
}
#if ADONET2
public override void Open ()
#else
public void Open ()
#endif
{
/*
* Open the database connection and set the ConnectionState
* property. If the underlying connection to the server is
* expensive to obtain, the implementation should provide
* implicit pooling of that connection.
*
* If the provider also supports automatic enlistment in
* distributed transactions, it should enlist during Open().
*/
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.Open ()");
if (state != ConnectionState.Closed)
throw new InvalidOperationException ("The connection has already been open.");
permission.Demand ();
if (options.Pooling)
{
if (pool == null)
pool = ConnectionPool.GetPool (options);
innerConnection = pool.GetConnection (options, this);
}
else
{
innerConnection = CreateInnerConnection (options, true);
}
state = ConnectionState.Open;
options.Secure ();
OnOpen ();
}
#if !MONO
// [Description ("hahaahha")]
[Category("Data")]
#endif
#if ADONET2 && !MONO1231
public override event StateChangeEventHandler StateChange;
#else
public event StateChangeEventHandler StateChange;
#endif
private void OnOpen ()
{
if (StateChange != null)
{
StateChangeEventArgs args = new StateChangeEventArgs (ConnectionState.Closed, ConnectionState.Open);
StateChange (this, args);
}
}
private void OnClose ()
{
if (StateChange != null)
{
StateChangeEventArgs args = new StateChangeEventArgs (ConnectionState.Open, ConnectionState.Closed);
StateChange (this, args);
}
}
#if !MONO
// [Description ("hahaahha")]
[Category("Data")]
#endif
public event VirtuosoInfoMessageEventHandler InfoMessage;
internal void OnInfoMessage (VirtuosoInfoMessageEventArgs args)
{
if (InfoMessage != null)
{
InfoMessage (this, args);
}
}
internal void EndTransaction (bool commit)
{
if (state == System.Data.ConnectionState.Closed)
throw new InvalidOperationException ("The connection is closed.");
if (autocommit)
throw new InvalidOperationException ("No transaction is active.");
innerConnection.EndTransaction (commit);
transactionStrongRef = null;
autocommit = true;
}
internal VirtuosoTransaction CheckTransaction (VirtuosoTransaction transaction)
{
if (transactionStrongRef != null)
{
VirtuosoTransaction currentTransaction = (VirtuosoTransaction) transactionStrongRef;
if (currentTransaction != transaction)
{
if (currentTransaction == null)
EndTransaction (false);
if (transaction == null)
throw new InvalidOperationException ("The transaction is not set.");
else
throw new InvalidOperationException ("The transaction is not associated with the connection.");
}
}
else if (transaction != null)
{
if (transaction.Connection != null)
throw new InvalidOperationException ("The transaction is not associated with the connection.");
transaction = null;
}
return transaction;
}
protected override void Dispose (bool disposing)
{
try
{
if (disposed)
return;
disposed = true;
if (disposing)
{
Close ();
}
innerConnection = null;
options = null;
base.Dispose (disposing);
}
catch (Exception e)
{
Debug.WriteLineIf(CLI.FnTrace.Enabled,
"VirtuosoConnection.Dispose caught exception: " + e.Message);
}
}
private ConnectionOptions ParseConnectionString (string connectionString)
{
pool = null;
ConnectionStringParser parser = new ConnectionStringParser ();
ConnectionOptions newOptions = new ConnectionOptions ();
parser.Parse (connectionString, newOptions); // can throw an exception
newOptions.Verify (); // can throw an exception
return newOptions;
}
internal IInnerConnection CreateInnerConnection (ConnectionOptions options, bool enlist)
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoConnection.CreateInnerConnection()");
IInnerConnection conn;
#if UNMANAGED_ODBC
if (options.UseOdbc)
conn = new OdbcConnection ();
else
#endif
conn = new TcpConnection ();
conn.OuterConnectionWeakRef = new WeakReference (this);
conn.Open (options);
#if MTS
if (enlist && options.Enlist && ContextUtil.IsInTransaction)
EnlistInnerConnection (conn);
#endif
return conn;
}
internal void EnlistInnerConnection (IInnerConnection conn)
{
try
{
object dt = System.EnterpriseServices.ContextUtil.Transaction;
conn.Enlist (dt);
conn.DistributedTransaction = dt;
conn.DistributedTransactionId = System.EnterpriseServices.ContextUtil.TransactionId;
autocommit = false;
}
catch
{
conn.Close ();
throw;
}
}
public string GetConnectionOption (string name)
{
return options.GetOption (name).ToString ();
}
#region ADO.NET 2.0
#if ADONET2
//TODO: FIX THAT
//string m_dataSourceName;
public override string DataSource
{
get { return "DummyDataSource"; }
}
public override string ServerVersion
{
get { return this.innerConnection.ServerVersion; }
}
#endif
#if ADONET2
//
// Empties the connection pool associated with the specified connection.
// ClearPool clears the connection pool that is associated with the
// connection. If additional connections associated with the pool
// are in use at the time of the call, they are marked appropriately
// and are discarded (instead of being returned to the pool) when
// Close is called on them.
//
public static void ClearPool(VirtuosoConnection connection)
{
if (connection == null)
throw new ArgumentNullException("connection");
if (!connection.options.Pooling || connection.pool == null)
throw new InvalidOperationException("This connection is not pooled.");
ConnectionPool.ClearPool(connection.options.ConnectionString);
}
//
// ClearAllPools resets (or empties) the connection pool. If there
// are connections in use at the time of the call, they are marked
// appropriately and will be discarded (instead of being returned
// to the pool) when Close is called on them.
//
public static void ClearAllPools()
{
ConnectionPool.ClearAllPools();
}
// Returns the MetaDataCollections schema.
public override DataTable GetSchema()
{
// Note:
// No base class functionality available. DbConnection.GetSchema()
// simply throws a NotSupportedException.
return GetSchema("MetaDataCollections", null);
}
// Returns schema information for the specific collection.
public override DataTable GetSchema(string collectionName)
{
return GetSchema(collectionName, null);
}
// Retrieves schema information using the specified constraint(s) for
// the specified collection.
public override DataTable GetSchema(string collectionName, string[] restrictionValues)
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "GetSchema" + collectionName + restrictionValues);
if (state != ConnectionState.Open)
throw new InvalidOperationException("The connection is not open.");
string[] parms = new string[6]; // Assume no schema supports > 6 restrictions
if (restrictionValues != null)
restrictionValues.CopyTo(parms, 0);
// bug 13648
// Virtuoso DBA userid is "dba", but the corresponding schema qualifier is "DBA"
// Convert any schema qualifier restrictions for this user to uppercase.
if (restrictionValues != null)
{
switch (collectionName.ToUpper())
{
case "COLUMNPRIVILEGES":
case "COLUMNS":
case "INDEXES":
case "PRIMARY KEYS":
case "PROCEDURES":
case "PROCEDURECOLUMNS":
case "PROCEDUREPARAMETERS":
case "TABLEPRIVILEGES":
case "TABLES":
case "VIEWS":
if (parms[1] != null && parms[1].Equals("dba"))
parms[1] = parms[1].ToUpper();
break;
case "SPECIALCOLUMNS":
if (parms[2] != null && parms[2].Equals("dba"))
parms[2] = parms[2].ToUpper();
break;
case "FOREIGNKEYS":
if (parms[1] != null && parms[1].Equals("dba"))
parms[1] = parms[1].ToUpper();
if (parms[4] != null && parms[4].Equals("dba"))
parms[4] = parms[4].ToUpper();
break;
}
}
// bug 13648
DataTable dt = null;
switch (collectionName.ToUpper())
{
case "METADATACOLLECTIONS":
dt = GetSchemaMetaDataCollections();
break;
case "DATASOURCEINFORMATION":
dt = GetSchemaDataSourceInformation();
break;
case "DATATYPES":
dt = GetSchemaDataTypes();
break;
case "RESTRICTIONS":
dt = GetSchemaRestrictions();
break;
case "RESERVEDWORDS":
dt = GetSchemaReservedWords();
break;
case "COLUMNPRIVILEGES":
dt = GetSchemaColumnPrivileges(parms[0], parms[1], parms[2], parms[3]);
break;
case "COLUMNS":
dt = GetSchemaColumns(parms[0], parms[1], parms[2], parms[3]);
break;
case "FOREIGNKEYS":
dt = GetSchemaForeignKeys(parms[0], parms[1], parms[2], parms[3],
parms[4], parms[5]);
break;
case "INDEXES":
dt = GetSchemaIndexes(parms[0], parms[1], parms[2], parms[3]);
break;
case "PRIMARYKEYS":
dt = GetSchemaPrimaryKeys(parms[0], parms[1], parms[2]);
break;
case "PROCEDURES":
dt = GetSchemaProcedures(parms[0], parms[1], parms[2], parms[3]);
break;
case "PROCEDURECOLUMNS":
dt = GetSchemaProcedureColumns(parms[0], parms[1], parms[2], parms[3]);
break;
case "PROCEDUREPARAMETERS":
dt = GetSchemaProcedureParameters(parms[0], parms[1], parms[2], parms[3]);
break;
case "SPECIALCOLUMNS":
dt = GetSchemaSpecialColumns(parms[0], parms[1], parms[2], parms[3],
parms[4], parms[5]);
break;
case "TABLEPRIVILEGES":
dt = GetSchemaTablePrivileges(parms[0], parms[1], parms[2]);
break;
case "TABLES":
dt = GetSchemaTables(parms[0], parms[1], parms[2], parms[3]);
break;
case "VIEWS":
dt = GetSchemaViews(parms[0], parms[1], parms[2]);
break;
default:
throw new ArgumentOutOfRangeException("Unsupported metadata collection name");
}
return dt;
}
private DataTable GetSchemaMetaDataCollections()
{
DataTable dt = new DataTable(DbMetaDataCollectionNames.MetaDataCollections);
dt.Columns.Add(DbMetaDataColumnNames.CollectionName, typeof(String));
dt.Columns.Add(DbMetaDataColumnNames.NumberOfRestrictions, typeof(Int32));
dt.Columns.Add(DbMetaDataColumnNames.NumberOfIdentifierParts, typeof(Int32));
dt.BeginLoadData();
dt.Rows.Add(new object[] { DbMetaDataCollectionNames.MetaDataCollections, 0, 0 });
dt.Rows.Add(new object[] { DbMetaDataCollectionNames.DataSourceInformation, 0, 0 });
dt.Rows.Add(new object[] { DbMetaDataCollectionNames.DataTypes, 0, 0 });
dt.Rows.Add(new object[] { DbMetaDataCollectionNames.Restrictions, 0, 0 });
dt.Rows.Add(new object[] { DbMetaDataCollectionNames.ReservedWords, 0, 0 });
dt.Rows.Add(new object[] { "ColumnPrivileges", 4, 4 });
dt.Rows.Add(new object[] { "Columns", 4, 4 });
dt.Rows.Add(new object[] { "ExtendedDataSourceInformation", 0, 0 });
dt.Rows.Add(new object[] { "ForeignKeys", 6, 4 });
dt.Rows.Add(new object[] { "Indexes", 4, 4 });
dt.Rows.Add(new object[] { "PrimaryKeys", 3, 4 });
dt.Rows.Add(new object[] { "Procedures", 4, 3 });
dt.Rows.Add(new object[] { "ProcedureColumns", 4, 4 });
dt.Rows.Add(new object[] { "ProcedureParameters", 4, 4 });
dt.Rows.Add(new object[] { "SpecialColumns", 6, 3 });
dt.Rows.Add(new object[] { "TablePrivileges", 3, 3 });
dt.Rows.Add(new object[] { "Tables", 4, 3 });
dt.Rows.Add(new object[] { "Views", 3, 3 });
dt.AcceptChanges();
dt.EndLoadData();
return dt;
}
private DataTable GetSchemaDataSourceInformation()
{
CLI.IdentCase identCase = innerConnection.IdentCase;
CLI.IdentCase quotedIdentCase = innerConnection.QuotedIdentCase;
string dbmsName = innerConnection.ServerName;
string dbmsVer = innerConnection.ServerVersion;
bool orderByColsInSelect = false;
CLI.GroupBy groupByBehavior = CLI.GroupBy.SQL_GB_GROUP_BY_CONTAINS_SELECT;
CLI.OuterJoin supportedJoinOps = CLI.OuterJoin.SQL_OJ_LEFT | CLI.OuterJoin.SQL_OJ_RIGHT | CLI.OuterJoin.SQL_OJ_NESTED;
DataTable dt = new DataTable(DbMetaDataCollectionNames.DataSourceInformation);
dt.Columns.Add(DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.DataSourceProductName, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.DataSourceProductVersion, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.DataSourceProductVersionNormalized, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.GroupByBehavior, typeof(int));
dt.Columns.Add(DbMetaDataColumnNames.IdentifierPattern, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.IdentifierCase, typeof(int));
dt.Columns.Add(DbMetaDataColumnNames.OrderByColumnsInSelect, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.ParameterMarkerFormat, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.ParameterMarkerPattern, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.ParameterNameMaxLength, typeof(int));
dt.Columns.Add(DbMetaDataColumnNames.ParameterNamePattern, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.QuotedIdentifierPattern, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.QuotedIdentifierCase, typeof(int));
dt.Columns.Add(DbMetaDataColumnNames.StatementSeparatorPattern, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.StringLiteralPattern, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.SupportedJoinOperators, typeof(int));
dt.Rows.Add(new object[]
{
// CompositeIdentifierSeparatorPattern
@"\.",
// DataSourceProductName
// jch Check this
"Virtuoso",
// DataSourceProductVersion
dbmsVer,
// DataSourceProductVersionNormalized
dbmsVer,
// GroupByBehavior
groupByBehavior,
// IdentifierPattern
// c.f. MS ODBC provider returns null
null,
// IdentifierCase
identCase,
// OrderByColumnsInSelect
orderByColsInSelect,
// ParameterMarkerFormat
"?",
// ParameterMarkerPattern
"?",
// ParameterNameMaxLength
0,
// ParameterNamePattern
// c.f. MS ODBC provider returns null
null,
// QuotedIdentifierPattern
"\"(([^\"]|\"\")*)\"",
// QuotedIdentifierCase
quotedIdentCase,
// StatementSeparatorPattern
// c.f. MS ODBC provider returns null
null,
// StringLiteralPattern
@"'(([^']|'')*)'",
// SupportedJoinOperators
supportedJoinOps
});
dt.AcceptChanges();
dt.EndLoadData();
return dt;
}
private DataTable GetSchemaDataTypes()
{
DataTable dt = new DataTable(DbMetaDataCollectionNames.DataTypes);
dt.Columns.Add(DbMetaDataColumnNames.TypeName, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.ProviderDbType, typeof(int));
dt.Columns.Add(DbMetaDataColumnNames.ColumnSize, typeof(long));
dt.Columns.Add(DbMetaDataColumnNames.CreateFormat, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.CreateParameters, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.DataType, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.IsAutoIncrementable, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsBestMatch, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsCaseSensitive, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsFixedLength, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsFixedPrecisionScale, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsLong, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsNullable, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsSearchable, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsSearchableWithLike, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsUnsigned, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.MaximumScale, typeof(short));
dt.Columns.Add(DbMetaDataColumnNames.MinimumScale, typeof(short));
dt.Columns.Add(DbMetaDataColumnNames.IsConcurrencyType, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.IsLiteralSupported, typeof(bool));
dt.Columns.Add(DbMetaDataColumnNames.LiteralPrefix, typeof(string));
dt.Columns.Add(DbMetaDataColumnNames.LiteralSuffix, typeof(string));
dt.Rows.Add(new object[]{"character", 1, 4070, null, "length",
"System.String", 0, null, 1, 1, 0, 0, 1, 1, 1, 0, null, null,
null, null, "''", "''"});
dt.Rows.Add(new object[]{"numeric", 2, 40, null, "precision,scale",
"System.Decimal", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, 15, 0,
null, null, "", ""});
dt.Rows.Add(new object[]{"decimal", 3, 40, null, "precision,scale",
"System.Decimal", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, 15, 0,
null, null, "", ""});
dt.Rows.Add(new object[]{"integer", 4, 10, null, null,
"System.Int32", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, 10, 0,
null, null, "", ""});
dt.Rows.Add(new object[]{"smallint", 5, 3, null, null,
"System.Int16", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "", ""});
dt.Rows.Add(new object[]{"smallint", -7, 3, null, null,
"System.Int16", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "", ""});
dt.Rows.Add(new object[]{"bigint", -5, 20, null, null,
"System.Int64", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "", ""});
dt.Rows.Add(new object[]{"float", 6, 16, null, null,
"System.Double", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null,null,
null, null, "", "e0"});
dt.Rows.Add(new object[]{"real", 7, 16, null, null,
"real", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "", "e0"});
dt.Rows.Add(new object[]{"double precision", 8, 16, null, null,
"System.Double", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "", "e0"});
dt.Rows.Add(new object[]{"varchar", 12, 4070, null, "length",
"System.String", 0, null, 1, 0, 0, 0, 1, 1, 1, 0, null, null,
null, null, "''", "''"});
dt.Rows.Add(new object[]{"long varchar", -1, 2147483647, null,null,
"System.String", 0, null, 1, 0, 0, 1, 1, 0, 0, 0, null, null,
null, null, "''", "''"});
dt.Rows.Add(new object[]{"long varbinary", -4,2147483647,null,null,
"System.Byte[]", 0, null, 1, 0, 0, 1, 1, 0, 0, 0, null, null,
null, null, "''", "''"});
dt.Rows.Add(new object[]{"datetime", 93, 19, null, null,
"System.DateTime", 0, null, 1, 1, 0, 0, 1, 1, 1, 0, null, null,
null, null, "{ts", "}"});
dt.Rows.Add(new object[]{"timestamp", -2, 10, null, null,
"System.Byte[]", 0, null, 0, 1, 0, 0, 0, 1, 0, 0, null, null,
null, null, "0x", null});
dt.Rows.Add(new object[]{"time", 92, 8, null, null,
"System.DateTime", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "{t", "}"});
dt.Rows.Add(new object[]{"date", 91, 10, null, null,
"System.DateTime", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "{d", "}"});
dt.Rows.Add(new object[]{"binary", -2, 4070, null, "length",
"System.Byte[]", 0, null, 1, 1, 0, 0, 1, 1, 0, 0, null, null,
null, null, "0x", ""});
dt.Rows.Add(new object[]{"varbinary", -3, 4070, null, "length",
"System.Byte[]", 0, null, 1, 0, 0, 0, 1, 1, 0, 0, null, null,
null, null, "0x", ""});
dt.Rows.Add(new object[]{"nchar", -8, 4070, null, "length",
"System.String", 0, null, 1, 1, 0, 0, 1, 1, 1, 0, null, null,
null, null, "N''", "''"});
dt.Rows.Add(new object[]{"nvarchar", -9, 4070, null, "length",
"System.String", 0, null, 1, 0, 0, 0, 1, 1, 1, 0, null, null,
null, null, "N''", "''"});
dt.Rows.Add(new object[]{"long nvarchar", -10,1073741823,null,null,
"System.String", 0, null, 1, 0, 0, 1, 1, 0, 0, 0, null, null,
null, null, "N''", "''"});
dt.Rows.Add(new object[]{"any", 12, 4070, null, null,
"System.Object", 0, null, 1, 1, 0, 0, 1, 1, 1, 0, null, null,
null, null, "''", "''"});
dt.AcceptChanges();
dt.EndLoadData();
return dt;
}
private DataTable GetSchemaRestrictions()
{
DataTable dt = new DataTable("Restrictions");
dt.Columns.Add("CollectionName", typeof(string));
dt.Columns.Add("RestrictionName", typeof(string));
dt.Columns.Add("RestrictionDefault", typeof(string));
dt.Columns.Add("RestrictionNumber", typeof(int));
dt.BeginLoadData();
dt.Rows.Add(new object[] { "ColumnPrivileges", "TABLE_CAT", null, 1 });
dt.Rows.Add(new object[] { "ColumnPrivileges", "TABLE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "ColumnPrivileges", "TABLE_NAME", null, 3 });
dt.Rows.Add(new object[] { "ColumnPrivileges", "COLUMN_NAME", null, 4 });
dt.Rows.Add(new object[] { "Columns", "TABLE_CAT", null, 1 });
dt.Rows.Add(new object[] { "Columns", "TABLE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "Columns", "TABLE_NAME", null, 3 });
dt.Rows.Add(new object[] { "Columns", "COLUMN_NAME", null, 4 });
dt.Rows.Add(new object[] { "ForeignKeys", "PK_CAT_NAME", null, 1 });
dt.Rows.Add(new object[] { "ForeignKeys", "PK_SCHEM_NAME", null, 2 });
dt.Rows.Add(new object[] { "ForeignKeys", "PK_TABLE_NAME", null, 3 });
dt.Rows.Add(new object[] { "ForeignKeys", "FK_CAT_NAME", null, 4 });
dt.Rows.Add(new object[] { "ForeignKeys", "FK_SCHEM_NAME", null, 5 });
dt.Rows.Add(new object[] { "ForeignKeys", "FK_TABLE_NAME", null, 6 });
dt.Rows.Add(new object[] { "Indexes", "TABLE_CAT", null, 1 });
dt.Rows.Add(new object[] { "Indexes", "TABLE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "Indexes", "TABLE_NAME", null, 3 });
dt.Rows.Add(new object[] { "Indexes", "INDEX_NAME", null, 4 });
dt.Rows.Add(new object[] { "PrimaryKeys", "TABLE_CAT", null, 1 });
dt.Rows.Add(new object[] { "PrimaryKeys", "TABLE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "PrimaryKeys", "TABLE_NAME", null, 3 });
dt.Rows.Add(new object[] { "Procedures", "PROCEDURE_CAT", null, 1 });
dt.Rows.Add(new object[] { "Procedures", "PROCEDURE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "Procedures", "PROCEDURE_NAME", null, 3 });
dt.Rows.Add(new object[] { "Procedures", "PROCEDURE_TYPE", null, 4 });
dt.Rows.Add(new object[] { "ProcedureColumns", "PROCEDURE_CAT", null, 1 });
dt.Rows.Add(new object[] { "ProcedureColumns", "PROCEDURE_SCHE", null, 2 });
dt.Rows.Add(new object[] { "ProcedureColumns", "PROCEDURE_NAME", null, 3 });
dt.Rows.Add(new object[] { "ProcedureColumns", "COLUMN_NAME", null, 4 });
dt.Rows.Add(new object[] { "ProcedureParameters", "PROCEDURE_CAT", null, 1 });
dt.Rows.Add(new object[] { "ProcedureParameters", "PROCEDURE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "ProcedureParameters", "PROCEDURE_NAME", null, 3 });
dt.Rows.Add(new object[] { "ProcedureParameters", "COLUMN_NAME", null, 4 });
dt.Rows.Add(new object[] { "SpecialColumns", "IDENTIFIER_TYPE", null, 1 });
dt.Rows.Add(new object[] { "SpecialColumns", "TABLE_CAT", null, 2 });
dt.Rows.Add(new object[] { "SpecialColumns", "TABLE_SCHEM", null, 3 });
dt.Rows.Add(new object[] { "SpecialColumns", "TABLE_NAME", null, 4 });
dt.Rows.Add(new object[] { "SpecialColumns", "SCOPE", null, 5 });
dt.Rows.Add(new object[] { "SpecialColumns", "NULLABLE", null, 6 });
dt.Rows.Add(new object[] { "TablePrivileges", "TABLE_CAT", null, 1 });
dt.Rows.Add(new object[] { "TablePrivileges", "TABLE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "TablePrivileges", "TABLE_NAME", null, 3 });
dt.Rows.Add(new object[] { "Tables", "TABLE_CAT", null, 1 });
dt.Rows.Add(new object[] { "Tables", "TABLE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "Tables", "TABLE_NAME", null, 3 });
dt.Rows.Add(new object[] { "Tables", "TABLE_TYPE", null, 4 });
dt.Rows.Add(new object[] { "Views", "TABLE_CAT", null, 1 });
dt.Rows.Add(new object[] { "Views", "TABLE_SCHEM", null, 2 });
dt.Rows.Add(new object[] { "Views", "TABLE_NAME", null, 3 });
dt.AcceptChanges();
dt.EndLoadData();
return dt;
}
private DataTable GetSchemaReservedWords()
{
// The MS ODBC provider returns a list of:
// a) all the ODBC reserved keywords listed in Appendix C
// (SQL Grammar) of the ODBC specification
// followed by
// b) the keywords returned by SQLGetInfo(SQL_KEYWORDS)
// jch TODO Needs checking for Virtuoso
StringBuilder reservedWords = new StringBuilder(SqlReservedWords);
string[] splitWords = reservedWords.ToString().Split(new Char[] { ',' });
DataTable dt = new DataTable(DbMetaDataCollectionNames.ReservedWords);
dt.Columns.Add(DbMetaDataColumnNames.ReservedWord, typeof(string));
dt.BeginLoadData();
foreach (String reservedWord in splitWords)
{
string trimmedWord;
if (!reservedWord.Equals(string.Empty) &&
(trimmedWord = reservedWord.Trim()) != "")
dt.Rows.Add(new object[] { trimmedWord });
}
dt.AcceptChanges();
dt.EndLoadData();
return dt;
}
private DataTable GetSchemaColumnPrivileges(string catalog, string schema, string table, string column)
{
DataTable dt = new DataTable("ColumnPrivileges");
StringBuilder cmdText = new StringBuilder ("select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES where ");
if (catalog != null && catalog.Length != 0)
cmdText.Append ("TABLE_CATALOG like '" + catalog + "' AND ");
if (schema != null && schema.Length != 0)
cmdText.Append ("TABLE_SCHEMA like '" + schema + "' AND ");
if (table != null && table.Length != 0)
cmdText.Append ("TABLE_NAME like '" + table + "' AND ");
if (column != null && column.Length != 0)
cmdText.Append ("COLUMN_NAME like '" + column + "' AND ");
cmdText.Append ("0 = 0");
VirtuosoCommand cmd = new VirtuosoCommand (cmdText.ToString() ,this);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
return dt;
}
private DataTable GetSchemaTablePrivileges(string catalog, string schema, string table)
{
DataTable dt = new DataTable("TablePrivileges");
StringBuilder cmdText = new StringBuilder ("select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES where ");
if (catalog != null && catalog.Length != 0)
cmdText.Append ("TABLE_CATALOG like '" + catalog + "' AND ");
if (schema != null && schema.Length != 0)
cmdText.Append ("TABLE_SCHEMA like '" + schema + "' AND ");
if (table != null && table.Length != 0)
cmdText.Append ("TABLE_NAME like '" + table + "' AND ");
cmdText.Append ("0 = 0");
VirtuosoCommand cmd = new VirtuosoCommand (cmdText.ToString() ,this);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
return dt;
}
private static String getWideColumnsText_case0 =
"SELECT " +
"charset_recode (name_part(k.KEY_TABLE,0), 'UTF-8', '_WIDE_') AS TABLE_CAT NVARCHAR(128), " +
"charset_recode (name_part(k.KEY_TABLE,1), 'UTF-8', '_WIDE_') AS TABLE_SCHEM NVARCHAR(128), " +
"charset_recode (name_part(k.KEY_TABLE,2), 'UTF-8', '_WIDE_') AS TABLE_NAME NVARCHAR(128), " +
"charset_recode (c.\"COLUMN\", 'UTF-8', '_WIDE_') AS COLUMN_NAME NVARCHAR(128), " +
"dv_to_sql_type(c.COL_DTP) AS DATA_TYPE SMALLINT, " +
"dv_type_title(c.COL_DTP) AS TYPE_NAME VARCHAR(128), " +
"c.COL_PREC AS COLUMN_SIZE INTEGER, " +
"NULL AS BUFFER_LENGTH INTEGER, " +
"c.COL_SCALE AS DECIMAL_DIGITS SMALLINT, " +
"2 AS NUM_PREC_RADIX SMALLINT, " +
"either(isnull(c.COL_NULLABLE),2,c.COL_NULLABLE) AS NULLABLE SMALLINT, " +
"NULL AS REMARKS VARCHAR(254), " +
"NULL AS COLUMN_DEF VARCHAR(128), " +
"NULL AS SQL_DATA_TYPE INTEGER, " +
"NULL AS SQL_DATETIME_SUB INTEGER, " +
"NULL AS CHAR_OCTET_LENGTH INTEGER, " +
"NULL AS ORDINAL_POSITION INTEGER, " +
"NULL AS IS_NULLABLE VARCHAR(10) " +
"FROM " +
"DB.DBA.SYS_KEYS k, " +
"DB.DBA.SYS_KEY_PARTS kp, " +
"DB.DBA.SYS_COLS c " +
"WHERE " +
"name_part(k.KEY_TABLE,0) LIKE ? " +
"AND name_part(k.KEY_TABLE,1) LIKE ? " +
"AND name_part(k.KEY_TABLE,2) LIKE ? " +
"AND c.\"COLUMN\" LIKE ? " +
"AND c.\"COLUMN\" <> '_IDN' " +
"AND k.KEY_IS_MAIN = 1 " +
"AND k.KEY_MIGRATE_TO is null " +
"AND kp.KP_KEY_ID = k.KEY_ID " +
"AND COL_ID = KP_COL " +
"ORDER BY k.KEY_TABLE, c.COL_ID";
private static String getWideColumnsText_case2 =
"SELECT " +
"charset_recode (name_part(k.KEY_TABLE,0), 'UTF-8', '_WIDE_') AS TABLE_CAT NVARCHAR(128), " +
"charset_recode (name_part(k.KEY_TABLE,1), 'UTF-8', '_WIDE_') AS TABLE_SCHEM NVARCHAR(128), " +
"charset_recode (name_part(k.KEY_TABLE,2), 'UTF-8', '_WIDE_') AS TABLE_NAME NVARCHAR(128), " +
"charset_recode (c.\"COLUMN\", 'UTF-8', '_WIDE_') AS COLUMN_NAME NVARCHAR(128), " +
"dv_to_sql_type(c.COL_DTP) AS DATA_TYPE SMALLINT," +
"dv_type_title(c.COL_DTP) AS TYPE_NAME VARCHAR(128), " +
"c.COL_PREC AS COLUMN_SIZE INTEGER, " +
"NULL AS BUFFER_LENGTH INTEGER, " +
"c.COL_SCALE AS DECIMAL_DIGITS SMALLINT," +
"2 AS NUM_PREC_RADIX SMALLINT, " +
"either(isnull(c.COL_NULLABLE),2,c.COL_NULLABLE) AS NULLABLE SMALLINT,"+
"NULL AS REMARKS VARCHAR(254), " +
"NULL AS COLUMN_DEF VARCHAR(128), " +
"NULL AS SQL_DATA_TYPE INTEGER, " +
"NULL AS SQL_DATETIME_SUB INTEGER," +
"NULL AS CHAR_OCTET_LENGTH INTEGER, " +
"NULL AS ORDINAL_POSITION INTEGER, " +
"NULL AS IS_NULLABLE VARCHAR(10) " +
"FROM " +
"DB.DBA.SYS_KEYS k, " +
"DB.DBA.SYS_KEY_PARTS kp, " +
"DB.DBA.SYS_COLS c " +
"WHERE " +
"charset_recode (upper(charset_recode (name_part(k.KEY_TABLE,0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" LIKE charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"AND charset_recode (upper(charset_recode (name_part(k.KEY_TABLE,1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" LIKE charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"AND charset_recode (upper(charset_recode (name_part(k.KEY_TABLE,2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" LIKE charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"AND charset_recode (upper (charset_recode (c.\"COLUMN\", 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" LIKE charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"AND c.\"COLUMN\" <> '_IDN' " +
"AND k.KEY_IS_MAIN = 1 " +
"AND k.KEY_MIGRATE_TO is null " +
"AND kp.KP_KEY_ID = k.KEY_ID " +
"AND COL_ID = KP_COL " +
"ORDER BY k.KEY_TABLE, c.COL_ID";
/**
* Gets a description of table columns available in
* the specified catalog.
*
* <P>Only column descriptions matching the catalog, schema, table
* and column name criteria are returned. They are ordered by
* TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
*
* <P>Each column description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be null)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>COLUMN_NAME</B> String => column name
* <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types
* <LI><B>TYPE_NAME</B> String => Data source dependent type name,
* for a UDT the type name is fully qualified
* <LI><B>COLUMN_SIZE</B> int => column size. For char or date
* types this is the maximum number of characters, for numeric or
* decimal types this is precision.
* <LI><B>BUFFER_LENGTH</B> is not used.
* <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits
* <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2)
* <LI><B>NULLABLE</B> int => is NULL allowed?
* <UL>
* <LI> columnNoNulls - might not allow NULL values
* <LI> columnNullable - definitely allows NULL values
* <LI> columnNullableUnknown - nullability unknown
* </UL>
* <LI><B>REMARKS</B> String => comment describing column (may be null)
* <LI><B>COLUMN_DEF</B> String => default value (may be null)
* <LI><B>SQL_DATA_TYPE</B> int => unused
* <LI><B>SQL_DATETIME_SUB</B> int => unused
* <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the
* maximum number of bytes in the column
* <LI><B>ORDINAL_POSITION</B> int => index of column in table
* (starting at 1)
* <LI><B>IS_NULLABLE</B> String => "NO" means column definitely
* does not allow NULL values; "YES" means the column might
* allow NULL values. An empty string means nobody knows.
* </OL>
*
* @param catalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param schemaPattern a schema name pattern; "" retrieves those
* without a schema
* @param tableNamePattern a table name pattern
* @param columnNamePattern a column name pattern
* @return ResultSet - each row is a column description
* @exception virtuoso.jdbc2.VirtuosoException if a database access error
* occurs
* @see #getSearchStringEscape
*/
private DataTable GetSchemaColumns(string catalog, string schema, string table, string column)
{
DataTable dt = new DataTable("Columns");
// Following schema mirrors System.Data.Odbc provider.
// System.Data.SqlClient provider schema differs significantly.
dt.Columns.Add("TABLE_CAT", typeof(string));
dt.Columns.Add("TABLE_SCHEM", typeof(string));
dt.Columns.Add("TABLE_NAME", typeof(string));
dt.Columns.Add("COLUMN_NAME", typeof(string));
dt.Columns.Add("DATA_TYPE", typeof(short));
dt.Columns.Add("TYPE_NAME", typeof(string));
dt.Columns.Add("COLUMN_SIZE", typeof(int));
dt.Columns.Add("BUFFER_LENGTH", typeof(int));
dt.Columns.Add("DECIMAL_DIGITS", typeof(short));
dt.Columns.Add("NUM_PREC_RADIX", typeof(short));
dt.Columns.Add("NULLABLE", typeof(short));
dt.Columns.Add("REMARKS", typeof(string));
dt.Columns.Add("COLUMN_DEF", typeof(string));
dt.Columns.Add("SQL_DATA_TYPE", typeof(short));
dt.Columns.Add("SQL_DATETIME_SUB", typeof(short));
dt.Columns.Add("CHAR_OCTET_LENGTH", typeof(int));
dt.Columns.Add("ORDINAL_POSITION", typeof(int));
dt.Columns.Add("IS_NULLABLE", typeof(string));
if(catalog == null)
catalog = "";
if(schema == null)
schema = "";
if(table == null)
table = "";
if(column == null)
column = "";
catalog = (catalog.Length == 0) ? "%" : catalog;
schema = (schema.Length == 0) ? "%" : schema;
table = (table.Length == 0) ? "%" : table;
column = (column.Length == 0) ? "%" : column;
DataTable dtColumns = new DataTable("Columns");
String cmdText;
cmdText = (innerConnection.IdentCase ==
CLI.IdentCase.SQL_IC_MIXED) ? getWideColumnsText_case2 :
getWideColumnsText_case0;
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = catalog;
p1.ParameterName = ("@catalog");
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = schema;
p2.ParameterName = ("@schema");
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = table;
p3.ParameterName = ("@table");
cmd.Parameters.Add (p3);
VirtuosoParameter p4 = (VirtuosoParameter) cmd.CreateParameter();
p4.Value = column;
p4.ParameterName = ("@column");
cmd.Parameters.Add (p4);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dtColumns.Load(reader);
return dt;
}
/* Half-way implementation by AK 12-APR-1997:
fColType must be SQL_ROWVER and fScope and fNullable are ignored.
13-APR-1997 AK Added also SQL_BEST_ROWID functionality.
Because SQLSpecialColumns should return the results as a standard
result set, ordered by SCOPE, and because SCOPE is always constant
in this implementation (0 or NULL), we can use our own additional
sorting with ORDER BY clause.
*/
private static String sql_special_columnsw1_casemode_0 =
"select" +
" 0 AS \\SCOPE SMALLINT," +
" charset_recode (SYS_COLS.\\COLUMN, 'UTF-8', '_WIDE_') AS \\COLUMN_NAME NVARCHAR(128)," /* NOT NULL */ +
" dv_to_sql_type(SYS_COLS.COL_DTP) AS \\DATA_TYPE SMALLINT,"/* NOT NULL */ +
" case when (SYS_COLS.COL_DTP in (125, 132) and get_keyword ('xml_col', coalesce (SYS_COLS.COL_OPTIONS, vector ())) is not null) then 'XMLType' else dv_type_title(SYS_COLS.COL_DTP) end AS TYPE_NAME VARCHAR(128),\n" /*DV_BLOB=125, DV_BLOB_WIDE=132 */ +
" case when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP in (125, 132)) then " + VARCHAR_UNSPEC_SIZE + " when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP = 225) then " + VARCHAR_UNSPEC_SIZE + " else SYS_COLS.COL_PREC end AS \\PRECISION INTEGER,\n" +
" SYS_COLS.COL_PREC AS \\LENGTH INTEGER," +
" SYS_COLS.COL_SCALE AS \\SCALE SMALLINT," +
" 1 AS \\PSEUDO_COLUMN SMALLINT " /* = SQL_PC_NOT_PSEUDO */ +
"from DB.DBA.SYS_KEYS SYS_KEYS, DB.DBA.SYS_KEY_PARTS SYS_KEY_PARTS," +
" DB.DBA.SYS_COLS SYS_COLS " +
" where name_part(SYS_KEYS.KEY_TABLE,0) like ?" +
" and __any_grants (KEY_TABLE) " +
" and name_part(SYS_KEYS.KEY_TABLE,1) like ?" +
" and name_part(SYS_KEYS.KEY_TABLE,2) like ?" +
" and SYS_KEYS.KEY_IS_MAIN = 1" +
" and SYS_KEYS.KEY_MIGRATE_TO is NULL" +
" and SYS_KEY_PARTS.KP_KEY_ID = SYS_KEYS.KEY_ID" +
" and SYS_KEY_PARTS.KP_NTH < SYS_KEYS.KEY_DECL_PARTS" +
" and SYS_COLS.COL_ID = SYS_KEY_PARTS.KP_COL " +
" order by SYS_KEYS.KEY_TABLE, SYS_KEY_PARTS.KP_NTH";
private static String sql_special_columnsw1_casemode_2 =
"select" +
" 0 AS \\SCOPE SMALLINT," +
" charset_recode (SYS_COLS.\\COLUMN, 'UTF-8', '_WIDE_') AS \\COLUMN_NAME NVARCHAR(128)," /* NOT NULL */ +
" dv_to_sql_type(SYS_COLS.COL_DTP) AS \\DATA_TYPE SMALLINT,"/* NOT NULL */ +
" case when (SYS_COLS.COL_DTP in (125, 132) and get_keyword ('xml_col', coalesce (SYS_COLS.COL_OPTIONS, vector ())) is not null) then 'XMLType' else dv_type_title(SYS_COLS.COL_DTP) end AS TYPE_NAME VARCHAR(128),\n" /*DV_BLOB=125, DV_BLOB_WIDE=132 */ +
" case when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP in (125, 132)) then " + VARCHAR_UNSPEC_SIZE + " when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP = 225) then " + VARCHAR_UNSPEC_SIZE + " else SYS_COLS.COL_PREC end AS \\PRECISION INTEGER,\n" +
" SYS_COLS.COL_PREC AS \\LENGTH INTEGER," +
" SYS_COLS.COL_SCALE AS \\SCALE SMALLINT," +
" 1 AS \\PSEUDO_COLUMN SMALLINT " /* = SQL_PC_NOT_PSEUDO */ +
"from DB.DBA.SYS_KEYS SYS_KEYS, DB.DBA.SYS_KEY_PARTS SYS_KEY_PARTS," +
" DB.DBA.SYS_COLS SYS_COLS " +
" where charset_recode (upper(charset_recode (name_part(SYS_KEYS.KEY_TABLE,0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and __any_grants (KEY_TABLE) " +
" and charset_recode (upper(charset_recode (name_part(SYS_KEYS.KEY_TABLE,1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper(charset_recode (name_part(SYS_KEYS.KEY_TABLE,2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and SYS_KEYS.KEY_IS_MAIN = 1" +
" and SYS_KEYS.KEY_MIGRATE_TO is NULL" +
" and SYS_KEY_PARTS.KP_KEY_ID = SYS_KEYS.KEY_ID" +
" and SYS_KEY_PARTS.KP_NTH < SYS_KEYS.KEY_DECL_PARTS" +
" and SYS_COLS.COL_ID = SYS_KEY_PARTS.KP_COL " +
" order by SYS_KEYS.KEY_TABLE, SYS_KEY_PARTS.KP_NTH";
private static String sql_special_columnsw2_casemode_0 =
"select" +
" null as \\SCOPE smallint," +
" charset_recode (\\COLUMN, 'UTF-8', '_WIDE_') as \\COLUMN_NAME nvarchar(128)," /* not null */ +
" dv_to_sql_type(COL_DTP) as \\DATA_TYPE smallint," /* not null */ +
" case when (SYS_COLS.COL_DTP in (125, 132) and get_keyword ('xml_col', coalesce (SYS_COLS.COL_OPTIONS, vector ())) is not null) then 'XMLType' else dv_type_title(SYS_COLS.COL_DTP) end AS TYPE_NAME VARCHAR(128),\n" /* DV_BLOB=125, DV_BLOB_WIDE=132 */ +
" case when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP in (125, 132)) then " + VARCHAR_UNSPEC_SIZE + " when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP = 225) then " + VARCHAR_UNSPEC_SIZE + " else SYS_COLS.COL_PREC end AS \\PRECISION INTEGER,\n" +
" COL_PREC as \\LENGTH integer," +
" COL_SCALE as \\SCALE smallint," +
" 1 as \\PSEUDO_COLUMN smallint " /* = sql_pc_not_pseudo */ +
"from DB.DBA.SYS_COLS " +
"where \\COL_DTP = 128" +
" and name_part(\\TABLE,0) like ?" +
" and name_part(\\TABLE,1) like ?" +
" and name_part(\\TABLE,2) like ? " +
"order by \\TABLE, \\COL_ID";
private static String sql_special_columnsw2_casemode_2 =
"select" +
" NULL as \\SCOPE smallint," +
" charset_recode (\\COLUMN, 'UTF-8', '_WIDE_') as \\COLUMN_NAME nvarchar(128)," /* NOT NULL */ +
" dv_to_sql_type(COL_DTP) as \\DATA_TYPE smallint," /* NOT NULL */ +
" case when (SYS_COLS.COL_DTP in (125, 132) and get_keyword ('xml_col', coalesce (SYS_COLS.COL_OPTIONS, vector ())) is not null) then 'XMLType' else dv_type_title(SYS_COLS.COL_DTP) end AS TYPE_NAME VARCHAR(128),\n" /* DV_BLOB=125, DV_BLOB_WIDE=132 */ +
" case when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP in (125, 132)) then " + VARCHAR_UNSPEC_SIZE + " when (SYS_COLS.COL_PREC = 0 and SYS_COLS.COL_DTP = 225) then " + VARCHAR_UNSPEC_SIZE + " else SYS_COLS.COL_PREC end AS \\PRECISION INTEGER,\n" +
" COL_PREC as \\LENGTH integer," +
" COL_SCALE as \\SCALE smallint," +
" 1 as \\PSEUDO_COLUMN smallint " /* = SQL_PC_NOT_PSEUDO */ +
"from DB.DBA.SYS_COLS " +
"where \\COL_DTP = 128" +
" and charset_recode (upper(charset_recode (name_part(\\TABLE,0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper(charset_recode (name_part(\\TABLE,1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper(charset_recode (name_part(\\TABLE,2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"order by \\TABLE, \\COL_ID";
private DataTable GetSchemaSpecialColumns(
string identifierType,
string catalog,
string schema,
string table,
string scope,
string nullable
)
{
if(catalog == null)
catalog = "";
if(schema == null)
schema = "";
if(table == null)
table = "";
CLI.IdentifierType _identifierType;
CLI.Scope _scope;
CLI.Nullable _nullable;
// Convert non-string restrictions from supplied string
if (String.Compare(identifierType,
SpecialColumnsRestrictions.IDENTIFIER_TYPE_BEST_ROWID) == 0)
_identifierType = CLI.IdentifierType.SQL_BEST_ROWID;
else if (String.Compare(identifierType,
SpecialColumnsRestrictions.IDENTIFIER_TYPE_ROWVER) == 0)
_identifierType = CLI.IdentifierType.SQL_ROWVER;
else
throw new ArgumentOutOfRangeException(
#if MONO
"SpecialColumnsRestrictions",
"IDENTIFIER_TYPE restriction out of range");
#else
"IDENTIFIER_TYPE restriction out of range",
(Exception) null);
#endif
if (String.Compare(scope,
SpecialColumnsRestrictions.SCOPE_CURROW) == 0)
_scope = CLI.Scope.SQL_SCOPE_CURROW;
else if (String.Compare(scope,
SpecialColumnsRestrictions.SCOPE_SESSION) == 0)
_scope = CLI.Scope.SQL_SCOPE_SESSION;
else if (String.Compare(scope,
SpecialColumnsRestrictions.SCOPE_TRANSACTION) == 0)
_scope = CLI.Scope.SQL_SCOPE_TRANSACTION;
else
throw new ArgumentOutOfRangeException(
#if MONO
"SpecialColumnsRestrictions",
"SCOPE restriction out of range");
#else
"SCOPE restriction out of range",
(Exception) null);
#endif
if (String.Compare(nullable,
SpecialColumnsRestrictions.NO_NULLS) == 0)
_nullable = CLI.Nullable.SQL_NO_NULLS;
else if (String.Compare(nullable,
SpecialColumnsRestrictions.NULLABLE) == 0)
_nullable = CLI.Nullable.SQL_NULLABLE;
else
throw new ArgumentOutOfRangeException(
#if MONO
"SpecialColumnsRestrictions",
"NULLABLE restriction out of range");
#else
"NULLABLE restriction out of range",
(Exception) null);
#endif
if (table == null || table.Trim().Length == 0)
throw new ArgumentOutOfRangeException(
#if MONO
"table",
"TABLE_NAME restriction cannot be null or empty");
#else
"TABLE_NAME restriction cannot be null or empty",
(Exception) null);
#endif
DataTable dt = new DataTable("SpecialColumns");
/*
* Comment from virtodbc implementation for SQLSpecialColumns
*/
/* fColType must be one of the following values:
SQL_BEST_ROWID: Returns the optimal column or set of columns that,
by retrieving values from the column or columns, allows any row in
the specified table to be uniquely identified. A column can be either
a pseudocolumn specifically designed for this purpose
(as in Oracle ROWID or Ingres TID) or the column or columns of any
unique index for the table.
Well, we implement this later better. Now just choose all the columns
of the primary key.
(0 = SQL_SCOPE_CURROW) Let's use the most narrow scope as I am not
really sure about this. fScope argument is
ignored anyway.
(1 = SQL_SCOPE_TRANSACTION)
(2 = SQL_SCOPE_SESSION)
*/
String cmdText;
if (_identifierType != CLI.IdentifierType.SQL_ROWVER)
{
cmdText = (innerConnection.IdentCase ==
CLI.IdentCase.SQL_IC_MIXED) ?
sql_special_columnsw1_casemode_2:
sql_special_columnsw1_casemode_0;
}
else
{
/*
fColType is SQL_ROWVER: Returns the column or columns in the
specified table, if any, that are automatically updated by the
data source when any value in the row is updated by any transaction
as in SQLBase ROWID or Sybase (and KUBL!) TIMESTAMP (= COL_DTP 128).
*/
cmdText = (innerConnection.IdentCase ==
CLI.IdentCase.SQL_IC_MIXED) ?
sql_special_columnsw2_casemode_2:
sql_special_columnsw2_casemode_0;
/* With COL_ID returns columns in the same order as they were defined
with create table. Without it they would be in alphabetical order. */
}
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = catalog;
p1.ParameterName = ("@catalog");
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = schema;
p2.ParameterName = ("@schema");
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = table;
p3.ParameterName = ("@table");
cmd.Parameters.Add (p3);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
return dt;
}
private static int SQL_INDEX_OBJECT_ID_STR = 8;
public static String sql_statistics_textw_casemode_0 =
"select" +
" charset_recode (name_part(SYS_KEYS.KEY_TABLE,0), 'UTF-8', '_WIDE_') AS \\TABLE_CAT NVARCHAR(128)," +
" charset_recode (name_part(SYS_KEYS.KEY_TABLE,1), 'UTF-8', '_WIDE_') AS \\TABLE_SCHEM NVARCHAR(128)," +
" charset_recode (name_part(SYS_KEYS.KEY_TABLE,2), 'UTF-8', '_WIDE_') AS \\TABLE_NAME NVARCHAR(128)," +/* NOT NULL */
" iszero(SYS_KEYS.KEY_IS_UNIQUE) AS \\NON_UNIQUE SMALLINT," +
" charset_recode (name_part (SYS_KEYS.KEY_TABLE, 0), 'UTF-8', '_WIDE_') AS \\INDEX_QUALIFIER NVARCHAR(128)," +
" charset_recode (name_part (SYS_KEYS.KEY_NAME, 2), 'UTF-8', '_WIDE_') AS \\INDEX_NAME NVARCHAR(128)," +
" ((SYS_KEYS.KEY_IS_OBJECT_ID*" + SQL_INDEX_OBJECT_ID_STR + ") + " +
"(3-(2*iszero(SYS_KEYS.KEY_CLUSTER_ON_ID)))) AS \\TYPE SMALLINT," + /* NOT NULL */
" (SYS_KEY_PARTS.KP_NTH+1) AS \\ORDINAL_POSITION SMALLINT," +
" charset_recode (SYS_COLS.\\COLUMN, 'UTF-8', '_WIDE_') AS \\COLUMN_NAME NVARCHAR(128)," +
" NULL AS \\ASC_OR_DESC CHAR(1)," + /* Value is either NULL, 'A' or 'D' */
" NULL AS \\CARDINALITY INTEGER," +
" NULL AS \\PAGES INTEGER," +
" NULL AS \\FILTER_CONDITION VARCHAR(128) " +
"from DB.DBA.SYS_KEYS SYS_KEYS, DB.DBA.SYS_KEY_PARTS SYS_KEY_PARTS," +
" DB.DBA.SYS_COLS SYS_COLS " +
"where name_part(SYS_KEYS.KEY_TABLE,0) like ?" +
" and __any_grants (SYS_KEYS.KEY_TABLE) " +
" and name_part(SYS_KEYS.KEY_TABLE,1) like ?" +
" and name_part(SYS_KEYS.KEY_TABLE,2) like ?" +
" and SYS_KEYS.KEY_IS_UNIQUE >= ?" +
" and SYS_KEYS.KEY_MIGRATE_TO is NULL" +
" and SYS_KEY_PARTS.KP_KEY_ID = SYS_KEYS.KEY_ID" +
" and SYS_KEY_PARTS.KP_NTH < SYS_KEYS.KEY_DECL_PARTS" +
" and SYS_COLS.COL_ID = SYS_KEY_PARTS.KP_COL" +
" and SYS_COLS.\\COLUMN <> '_IDN' " +
"order by SYS_KEYS.KEY_TABLE, SYS_KEYS.KEY_NAME, SYS_KEY_PARTS.KP_NTH";
public static String sql_statistics_textw_casemode_2 =
"select" +
" charset_recode (name_part(SYS_KEYS.KEY_TABLE,0), 'UTF-8', '_WIDE_') AS TABLE_CAT NVARCHAR(128)," +
" charset_recode (name_part(SYS_KEYS.KEY_TABLE,1), 'UTF-8', '_WIDE_') AS \\TABLE_SCHEM NVARCHAR(128)," +
" charset_recode (name_part(SYS_KEYS.KEY_TABLE,2), 'UTF-8', '_WIDE_') AS \\TABLE_NAME NVARCHAR(128)," + /* NOT NULL */
" iszero(SYS_KEYS.KEY_IS_UNIQUE) AS \\NON_UNIQUE SMALLINT," +
" charset_recode (name_part (SYS_KEYS.KEY_TABLE, 0), 'UTF-8', '_WIDE_') AS \\INDEX_QUALIFIER NVARCHAR(128)," +
" charset_recode (name_part (SYS_KEYS.KEY_NAME, 2), 'UTF-8', '_WIDE_') AS \\INDEX_NAME NVARCHAR(128)," +
" ((SYS_KEYS.KEY_IS_OBJECT_ID*" + SQL_INDEX_OBJECT_ID_STR + ") + " +
"(3-(2*iszero(SYS_KEYS.KEY_CLUSTER_ON_ID)))) AS \\TYPE SMALLINT," + /* NOT NULL */
" (SYS_KEY_PARTS.KP_NTH+1) AS \\ORDINAL_POSITION SMALLINT," +
" charset_recode (SYS_COLS.\\COLUMN, 'UTF-8', '_WIDE_') AS \\COLUMN_NAME NVARCHAR(128)," +
" NULL AS \\ASC_OR_DESC CHAR(1)," + /* Value is either NULL, 'A' or 'D' */
" NULL AS \\CARDINALITY INTEGER," +
" NULL AS \\PAGES INTEGER," +
" NULL AS \\FILTER_CONDITION VARCHAR(128) " +
"from DB.DBA.SYS_KEYS SYS_KEYS, DB.DBA.SYS_KEY_PARTS SYS_KEY_PARTS," +
" DB.DBA.SYS_COLS SYS_COLS " +
"where charset_recode (upper(charset_recode (name_part(SYS_KEYS.KEY_TABLE,0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and __any_grants (SYS_KEYS.KEY_TABLE) " +
" and charset_recode (upper(charset_recode (name_part(SYS_KEYS.KEY_TABLE,1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper(charset_recode (name_part(SYS_KEYS.KEY_TABLE,2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and SYS_KEYS.KEY_IS_UNIQUE >= ?" +
" and SYS_KEYS.KEY_MIGRATE_TO is NULL" +
" and SYS_KEY_PARTS.KP_KEY_ID = SYS_KEYS.KEY_ID" +
" and SYS_KEY_PARTS.KP_NTH < SYS_KEYS.KEY_DECL_PARTS" +
" and SYS_COLS.COL_ID = SYS_KEY_PARTS.KP_COL" +
" and SYS_COLS.\\COLUMN <> '_IDN' " +
"order by SYS_KEYS.KEY_TABLE, SYS_KEYS.KEY_NAME, SYS_KEY_PARTS.KP_NTH";
/**
* Gets a description of a table's indices and statistics. They are
* ordered by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION.
*
* <P>Each index column description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be null)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>NON_UNIQUE</B> boolean => Can index values be non-unique?
* false when TYPE is tableIndexStatistic
* <LI><B>INDEX_QUALIFIER</B> String => index catalog (may be null);
* null when TYPE is tableIndexStatistic
* <LI><B>INDEX_NAME</B> String => index name; null when TYPE is
* tableIndexStatistic
* <LI><B>TYPE</B> short => index type:
* <UL>
* <LI> tableIndexStatistic - this identifies table statistics that
* are
* returned in conjunction with a table's index descriptions
* <LI> tableIndexClustered - this is a clustered index
* <LI> tableIndexHashed - this is a hashed index
* <LI> tableIndexOther - this is some other style of index
* </UL>
* <LI><B>ORDINAL_POSITION</B> short => column sequence number
* within index; zero when TYPE is tableIndexStatistic
* <LI><B>COLUMN_NAME</B> String => column name; null when TYPE is
* tableIndexStatistic
* <LI><B>ASC_OR_DESC</B> String => column sort sequence, "A" =>
* ascending,
* "D" => descending, may be null if sort sequence is not supported;
* null when TYPE is tableIndexStatistic
* <LI><B>CARDINALITY</B> int => When TYPE is tableIndexStatistic, then
* this is the number of rows in the table; otherwise, it is the
* number of unique values in the index.
* <LI><B>PAGES</B> int => When TYPE is tableIndexStatistic then
* this is the number of pages used for the table, otherwise it
* is the number of pages used for the current index.
* <LI><B>FILTER_CONDITION</B> String => Filter condition, if any.
* (may be null)
* </OL>
*
* @param catalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param schema a schema name; "" retrieves those without a schema
* @param table a table name
* @param unique when true, return only indices for unique values;
* when false, return indices regardless of whether unique or not
* @param approximate when true, result is allowed to reflect approximate
* or out of data values; when false, results are requested to be
* accurate
* @return ResultSet - each row is an index column description
* @exception virtuoso.jdbc2.VirtuosoException if a database access error
* occurs
*/
private DataTable GetSchemaIndexes(string catalog, string schema, string table, string index)
{
DataTable dt = new DataTable("Indexes");
if(catalog == null)
catalog = "";
if(schema == null)
schema = "";
if(table == null)
table = "";
catalog = catalog == "" ? "%" : catalog;
schema = schema == "" ? "%" : schema;
table = table == "" ? "%" : table;
String cmdText;
cmdText = (innerConnection.IdentCase ==
CLI.IdentCase.SQL_IC_MIXED) ?
sql_statistics_textw_casemode_2:
sql_statistics_textw_casemode_0;
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = catalog;
p1.ParameterName = ("@catalog");
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = schema;
p2.ParameterName = ("@schema");
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = table;
p3.ParameterName = ("@table");
cmd.Parameters.Add (p3);
VirtuosoParameter p4 = (VirtuosoParameter) cmd.CreateParameter();
p4.Value = CLI.IndexType.SQL_INDEX_ALL;
p4.ParameterName = ("@unique");
cmd.Parameters.Add (p4);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
DataTable dtSqlStats = new DataTable("SQLStatistics");
dtSqlStats.Load(reader);
// Filter on any index restriction and exclude SQL_TABLE_STAT rows
string indexFilter = "";
if (index != null && index.Trim().Length > 0)
indexFilter = " AND INDEX_NAME LIKE '" + index + "'";
DataView dv = dtSqlStats.DefaultView;
dv.RowFilter = "TYPE <> 0" + indexFilter;
dt = dv.ToTable();
return dt;
}
private static String getWideProceduresCaseMode0 =
"SELECT " +
"charset_recode (name_part (\\P_NAME, 0), 'UTF-8', '_WIDE_') AS PROCEDURE_CAT NVARCHAR(128)," +
"charset_recode (name_part (\\P_NAME, 1), 'UTF-8', '_WIDE_') AS PROCEDURE_SCHEM NVARCHAR(128)," +
"charset_recode (name_part (\\P_NAME, 2), 'UTF-8', '_WIDE_') AS PROCEDURE_NAME NVARCHAR(128)," +
"\\P_N_IN AS RES1," +
"\\P_N_OUT AS RES2," +
"\\P_N_R_SETS AS RES3," +
"\\P_COMMENT AS REMARKS VARCHAR(254)," +
"either(isnull(P_TYPE),0,P_TYPE) AS PROCEDURE_TYPE SMALLINT " +
"FROM DB.DBA.SYS_PROCEDURES " +
"WHERE " +
"name_part (\\P_NAME, 0) like ? AND " +
"name_part (\\P_NAME, 1) like ? AND " +
"name_part (\\P_NAME, 2) like ? AND " +
"__proc_exists (\\P_NAME) is not null " +
"ORDER BY P_QUAL, P_NAME";
private static String getWideProceduresCaseMode2 =
"SELECT " +
"charset_recode (name_part (\\P_NAME, 0), 'UTF-8', '_WIDE_') AS PROCEDURE_CAT NVARCHAR(128)," +
"charset_recode (name_part (\\P_NAME, 1), 'UTF-8', '_WIDE_') AS PROCEDURE_SCHEM NVARCHAR(128)," +
"charset_recode (name_part (\\P_NAME, 2), 'UTF-8', '_WIDE_') AS PROCEDURE_NAME NVARCHAR(128)," +
"\\P_N_IN AS RES1," +
"\\P_N_OUT AS RES2," +
"\\P_N_R_SETS AS RES3," +
"\\P_COMMENT AS REMARKS VARCHAR(254)," +
"either(isnull(P_TYPE),0,P_TYPE) AS PROCEDURE_TYPE SMALLINT " +
"FROM DB.DBA.SYS_PROCEDURES " +
"WHERE " +
"charset_recode (upper (charset_recode (name_part (\\P_NAME, 0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') AND " +
"charset_recode (upper (charset_recode (name_part (\\P_NAME, 1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') AND " +
"charset_recode (upper (charset_recode (name_part (\\P_NAME, 2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" like charset_recode (upper(charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') AND " +
"__proc_exists (\\P_NAME) is not null " +
"ORDER BY P_QUAL, P_NAME";
/**
* Gets a description of the stored procedures available in a
* catalog.
*
* <P>Only procedure descriptions matching the schema and
* procedure name criteria are returned. They are ordered by
* PROCEDURE_SCHEM, and PROCEDURE_NAME.
*
* <P>Each procedure description has the following columns:
* <OL>
* <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be null)
* <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be null)
* <LI><B>PROCEDURE_NAME</B> String => procedure name
* <LI> reserved for future use
* <LI> reserved for future use
* <LI> reserved for future use
* <LI><B>REMARKS</B> String => explanatory comment on the procedure
* <LI><B>PROCEDURE_TYPE</B> short => kind of procedure:
* <UL>
* <LI> procedureResultUnknown - May return a result
* <LI> procedureNoResult - Does not return a result
* <LI> procedureReturnsResult - Returns a result
* </UL>
* </OL>
*
* @param catalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param schemaPattern a schema name pattern; "" retrieves those
* without a schema
* @param procedureNamePattern a procedure name pattern
* @return ResultSet - each row is a procedure description
* @exception virtuoso.jdbc2.VirtuosoException if a database access error
* occurs
* @see #getSearchStringEscape
*/
private DataTable GetSchemaProcedures(string catalog, string schema, string procedure, string type)
{
CLI.ProcedureType procType = CLI.ProcedureType.SQL_PT_UNKNOWN;
if (type != null && type.Trim().Length > 0)
{
try
{
procType = (CLI.ProcedureType)Int32.Parse(type);
}
catch
{
throw new ArgumentOutOfRangeException("The string received for a PROCEDURE_TYPE restriction must " +
"parse to one of the following integer values: SQL_PT_UNKNOWN(0), SQL_PT_PROCEDURE(1) or " +
"SQL_PT_FUNCTION(2)");
}
}
if(catalog == null)
catalog = "%";
if(schema == null)
schema = "%";
if(procedure == null)
procedure = "%";
DataTable dt = new DataTable("Procedures");
String cmdText;
cmdText = innerConnection.IdentCase == CLI.IdentCase.SQL_IC_MIXED ?
getWideProceduresCaseMode2 :
getWideProceduresCaseMode0;
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = catalog;
p1.ParameterName = ("@catalog");
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = schema;
p2.ParameterName = ("@schema");
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = procedure;
p3.ParameterName = ("@procedure");
cmd.Parameters.Add (p3);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
// Filter on the 'type' restriction here.
// The underlying SQLProcedures call doesn't support this.
if (procType != CLI.ProcedureType.SQL_PT_UNKNOWN)
{
foreach (DataRow dr in dt.Rows)
{
if (dr[7] != null)
{
int iProcType = Int32.Parse(dr[7].ToString());
if (iProcType != (int)CLI.ProcedureType.SQL_PT_UNKNOWN &&
iProcType != (int)procType)
dt.Rows.Remove (dr);
}
}
}
dt.AcceptChanges();
return dt;
}
private static String get_wide_pk_case0 =
"SELECT " +
"charset_recode (name_part(v1.KEY_TABLE,0), 'UTF-8', '_WIDE_') AS \\TABLE_CAT NVARCHAR(128), " +
"charset_recode (name_part(v1.KEY_TABLE,1), 'UTF-8', '_WIDE_') AS \\TABLE_SCHEM NVARCHAR(128), " +
"charset_recode (name_part(v1.KEY_TABLE,2), 'UTF-8', '_WIDE_') AS \\TABLE_NAME NVARCHAR(128), " +
"charset_recode (DB.DBA.SYS_COLS.\"COLUMN\", 'UTF-8', '_WIDE_') AS \\COLUMN_NAME NVARCHAR(128), " +
"(kp.KP_NTH+1) AS \\KEY_SEQ SMALLINT, " +
"charset_recode (name_part (v1.KEY_NAME, 2), 'UTF-8', '_WIDE_') AS \\PK_NAME VARCHAR(128) " +
"FROM " +
"DB.DBA.SYS_KEYS v1, " +
"DB.DBA.SYS_KEYS v2, " +
"DB.DBA.SYS_KEY_PARTS kp, " +
"DB.DBA.SYS_COLS " +
"WHERE " +
"name_part(v1.KEY_TABLE,0) LIKE ? " +
"AND name_part(v1.KEY_TABLE,1) LIKE ? " +
"AND name_part(v1.KEY_TABLE,2) LIKE ? " +
"AND __any_grants (v1.KEY_TABLE) " +
"AND v1.KEY_IS_MAIN = 1 " +
"AND v1.KEY_MIGRATE_TO is NULL " +
"AND v1.KEY_SUPER_ID = v2.KEY_ID " +
"AND kp.KP_KEY_ID = v1.KEY_ID " +
"AND kp.KP_NTH < v1.KEY_DECL_PARTS " +
"AND DB.DBA.SYS_COLS.COL_ID = kp.KP_COL " +
"AND DB.DBA.SYS_COLS.\"COLUMN\" <> '_IDN' " +
"ORDER BY v1.KEY_TABLE, kp.KP_NTH";
private static String get_wide_pk_case2 =
"SELECT " +
"charset_recode (name_part(v1.KEY_TABLE,0), 'UTF-8', '_WIDE_') AS \\TABLE_CAT NVARCHAR(128), " +
"charset_recode (name_part(v1.KEY_TABLE,1), 'UTF-8', '_WIDE_') AS \\TABLE_SCHEM NVARCHAR(128), " +
"charset_recode (name_part(v1.KEY_TABLE,2), 'UTF-8', '_WIDE_') AS \\TABLE_NAME NVARCHAR(128), " +
"charset_recode (DB.DBA.SYS_COLS.\"COLUMN\", 'UTF-8', '_WIDE_') AS \\COLUMN_NAME NVARCHAR(128), " +
"(kp.KP_NTH+1) AS \\KEY_SEQ SMALLINT, " +
"charset_recode (name_part (v1.KEY_NAME, 2), 'UTF-8', '_WIDE_') AS \\PK_NAME VARCHAR(128) " +
"FROM " +
"DB.DBA.SYS_KEYS v1, " +
"DB.DBA.SYS_KEYS v2, " +
"DB.DBA.SYS_KEY_PARTS kp, " +
"DB.DBA.SYS_COLS " +
"WHERE " +
"charset_recode (upper (charset_recode (name_part(v1.KEY_TABLE,0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')"+
" LIKE charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"AND charset_recode (upper (charset_recode (name_part(v1.KEY_TABLE,1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" LIKE charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"AND charset_recode (upper (charset_recode (name_part(v1.KEY_TABLE,2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" LIKE charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"AND __any_grants (v1.KEY_TABLE) " +
"AND v1.KEY_IS_MAIN = 1 " +
"AND v1.KEY_MIGRATE_TO is NULL " +
"AND v1.KEY_SUPER_ID = v2.KEY_ID " +
"AND kp.KP_KEY_ID = v1.KEY_ID " +
"AND kp.KP_NTH < v1.KEY_DECL_PARTS " +
"AND DB.DBA.SYS_COLS.COL_ID = kp.KP_COL " +
"AND DB.DBA.SYS_COLS.\"COLUMN\" <> '_IDN' " +
"ORDER BY v1.KEY_TABLE, kp.KP_NTH";
/**
* Gets a description of a table's primary key columns. They
* are ordered by COLUMN_NAME.
*
* <P>Each primary key column description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be null)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>COLUMN_NAME</B> String => column name
* <LI><B>KEY_SEQ</B> short => sequence number within primary key
* <LI><B>PK_NAME</B> String => primary key name (may be null)
* </OL>
*
* @param catalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param schema a schema name; "" retrieves those
* without a schema
* @param table a table name
* @return ResultSet - each row is a primary key column description
* @exception virtuoso.jdbc2.VirtuosoException if a database access error
* occurs
*/
private DataTable GetSchemaPrimaryKeys(string catalog, string schema, string table)
{
DataTable dt = new DataTable("PrimaryKeys");
if(catalog == null)
catalog = "";
if(schema == null)
schema = "";
if(table == null)
table = "";
catalog = catalog == "" ? "%" : catalog;
schema = schema == "" ? "%" : schema;
table = table == "" ? "%" : table;
String cmdText;
cmdText = innerConnection.IdentCase == CLI.IdentCase.SQL_IC_MIXED ?
get_wide_pk_case2 :
get_wide_pk_case0;
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = catalog;
p1.ParameterName = ("@catalog");
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = schema;
p2.ParameterName = ("@schema");
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = table;
p3.ParameterName = ("@table");
cmd.Parameters.Add (p3);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
return dt;
}
private DataTable GetSchemaProcedureColumns(string catalog, string schema, string procedure, string column)
{
DataTable dt = new DataTable("ProcedureColumns");
// Following schema mirrors System.Data.Odbc provider.
dt.Columns.Add("PROCEDURE_CAT", typeof(string));
dt.Columns.Add("PROCEDURE_SCHEM", typeof(string));
dt.Columns.Add("PROCEDURE_NAME", typeof(string));
dt.Columns.Add("COLUMN_NAME", typeof(string));
dt.Columns.Add("COLUMN_TYPE", typeof(short));
dt.Columns.Add("DATA_TYPE", typeof(short));
dt.Columns.Add("TYPE_NAME", typeof(string));
dt.Columns.Add("COLUMN_SIZE", typeof(int));
dt.Columns.Add("BUFFER_LENGTH", typeof(int));
dt.Columns.Add("DECIMAL_DIGITS", typeof(short));
dt.Columns.Add("NUM_PREC_RADIX", typeof(short));
dt.Columns.Add("NULLABLE", typeof(short));
dt.Columns.Add("REMARKS", typeof(string));
dt.Columns.Add("COLUMN_DEF", typeof(string));
dt.Columns.Add("SQL_DATA_TYPE", typeof(short));
dt.Columns.Add("SQL_DATETIME_SUB", typeof(short));
dt.Columns.Add("CHAR_OCTET_LENGTH", typeof(int));
dt.Columns.Add("ORDINAL_POSITION", typeof(int));
dt.Columns.Add("IS_NULLABLE", typeof(string));
if(catalog == null)
catalog = "%";
if(schema == null)
schema = "%";
if(procedure == null)
procedure = "%";
if(column == null)
column = "%";
string cmdText = "DB.DBA.SQL_PROCEDURE_COLUMNSW (?, ?, ?, ?, ?, ?)";
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = catalog;
p1.ParameterName = ("@catalog");
p1.DbType = DbType.AnsiString;
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = schema;
p2.ParameterName = ("@schema");
p2.DbType = DbType.AnsiString;
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = procedure;
p3.ParameterName = ("@procedure");
p3.DbType = DbType.AnsiString;
cmd.Parameters.Add (p3);
VirtuosoParameter p4 = (VirtuosoParameter) cmd.CreateParameter();
p4.Value = (column);
p4.ParameterName = ("@column");
p4.DbType = DbType.AnsiString;
cmd.Parameters.Add (p4);
VirtuosoParameter p5 = (VirtuosoParameter) cmd.CreateParameter();
if (innerConnection.IdentCase == CLI.IdentCase.SQL_IC_MIXED)
p5.Value = 2;
else if (innerConnection.IdentCase == CLI.IdentCase.SQL_IC_UPPER)
p5.Value = 1;
else
p5.Value = 0;
p5.ParameterName = ("@case");
cmd.Parameters.Add (p5);
VirtuosoParameter p6 = (VirtuosoParameter) cmd.CreateParameter();
p6.Value = 1;
p6.ParameterName = ("@isODBC3");
cmd.Parameters.Add (p6);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
// The MS Odbc provider supports both ProcedureColumns and
// ProcedureParameters metadata collections. This provider
// does likewise. Filter the output on COLUMN_TYPE to
// differentiate these two metadata collections.
foreach (DataRow dr in dt.Rows)
{
if (dr[4] != null)
{
short colType = Int16.Parse(dr[4].ToString());
if (colType != (short)CLI.InOutType.SQL_RESULT_COL)
dr.Delete();
}
}
dt.AcceptChanges();
return dt;
}
private DataTable GetSchemaProcedureParameters(string catalog, string schema, string procedure, string column)
{
DataTable dt = new DataTable("ProcedureParameters");
// Following schema mirrors System.Data.Odbc provider.
dt.Columns.Add("PROCEDURE_CAT", typeof(string));
dt.Columns.Add("PROCEDURE_SCHEM", typeof(string));
dt.Columns.Add("PROCEDURE_NAME", typeof(string));
dt.Columns.Add("COLUMN_NAME", typeof(string));
dt.Columns.Add("COLUMN_TYPE", typeof(short));
dt.Columns.Add("DATA_TYPE", typeof(short));
dt.Columns.Add("TYPE_NAME", typeof(string));
dt.Columns.Add("COLUMN_SIZE", typeof(int));
dt.Columns.Add("BUFFER_LENGTH", typeof(int));
dt.Columns.Add("DECIMAL_DIGITS", typeof(short));
dt.Columns.Add("NUM_PREC_RADIX", typeof(short));
dt.Columns.Add("NULLABLE", typeof(short));
dt.Columns.Add("REMARKS", typeof(string));
dt.Columns.Add("COLUMN_DEF", typeof(string));
dt.Columns.Add("SQL_DATA_TYPE", typeof(short));
dt.Columns.Add("SQL_DATETIME_SUB", typeof(short));
dt.Columns.Add("CHAR_OCTET_LENGTH", typeof(int));
dt.Columns.Add("ORDINAL_POSITION", typeof(int));
dt.Columns.Add("IS_NULLABLE", typeof(string));
if(catalog == null)
catalog = "%";
if(schema == null)
schema = "%";
if(procedure == null)
procedure = "%";
if(column == null)
column = "%";
string cmdText = "DB.DBA.SQL_PROCEDURE_COLUMNSW (?, ?, ?, ?, ?, ?)";
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
// Arguments to SQL_PROCEDURE_COLUMNSW must be narrow so change
// the parameter type to AnsiString
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = catalog;
p1.ParameterName = ("@catalog");
p1.DbType = DbType.AnsiString;
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = schema;
p2.ParameterName = ("@schema");
p2.DbType = DbType.AnsiString;
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = procedure;
p3.ParameterName = ("@procedure");
p3.DbType = DbType.AnsiString;
cmd.Parameters.Add (p3);
VirtuosoParameter p4 = (VirtuosoParameter) cmd.CreateParameter();
p4.Value = column;
p4.ParameterName = ("@column");
p4.DbType = DbType.AnsiString;
cmd.Parameters.Add (p4);
VirtuosoParameter p5 = (VirtuosoParameter) cmd.CreateParameter();
if (innerConnection.IdentCase == CLI.IdentCase.SQL_IC_MIXED)
p5.Value = 2;
else if (innerConnection.IdentCase == CLI.IdentCase.SQL_IC_UPPER)
p5.Value = 1;
else
p5.Value = 0;
p5.ParameterName = ("@case");
cmd.Parameters.Add (p5);
VirtuosoParameter p6 = (VirtuosoParameter) cmd.CreateParameter();
p6.Value = 1;
p6.ParameterName = ("@isODBC3");
cmd.Parameters.Add (p6);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
// The MS Odbc provider supports both ProcedureColumns and
// ProcedureParameters metadata collections. This provider
// does likewise. Filter the output on COLUMN_TYPE to
// differentiate these two metadata collections.
foreach (DataRow dr in dt.Rows)
{
if (dr[4] != null)
{
short colType = Int16.Parse(dr[4].ToString());
if (colType == (short)CLI.InOutType.SQL_RESULT_COL)
dr.Delete();
}
}
dt.AcceptChanges();
return dt;
}
private DataTable GetSchemaTables(string catalog, string schema, string table, string types)
{
DataTable dt = new DataTable("Tables");
StringBuilder cmdText = new StringBuilder ("select TABLE_CATALOG as TABLE_CAT, TABLE_SCHEMA as TABLE_SCHEM, TABLE_NAME, TABLE_TYPE from INFORMATION_SCHEMA.TABLES where ");
if (catalog != null && catalog.Length != 0)
cmdText.Append ("TABLE_CATALOG like '" + catalog + "' AND ");
if (schema != null && schema.Length != 0)
cmdText.Append ("TABLE_SCHEMA like '" + schema + "' AND ");
if (table != null && table.Length != 0)
cmdText.Append ("TABLE_NAME like '" + table + "' AND ");
if (types != null && types.Length != 0)
cmdText.Append ("TABLE_TYPE like '**" + types + "' AND ");
cmdText.Append ("0 = 0");
VirtuosoCommand cmd = new VirtuosoCommand (cmdText.ToString() ,this);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
return dt;
}
private DataTable GetSchemaViews(string catalog, string schema, string view)
{
DataTable dt = new DataTable("Views");
StringBuilder cmdText = new StringBuilder ("select TABLE_CATALOG as TABLE_CAT, TABLE_SCHEMA as TABLE_SCHEM, TABLE_NAME, 'VIEW' as TABLE_TYPE from INFORMATION_SCHEMA.VIEWS where ");
if (catalog != null && catalog.Length != 0)
cmdText.Append ("TABLE_CATALOG like '" + catalog + "' AND ");
if (schema != null && schema.Length != 0)
cmdText.Append ("TABLE_SCHEMA like '" + schema + "' AND ");
if (view != null && view.Length != 0)
cmdText.Append ("TABLE_NAME like '" + view + "' AND ");
cmdText.Append ("0 = 0");
VirtuosoCommand cmd = new VirtuosoCommand (cmdText.ToString() ,this);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
return dt;
}
public static String fk_textw_casemode_0 =
"select" +
" charset_recode (name_part (PK_TABLE, 0), 'UTF-8', '_WIDE_') as PKTABLE_CAT nvarchar (128)," +
" charset_recode (name_part (PK_TABLE, 1), 'UTF-8', '_WIDE_') as PKTABLE_SCHEM nvarchar (128)," +
" charset_recode (name_part (PK_TABLE, 2), 'UTF-8', '_WIDE_') as PKTABLE_NAME nvarchar (128)," +
" charset_recode (PKCOLUMN_NAME, 'UTF-8', '_WIDE_') as PKCOLUMN_NAME nvarchar (128)," +
" charset_recode (name_part (FK_TABLE, 0), 'UTF-8', '_WIDE_') as FKTABLE_CAT nvarchar (128)," +
" charset_recode (name_part (FK_TABLE, 1), 'UTF-8', '_WIDE_') as FKTABLE_SCHEM nvarchar (128)," +
" charset_recode (name_part (FK_TABLE, 2), 'UTF-8', '_WIDE_') as FKTABLE_NAME nvarchar (128)," +
" charset_recode (FKCOLUMN_NAME, 'UTF-8', '_WIDE_') as FKCOLUMN_NAME nvarchar (128)," +
" (KEY_SEQ + 1) as KEY_SEQ SMALLINT," +
" (case UPDATE_RULE when 0 then 3 when 1 then 0 when 3 then 4 end) as UPDATE_RULE smallint," +
" (case DELETE_RULE when 0 then 3 when 1 then 0 when 3 then 4 end) as DELETE_RULE smallint," +
" charset_recode (FK_NAME, 'UTF-8', '_WIDE_') as FK_NAME nvarchar (128)," +
" charset_recode (PK_NAME, 'UTF-8', '_WIDE_') as PK_NAME nvarchar (128), "+
" NULL as DEFERRABILITY " +
"from DB.DBA.SYS_FOREIGN_KEYS SYS_FOREIGN_KEYS " +
"where name_part (PK_TABLE, 0) like ?" +
" and name_part (PK_TABLE, 1) like ?" +
" and name_part (PK_TABLE, 2) like ?" +
" and name_part (FK_TABLE, 0) like ?" +
" and name_part (FK_TABLE, 1) like ?" +
" and name_part (FK_TABLE, 2) like ? " +
"order by 1, 2, 3, 5, 6, 7, 9";
public static String fk_textw_casemode_2 =
"select" +
" charset_recode (name_part (PK_TABLE, 0), 'UTF-8', '_WIDE_') as PKTABLE_CAT nvarchar (128)," +
" charset_recode (name_part (PK_TABLE, 1), 'UTF-8', '_WIDE_') as PKTABLE_SCHEM nvarchar (128)," +
" charset_recode (name_part (PK_TABLE, 2), 'UTF-8', '_WIDE_') as PKTABLE_NAME nvarchar (128)," +
" charset_recode (PKCOLUMN_NAME, 'UTF-8', '_WIDE_') as PKCOLUMN_NAME nvarchar (128)," +
" charset_recode (name_part (FK_TABLE, 0), 'UTF-8', '_WIDE_') as FKTABLE_CAT nvarchar (128)," +
" charset_recode (name_part (FK_TABLE, 1), 'UTF-8', '_WIDE_') as FKTABLE_SCHEM nvarchar (128)," +
" charset_recode (name_part (FK_TABLE, 2), 'UTF-8', '_WIDE_') as FKTABLE_NAME nvarchar (128)," +
" charset_recode (FKCOLUMN_NAME, 'UTF-8', '_WIDE_') as FKCOLUMN_NAME nvarchar (128)," +
" (KEY_SEQ + 1) as KEY_SEQ SMALLINT," +
" (case UPDATE_RULE when 0 then 3 when 1 then 0 when 3 then 4 end) as UPDATE_RULE smallint," +
" (case DELETE_RULE when 0 then 3 when 1 then 0 when 3 then 4 end) as DELETE_RULE smallint," +
" charset_recode (FK_NAME, 'UTF-8', '_WIDE_') as FK_NAME nvarchar (128)," +
" charset_recode (PK_NAME, 'UTF-8', '_WIDE_') as PK_NAME nvarchar (128),"+
" NULL as DEFERRABILITY " +
"from DB.DBA.SYS_FOREIGN_KEYS SYS_FOREIGN_KEYS " +
"where charset_recode (upper (charset_recode (name_part (PK_TABLE, 0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper (charset_recode (name_part (PK_TABLE, 1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper (charset_recode (name_part (PK_TABLE, 2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper (charset_recode (name_part (FK_TABLE, 0), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper (charset_recode (name_part (FK_TABLE, 1), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8')" +
" and charset_recode (upper (charset_recode (name_part (FK_TABLE, 2), 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') like charset_recode (upper (charset_recode (?, 'UTF-8', '_WIDE_')), '_WIDE_', 'UTF-8') " +
"order by 1, 2, 3, 5, 6, 7, 9";
/**
* Gets a description of the foreign key columns in the foreign key
* table that reference the primary key columns of the primary key
* table (describe how one table imports another's key.) This
* should normally return a single foreign key/primary key pair
* (most tables only import a foreign key from a table once.) They
* are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and
* KEY_SEQ.
*
* <P>Each foreign key column description has the following columns:
* <OL>
* <LI><B>PKTABLE_CAT</B> String => primary key table catalog (may be
* null)
* <LI><B>PKTABLE_SCHEM</B> String => primary key table schema (may be
* null)
* <LI><B>PKTABLE_NAME</B> String => primary key table name
* <LI><B>PKCOLUMN_NAME</B> String => primary key column name
* <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be
* null)
* being exported (may be null)
* <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be
* null)
* being exported (may be null)
* <LI><B>FKTABLE_NAME</B> String => foreign key table name
* being exported
* <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
* being exported
* <LI><B>KEY_SEQ</B> short => sequence number within foreign key
* <LI><B>UPDATE_RULE</B> short => What happens to
* foreign key when primary is updated:
* <UL>
* <LI> importedNoAction - do not allow update of primary
* key if it has been imported
* <LI> importedKeyCascade - change imported key to agree
* with primary key update
* <LI> importedKeySetNull - change imported key to NULL if
* its primary key has been updated
* <LI> importedKeySetDefault - change imported key to default values
* if its primary key has been updated
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* </UL>
* <LI><B>DELETE_RULE</B> short => What happens to
* the foreign key when primary is deleted.
* <UL>
* <LI> importedKeyNoAction - do not allow delete of primary
* key if it has been imported
* <LI> importedKeyCascade - delete rows that import a deleted key
* <LI> importedKeySetNull - change imported key to NULL if
* its primary key has been deleted
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* <LI> importedKeySetDefault - change imported key to default if
* its primary key has been deleted
* </UL>
* <LI><B>FK_NAME</B> String => foreign key name (may be null)
* <LI><B>PK_NAME</B> String => primary key name (may be null)
* <LI><B>DEFERRABILITY</B> short => can the evaluation of foreign key
* constraints be deferred until commit
* <UL>
* <LI> importedKeyInitiallyDeferred - see SQL92 for definition
* <LI> importedKeyInitiallyImmediate - see SQL92 for definition
* <LI> importedKeyNotDeferrable - see SQL92 for definition
* </UL>
* </OL>
*
* @param primaryCatalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param primarySchema a schema name; "" retrieves those
* without a schema
* @param primaryTable the table name that exports the key
* @param foreignCatalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param foreignSchema a schema name; "" retrieves those
* without a schema
* @param foreignTable the table name that imports the key
* @return ResultSet - each row is a foreign key column description
* @exception virtuoso.jdbc2.VirtuosoException if a database access error
* occurs
* @see #getImportedKeys
*/
private DataTable GetSchemaForeignKeys(
string pkCatalog, string pkSchema, string pkTable,
string fkCatalog, string fkSchema, string fkTable)
{
DataTable dt = new DataTable("ForeignKeys");
if(pkCatalog == null)
pkCatalog = "";
if(pkSchema == null)
pkSchema = "";
if(pkTable == null)
pkTable = "";
if(fkCatalog == null)
fkCatalog = "";
if(fkSchema == null)
fkSchema = "";
if(fkTable == null)
fkTable = "";
pkCatalog = pkCatalog == "" ? "%" : pkCatalog;
pkSchema = pkSchema == "" ? "%" : pkSchema;
pkTable = pkTable == "" ? "%" : pkTable;
fkCatalog = fkCatalog == "" ? "%" : fkCatalog;
fkSchema = fkSchema == "" ? "%" : fkSchema;
fkTable = fkTable == "" ? "%" : fkTable;
String cmdText;
cmdText = innerConnection.IdentCase == CLI.IdentCase.SQL_IC_MIXED ?
fk_textw_casemode_2 :
fk_textw_casemode_0;
VirtuosoCommand cmd = new VirtuosoCommand(cmdText ,this);
VirtuosoParameter p1 = (VirtuosoParameter) cmd.CreateParameter();
p1.Value = pkCatalog;
p1.ParameterName = ("@pkCatalog");
cmd.Parameters.Add (p1);
VirtuosoParameter p2 = (VirtuosoParameter) cmd.CreateParameter();
p2.Value = pkSchema;
p2.ParameterName = ("@pkSchema");
cmd.Parameters.Add (p2);
VirtuosoParameter p3 = (VirtuosoParameter) cmd.CreateParameter();
p3.Value = pkTable;
p3.ParameterName = ("@pkTable");
cmd.Parameters.Add (p3);
VirtuosoParameter p4 = (VirtuosoParameter) cmd.CreateParameter();
p4.Value = fkCatalog;
p4.ParameterName = ("@fkCatalog");
cmd.Parameters.Add (p4);
VirtuosoParameter p5 = (VirtuosoParameter) cmd.CreateParameter();
p5.Value = fkSchema;
p5.ParameterName = ("@fkSchema");
cmd.Parameters.Add (p5);
VirtuosoParameter p6 = (VirtuosoParameter) cmd.CreateParameter();
p6.Value = fkTable;
p6.ParameterName = ("@fkTable");
cmd.Parameters.Add (p6);
VirtuosoDataReader reader = (VirtuosoDataReader)cmd.ExecuteReader();
dt.Load(reader);
return dt;
}
#endif
#endregion
}
}
|