Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | In the command-line shell, in the output of the ".dump", ".schema", and ".fullschema" commands, convert CREATE TABLE statements that appear to come from shadow tables into CREATE TABLE IF NOT EXISTS statements. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
c7021960f5c070fb5c9db9e41b4000d3 |
User & Date: | drh 2016-12-13 23:22:39 |
Context
2016-12-14
| ||
10:30 | Fix the optimization that prevents writing freelist pages to the journal. (check-in: 6aa9b265 user: drh tags: trunk) | |
2016-12-13
| ||
23:22 | In the command-line shell, in the output of the ".dump", ".schema", and ".fullschema" commands, convert CREATE TABLE statements that appear to come from shadow tables into CREATE TABLE IF NOT EXISTS statements. (check-in: c7021960 user: drh tags: trunk) | |
20:30 | Fix harmless compiler warnings. (check-in: ed2c9f37 user: drh tags: trunk) | |
Changes
Changes to src/shell.c.
︙ | ︙ | |||
942 943 944 945 946 947 948 949 950 951 952 953 954 955 | } } raw_printf(p->out, "\n"); return SQLITE_OK; } #endif /* ** This is the callback routine that the shell ** invokes for each row of a query result. */ static int shell_callback( void *pArg, | > > > > > > > > > > > > > > > > > > > | 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | } } raw_printf(p->out, "\n"); return SQLITE_OK; } #endif /* ** Print a schema statement. Part of MODE_Semi and MODE_Pretty output. ** ** This routine converts some CREATE TABLE statements for shadow tables ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements. */ static void printSchemaLine(FILE *out, const char *z, const char *zTail){ if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){ utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail); }else{ utf8_printf(out, "%s%s", z, zTail); } } static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){ char c = z[n]; z[n] = 0; printSchemaLine(out, z, zTail); z[n] = c; } /* ** This is the callback routine that the shell ** invokes for each row of a query result. */ static int shell_callback( void *pArg, |
︙ | ︙ | |||
1060 1061 1062 1063 1064 1065 1066 | azArg[i] ? azArg[i] : p->nullValue, i==nArg-1 ? rowSep : " "); } } break; } case MODE_Semi: { /* .schema and .fullschema output */ | | | 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | azArg[i] ? azArg[i] : p->nullValue, i==nArg-1 ? rowSep : " "); } } break; } case MODE_Semi: { /* .schema and .fullschema output */ printSchemaLine(p->out, azArg[0], ";\n"); break; } case MODE_Pretty: { /* .schema and .fullschema with --indent */ char *z; int j; int nParen = 0; char cEnd = 0; |
︙ | ︙ | |||
1104 1105 1106 1107 1108 1109 1110 | }else if( c=='[' ){ cEnd = ']'; }else if( c=='(' ){ nParen++; }else if( c==')' ){ nParen--; if( nLine>0 && nParen==0 && j>0 ){ | | | | | 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | }else if( c=='[' ){ cEnd = ']'; }else if( c=='(' ){ nParen++; }else if( c==')' ){ nParen--; if( nLine>0 && nParen==0 && j>0 ){ printSchemaLineN(p->out, z, j, "\n"); j = 0; } } z[j++] = c; if( nParen==1 && (c=='(' || c==',' || c=='\n') ){ if( c=='\n' ) j--; printSchemaLineN(p->out, z, j, "\n "); j = 0; nLine++; while( IsSpace(z[i+1]) ){ i++; } } } z[j] = 0; } printSchemaLine(p->out, z, ";\n"); sqlite3_free(z); break; } case MODE_List: { if( p->cnt++==0 && p->showHeader ){ for(i=0; i<nArg; i++){ utf8_printf(p->out,"%s%s",azCol[i], |
︙ | ︙ | |||
2042 2043 2044 2045 2046 2047 2048 | "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)" "VALUES('table','%q','%q',0,'%q');", zTable, zTable, zSql); utf8_printf(p->out, "%s\n", zIns); sqlite3_free(zIns); return 0; }else{ | | | 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 | "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)" "VALUES('table','%q','%q',0,'%q');", zTable, zTable, zSql); utf8_printf(p->out, "%s\n", zIns); sqlite3_free(zIns); return 0; }else{ printSchemaLine(p->out, zSql, ";\n"); } if( strcmp(zType, "table")==0 ){ sqlite3_stmt *pTableInfo = 0; char *zSelect = 0; char *zTableInfo = 0; char *zTmp = 0; |
︙ | ︙ |