Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overwrite-auto: change sqlite3 schema to expect "column", not "col" #248

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/[email protected] && ${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}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/[email protected] && ${TEST_PASS} || ${TEST_FAIL}
@${PREFIX} $< ${TEST_DATA_DIR}/loans_2.csv --overwrite-auto ${REDIRECT} ${TMP_DIR}/[email protected]
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