0
0
mirror of https://github.com/sqlite/sqlite.git synced 2024-11-21 11:19:14 +01:00

Port sqldiff over to use sqlite3_stdio.

FossilOrigin-Name: 18f784c47d4252bc3696a7e084a1afb9f51f006cf2021292f2103531b8235226
This commit is contained in:
drh 2024-09-24 17:40:54 +00:00
parent 0be2dd9a1b
commit a55901a27c
8 changed files with 106 additions and 102 deletions

View File

@ -694,8 +694,8 @@ sqlite3$(TEXE): shell.c sqlite3.c
shell.c sqlite3.c \
$(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
sqldiff$(TEXE): $(TOP)/tool/sqldiff.c sqlite3.lo sqlite3.h
$(LTLINK) -o $@ $(TOP)/tool/sqldiff.c sqlite3.lo $(TLIBS)
sqldiff$(TEXE): $(TOP)/tool/sqldiff.c $(TOP)/ext/misc/sqlite3_stdio.h sqlite3.lo sqlite3.h
$(LTLINK) -I$(TOP)/ext/misc -o $@ $(TOP)/tool/sqldiff.c sqlite3.lo $(TLIBS)
dbhash$(TEXE): $(TOP)/tool/dbhash.c sqlite3.lo sqlite3.h
$(LTLINK) -o $@ $(TOP)/tool/dbhash.c sqlite3.lo $(TLIBS)

View File

@ -1861,8 +1861,8 @@ $(SQLITE3EXE): shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLIT
/link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS)
# <<mark>>
sqldiff.exe: $(TOP)\tool\sqldiff.c $(TOP)\ext\consio\console_io.h $(TOP)\ext\consio\console_io.c $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS)
$(LTLINK) $(NO_WARN) -I$(TOP)\ext\consio $(TOP)\tool\sqldiff.c $(TOP)\ext\consio\console_io.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) $(LIBRESOBJS)
sqldiff.exe: $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.h $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS)
$(LTLINK) $(NO_WARN) -I$(TOP)\ext\misc $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) $(LIBRESOBJS)
dbhash.exe: $(TOP)\tool\dbhash.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(TOP)\tool\dbhash.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)

View File

