mirror of https://github.com/sqlite/sqlite
Move the "shell_add_schema()" SQL function used by the ".schema" command
of the command-line shell to a different spot in the shell.c source file so that it is not in the middle of an unrelated module. FossilOrigin-Name: 254617a1ccfa1736d4e53d670d80319c79c4d93ebf1de69d89ebdba3949bc270
This commit is contained in:
parent
f217f3b68c
commit
0942559a14
12
manifest
12
manifest
|
@ -1,5 +1,5 @@
|
|||
C Fix\stypo\sand\simprove\sthe\swording\sof\sthe\sdescription\sof\s"Metadata"\sin\sthe\noutput\sof\sthe\ssqlite3_analyzer\stool.
|
||||
D 2017-06-15T16:45:23.229
|
||||
C Move\sthe\s"shell_add_schema()"\sSQL\sfunction\sused\sby\sthe\s".schema"\scommand\nof\sthe\scommand-line\sshell\sto\sa\sdifferent\sspot\sin\sthe\sshell.c\ssource\sfile\nso\sthat\sit\sis\snot\sin\sthe\smiddle\sof\san\sunrelated\smodule.
|
||||
D 2017-06-15T16:56:05.134
|
||||
F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc
|
||||
|
@ -406,7 +406,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
|
|||
F src/resolve.c adf3ef9843135b1383321ad751f16f5a40c3f37925154555a3e61653d2a954e8
|
||||
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
|
||||
F src/select.c 0d2afdbdba5fbc61432c5454a35e0236e7aa4aa3756986a7d51b81a508e8083a
|
||||
F src/shell.c c45ae9a95faf5a495280bfa2d6b7956c707f347e56eb8b1985c852d152e46894
|
||||
F src/shell.c bcd3358ad6cb3f3dc7ec76ad3bd8191f123ed2425360c5c48fe431780eceb729
|
||||
F src/sqlite.h.in 67fa8bd29808e7988e0ce36c8d4c6043eb1727f94522fc612687aa5af51931e6
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 58fd0676d3111d02e62e5a35992a7d3da5d3f88753acc174f2d37b774fbbdd28
|
||||
|
@ -1582,7 +1582,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 9afd7a2ffd3a39456190ad05e85ff6485298aae262d9e0698a58c1d73507a36f
|
||||
R d7d9e08f1b748cb64c86b209b3f80ec6
|
||||
P ca1ff70780e07e5ee930fe7972db02e887d9b085d8ab78e878d7f966b6d684d4
|
||||
R 726cc59902873bb7eaa232bba10d7407
|
||||
U drh
|
||||
Z ab25672babe6d73331acc6dc2b1d5532
|
||||
Z 1749d6289173114f89482a05c36735c7
|
||||
|
|
|
@ -1 +1 @@
|
|||
ca1ff70780e07e5ee930fe7972db02e887d9b085d8ab78e878d7f966b6d684d4
|
||||
254617a1ccfa1736d4e53d670d80319c79c4d93ebf1de69d89ebdba3949bc270
|
110
src/shell.c
110
src/shell.c
|
@ -729,6 +729,61 @@ static char quoteChar(const char *zName){
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** SQL function: shell_add_schema(S,X)
|
||||
**
|
||||
** Add the schema name X to the CREATE statement in S and return the result.
|
||||
** Examples:
|
||||
**
|
||||
** CREATE TABLE t1(x) -> CREATE TABLE xyz.t1(x);
|
||||
**
|
||||
** Also works on
|
||||
**
|
||||
** CREATE INDEX
|
||||
** CREATE UNIQUE INDEX
|
||||
** CREATE VIEW
|
||||
** CREATE TRIGGER
|
||||
** CREATE VIRTUAL TABLE
|
||||
**
|
||||
** This UDF is used by the .schema command to insert the schema name of
|
||||
** attached databases into the middle of the sqlite_master.sql field.
|
||||
*/
|
||||
static void shellAddSchemaName(
|
||||
sqlite3_context *pCtx,
|
||||
int nVal,
|
||||
sqlite3_value **apVal
|
||||
){
|
||||
static const char *aPrefix[] = {
|
||||
"TABLE",
|
||||
"INDEX",
|
||||
"UNIQUE INDEX",
|
||||
"VIEW",
|
||||
"TRIGGER",
|
||||
"VIRTUAL TABLE"
|
||||
};
|
||||
int i = 0;
|
||||
const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
|
||||
const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
|
||||
assert( nVal==2 );
|
||||
if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
|
||||
for(i=0; i<sizeof(aPrefix)/sizeof(aPrefix[0]); i++){
|
||||
int n = strlen30(aPrefix[i]);
|
||||
if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
|
||||
char cQuote = quoteChar(zSchema);
|
||||
char *z;
|
||||
if( cQuote ){
|
||||
z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
|
||||
}else{
|
||||
z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
|
||||
}
|
||||
sqlite3_result_text(pCtx, z, -1, sqlite3_free);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_result_value(pCtx, apVal[0]);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
** SHA3 hash implementation copied from ../ext/misc/shathree.c
|
||||
*/
|
||||
|
@ -1185,61 +1240,6 @@ static unsigned char *SHA3Final(SHA3Context *p){
|
|||
return &p->u.x[p->nRate];
|
||||
}
|
||||
|
||||
/*
|
||||
** SQL function: shell_add_schema(S,X)
|
||||
**
|
||||
** Add the schema name X to the CREATE statement in S and return the result.
|
||||
** Examples:
|
||||
**
|
||||
** CREATE TABLE t1(x) -> CREATE TABLE xyz.t1(x);
|
||||
**
|
||||
** Also works on
|
||||
**
|
||||
** CREATE INDEX
|
||||
** CREATE UNIQUE INDEX
|
||||
** CREATE VIEW
|
||||
** CREATE TRIGGER
|
||||
** CREATE VIRTUAL TABLE
|
||||
**
|
||||
** This UDF is used by the .schema command to insert the schema name of
|
||||
** attached databases into the middle of the sqlite_master.sql field.
|
||||
*/
|
||||
static void shellAddSchemaName(
|
||||
sqlite3_context *pCtx,
|
||||
int nVal,
|
||||
sqlite3_value **apVal
|
||||
){
|
||||
static const char *aPrefix[] = {
|
||||
"TABLE",
|
||||
"INDEX",
|
||||
"UNIQUE INDEX",
|
||||
"VIEW",
|
||||
"TRIGGER",
|
||||
"VIRTUAL TABLE"
|
||||
};
|
||||
int i = 0;
|
||||
const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
|
||||
const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
|
||||
assert( nVal==2 );
|
||||
if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
|
||||
for(i=0; i<sizeof(aPrefix)/sizeof(aPrefix[0]); i++){
|
||||
int n = strlen30(aPrefix[i]);
|
||||
if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
|
||||
char cQuote = quoteChar(zSchema);
|
||||
char *z;
|
||||
if( cQuote ){
|
||||
z = sqlite3_mprintf("%.*s \"%w\".%s", n+7, zIn, zSchema, zIn+n+8);
|
||||
}else{
|
||||
z = sqlite3_mprintf("%.*s %s.%s", n+7, zIn, zSchema, zIn+n+8);
|
||||
}
|
||||
sqlite3_result_text(pCtx, z, -1, sqlite3_free);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_result_value(pCtx, apVal[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sha3(X,SIZE) function.
|
||||
**
|
||||
|
|
Loading…
Reference in New Issue