Changeset: 1b22b146b13d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/1b22b146b13d Modified Files: sql/server/sql_datetime.c sql/server/sql_parser.y sql/test/odbc-escape-sequences/Tests/time-date-interval-functions.test Branch: default Log Message:
add support for tsi_fraq_sec intervals in timestampadd (odbc escapes) add support for scalar inputs, ie a computaion of values or decimals diffs (97 lines): diff --git a/sql/server/sql_datetime.c b/sql/server/sql_datetime.c --- a/sql/server/sql_datetime.c +++ b/sql/server/sql_datetime.c @@ -510,6 +510,9 @@ process_odbc_interval(mvc *sql, itype in case isec: mul *= 1000; break; + case insec: + d = 5; + break; default: snprintf(sql->errstr, ERRSIZE, _("Internal error: bad interval qualifier (%d)\n"), interval); return -1; diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y --- a/sql/server/sql_parser.y +++ b/sql/server/sql_parser.y @@ -6481,19 +6481,26 @@ odbc_datetime_func: append_symbol(l, $3); $$ = _symbol_create_list( SQL_UNOP, l ); } - | TIMESTAMPADD '(' odbc_tsi_qualifier ',' intval ',' search_condition ')' + | TIMESTAMPADD '(' odbc_tsi_qualifier ',' scalar_exp ',' search_condition ')' { dlist *l = L(); append_list( l, append_string(L(), sa_strdup(SA, "timestampadd"))); append_int(l, FALSE); /* ignore distinct */ sql_subtype t; lng i = 0; - if (process_odbc_interval(m, $3, $5, &t, &i) < 0) { + if (process_odbc_interval(m, $3, 1, &t, &i) < 0) { yyerror(m, "incorrect interval"); $$ = NULL; YYABORT; } append_symbol(l, $7); - append_symbol(l, _newAtomNode(atom_int(SA, &t, i))); + append_symbol(l, _symbol_create_list( SQL_BINOP, + append_symbol( + append_symbol( + append_int( + append_list(L(), append_string(L(), sa_strdup(SA, "sql_mul"))), + FALSE), /* ignore distinct */ + _newAtomNode(atom_int(SA, &t, i))), + $5))); $$ = _symbol_create_list( SQL_BINOP, l ); } | TIMESTAMPDIFF '(' odbc_tsi_qualifier ',' search_condition ',' search_condition ')' @@ -6655,7 +6662,9 @@ odbc_data_type: ; odbc_tsi_qualifier: - SQL_TSI_SECOND + SQL_TSI_FRAC_SECOND + { $$ = insec; } + | SQL_TSI_SECOND { $$ = isec; } | SQL_TSI_MINUTE { $$ = imin; } diff --git a/sql/test/odbc-escape-sequences/Tests/time-date-interval-functions.test b/sql/test/odbc-escape-sequences/Tests/time-date-interval-functions.test --- a/sql/test/odbc-escape-sequences/Tests/time-date-interval-functions.test +++ b/sql/test/odbc-escape-sequences/Tests/time-date-interval-functions.test @@ -273,27 +273,25 @@ select sql_sub({fn timestampadd(SQL_TSI_ ---- 0:00:00 -# TODO Implement SQL_TSI_FRAC_SECOND option -statement error 42000!syntax error in: "select { fn timestampadd(sql_tsi_frac_second" +query T rowsort select { fn timestampadd(SQL_TSI_FRAC_SECOND, 123, timestamp'2022-11-14 14:13:12') } -# ---- -# 2022-11-14 14:13:12.123 +---- +2022-11-14 14:13:12.123000 query T rowsort select { fn timestampadd(SQL_TSI_SECOND, 11, timestamp'2022-11-14 14:13:12') } ---- 2022-11-14 14:13:23 -statement error 42000!syntax error in: "select { fn timestampadd(sql_tsi_second, 11.234" +query T rowsort select { fn timestampadd(SQL_TSI_SECOND, 11.234, timestamp'2022-11-14 14:13:12') } -# ---- -# 2022-11-14 14:13:23.234 +---- +2022-11-14 14:13:23.234000 -# TODO: add support for integer expression as second argument. -statement error 42000!syntax error in: "select { fn timestampadd(sql_tsi_second, 15*" +query T rowsort select { fn timestampadd(SQL_TSI_SECOND, 15*60, timestamp'2022-11-14 14:13:12') } -# ---- -# 2022-11-14 14:28:12 +---- +2022-11-14 14:28:12 query T rowsort select { fn timestampadd(SQL_TSI_MINUTE, 12, timestamp'2022-11-14 14:13:12') } _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org