Created
November 18, 2016 05:06
-
-
Save verdimrc/d7aa807e7bb6252f7e5a8f6d4dcbe073 to your computer and use it in GitHub Desktop.
Patched csv module for sqlite ('\t' as field separator)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wget -O csv.c https://www.sqlite.org/src/raw/ext/misc/csv.c?name=531a46cbad789fca0aa9db69a0e6c8ac9e68767d | |
PATCH_FILE=$(mktemp) | |
cat << EOF > $PATCH_FILE | |
--- csv.c 2016-11-17 18:41:12.567483787 +0000 | |
+++ csv-patched.c 2016-11-17 18:41:03.931517320 +0000 | |
@@ -226,7 +226,7 @@ | |
continue; | |
} | |
} | |
- if( (c==',' && pc=='"') | |
+ if( (c=='\t' && pc=='"') | |
|| (c=='\n' && pc=='"') | |
|| (c=='\n' && pc=='\r' && ppc=='"') | |
|| (c==EOF && pc=='"') | |
@@ -251,7 +251,7 @@ | |
pc = c; | |
} | |
}else{ | |
- while( c>',' || (c!=EOF && c!=',' && c!='\n') ){ | |
+ while( c>',' || (c!=EOF && c!='\t' && c!='\n') ){ | |
if( csv_append(p, (char)c) ) return 0; | |
c = csv_getc(p); | |
} | |
@@ -528,7 +528,7 @@ | |
const char *z = csv_read_one_field(&sRdr); | |
if( z==0 ) goto csvtab_connect_oom; | |
pNew->nCol++; | |
- }while( sRdr.cTerm==',' ); | |
+ }while( sRdr.cTerm=='\t' ); | |
} | |
pNew->zFilename = CSV_FILENAME; CSV_FILENAME = 0; | |
pNew->zData = CSV_DATA; CSV_DATA = 0; | |
@@ -661,7 +661,7 @@ | |
memcpy(pCur->azVal[i], z, pCur->rdr.n+1); | |
i++; | |
} | |
- }while( pCur->rdr.cTerm==',' ); | |
+ }while( pCur->rdr.cTerm=='\t' ); | |
while( i<pTab->nCol ){ | |
sqlite3_free(pCur->azVal[i]); | |
pCur->azVal[i] = 0; | |
EOF | |
patch csv.c $PATCH_FILE | |
gcc -g -fPIC -shared csv.c -o csv.so |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment