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 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203
|
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* 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, version 2.0, 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
*/
#include <cppconn/warning.h>
#include "connection.h"
#include <stdlib.h>
#include <fstream>
#include <cppconn/connection.h>
#include <driver/mysql_connection.h>
#include <cppconn/exception.h>
#include <cppconn/version_info.h>
#include <boost/scoped_ptr.hpp>
#include <list>
namespace testsuite
{
namespace classes
{
void connection::getClientInfo()
{
logMsg("connection::getClientInfo() - MySQL_Connection::getClientInfo()");
try
{
std::string ret;
ret=con->getClientInfo();
if (ret != "cppconn")
FAIL("Expecting 'cppconn' got '" + ret + "'.");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::getClientOption()
{
logMsg("connection::getClientOption() - MySQL_Connection::get|setClientOption()");
try
{
const std::string option("metadataUseInfoSchema");
{
bool input_value=true;
bool output_value=false;
void * input;
void * output;
input=(static_cast<bool *> (&input_value));
output=(static_cast<bool *> (&output_value));
con->setClientOption("metadataUseInfoSchema", input);
con->getClientOption("metadataUseInfoSchema", output);
ASSERT_EQUALS(input_value, output_value);
con->setClientOption("metadataUseInfoSchema", input);
con->getClientOption("metadataUseInfoSchema", output);
ASSERT_EQUALS(input_value, output_value);
input_value=false;
output_value=true;
con->setClientOption("metadataUseInfoSchema", input);
con->getClientOption("metadataUseInfoSchema", output);
ASSERT_EQUALS(input_value, output_value);
}
{
int input_value=sql::ResultSet::TYPE_SCROLL_INSENSITIVE;
int output_value=sql::ResultSet::TYPE_FORWARD_ONLY;
void * input;
void * output;
input=(static_cast<int *> (&input_value));
output=(static_cast<int *> (&output_value));
con->setClientOption("defaultStatementResultType", input);
con->getClientOption("defaultStatementResultType", output);
ASSERT_EQUALS(input_value, output_value);
input_value=sql::ResultSet::TYPE_FORWARD_ONLY;
output_value=sql::ResultSet::TYPE_SCROLL_INSENSITIVE;
con->setClientOption("defaultStatementResultType", input);
con->getClientOption("defaultStatementResultType", output);
ASSERT_EQUALS(input_value, output_value);
try
{
input_value=sql::ResultSet::TYPE_SCROLL_SENSITIVE;
con->setClientOption("defaultStatementResultType", input);
FAIL("API Change or bug, please check");
}
catch (sql::InvalidArgumentException &)
{
/* expected */
}
try
{
input_value=sql::ResultSet::TYPE_SCROLL_SENSITIVE + sql::ResultSet::TYPE_SCROLL_INSENSITIVE + sql::ResultSet::TYPE_FORWARD_ONLY;
con->setClientOption("defaultStatementResultType", input);
FAIL("API Change or bug, please check");
}
catch (sql::InvalidArgumentException &)
{
/* expected */
}
}
try
{
bool input_value=true;
bool output_value=false;
void * input;
void * output;
input=(static_cast<bool *> (&input_value));
output=(static_cast<bool *> (&output_value));
con->setClientOption("defaultPreparedStatementResultType", input);
con->getClientOption("defaultPreparedStatementResultType", output);
ASSERT_EQUALS(input_value, output_value);
input_value=false;
output_value=true;
con->setClientOption("defaultPreparedStatementResultType", input);
con->getClientOption("defaultPreparedStatementResultType", output);
ASSERT_EQUALS(input_value, output_value);
}
catch (sql::MethodNotImplementedException &)
{
/* compiled without -DWE_SUPPORT_USE_RESULT_WITH_PS */
}
try
{
sql::SQLString input_value("latin1");
sql::SQLString output_value;
con->setClientOption("characterSetResults", input_value);
output_value=con->getClientOption("characterSetResults");
ASSERT_EQUALS(input_value, output_value);
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
int serverVersion=getMySQLVersion(con);
if ( serverVersion >= 57003)
{
try
{
sql::ConnectOptionsMap opts;
int input_value=111;
int output_value=2367;
void * output;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts["OPT_READ_TIMEOUT"]=111;
created_objects.clear();
con.reset(driver->connect(opts));
output=(static_cast<int *> (&output_value));
con->getClientOption("OPT_READ_TIMEOUT", output);
ASSERT_EQUALS(input_value, output_value);
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
try
{
sql::ConnectOptionsMap opts;
bool input_value=true;
bool output_value=false;
void * output;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts["OPT_RECONNECT"]=input_value;
created_objects.clear();
con.reset(driver->connect(opts));
output=(static_cast<bool *> (&output_value));
con->getClientOption("OPT_RECONNECT", output);
ASSERT_EQUALS(input_value, output_value);
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
try
{
sql::ConnectOptionsMap opts;
sql::SQLString input_value("../lib/plugin/");
const char *output_value="../lib/plugin/";
void * output;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts["pluginDir"]=input_value;
created_objects.clear();
con.reset(driver->connect(opts));
output=(static_cast<const char **> (&output_value));
con->getClientOption("pluginDir", output);
ASSERT_EQUALS(input_value, output_value);
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
try
{
sql::SQLString tmp=con->getClientOption("characterSetDirectory");
tmp=con->getClientOption("readDefaultFile");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::getSessionVariable()
{
logMsg("connection::getSessionVariable() - MySQL_Connection::get|setSessionVariable()");
try
{
std::string value("");
boost::scoped_ptr< sql::mysql::MySQL_Connection > my_con(dynamic_cast<sql::mysql::MySQL_Connection*> (driver->connect(url, user, passwd)));
value=my_con->getSessionVariable("sql_mode");
my_con->setSessionVariable("sql_mode", "ANSI");
// The server will translate ANSI into something that is version dependent -
// ASSERT_EQUALS(my_con->getSessionVariable("sql_mode"), "");
my_con->setSessionVariable("sql_mode", value);
ASSERT_EQUALS(value, my_con->getSessionVariable("sql_mode"));
value=my_con->getSessionVariable("sql_warnings");
std::string on("ON");
std::string off("OFF");
try
{
my_con->setSessionVariable("sql_warnings", "0");
on="1";
off="0";
}
catch (sql::SQLException &)
{
}
try
{
my_con->setSessionVariable("sql_warnings", on);
ASSERT_EQUALS(on, my_con->getSessionVariable("sql_warnings"));
my_con->setSessionVariable("sql_warnings", off);
ASSERT_EQUALS(off, my_con->getSessionVariable("sql_warnings"));
}
catch (sql::SQLException &)
{
}
my_con->setSessionVariable("sql_warnings", value);
ASSERT_EQUALS(value, my_con->getSessionVariable("sql_warnings"));
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::getNoWarningsOnNewLine()
{
logMsg("connection::getNoWarningsOnNewLine() - MySQL_Connection::getWarnings()");
try
{
const sql::SQLWarning* warning;
warning=con->getWarnings();
if (warning != NULL)
FAIL("There should be no warnings on the default connection");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::invalidCredentials()
{
logMsg("connection::invalidCredentials() - MySQL_Connection connect");
std::string myurl("tcp://");
std::string myuser("");
std::string mypasswd("");
try
{
try
{
con.reset(driver->connect(myurl, user, passwd));
logMsg("... using invalid URL should have failed, but we can't be sure that is it an issue, because we do not know for sure what defaults a test system is using,");
con.reset(driver->connect(url, user, passwd));
}
catch (sql::SQLException &/*e*/)
{
logMsg("... using wrong URL caused expected failure");
con.reset(driver->connect(url, user, passwd));
}
if (!url.empty())
{
try
{
con.reset(driver->connect("", user, passwd));
logMsg("... using empty URL should have failed, but we can't be sure that is it an issue, because we do not know for sure what defaults a test system is using,");
con.reset(driver->connect(url, user, passwd));
}
catch (sql::SQLException &)
{
logMsg("... using empty URL caused expected failure");
con.reset(driver->connect(url, user, passwd));
try
{
con.reset(driver->connect("", user, passwd));
FAIL("Should have caused exception");
}
catch (sql::SQLException &)
{
}
}
}
if (user.empty())
{
myuser.append("H17ba76inosuchuser");
try
{
con.reset(driver->connect(url, myuser, passwd));
FAIL("... using invalid user should cause failure");
}
catch (sql::SQLException &)
{
logMsg("... using wrong URL caused expected failure");
con.reset(driver->connect(url, user, passwd));
try
{
con.reset(driver->connect(url, myuser, passwd));
FAIL("Should have caused exception");
}
catch (sql::SQLException &)
{
}
}
}
else
{
/* Its a guess, but usually such a user won't exist... */
myuser.append(user);
myuser.append(user);
try
{
con.reset(driver->connect(url, myuser, myuser));
FAIL("... using invalid user should have failed");
}
catch (sql::SQLException &)
{
logMsg("... using wrong user caused expected failure");
con.reset(driver->connect(url, user, passwd));
try
{
con.reset(driver->connect(url, myuser, myuser));
FAIL("Should have caused exception");
}
catch (sql::SQLException &)
{
}
}
}
if (passwd.empty())
{
mypasswd.append("27jahjk327ahime27879xas");
try
{
con.reset(driver->connect(url, user, mypasswd));
FAIL("... using invalid password should cause failure");
}
catch (sql::SQLException &)
{
logMsg("... using wrong password caused expected failure");
con.reset(driver->connect(url, user, passwd));
try
{
con.reset(driver->connect(url, user, mypasswd));
FAIL("Should have caused exception");
}
catch (sql::SQLException &)
{
}
}
}
else
{
mypasswd.append(passwd);
mypasswd.append(passwd);
try
{
con.reset(driver->connect(url, user, mypasswd));
FAIL("... using invalid password should have failed");
}
catch (sql::SQLException &)
{
logMsg("... using wrong password caused expected failure");
con.reset(driver->connect(url, user, passwd));
try
{
con.reset(driver->connect(url, user, mypasswd));
FAIL("Should have caused exception");
}
catch (sql::SQLException &)
{
}
}
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::getNoWarningsAfterClear()
{
logMsg("connection::getNoWarningsAfterClear() - MySQL_Connection::getWarnings()");
try
{
const sql::SQLWarning* warning;
/* TODO: pointless test as there is no warning before running clearWarnings() */
con->clearWarnings();
warning=con->getWarnings();
if (warning != NULL)
FAIL("There should be no warnings on the default connection");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::checkClosed()
{
logMsg("connection::checkClosed - MySQL_Connection::close, isClosed() and internal check_closed()");
try
{
if (con->isClosed())
FAIL("Connection should not be reported as closed");
con->close();
if (!con->isClosed())
FAIL("Connection should be closed");
try
{
con->rollback();
}
catch (sql::SQLException &e)
{
std::string reason(exceptionIsOK(e, "HY000", 0));
if (!reason.empty())
fail(reason.c_str(), __FILE__, __LINE__);
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::connectUsingMapWrongTypes()
{
logMsg("connection::connectUsingMapWrongTypes - using map to pass connection parameters but parameter of wrong type");
try
{
sql::ConnectOptionsMap connection_properties;
bool boolval=true;
std::string strval("");
try
{
connection_properties["hostName"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception I");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("hostName");
connection_properties["hostName"]=url;
try
{
connection_properties["userName"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception II");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("userName");
connection_properties["userName"]=user;
try
{
connection_properties["password"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception III");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("password");
connection_properties["password"]=passwd;
try
{
connection_properties["port"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception IV");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("port");
try
{
connection_properties["socket"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception V");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("socket");
try
{
connection_properties["pipe"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception VI");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("pipe");
try
{
connection_properties["schema"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception VII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("schema");
try
{
connection_properties["characterSetResults"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception VIII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("characterSetResults");
try
{
connection_properties["sslKey"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception IX");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslKey");
try
{
connection_properties["sslCert"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception X");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslCert");
try
{
connection_properties["sslCA"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XI");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslCA");
try
{
connection_properties["sslCAPath"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslCAPath");
try
{
connection_properties["sslCipher"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XIII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslCipher");
/*
TODO -- will be moved into driver class.
try
{
connection_properties["clientlib"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XIV");
}
catch (sql::InvalidArgumentException&)
{
expected
}
connection_properties.erase("clientlib");
*/
try
{
connection_properties["defaultStatementResultType"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XV");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("defaultStatementResultType");
try
{
connection_properties["metadataUseInfoSchema"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XVI");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("metadataUseInfoSchema");
try
{
connection_properties["CLIENT_COMPRESS"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XVII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_COMPRESS");
try
{
connection_properties["CLIENT_FOUND_ROWS"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XVIII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_FOUND_ROWS");
try
{
connection_properties["CLIENT_IGNORE_SIGPIPE"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XIX");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_IGNORE_SIGPIPE");
try
{
connection_properties["CLIENT_IGNORE_SPACE"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XX");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_IGNORE_SPACE");
try
{
connection_properties["CLIENT_INTERACTIVE"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXI");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_INTERACTIVE");
try
{
connection_properties["CLIENT_LOCAL_FILES"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_LOCAL_FILES");
try
{
connection_properties["CLIENT_MULTI_STATEMENTS"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXIII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_MULTI_STATEMENTS");
try
{
connection_properties["CLIENT_NO_SCHEMA"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXIV");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("CLIENT_NO_SCHEMA");
try
{
connection_properties["OPT_CONNECT_TIMEOUT"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXV");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("OPT_CONNECT_TIMEOUT");
try
{
connection_properties["OPT_READ_TIMEOUT"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXVI");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("OPT_READ_TIMEOUT");
try
{
connection_properties["OPT_WRITE_TIMEOUT"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXVII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("OPT_WRITE_TIMEOUT");
try
{
connection_properties["OPT_RECONNECT"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXVIII");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("OPT_RECONNECT");
try
{
connection_properties["OPT_CHARSET_NAME"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXIX");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("OPT_CHARSET_NAME");
try
{
connection_properties["OPT_REPORT_DATA_TRUNCATION"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXX");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("OPT_REPORT_DATA_TRUNCATION");
try
{
connection_properties["sslVerify"]=(strval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXXI - sslVerify");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslVerify");
try
{
connection_properties["sslCRL"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXXII - sslCRL");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslCRL");
try
{
connection_properties["sslCRLPath"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXXIII - sslCRLPath");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("sslCRLPath");
try
{
connection_properties["rsaKey"]=(boolval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("No exception XXXIII - rsaKey");
}
catch (sql::InvalidArgumentException&)
{
/* expected */
}
connection_properties.erase("rsaKey");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::connectUsingMap()
{
logMsg("connection::connectUsingMap - using map to pass connection parameters");
try
{
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"]=url;
connection_properties["userName"]=user;
connection_properties["password"]=passwd;
bool bval= !TestsRunner::getStartOptions()->getBool("dont-use-is");
connection_properties["metadataUseInfoSchema"]=(bval);
created_objects.clear();
con.reset(driver->connect(connection_properties));
/*
The property map now contains the minimum required entries and it works.
Lets play with so-to-say optional entries.
*/
/* 1) Port */
connection_properties.erase("port");
{
int port= -1;
if (url.compare(0, sizeof ("tcp://") - 1, "tcp://") == 0)
{
size_t port_pos;
port_pos=url.find_last_of(":", std::string::npos);
if (port_pos != std::string::npos)
port=atoi(url.substr(port_pos + 1, std::string::npos).c_str());
if (port == -1)
{
/* The user is using TCP/IP and default port 3306 */
connection_properties["password"]=(port);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
FAIL("Connect works with invalid port of -1");
}
catch (sql::SQLException &e)
{
std::string reason(exceptionIsOK(e, "HY000", 2003));
logErr(reason);
}
}
else
{
/* The user is using TCP/IP and has specified the port.
A port setting shall NOT overrule the setting from the URL */
port= -1;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
FAIL("URL shall overrule port setting");
}
}
}
else
{
/* We must be using a socket connection - all port settings shall be ignored */
connection_properties["port"]=(port);
/* Must not throw an exception */
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
FAIL("Port setting should be ignored, using Unix socket!");
}
}
}
connection_properties.erase("port");
/* 2) Socket */
connection_properties.erase("socket");
{
std::string socket("");
#ifndef CPPWIN_WIN32
if (url.compare(0, sizeof ("unix://") - 1, "unix://") == 0)
{
// Unix socket connection
socket="I hope this is invalid";
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
FAIL("Socket setting should be ignored, socket is part of the URL");
}
}
else
#endif
if (url.compare(0, sizeof ("tcp://") - 1, "tcp://") == 0)
{
// TCP/IP connection, socket shall be ignored
socket="I hope this is invalid";
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
FAIL("Socket setting should be ignored because its a TCP/IP connection");
}
}
}
connection_properties.erase("socket");
/* 2) Schema */
connection_properties.erase("schema");
{
std::string schema("");
std::string myschema("mysql");
std::string retschema("");
if (url.compare(0, sizeof ("tcp://") - 1, "tcp://") == 0)
{
// TCP/IP connection - schema cannot be set when using unix socket syntax
size_t schema_pos;
std::string host(url.substr(sizeof ("tcp://") - 1, std::string::npos));
schema_pos=host.find("/");
if (schema_pos != std::string::npos)
{
schema_pos++;
schema=host.substr(schema_pos, host.size() - schema_pos);
}
}
if (schema.empty())
{
logMsg("... schema not set through the URL");
connection_properties[std::string("schema")]=schema;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
schema=con->getSchema();
if (!schema.empty())
FAIL("Empty schama specified but certain schema selected upon connect");
}
catch (sql::SQLException &)
{
FAIL("Connect should have worked although schema property set to empty string");
}
logMsg("... trying to connect to mysql schema, may or may not work");
connection_properties.erase("schema");
connection_properties["schema"]=(myschema);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
Connection mycon(driver->connect(connection_properties));
retschema=mycon->getSchema();
if (retschema != myschema)
{
logErr(retschema);
logErr(myschema);
logErr(mycon->getCatalog());
logErr(mycon->getSchema());
FAIL("Connected to schema mysql but getSchema() reports different schema");
}
}
catch (sql::SQLException &)
{
logMsg("... cannot connect to mysql schema but that is OK, might be insufficient grants");
}
}
else
{
/* schema is set in the TCP/IP url */
logMsg("... schema is set in the URL and property shall be ignored");
/* no property set */
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
retschema=con->getSchema();
if (retschema != schema)
{
logErr(retschema);
logErr(schema);
FAIL("Connected to a certain schema but getSchema() reports different schema");
}
}
catch (sql::SQLException &)
{
FAIL("Connect should not fail");
}
/* property set */
connection_properties["schema"]=(myschema);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
retschema=con->getSchema();
if (retschema != schema)
{
logErr(retschema);
logErr(schema);
FAIL("Connected to a certain schema but getSchema() reports different schema");
}
}
catch (sql::SQLException &)
{
FAIL("Connect should not fail");
}
}
}
connection_properties.erase("schema");
/* 3) ssl* */
connection_properties.erase("sslKey");
connection_properties.erase("sslCert");
connection_properties.erase("sslCA");
connection_properties.erase("sslCAPath");
connection_properties.erase("sslCipher");
{
logMsg("... setting bogus SSL properties");
std::string sql("ramdom bogus value");
connection_properties["sslKey"]=(sql);
connection_properties["sslCert"]=(sql);
connection_properties["sslCA"]=(sql);
connection_properties["sslCAPath"]=(sql);
connection_properties["sslCipher"]=(sql);
/*
mysql_ssl_set is silly:
This function always returns 0.
If SSL setup is incorrect, mysql_real_connect()
returns an error when you attempt to connect.
*/
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("sslKey");
connection_properties.erase("sslCert");
connection_properties.erase("sslCA");
connection_properties.erase("sslCAPath");
connection_properties.erase("sslCipher");
/* All the CLIENT* are pointless. There is no way (yet) to verify the settings */
/* 4) CLIENT_COMPRESS */
connection_properties.erase("CLIENT_COMPRESS");
{
logMsg("... testing CLIENT_COMPRESS");
connection_properties["CLIENT_COMPRESS"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_COMPRESS"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_COMPRESS");
/* 5) CLIENT_FOUND_ROWS */
connection_properties.erase("CLIENT_FOUND_ROWS");
{
logMsg("... testing CLIENT_FOUND_ROWS");
connection_properties["CLIENT_FOUND_ROWS"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_FOUND_ROWS"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties.erase("CLIENT_FOUND_ROWS");
connection_properties["CLIENT_FOUND_ROWS"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_FOUND_ROWS");
/* 6) CLIENT_IGNORE_SIGPIPE */
connection_properties.erase("CLIENT_IGNORE_SIGPIPE");
{
logMsg("... testing CLIENT_IGNORE_SIGPIPE");
connection_properties["CLIENT_IGNORE_SIGPIPE"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_IGNORE_SIGPIPE"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_IGNORE_SIGPIPE"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_IGNORE_SIGPIPE");
/* 7) CLIENT_IGNORE_SPACE */
connection_properties.erase("CLIENT_IGNORE_SPACE");
{
logMsg("... testing CLIENT_IGNORE_SPACE");
connection_properties["CLIENT_IGNORE_SPACE"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_IGNORE_SPACE"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties.erase("CLIENT_IGNORE_SPACE");
connection_properties["CLIENT_IGNORE_SPACE"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_IGNORE_SPACE");
/* 8) CLIENT_INTERACTIVE */
connection_properties.erase("CLIENT_INTERACTIVE");
{
logMsg("... testing CLIENT_INTERACTIVE");
connection_properties["CLIENT_INTERACTIVE"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_INTERACTIVE"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties.erase("CLIENT_INTERACTIVE");
connection_properties["CLIENT_INTERACTIVE"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_INTERACTIVE");
/* 9) CLIENT_LOCAL_FILES */
/* TODO - add proper test */
connection_properties.erase("CLIENT_LOCAL_FILES");
{
logMsg("... testing CLIENT_LOCAL_FILES");
connection_properties["CLIENT_LOCAL_FILES"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_LOCAL_FILES"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties.erase("CLIENT_LOCAL_FILES");
connection_properties["CLIENT_LOCAL_FILES"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_LOCAL_FILES");
/* 10) CLIENT_MULTI_RESULTS */
/* TODO - add proper test */
connection_properties.erase("CLIENT_MULTI_RESULTS");
{
logMsg("... testing CLIENT_MULTI_RESULTS");
connection_properties["CLIENT_MULTI_RESULTS"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_MULTI_RESULTS"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties.erase("CLIENT_MULTI_RESULTS");
connection_properties["CLIENT_MULTI_RESULTS"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_MULTI_RESULTS");
/* 11) CLIENT_MULTI_STATEMENTS */
/* TODO: add proper test */
connection_properties.erase("CLIENT_MULTI_STATEMENTS");
{
logMsg("... testing CLIENT_MULTI_STATEMENTS");
connection_properties["CLIENT_MULTI_STATEMENTS"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_MULTI_STATEMENTS"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties.erase("CLIENT_MULTI_STATEMENTS");
connection_properties["CLIENT_MULTI_STATEMENTS"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_MULTI_STATEMENTS");
/* 12) CLIENT_NO_SCHEMA */
connection_properties.erase("CLIENT_NO_SCHEMA");
{
logMsg("... testing CLIENT_NO_SCHEMA");
connection_properties["CLIENT_NO_SCHEMA"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties["CLIENT_NO_SCHEMA"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
connection_properties.erase("CLIENT_NO_SCHEMA");
connection_properties["CLIENT_NO_SCHEMA"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &)
{
}
}
connection_properties.erase("CLIENT_NO_SCHEMA");
/* 13) MYSQL_OPT_CONNECT_TIMEOUT */
connection_properties.erase("OPT_CONNECT_TIMEOUT");
{
logMsg("... testing OPT_CONNECT_TIMEOUT");
/*
C-API does not care about the actual value, its passed down to the OS,
The OS may or may not detect bogus values such as negative values.
*/
connection_properties["OPT_CONNECT_TIMEOUT"]=1;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_CONNECT_TIMEOUT");
/* 14) MYSQL_OPT_READ_TIMEOUT */
connection_properties.erase("OPT_READ_TIMEOUT");
{
logMsg("... testing OPT_READ_TIMEOUT");
/*
C-API does not care about the actual value, its passed down to the OS,
The OS may or may not detect bogus values such as negative values.
*/
connection_properties["OPT_READ_TIMEOUT"]=1;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_READ_TIMEOUT");
/* 15) MYSQL_OPT_WRITE_TIMEOUT */
connection_properties.erase("OPT_WRITE_TIMEOUT");
{
logMsg("... testing OPT_WRITE_TIMEOUT");
/* C-API does not care about the actual value */
connection_properties["OPT_WRITE_TIMEOUT"]=1;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_WRITE_TIMEOUT");
/* 16) MYSQL_OPT_RECONNECT */
connection_properties.erase("OPT_RECONNECT");
{
logMsg("... testing OPT_RECONNECT");
/* C-API does not care about the actual value */
connection_properties["OPT_RECONNECT"]=true;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_RECONNECT");
/* 17) MYSQL_OPT_SET_CHARSET_NAME */
connection_properties.erase("OPT_SET_CHARSET_NAME");
{
logMsg("... testing OPT_SET_CHARSET_NAME");
std::string charset("utf8");
/* C-API does not care about the actual value */
connection_properties["OPT_SET_CHARSET_NAME"]=(charset);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_SET_CHARSET_NAME");
/* 18) MYSQL_REPORT_DATA_TRUNCATION */
connection_properties.erase("REPORT_DATA_TRUNCATION");
{
logMsg("... testing REPORT_DATA_TRUNCATION");
std::string charset("1");
/* C-API does not care about the actual value */
connection_properties["REPORT_DATA_TRUNCATION"]=(charset);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("REPORT_DATA_TRUNCATION");
/* 19) metadataUseInfoSchema */
connection_properties.erase("metadataUseInfoSchema");
{
logMsg("... testing metadataUseInfoSchema");
connection_properties["metadataUseInfoSchema"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
connection_properties.erase("metadataUseInfoSchema");
connection_properties["metadataUseInfoSchema"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("metadataUseInfoSchema");
/* 20) defaultStatementResultType */
connection_properties.erase("defaultStatementResultType");
{
logMsg("... testing defaultStatementResultType");
connection_properties["defaultStatementResultType"]=(sql::ResultSet::TYPE_FORWARD_ONLY);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
connection_properties.erase("defaultStatementResultType");
connection_properties["defaultStatementResultType"]=(sql::ResultSet::TYPE_SCROLL_INSENSITIVE);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
connection_properties.erase("defaultStatementResultType");
connection_properties["defaultStatementResultType"]=(sql::ResultSet::TYPE_SCROLL_SENSITIVE);
try
{
created_objects.clear();
try
{
con.reset(driver->connect(connection_properties));
FAIL("Bug or API change - TYPE_SCROLL_SENSITIVE is unsupported");
}
catch (sql::SQLException &e)
{
logMsg("... expected exception because TYPE_SCROLL_SENSITIVE is unsupported!");
logMsg(e.what());
}
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("defaultStatementResultType");
#ifdef CPPWIN_WIN32
/* 21) OPT_NAMED_PIPE - handled but ignored! */
connection_properties.erase("OPT_NAMED_PIPE");
{
logMsg("... testing OPT_NAMED_PIPE");
std::string pipe("IGNORED");
connection_properties["OPT_NAMED_PIPE"]=(pipe);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_NAMED_PIPE");
#endif
/* 22) OPT_CHARSET_NAME = MYSQL_SET_CHARSET_NAME */
connection_properties.erase("OPT_CHARSET_NAME");
{
logMsg("... testing OPT_CHARSET_NAME");
std::string charset("utf8");
connection_properties["OPT_CHARSET_NAME"]=(charset);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_CHARSET_NAME");
/* 23) OPT_REPORT_DATA_TRUNCATION */
connection_properties.erase("OPT_REPORT_DATA_TRUNCATION");
{
logMsg("... testing OPT_REPORT_DATA_TRUNCATION");
connection_properties["OPT_REPORT_DATA_TRUNCATION"]=(true);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
connection_properties.erase("OPT_REPORT_DATA_TRUNCATION");
connection_properties["OPT_REPORT_DATA_TRUNCATION"]=(false);
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
fail(e.what(), __FILE__, __LINE__);
}
}
connection_properties.erase("OPT_REPORT_DATA_TRUNCATION");
/* 24) defaultPreparedStatementResultType */
connection_properties.erase("defaultPreparedStatementResultType");
{
logMsg("... testing defaultPreparedStatementResultType");
connection_properties["defaultPreparedStatementResultType"]=sql::ResultSet::TYPE_FORWARD_ONLY;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &/*e*/)
{
/* may not be compiled in - ignore */
}
}
connection_properties.erase("defaultPreparedStatementResultType");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::connectOptReconnect()
{
logMsg("connection::connectOptReconnect - OPT_RECONNECT");
std::stringstream msg;
try
{
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"]=url;
connection_properties["userName"]=user;
connection_properties["password"]=passwd;
bool bval= !TestsRunner::getStartOptions()->getBool("dont-use-is");
connection_properties["metadataUseInfoSchema"]=(bval);
logMsg("... OPT_RECONNECT disabled");
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=false;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
con->close();
ASSERT(con->isClosed());
try
{
stmt.reset(con->createStatement());
stmt->execute("DROP TABLE IF EXISTS test");
FAIL("Can create statement although connection has been closed");
}
catch (sql::SQLException &/*e*/)
{
/* expected */
}
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=false;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
ASSERT_EQUALS(false, con->isClosed());
try
{
stmt.reset(con->createStatement());
stmt->execute("DROP TABLE IF EXISTS test");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
logMsg("... OPT_RECONNECT enabled");
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=true;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
con->close();
ASSERT(con->isClosed());
try
{
stmt.reset(con->createStatement());
stmt->execute("DROP TABLE IF EXISTS test");
FAIL("Can create statement although connection has been closed");
}
catch (sql::SQLException &/*e*/)
{
/* expected */
}
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=true;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
ASSERT_EQUALS(false, con->isClosed());
try
{
stmt.reset(con->createStatement());
stmt->execute("DROP TABLE IF EXISTS test");
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
logMsg("... OPT_RECONNECT disabled and KILL");
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=false;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SELECT CONNECTION_ID() as _pid"));
ASSERT(res->next());
msg.str("");
msg << "KILL " << res->getInt("_pid");
try
{
Connection my_con(getConnection());
my_con->setSchema(db);
Statement my_stmt(my_con->createStatement());
my_stmt->execute(msg.str());
logMsg("... we seem to be lucky, we have killed a connection");
logMsg(msg.str());
try
{
msg.str("");
msg << "USE " << db;
stmt->execute(msg.str());
stmt->execute("DROP TABLE IF EXISTS test");
FAIL("Statement object is still usable");
}
catch (sql::SQLException &e)
{
// Any error message is fine, connection should have been killed
logMsg(e.what());
}
}
catch (sql::SQLException &/*e*/)
{
// KILL has failed - that is OK, we may not have permissions
}
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=false;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SELECT CONNECTION_ID() as _pid"));
ASSERT(res->next());
msg.str("");
msg << "KILL " << res->getInt("_pid");
try
{
Connection my_con(getConnection());
my_con->setSchema(db);
Statement my_stmt(my_con->createStatement());
my_stmt->execute(msg.str());
logMsg("... we seem to be lucky, we have killed a connection");
logMsg(msg.str());
try
{
stmt.reset(con->createStatement());
logMsg("... we got a new statement object");
stmt->execute("DROP TABLE IF EXISTS test");
FAIL("Statement object is still usable");
}
catch (sql::SQLException &e)
{
/* Any error message is fine, connection should have been killed */
logMsg(e.what());
}
}
catch (sql::SQLException &/*e*/)
{
/* KILL has failed - that is OK, we may not have permissions */
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::setTransactionIsolation()
{
logMsg("connection::setTransactionIsolation() - MySQL_Connection::setTransactionIsolation()");
bool have_innodb=false;
int cant_be_changed_error= -1;
int server_dependent_insert= -1;
stmt.reset(con->createStatement());
try
{
con->setTransactionIsolation(sql::TRANSACTION_READ_COMMITTED);
ASSERT_EQUALS(sql::TRANSACTION_READ_COMMITTED, con->getTransactionIsolation());
res.reset(stmt->executeQuery("SHOW VARIABLES LIKE 'transaction_isolation'"));
checkResultSetScrolling(res);
res->next();
ASSERT_EQUALS("READ-COMMITTED", res->getString("Value"));
con->setTransactionIsolation(sql::TRANSACTION_READ_UNCOMMITTED);
ASSERT_EQUALS(sql::TRANSACTION_READ_UNCOMMITTED, con->getTransactionIsolation());
res.reset(stmt->executeQuery("SHOW VARIABLES LIKE 'transaction_isolation'"));
res->next();
ASSERT_EQUALS("READ-UNCOMMITTED", res->getString("Value"));
con->setTransactionIsolation(sql::TRANSACTION_REPEATABLE_READ);
ASSERT_EQUALS(sql::TRANSACTION_REPEATABLE_READ, con->getTransactionIsolation());
res.reset(stmt->executeQuery("SHOW VARIABLES LIKE 'transaction_isolation'"));
res->next();
ASSERT_EQUALS("REPEATABLE-READ", res->getString("Value"));
con->setTransactionIsolation(sql::TRANSACTION_SERIALIZABLE);
ASSERT_EQUALS(sql::TRANSACTION_SERIALIZABLE, con->getTransactionIsolation());
res.reset(stmt->executeQuery("SHOW VARIABLES LIKE 'transaction_isolation'"));
res->next();
ASSERT_EQUALS("SERIALIZABLE", res->getString("Value"));
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
try
{
con.reset(getConnection());
stmt.reset(con->createStatement());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
try
{
con->setAutoCommit(true);
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT) ENGINE = InnoDB");
have_innodb=true;
}
catch (sql::SQLException &)
{
have_innodb=false;
}
if (have_innodb)
{
try
{
con->setAutoCommit(false);
stmt->execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
stmt->execute("INSERT INTO test(id) VALUES (1)");
/* JDBC documentation: If this method is called while
in the middle of a transaction, any changes up to that point
will be committed.*/
stmt->execute("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ");
// con->setTransactionIsolation(sql::TRANSACTION_REPEATABLE_READ);
/* According to the JDBC docs the INSERT has been comitted
and this ROLLBACK must have no impat */
con->rollback();
res.reset(stmt->executeQuery("SELECT COUNT(*) AS _num FROM test"));
res->next();
server_dependent_insert=res->getInt("_num");
}
catch (sql::SQLException &e)
{
logMsg("... EXPECTED behaviour - Transaction isolation level can't be changed while a transaction is in progress.");
logMsg(e.what());
logMsg("SQLState: " + std::string(e.getSQLState()));
cant_be_changed_error=e.getErrorCode();
}
try
{
con.reset(getConnection());
stmt.reset(con->createStatement());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
try
{
con->setAutoCommit(true);
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT) ENGINE = InnoDB");
con->setAutoCommit(false);
con->setTransactionIsolation(sql::TRANSACTION_SERIALIZABLE);
stmt->execute("INSERT INTO test(id) VALUES (1)");
/* JDBC documentation: If this method is called while
in the middle of a transaction, any changes up to that point
will be committed.*/
con->setTransactionIsolation(sql::TRANSACTION_REPEATABLE_READ);
if (-1 != cant_be_changed_error)
{
FAIL("Changing the transaction level manually has caused an exception. Changing it through API has not!");
}
/* According to the JDBC docs the INSERT has been comitted
and this ROLLBACK must have no impat */
con->rollback();
res.reset(stmt->executeQuery("SELECT COUNT(*) AS _num FROM test"));
res->next();
ASSERT_EQUALS(server_dependent_insert, res->getInt("_num"));
stmt->execute("DROP TABLE IF EXISTS test");
}
catch (sql::SQLException &e)
{
if (e.getErrorCode() != cant_be_changed_error)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
else
{
logMsg("... EXPECTED behaviour - Transaction isolation level can't be changed while a transaction is in progress.");
logMsg(e.what());
logMsg("SQLState: " + std::string(e.getSQLState()));
}
}
}
con->close();
try
{
con->setTransactionIsolation(sql::TRANSACTION_READ_COMMITTED);
FAIL("Closed connection not detected");
}
catch (sql::SQLException &)
{
}
}
void connection::rollback()
{
try
{
con->setAutoCommit(false);
try
{
try
{
con->setAutoCommit(true);
con->rollback(con->setSavepoint("foo"));
FAIL("autoCommit mode not detected");
}
catch (sql::InvalidArgumentException &e)
{
ASSERT_EQUALS(e.what(), "The connection is in autoCommit mode");
}
}
catch (sql::SQLException &)
{
/* no support for savepoints, bad luck... */
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
/* Exploiting bug that different wrapper is currently created if requested for ""
* and default lib name. just to test that nothing bad happens.
* Test itself shouldn't fail.
*/
#ifndef MYSQLCLIENT_STATIC_BINDING
void connection::loadSameLibraryTwice()
{
#if defined(_WIN32)
const sql::SQLString baseName("libmysql.dll");
#elif defined(__APPLE__)
const sql::SQLString baseName("libmysqlclient_r.dylib");
#elif defined(__hpux) && defined(__hppa)
const sql::SQLString baseName("libmysqlclient_r.sl");
#else
const sql::SQLString baseName("libmysqlclient_r.so");
#endif
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"]=url;
connection_properties["userName"]=user;
connection_properties["password"]=passwd;
connection_properties["clientlib"]=baseName;
con.reset(driver->connect(connection_properties));
}
#endif
/* Test of the OPT_ENABLE_CLEARTEXT_PLUGIN connection of the text
The test idea - we try to create fake PAM authorized user and try to connect
using that user first without, and then with the new option selected. In
first case the error has to be that cleartext plugin could not be loaded, and
in second case the error has to be different */
void connection::enableClearTextAuth()
{
int serverVersion=getMySQLVersion(con);
if ( ((serverVersion < 55027) || (serverVersion > 56000)) && (serverVersion < 56007))
{
SKIP("The server does not support tested functionality(cleartext plugin enabling)");
}
try
{
stmt->executeUpdate("DROP USER 't_ct_user'@'%'");
}
catch (sql::SQLException &)
{
// Catching exception if user did not exist
}
try
{
stmt->executeUpdate("GRANT ALL ON 't_ct_plugin' TO 't_ct_user' IDENTIFIED WITH "
"'authentication_pam'");
}
catch (sql::SQLException &)
{
SKIP("The authentication_pam plugin not loaded");
}
sql::ConnectOptionsMap opts;
testsuite::Connection c2;
opts["userName"]=sql::SQLString("t_ct_user");
opts["password"]=sql::SQLString("foo");
/*
Expecting error CR_AUTH_PLUGIN_CANNOT_LOAD_ERROR
without option ENABLE_CLEARTEXT_PLUGIN
*/
try
{
c2.reset(getConnection(&opts));
}
catch (sql::SQLException &e)
{
/* We should have dropped the created user here if assertion fails -
TODO: Add sort of dropSchemaObject for created users in tearDown */
ASSERT_EQUALS(2059, e.getErrorCode()/*CR_AUTH_PLUGIN_CANNOT_LOAD_ERROR*/);
}
/*
Expecting error other then CR_AUTH_PLUGIN_CANNOT_LOAD_ERROR
as option ENABLE_CLEARTEXT_PLUGIN is used
*/
opts["OPT_ENABLE_CLEARTEXT_PLUGIN"]=true;
try
{
c2.reset(getConnection(&opts));
}
catch (sql::SQLException &e)
{
ASSERT(e.getErrorCode() != 2059);
}
stmt->executeUpdate("DROP USER 't_ct_user'@'%'");
}
void connection::connectAttrAdd()
{
logMsg("connection::connectAttr - MYSQL_OPT_CONNECT_ATTR_ADD|MYSQL_OPT_CONNECT_ATTR_DELETE");
//TODO: Enable it after fixing
SKIP("Removed untill fixed");
int serverVersion=getMySQLVersion(con);
if ( serverVersion < 56006)
{
SKIP("The server does not support tested functionality(cleartext plugin enabling)");
}
try
{
testsuite::Connection conn1;
sql::ConnectOptionsMap opts;
std::map< sql::SQLString, sql::SQLString > connectAttrMap;
std::list< std::string > connectAttrList;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
connectAttrMap["keyc1"]="value1";
connectAttrMap["keyc2"]="value2";
connectAttrMap["keyc3"]="value3";
connectAttrMap["keyc4"]="value4";
connectAttrMap["keyc5"]="value5";
connectAttrList.push_back(std::string("keyc2"));
connectAttrList.push_back(std::string("keyc5"));
opts.erase("OPT_CONNECT_ATTR_ADD");
opts.erase("OPT_CONNECT_ATTR_DELETE");
opts["OPT_CONNECT_ATTR_ADD"]=connectAttrMap;
opts["OPT_CONNECT_ATTR_DELETE"]=connectAttrList;
created_objects.clear();
conn1.reset(driver->connect(opts));
stmt.reset(conn1->createStatement());
res.reset(stmt->executeQuery("SELECT ATTR_NAME, ATTR_VALUE FROM "
"performance_schema.session_account_connect_attrs WHERE "
"ATTR_NAME LIKE '%keyc%' ORDER BY ATTR_NAME ASC;"));
ASSERT(res->next());
ASSERT_EQUALS(res->getString("ATTR_NAME"), "keyc1");
ASSERT_EQUALS(res->getString("ATTR_VALUE"), "value1");
ASSERT(res->next());
ASSERT_EQUALS(res->getString("ATTR_NAME"), "keyc3");
ASSERT_EQUALS(res->getString("ATTR_VALUE"), "value3");
ASSERT(res->next());
ASSERT_EQUALS(res->getString("ATTR_NAME"), "keyc4");
ASSERT_EQUALS(res->getString("ATTR_VALUE"), "value4");
ASSERT(!res->next());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
/*
Check for empty OPT_CONNECT_ATTR_ADD map
should not result in errors
*/
try
{
testsuite::Connection conn1;
sql::ConnectOptionsMap opts;
std::map< sql::SQLString, sql::SQLString > connectAttrMap;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts.erase("OPT_CONNECT_ATTR_ADD");
opts["OPT_CONNECT_ATTR_ADD"]=connectAttrMap;
created_objects.clear();
conn1.reset(driver->connect(opts));
stmt.reset(conn1->createStatement());
res.reset(stmt->executeQuery("SELECT 1"));
ASSERT(res->next());
ASSERT_EQUALS(res->getInt(1), 1);
ASSERT(!res->next());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
/*
Check for empty OPT_CONNECT_ATTR_DELETE list
*/
try
{
testsuite::Connection conn1;
sql::ConnectOptionsMap opts;
std::map< sql::SQLString, sql::SQLString > connectAttrMap;
std::list< std::string > connectAttrList;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
connectAttrMap["keya1"]="value1";
connectAttrMap["keya2"]="value2";
opts.erase("OPT_CONNECT_ATTR_ADD");
opts.erase("OPT_CONNECT_ATTR_DELETE");
opts["OPT_CONNECT_ATTR_ADD"]=connectAttrMap;
opts["OPT_CONNECT_ATTR_DELETE"]=connectAttrList;
created_objects.clear();
conn1.reset(driver->connect(opts));
stmt.reset(conn1->createStatement());
res.reset(stmt->executeQuery("SELECT ATTR_NAME, ATTR_VALUE FROM "
"performance_schema.session_account_connect_attrs WHERE "
"ATTR_NAME LIKE '%keya%' ORDER BY ATTR_NAME ASC;"));
ASSERT(res->next());
ASSERT_EQUALS(res->getString("ATTR_NAME"), "keya1");
ASSERT_EQUALS(res->getString("ATTR_VALUE"), "value1");
ASSERT(res->next());
ASSERT_EQUALS(res->getString("ATTR_NAME"), "keya2");
ASSERT_EQUALS(res->getString("ATTR_VALUE"), "value2");
ASSERT(!res->next());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
/*
Check with inserting max allowed key-value pair i.e. lesser then size
of performance_schema_session_connect_attrs_size
*/
try
{
testsuite::Connection conn1;
sql::ConnectOptionsMap opts;
int max_count;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
created_objects.clear();
conn1.reset(driver->connect(opts));
stmt.reset(conn1->createStatement());
res.reset(stmt->executeQuery("SHOW VARIABLES LIKE "
"'performance_schema_session_connect_attrs_size';"));
ASSERT(res->next());
ASSERT_EQUALS(res->getString("Variable_name"), "performance_schema_session_connect_attrs_size");
int perf_conn_attr_size= res->getInt("Value");
if (perf_conn_attr_size < 512) {
SKIP("The performance_schema_session_connect_attrs_size is less then 512");
} else if (perf_conn_attr_size >= 512 && perf_conn_attr_size < 1024) {
max_count= 32;
} else if (perf_conn_attr_size >= 1024 && perf_conn_attr_size < 2048) {
max_count= 64;
} else if (perf_conn_attr_size >= 2048) {
max_count= 128;
}
try
{
testsuite::Connection conn2;
std::map< sql::SQLString, sql::SQLString > connectAttrMap;
std::list< std::string > connectAttrList;
std::stringstream skey;
int i;
for (i=1; i <= max_count; ++i) {
skey.str("");
skey << "keymu" << i;
connectAttrMap[skey.str()] = "value";
}
opts.erase("OPT_CONNECT_ATTR_ADD");
opts.erase("OPT_CONNECT_ATTR_DELETE");
opts["OPT_CONNECT_ATTR_ADD"]= connectAttrMap;
created_objects.clear();
conn2.reset(driver->connect(opts));
stmt.reset(conn2->createStatement());
res.reset(stmt->executeQuery("SELECT ATTR_NAME, ATTR_VALUE FROM "
"performance_schema.session_account_connect_attrs WHERE "
"ATTR_NAME LIKE '%keymu%' ORDER BY SUBSTRING(ATTR_NAME, 6)+0 ASC;"));
i=0;
while (res->next()) {
skey.str("");
skey << "keymu" << ++i;
ASSERT_EQUALS(res->getString("ATTR_NAME"), skey.str());
ASSERT_EQUALS(res->getString("ATTR_VALUE"), "value");
}
ASSERT(max_count == i);
ASSERT(!res->next());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::connectAttrReset()
{
logMsg("connection::connectAttr - MYSQL_OPT_CONNECT_ATTR_RESET");
int serverVersion= getMySQLVersion(con);
if ( serverVersion < 50606)
{
SKIP("The server does not support tested functionality(cleartext plugin enabling)");
}
try
{
testsuite::Connection conn2;
sql::ConnectOptionsMap opts;
std::map< sql::SQLString, sql::SQLString > connectAttrMap;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
connectAttrMap["keyd1"]="value1";
connectAttrMap["keyd2"]="value2";
connectAttrMap["keyd3"]="value3";
opts.erase("OPT_CONNECT_ATTR_ADD");
opts["OPT_CONNECT_ATTR_ADD"]=connectAttrMap;
opts["OPT_CONNECT_ATTR_RESET"]=0;
created_objects.clear();
conn2.reset(driver->connect(opts));
stmt.reset(conn2->createStatement());
res.reset(stmt->executeQuery("SELECT ATTR_NAME, ATTR_VALUE FROM "
"performance_schema.session_account_connect_attrs WHERE "
"ATTR_NAME LIKE '%keyd%' ORDER BY ATTR_NAME ASC;"));
ASSERT(!res->next());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::connectCharsetDir()
{
try
{
sql::ConnectOptionsMap opts;
sql::SQLString charDir("/tmp/");
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts["charsetDir"]=charDir;
created_objects.clear();
con.reset(driver->connect(opts));
sql::SQLString outDir=con->getClientOption("characterSetDirectory");
ASSERT_EQUALS(charDir, outDir);
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::connectSSLEnforce()
{
try
{
sql::ConnectOptionsMap opts;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts["sslEnforce"]=true;
created_objects.clear();
con.reset(driver->connect(opts));
}
catch (sql::SQLException &e)
{
ASSERT_EQUALS(2026, e.getErrorCode() /*CR_SSL_CONNECTION_ERROR*/);
}
}
void connection::setAuthDir()
{
logMsg("connection::setAuthDir - MYSQL_PLUGIN_DIR");
int serverVersion=getMySQLVersion(con);
if ( serverVersion >= 50703 )
{
SKIP("Server version >= 5.7.3 needed to run this test");
}
try
{
testsuite::Connection conn1;
sql::ConnectOptionsMap opts;
sql::SQLString in_plugin_dir;
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
#ifdef _WIN32
in_plugin_dir=sql::SQLString("C:\test_plugin");
#else
in_plugin_dir=sql::SQLString("\tmp\test_plugin");
#endif //_WIN32
opts["pluginDir"]=in_plugin_dir;
created_objects.clear();
conn1.reset(driver->connect(opts));
sql::SQLString out_plugin_dir=conn1->getClientOption(sql::SQLString("pluginDir"));
ASSERT_EQUALS(in_plugin_dir, out_plugin_dir);
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::setDefaultAuth()
{
logMsg("connection::setDefaultAuth - MYSQL_DEFAULT_AUTH");
int serverVersion=getMySQLVersion(con);
if ( serverVersion < 50703 )
{
SKIP("Server version >= 5.7.3 needed to run this test");
}
try
{
testsuite::Connection conn1;
sql::ConnectOptionsMap opts;
sql::SQLString in_plugin_dir;
sql::SQLString def_auth("test_set_default_password");
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts["defaultAuth"]=def_auth;
created_objects.clear();
try
{
conn1.reset(driver->connect(opts));
}
catch (sql::SQLException &e)
{
/* Error expected as trying to load unknown authentication plugin */
ASSERT_EQUALS(2059, e.getErrorCode()/*CR_AUTH_PLUGIN_CANNOT_LOAD_ERROR*/);
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::localInfile()
{
logMsg("connection::setDefaultAuth - MYSQL_OPT_LOCAL_INFILE");
#ifdef _UNIX_
try
{
testsuite::Connection conn1;
sql::ConnectOptionsMap opts;
sql::SQLString in_plugin_dir;
sql::SQLString schema("test");
std::ofstream infile;
infile.open("test_infile.txt");
infile << "1,\"val1\"\n";
infile << "2,\"val2\"\n";
infile.close();
opts["hostName"]=url;
opts["userName"]=user;
opts["password"]=passwd;
opts["schema"]=schema;
opts["OPT_LOCAL_INFILE"]=1;
created_objects.clear();
conn1.reset(driver->connect(opts));
stmt.reset(conn1->createStatement());
stmt->execute("DROP TABLE IF EXISTS test_local_infile");
stmt->execute("CREATE TABLE test_local_infile(id INT, value VARCHAR(20))");
stmt->execute("LOAD DATA LOCAL INFILE 'test_infile.txt' "
"INTO TABLE test_local_infile FIELDS TERMINATED BY ',' OPTIONALLY "
"ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
res.reset(stmt->executeQuery("SELECT * FROM test_local_infile ORDER BY id ASC;"));
ASSERT(res->next());
ASSERT_EQUALS("1", res->getInt(1));
ASSERT_EQUALS("val1", res->getString(2));
ASSERT(res->next());
ASSERT_EQUALS("2", res->getInt(1));
ASSERT_EQUALS("val2", res->getString(2));
ASSERT(!res->next());
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
#endif //_UNIX_
}
void connection::isValid()
{
logMsg("connection::isValid");
try
{
if (!con->isValid())
{
FAIL("Connection is not active");
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::reconnect()
{
logMsg("connection::connectOptReconnect - OPT_RECONNECT");
logMsg("OPT_RECONNECT disabled");
try
{
try
{
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"]=url;
connection_properties["userName"]=user;
connection_properties["password"]=passwd;
connection_properties["OPT_READ_TIMEOUT"]=1;
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=false;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SELECT sleep(10);"));
FAIL("Connection didn't timed out");
}
catch (sql::SQLException &/*e*/)
{
ASSERT(con->reconnect());
res.reset(stmt->executeQuery("SELECT 1;"));
ASSERT(res->next());
ASSERT_EQUALS(res->getInt(1), 1);
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
logMsg("OPT_RECONNECT enabled");
try
{
try
{
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"]=url;
connection_properties["userName"]=user;
connection_properties["password"]=passwd;
connection_properties["OPT_READ_TIMEOUT"]=1;
connection_properties.erase("OPT_RECONNECT");
connection_properties["OPT_RECONNECT"]=true;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SELECT sleep(10);"));
FAIL("Connection didn't timed out");
}
catch (sql::SQLException &/*e*/)
{
ASSERT(con->reconnect());
res.reset(stmt->executeQuery("SELECT 1;"));
ASSERT(res->next());
ASSERT_EQUALS(res->getInt(1), 1);
}
}
catch (sql::SQLException &e)
{
logErr(e.what());
logErr("SQLState: " + std::string(e.getSQLState()));
fail(e.what(), __FILE__, __LINE__);
}
}
void connection::ssl_mode()
{
logMsg("connection::ssl_mode - OPT_SSL_MODE");
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"]=url;
connection_properties["userName"]=user;
connection_properties["password"]=passwd;
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SHOW GLOBAL VARIABLES LIKE 'tls_version'"));
res->next();
std::string tls_versions = res->getString(2);
std::cout << "TLS VERSIONS: " <<tls_versions << std::endl;
if (tls_versions.empty())
{
SKIP("Server doesn't support SSL connections");
}
res.reset(stmt->executeQuery("SHOW SESSION STATUS LIKE 'Ssl_version'"));
res->next();
ASSERT_EQUALS(0, static_cast<int>(res->getString(2).length()));
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_REQUIRED;
try
{
created_objects.clear();
con.reset(driver->connect(connection_properties));
}
catch (std::exception&)
{
SKIP("Server doesn't support SSL connections");
}
con->setSchema(db);
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SHOW SESSION STATUS LIKE 'Ssl_version'"));
res->next();
ASSERT_GT(0, static_cast<int>(res->getString(2).length()));
stmt->execute("Drop user if exists ssluser");
stmt->execute("CREATE USER 'ssluser' IDENTIFIED BY 'sslpass' require SSL");
stmt->execute("GRANT all on test.* to 'ssluser'");
connection_properties["hostName"]=url;
connection_properties["userName"]="ssluser";
connection_properties["password"]="sslpass";
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_REQUIRED;
created_objects.clear();
con.reset(driver->connect(connection_properties));
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
//only to trigger setssl which changes SSL_MODE
connection_properties["sslCA"] = "invalid_path";
created_objects.clear();
try
{
con.reset(driver->connect(connection_properties));
FAIL("User requires SSL");
} catch (std::exception &e)
{
std::cout << e.what() << std::endl;
}
}
void connection::tls_version()
{
logMsg("connection::tls_version - OPT_TLS_VERSION");
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"]=url;
connection_properties["userName"]=user;
connection_properties["password"]=passwd;
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
created_objects.clear();
con.reset(driver->connect(connection_properties));
con->setSchema(db);
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SHOW GLOBAL VARIABLES LIKE 'tls_version'"));
res->next();
std::string tls_available = res->getString(2);
std::cout << "TLS VERSIONS: " <<tls_available << std::endl;
std::vector<std::string> tls_versions;
size_t begin_pos = 0;
for ( size_t end_pos = tls_available.find_first_of(',',begin_pos);
begin_pos != std::string::npos || end_pos != std::string::npos;
begin_pos = end_pos == std::string::npos ? end_pos : end_pos+1,
end_pos = tls_available.find_first_of(',',begin_pos))
{
tls_versions.push_back(tls_available.substr(begin_pos, end_pos-begin_pos));
}
connection_properties["OPT_SSL_MODE"] = sql::SSL_MODE_REQUIRED;
// Using wrong TLS version... should fail to connect
connection_properties["OPT_TLS_VERSION"] = sql::SQLString("TLSv999");
created_objects.clear();
try
{
con.reset(driver->connect(connection_properties));
FAIL("Wrong TLS version used and still can connect!");
}
catch (sql::SQLException &e)
{
//Should FAIL to connect
}
for (std::vector<std::string>::const_iterator version = tls_versions.begin();
version != tls_versions.end();
++version)
{
connection_properties["OPT_TLS_VERSION"] = sql::SQLString(*version);
created_objects.clear();
try
{
con.reset(driver->connect(connection_properties));
}
catch (sql::SQLException &e)
{
//Server exports TLS_VERSION even if no certs installed...
//So skipping anyway if error on connect
std::cout << "SKIP "<< *version << ": " << e.what() << std::endl;
continue;
}
stmt.reset(con->createStatement());
res.reset(stmt->executeQuery("SHOW SESSION STATUS LIKE 'Ssl_version'"));
res->next();
ASSERT_EQUALS(*version, res->getString(2));
}
}
void connection::cached_sha2_auth()
{
logMsg("connection::auth - MYSQL_OPT_GET_SERVER_PUBLIC_KEY");
if (getMySQLVersion(con) < 80000)
{
SKIP("Server doesn't support caching_sha2_password");
return;
}
try {
stmt->execute("DROP USER 'doomuser'@'%';");
} catch (...) {}
stmt->execute("CREATE USER 'doomuser'@'%' IDENTIFIED WITH caching_sha2_password BY '!sha2user_pass';");
sql::ConnectOptionsMap opts;
opts["hostName"] = url;
opts["userName"] = "doomuser";
opts["password"] = "!sha2user_pass";
opts["OPT_GET_SERVER_PUBLIC_KEY"] = false;
opts["OPT_SSL_MODE"] = sql::SSL_MODE_DISABLED;
try {
// Should fail using unencrypted connection, since we don't have server
// public key
created_objects.clear();
//need to close connection, otherwise will use fast auth!
con->close();
con.reset(driver->connect(opts));
FAIL("caching_sha2_password can't be used on unexcrypted connection");
throw "caching_sha2_password can't be used on unexcrypted connection";
}
catch(std::exception &e)
{
std::stringstream err;
err << "Expected error: ";
err << e.what();
logMsg(err.str());
}
opts["OPT_GET_SERVER_PUBLIC_KEY"] = true;
// Now we can connect using unencrypted connection, since we now can ask for
// the server public key
con.reset(driver->connect(opts));
//Now using fast auth!
con->close();
opts["OPT_GET_SERVER_PUBLIC_KEY"] = false;
con.reset(driver->connect(opts));
// Cleanup
con.reset(getConnection());
stmt.reset(con->createStatement());
stmt->execute("DROP USER 'doomuser'@'%';");
}
} /* namespace connection */
} /* namespace testsuite */
|