Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Infrastructure for an extension C-library to implement sqlite3_db_dump() and a corresponding "dbdump" command-line utility - both of which do the same work as the ".dump" command of the CLI. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | dbdump |
Files: | files | file ages | folders |
SHA3-256: |
74c5ace498f72d7f5495203678bedd0b |
User & Date: | drh 2017-03-13 19:26:34.140 |
Context
2017-03-13
| ||
21:26 | First draft of the complete dbdump.c library. (check-in: 84ea4fcc52 user: drh tags: dbdump) | |
19:26 | Infrastructure for an extension C-library to implement sqlite3_db_dump() and a corresponding "dbdump" command-line utility - both of which do the same work as the ".dump" command of the CLI. (check-in: 74c5ace498 user: drh tags: dbdump) | |
18:24 | In the output of the ".dump" command in the CLI, quote newline and carriage-return characters using the char() function, so that they do not get eaten by end-of-line processing logic in the OS or in other command-line utilities and/or libraries. (check-in: 68f6dc7af1 user: drh tags: trunk) | |
Changes
Changes to Makefile.in.
︙ | ︙ | |||
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 | echo "static const char *zMainloop = " >> $@ $(TCLSH_CMD) $(TOP)/tool/tostr.tcl $(TOP)/tool/spaceanal.tcl >> $@ echo "; return zMainloop; }" >> $@ sqlite3_analyzer$(TEXE): sqlite3_analyzer.c $(LTLINK) sqlite3_analyzer.c -o $@ $(LIBTCL) $(TLIBS) showdb$(TEXE): $(TOP)/tool/showdb.c sqlite3.lo $(LTLINK) -o $@ $(TOP)/tool/showdb.c sqlite3.lo $(TLIBS) showstat4$(TEXE): $(TOP)/tool/showstat4.c sqlite3.lo $(LTLINK) -o $@ $(TOP)/tool/showstat4.c sqlite3.lo $(TLIBS) showjournal$(TEXE): $(TOP)/tool/showjournal.c sqlite3.lo | > > > > | 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | echo "static const char *zMainloop = " >> $@ $(TCLSH_CMD) $(TOP)/tool/tostr.tcl $(TOP)/tool/spaceanal.tcl >> $@ echo "; return zMainloop; }" >> $@ sqlite3_analyzer$(TEXE): sqlite3_analyzer.c $(LTLINK) sqlite3_analyzer.c -o $@ $(LIBTCL) $(TLIBS) dbdump$(TEXE): $(TOP)/ext/misc/dbdump.c sqlite3.lo $(LTLINK) -DDBDUMP_STANDALONE -o $@ \ $(TOP)/ext/misc/dbdump.c sqlite3.lo $(TLIBS) showdb$(TEXE): $(TOP)/tool/showdb.c sqlite3.lo $(LTLINK) -o $@ $(TOP)/tool/showdb.c sqlite3.lo $(TLIBS) showstat4$(TEXE): $(TOP)/tool/showstat4.c sqlite3.lo $(LTLINK) -o $@ $(TOP)/tool/showstat4.c sqlite3.lo $(TLIBS) showjournal$(TEXE): $(TOP)/tool/showjournal.c sqlite3.lo |
︙ | ︙ |
Added ext/misc/dbdump.c.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | /* ** 2016-03-13 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** ** This file implements a C-language subroutine that converts the content ** of an SQLite database into UTF-8 text SQL statements that can be used ** to exactly recreate the original database. ** ** A prototype of the implemented subroutine is this: ** ** int sqlite3_db_dump( ** sqlite3 *db, ** const char *zSchema, ** const char *zTable, ** void (*xCallback)(void*, const char*), ** void *pArg ** ); ** ** The db parameter is the database connection. zSchema is the schema within ** that database which is to be dumped. Usually the zSchema is "main" but ** can also be "temp" or any ATTACH-ed database. If zTable is not NULL, then ** only the content of that one table is dumped. If zTable is NULL, then all ** tables are dumped. ** ** The generate text is passed to xCallback() in multiple calls. The second ** argument to xCallback() is a copy of the pArg parameter. The first ** argument is some of the output text that this routine generates. The ** signature to xCallback() is designed to make it compatible with fputs(). ** ** The sqlite3_db_dump() subroutine returns SQLITE_OK on success or some error ** code if it encounters a problem. ** ** If this file is compiled with -DDBDUMP_STANDALONE then a "main()" routine ** is included so that this routine becomes a command-line utility. The ** command-line utility takes two or three arguments which are the name ** of the database file, the schema, and optionally the table, forming the ** first three arguments of a single call to the library routine. */ #include "sqlite3.h" /* ** Convert an SQLite database into SQL statements that will recreate that ** database. */ int sqlite3_db_dump( sqlite3 *db, /* The database connection */ const char *zSchema, /* Which schema to dump. Usually "main". */ const char *zTable, /* Which table to dump. NULL means everything. */ int (*xCallback)(const char*,void*), /* Output sent to this callback */ void *pArg /* Second argument of the callback */ ){ return SQLITE_OK; } /* The generic subroutine is above. The code the follows implements ** the command-line interface. */ #ifdef DBDUMP_STANDALONE #include <stdio.h> /* ** Command-line interface */ int main(int argc, char **argv){ sqlite3 *db; const char *zDb; const char *zSchema; const char *zTable = 0; int rc; if( argc<2 || argc>4 ){ fprintf(stderr, "Usage: %s DATABASE ?SCHEMA? ?TABLE?\n", argv[0]); return 1; } zDb = argv[1]; zSchema = argc>=3 ? argv[2] : "main"; zTable = argc==4 ? argv[3] : 0; rc = sqlite3_open(zDb, &db); if( rc ){ fprintf(stderr, "Cannot open \"%s\": %s\n", zDb, sqlite3_errmsg(db)); sqlite3_close(db); return 1; } rc = sqlite3_db_dump(db, zSchema, zTable, (int(*)(const char*,void*))fputs, (void*)stdout); if( rc ){ fprintf(stderr, "Error: sqlite3_db_dump() returns %d\n", rc); } sqlite3_close(db); return rc!=SQLITE_OK; } #endif /* DBDUMP_STANDALONE */ |
Changes to main.mk.
︙ | ︙ | |||
757 758 759 760 761 762 763 764 765 766 767 768 769 770 | echo "static const char *zMainloop = " >> $@ tclsh $(TOP)/tool/tostr.tcl $(TOP)/tool/spaceanal.tcl >> $@ echo "; return zMainloop; }" >> $@ sqlite3_analyzer$(EXE): sqlite3_analyzer.c $(TCCX) $(TCL_FLAGS) sqlite3_analyzer.c -o $@ $(LIBTCL) $(THREADLIB) # Rules to build the 'testfixture' application. # TESTFIXTURE_FLAGS = -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE TESTFIXTURE_FLAGS += -DSQLITE_SERIES_CONSTRAINT_VERIFY=1 TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024 | > > > > | 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | echo "static const char *zMainloop = " >> $@ tclsh $(TOP)/tool/tostr.tcl $(TOP)/tool/spaceanal.tcl >> $@ echo "; return zMainloop; }" >> $@ sqlite3_analyzer$(EXE): sqlite3_analyzer.c $(TCCX) $(TCL_FLAGS) sqlite3_analyzer.c -o $@ $(LIBTCL) $(THREADLIB) dbdump$(EXE): $(TOP)/ext/misc/dbdump.c sqlite3.o $(TCCX) -DDBDUMP_STANDALONE -o dbdump$(EXE) \ $(TOP)/ext/misc/dbdump.c sqlite3.o $(THREADLIB) # Rules to build the 'testfixture' application. # TESTFIXTURE_FLAGS = -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE TESTFIXTURE_FLAGS += -DSQLITE_SERIES_CONSTRAINT_VERIFY=1 TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024 |
︙ | ︙ |