Changeset: 328adb795d83 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=328adb795d83 Modified Files: gdk/gdk_logger.c monetdb5/modules/mal/tablet.c sql/backends/monet5/sql_upgrades.c sql/test/testdb-upgrade-chain/Tests/dump.stable.out sql/test/testdb-upgrade-chain/Tests/dump.stable.out.Windows sql/test/testdb-upgrade/Tests/dump.stable.out sql/test/testdb-upgrade/Tests/dump.stable.out.Windows Branch: default Log Message:
Merge with Jul2015 branch. diffs (292 lines): diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -1397,6 +1397,60 @@ logger_new(int debug, const char *fn, co BBPincref(d->batCacheid, TRUE); if (BBPrename(d->batCacheid, bak) < 0) logger_fatal("Logger_new: BBPrename to %s failed", bak, 0, 0); + if (!BAThdense(b) || !BAThdense(n)) { + /* we need to convert catalog_bid and + * catalog_nme to be dense-headed; we + * do this by replacing the two with + * new, dense versions */ + BATiter bi, ni; + BUN r; + const oid *o; + BAT *b2, *n2; + bat list[5]; + + list[0] = 0; + list[1] = b->batCacheid; + list[2] = n->batCacheid; + if ((b2 = logbat_new(b->ttype, BATSIZE, PERSISTENT)) == NULL) + logger_fatal("Logger_new: cannot create BAT", 0, 0, 0); + if ((n2 = logbat_new(n->ttype, BATSIZE, PERSISTENT)) == NULL) + logger_fatal("Logger_new: cannot create BAT", 0, 0, 0); + list[3] = b2->batCacheid; + list[4] = n2->batCacheid; + if (BATmode(b, TRANSIENT) != GDK_SUCCEED) + logger_fatal("Logger_new: cannot convert old catalog_bid to transient", 0, 0, 0); + if (BATmode(n, TRANSIENT) != GDK_SUCCEED) + logger_fatal("Logger_new: cannot convert old catalog_nme to transient", 0, 0, 0); + snprintf(bak, sizeof(bak), "tmp_%o", b->batCacheid); + if (BBPrename(b->batCacheid, bak) != 0) + logger_fatal("Logger_new: cannot rename old catalog_bid", 0, 0, 0); + snprintf(bak, sizeof(bak), "tmp_%o", n->batCacheid); + if (BBPrename(n->batCacheid, bak) != 0) + logger_fatal("Logger_new: cannot rename old catalog_nme", 0, 0, 0); + snprintf(bak, sizeof(bak), "%s_catalog_bid", fn); + if (BBPrename(b2->batCacheid, bak) != 0) + logger_fatal("Logger_new: cannot rename new catalog_bid", 0, 0, 0); + snprintf(bak, sizeof(bak), "%s_catalog_nme", fn); + if (BBPrename(n2->batCacheid, bak) != 0) + logger_fatal("Logger_new: cannot rename new catalog_nme", 0, 0, 0); + bi = bat_iterator(b); + ni = bat_iterator(n); + BATloop(b, p, q) { + o = (const oid *) BUNhloc(bi, p); + r = BUNfnd(BATmirror(n), o); + if (r != BUN_NONE) { + if (BUNappend(b2, BUNtloc(bi, p), 0) != GDK_SUCCEED || + BUNappend(n2, BUNtvar(ni, r), 0) != GDK_SUCCEED) + logger_fatal("Logger_new: cannot append to new catalog BATs", 0, 0, 0); + } + } + BBPunfix(b->batCacheid); + BBPunfix(n->batCacheid); + b = b2; + n = n2; + if (TMsubcommit_list(list, 5) != GDK_SUCCEED) + logger_fatal("Logger_new: committing new catalog_bid/catalog_nme failed", 0, 0, 0); + } } /* the catalog exists, and so should the log file */ diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c --- a/monetdb5/modules/mal/tablet.c +++ b/monetdb5/modules/mal/tablet.c @@ -738,30 +738,123 @@ tablet_error(READERtask *task, lng row, * Furthermore, it assume a uniform (SQL) pattern, without whitespace skipping, but with quote and separator. */ +static size_t +mystrlen(const char *s) +{ + /* Calculate and return the space that is needed for the function + * mycpstr below to do its work. */ + size_t len = 0; + const char *s0 = s; + + while (*s) { + if ((*s & 0x80) == 0) { + ; + } else if ((*s & 0xC0) == 0x80) { + /* continuation byte */ + len += 3; + } else if ((*s & 0xE0) == 0xC0) { + /* two-byte sequence */ + if ((s[1] & 0xC0) != 0x80) + len += 3; + else + s += 2; + } else if ((*s & 0xF0) == 0xE0) { + /* three-byte sequence */ + if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80) + len += 3; + else + s += 3; + } else if ((*s & 0xF8) == 0xF0) { + /* four-byte sequence */ + if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80 || (s[3] & 0xC0) != 0x80) + len += 3; + else + s += 4; + } else { + /* not a valid start byte */ + len += 3; + } + s++; + } + len += s - s0; + return len; +} + +static char * +mycpstr(char *t, const char *s) +{ + /* Copy the string pointed to by s into the buffer pointed to by + * t, and return a pointer to the NULL byte at the end. During + * the copy we translate incorrect UTF-8 sequences to escapes + * looking like <XX> where XX is the hexadecimal representation of + * the incorrect byte. The buffer t needs to be large enough to + * hold the result, but the correct length can be calculated by + * the function mystrlen above.*/ + while (*s) { + if ((*s & 0x80) == 0) { + *t++ = *s++; + } else if ((*s & 0xC0) == 0x80) { + t += sprintf(t, "<%02X>", *s++ & 0xFF); + } else if ((*s & 0xE0) == 0xC0) { + /* two-byte sequence */ + if ((s[1] & 0xC0) != 0x80) + t += sprintf(t, "<%02X>", *s++ & 0xFF); + else { + *t++ = *s++; + *t++ = *s++; + } + } else if ((*s & 0xF0) == 0xE0) { + /* three-byte sequence */ + if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80) + t += sprintf(t, "<%02X>", *s++ & 0xFF); + else { + *t++ = *s++; + *t++ = *s++; + *t++ = *s++; + } + } else if ((*s & 0xF8) == 0xF0) { + /* four-byte sequence */ + if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80 || (s[3] & 0xC0) != 0x80) + t += sprintf(t, "<%02X>", *s++ & 0xFF); + else { + *t++ = *s++; + *t++ = *s++; + *t++ = *s++; + *t++ = *s++; + } + } else { + /* not a valid start byte */ + t += sprintf(t, "<%02X>", *s++ & 0xFF); + } + } + *t = 0; + return t; +} + static str SQLload_error(READERtask *task, lng idx) { str line; + char *s; size_t sz = 0; unsigned int i; - for (i = 0; i < task->as->nr_attrs; i++) + for (i = 0; i < task->as->nr_attrs; i++) { if (task->fields[i][idx]) - sz += strlen(task->fields[i][idx]) + task->seplen; - else - sz += task->seplen; + sz += mystrlen(task->fields[i][idx]); + sz += task->seplen; + } - line = (str) GDKzalloc(sz + task->rseplen + 1); + s = line = GDKmalloc(sz + task->rseplen + 1); if (line == 0) { tablet_error(task, idx, int_nil, "SQLload malloc error", "SQLload_error"); return 0; } - line[0] = 0; for (i = 0; i < task->as->nr_attrs; i++) { if (task->fields[i][idx]) - strcat(line, task->fields[i][idx]); + s = mycpstr(s, task->fields[i][idx]); if (i < task->as->nr_attrs - 1) - strcat(line, task->csep); + s = mycpstr(s, task->csep); } strcat(line, task->rsep); return line; diff --git a/sql/backends/monet5/sql_upgrades.c b/sql/backends/monet5/sql_upgrades.c --- a/sql/backends/monet5/sql_upgrades.c +++ b/sql/backends/monet5/sql_upgrades.c @@ -1259,7 +1259,7 @@ sql_update_hugeint(Client c) #endif static str -sql_update_feb2015(Client c) +sql_update_jul2015(Client c) { size_t bufsize = 10240, pos = 0; char *buf = GDKmalloc(bufsize), *err = NULL; @@ -1642,7 +1642,7 @@ SQLupgrades(Client c, mvc *m) /* add missing features needed beyond Oct 2014 */ sql_find_subtype(&tp, "clob", 0, 0); if (!sql_bind_func(m->sa, mvc_bind_schema(m, "sys"), "like", &tp, &tp, F_FILT)) { - if ((err = sql_update_feb2015(c)) !=NULL) { + if ((err = sql_update_jul2015(c)) !=NULL) { fprintf(stderr, "!%s\n", err); GDKfree(err); } diff --git a/sql/test/testdb-upgrade-chain/Tests/dump.stable.out b/sql/test/testdb-upgrade-chain/Tests/dump.stable.out --- a/sql/test/testdb-upgrade-chain/Tests/dump.stable.out +++ b/sql/test/testdb-upgrade-chain/Tests/dump.stable.out @@ -101254,6 +101254,14 @@ begin ); end; SET SCHEMA "sys"; +create procedure analyze(minmax int, "sample" bigint) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string, col string) +external name sql.analyze; ALTER TABLE "testschema"."keytest2" ADD CONSTRAINT "keytest2_key1_key2_fkey" FOREIGN KEY ("key1", "key2") REFERENCES "testschema"."keytest1" ("key1", "key2"); ALTER TABLE "testschema"."selfref" ADD CONSTRAINT "selfref_parentid_fkey" FOREIGN KEY ("parentid") REFERENCES "testschema"."selfref" ("id"); ALTER SEQUENCE "testschema"."selfref_seq" RESTART WITH 7 NO CYCLE; diff --git a/sql/test/testdb-upgrade-chain/Tests/dump.stable.out.Windows b/sql/test/testdb-upgrade-chain/Tests/dump.stable.out.Windows --- a/sql/test/testdb-upgrade-chain/Tests/dump.stable.out.Windows +++ b/sql/test/testdb-upgrade-chain/Tests/dump.stable.out.Windows @@ -101254,6 +101254,14 @@ begin ); end; SET SCHEMA "sys"; +create procedure analyze(minmax int, "sample" bigint) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string, col string) +external name sql.analyze; ALTER TABLE "testschema"."keytest2" ADD CONSTRAINT "keytest2_key1_key2_fkey" FOREIGN KEY ("key1", "key2") REFERENCES "testschema"."keytest1" ("key1", "key2"); ALTER TABLE "testschema"."selfref" ADD CONSTRAINT "selfref_parentid_fkey" FOREIGN KEY ("parentid") REFERENCES "testschema"."selfref" ("id"); ALTER SEQUENCE "testschema"."selfref_seq" RESTART WITH 7 NO CYCLE; diff --git a/sql/test/testdb-upgrade/Tests/dump.stable.out b/sql/test/testdb-upgrade/Tests/dump.stable.out --- a/sql/test/testdb-upgrade/Tests/dump.stable.out +++ b/sql/test/testdb-upgrade/Tests/dump.stable.out @@ -101256,6 +101256,14 @@ COPY 2 RECORDS INTO "testschema"."geomte POINT (10.5000000000000000 12.3000000000000007) LINESTRING (10.0000000000000000 10.0000000000000000, 20.0000000000000000 20.0000000000000000, 30.0000000000000000 40.0000000000000000) LINESTRING (10.0000000000000000 10.0000000000000000, 20.0000000000000000 20.0000000000000000, 30.0000000000000000 40.0000000000000000) POLYGON ((10.0000000000000000 10.0000000000000000, 10.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 20.0000000000000000 15.0000000000000000, 10.0000000000000000 10.0000000000000000)) POLYGON ((10.0000000000000000 10.0000000000000000, 10.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 20.0000000000000000 15.0000000000000000, 10.0000000000000000 10.0000000000000000)) MULTIPOINT (20.0000000000000000 80.0000000000000000, 110.0000000000000000 160.0000000000000000, 20.0000000000000000 160.0000000000000000) MULTILINESTRING ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 80.0000000000000000, 60.000000000 0000000 80.0000000000000000, 60.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)) MULTILINESTRING ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 80.0000000000000000, 60.0000000000000000 80.0000000000000000, 60.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)) MULTIPOLYGON (((140.0000000000000000 110.0000000000000000, 260.0000000000000000 110.0000000000000000, 170.0000000000000000 20.0000000000000000, 50.0000000000000000 20.0000000000000000, 140.0000000000000000 110.0000000000000000)), ((300.0000000000000000 270.0000000000000000, 420.0000000000000000 270.0000000000000000, 340.0000000000000000 190.0000000000000000, 220.0000000000000000 190.0000000000000000, 300.0000000000000000 270.0000000000000000))) MULTIPOLYGON (((140.0000000000000000 110.0000000000000000, 260.0000000000000000 110.0000000000000000, 170.0000000000000000 20.0000000000000000, 50.0000000000000000 20.0000000000000000, 140.0000000000000000 110.00000000000 00000)), ((300.0000000000000000 270.0000000000000000, 420.0000000000000000 270.0000000000000000, 340.0000000000000000 190.0000000000000000, 220.0000000000000000 190.0000000000000000, 300.0000000000000000 270.0000000000000000))) POLYGON ((10.0000000000000000 10.0000000000000000, 10.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 20.0000000000000000 15.0000000000000000, 10.0000000000000000 10.0000000000000000)) GEOMETRYCOLLECTION (POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 100.0000000000000000, 100.0000000000000000 100.0000000000000000, 100.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)), LINESTRING (10.0000000000000000 10.0000000000000000, 20.0000000000000000 20.0000000000000000, 30.0000000000000000 40.0000000000000000)) BOX (10.000000 10.000000, 20.000000 20.000000) NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL SET SCHEMA "sys"; +create procedure analyze(minmax int, "sample" bigint) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string, col string) +external name sql.analyze; ALTER TABLE "testschema"."keytest2" ADD CONSTRAINT "keytest2_key1_key2_fkey" FOREIGN KEY ("key1", "key2") REFERENCES "testschema"."keytest1" ("key1", "key2"); ALTER TABLE "testschema"."selfref" ADD CONSTRAINT "selfref_parentid_fkey" FOREIGN KEY ("parentid") REFERENCES "testschema"."selfref" ("id"); ALTER SEQUENCE "testschema"."selfref_seq" RESTART WITH 7 NO CYCLE; diff --git a/sql/test/testdb-upgrade/Tests/dump.stable.out.Windows b/sql/test/testdb-upgrade/Tests/dump.stable.out.Windows --- a/sql/test/testdb-upgrade/Tests/dump.stable.out.Windows +++ b/sql/test/testdb-upgrade/Tests/dump.stable.out.Windows @@ -101256,6 +101256,14 @@ COPY 2 RECORDS INTO "testschema"."geomte POINT (10.5000000000000000 12.3000000000000010) LINESTRING (10.0000000000000000 10.0000000000000000, 20.0000000000000000 20.0000000000000000, 30.0000000000000000 40.0000000000000000) LINESTRING (10.0000000000000000 10.0000000000000000, 20.0000000000000000 20.0000000000000000, 30.0000000000000000 40.0000000000000000) POLYGON ((10.0000000000000000 10.0000000000000000, 10.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 20.0000000000000000 15.0000000000000000, 10.0000000000000000 10.0000000000000000)) POLYGON ((10.0000000000000000 10.0000000000000000, 10.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 20.0000000000000000 15.0000000000000000, 10.0000000000000000 10.0000000000000000)) MULTIPOINT (20.0000000000000000 80.0000000000000000, 110.0000000000000000 160.0000000000000000, 20.0000000000000000 160.0000000000000000) MULTILINESTRING ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 80.0000000000000000, 60.000000000 0000000 80.0000000000000000, 60.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)) MULTILINESTRING ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 80.0000000000000000, 60.0000000000000000 80.0000000000000000, 60.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)) MULTIPOLYGON (((140.0000000000000000 110.0000000000000000, 260.0000000000000000 110.0000000000000000, 170.0000000000000000 20.0000000000000000, 50.0000000000000000 20.0000000000000000, 140.0000000000000000 110.0000000000000000)), ((300.0000000000000000 270.0000000000000000, 420.0000000000000000 270.0000000000000000, 340.0000000000000000 190.0000000000000000, 220.0000000000000000 190.0000000000000000, 300.0000000000000000 270.0000000000000000))) MULTIPOLYGON (((140.0000000000000000 110.0000000000000000, 260.0000000000000000 110.0000000000000000, 170.0000000000000000 20.0000000000000000, 50.0000000000000000 20.0000000000000000, 140.0000000000000000 110.00000000000 00000)), ((300.0000000000000000 270.0000000000000000, 420.0000000000000000 270.0000000000000000, 340.0000000000000000 190.0000000000000000, 220.0000000000000000 190.0000000000000000, 300.0000000000000000 270.0000000000000000))) POLYGON ((10.0000000000000000 10.0000000000000000, 10.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 20.0000000000000000 15.0000000000000000, 10.0000000000000000 10.0000000000000000)) GEOMETRYCOLLECTION (POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 100.0000000000000000, 100.0000000000000000 100.0000000000000000, 100.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)), LINESTRING (10.0000000000000000 10.0000000000000000, 20.0000000000000000 20.0000000000000000, 30.0000000000000000 40.0000000000000000)) BOX (10.000000 10.000000, 20.000000 20.000000) NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL SET SCHEMA "sys"; +create procedure analyze(minmax int, "sample" bigint) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string) +external name sql.analyze; +create procedure analyze(minmax int, "sample" bigint,sch string, tbl string, col string) +external name sql.analyze; ALTER TABLE "testschema"."keytest2" ADD CONSTRAINT "keytest2_key1_key2_fkey" FOREIGN KEY ("key1", "key2") REFERENCES "testschema"."keytest1" ("key1", "key2"); ALTER TABLE "testschema"."selfref" ADD CONSTRAINT "selfref_parentid_fkey" FOREIGN KEY ("parentid") REFERENCES "testschema"."selfref" ("id"); ALTER SEQUENCE "testschema"."selfref_seq" RESTART WITH 7 NO CYCLE; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list