@ -14,6 +14,19 @@
** on Windows.
*/
#ifdef _WIN32 /* This file is a no-op on all platforms except Windows */
#include "sqlite3_stdio.h"
#undef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "sqlite3.h"
#include <ctype.h>
#include <stdarg.h>
#include <io.h>
#include <fcntl.h>
/*
** Work-alike for the fopen() routine from the standard C library.
@ -68,7 +81,7 @@ FILE *sqlite3_popen(const char *zCommand, const char *zMode){
** Work-alike for fgets() from the standard C library.
*/
char *sqlite3_fgets(char *buf, int sz, FILE *in){
if( isatty(_fileno(in)) ){
if( _isatty(_fileno(in)) ){
/* When reading from the command-prompt in Windows, it is necessary
** to use _O_WTEXT input mode to read UTF-16 characters, then translate
** that into UTF-8. Otherwise, non-ASCII characters all get translated
@ -95,7 +108,7 @@ char *sqlite3_fgets(char *buf, int sz, FILE *in){
** Work-alike for fputs() from the standard C library.
*/
int sqlite3_fputs(const char *z, FILE *out){
if( isatty(_fileno(out)) ){
if( _isatty(_fileno(out)) ){
/* When writing to the command-prompt in Windows, it is necessary
** to use _O_WTEXT input mode and write UTF-16 characters.
*/
@ -121,7 +134,7 @@ int sqlite3_fputs(const char *z, FILE *out){
*/
int sqlite3_fprintf(FILE *out, const char *zFormat, ...){
int rc;
if( isatty(fileno(out)) ){
if( _isatty(fileno(out)) ){
/* When writing to the command-prompt in Windows, it is necessary
** to use _O_WTEXT input mode and write UTF-16 characters.
*/

View File

@ -26,6 +26,8 @@
** also link in the accompanying sqlite3_stdio.c source file when compiling
** to get compatible interfaces.
*/
#ifndef _SQLITE3_STDIO_H_
#define _SQLITE3_STDIO_H_ 1
#ifdef _WIN32
/**** Definitions For Windows ****/
#include <stdio.h>
@ -50,3 +52,4 @@ void sqlite3_fsetmode(FILE *stream, int mode);
#define sqlite3_fsetmode(F,X) /*no-op*/
#endif
#endif /* _SQLITE3_STDIO_H_ */

View File

@ -560,8 +560,8 @@ sqlite3$(EXE): sqlite3.h libsqlite3.a shell.c
$(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) $(SHELL_OPT) \
shell.c libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB)
sqldiff$(EXE): $(TOP)/tool/sqldiff.c sqlite3.c sqlite3.h
$(TCCX) -o sqldiff$(EXE) -DSQLITE_THREADSAFE=0 \
sqldiff$(EXE): $(TOP)/tool/sqldiff.c $(TOP)/ext/misc/sqlite3_stdio.h sqlite3.c sqlite3.h
$(TCCX) -I$(TOP)/ext/misc -o sqldiff$(EXE) -DSQLITE_THREADSAFE=0 \
$(TOP)/tool/sqldiff.c sqlite3.c $(TLIBS) $(THREADLIB)
dbhash$(EXE): $(TOP)/tool/dbhash.c sqlite3.c sqlite3.h

View File

@ -1,11 +1,11 @@
C Get\soutput\sredirection\sworking\sagain\sin\sthe\sCLI.
D 2024-09-24T16:09:50.466
C Port\ssqldiff\sover\sto\suse\ssqlite3_stdio.
D 2024-09-24T17:40:54.086
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F Makefile.in a8e1d44a1166b6fb368effb19edc9adf7fede9225e9563352b9bb1989cd0150d
F Makefile.in 6a826facc78c3c8ad38bf00ed588f6aa3665ccd7a9749b891d20582fc290c77e
F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6
F Makefile.msc 1a5234794c9a5a71ba13fb47bcf031814d45b3ed6a56b4cb8e9f63fd32b4febe
F Makefile.msc 10fcf3b1eff1859846878469ffad1ebcd168fa0bd9e8a81f76ce65465b79e35d
F README.md c3c0f19532ce28f6297a71870f3c7b424729f0e6d9ab889616d3587dd2332159
F VERSION 0db40f92c04378404eb45bff93e9e42c148c7e54fd3da99469ed21e22411f5a6
F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50
@ -425,8 +425,8 @@ F ext/misc/shathree.c 1821d90a0040c9accdbe3e3527d378d30569475d758aa70f6848924c0b
F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52
F ext/misc/spellfix.c c0aa7b80d6df45f7da59d912b38752bcac1af53a5766966160e6c5cdd397dbea
F ext/misc/sqlar.c a6175790482328171da47095f87608b48a476d4fac78d8a9ff18b03a2454f634
F ext/misc/sqlite3_stdio.c 4d4190eac193a8ea8fc3f8259e0996cf8e54254b4f4925d71e456e88165401d8
F ext/misc/sqlite3_stdio.h ddefddeb448eee7fe2d41a828356a0019f813a4ced4ea2e97faa1d6c3e803742
F ext/misc/sqlite3_stdio.c d9c7b3883788ef6e15134323783d6a3c69d2b453545a2aa60d8a3503bfeadcb7
F ext/misc/sqlite3_stdio.h f05eaf5e0258f0573910324a789a9586fc360a57678c57a6d63cfaa2245b6176
F ext/misc/stmt.c b090086cd6bd6281c21271d38d576eeffe662f0e6b67536352ce32bbaa438321
F ext/misc/stmtrand.c 59cffa5d8e158943ff1ce078956d8e208e8c04e67307e8f249dece2436dcb7fc
F ext/misc/templatevtab.c 10f15b165b95423ddef593bc5dcb915ec4eb5e0f1066d585e5435a368b8bc22b
@ -689,7 +689,7 @@ F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
F main.mk dcb5cbba0ad64bd639b3e05d73d92e27c144a55bab9fca3460699602f4e9f4c2
F main.mk 0a55ebec3508ca1bdb593d86f3aa19d7fa42a2ddd3220703e6dc0a65f1338a43
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421
@ -2175,7 +2175,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 7ce07da76b5e745783e703a834417d725b7d45fd
F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d40618 x
F tool/split-sqlite3c.tcl 5aa60643afca558bc732b1444ae81a522326f91e1dc5665b369c54f09e20de60
F tool/sqldiff.c 847fc8fcfddf5ce4797b7394cad6372f2f5dc17d8186e2ef8fb44d50fae4f44a
F tool/sqldiff.c 2a0987d183027c795ced13d6749061c1d2f38e24eddb428f56fa64c3a8f51e4b
F tool/sqlite3-rsync.c 187b262035c1159b047dbfa1959c168b87b5a153b63465e8c8bd1b54fabf4460
F tool/sqlite3_analyzer.c.in 8da2b08f56eeac331a715036cf707cc20f879f231362be0c22efd682e2b89b4f
F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898
@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P fcd0ecffc9889f8c855ea340f075ec42cdca482df82d6e67dc9c32613e8d5846
R bfd2b7dbaf4f82e5e4b17d1ed0ea1a8f
P 086034c3508d95e4f620c5e0580fae770e85410b0c8bd94f600fc0fd25088947
R d688762d4b1334b98cdf41bc1c1c4c96
U drh
Z 5097f278634497c50b8747316810c634
Z 9855069890c5f74ec21934036ad0fa9f
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
086034c3508d95e4f620c5e0580fae770e85410b0c8bd94f600fc0fd25088947
18f784c47d4252bc3696a7e084a1afb9f51f006cf2021292f2103531b8235226

View File

@ -14,7 +14,7 @@
** between two SQLite databases.
**
** To compile, simply link against SQLite. (Windows builds must also link
** against ext/consio/console_io.c.)
** against ext/misc/sqlite3_stdio.c.)
**
** See the showHelp() routine below for a brief description of how to
** run the utility.
@ -26,19 +26,7 @@
#include <string.h>
#include <assert.h>
#include "sqlite3.h"
/* Output function substitutions that cause UTF8 characters to be rendered
** correctly on Windows:
**
** fprintf() -> Wfprintf()
**
*/
#if defined(_WIN32)
# include "console_io.h"
# define Wfprintf fPrintfUtf8
#else
# define Wfprintf fprintf
#endif
#include "sqlite3_stdio.h"
/*
** All global variables are gathered into the "g" singleton.
@ -76,9 +64,9 @@ static void cmdlineError(const char *zFormat, ...){
va_start(ap, zFormat);
sqlite3_str_vappendf(pOut, zFormat, ap);
va_end(ap);
Wfprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut));
sqlite3_fprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut));
strFree(pOut);
Wfprintf(stderr, "\"%s --help\" for more help\n", g.zArgv0);
sqlite3_fprintf(stderr, "\"%s --help\" for more help\n", g.zArgv0);
exit(1);
}
@ -92,7 +80,7 @@ static void runtimeError(const char *zFormat, ...){
va_start(ap, zFormat);
sqlite3_str_vappendf(pOut, zFormat, ap);
va_end(ap);
Wfprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut));
sqlite3_fprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut));
strFree(pOut);
exit(1);
}
@ -349,11 +337,11 @@ static void printQuoted(FILE *out, sqlite3_value *X){
char zBuf[50];
r1 = sqlite3_value_double(X);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1);
fprintf(out, "%s", zBuf);
sqlite3_fprintf(out, "%s", zBuf);
break;
}
case SQLITE_INTEGER: {
fprintf(out, "%lld", sqlite3_value_int64(X));
sqlite3_fprintf(out, "%lld", sqlite3_value_int64(X));
break;
}
case SQLITE_BLOB: {
@ -361,14 +349,14 @@ static void printQuoted(FILE *out, sqlite3_value *X){
int nBlob = sqlite3_value_bytes(X);
if( zBlob ){
int i;
fprintf(out, "x'");
sqlite3_fprintf(out, "x'");
for(i=0; i<nBlob; i++){
fprintf(out, "%02x", zBlob[i]);
sqlite3_fprintf(out, "%02x", zBlob[i]);
}
fprintf(out, "'");
sqlite3_fprintf(out, "'");
}else{
/* Could be an OOM, could be a zero-byte blob */
fprintf(out, "X''");
sqlite3_fprintf(out, "X''");
}
break;
}
@ -376,38 +364,38 @@ static void printQuoted(FILE *out, sqlite3_value *X){
const unsigned char *zArg = sqlite3_value_text(X);
if( zArg==0 ){
fprintf(out, "NULL");
sqlite3_fprintf(out, "NULL");
}else{
int inctl = 0;
int i, j;
fprintf(out, "'");
sqlite3_fprintf(out, "'");
for(i=j=0; zArg[i]; i++){
char c = zArg[i];
int ctl = iscntrl((unsigned char)c);
if( ctl>inctl ){
inctl = ctl;
fprintf(out, "%.*s'||X'%02x", i-j, &zArg[j], c);
sqlite3_fprintf(out, "%.*s'||X'%02x", i-j, &zArg[j], c);
j = i+1;
}else if( ctl ){
fprintf(out, "%02x", c);
sqlite3_fprintf(out, "%02x", c);
j = i+1;
}else{
if( inctl ){
inctl = 0;
fprintf(out, "'\n||'");
sqlite3_fprintf(out, "'\n||'");
}
if( c=='\'' ){
fprintf(out, "%.*s'", i-j+1, &zArg[j]);
sqlite3_fprintf(out, "%.*s'", i-j+1, &zArg[j]);
j = i+1;
}
}
}
fprintf(out, "%s'", &zArg[j]);
sqlite3_fprintf(out, "%s'", &zArg[j]);
}
break;
}
case SQLITE_NULL: {
fprintf(out, "NULL");
sqlite3_fprintf(out, "NULL");
break;
}
}
@ -428,7 +416,7 @@ static void dump_table(const char *zTab, FILE *out){
pStmt = db_prepare("SELECT sql FROM aux.sqlite_schema WHERE name=%Q", zTab);
if( SQLITE_ROW==sqlite3_step(pStmt) ){
fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0));
sqlite3_fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0));
}
sqlite3_finalize(pStmt);
if( !g.bSchemaOnly ){
@ -463,14 +451,14 @@ static void dump_table(const char *zTab, FILE *out){
}
nCol = sqlite3_column_count(pStmt);
while( SQLITE_ROW==sqlite3_step(pStmt) ){
Wfprintf(out, "%s",sqlite3_str_value(pIns));
sqlite3_fprintf(out, "%s",sqlite3_str_value(pIns));
zSep = "(";
for(i=0; i<nCol; i++){
Wfprintf(out, "%s",zSep);
sqlite3_fprintf(out, "%s",zSep);
printQuoted(out, sqlite3_column_value(pStmt,i));
zSep = ",";
}
Wfprintf(out, ");\n");
sqlite3_fprintf(out, ");\n");
}
sqlite3_finalize(pStmt);
strFree(pIns);
@ -479,7 +467,7 @@ static void dump_table(const char *zTab, FILE *out){
" WHERE type='index' AND tbl_name=%Q AND sql IS NOT NULL",
zTab);
while( SQLITE_ROW==sqlite3_step(pStmt) ){
Wfprintf(out, "%s;\n", sqlite3_column_text(pStmt,0));
sqlite3_fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0));
}
sqlite3_finalize(pStmt);
sqlite3_free(zId);
@ -514,14 +502,14 @@ static void diff_one_table(const char *zTab, FILE *out){
*/
az = columnNames("aux",zTab, &nPk, 0);
if( az==0 ){
Wfprintf(stdout, "Rowid not accessible for %s\n", zId);
sqlite3_fprintf(stdout, "Rowid not accessible for %s\n", zId);
}else{
Wfprintf(stdout, "%s:", zId);
sqlite3_fprintf(stdout, "%s:", zId);
for(i=0; az[i]; i++){
Wfprintf(stdout, " %s", az[i]);
if( i+1==nPk ) Wfprintf(stdout, " *");
sqlite3_fprintf(stdout, " %s", az[i]);
if( i+1==nPk ) sqlite3_fprintf(stdout, " *");
}
Wfprintf(stdout, "\n");
sqlite3_fprintf(stdout, "\n");
}
goto end_diff_one_table;
}
@ -530,9 +518,9 @@ static void diff_one_table(const char *zTab, FILE *out){
if( !sqlite3_table_column_metadata(g.db,"main",zTab,0,0,0,0,0,0) ){
/* Table missing from second database. */
if( g.bSchemaCompare )
Wfprintf(out, "-- 2nd DB has no %s table\n", zTab);
sqlite3_fprintf(out, "-- 2nd DB has no %s table\n", zTab);
else
Wfprintf(out, "DROP TABLE %s;\n", zId);
sqlite3_fprintf(out, "DROP TABLE %s;\n", zId);
}
goto end_diff_one_table;
}
@ -540,7 +528,7 @@ static void diff_one_table(const char *zTab, FILE *out){
if( sqlite3_table_column_metadata(g.db,"main",zTab,0,0,0,0,0,0) ){
/* Table missing from source */
if( g.bSchemaCompare ){
Wfprintf(out, "-- 1st DB has no %s table\n", zTab);
sqlite3_fprintf(out, "-- 1st DB has no %s table\n", zTab);
}else{
dump_table(zTab, out);
}
@ -560,7 +548,7 @@ static void diff_one_table(const char *zTab, FILE *out){
|| az[n]
){
/* Schema mismatch */
Wfprintf(out, "%sDROP TABLE %s; -- due to schema mismatch\n", zLead, zId);
sqlite3_fprintf(out, "%sDROP TABLE %s; -- due to schema mismatch\n", zLead, zId);
dump_table(zTab, out);
goto end_diff_one_table;
}
@ -568,7 +556,7 @@ static void diff_one_table(const char *zTab, FILE *out){
/* Build the comparison query */
for(n2=n; az2[n2]; n2++){
char *zNTab = safeId(az2[n2]);
Wfprintf(out, "ALTER TABLE %s ADD COLUMN %s;\n", zId, zNTab);
sqlite3_fprintf(out, "ALTER TABLE %s ADD COLUMN %s;\n", zId, zNTab);
sqlite3_free(zNTab);
}
nQ = nPk2+1+2*(n2-nPk2);
@ -669,7 +657,7 @@ static void diff_one_table(const char *zTab, FILE *out){
zTab, zTab);
while( SQLITE_ROW==sqlite3_step(pStmt) ){
char *z = safeId((const char*)sqlite3_column_text(pStmt,0));
fprintf(out, "DROP INDEX %s;\n", z);
sqlite3_fprintf(out, "DROP INDEX %s;\n", z);
sqlite3_free(z);
}
sqlite3_finalize(pStmt);
@ -681,39 +669,39 @@ static void diff_one_table(const char *zTab, FILE *out){
int iType = sqlite3_column_int(pStmt, nPk);
if( iType==1 || iType==2 ){
if( iType==1 ){ /* Change the content of a row */
fprintf(out, "%sUPDATE %s", zLead, zId);
sqlite3_fprintf(out, "%sUPDATE %s", zLead, zId);
zSep = " SET";
for(i=nPk+1; i<nQ; i+=2){
if( sqlite3_column_int(pStmt,i)==0 ) continue;
fprintf(out, "%s %s=", zSep, az2[(i+nPk-1)/2]);
sqlite3_fprintf(out, "%s %s=", zSep, az2[(i+nPk-1)/2]);
zSep = ",";
printQuoted(out, sqlite3_column_value(pStmt,i+1));
}
}else{ /* Delete a row */
fprintf(out, "%sDELETE FROM %s", zLead, zId);
sqlite3_fprintf(out, "%sDELETE FROM %s", zLead, zId);
}
zSep = " WHERE";
for(i=0; i<nPk; i++){
fprintf(out, "%s %s=", zSep, az2[i]);
sqlite3_fprintf(out, "%s %s=", zSep, az2[i]);
printQuoted(out, sqlite3_column_value(pStmt,i));
zSep = " AND";
}
fprintf(out, ";\n");
sqlite3_fprintf(out, ";\n");
}else{ /* Insert a row */
fprintf(out, "%sINSERT INTO %s(%s", zLead, zId, az2[0]);
for(i=1; az2[i]; i++) fprintf(out, ",%s", az2[i]);
fprintf(out, ") VALUES");
sqlite3_fprintf(out, "%sINSERT INTO %s(%s", zLead, zId, az2[0]);
for(i=1; az2[i]; i++) sqlite3_fprintf(out, ",%s", az2[i]);
sqlite3_fprintf(out, ") VALUES");
zSep = "(";
for(i=0; i<nPk2; i++){
fprintf(out, "%s", zSep);
sqlite3_fprintf(out, "%s", zSep);
zSep = ",";
printQuoted(out, sqlite3_column_value(pStmt,i));
}
for(i=nPk2+2; i<nQ; i+=2){
fprintf(out, ",");
sqlite3_fprintf(out, ",");
printQuoted(out, sqlite3_column_value(pStmt,i));
}
fprintf(out, ");\n");
sqlite3_fprintf(out, ");\n");
}
}
sqlite3_finalize(pStmt);
@ -729,7 +717,7 @@ static void diff_one_table(const char *zTab, FILE *out){
" AND sql IS NOT NULL)",
zTab, zTab);
while( SQLITE_ROW==sqlite3_step(pStmt) ){
fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0));
sqlite3_fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0));
}
sqlite3_finalize(pStmt);
@ -1283,17 +1271,17 @@ static void rbudiff_one_table(const char *zTab, FILE *out){
** statement first. And reset pCt so that it will not be
** printed again. */
if( sqlite3_str_length(pCt) ){
fprintf(out, "%s\n", sqlite3_str_value(pCt));
sqlite3_fprintf(out, "%s\n", sqlite3_str_value(pCt));
sqlite3_str_reset(pCt);
}
/* Output the first part of the INSERT statement */
fprintf(out, "%s", sqlite3_str_value(pInsert));
sqlite3_fprintf(out, "%s", sqlite3_str_value(pInsert));
nRow++;
if( sqlite3_column_type(pStmt, nCol)==SQLITE_INTEGER ){
for(i=0; i<=nCol; i++){
if( i>0 ) fprintf(out, ", ");
if( i>0 ) sqlite3_fprintf(out, ", ");
printQuoted(out, sqlite3_column_value(pStmt, i));
}
}else{
@ -1320,9 +1308,9 @@ static void rbudiff_one_table(const char *zTab, FILE *out){
nDelta = rbuDeltaCreate(aSrc, nSrc, aFinal, nFinal, aDelta);
if( nDelta<nFinal ){
int j;
fprintf(out, "x'");
for(j=0; j<nDelta; j++) fprintf(out, "%02x", (u8)aDelta[j]);
fprintf(out, "'");
sqlite3_fprintf(out, "x'");
for(j=0; j<nDelta; j++) sqlite3_fprintf(out, "%02x", (u8)aDelta[j]);
sqlite3_fprintf(out, "'");
zOtaControl[i-bOtaRowid] = 'f';
bDone = 1;
}
@ -1332,14 +1320,14 @@ static void rbudiff_one_table(const char *zTab, FILE *out){
if( bDone==0 ){
printQuoted(out, sqlite3_column_value(pStmt, i));
}
fprintf(out, ", ");
sqlite3_fprintf(out, ", ");
}
fprintf(out, "'%s'", zOtaControl);
sqlite3_fprintf(out, "'%s'", zOtaControl);
sqlite3_free(zOtaControl);
}
/* And the closing bracket of the insert statement */
fprintf(out, ");\n");
sqlite3_fprintf(out, ");\n");
}
sqlite3_finalize(pStmt);
@ -1347,7 +1335,7 @@ static void rbudiff_one_table(const char *zTab, FILE *out){
sqlite3_str *pCnt = sqlite3_str_new(0);
sqlite3_str_appendf(pCnt,
"INSERT INTO rbu_count VALUES('data_%q', %d);", zTab, nRow);
fprintf(out, "%s\n", sqlite3_str_value(pCnt));
sqlite3_fprintf(out, "%s\n", sqlite3_str_value(pCnt));
strFree(pCnt);
}
@ -1386,14 +1374,14 @@ static void summarize_one_table(const char *zTab, FILE *out){
if( sqlite3_table_column_metadata(g.db,"aux",zTab,0,0,0,0,0,0) ){
if( !sqlite3_table_column_metadata(g.db,"main",zTab,0,0,0,0,0,0) ){
/* Table missing from second database. */
Wfprintf(out, "%s: missing from second database\n", zTab);
sqlite3_fprintf(out, "%s: missing from second database\n", zTab);
}
goto end_summarize_one_table;
}
if( sqlite3_table_column_metadata(g.db,"main",zTab,0,0,0,0,0,0) ){
/* Table missing from source */
Wfprintf(out, "%s: missing from first database\n", zTab);
sqlite3_fprintf(out, "%s: missing from first database\n", zTab);
goto end_summarize_one_table;
}
@ -1410,7 +1398,7 @@ static void summarize_one_table(const char *zTab, FILE *out){
|| az[n]
){
/* Schema mismatch */
Wfprintf(out, "%s: incompatible schema\n", zTab);
sqlite3_fprintf(out, "%s: incompatible schema\n", zTab);
goto end_summarize_one_table;
}
@ -1455,7 +1443,7 @@ static void summarize_one_table(const char *zTab, FILE *out){
sqlite3_str_appendf(pSql, ")\n ORDER BY 1;\n");
if( (g.fDebug & DEBUG_DIFF_SQL)!=0 ){
Wfprintf(stdout, "SQL for %s:\n%s\n", zId, sqlite3_str_value(pSql));
sqlite3_fprintf(stdout, "SQL for %s:\n%s\n", zId, sqlite3_str_value(pSql));
goto end_summarize_one_table;
}
@ -1480,7 +1468,7 @@ static void summarize_one_table(const char *zTab, FILE *out){
}
}
sqlite3_finalize(pStmt);
Wfprintf(out,
sqlite3_fprintf(out,
"%s: %lld changes, %lld inserts, %lld deletes, %lld unchanged\n",
zTab, nUpdate, nInsert, nDelete, nUnchanged);
@ -1661,7 +1649,7 @@ static void changeset_one_table(const char *zTab, FILE *out){
sqlite3_str_appendf(pSql, ";\n");
if( g.fDebug & DEBUG_DIFF_SQL ){
Wfprintf(stdout, "SQL for %s:\n%s\n", zId, sqlite3_str_value(pSql));
sqlite3_fprintf(stdout, "SQL for %s:\n%s\n", zId, sqlite3_str_value(pSql));
goto end_changeset_one_table;
}
@ -1891,8 +1879,8 @@ const char *all_tables_sql(){
** Print sketchy documentation for this utility program
*/
static void showHelp(void){
Wfprintf(stdout, "Usage: %s [options] DB1 DB2\n", g.zArgv0);
Wfprintf(stdout,
sqlite3_fprintf(stdout, "Usage: %s [options] DB1 DB2\n", g.zArgv0);
sqlite3_fprintf(stdout,
"Output SQL text that would transform DB1 into DB2.\n"
"Options:\n"
" --changeset FILE Write a CHANGESET into FILE\n"
@ -1935,7 +1923,7 @@ int main(int argc, char **argv){
if( z[0]=='-' ) z++;
if( strcmp(z,"changeset")==0 ){
if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]);
out = fopen(argv[++i], "wb");
out = sqlite3_fopen(argv[++i], "wb");
if( out==0 ) cmdlineError("cannot open: %s", argv[i]);
xDiff = changeset_one_table;
neverUseTransaction = 1;
@ -2036,9 +2024,9 @@ int main(int argc, char **argv){
}
if( neverUseTransaction ) useTransaction = 0;
if( useTransaction ) Wfprintf(out, "BEGIN TRANSACTION;\n");
if( useTransaction ) sqlite3_fprintf(out, "BEGIN TRANSACTION;\n");
if( xDiff==rbudiff_one_table ){
Wfprintf(out, "CREATE TABLE IF NOT EXISTS rbu_count"
sqlite3_fprintf(out, "CREATE TABLE IF NOT EXISTS rbu_count"
"(tbl TEXT PRIMARY KEY COLLATE NOCASE, cnt INTEGER) "
"WITHOUT ROWID;\n"
);
@ -2053,7 +2041,7 @@ int main(int argc, char **argv){
}
sqlite3_finalize(pStmt);
}
if( useTransaction ) Wfprintf(stdout,"COMMIT;\n");
if( useTransaction ) sqlite3_fprintf(stdout,"COMMIT;\n");
/* TBD: Handle trigger differences */
/* TBD: Handle view differences */