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
|
#ifndef ITEM_TIMEFUNC_INCLUDED
#define ITEM_TIMEFUNC_INCLUDED
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates.
Copyright (c) 2009-2011, Monty Program Ab
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 Street, Fifth Floor, Boston, MA 02110-1335 USA */
/* Function items used by mysql */
#ifdef USE_PRAGMA_INTERFACE
#pragma interface /* gcc class implementation */
#endif
class MY_LOCALE;
bool get_interval_value(THD *thd, Item *args,
interval_type int_type, INTERVAL *interval);
class Item_long_func_date_field: public Item_long_func
{
bool check_arguments() const
{ return args[0]->check_type_can_return_date(func_name()); }
public:
Item_long_func_date_field(THD *thd, Item *a)
:Item_long_func(thd, a) { }
};
class Item_long_func_time_field: public Item_long_func
{
bool check_arguments() const
{ return args[0]->check_type_can_return_time(func_name()); }
public:
Item_long_func_time_field(THD *thd, Item *a)
:Item_long_func(thd, a) { }
};
class Item_func_period_add :public Item_long_func
{
bool check_arguments() const
{ return check_argument_types_can_return_int(0, 2); }
public:
Item_func_period_add(THD *thd, Item *a, Item *b): Item_long_func(thd, a, b) {}
longlong val_int();
const char *func_name() const { return "period_add"; }
bool fix_length_and_dec()
{
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
return FALSE;
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_period_add>(thd, this); }
};
class Item_func_period_diff :public Item_long_func
{
bool check_arguments() const
{ return check_argument_types_can_return_int(0, 2); }
public:
Item_func_period_diff(THD *thd, Item *a, Item *b): Item_long_func(thd, a, b) {}
longlong val_int();
const char *func_name() const { return "period_diff"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
return FALSE;
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_period_diff>(thd, this); }
};
class Item_func_to_days :public Item_long_func_date_field
{
public:
Item_func_to_days(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "to_days"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
enum_monotonicity_info get_monotonicity_info() const;
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_to_days>(thd, this); }
};
class Item_func_to_seconds :public Item_longlong_func
{
bool check_arguments() const
{ return check_argument_types_can_return_date(0, arg_count); }
public:
Item_func_to_seconds(THD *thd, Item *a): Item_longlong_func(thd, a) {}
longlong val_int();
const char *func_name() const { return "to_seconds"; }
bool fix_length_and_dec()
{
decimals=0;
fix_char_length(12);
maybe_null= 1;
return FALSE;
}
enum_monotonicity_info get_monotonicity_info() const;
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
bool check_partition_func_processor(void *bool_arg) { return FALSE;}
/* Only meaningful with date part and optional time part */
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_to_seconds>(thd, this); }
};
class Item_func_dayofmonth :public Item_long_func_date_field
{
public:
Item_func_dayofmonth(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "dayofmonth"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_dayofmonth>(thd, this); }
};
class Item_func_month :public Item_long_func
{
public:
Item_func_month(THD *thd, Item *a): Item_long_func(thd, a)
{ }
longlong val_int();
const char *func_name() const { return "month"; }
bool fix_length_and_dec()
{
decimals= 0;
fix_char_length(2);
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_month>(thd, this); }
};
class Item_func_monthname :public Item_str_func
{
MY_LOCALE *locale;
public:
Item_func_monthname(THD *thd, Item *a): Item_str_func(thd, a) {}
const char *func_name() const { return "monthname"; }
String *val_str(String *str);
bool fix_length_and_dec();
bool check_partition_func_processor(void *int_arg) {return TRUE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_monthname>(thd, this); }
};
class Item_func_dayofyear :public Item_long_func_date_field
{
public:
Item_func_dayofyear(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "dayofyear"; }
bool fix_length_and_dec()
{
decimals= 0;
fix_char_length(3);
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_dayofyear>(thd, this); }
};
class Item_func_hour :public Item_long_func_time_field
{
public:
Item_func_hour(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "hour"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_time_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_hour>(thd, this); }
};
class Item_func_minute :public Item_long_func_time_field
{
public:
Item_func_minute(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "minute"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_time_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_minute>(thd, this); }
};
class Item_func_quarter :public Item_long_func_date_field
{
public:
Item_func_quarter(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "quarter"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_quarter>(thd, this); }
};
class Item_func_second :public Item_long_func_time_field
{
public:
Item_func_second(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "second"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_time_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_second>(thd, this); }
};
class Item_func_week :public Item_long_func
{
bool check_arguments() const
{
return args[0]->check_type_can_return_date(func_name()) ||
(arg_count > 1 && args[1]->check_type_can_return_int(func_name()));
}
public:
Item_func_week(THD *thd, Item *a): Item_long_func(thd, a) {}
Item_func_week(THD *thd, Item *a, Item *b): Item_long_func(thd, a, b) {}
longlong val_int();
const char *func_name() const { return "week"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_vcol_func_processor(void *arg)
{
if (arg_count == 2)
return FALSE;
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
bool check_valid_arguments_processor(void *int_arg)
{
return arg_count == 2;
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_week>(thd, this); }
};
class Item_func_yearweek :public Item_long_func
{
bool check_arguments() const
{
return args[0]->check_type_can_return_date(func_name()) ||
args[1]->check_type_can_return_int(func_name());
}
public:
Item_func_yearweek(THD *thd, Item *a, Item *b)
:Item_long_func(thd, a, b) {}
longlong val_int();
const char *func_name() const { return "yearweek"; }
bool fix_length_and_dec()
{
decimals=0;
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_yearweek>(thd, this); }
};
class Item_func_year :public Item_long_func_date_field
{
public:
Item_func_year(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "year"; }
enum_monotonicity_info get_monotonicity_info() const;
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
bool fix_length_and_dec()
{
decimals=0;
max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_year>(thd, this); }
};
class Item_func_weekday :public Item_long_func
{
bool odbc_type;
public:
Item_func_weekday(THD *thd, Item *a, bool type_arg):
Item_long_func(thd, a), odbc_type(type_arg) { }
longlong val_int();
const char *func_name() const
{
return (odbc_type ? "dayofweek" : "weekday");
}
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
{
return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate);
}
bool fix_length_and_dec()
{
decimals= 0;
fix_char_length(1);
maybe_null=1;
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_weekday>(thd, this); }
};
class Item_func_dayname :public Item_str_func
{
MY_LOCALE *locale;
public:
Item_func_dayname(THD *thd, Item *a): Item_str_func(thd, a) {}
const char *func_name() const { return "dayname"; }
String *val_str(String *str);
const Type_handler *type_handler() const { return &type_handler_varchar; }
bool fix_length_and_dec();
bool check_partition_func_processor(void *int_arg) {return TRUE;}
bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_date_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_dayname>(thd, this); }
};
class Item_func_seconds_hybrid: public Item_func_numhybrid
{
public:
Item_func_seconds_hybrid(THD *thd): Item_func_numhybrid(thd) {}
Item_func_seconds_hybrid(THD *thd, Item *a): Item_func_numhybrid(thd, a) {}
void fix_length_and_dec_generic(uint dec)
{
DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
decimals= dec;
max_length=17 + (decimals ? decimals + 1 : 0);
maybe_null= true;
if (decimals)
set_handler(&type_handler_newdecimal);
else
set_handler(type_handler_long_or_longlong());
}
double real_op() { DBUG_ASSERT(0); return 0; }
String *str_op(String *str) { DBUG_ASSERT(0); return 0; }
bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
{
DBUG_ASSERT(0);
return true;
}
};
class Item_func_unix_timestamp :public Item_func_seconds_hybrid
{
bool get_timestamp_value(my_time_t *seconds, ulong *second_part);
public:
Item_func_unix_timestamp(THD *thd): Item_func_seconds_hybrid(thd) {}
Item_func_unix_timestamp(THD *thd, Item *a):
Item_func_seconds_hybrid(thd, a) {}
const char *func_name() const { return "unix_timestamp"; }
enum_monotonicity_info get_monotonicity_info() const;
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
bool check_partition_func_processor(void *int_arg) {return FALSE;}
/*
UNIX_TIMESTAMP() depends on the current timezone
(and thus may not be used as a partitioning function)
when its argument is NOT of the TIMESTAMP type.
*/
bool check_valid_arguments_processor(void *int_arg)
{
return !has_timestamp_args();
}
bool check_vcol_func_processor(void *arg)
{
if (arg_count)
return FALSE;
return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
}
bool fix_length_and_dec()
{
fix_length_and_dec_generic(arg_count ?
args[0]->datetime_precision(current_thd) : 0);
return FALSE;
}
longlong int_op();
my_decimal *decimal_op(my_decimal* buf);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_unix_timestamp>(thd, this); }
};
class Item_func_time_to_sec :public Item_func_seconds_hybrid
{
public:
Item_func_time_to_sec(THD *thd, Item *item):
Item_func_seconds_hybrid(thd, item) {}
const char *func_name() const { return "time_to_sec"; }
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_time_args();
}
bool fix_length_and_dec()
{
fix_length_and_dec_generic(args[0]->time_precision(current_thd));
return FALSE;
}
longlong int_op();
my_decimal *decimal_op(my_decimal* buf);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_time_to_sec>(thd, this); }
};
class Item_datefunc :public Item_func
{
public:
Item_datefunc(THD *thd): Item_func(thd) { }
Item_datefunc(THD *thd, Item *a): Item_func(thd, a) { }
Item_datefunc(THD *thd, Item *a, Item *b): Item_func(thd, a, b) { }
const Type_handler *type_handler() const { return &type_handler_newdate; }
longlong val_int() { return Date(this).to_longlong(); }
double val_real() { return Date(this).to_double(); }
String *val_str(String *to) { return Date(this).to_string(to); }
my_decimal *val_decimal(my_decimal *to) { return Date(this).to_decimal(to); }
bool fix_length_and_dec()
{
fix_attributes_date();
maybe_null= (arg_count > 0);
return FALSE;
}
};
class Item_timefunc :public Item_func
{
public:
Item_timefunc(THD *thd): Item_func(thd) {}
Item_timefunc(THD *thd, Item *a): Item_func(thd, a) {}
Item_timefunc(THD *thd, Item *a, Item *b): Item_func(thd, a, b) {}
Item_timefunc(THD *thd, Item *a, Item *b, Item *c): Item_func(thd, a, b ,c) {}
const Type_handler *type_handler() const { return &type_handler_time2; }
longlong val_int() { return Time(this).to_longlong(); }
double val_real() { return Time(this).to_double(); }
String *val_str(String *to) { return Time(this).to_string(to, decimals); }
my_decimal *val_decimal(my_decimal *to) { return Time(this).to_decimal(to); }
bool val_native(THD *thd, Native *to)
{
return Time(thd, this).to_native(to, decimals);
}
};
class Item_datetimefunc :public Item_func
{
public:
Item_datetimefunc(THD *thd): Item_func(thd) {}
Item_datetimefunc(THD *thd, Item *a): Item_func(thd, a) {}
Item_datetimefunc(THD *thd, Item *a, Item *b): Item_func(thd, a, b) {}
Item_datetimefunc(THD *thd, Item *a, Item *b, Item *c):
Item_func(thd, a, b ,c) {}
const Type_handler *type_handler() const { return &type_handler_datetime2; }
longlong val_int() { return Datetime(this).to_longlong(); }
double val_real() { return Datetime(this).to_double(); }
String *val_str(String *to) { return Datetime(this).to_string(to, decimals); }
my_decimal *val_decimal(my_decimal *to) { return Datetime(this).to_decimal(to); }
};
/* Abstract CURTIME function. Children should define what time zone is used */
class Item_func_curtime :public Item_timefunc
{
MYSQL_TIME ltime;
query_id_t last_query_id;
public:
Item_func_curtime(THD *thd, uint dec): Item_timefunc(thd), last_query_id(0)
{ decimals= dec; }
bool fix_fields(THD *, Item **);
bool fix_length_and_dec() { fix_attributes_time(decimals); return FALSE; }
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
/*
Abstract method that defines which time zone is used for conversion.
Converts time current time in my_time_t representation to broken-down
MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
*/
virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0;
bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
}
void print(String *str, enum_query_type query_type);
};
class Item_func_curtime_local :public Item_func_curtime
{
public:
Item_func_curtime_local(THD *thd, uint dec): Item_func_curtime(thd, dec) {}
const char *func_name() const { return "curtime"; }
virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_curtime_local>(thd, this); }
};
class Item_func_curtime_utc :public Item_func_curtime
{
public:
Item_func_curtime_utc(THD *thd, uint dec): Item_func_curtime(thd, dec) {}
const char *func_name() const { return "utc_time"; }
virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_curtime_utc>(thd, this); }
};
/* Abstract CURDATE function. See also Item_func_curtime. */
class Item_func_curdate :public Item_datefunc
{
query_id_t last_query_id;
MYSQL_TIME ltime;
public:
Item_func_curdate(THD *thd): Item_datefunc(thd), last_query_id(0) {}
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0;
bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
}
};
class Item_func_curdate_local :public Item_func_curdate
{
public:
Item_func_curdate_local(THD *thd): Item_func_curdate(thd) {}
const char *func_name() const { return "curdate"; }
void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_curdate_local>(thd, this); }
};
class Item_func_curdate_utc :public Item_func_curdate
{
public:
Item_func_curdate_utc(THD *thd): Item_func_curdate(thd) {}
const char *func_name() const { return "utc_date"; }
void store_now_in_TIME(THD* thd, MYSQL_TIME *now_time);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_curdate_utc>(thd, this); }
};
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
class Item_func_now :public Item_datetimefunc
{
MYSQL_TIME ltime;
query_id_t last_query_id;
public:
Item_func_now(THD *thd, uint dec): Item_datetimefunc(thd), last_query_id(0)
{ decimals= dec; }
bool fix_fields(THD *, Item **);
bool fix_length_and_dec()
{ fix_attributes_datetime(decimals); return FALSE;}
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0;
bool check_vcol_func_processor(void *arg)
{
/*
NOW is safe for replication as slaves will run with same time as
master
*/
return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
}
void print(String *str, enum_query_type query_type);
};
class Item_func_now_local :public Item_func_now
{
public:
Item_func_now_local(THD *thd, uint dec): Item_func_now(thd, dec) {}
const char *func_name() const { return "current_timestamp"; }
int save_in_field(Field *field, bool no_conversions);
virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
virtual enum Functype functype() const { return NOW_FUNC; }
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_now_local>(thd, this); }
};
class Item_func_now_utc :public Item_func_now
{
public:
Item_func_now_utc(THD *thd, uint dec): Item_func_now(thd, dec) {}
const char *func_name() const { return "utc_timestamp"; }
virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
virtual enum Functype functype() const { return NOW_UTC_FUNC; }
virtual bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg,
VCOL_TIME_FUNC | VCOL_NON_DETERMINISTIC);
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_now_utc>(thd, this); }
};
/*
This is like NOW(), but always uses the real current time, not the
query_start(). This matches the Oracle behavior.
*/
class Item_func_sysdate_local :public Item_func_now
{
public:
Item_func_sysdate_local(THD *thd, uint dec): Item_func_now(thd, dec) {}
bool const_item() const { return 0; }
const char *func_name() const { return "sysdate"; }
void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
table_map used_tables() const { return RAND_TABLE_BIT; }
bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg,
VCOL_TIME_FUNC | VCOL_NON_DETERMINISTIC);
}
virtual enum Functype functype() const { return SYSDATE_FUNC; }
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_sysdate_local>(thd, this); }
};
class Item_func_from_days :public Item_datefunc
{
bool check_arguments() const
{ return args[0]->check_type_can_return_int(func_name()); }
public:
Item_func_from_days(THD *thd, Item *a): Item_datefunc(thd, a) {}
const char *func_name() const { return "from_days"; }
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return has_date_args() || has_time_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_from_days>(thd, this); }
};
class Item_func_date_format :public Item_str_func
{
bool check_arguments() const
{
return args[0]->check_type_can_return_date(func_name()) ||
check_argument_types_can_return_text(1, arg_count);
}
const MY_LOCALE *locale;
int fixed_length;
String value;
protected:
bool is_time_format;
public:
Item_func_date_format(THD *thd, Item *a, Item *b):
Item_str_func(thd, a, b), locale(0), is_time_format(false) {}
Item_func_date_format(THD *thd, Item *a, Item *b, Item *c):
Item_str_func(thd, a, b, c), locale(0), is_time_format(false) {}
String *val_str(String *str);
const char *func_name() const { return "date_format"; }
bool fix_length_and_dec();
uint format_length(const String *format);
bool eq(const Item *item, bool binary_cmp) const;
bool check_vcol_func_processor(void *arg)
{
if (arg_count > 2)
return false;
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_date_format>(thd, this); }
};
class Item_func_time_format: public Item_func_date_format
{
public:
Item_func_time_format(THD *thd, Item *a, Item *b):
Item_func_date_format(thd, a, b) { is_time_format= true; }
const char *func_name() const { return "time_format"; }
bool check_vcol_func_processor(void *arg) { return false; }
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_time_format>(thd, this); }
};
class Item_func_from_unixtime :public Item_datetimefunc
{
bool check_arguments() const
{ return args[0]->check_type_can_return_decimal(func_name()); }
Time_zone *tz;
public:
Item_func_from_unixtime(THD *thd, Item *a): Item_datetimefunc(thd, a) {}
const char *func_name() const { return "from_unixtime"; }
bool fix_length_and_dec();
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_from_unixtime>(thd, this); }
};
/*
We need Time_zone class declaration for storing pointers in
Item_func_convert_tz.
*/
class Time_zone;
/*
This class represents CONVERT_TZ() function.
The important fact about this function that it is handled in special way.
When such function is met in expression time_zone system tables are added
to global list of tables to open, so later those already opened and locked
tables can be used during this function calculation for loading time zone
descriptions.
*/
class Item_func_convert_tz :public Item_datetimefunc
{
bool check_arguments() const
{
return args[0]->check_type_can_return_date(func_name()) ||
check_argument_types_can_return_text(1, arg_count);
}
/*
If time zone parameters are constants we are caching objects that
represent them (we use separate from_tz_cached/to_tz_cached members
to indicate this fact, since NULL is legal value for from_tz/to_tz
members.
*/
bool from_tz_cached, to_tz_cached;
Time_zone *from_tz, *to_tz;
public:
Item_func_convert_tz(THD *thd, Item *a, Item *b, Item *c):
Item_datetimefunc(thd, a, b, c), from_tz_cached(0), to_tz_cached(0) {}
const char *func_name() const { return "convert_tz"; }
bool fix_length_and_dec()
{
fix_attributes_datetime(args[0]->datetime_precision(current_thd));
maybe_null= true;
return FALSE;
}
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
void cleanup();
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_convert_tz>(thd, this); }
};
class Item_func_sec_to_time :public Item_timefunc
{
bool check_arguments() const
{ return args[0]->check_type_can_return_decimal(func_name()); }
public:
Item_func_sec_to_time(THD *thd, Item *item): Item_timefunc(thd, item) {}
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
bool fix_length_and_dec()
{
fix_attributes_time(args[0]->decimals);
maybe_null= true;
return FALSE;
}
const char *func_name() const { return "sec_to_time"; }
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_sec_to_time>(thd, this); }
};
class Item_date_add_interval :public Item_handled_func
{
public:
const interval_type int_type; // keep it public
const bool date_sub_interval; // keep it public
Item_date_add_interval(THD *thd, Item *a, Item *b, interval_type type_arg,
bool neg_arg):
Item_handled_func(thd, a, b), int_type(type_arg),
date_sub_interval(neg_arg) {}
const char *func_name() const { return "date_add_interval"; }
bool fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const;
void print(String *str, enum_query_type query_type);
enum precedence precedence() const { return INTERVAL_PRECEDENCE; }
bool need_parentheses_in_default() { return true; }
Item *get_copy(THD *thd)
{ return get_item_copy<Item_date_add_interval>(thd, this); }
};
class Item_extract :public Item_int_func,
public Type_handler_hybrid_field_type
{
date_mode_t m_date_mode;
const Type_handler_int_result *handler_by_length(uint32 length,
uint32 threashold)
{
if (length >= threashold)
return &type_handler_slonglong;
return &type_handler_slong;
}
void set_date_length(uint32 length)
{
/*
Although DATE components (e.g. YEAR, YEAR_MONTH, QUARTER, MONTH, WEEK)
cannot have a sign, we should probably still add +1,
because all around the code we assume that max_length is sign inclusive.
Another options is to set unsigned_flag to "true".
*/
set_handler(handler_by_length(max_length= length, 10)); // QQ: see above
m_date_mode= date_mode_t(0);
}
void set_day_length(uint32 length)
{
/*
Units starting with DAY can be negative:
EXTRACT(DAY FROM '-24:00:00') -> -1
*/
set_handler(handler_by_length(max_length= length + 1/*sign*/, 11));
m_date_mode= Temporal::Options(TIME_INTERVAL_DAY, current_thd);
}
void set_time_length(uint32 length)
{
set_handler(handler_by_length(max_length= length + 1/*sign*/, 11));
m_date_mode= Temporal::Options(TIME_INTERVAL_hhmmssff, current_thd);
}
public:
const interval_type int_type; // keep it public
Item_extract(THD *thd, interval_type type_arg, Item *a):
Item_int_func(thd, a),
Type_handler_hybrid_field_type(&type_handler_slonglong),
m_date_mode(date_mode_t(0)),
int_type(type_arg)
{ }
const Type_handler *type_handler() const
{
return Type_handler_hybrid_field_type::type_handler();
}
longlong val_int();
enum Functype functype() const { return EXTRACT_FUNC; }
const char *func_name() const { return "extract"; }
bool check_arguments() const;
bool fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const;
void print(String *str, enum_query_type query_type);
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg)
{
if (int_type != INTERVAL_WEEK)
return FALSE;
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
bool check_valid_arguments_processor(void *int_arg)
{
switch (int_type) {
case INTERVAL_YEAR:
case INTERVAL_YEAR_MONTH:
case INTERVAL_QUARTER:
case INTERVAL_MONTH:
/* case INTERVAL_WEEK: Not allowed as partitioning function, bug#57071 */
case INTERVAL_DAY:
return !has_date_args();
case INTERVAL_DAY_HOUR:
case INTERVAL_DAY_MINUTE:
case INTERVAL_DAY_SECOND:
case INTERVAL_DAY_MICROSECOND:
return !has_datetime_args();
case INTERVAL_HOUR:
case INTERVAL_HOUR_MINUTE:
case INTERVAL_HOUR_SECOND:
case INTERVAL_MINUTE:
case INTERVAL_MINUTE_SECOND:
case INTERVAL_SECOND:
case INTERVAL_MICROSECOND:
case INTERVAL_HOUR_MICROSECOND:
case INTERVAL_MINUTE_MICROSECOND:
case INTERVAL_SECOND_MICROSECOND:
return !has_time_args();
default:
/*
INTERVAL_LAST is only an end marker,
INTERVAL_WEEK depends on default_week_format which is a session
variable and cannot be used for partitioning. See bug#57071.
*/
break;
}
return true;
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_extract>(thd, this); }
};
class Item_char_typecast :public Item_handled_func
{
uint cast_length;
CHARSET_INFO *cast_cs, *from_cs;
bool charset_conversion;
String tmp_value;
bool m_suppress_warning_to_error_escalation;
public:
bool has_explicit_length() const { return cast_length != ~0U; }
private:
String *reuse(String *src, size_t length);
String *copy(String *src, CHARSET_INFO *cs);
uint adjusted_length_with_warn(uint length);
void check_truncation_with_warn(String *src, size_t dstlen);
void fix_length_and_dec_internal(CHARSET_INFO *fromcs);
public:
// Methods used by ColumnStore
uint get_cast_length() const { return cast_length; }
public:
Item_char_typecast(THD *thd, Item *a, uint length_arg, CHARSET_INFO *cs_arg):
Item_handled_func(thd, a), cast_length(length_arg), cast_cs(cs_arg),
m_suppress_warning_to_error_escalation(false) {}
enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
bool eq(const Item *item, bool binary_cmp) const;
const char *func_name() const { return "cast_as_char"; }
CHARSET_INFO *cast_charset() const { return cast_cs; }
String *val_str_generic(String *a);
String *val_str_binary_from_native(String *a);
void fix_length_and_dec_generic();
void fix_length_and_dec_numeric();
void fix_length_and_dec_str();
void fix_length_and_dec_native_to_binary(uint32 octet_length);
bool fix_length_and_dec()
{
return args[0]->type_handler()->Item_char_typecast_fix_length_and_dec(this);
}
void print(String *str, enum_query_type query_type);
bool need_parentheses_in_default() { return true; }
Item *get_copy(THD *thd)
{ return get_item_copy<Item_char_typecast>(thd, this); }
};
class Item_interval_DDhhmmssff_typecast :public Item_char_typecast
{
uint m_fsp;
public:
Item_interval_DDhhmmssff_typecast(THD *thd, Item *a, uint fsp)
:Item_char_typecast(thd, a,Interval_DDhhmmssff::max_char_length(fsp),
&my_charset_latin1),
m_fsp(fsp)
{ }
String *val_str(String *to)
{
Interval_DDhhmmssff it(current_thd, args[0], m_fsp);
null_value= !it.is_valid_interval_DDhhmmssff();
return it.to_string(to, m_fsp);
}
};
class Item_date_typecast :public Item_datefunc
{
public:
Item_date_typecast(THD *thd, Item *a): Item_datefunc(thd, a) {}
const char *func_name() const { return "cast_as_date"; }
void print(String *str, enum_query_type query_type)
{
print_cast_temporal(str, query_type);
}
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate);
bool fix_length_and_dec()
{
return args[0]->type_handler()->Item_date_typecast_fix_length_and_dec(this);
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_date_typecast>(thd, this); }
};
class Item_time_typecast :public Item_timefunc
{
public:
Item_time_typecast(THD *thd, Item *a, uint dec_arg):
Item_timefunc(thd, a) { decimals= dec_arg; }
const char *func_name() const { return "cast_as_time"; }
void print(String *str, enum_query_type query_type)
{
print_cast_temporal(str, query_type);
}
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate);
bool fix_length_and_dec()
{
return args[0]->type_handler()->
Item_time_typecast_fix_length_and_dec(this);
}
Sql_mode_dependency value_depends_on_sql_mode() const;
Item *get_copy(THD *thd)
{ return get_item_copy<Item_time_typecast>(thd, this); }
};
class Item_datetime_typecast :public Item_datetimefunc
{
public:
Item_datetime_typecast(THD *thd, Item *a, uint dec_arg):
Item_datetimefunc(thd, a) { decimals= dec_arg; }
const char *func_name() const { return "cast_as_datetime"; }
void print(String *str, enum_query_type query_type)
{
print_cast_temporal(str, query_type);
}
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate);
bool fix_length_and_dec()
{
return args[0]->type_handler()->
Item_datetime_typecast_fix_length_and_dec(this);
}
Sql_mode_dependency value_depends_on_sql_mode() const;
Item *get_copy(THD *thd)
{ return get_item_copy<Item_datetime_typecast>(thd, this); }
};
class Item_func_makedate :public Item_datefunc
{
bool check_arguments() const
{ return check_argument_types_can_return_int(0, arg_count); }
public:
Item_func_makedate(THD *thd, Item *a, Item *b):
Item_datefunc(thd, a, b) {}
const char *func_name() const { return "makedate"; }
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_makedate>(thd, this); }
};
class Item_func_timestamp :public Item_datetimefunc
{
bool check_arguments() const
{
return args[0]->check_type_can_return_date(func_name()) ||
args[1]->check_type_can_return_time(func_name());
}
public:
Item_func_timestamp(THD *thd, Item *a, Item *b)
:Item_datetimefunc(thd, a, b)
{ }
const char *func_name() const { return "timestamp"; }
bool fix_length_and_dec()
{
THD *thd= current_thd;
uint dec0= args[0]->datetime_precision(thd);
uint dec1= Interval_DDhhmmssff::fsp(thd, args[1]);
fix_attributes_datetime(MY_MAX(dec0, dec1));
maybe_null= true;
return false;
}
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
{
Datetime dt(thd, args[0], Datetime::Options(TIME_CONV_NONE, thd));
if (!dt.is_valid_datetime())
return null_value= true;
Interval_DDhhmmssff it(thd, args[1]);
if (!it.is_valid_interval_DDhhmmssff())
return null_value= true;
return (null_value= Sec6_add(dt.get_mysql_time(), it.get_mysql_time(), 1).
to_datetime(ltime));
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_timestamp>(thd, this); }
};
/**
ADDTIME(t,a) and SUBTIME(t,a) are time functions that calculate a
time/datetime value
t: time_or_datetime_expression
a: time_expression
Result: Time value or datetime value
*/
class Item_func_add_time :public Item_handled_func
{
int sign;
public:
// Methods used by ColumnStore
int get_sign() const { return sign; }
public:
Item_func_add_time(THD *thd, Item *a, Item *b, bool neg_arg)
:Item_handled_func(thd, a, b), sign(neg_arg ? -1 : 1)
{ }
bool fix_length_and_dec();
const char *func_name() const { return sign > 0 ? "addtime" : "subtime"; }
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_add_time>(thd, this); }
};
class Item_func_timediff :public Item_timefunc
{
bool check_arguments() const
{ return check_argument_types_can_return_time(0, arg_count); }
public:
Item_func_timediff(THD *thd, Item *a, Item *b): Item_timefunc(thd, a, b) {}
const char *func_name() const { return "timediff"; }
bool fix_length_and_dec()
{
THD *thd= current_thd;
uint dec= MY_MAX(args[0]->time_precision(thd),
args[1]->time_precision(thd));
fix_attributes_time(dec);
maybe_null= true;
return FALSE;
}
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_timediff>(thd, this); }
};
class Item_func_maketime :public Item_timefunc
{
bool check_arguments() const
{
return check_argument_types_can_return_int(0, 2) ||
args[2]->check_type_can_return_decimal(func_name());
}
public:
Item_func_maketime(THD *thd, Item *a, Item *b, Item *c):
Item_timefunc(thd, a, b, c)
{}
bool fix_length_and_dec()
{
fix_attributes_time(args[2]->decimals);
maybe_null= true;
return FALSE;
}
const char *func_name() const { return "maketime"; }
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_maketime>(thd, this); }
};
class Item_func_microsecond :public Item_long_func_time_field
{
public:
Item_func_microsecond(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
longlong val_int();
const char *func_name() const { return "microsecond"; }
bool fix_length_and_dec()
{
decimals=0;
maybe_null=1;
fix_char_length(6);
return FALSE;
}
bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;}
bool check_valid_arguments_processor(void *int_arg)
{
return !has_time_args();
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_microsecond>(thd, this); }
};
class Item_func_timestamp_diff :public Item_longlong_func
{
bool check_arguments() const
{ return check_argument_types_can_return_date(0, arg_count); }
const interval_type int_type;
public:
// Methods used by ColumnStore
interval_type get_int_type() const { return int_type; };
public:
Item_func_timestamp_diff(THD *thd, Item *a, Item *b, interval_type type_arg):
Item_longlong_func(thd, a, b), int_type(type_arg) {}
const char *func_name() const { return "timestampdiff"; }
longlong val_int();
bool fix_length_and_dec()
{
decimals=0;
maybe_null=1;
return FALSE;
}
virtual void print(String *str, enum_query_type query_type);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_timestamp_diff>(thd, this); }
};
enum date_time_format
{
USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
};
class Item_func_get_format :public Item_str_ascii_func
{
public:
const timestamp_type type; // keep it public
Item_func_get_format(THD *thd, timestamp_type type_arg, Item *a):
Item_str_ascii_func(thd, a), type(type_arg)
{}
String *val_str_ascii(String *str);
const char *func_name() const { return "get_format"; }
bool fix_length_and_dec()
{
maybe_null= 1;
decimals=0;
fix_length_and_charset(17, default_charset());
return FALSE;
}
virtual void print(String *str, enum_query_type query_type);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_get_format>(thd, this); }
};
class Item_func_str_to_date :public Item_handled_func
{
bool const_item;
String subject_converter;
String format_converter;
CHARSET_INFO *internal_charset;
public:
Item_func_str_to_date(THD *thd, Item *a, Item *b):
Item_handled_func(thd, a, b), const_item(false),
internal_charset(NULL)
{}
bool get_date_common(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate,
timestamp_type);
const char *func_name() const { return "str_to_date"; }
bool fix_length_and_dec();
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_str_to_date>(thd, this); }
};
class Item_func_last_day :public Item_datefunc
{
bool check_arguments() const
{ return args[0]->check_type_can_return_date(func_name()); }
public:
Item_func_last_day(THD *thd, Item *a): Item_datefunc(thd, a) {}
const char *func_name() const { return "last_day"; }
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_last_day>(thd, this); }
};
/*****************************************************************************/
class Func_handler_date_add_interval
{
protected:
static uint interval_dec(const Item *item, interval_type int_type)
{
if (int_type == INTERVAL_MICROSECOND ||
(int_type >= INTERVAL_DAY_MICROSECOND &&
int_type <= INTERVAL_SECOND_MICROSECOND))
return TIME_SECOND_PART_DIGITS;
if (int_type == INTERVAL_SECOND && item->decimals > 0)
return MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS);
return 0;
}
interval_type int_type(const Item_handled_func *item) const
{
return static_cast<const Item_date_add_interval*>(item)->int_type;
}
bool sub(const Item_handled_func *item) const
{
return static_cast<const Item_date_add_interval*>(item)->date_sub_interval;
}
bool add(THD *thd, Item *item, interval_type type, bool sub, MYSQL_TIME *to) const
{
INTERVAL interval;
if (get_interval_value(thd, item, type, &interval))
return true;
if (sub)
interval.neg = !interval.neg;
return date_add_interval(thd, to, type, interval);
}
};
class Func_handler_date_add_interval_datetime:
public Item_handled_func::Handler_datetime,
public Func_handler_date_add_interval
{
public:
bool fix_length_and_dec(Item_handled_func *item) const
{
uint dec= MY_MAX(item->arguments()[0]->datetime_precision(current_thd),
interval_dec(item->arguments()[1], int_type(item)));
item->fix_attributes_datetime(dec);
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
Datetime::Options opt(TIME_CONV_NONE, thd);
Datetime dt(thd, item->arguments()[0], opt);
if (!dt.is_valid_datetime() ||
dt.check_date_with_warn(thd, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return (item->null_value= true);
dt.copy_to_mysql_time(to);
return (item->null_value= add(thd, item->arguments()[1],
int_type(item), sub(item), to));
}
};
class Func_handler_date_add_interval_datetime_arg0_time:
public Func_handler_date_add_interval_datetime
{
public:
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const;
};
class Func_handler_date_add_interval_date:
public Item_handled_func::Handler_date,
public Func_handler_date_add_interval
{
public:
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
/*
The first argument is known to be of the DATE data type (not DATETIME).
We don't need rounding here.
*/
Date d(thd, item->arguments()[0], TIME_CONV_NONE);
if (!d.is_valid_date() ||
d.check_date_with_warn(thd, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return (item->null_value= true);
d.copy_to_mysql_time(to);
return (item->null_value= add(thd, item->arguments()[1],
int_type(item), sub(item), to));
}
};
class Func_handler_date_add_interval_time:
public Item_handled_func::Handler_time,
public Func_handler_date_add_interval
{
public:
bool fix_length_and_dec(Item_handled_func *item) const
{
uint dec= MY_MAX(item->arguments()[0]->time_precision(current_thd),
interval_dec(item->arguments()[1], int_type(item)));
item->fix_attributes_time(dec);
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
Time t(thd, item->arguments()[0]);
if (!t.is_valid_time())
return (item->null_value= true);
t.copy_to_mysql_time(to);
return (item->null_value= add(thd, item->arguments()[1],
int_type(item), sub(item), to));
}
};
class Func_handler_date_add_interval_string:
public Item_handled_func::Handler_temporal_string,
public Func_handler_date_add_interval
{
public:
bool fix_length_and_dec(Item_handled_func *item) const
{
uint dec= MY_MAX(item->arguments()[0]->datetime_precision(current_thd),
interval_dec(item->arguments()[1], int_type(item)));
item->Type_std_attributes::set(
Type_temporal_attributes_not_fixed_dec(MAX_DATETIME_WIDTH, dec, false),
DTCollation(item->default_charset(),
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII));
item->fix_char_length(item->max_length);
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
if (item->arguments()[0]->
get_date(thd, to, Datetime::Options(TIME_CONV_NONE, thd)) ||
(to->time_type != MYSQL_TIMESTAMP_TIME &&
check_date_with_warn(thd, to, TIME_NO_ZEROS, MYSQL_TIMESTAMP_ERROR)))
return (item->null_value= true);
return (item->null_value= add(thd, item->arguments()[1],
int_type(item), sub(item), to));
}
};
class Func_handler_sign
{
protected:
int m_sign;
Func_handler_sign(int sign) :m_sign(sign) { }
};
class Func_handler_add_time_datetime:
public Item_handled_func::Handler_datetime,
public Func_handler_sign
{
public:
Func_handler_add_time_datetime(int sign)
:Func_handler_sign(sign)
{ }
bool fix_length_and_dec(Item_handled_func *item) const
{
THD *thd= current_thd;
uint dec0= item->arguments()[0]->datetime_precision(thd);
uint dec1= Interval_DDhhmmssff::fsp(thd, item->arguments()[1]);
item->fix_attributes_datetime(MY_MAX(dec0, dec1));
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
DBUG_ASSERT(item->is_fixed());
Datetime::Options opt(TIME_CONV_NONE, thd);
Datetime dt(thd, item->arguments()[0], opt);
if (!dt.is_valid_datetime())
return item->null_value= true;
Interval_DDhhmmssff it(thd, item->arguments()[1]);
if (!it.is_valid_interval_DDhhmmssff())
return item->null_value= true;
return (item->null_value= (Sec6_add(dt.get_mysql_time(),
it.get_mysql_time(), m_sign).
to_datetime(to)));
}
};
class Func_handler_add_time_time:
public Item_handled_func::Handler_time,
public Func_handler_sign
{
public:
Func_handler_add_time_time(int sign)
:Func_handler_sign(sign)
{ }
bool fix_length_and_dec(Item_handled_func *item) const
{
THD *thd= current_thd;
uint dec0= item->arguments()[0]->time_precision(thd);
uint dec1= Interval_DDhhmmssff::fsp(thd, item->arguments()[1]);
item->fix_attributes_time(MY_MAX(dec0, dec1));
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
DBUG_ASSERT(item->is_fixed());
Time t(thd, item->arguments()[0]);
if (!t.is_valid_time())
return item->null_value= true;
Interval_DDhhmmssff i(thd, item->arguments()[1]);
if (!i.is_valid_interval_DDhhmmssff())
return item->null_value= true;
return (item->null_value= (Sec6_add(t.get_mysql_time(),
i.get_mysql_time(), m_sign).
to_time(thd, to, item->decimals)));
}
};
class Func_handler_add_time_string:
public Item_handled_func::Handler_temporal_string,
public Func_handler_sign
{
public:
Func_handler_add_time_string(int sign)
:Func_handler_sign(sign)
{ }
bool fix_length_and_dec(Item_handled_func *item) const
{
uint dec0= item->arguments()[0]->decimals;
uint dec1= Interval_DDhhmmssff::fsp(current_thd, item->arguments()[1]);
uint dec= MY_MAX(dec0, dec1);
item->Type_std_attributes::set(
Type_temporal_attributes_not_fixed_dec(MAX_DATETIME_WIDTH, dec, false),
DTCollation(item->default_charset(),
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII));
item->fix_char_length(item->max_length);
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
DBUG_ASSERT(item->is_fixed());
// Detect a proper timestamp type based on the argument values
Temporal_hybrid l_time1(thd, item->arguments()[0],
Temporal::Options(TIME_TIME_ONLY, thd));
if (!l_time1.is_valid_temporal())
return (item->null_value= true);
Interval_DDhhmmssff l_time2(thd, item->arguments()[1]);
if (!l_time2.is_valid_interval_DDhhmmssff())
return (item->null_value= true);
Sec6_add add(l_time1.get_mysql_time(), l_time2.get_mysql_time(), m_sign);
return (item->null_value= (l_time1.get_mysql_time()->time_type ==
MYSQL_TIMESTAMP_TIME ?
add.to_time(thd, to, item->decimals) :
add.to_datetime(to)));
}
};
class Func_handler_str_to_date_datetime_sec:
public Item_handled_func::Handler_datetime
{
public:
bool fix_length_and_dec(Item_handled_func *item) const
{
item->fix_attributes_datetime(0);
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
return static_cast<Item_func_str_to_date*>(item)->
get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_DATETIME);
}
};
class Func_handler_str_to_date_datetime_usec:
public Item_handled_func::Handler_datetime
{
public:
bool fix_length_and_dec(Item_handled_func *item) const
{
item->fix_attributes_datetime(TIME_SECOND_PART_DIGITS);
return false;
}
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
return static_cast<Item_func_str_to_date*>(item)->
get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_DATETIME);
}
};
class Func_handler_str_to_date_date: public Item_handled_func::Handler_date
{
public:
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
return static_cast<Item_func_str_to_date*>(item)->
get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_DATE);
}
};
class Func_handler_str_to_date_time: public Item_handled_func::Handler_time
{
public:
bool get_date(THD *thd, Item_handled_func *item,
MYSQL_TIME *to, date_mode_t fuzzy) const
{
if (static_cast<Item_func_str_to_date*>(item)->
get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_TIME))
return true;
if (to->day)
{
/*
Day part for time type can be nonzero value and so
we should add hours from day part to hour part to
keep valid time value.
*/
to->hour+= to->day * 24;
to->day= 0;
}
return false;
}
};
class Func_handler_str_to_date_time_sec: public Func_handler_str_to_date_time
{
public:
bool fix_length_and_dec(Item_handled_func *item) const
{
item->fix_attributes_time(0);
return false;
}
};
class Func_handler_str_to_date_time_usec: public Func_handler_str_to_date_time
{
public:
bool fix_length_and_dec(Item_handled_func *item) const
{
item->fix_attributes_time(TIME_SECOND_PART_DIGITS);
return false;
}
};
#endif /* ITEM_TIMEFUNC_INCLUDED */
|