/ Check-in [8882d1f3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the --transaction option to the sqldiff tool.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8882d1f3ef0fc53d7c19918c3af43c5bdd79e88f
User & Date: drh 2015-11-13 13:15:42
Context
2015-11-13
16:59
Add the "--enable-static-shell" option to the amalgamation autoconf script. If set (the default) the compiled shell tool is statically linked against sqlite3.o. Otherwise, it is linked against libsqlite3.so. check-in: 499a02a3 user: dan tags: trunk
13:15
Add the --transaction option to the sqldiff tool. check-in: 8882d1f3 user: drh tags: trunk
12:52
Fix the releasetest-out.txt log output from releasetest.tcl so that it works when the --jobs option is used. check-in: 6bb314a5 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/sqldiff.c.

  1737   1737   "  --changeset FILE      Write a CHANGESET into FILE\n"
  1738   1738   "  -L|--lib LIBRARY      Load an SQLite extension library\n"
  1739   1739   "  --primarykey          Use schema-defined PRIMARY KEYs\n"
  1740   1740   "  --rbu                 Output SQL to create/populate RBU table(s)\n"
  1741   1741   "  --schema              Show only differences in the schema\n"
  1742   1742   "  --summary             Show only a summary of the differences\n"
  1743   1743   "  --table TAB           Show only differences in table TAB\n"
         1744  +"  --transaction         Show SQL output inside a transaction\n"
  1744   1745     );
  1745   1746   }
  1746   1747   
  1747   1748   int main(int argc, char **argv){
  1748   1749     const char *zDb1 = 0;
  1749   1750     const char *zDb2 = 0;
  1750   1751     int i;
................................................................................
  1753   1754     char *zSql;
  1754   1755     sqlite3_stmt *pStmt;
  1755   1756     char *zTab = 0;
  1756   1757     FILE *out = stdout;
  1757   1758     void (*xDiff)(const char*,FILE*) = diff_one_table;
  1758   1759     int nExt = 0;
  1759   1760     char **azExt = 0;
         1761  +  int useTransaction = 0;
         1762  +  int neverUseTransaction = 0;
  1760   1763   
  1761   1764     g.zArgv0 = argv[0];
  1762   1765     sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
  1763   1766     for(i=1; i<argc; i++){
  1764   1767       const char *z = argv[i];
  1765   1768       if( z[0]=='-' ){
  1766   1769         z++;
  1767   1770         if( z[0]=='-' ) z++;
  1768   1771         if( strcmp(z,"changeset")==0 ){
  1769   1772           if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]);
  1770   1773           out = fopen(argv[++i], "wb");
  1771   1774           if( out==0 ) cmdlineError("cannot open: %s", argv[i]);
  1772   1775           xDiff = changeset_one_table;
         1776  +        neverUseTransaction = 1;
  1773   1777         }else
  1774   1778         if( strcmp(z,"debug")==0 ){
  1775   1779           if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]);
  1776   1780           g.fDebug = strtol(argv[++i], 0, 0);
  1777   1781         }else
  1778   1782         if( strcmp(z,"help")==0 ){
  1779   1783           showHelp();
................................................................................
  1798   1802         }else
  1799   1803         if( strcmp(z,"summary")==0 ){
  1800   1804           xDiff = summarize_one_table;
  1801   1805         }else
  1802   1806         if( strcmp(z,"table")==0 ){
  1803   1807           if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]);
  1804   1808           zTab = argv[++i];
         1809  +      }else
         1810  +      if( strcmp(z,"transaction")==0 ){
         1811  +        useTransaction = 1;
  1805   1812         }else
  1806   1813         {
  1807   1814           cmdlineError("unknown option: %s", argv[i]);
  1808   1815         }
  1809   1816       }else if( zDb1==0 ){
  1810   1817         zDb1 = argv[i];
  1811   1818       }else if( zDb2==0 ){
................................................................................
  1841   1848       cmdlineError("cannot attach database \"%s\"", zDb2);
  1842   1849     }
  1843   1850     rc = sqlite3_exec(g.db, "SELECT * FROM aux.sqlite_master", 0, 0, &zErrMsg);
  1844   1851     if( rc || zErrMsg ){
  1845   1852       cmdlineError("\"%s\" does not appear to be a valid SQLite database", zDb2);
  1846   1853     }
  1847   1854   
         1855  +  if( neverUseTransaction ) useTransaction = 0;
         1856  +  if( useTransaction ) printf("BEGIN TRANSACTION;\n");
  1848   1857     if( zTab ){
  1849   1858       xDiff(zTab, out);
  1850   1859     }else{
  1851   1860       /* Handle tables one by one */
  1852   1861       pStmt = db_prepare(
  1853   1862         "SELECT name FROM main.sqlite_master\n"
  1854   1863         " WHERE type='table' AND sql NOT LIKE 'CREATE VIRTUAL%%'\n"
................................................................................
  1858   1867         " ORDER BY name"
  1859   1868       );
  1860   1869       while( SQLITE_ROW==sqlite3_step(pStmt) ){
  1861   1870         xDiff((const char*)sqlite3_column_text(pStmt,0), out);
  1862   1871       }
  1863   1872       sqlite3_finalize(pStmt);
  1864   1873     }
         1874  +  if( useTransaction ) printf("COMMIT;\n");
  1865   1875   
  1866   1876     /* TBD: Handle trigger differences */
  1867   1877     /* TBD: Handle view differences */
  1868   1878     sqlite3_close(g.db);
  1869   1879     return 0;
  1870   1880   }