Changeset: e207670a5c19 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e207670a5c19 Modified Files: clients/mapiclient/mclient.c monetdb5/mal/mal_exception.c monetdb5/modules/kernel/algebra.c sql/backends/monet5/sql_scenario.c sql/test/pg_regress/Tests/timestamp.sql sql/test/pg_regress/Tests/timestamptz.sql Branch: default Log Message:
Merge with Apr2019 branch. diffs (242 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -1872,6 +1872,11 @@ format_result(Mapi mid, MapiHdl hdl, boo timerHumanCalled = false; do { + // get the timings as reported by the backend + sqloptimizer = mapi_get_sqloptimizertime(hdl); + maloptimizer = mapi_get_maloptimizertime(hdl); + querytime = mapi_get_querytime(hdl); + timerHumanStop(); /* handle errors first */ if (mapi_result_error(hdl) != NULL) { mnstr_flush(toConsole); @@ -1884,14 +1889,10 @@ format_result(Mapi mid, MapiHdl hdl, boo errseen = true; /* don't need to print something like '0 * tuples' if we got an error */ + timerHuman(sqloptimizer, maloptimizer, querytime, singleinstr, false); continue; } - // get the timings as reported by the backend - sqloptimizer = mapi_get_sqloptimizertime(hdl); - maloptimizer = mapi_get_maloptimizertime(hdl); - querytime = mapi_get_querytime(hdl); - timerHumanStop(); switch (mapi_get_querytype(hdl)) { case Q_BLOCK: case Q_PARSE: diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c --- a/monetdb5/mal/mal_exception.c +++ b/monetdb5/mal/mal_exception.c @@ -357,7 +357,7 @@ getExceptionMessageAndState(const char * if (strncmp(exceptionNames[i], exception, l) == 0 && exception[l] == ':') { s = exception + l + 1; - if ((t = strchr(s, ':')) != NULL) + if ((t = strpbrk(s, ":\n")) != NULL && *t == ':') return (str) (t + 1); return (str) s; } diff --git a/monetdb5/modules/kernel/algebra.c b/monetdb5/modules/kernel/algebra.c --- a/monetdb5/modules/kernel/algebra.c +++ b/monetdb5/modules/kernel/algebra.c @@ -382,7 +382,7 @@ do_join(bat *r1, bat *r2, const bat *lid else est = (BUN) *estimate; - err = GDK_EXCEPTION; /* most likely error now */ + err = NULL; /* most likely error now is GDK_EXCEPTION */ if (thetafunc) { assert(joinfunc == NULL); @@ -453,6 +453,8 @@ do_join(bat *r1, bat *r2, const bat *lid BBPunfix(candleft->batCacheid); if (candright) BBPunfix(candright->batCacheid); + if (err == NULL) + throw(MAL, funcname, GDK_EXCEPTION); throw(MAL, funcname, "%s", err); } diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -1312,18 +1312,19 @@ SQLCacheRemove(Client c, str nme) str SQLcallback(Client c, str msg){ - if(msg && (strstr(msg, "MALexception") || strstr(msg,"GDKexception"))) { + char newerr[1024]; + + if (msg && (strstr(msg, "MALexception") || strstr(msg,"GDKexception"))) { // massage the error to comply with SQL char *s; - s= strchr(msg,(int)':'); - if (s ) - s= strchr(msg,(int)':'); - if( s){ - char newerr[1024]; + s = strchr(msg, ':'); + if (s) { s++; + if (s - msg >= (ptrdiff_t) sizeof(newerr)) + s = msg + sizeof(newerr) - 1; strncpy(newerr, msg, s - msg); newerr[s-msg] = 0; - snprintf(newerr + (s-msg), 1024 -(s-msg), SQLSTATE(HY020) "%s",s); + snprintf(newerr + (s-msg), sizeof(newerr) -(s-msg), SQLSTATE(HY020) "%s",s); freeException(msg); msg = GDKstrdup(newerr); } @@ -1333,23 +1334,25 @@ SQLcallback(Client c, str msg){ char *m, *n, *p, *s; size_t l; - m = p = msg; + m = msg; + p = newerr; while (m && *m) { n = strchr(m, '\n'); - if (n) - *n = 0; s = getExceptionMessageAndState(m); if (n) { - *n++ = '\n'; + n++; /* include newline */ l = n - s; } else { l = strlen(s); } - memmove(p, s, l); + if (p + l >= newerr + sizeof(newerr)) + l = newerr + sizeof(newerr) - p - 1; + memcpy(p, s, l); p += l; m = n; } *p = 0; + msg = GDKstrdup(newerr); } return MALcallback(c,msg); } diff --git a/sql/test/pg_regress/Tests/timestamp.sql b/sql/test/pg_regress/Tests/timestamp.sql --- a/sql/test/pg_regress/Tests/timestamp.sql +++ b/sql/test/pg_regress/Tests/timestamp.sql @@ -5,6 +5,13 @@ /* SET australian_timezones = 'off'; */ CREATE TABLE TIMESTAMP_TBL ( d1 timestamp(2) ); +DECLARE test_now timestamp(2); +DECLARE test_current_timestamp timestamp(2); +DECLARE test_current_date date; + +SET test_now = now; +SET test_current_timestamp = current_timestamp; +SET test_current_date = current_date; -- Shorthand values -- Not directly usable for regression testing since these are not constants. @@ -13,31 +20,31 @@ CREATE TABLE TIMESTAMP_TBL ( d1 timestam -- statements. --INSERT INTO TIMESTAMP_TBL VALUES ('now'); -INSERT INTO TIMESTAMP_TBL VALUES (now); +INSERT INTO TIMESTAMP_TBL VALUES (test_now); --INSERT INTO TIMESTAMP_TBL VALUES ('current'); -INSERT INTO TIMESTAMP_TBL VALUES (cast(current_timestamp as timestamp)); +INSERT INTO TIMESTAMP_TBL VALUES (cast(test_current_timestamp as timestamp)); --INSERT INTO TIMESTAMP_TBL VALUES ('today'); -INSERT INTO TIMESTAMP_TBL VALUES (cast(current_date as timestamp)); +INSERT INTO TIMESTAMP_TBL VALUES (cast(test_current_date as timestamp)); --INSERT INTO TIMESTAMP_TBL VALUES ('yesterday'); -INSERT INTO TIMESTAMP_TBL VALUES (cast(sql_sub(current_date, 24*60*60.0) as timestamp)); +INSERT INTO TIMESTAMP_TBL VALUES (cast(sql_sub(test_current_date, 24*60*60.0) as timestamp)); --INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow'); -INSERT INTO TIMESTAMP_TBL VALUES (cast(sql_add(current_date, 24*60*60.0) as timestamp)); +INSERT INTO TIMESTAMP_TBL VALUES (cast(sql_add(test_current_date, 24*60*60.0) as timestamp)); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu'); --SELECT d1 FROM TIMESTAMP_TBL; -SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = cast(current_date as timestamp); -SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = cast(sql_add(current_date, 24*60*60.0) as timestamp); -SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = cast(sql_sub(current_date, 24*60*60.0) as timestamp); -SELECT count(*) AS None FROM TIMESTAMP_TBL WHERE d1 = cast(now as timestamp); +SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = cast(test_current_date as timestamp); +SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = cast(sql_add(test_current_date, 24*60*60.0) as timestamp); +SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = cast(sql_sub(test_current_date, 24*60*60.0) as timestamp); +SELECT count(*) AS None FROM TIMESTAMP_TBL WHERE d1 = cast(test_now as timestamp); DELETE FROM TIMESTAMP_TBL; -- verify uniform transaction time within transaction block START TRANSACTION; -INSERT INTO TIMESTAMP_TBL VALUES (now); -INSERT INTO TIMESTAMP_TBL VALUES (now()); -SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 <= cast(now as timestamp); +INSERT INTO TIMESTAMP_TBL VALUES (test_now); +INSERT INTO TIMESTAMP_TBL VALUES (test_now); +SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 <= cast(test_now as timestamp); COMMIT; DELETE FROM TIMESTAMP_TBL; diff --git a/sql/test/pg_regress/Tests/timestamptz.sql b/sql/test/pg_regress/Tests/timestamptz.sql --- a/sql/test/pg_regress/Tests/timestamptz.sql +++ b/sql/test/pg_regress/Tests/timestamptz.sql @@ -5,33 +5,40 @@ /* SET australian_timezones = 'off'; */ CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone); +DECLARE test_now timestamp(2) with time zone; +DECLARE test_current_timestamp timestamp(2) with time zone; +DECLARE test_current_date date; + +SET test_now = now; +SET test_current_timestamp = current_timestamp; +SET test_current_date = current_date; --INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); -INSERT INTO TIMESTAMPTZ_TBL VALUES (now); +INSERT INTO TIMESTAMPTZ_TBL VALUES (test_now); --INSERT INTO TIMESTAMPTZ_TBL VALUES ('current'); -INSERT INTO TIMESTAMPTZ_TBL VALUES (current_timestamp); +INSERT INTO TIMESTAMPTZ_TBL VALUES (test_current_timestamp); --INSERT INTO TIMESTAMPTZ_TBL VALUES ('today'); -INSERT INTO TIMESTAMPTZ_TBL VALUES (cast(current_date as timestamptz)); +INSERT INTO TIMESTAMPTZ_TBL VALUES (cast(test_current_date as timestamptz)); --INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday'); -INSERT INTO TIMESTAMPTZ_TBL VALUES (cast(sql_sub(current_date, 24*60*60.0) as timestamptz)); +INSERT INTO TIMESTAMPTZ_TBL VALUES (cast(sql_sub(test_current_date, 24*60*60.0) as timestamptz)); --INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow'); -INSERT INTO TIMESTAMPTZ_TBL VALUES (cast(sql_add(current_date, 24*60*60.0) as timestamptz)); +INSERT INTO TIMESTAMPTZ_TBL VALUES (cast(sql_add(test_current_date, 24*60*60.0) as timestamptz)); INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow EST'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow zulu'); --SELECT d1 FROM TIMESTAMPTZ_TBL; -SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = cast(current_date as timestamptz); -SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = cast(sql_add(current_date, 24*60*60.0)as timestamptz); -SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = cast(sql_sub(current_date, 24*60*60.0)as timestamptz); -SELECT count(*) AS None FROM TIMESTAMPTZ_TBL WHERE d1 = cast(now as timestamptz); +SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = cast(test_current_date as timestamptz); +SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = cast(sql_add(test_current_date, 24*60*60.0)as timestamptz); +SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = cast(sql_sub(test_current_date, 24*60*60.0)as timestamptz); +SELECT count(*) AS None FROM TIMESTAMPTZ_TBL WHERE d1 = cast(test_now as timestamptz); DELETE FROM TIMESTAMPTZ_TBL; -- verify uniform transaction time within transaction block START TRANSACTION; -INSERT INTO TIMESTAMPTZ_TBL VALUES (now); -INSERT INTO TIMESTAMPTZ_TBL VALUES (now()); -SELECT count(*) AS two FROM TIMESTAMPTZ_TBL WHERE d1 <= cast(now as timestamptz); +INSERT INTO TIMESTAMPTZ_TBL VALUES (test_now); +INSERT INTO TIMESTAMPTZ_TBL VALUES (test_now); +SELECT count(*) AS two FROM TIMESTAMPTZ_TBL WHERE d1 <= cast(test_now as timestamptz); COMMIT; DELETE FROM TIMESTAMPTZ_TBL; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list