** Try to transfer data for table zTable. If an error is seen while ** moving forward, try to go backwards. The backwards movement won't ** work for WITHOUT ROWID tables. */
| 21016 | ** work for WITHOUT ROWID tables. |
| 21017 | */ |
| 21018 | static void tryToCloneData( |
| 21019 | ShellState *p, |
| 21020 | sqlite3 *newDb, |
| 21021 | const char *zTable |
| 21022 | ){ |
| 21023 | sqlite3_stmt *pQuery = 0; |
| 21024 | sqlite3_stmt *pInsert = 0; |
| 21025 | char *zQuery = 0; |
| 21026 | char *zInsert = 0; |
| 21027 | int rc; |
| 21028 | int i, j, n; |
| 21029 | int nTable = strlen30(zTable); |
| 21030 | int k = 0; |
| 21031 | int cnt = 0; |
| 21032 | const int spinRate = 10000; |
| 21033 | |
| 21034 | zQuery = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable); |
| 21035 | shell_check_oom(zQuery); |
| 21036 | rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); |
| 21037 | if( rc ){ |
| 21038 | utf8_printf(stderr, "Error %d: %s on [%s]\n", |
| 21039 | sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), |
| 21040 | zQuery); |
| 21041 | goto end_data_xfer; |
| 21042 | } |
| 21043 | n = sqlite3_column_count(pQuery); |
| 21044 | zInsert = sqlite3_malloc64(200 + nTable + n*3); |
| 21045 | shell_check_oom(zInsert); |
| 21046 | sqlite3_snprintf(200+nTable,zInsert, |
| 21047 | "INSERT OR IGNORE INTO \"%s\" VALUES(?", zTable); |
| 21048 | i = strlen30(zInsert); |
| 21049 | for(j=1; j<n; j++){ |
| 21050 | memcpy(zInsert+i, ",?", 2); |
| 21051 | i += 2; |
| 21052 | } |
| 21053 | memcpy(zInsert+i, ");", 3); |
| 21054 | rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0); |
| 21055 | if( rc ){ |
| 21056 | utf8_printf(stderr, "Error %d: %s on [%s]\n", |
| 21057 | sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb), |
| 21058 | zQuery); |
| 21059 | goto end_data_xfer; |
| 21060 | } |
| 21061 | for(k=0; k<2; k++){ |
| 21062 | while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){ |
| 21063 | for(i=0; i<n; i++){ |
| 21064 | switch( sqlite3_column_type(pQuery, i) ){ |
| 21065 | case SQLITE_NULL: { |
| 21066 | sqlite3_bind_null(pInsert, i+1); |
| 21067 | break; |
| 21068 | } |
| 21069 | case SQLITE_INTEGER: { |
| 21070 | sqlite3_bind_int64(pInsert, i+1, sqlite3_column_int64(pQuery,i)); |
| 21071 | break; |
| 21072 | } |
| 21073 | case SQLITE_FLOAT: { |
| 21074 | sqlite3_bind_double(pInsert, i+1, sqlite3_column_double(pQuery,i)); |
| 21075 | break; |
nothing calls this directly
no test coverage detected