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
|
/* Copyright (c) 2011, Monty Program Ab
Copyright (c) 2011, Oleksandr Byelkin
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <ma_dyncol.h>
#include <tap.h>
void test_value_single_null()
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_NULL;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_NULL);
err:
ok(rc, "%s", "NULL");
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_value_single_uint(ulonglong num, const char *name)
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_UINT;
val.x.ulong_value= num;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_UINT) && (res.x.ulong_value == num);
num= res.x.ulong_value;
err:
ok(rc, "%s - %llu", name, num);
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_value_single_sint(longlong num, const char *name)
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_INT;
val.x.long_value= num;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_INT) && (res.x.long_value == num);
num= res.x.ulong_value;
err:
ok(rc, "%s - %lld", name, num);
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_value_single_double(double num, const char *name)
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_DOUBLE;
val.x.double_value= num;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_DOUBLE) && (res.x.double_value == num);
num= res.x.ulong_value;
err:
ok(rc, "%s - %lf", name, num);
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_value_single_decimal(const char *num)
{
char *end= (((char*)num) + strlen(num));
char buff[80];
int rc= FALSE;
int length= 80;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
mariadb_dyncol_prepare_decimal(&val); // special procedure for decimal!!!
if (string2decimal(num, &val.x.decimal.value, &end) != E_DEC_OK)
goto err;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_DECIMAL) &&
(decimal_cmp(&res.x.decimal.value, &val.x.decimal.value) == 0));
decimal2string(&res.x.decimal.value, buff, &length, 0, 0, ' ');
err:
ok(rc, "%s - %s", num, buff);
/* cleanup */
mariadb_dyncol_free(&str);
}
static CHARSET_INFO *charset_list[]=
{
#ifdef HAVE_CHARSET_big5
&my_charset_big5_chinese_ci,
&my_charset_big5_bin,
#endif
#ifdef HAVE_CHARSET_euckr
&my_charset_euckr_korean_ci,
&my_charset_euckr_bin,
#endif
#ifdef HAVE_CHARSET_gb2312
&my_charset_gb2312_chinese_ci,
&my_charset_gb2312_bin,
#endif
#ifdef HAVE_CHARSET_gbk
&my_charset_gbk_chinese_ci,
&my_charset_gbk_bin,
#endif
#ifdef HAVE_CHARSET_latin1
&my_charset_latin1,
&my_charset_latin1_bin,
#endif
#ifdef HAVE_CHARSET_sjis
&my_charset_sjis_japanese_ci,
&my_charset_sjis_bin,
#endif
#ifdef HAVE_CHARSET_tis620
&my_charset_tis620_thai_ci,
&my_charset_tis620_bin,
#endif
#ifdef HAVE_CHARSET_ujis
&my_charset_ujis_japanese_ci,
&my_charset_ujis_bin,
#endif
#ifdef HAVE_CHARSET_utf8
&my_charset_utf8_general_ci,
#ifdef HAVE_UCA_COLLATIONS
&my_charset_utf8_unicode_ci,
#endif
&my_charset_utf8_bin,
#endif
};
void test_value_single_string(const char *string, size_t len,
CHARSET_INFO *cs)
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_STRING;
val.x.string.value.str= (char*)string;
val.x.string.value.length= len;
val.x.string.charset= cs;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_STRING) &&
(res.x.string.value.length == len) &&
(memcmp(res.x.string.value.str, string, len) == 0) &&
(res.x.string.charset->number == cs->number));
err:
ok(rc, "'%s' - '%s' %u %u-%s", string,
res.x.string.value.str, (uint)res.x.string.value.length,
(uint)res.x.string.charset->number, res.x.string.charset->name);
/* cleanup */
val.x.string.value.str= NULL; // we did not allocated it
mariadb_dyncol_free(&str);
}
void test_value_single_date(uint year, uint month, uint day, const char *name)
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_DATE;
val.x.time_value.time_type= MYSQL_TIMESTAMP_DATE;
val.x.time_value.year= year;
val.x.time_value.month= month;
val.x.time_value.day= day;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_DATE) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_DATE) &&
(res.x.time_value.year == year) &&
(res.x.time_value.month == month) &&
(res.x.time_value.day == day));
err:
ok(rc, "%s - %04u-%02u-%02u", name, year, month, day);
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_value_single_time(uint neg, uint hour, uint minute, uint second,
uint mic, const char *name)
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_TIME;
val.x.time_value.time_type= MYSQL_TIMESTAMP_TIME;
val.x.time_value.neg= neg;
val.x.time_value.hour= hour;
val.x.time_value.minute= minute;
val.x.time_value.second= second;
val.x.time_value.second_part= mic;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_TIME) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_TIME) &&
(res.x.time_value.neg == (int)neg) &&
(res.x.time_value.hour == hour) &&
(res.x.time_value.minute == minute) &&
(res.x.time_value.second == second) &&
(res.x.time_value.second_part == mic));
err:
ok(rc, "%s - %c%02u:%02u:%02u.%06u", name, (neg ? '-' : '+'),
hour, minute, second, mic);
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_value_single_datetime(uint neg, uint year, uint month, uint day,
uint hour, uint minute, uint second,
uint mic, const char *name)
{
int rc= FALSE;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_DATETIME;
val.x.time_value.time_type= MYSQL_TIMESTAMP_DATETIME;
val.x.time_value.neg= neg;
val.x.time_value.year= year;
val.x.time_value.month= month;
val.x.time_value.day= day;
val.x.time_value.hour= hour;
val.x.time_value.minute= minute;
val.x.time_value.second= second;
val.x.time_value.second_part= mic;
mariadb_dyncol_value_init(&res);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_DATETIME) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) &&
(res.x.time_value.neg == (int)neg) &&
(res.x.time_value.year == year) &&
(res.x.time_value.month == month) &&
(res.x.time_value.day == day) &&
(res.x.time_value.hour == hour) &&
(res.x.time_value.minute == minute) &&
(res.x.time_value.second == second) &&
(res.x.time_value.second_part == mic));
err:
ok(rc, "%s - %c %04u-%02u-%02u %02u:%02u:%02u.%06u", name, (neg ? '-' : '+'),
year, month, day, hour, minute, second, mic);
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_value_multi(ulonglong num0,
longlong num1,
double num2,
const char *num3,
const char *string4, size_t len4, CHARSET_INFO *cs4,
uint year5, uint month5, uint day5,
uint neg6, uint hour6, uint minute6,
uint second6, uint mic6,
uint neg7, uint year7, uint month7, uint day7,
uint hour7, uint minute7, uint second7,
uint mic7,
uint *column_numbers,
const char *name)
{
char *end3= (((char*)num3) + strlen(num3));
int rc= FALSE;
uint i;
DYNAMIC_COLUMN_VALUE val[9], res[9];
DYNAMIC_COLUMN str;
/* init values */
val[0].type= DYN_COL_UINT;
val[0].x.ulong_value= num0;
val[1].type= DYN_COL_INT;
val[1].x.long_value= num1;
val[2].type= DYN_COL_DOUBLE;
val[2].x.double_value= num2;
mariadb_dyncol_prepare_decimal(val + 3); // special procedure for decimal!!!
if (string2decimal(num3, &val[3].x.decimal.value, &end3) != E_DEC_OK)
goto err;
val[4].type= DYN_COL_STRING;
val[4].x.string.value.str= (char*)string4;
val[4].x.string.value.length= len4;
val[4].x.string.charset= cs4;
val[5].type= DYN_COL_DATE;
val[5].x.time_value.time_type= MYSQL_TIMESTAMP_DATE;
val[5].x.time_value.year= year5;
val[5].x.time_value.month= month5;
val[5].x.time_value.day= day5;
val[6].type= DYN_COL_TIME;
val[6].x.time_value.time_type= MYSQL_TIMESTAMP_TIME;
val[6].x.time_value.neg= neg6;
val[6].x.time_value.hour= hour6;
val[6].x.time_value.minute= minute6;
val[6].x.time_value.second= second6;
val[6].x.time_value.second_part= mic6;
val[7].type= DYN_COL_DATETIME;
val[7].x.time_value.time_type= MYSQL_TIMESTAMP_DATETIME;
val[7].x.time_value.neg= neg7;
val[7].x.time_value.year= year7;
val[7].x.time_value.month= month7;
val[7].x.time_value.day= day7;
val[7].x.time_value.hour= hour7;
val[7].x.time_value.minute= minute7;
val[7].x.time_value.second= second7;
val[7].x.time_value.second_part= mic7;
val[8].type= DYN_COL_NULL;
for (i= 0; i < 9; i++)
mariadb_dyncol_value_init(res + i);
/* create column */
if (mariadb_dyncol_create_many_num(&str, 9, column_numbers, val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
for (i= 0; i < 9; i++)
if (mariadb_dyncol_get_num(&str, column_numbers[i], res + i))
goto err;
rc= ((res[0].type == DYN_COL_UINT) &&
(res[0].x.ulong_value == num0) &&
(res[1].type == DYN_COL_INT) &&
(res[1].x.long_value == num1) &&
(res[2].type == DYN_COL_DOUBLE) &&
(res[2].x.double_value == num2) &&
(res[3].type == DYN_COL_DECIMAL) &&
(decimal_cmp(&res[3].x.decimal.value, &val[3].x.decimal.value) == 0) &&
(res[4].type == DYN_COL_STRING) &&
(res[4].x.string.value.length == len4) &&
(memcmp(res[4].x.string.value.str, string4, len4) == 0) &&
(res[4].x.string.charset->number == cs4->number) &&
(res[5].type == DYN_COL_DATE) &&
(res[5].x.time_value.time_type == MYSQL_TIMESTAMP_DATE) &&
(res[5].x.time_value.year == year5) &&
(res[5].x.time_value.month == month5) &&
(res[5].x.time_value.day == day5) &&
(res[6].type == DYN_COL_TIME) &&
(res[6].x.time_value.time_type == MYSQL_TIMESTAMP_TIME) &&
(res[6].x.time_value.neg == (int)neg6) &&
(res[6].x.time_value.hour == hour6) &&
(res[6].x.time_value.minute == minute6) &&
(res[6].x.time_value.second == second6) &&
(res[6].x.time_value.second_part == mic6) &&
(res[7].type == DYN_COL_DATETIME) &&
(res[7].x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) &&
(res[7].x.time_value.neg == (int)neg7) &&
(res[7].x.time_value.year == year7) &&
(res[7].x.time_value.month == month7) &&
(res[7].x.time_value.day == day7) &&
(res[7].x.time_value.hour == hour7) &&
(res[7].x.time_value.minute == minute7) &&
(res[7].x.time_value.second == second7) &&
(res[7].x.time_value.second_part == mic7) &&
(res[8].type == DYN_COL_NULL));
err:
ok(rc, "%s", name);
/* cleanup */
val[4].x.string.value.str= NULL; // we did not allocated it
mariadb_dyncol_free(&str);
}
void test_value_multi_same_num()
{
int rc= FALSE;
uint i;
DYNAMIC_COLUMN_VALUE val[5];
uint column_numbers[]= {3,4,5,3,6}; // same column numbers
DYNAMIC_COLUMN str;
/* init values */
for (i= 0; i < 5; i++)
val[i].type= DYN_COL_NULL;
/* create column */
if (!mariadb_dyncol_create_many_num(&str, 5, column_numbers, val, 1))
goto err;
rc= TRUE;
err:
ok(rc, "%s", "same column numbers check");
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_update_multi(uint *column_numbers, uint *column_values,
my_bool *null_values, int only_add, int all)
{
int rc= FALSE;
int i, j;
DYNAMIC_COLUMN str;
DYNAMIC_COLUMN_VALUE val;
val.type= DYN_COL_UINT;
val.x.ulong_value= column_values[0];
if (mariadb_dyncol_create_many_num(&str, 1, column_numbers, &val, 1))
goto err;
for (i= 1; i < all; i++)
{
val.type= (null_values[i] ? DYN_COL_NULL : DYN_COL_UINT);
val.x.ulong_value= column_values[i];
if (mariadb_dyncol_update_many_num(&str, 1, column_numbers +i, &val))
goto err;
/* check value(s) */
for (j= i; j >= (i < only_add ? 0 : i); j--)
{
if (mariadb_dyncol_get_num(&str, column_numbers[j], &val))
goto err;
if (null_values[j])
{
if (val.type != DYN_COL_NULL ||
mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_YES)
goto err;
}
else
{
if (val.type != DYN_COL_UINT ||
val.x.ulong_value != column_values[j] ||
mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_NO)
goto err;
}
}
if (i < only_add)
{
uint elements, *num;
if (mariadb_dyncol_list_num(&str, &elements, &num))
{
my_free(num);
goto err;
}
/* cross check arrays */
if ((int)elements != i + 1)
{
my_free(num);
goto err;
}
for(j= 0; j < i + 1; j++)
{
int k;
for(k= 0;
k < i + 1 && column_numbers[j] != num[k];
k++);
if (k >= i + 1)
{
my_free(num);
goto err;
}
for(k= 0;
k < i + 1 && column_numbers[k] != num[j];
k++);
if (k >= i + 1)
{
my_free(num);
goto err;
}
}
my_free(num);
}
}
rc= TRUE;
err:
ok(rc, "%s", "add/delete/update");
/* cleanup */
mariadb_dyncol_free(&str);
}
void test_empty_string()
{
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
uint *array_of_uint;
uint number_of_uint;
int rc;
uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE vals[1];
/* empty string */
bzero(&str, sizeof(str));
rc= mariadb_dyncol_get_num(&str, 1, &res);
ok( (rc == ER_DYNCOL_OK) && (res.type == DYN_COL_NULL), "%s", "empty get");
vals[0].type= DYN_COL_NULL;
rc= mariadb_dyncol_update_many_num(&str, 1, ids, vals);
ok( (rc == ER_DYNCOL_OK) && (str.str == 0), "%s", "empty delete");
rc= mariadb_dyncol_exists_num(&str, 1);
ok( (rc == ER_DYNCOL_NO), "%s", "empty exists");
rc= mariadb_dyncol_list_num(&str, &number_of_uint, &array_of_uint);
ok( (rc == ER_DYNCOL_OK) && (number_of_uint == 0) && (str.str == 0),
"%s", "empty list");
val.type= DYN_COL_UINT;
val.x.ulong_value= 1212;
rc= mariadb_dyncol_update_many_num(&str, 1, ids, &val);
if (rc == ER_DYNCOL_OK)
rc= mariadb_dyncol_get_num(&str, 1, &res);
ok( (rc == ER_DYNCOL_OK) && (str.str != 0) &&
(res.type == DYN_COL_UINT) && (res.x.ulong_value == val.x.ulong_value),
"%s", "empty update");
mariadb_dyncol_free(&str);
}
static void test_mdev_4994()
{
DYNAMIC_COLUMN dyncol;
LEX_STRING key= {0,0};
DYNAMIC_COLUMN_VALUE val;
int rc;
val.type= DYN_COL_NULL;
mariadb_dyncol_init(&dyncol);
rc= mariadb_dyncol_create_many_named(&dyncol, 1, &key, &val, 0); /* crash */
ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4994");
mariadb_dyncol_free(&dyncol);
}
static void test_mdev_4995()
{
DYNAMIC_COLUMN dyncol;
uint column_count= 5;
int rc;
mariadb_dyncol_init(&dyncol);
rc= mariadb_dyncol_column_count(&dyncol,&column_count);
ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4995");
}
void test_update_many(uint *column_numbers, uint *column_values,
uint column_count,
uint *update_numbers, uint *update_values,
my_bool *update_nulls, uint update_count,
uint *result_numbers, uint *result_values,
uint result_count)
{
int rc= FALSE;
uint i;
DYNAMIC_COLUMN str1;
DYNAMIC_COLUMN str2;
DYNAMIC_COLUMN_VALUE *val, *upd, *res;
val= (DYNAMIC_COLUMN_VALUE *)malloc(sizeof(DYNAMIC_COLUMN_VALUE) *
column_count);
upd= (DYNAMIC_COLUMN_VALUE *)malloc(sizeof(DYNAMIC_COLUMN_VALUE) *
update_count);
res= (DYNAMIC_COLUMN_VALUE *)malloc(sizeof(DYNAMIC_COLUMN_VALUE) *
result_count);
for (i= 0; i < column_count; i++)
{
val[i].type= DYN_COL_UINT;
val[i].x.ulong_value= column_values[i];
}
for (i= 0; i < update_count; i++)
{
if (update_nulls[i])
upd[i].type= DYN_COL_NULL;
else
{
upd[i].type= DYN_COL_UINT;
upd[i].x.ulong_value= update_values[i];
}
}
for (i= 0; i < result_count; i++)
{
res[i].type= DYN_COL_UINT;
res[i].x.ulong_value= result_values[i];
}
if (mariadb_dyncol_create_many_num(&str1, column_count, column_numbers, val, 1))
goto err;
if (mariadb_dyncol_update_many_num(&str1, update_count, update_numbers, upd))
goto err;
if (mariadb_dyncol_create_many_num(&str2, result_count, result_numbers, res, 1))
goto err;
if (str1.length == str2.length &&
memcmp(str1.str, str2.str, str1.length) ==0)
rc= TRUE;
err:
ok(rc, "%s", "update_many");
/* cleanup */
mariadb_dyncol_free(&str1);
mariadb_dyncol_free(&str2);
}
int main(int argc __attribute__((unused)), char **argv)
{
uint i;
char *big_string= (char *)malloc(1024*1024);
MY_INIT(argv[0]);
plan(62);
if (!big_string)
exit(1);
for (i= 0; i < 1024*1024; i++)
big_string[i]= ('0' + (i % 10));
test_value_single_null();
test_value_single_uint(0, "0");
test_value_single_uint(0xffffffffffffffffULL, "0xffffffffffffffff");
test_value_single_uint(0xaaaaaaaaaaaaaaaaULL, "0xaaaaaaaaaaaaaaaa");
test_value_single_uint(0x5555555555555555ULL, "0x5555555555555555");
test_value_single_uint(27652, "27652");
test_value_single_sint(0, "0");
test_value_single_sint(1, "1");
test_value_single_sint(-1, "-1");
test_value_single_sint(0x7fffffffffffffffLL, "0x7fffffffffffffff");
test_value_single_sint(0xaaaaaaaaaaaaaaaaLL, "0xaaaaaaaaaaaaaaaa");
test_value_single_sint(0x5555555555555555LL, "0x5555555555555555");
test_value_single_sint(0x8000000000000000LL, "0x8000000000000000");
test_value_single_double(0.0, "0.0");
test_value_single_double(1.0, "1.0");
test_value_single_double(-1.0, "-1.0");
test_value_single_double(1.0e100, "1.0e100");
test_value_single_double(1.0e-100, "1.0e-100");
test_value_single_double(9999999999999999999999999999999999999.0,
"9999999999999999999999999999999999999.0");
test_value_single_double(-9999999999999999999999999999999999999.0,
"-9999999999999999999999999999999999999.0");
test_value_single_decimal("0");
test_value_single_decimal("1");
test_value_single_decimal("-1");
test_value_single_decimal("9999999999999999999999999999999");
test_value_single_decimal("-9999999999999999999999999999999");
test_value_single_decimal("0.9999999999999999999999999999999");
test_value_single_decimal("-0.9999999999999999999999999999999");
test_value_single_string("", 0, charset_list[0]);
test_value_single_string("", 1, charset_list[0]);
test_value_single_string("1234567890", 11, charset_list[0]);
test_value_single_string("nulls\0\0\0\0\0", 10, charset_list[0]);
sprintf(big_string, "%x", 0x7a);
test_value_single_string(big_string, 0x7a, charset_list[0]);
sprintf(big_string, "%x", 0x80);
test_value_single_string(big_string, 0x80, charset_list[0]);
sprintf(big_string, "%x", 0x7ffa);
test_value_single_string(big_string, 0x7ffa, charset_list[0]);
sprintf(big_string, "%x", 0x8000);
test_value_single_string(big_string, 0x8000, charset_list[0]);
sprintf(big_string, "%x", 1024*1024);
test_value_single_string(big_string, 1024*1024, charset_list[0]);
test_value_single_date(0, 0, 0, "zero date");
test_value_single_date(9999, 12, 31, "max date");
test_value_single_date(2011, 3, 26, "some date");
test_value_single_time(0, 0, 0, 0, 0, "zero time");
test_value_single_time(1, 23, 59, 59, 999999, "min time");
test_value_single_time(0, 23, 59, 59, 999999, "max time");
test_value_single_time(0, 21, 36, 20, 28, "some time");
test_value_single_datetime(0, 0, 0, 0, 0, 0, 0, 0, "zero datetime");
test_value_single_datetime(1, 9999, 12, 31, 23, 59, 59, 999999,
"min datetime");
test_value_single_datetime(0, 9999, 12, 31, 23, 59, 59, 999999,
"max datetime");
test_value_single_datetime(0, 2011, 3, 26, 21, 53, 12, 3445,
"some datetime");
{
uint column_numbers[]= {100,1,2,3,4,5,6,7,8};
test_value_multi(0, 0, 0.0, "0",
"", 0, charset_list[0],
0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
column_numbers,
"zero data");
}
{
uint column_numbers[]= {10,1,12,37,4,57,6,76,87};
test_value_multi(0xffffffffffffffffULL, 0x7fffffffffffffffLL,
99999999.999e120, "9999999999999999999999999999999",
big_string, 1024*1024, charset_list[0],
9999, 12, 31,
0, 23, 59, 59, 999999,
0, 9999, 12, 31, 23, 59, 59, 999999,
column_numbers,
"much data");
}
free(big_string);
{
uint column_numbers[]= {101,12,122,37,24,572,16,726,77};
test_value_multi(37878, -3344,
2873.3874, "92743.238984789898",
"string", 6, charset_list[0],
2011, 3, 26,
1, 23, 23, 20, 333,
0, 2011, 3, 26, 23, 23, 53, 334,
column_numbers,
"zero data");
}
test_value_multi_same_num();
{
uint column_numbers[]= {1,2,3,4,5,6,7,2, 3, 4};
uint column_values[]= {1,2,3,4,5,6,7,0,30,40};
my_bool null_values[]= {0,0,0,0,0,0,0,1, 0, 0};
test_update_multi(column_numbers, column_values, null_values, 7, 10);
}
{
uint column_numbers[]= {4,3,2,1, 1,2,3,4};
uint column_values[]= {4,3,2,1, 0,0,0,0};
my_bool null_values[]= {0,0,0,0, 1,1,1,1};
test_update_multi(column_numbers, column_values, null_values, 4, 8);
}
{
uint column_numbers[]= {4,3,2,1, 4,3,2,1};
uint column_values[]= {4,3,2,1, 0,0,0,0};
my_bool null_values[]= {0,0,0,0, 1,1,1,1};
test_update_multi(column_numbers, column_values, null_values, 4, 8);
}
test_empty_string();
{
uint column_numbers[]= {1, 2, 3};
uint column_values[]= {1, 2, 3};
uint update_numbers[]= {4, 3, 2, 1};
uint update_values[]= {40,30, 0,10};
my_bool update_nulls[]={0, 0, 1, 0};
uint result_numbers[]= {1, 3, 4};
uint result_values[]= {10,30,40};
test_update_many(column_numbers, column_values, 3,
update_numbers, update_values, update_nulls, 4,
result_numbers, result_values, 3);
}
test_mdev_4994();
test_mdev_4995();
my_end(0);
return exit_status();
}
|