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
|
/*
Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
MySQL Connectors. There are special exceptions to the terms and
conditions of the GPLv2 as it is applied to this software, see the
FLOSS License Exception
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
This program 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; version 2 of the License.
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
*/
#include "odbctap.h"
DECLARE_TEST(my_ts)
{
SQLCHAR szTs[50];
TIMESTAMP_STRUCT ts;
SQLLEN len;
ok_sql(hstmt, "DROP TABLE IF EXISTS my_ts");
ok_sql(hstmt, "CREATE TABLE my_ts (ts TIMESTAMP)");
/* insert using SQL_C_CHAR to SQL_TIMESTAMP */
strcpy((char *)szTs, "2002-01-07 10:20:49.06");
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_C_CHAR, SQL_TIMESTAMP,
0, 0, szTs, sizeof(szTs), NULL));
ok_sql(hstmt, "INSERT INTO my_ts (ts) VALUES (?)");
ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_RESET_PARAMS));
ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE));
ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE,
(SQLPOINTER)SQL_CURSOR_KEYSET_DRIVEN, 0));
/* insert using SQL_C_TIMESTAMP to SQL_TIMESTAMP */
ts.year= 2002;
ts.month= 1;
ts.day= 7;
ts.hour= 19;
ts.minute= 47;
ts.second= 59;
ts.fraction= 4;
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_C_TIMESTAMP, SQL_TIMESTAMP,
0, 0, &ts, sizeof(ts), NULL));
ok_sql(hstmt, "INSERT INTO my_ts (ts) VALUES (?)");
ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_RESET_PARAMS));
ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE));
/* now fetch and verify the results .. */
ok_sql(hstmt, "SELECT * FROM my_ts");
/* now fetch first row */
ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 1));
ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, szTs, sizeof(szTs), &len));
is_str(szTs, "2002-01-07 10:20:49", len);
printf("# row1 using SQL_C_CHAR: %s (%ld)\n", szTs, len);
ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 1));
ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &len));
is_num(ts.year, 2002);
is_num(ts.month, 1);
is_num(ts.day, 7);
is_num(ts.hour, 10);
is_num(ts.minute,20);
is_num(ts.second,49);
printf("# row1 using SQL_C_TIMESTAMP: %d-%d-%d %d:%d:%d.%d (%ld)\n",
ts.year, ts.month,ts.day, ts.hour, ts.minute, ts.second, ts.fraction,
len);
ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 2));
ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, szTs, sizeof(szTs), &len));
is_str(szTs, "2002-01-07 19:47:59", len);
printf("# row2 using SQL_C_CHAR: %s(%ld)\n", szTs, len);
ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 2));
ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &len));
is_num(ts.year, 2002);
is_num(ts.month, 1);
is_num(ts.day, 7);
is_num(ts.hour, 19);
is_num(ts.minute,47);
is_num(ts.second,59);
printf("# row2 using SQL_C_TIMESTAMP: %d-%d-%d %d:%d:%d.%d (%ld)\n",
ts.year, ts.month,ts.day, ts.hour, ts.minute, ts.second, ts.fraction,
len);
expect_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 3),
SQL_NO_DATA_FOUND);
ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS my_ts");
return OK;
}
DECLARE_TEST(t_tstotime)
{
SQLRETURN rc;
SQL_TIMESTAMP_STRUCT ts;
ts.day = 02;
ts.month = 8;
ts.year = 2001;
ts.hour = 18;
ts.minute = 20;
ts.second = 45;
ts.fraction = 05;
ok_sql(hstmt, "DROP TABLE IF EXISTS t_tstotime");
rc = SQLTransact(NULL,hdbc,SQL_COMMIT);
mycon(hdbc,rc);
rc = tmysql_exec(hstmt,"create table t_tstotime(col1 date ,col2 time, col3 timestamp)");
mystmt(hstmt,rc);
rc = SQLTransact(NULL,hdbc,SQL_COMMIT);
mycon(hdbc,rc);
rc = SQLFreeStmt(hstmt,SQL_CLOSE);
mystmt(hstmt,rc);
/* TIMESTAMP TO DATE, TIME and TS CONVERSION */
rc = SQLPrepare(hstmt, (SQLCHAR *)"insert into t_tstotime(col1,col2,col3) values(?,?,?)",SQL_NTS);
mystmt(hstmt,rc);
rc = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_TIMESTAMP,
SQL_DATE,0,0,&ts,sizeof(ts),NULL);
mystmt(hstmt,rc);
rc = SQLBindParameter(hstmt,2,SQL_PARAM_INPUT,SQL_C_TIMESTAMP,
SQL_TIME,0,0,&ts,sizeof(ts),NULL);
mystmt(hstmt,rc);
rc = SQLBindParameter(hstmt,3,SQL_PARAM_INPUT,SQL_C_TIMESTAMP,
SQL_TIMESTAMP,0,0,&ts,sizeof(ts),NULL);
mystmt(hstmt,rc);
rc = SQLExecute(hstmt);
mystmt(hstmt,rc);
rc = SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
mystmt(hstmt,rc);
rc = SQLFreeStmt(hstmt,SQL_CLOSE);
mystmt(hstmt,rc);
rc = SQLTransact(NULL,hdbc,SQL_COMMIT);
mycon(hdbc,rc);
rc = tmysql_exec(hstmt,"select * from t_tstotime");
mystmt(hstmt,rc);
my_assert( 1 == myresult(hstmt));
rc = SQLFreeStmt(hstmt,SQL_UNBIND);
mystmt(hstmt,rc);
rc = SQLFreeStmt(hstmt,SQL_CLOSE);
mystmt(hstmt,rc);
ok_sql(hstmt, "DROP TABLE IF EXISTS t_tstotime");
return OK;
}
DECLARE_TEST(t_tstotime1)
{
SQLCHAR ts[40]= "2001-08-02 18:20:45.05";
ok_sql(hstmt,"DROP TABLE IF EXISTS t_tstotime1");
ok_sql(hstmt,
"CREATE TABLE t_tstotime1(col1 DATE, col2 TIME, col3 TIMESTAMP)");
ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE));
/* TIMESTAMP TO DATE, TIME and TS CONVERSION */
ok_stmt(hstmt, SQLPrepare(hstmt,
(SQLCHAR *)"INSERT INTO t_tstotime1 VALUES (?,?,?)",
SQL_NTS));
ok_stmt(hstmt, SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,
SQL_DATE,0,0,&ts,sizeof(ts),NULL));
ok_stmt(hstmt, SQLBindParameter(hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,
SQL_TIME,0,0,&ts,sizeof(ts),NULL));
ok_stmt(hstmt, SQLBindParameter(hstmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,
SQL_TIMESTAMP,0,0,&ts,sizeof(ts),NULL));
ok_stmt(hstmt, SQLExecute(hstmt));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_con(hdbc, SQLTransact(NULL,hdbc,SQL_COMMIT));
ok_sql(hstmt, "SELECT * FROM t_tstotime1");
my_assert(1 == myresult(hstmt));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_tstotime1");
return OK;
}
DECLARE_TEST(t_bug25846)
{
SQLSMALLINT column_count;
SQLLEN my_time_cb;
SQLLEN my_date_cb;
SQL_TIMESTAMP_STRUCT my_time_ts;
SQL_TIMESTAMP_STRUCT my_date_ts;
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug25846");
ok_sql(hstmt, "CREATE TABLE t_bug25846 (a TIME, b DATE)");
ok_sql(hstmt, "INSERT INTO t_bug25846 VALUES ('02:56:30', '1969-07-21')");
ok_sql(hstmt, "SELECT * FROM t_bug25846");
ok_stmt(hstmt, SQLNumResultCols(hstmt, &column_count));
is_num(column_count, 2);
/* Bind the TIMESTAMP buffer for TIME column */
ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_TIMESTAMP, &my_time_ts,
sizeof(my_time_ts), &my_time_cb));
/* Bind the TIMESTAMP buffer for DATE column */
ok_stmt(hstmt, SQLBindCol(hstmt, 2, SQL_C_TIMESTAMP, &my_date_ts,
sizeof(my_date_ts), &my_date_cb));
ok_stmt(hstmt, SQLFetch(hstmt));
is_num(my_time_ts.hour, 2);
is_num(my_time_ts.minute, 56);
is_num(my_time_ts.second, 30);
is_num(my_date_ts.year, 1969);
is_num(my_date_ts.month, 7);
is_num(my_date_ts.day, 21);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug25846");
return OK;
}
DECLARE_TEST(t_time)
{
SQLRETURN rc;
SQL_TIME_STRUCT tm;
SQLCHAR str[20];
ok_sql(hstmt, "DROP TABLE IF EXISTS t_time");
rc = tmysql_exec(hstmt,"create table t_time(tm time, ts timestamp)");
mystmt(hstmt,rc);
rc = SQLTransact(NULL,hdbc,SQL_COMMIT);
mycon(hdbc,rc);
ok_stmt(hstmt, SQLPrepare(hstmt,
(SQLCHAR *)"insert into t_time values (?,?)",
SQL_NTS));
rc = SQLBindParameter( hstmt, 1, SQL_PARAM_INPUT, SQL_C_TIME,
SQL_TIME, 0, 0, &tm, 0, NULL );
mystmt(hstmt,rc);
rc = SQLBindParameter( hstmt, 2, SQL_PARAM_INPUT, SQL_C_TIME,
SQL_TIMESTAMP, 0, 0, &tm, 15, NULL );
mystmt(hstmt,rc);
tm.hour = 20;
tm.minute = 59;
tm.second = 45;
rc = SQLExecute(hstmt);
mystmt(hstmt,rc);
rc = SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
mystmt(hstmt,rc);
rc = SQLFreeStmt(hstmt,SQL_CLOSE);
mystmt(hstmt,rc);
rc = SQLTransact(NULL,hdbc,SQL_COMMIT);
mycon(hdbc,rc);
ok_sql(hstmt, "select tm from t_time");
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt,1,SQL_C_CHAR,&str,100,NULL);
mystmt(hstmt,rc);
is_str(str, "20:59:45", 9);
rc = SQLFetch(hstmt);
my_assert(rc == SQL_NO_DATA_FOUND);
rc = SQLFreeStmt(hstmt,SQL_UNBIND);
mystmt(hstmt,rc);
rc = SQLFreeStmt(hstmt,SQL_CLOSE);
mystmt(hstmt,rc);
ok_sql(hstmt, "DROP TABLE IF EXISTS t_time");
return OK;
}
/* Test for a simple time struct */
DECLARE_TEST(t_time1)
{
SQLRETURN rc;
SQL_TIME_STRUCT tt;
SQLCHAR data[30];
SQLLEN length;
ok_sql(hstmt, "DROP TABLE IF EXISTS t_time");
ok_sql(hstmt, "create table t_time(t time, t1 timestamp, t2 datetime, t3 date)");
ok_stmt(hstmt, SQLPrepare(hstmt,
(SQLCHAR *)"insert into t_time(t) values(?)",
SQL_NTS));
rc = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_TYPE_TIME,
SQL_TIME,0,0,&tt,0,NULL);
tt.hour= 00;
tt.minute= 00;
tt.second= 03;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 01;
tt.minute= 00;
tt.second= 00;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 19;
tt.minute= 00;
tt.second= 00;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 01;
tt.minute= 01;
tt.second= 00;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 01;
tt.minute= 00;
tt.second= 01;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 00;
tt.minute= 01;
tt.second= 00;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 00;
tt.minute= 11;
tt.second= 12;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 01;
tt.minute= 01;
tt.second= 01;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 00;
tt.minute= 00;
tt.second= 00;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
tt.hour= 10;
tt.minute= 11;
tt.second= 12;
rc = SQLExecute(hstmt);
mystmt(hstmt, rc);
SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
SQLFreeStmt(hstmt, SQL_CLOSE);
ok_sql(hstmt, "select t from t_time");
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "00:00:03", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "01:00:00", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "19:00:00", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "01:01:00", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "01:00:01", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "00:01:00", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "00:11:12", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "01:01:01", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "00:00:00", 9);
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &length);
mystmt(hstmt,rc);
is_num(length, 8);
is_str(data, "10:11:12", 9);
rc = SQLFetch(hstmt);
myassert(rc == SQL_NO_DATA);
SQLFreeStmt(hstmt, SQL_UNBIND);
SQLFreeStmt(hstmt, SQL_CLOSE);
ok_sql(hstmt,"delete from t_time");
ok_sql(hstmt, "insert into t_time(t1) values('2003-05-12 10:11:12')");
ok_sql(hstmt, "select t1 from t_time");
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_TIME, &tt, sizeof(tt), &length);
mystmt(hstmt,rc);
is_num(tt.hour, 10);
is_num(tt.minute, 11);
is_num(tt.second, 12);
is_num(length, sizeof(SQL_TIME_STRUCT));
rc = SQLFetch(hstmt);
myassert(rc == SQL_NO_DATA);
SQLFreeStmt(hstmt, SQL_UNBIND);
SQLFreeStmt(hstmt, SQL_CLOSE);
ok_sql(hstmt,"delete from t_time");
ok_sql(hstmt,"insert into t_time(t2) values('03-12-28 05:59:59')");
ok_sql(hstmt,"select t2 from t_time");
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_TIME, &tt, sizeof(tt), &length);
mystmt(hstmt,rc);
is_num(tt.hour, 05);
is_num(tt.minute, 59);
is_num(tt.second, 59);
is_num(length, sizeof(SQL_TIME_STRUCT));
rc = SQLFetch(hstmt);
is_num(rc, SQL_NO_DATA);
SQLFreeStmt(hstmt, SQL_UNBIND);
SQLFreeStmt(hstmt, SQL_CLOSE);
ok_sql(hstmt,"delete from t_time");
ok_sql(hstmt,"insert into t_time(t3) values('2003-05-12 10:11:12')");
ok_sql(hstmt,"select t3 from t_time");
rc = SQLFetch(hstmt);
mystmt(hstmt,rc);
rc = SQLGetData(hstmt, 1, SQL_C_TIME, &tt, sizeof(tt), &length);
mystmt(hstmt,rc);
is(tt.hour == 00 || tt.minute == 00 || tt.second == 00);
is_num(length, sizeof(SQL_TIME_STRUCT));
rc = SQLFetch(hstmt);
myassert(rc == SQL_NO_DATA);
SQLFreeStmt(hstmt, SQL_UNBIND);
SQLFreeStmt(hstmt, SQL_CLOSE);
ok_sql(hstmt, "DROP TABLE IF EXISTS t_time");
return OK;
}
/**
Bug #12520: DATETIME Default Value 0000-00-00 00:00:00 not returning
correct thru ODBC
*/
DECLARE_TEST(t_bug12520)
{
SQL_TIMESTAMP_STRUCT my_time_ts;
SQLLEN len, my_time_cb;
SQLCHAR datetime[50];
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug12520");
ok_sql(hstmt,
"CREATE TABLE t_bug12520 (a DATETIME DEFAULT '0000-00-00 00:00',"
"b DATETIME DEFAULT '0000-00-00 00:00', c INT)");
ok_sql(hstmt, "INSERT INTO t_bug12520 (c) VALUES (1)");
ok_sql(hstmt, "SELECT a, b FROM t_bug12520");
ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_CHAR, datetime, sizeof(datetime),
&len));
ok_stmt(hstmt, SQLBindCol(hstmt, 2, SQL_C_TIMESTAMP, &my_time_ts, 0,
&my_time_cb));
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(datetime, "0000-00-00 00:00:00", 19);
is_num(my_time_cb, SQL_NULL_DATA);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug12520");
return OK;
}
/**
Bug #15773: Wrong between results
*/
DECLARE_TEST(t_bug15773)
{
SQL_DATE_STRUCT a,b,c,d;
SQLLEN len1;
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug15773");
ok_sql(hstmt, "CREATE TABLE t_bug15773("
"`a` varchar(255) NOT NULL default '',"
"`b` datetime NOT NULL default '0000-00-00 00:00:00',"
"`c` datetime NOT NULL default '0000-00-00 00:00:00'"
") ENGINE=InnoDB DEFAULT CHARSET=latin1");
ok_sql(hstmt, "INSERT INTO t_bug15773 VALUES ('a', '2005-12-24 00:00:00', '2008-05-12 00:00:00')");
ok_sql(hstmt, "INSERT INTO t_bug15773 VALUES ('b', '2004-01-01 00:00:00', '2005-01-01 00:00:00')");
ok_sql(hstmt, "INSERT INTO t_bug15773 VALUES ('c', '2004-12-12 00:00:00', '2005-12-12 00:00:00')");
ok_stmt(hstmt, SQLPrepare(hstmt, (SQLCHAR *)"SELECT * FROM t_bug15773"
" WHERE (?) BETWEEN b AND c", SQL_NTS));
d.day= 15;
d.month= 12;
d.year = 2005;
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TYPE_DATE,
SQL_TYPE_DATE, 0, 0, &d, 0, NULL));
ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_CHAR, &a, 255, &len1));
ok_stmt(hstmt, SQLBindCol(hstmt, 2, SQL_C_TYPE_DATE, &b, 0, &len1));
ok_stmt(hstmt, SQLBindCol(hstmt, 3, SQL_C_TYPE_DATE, &c, 0, &len1));
ok_stmt(hstmt, SQLExecute(hstmt));
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug15773");
return OK;
}
/**
Bug #9927: Updating datetime columns
*/
DECLARE_TEST(t_bug9927)
{
SQLCHAR col[10];
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug9927");
ok_sql(hstmt,
"CREATE TABLE t_bug9927 (a TIMESTAMP DEFAULT 0,"
"b TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)");
ok_stmt(hstmt, SQLSpecialColumns(hstmt,SQL_ROWVER, NULL, 0,
NULL, 0, (SQLCHAR *)"t_bug9927", SQL_NTS,
0, SQL_NO_NULLS));
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 2), "b", 1);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug9927");
return OK;
}
/**
Bug #30081: Can't distinguish between auto-set TIMESTAMP and auto-updated
TIMESTAMP
*/
DECLARE_TEST(t_bug30081)
{
if (!mysql_min_version(hdbc, "5.1.23", 6))
skip("necessary feature added in MySQL 5.1.23");
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug30081");
ok_sql(hstmt,
"CREATE TABLE t_bug30081 (a TIMESTAMP DEFAULT 0,"
"b TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
ok_stmt(hstmt, SQLSpecialColumns(hstmt,SQL_ROWVER, NULL, 0,
NULL, 0, (SQLCHAR *)"t_bug30081", SQL_NTS,
0, SQL_NO_NULLS));
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug30081");
return OK;
}
/**
Verify that we get correct data for SQL_DATA_TYPE and SQL_DATETIME_SUB
from SQLColumns(). Also check SQL_DESC_TYPE from SQLColAttribute().
*/
DECLARE_TEST(t_datecolumns)
{
SQLCHAR col[10];
SQLLEN type;
ok_sql(hstmt, "DROP TABLE IF EXISTS t_datecolumns");
ok_sql(hstmt,
"CREATE TABLE t_datecolumns(a TIMESTAMP, b DATETIME, c DATE, d TIME)");
ok_stmt(hstmt, SQLColumns(hstmt, NULL, 0, NULL, 0,
(SQLCHAR *)"t_datecolumns", SQL_NTS, NULL, 0));
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 4), "a", 1);
is_num(my_fetch_int(hstmt, 14), SQL_DATETIME);
is_num(my_fetch_int(hstmt, 15), SQL_TYPE_TIMESTAMP);
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 4), "b", 1);
is_num(my_fetch_int(hstmt, 14), SQL_DATETIME);
is_num(my_fetch_int(hstmt, 15), SQL_TYPE_TIMESTAMP);
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 4), "c", 1);
is_num(my_fetch_int(hstmt, 14), SQL_DATETIME);
is_num(my_fetch_int(hstmt, 15), SQL_TYPE_DATE);
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 4), "d", 1);
is_num(my_fetch_int(hstmt, 14), SQL_DATETIME);
is_num(my_fetch_int(hstmt, 15), SQL_TYPE_TIME);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "SELECT * FROM t_datecolumns");
ok_stmt(hstmt, SQLColAttribute(hstmt, 1, SQL_DESC_TYPE, NULL, 0, NULL,
&type));
is_num(type, SQL_DATETIME);
ok_stmt(hstmt, SQLColAttribute(hstmt, 2, SQL_DESC_TYPE, NULL, 0, NULL,
&type));
is_num(type, SQL_DATETIME);
ok_stmt(hstmt, SQLColAttribute(hstmt, 3, SQL_DESC_TYPE, NULL, 0, NULL,
&type));
is_num(type, SQL_DATETIME);
ok_stmt(hstmt, SQLColAttribute(hstmt, 4, SQL_DESC_TYPE, NULL, 0, NULL,
&type));
is_num(type, SQL_DATETIME);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_datecolumns");
return OK;
}
/**
Bug #14414: SQLColumn() does not return timestamp nullable attribute correctly
*/
DECLARE_TEST(t_bug14414)
{
SQLCHAR col[10];
SQLSMALLINT nullable;
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug14414");
ok_sql(hstmt, "CREATE TABLE t_bug14414(a TIMESTAMP, b TIMESTAMP NOT NULL,"
"c TIMESTAMP NULL)");
ok_stmt(hstmt, SQLColumns(hstmt, NULL, 0, NULL, 0,
(SQLCHAR *)"t_bug14414", SQL_NTS, NULL, 0));
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 4), "a", 1);
is_num(my_fetch_int(hstmt, 11), SQL_NULLABLE);
is_str(my_fetch_str(hstmt, col, 18), "YES", 3);
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 4), "b", 1);
is_num(my_fetch_int(hstmt, 11), SQL_NULLABLE);
is_str(my_fetch_str(hstmt, col, 18), "YES", 3);
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, col, 4), "c", 1);
is_num(my_fetch_int(hstmt, 11), SQL_NULLABLE);
is_str(my_fetch_str(hstmt, col, 18), "YES", 3);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
/**
Bug #26108 MyODBC ADO field attributes reporting adFldMayBeNull for
not null columns
*/
ok_sql(hstmt, "SELECT * FROM t_bug14414");
ok_stmt(hstmt, SQLDescribeCol(hstmt, 1, col, sizeof(col), NULL, NULL, NULL,
NULL, &nullable));
is_num(nullable, SQL_NULLABLE);
ok_stmt(hstmt, SQLDescribeCol(hstmt, 2, col, sizeof(col), NULL, NULL, NULL,
NULL, &nullable));
is_num(nullable, SQL_NULLABLE);
ok_stmt(hstmt, SQLDescribeCol(hstmt, 3, col, sizeof(col), NULL, NULL, NULL,
NULL, &nullable));
is_num(nullable, SQL_NULLABLE);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug14414");
return OK;
}
/**
Bug #30939: SQLGetTypeInfo returns 6 instead of 8 for COLUMN_SIZE for
SQL_TYPE_TIME
*/
DECLARE_TEST(t_bug30939)
{
ok_stmt(hstmt, SQLGetTypeInfo(hstmt, SQL_TYPE_TIME));
ok_stmt(hstmt, SQLFetch(hstmt));
is_num(my_fetch_int(hstmt, 3), 8);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA);
return OK;
}
/**
Bug #31009: Wrong SQL_DESC_LITERAL_PREFIX for date-time types
*/
DECLARE_TEST(t_bug31009)
{
SQLCHAR data[20];
SQLSMALLINT len;
SQLLEN dlen;
ok_sql(hstmt, "SELECT CAST('2007-01-13' AS DATE) AS col1");
ok_stmt(hstmt, SQLColAttribute(hstmt, 1, SQL_DESC_LITERAL_PREFIX,
data, sizeof(data), &len, NULL));
is_num(len, 1);
is_str(data, "'", 2);
ok_stmt(hstmt, SQLColAttribute(hstmt, 1, SQL_DESC_LITERAL_SUFFIX,
data, sizeof(data), &len, NULL));
is_num(len, 1);
is_str(data, "'", 2);
ok_stmt(hstmt, SQLFetch(hstmt));
ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, data, sizeof(data), &dlen));
is_num(dlen, 10);
is_str(data, "2007-01-13", 11);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
return OK;
}
/**
Bug #37342: ODBC TIMESTAMP string format not handled properly by ODBC driver
*/
DECLARE_TEST(t_bug37342)
{
SQLCHAR *date= (SQLCHAR *)"{dt '2007-01-13'}";
SQLCHAR *time= (SQLCHAR *)"194759";
SQLCHAR out[30];
TIMESTAMP_STRUCT ts;
SQLLEN len= SQL_NTS;
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_TIMESTAMP, 0, 0, date, 0, &len));
ok_sql(hstmt, "SELECT ? AS foo");
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, out, 1), "2007-01-13", 11);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_TYPE_TIME, 0, 0, time, 0, &len));
ok_sql(hstmt, "SELECT ? AS foo");
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, out, 1), "19:47:59", 9);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TIMESTAMP,
SQL_TYPE_TIME, 0, 0, &ts, sizeof(ts), NULL));
ts.hour= 19;
ts.minute= 47;
ts.second= 59;
ts.fraction= 4;
ok_sql(hstmt, "SELECT ? AS foo");
ok_stmt(hstmt, SQLFetch(hstmt));
is_str(my_fetch_str(hstmt, out, 1), "19:47:59", 9);
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
return OK;
}
BEGIN_TESTS
ADD_TEST(my_ts)
ADD_TEST(t_tstotime)
ADD_TEST(t_tstotime1)
ADD_TEST(t_bug25846)
ADD_TEST(t_time)
ADD_TEST(t_time1)
ADD_TEST(t_bug12520)
ADD_TEST(t_bug15773)
ADD_TEST(t_bug9927)
ADD_TEST(t_bug30081)
ADD_TEST(t_datecolumns)
ADD_TEST(t_bug14414)
ADD_TEST(t_bug30939)
ADD_TEST(t_bug31009)
ADD_TEST(t_bug37342)
END_TESTS
RUN_TESTS
|