Skip to content

Commit

Permalink
overwrite-auto: change sqlite3 schema to expect "column", not "col" (#…
Browse files Browse the repository at this point in the history
…248)

* overwrite-auto: change sqlite3 schema to expect "column", not "col"
  • Loading branch information
liquidaty authored Oct 29, 2024
1 parent 71b86e9 commit b3ab4f0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/utils/overwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions data/loans_2_overwrite.sql
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion include/zsv/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions include/zsv/utils/overwrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -29,7 +29,7 @@ struct zsv_overwrite_opts {
* 1. sqlite3 file source:
* sqlite3://<filename>[?sql=<query>]",
*
* 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
*
Expand Down

0 comments on commit b3ab4f0

Please sign in to comment.