mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Add --schema S option to .import
FossilOrigin-Name: 38d9dbca166078013a44214c88805fc7cca578976ceed9fc62f5159a38ec96a7
This commit is contained in:
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
||||
C When\sthe\sresult\sof\sa\ssubquery\sis\sto\sbe\sstored\sin\sa\sregister\sand\sthat\nsubquery\shas\san\sORDER\sBY\sclause\sand\san\sOFFSET,\sNULL\sout\sthe\sdestination\nregister\sbefore\sstarting\sthe\sORDER\sBY\sso\sthat\sthe\sregister\swill\sbe\sset\ncorrectly\seven\sif\sthe\sOFFSET\sis\slarger\sthan\sthe\snumber\sof\soutput\srows.\nFix\sfor\sthe\sproblem\sreported\sin\n[forum:/forumpost/0ec80f12d02acb3f|forum\spost\s0ec80f12d02acb3f].
|
||||
D 2022-01-12T20:31:14.514
|
||||
C Add\s--schema\sS\soption\sto\s.import
|
||||
D 2022-01-13T21:22:54.666
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -552,7 +552,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
|
||||
F src/resolve.c 359bc0e445d427583d2ab6110433a5dc777f64a0ecdf8d24826d8b475233ead9
|
||||
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
|
||||
F src/select.c a4a23a70f0a24a1103ac9698f6be181a6ec7ff6c19e03e8899c43cb6d2af09d6
|
||||
F src/shell.c.in f5111900d646a07da18e6438d57be20f112397daba6bfc85b117a0da586e55da
|
||||
F src/shell.c.in 851ce2b310888c68f3f66d876b7392cc822f0cb0e316b1a89997abb1d7ec67f0
|
||||
F src/sqlite.h.in a5e0d6bd47e67aabf1475986d36bdcc7bfa9e06566790ebf8e3aa7fa551c9f99
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 01eb85e4f2759a5ee79c183f4b2877889d4ffdc49d27ae74529c9579e3c8c0ef
|
||||
@ -1388,7 +1388,7 @@ F test/shell1.test 70f46b5d07776a107335c3c2c9cbd0431d44637bfeae1f6b9ded5e33b4c7c
|
||||
F test/shell2.test f00a0501c00583cbc46f7510e1d713366326b2b3e63d06d15937284171a8787c
|
||||
F test/shell3.test cb4b835a901742c9719437a89171172ecc4a8823ad97349af8e4e841e6f82566
|
||||
F test/shell4.test 3ed6c4b42fd695efcbc25d69ef759dbb15855ca8e52ba6c5ee076f8b435f48be
|
||||
F test/shell5.test 6e4aa0e531dcb8dcf74b7920a2a7442c6712d4dff8422bbc81f768f9dee8a0e3
|
||||
F test/shell5.test b85069bfcf3159b225228629ab2c3e69aa923d098fea8ea074b5dcd743522e2c
|
||||
F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3
|
||||
F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f
|
||||
F test/shell8.test 388471d16e4de767333107e30653983f186232c0e863f4490bb230419e830aae
|
||||
@ -1938,8 +1938,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 02aaa10f34ab17e76feb7b6f79048309536c0794fcb534b934e06f3daedfeaba
|
||||
R 926926c5df28210b2eccf7396e21106e
|
||||
U drh
|
||||
Z bb0f2b9d8929fd104a37ff3ae2f31816
|
||||
P 9282bcde301cee2a5c3c068b5b0b7ce992c155ece894413a6a9a51a81e4133fd
|
||||
R 85600e55f5465c0d7b90f18f16da5617
|
||||
U larrybr
|
||||
Z 49bd76acfcc3b273011e69ab0fa8281f
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
9282bcde301cee2a5c3c068b5b0b7ce992c155ece894413a6a9a51a81e4133fd
|
||||
38d9dbca166078013a44214c88805fc7cca578976ceed9fc62f5159a38ec96a7
|
@ -4070,6 +4070,7 @@ static const char *(azHelp[]) = {
|
||||
" --ascii Use \\037 and \\036 as column and row separators",
|
||||
" --csv Use , and \\n as column and row separators",
|
||||
" --skip N Skip the first N rows of input",
|
||||
" --schema S Target table to be S.TABLE",
|
||||
" -v \"Verbose\" - increase auxiliary output",
|
||||
" Notes:",
|
||||
" * If TABLE does not exist, it is created. The first row of input",
|
||||
@ -8382,6 +8383,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
|
||||
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
|
||||
char *zTable = 0; /* Insert data into this table */
|
||||
char *zSchema = "main"; /* within this schema */
|
||||
char *zFile = 0; /* Name of file to extra content from */
|
||||
sqlite3_stmt *pStmt = NULL; /* A statement */
|
||||
int nCol; /* Number of columns in the table */
|
||||
@ -8424,6 +8426,8 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
}
|
||||
}else if( strcmp(z,"-v")==0 ){
|
||||
eVerbose++;
|
||||
}else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
|
||||
zSchema = azArg[++i];
|
||||
}else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
|
||||
nSkip = integerValue(azArg[++i]);
|
||||
}else if( strcmp(z,"-ascii")==0 ){
|
||||
@ -8515,6 +8519,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
import_cleanup(&sCtx);
|
||||
goto meta_command_exit;
|
||||
}
|
||||
/* Below, resources must be freed before exit. */
|
||||
if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
|
||||
char zSep[2];
|
||||
zSep[1] = 0;
|
||||
@ -8529,7 +8534,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
while( (nSkip--)>0 ){
|
||||
while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
|
||||
}
|
||||
zSql = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
|
||||
zSql = sqlite3_mprintf("SELECT * FROM %s.\"%w\"", zSchema, zTable);
|
||||
if( zSql==0 ){
|
||||
import_cleanup(&sCtx);
|
||||
shell_out_of_memory();
|
||||
@ -8538,7 +8543,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
|
||||
import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
|
||||
if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
|
||||
char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\"", zTable);
|
||||
char *zCreate = sqlite3_mprintf("CREATE TABLE %s.\"%w\"", zSchema,zTable);
|
||||
char cSep = '(';
|
||||
while( xRead(&sCtx) ){
|
||||
zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
|
||||
@ -8559,8 +8564,8 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
|
||||
sqlite3_free(zCreate);
|
||||
if( rc ){
|
||||
utf8_printf(stderr, "CREATE TABLE \"%s\"(...) failed: %s\n", zTable,
|
||||
sqlite3_errmsg(p->db));
|
||||
utf8_printf(stderr, "CREATE TABLE %s.\"%s\"(...) failed: %s\n",
|
||||
zSchema, zTable, sqlite3_errmsg(p->db));
|
||||
import_cleanup(&sCtx);
|
||||
rc = 1;
|
||||
goto meta_command_exit;
|
||||
@ -8584,7 +8589,8 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
import_cleanup(&sCtx);
|
||||
shell_out_of_memory();
|
||||
}
|
||||
sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
|
||||
sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s.\"%w\" VALUES(?",
|
||||
zSchema, zTable);
|
||||
j = strlen30(zSql);
|
||||
for(i=1; i<nCol; i++){
|
||||
zSql[j++] = ',';
|
||||
|
@ -88,8 +88,9 @@ do_test shell5-1.4.2 {
|
||||
forcedelete shell5.csv
|
||||
set in [open shell5.csv w]
|
||||
close $in
|
||||
set res [catchcmd "test.db" {.import shell5.csv t1
|
||||
SELECT COUNT(*) FROM t1;}]
|
||||
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
|
||||
.import -schema test shell5.csv t1
|
||||
SELECT COUNT(*) FROM test.t1;}]
|
||||
} {0 0}
|
||||
|
||||
# import file with 1 row, 1 column (expecting 2 cols)
|
||||
@ -97,7 +98,8 @@ do_test shell5-1.4.3 {
|
||||
set in [open shell5.csv w]
|
||||
puts $in "1"
|
||||
close $in
|
||||
set res [catchcmd "test.db" {.import shell5.csv t1}]
|
||||
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
|
||||
.import -schema test shell5.csv t1}]
|
||||
} {1 {shell5.csv:1: expected 2 columns but found 1 - filling the rest with NULL}}
|
||||
|
||||
# import file with 1 row, 3 columns (expecting 2 cols)
|
||||
@ -105,7 +107,8 @@ do_test shell5-1.4.4 {
|
||||
set in [open shell5.csv w]
|
||||
puts $in "1|2|3"
|
||||
close $in
|
||||
set res [catchcmd "test.db" {.import shell5.csv t1}]
|
||||
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
|
||||
.import --schema test shell5.csv t1}]
|
||||
} {1 {shell5.csv:1: expected 2 columns but found 3 - extras ignored}}
|
||||
|
||||
# import file with 1 row, 2 columns
|
||||
@ -126,8 +129,9 @@ do_test shell5-1.4.6 {
|
||||
puts $in "2|3"
|
||||
puts $in "3|4"
|
||||
close $in
|
||||
set res [catchcmd "test.db" {.import shell5.csv t1
|
||||
SELECT COUNT(*) FROM t1;}]
|
||||
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
|
||||
.import -schema test shell5.csv t1
|
||||
SELECT COUNT(*) FROM test.t1;}]
|
||||
} {0 3}
|
||||
|
||||
# import file with 1 row, 2 columns, using a comma
|
||||
@ -135,9 +139,10 @@ do_test shell5-1.4.7 {
|
||||
set in [open shell5.csv w]
|
||||
puts $in "4,5"
|
||||
close $in
|
||||
set res [catchcmd "test.db" {.separator ,
|
||||
.import shell5.csv t1
|
||||
SELECT COUNT(*) FROM t1;}]
|
||||
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
|
||||
.separator ,
|
||||
.import --schema test shell5.csv t1
|
||||
SELECT COUNT(*) FROM test.t1;}]
|
||||
} {0 4}
|
||||
|
||||
# import file with 1 row, 2 columns, text data
|
||||
|
Reference in New Issue
Block a user