From 412c9ded71b448da60a59c06ade1a068d9523ab7 Mon Sep 17 00:00:00 2001 From: liquidaty Date: Tue, 29 Oct 2024 13:37:50 -0700 Subject: [PATCH 1/3] overwrite-auto: change sqlite3 schema to expect "column", not "col" --- app/utils/overwrite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/utils/overwrite.c b/app/utils/overwrite.c index 16c87f3a..38192951 100644 --- a/app/utils/overwrite.c +++ b/app/utils/overwrite.c @@ -138,7 +138,7 @@ static enum zsv_status zsv_overwrite_init_sqlite3(struct zsv_overwrite_ctx *ctx, ok = 1; } else if (len > strlen(".sqlite3") && !strcmp(source + len - strlen(".sqlite3"), ".sqlite3")) { ctx->sqlite3.filename = strdup(source); - ctx->sqlite3.sql = "select row, col, value from overwrites order by row, col"; + ctx->sqlite3.sql = "select row, column, value from overwrites order by row, column"; ok = 1; } @@ -195,7 +195,7 @@ enum zsv_status zsv_overwrite_open(void *h) { struct zsv_cell val = zsv_get_cell(ctx->csv.parser, 2); if (row.len < 3 || memcmp(row.str, "row", 3) || col.len < 3 || memcmp(col.str, "col", 3) || val.len < 3 || memcmp(val.str, "val", 3)) - fprintf(stderr, "Warning! overwrite expects 'row,col,value' header, got '%.*s,%.*s,%.*s'\n", (int)row.len, + fprintf(stderr, "Warning! overwrite expects 'row,column,value' header, got '%.*s,%.*s,%.*s'\n", (int)row.len, row.str, (int)col.len, col.str, (int)val.len, val.str); } ctx->next = zsv_next_overwrite_csv; From 24289b7a956de8a43da11583ad4cf3e1701f2596 Mon Sep 17 00:00:00 2001 From: liquidaty Date: Tue, 29 Oct 2024 14:00:37 -0700 Subject: [PATCH 2/3] clean up header files and tests --- app/test/Makefile | 2 +- app/utils/overwrite.c | 2 +- include/zsv/common.h | 2 +- include/zsv/utils/overwrite.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/test/Makefile b/app/test/Makefile index 2ca8f5ae..59fb57a3 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -170,7 +170,7 @@ test-echo-overwrite-auto: ${BUILD_DIR}/bin/zsv_echo${EXE} @${PREFIX} $< ${TEST_DATA_DIR}/loans_2.csv ${REDIRECT} ${TMP_DIR}/$@-before.out @${CMP} ${TMP_DIR}/$@-before.out expected/$@-before.out && ${TEST_PASS} || ${TEST_FAIL} @mkdir -p ${TEST_DATA_DIR}/.zsv/data/loans_2.csv - @cp -p ${TEST_DATA_DIR}/loans_1-overwrite.db ${TEST_DATA_DIR}/.zsv/data/loans_2.csv/overwrite.sqlite3 + @sqlite3 ${TEST_DATA_DIR}/.zsv/data/loans_2.csv/overwrite.sqlite3 < ${TEST_DATA_DIR}/loans_2_overwrite.sql @${PREFIX} $< ${TEST_DATA_DIR}/loans_2.csv ${REDIRECT} ${TMP_DIR}/$@-after-ignored.out @${CMP} ${TMP_DIR}/$@-after-ignored.out expected/$@-after-ignored.out && ${TEST_PASS} || ${TEST_FAIL} @${PREFIX} $< ${TEST_DATA_DIR}/loans_2.csv --overwrite-auto ${REDIRECT} ${TMP_DIR}/$@-after-applied.out diff --git a/app/utils/overwrite.c b/app/utils/overwrite.c index 38192951..873e6872 100644 --- a/app/utils/overwrite.c +++ b/app/utils/overwrite.c @@ -195,7 +195,7 @@ enum zsv_status zsv_overwrite_open(void *h) { struct zsv_cell val = zsv_get_cell(ctx->csv.parser, 2); if (row.len < 3 || memcmp(row.str, "row", 3) || col.len < 3 || memcmp(col.str, "col", 3) || val.len < 3 || memcmp(val.str, "val", 3)) - fprintf(stderr, "Warning! overwrite expects 'row,column,value' header, got '%.*s,%.*s,%.*s'\n", (int)row.len, + fprintf(stderr, "Warning! overwrite expects 'row,col,value' header, got '%.*s,%.*s,%.*s'\n", (int)row.len, row.str, (int)col.len, col.str, (int)val.len, val.str); } ctx->next = zsv_next_overwrite_csv; diff --git a/include/zsv/common.h b/include/zsv/common.h index 651fafa6..4de1906e 100644 --- a/include/zsv/common.h +++ b/include/zsv/common.h @@ -295,7 +295,7 @@ struct zsv_opts { /** * If non-zero, automatically apply overwrites located in - * /path/to/.zsv/data/my-data.csv/overwrites.db for a given + * /path/to/.zsv/data/my-data.csv/overwrite.sqlite3 for a given * input /path/to/my-data.csv * * This flag is only used by zsv_new_with_properties() diff --git a/include/zsv/utils/overwrite.h b/include/zsv/utils/overwrite.h index 7a0a5a97..64e6d957 100644 --- a/include/zsv/utils/overwrite.h +++ b/include/zsv/utils/overwrite.h @@ -4,7 +4,7 @@ /** * The easiest way to enable overwrite support is to use zsv_overwrite_auto() * which, given an input located at /path/to/my-data.csv, will assume an overwrite source - * located at /path/to/.zsv/data/my-data.csv/overwrites.sqlite3 + * located at /path/to/.zsv/data/my-data.csv/overwrite.sqlite3 * in a table named 'overwrites' * * zsv_overwrite_auto() returns: @@ -29,7 +29,7 @@ struct zsv_overwrite_opts { * 1. sqlite3 file source: * sqlite3://[?sql=]", * - * e.g. sqlite3://overwrites.db?sql=select row, column, value from overwrites order by row, column", + * e.g. sqlite3:///path/to/my-overwritedb.sqlite3?sql=select row, column, value from overwrites order by row, column", * * or * From d32db77b9a1127280cdb0b4e253ec32fb599a16a Mon Sep 17 00:00:00 2001 From: liquidaty Date: Tue, 29 Oct 2024 14:05:02 -0700 Subject: [PATCH 3/3] add data/loans_2_overwrite.sql --- data/loans_2_overwrite.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 data/loans_2_overwrite.sql diff --git a/data/loans_2_overwrite.sql b/data/loans_2_overwrite.sql new file mode 100644 index 00000000..2bbcad2f --- /dev/null +++ b/data/loans_2_overwrite.sql @@ -0,0 +1,9 @@ +PRAGMA foreign_keys=OFF; +BEGIN TRANSACTION; +CREATE TABLE overwrites(row int, column int, value text); +INSERT INTO overwrites VALUES(10,4,'hello1'); +INSERT INTO overwrites VALUES(10,2,'hello2'); +INSERT INTO overwrites VALUES(8,3,'hello3'); +INSERT INTO overwrites VALUES(8,15,'hello4'); +INSERT INTO overwrites VALUES(8,99999,'never'); +COMMIT;