1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Update the shell to use the recover extension for the .recover command.

FossilOrigin-Name: ae832e77084eddd696c80cb926d070a5db9d45dce34156a02522b3140e8f5e8b
This commit is contained in:
dan
2022-09-08 19:22:29 +00:00
parent 3887ffe82a
commit 9a27d65044
7 changed files with 54 additions and 656 deletions

View File

@ -45,7 +45,6 @@ proc do_recover_test {tn} {
uplevel [list do_test $tn.1 {
set R [sqlite3_recover_init db main test.db2]
$R config testdb rstate.db
$R config rowids 1
$R step
$R finish
} {}]
@ -68,7 +67,6 @@ proc do_recover_test {tn} {
sqlite3 db2 test.db2
execsql [join $::sqlhook ";"] db2
# puts [join $::sqlhook ";\n"]
uplevel [list do_test $tn.4 [list compare_dbs db db2] {}]
db2 close
}

View File

@ -84,6 +84,11 @@ struct sqlite3_recover {
int (*xSql)(void*,const char*);
};
/*
** Default value for SQLITE_RECOVER_ROWIDS (sqlite3_recover.bRecoverRowid).
*/
#define RECOVER_ROWID_DEFAULT 1
/*
** Like strlen(). But handles NULL pointer arguments.
*/
@ -371,7 +376,7 @@ static void recoverGetPage(
** Try to use zA and zB first. If both of those are already found in z[]
** then make up some string and store it in the buffer zBuf.
*/
static const char *unused_string(
static const char *recoverUnusedString(
const char *z, /* Result must not appear anywhere in z */
const char *zA, const char *zB, /* Try these first */
char *zBuf /* Space to store a generated string */
@ -416,11 +421,11 @@ static void recoverEscapeCrnl(
for(i=0; zText[i]; i++){
if( zNL==0 && zText[i]=='\n' ){
zNL = unused_string(zText, "\\n", "\\012", zBuf1);
zNL = recoverUnusedString(zText, "\\n", "\\012", zBuf1);
nNL = (int)strlen(zNL);
}
if( zCR==0 && zText[i]=='\r' ){
zCR = unused_string(zText, "\\r", "\\015", zBuf2);
zCR = recoverUnusedString(zText, "\\r", "\\015", zBuf2);
nCR = (int)strlen(zCR);
}
}
@ -1281,6 +1286,7 @@ sqlite3_recover *recoverInit(
memcpy(pRet->zUri, zUri, nUri);
pRet->xSql = xSql;
pRet->pSqlCtx = pSqlCtx;
pRet->bRecoverRowid = RECOVER_ROWID_DEFAULT;
}
return pRet;
@ -1330,11 +1336,11 @@ int sqlite3_recover_config(sqlite3_recover *p, int op, void *pArg){
break;
case SQLITE_RECOVER_FREELIST_CORRUPT:
p->bFreelistCorrupt = (pArg ? 1 : 0);
p->bFreelistCorrupt = *(int*)pArg;
break;
case SQLITE_RECOVER_ROWIDS:
p->bRecoverRowid = (pArg ? 1 : 0);
p->bRecoverRowid = *(int*)pArg;
break;
default:

View File

@ -16,7 +16,7 @@
#ifndef _SQLITE_RECOVER_H
#define _SQLITE_RECOVER_H
#include "sqlite3.h" /* Required for error code definitions */
#include "sqlite3.h"
#ifdef __cplusplus
extern "C" {
@ -58,9 +58,9 @@ int sqlite3_recover_config(sqlite3_recover*, int op, void *pArg);
** pages to add to the lost-and-found table.
**
** SQLITE_RECOVER_FREELIST_CORRUPT:
** The pArg value must actually be integer (type "int") value 0 or 1
** cast as a (void*). If this option is set (argument is 1) and
** a lost-and-found table has been configured using
** The pArg value must actually be a pointer to a value of type
** int containing value 0 or 1 cast as a (void*). If this option is set
** (argument is 1) and a lost-and-found table has been configured using
** SQLITE_RECOVER_LOST_AND_FOUND, then is assumed that the freelist is
** corrupt and an attempt is made to recover records from pages that
** appear to be linked into the freelist. Otherwise, pages on the freelist

View File

@ -129,7 +129,7 @@ static int testRecoverCmd(
int iVal = 0;
if( Tcl_GetBooleanFromObj(interp, objv[3], &iVal) ) return TCL_ERROR;
res = sqlite3_recover_config(pTest->p,
SQLITE_RECOVER_FREELIST_CORRUPT, SQLITE_INT_TO_PTR(iVal)
SQLITE_RECOVER_FREELIST_CORRUPT, (void*)&iVal
);
break;
}
@ -137,7 +137,7 @@ static int testRecoverCmd(
int iVal = 0;
if( Tcl_GetBooleanFromObj(interp, objv[3], &iVal) ) return TCL_ERROR;
res = sqlite3_recover_config(pTest->p,
SQLITE_RECOVER_ROWIDS, SQLITE_INT_TO_PTR(iVal)
SQLITE_RECOVER_ROWIDS, (void*)&iVal
);
break;
}