4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** This file contains test logic for the sqlite3_backup() interface.
20 /* These functions are implemented in test1.c. */
21 int getDbPointer(Tcl_Interp
*, const char *, sqlite3
**);
22 const char *sqlite3TestErrorName(int);
24 static int backupTestCmd(
25 ClientData clientData
,
30 enum BackupSubCommandEnum
{
31 BACKUP_STEP
, BACKUP_FINISH
, BACKUP_REMAINING
, BACKUP_PAGECOUNT
33 struct BackupSubCommand
{
35 enum BackupSubCommandEnum eCmd
;
39 {"step", BACKUP_STEP
, 1, "npage" },
40 {"finish", BACKUP_FINISH
, 0, "" },
41 {"remaining", BACKUP_REMAINING
, 0, "" },
42 {"pagecount", BACKUP_PAGECOUNT
, 0, "" },
46 sqlite3_backup
*p
= (sqlite3_backup
*)clientData
;
50 rc
= Tcl_GetIndexFromObjStruct(
51 interp
, objv
[1], aSub
, sizeof(aSub
[0]), "option", 0, &iCmd
56 if( objc
!=(2 + aSub
[iCmd
].nArg
) ){
57 Tcl_WrongNumArgs(interp
, 2, objv
, aSub
[iCmd
].zArg
);
61 switch( aSub
[iCmd
].eCmd
){
66 zCmdName
= Tcl_GetString(objv
[0]);
67 Tcl_GetCommandInfo(interp
, zCmdName
, &cmdInfo
);
68 cmdInfo
.deleteProc
= 0;
69 Tcl_SetCommandInfo(interp
, zCmdName
, &cmdInfo
);
70 Tcl_DeleteCommand(interp
, zCmdName
);
72 rc
= sqlite3_backup_finish(p
);
73 Tcl_SetResult(interp
, (char *)sqlite3TestErrorName(rc
), TCL_STATIC
);
79 if( TCL_OK
!=Tcl_GetIntFromObj(interp
, objv
[2], &nPage
) ){
82 rc
= sqlite3_backup_step(p
, nPage
);
83 Tcl_SetResult(interp
, (char *)sqlite3TestErrorName(rc
), TCL_STATIC
);
87 case BACKUP_REMAINING
:
88 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_backup_remaining(p
)));
91 case BACKUP_PAGECOUNT
:
92 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_backup_pagecount(p
)));
99 static void backupTestFinish(ClientData clientData
){
100 sqlite3_backup
*pBackup
= (sqlite3_backup
*)clientData
;
101 sqlite3_backup_finish(pBackup
);
105 ** sqlite3_backup CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME
108 static int backupTestInit(
109 ClientData clientData
,
114 sqlite3_backup
*pBackup
;
117 const char *zDestName
;
118 const char *zSrcName
;
123 interp
, 1, objv
, "CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME"
128 zCmd
= Tcl_GetString(objv
[1]);
129 getDbPointer(interp
, Tcl_GetString(objv
[2]), &pDestDb
);
130 zDestName
= Tcl_GetString(objv
[3]);
131 getDbPointer(interp
, Tcl_GetString(objv
[4]), &pSrcDb
);
132 zSrcName
= Tcl_GetString(objv
[5]);
134 pBackup
= sqlite3_backup_init(pDestDb
, zDestName
, pSrcDb
, zSrcName
);
136 Tcl_AppendResult(interp
, "sqlite3_backup_init() failed", 0);
140 Tcl_CreateObjCommand(interp
, zCmd
, backupTestCmd
, pBackup
, backupTestFinish
);
141 Tcl_SetObjResult(interp
, objv
[1]);
145 int Sqlitetestbackup_Init(Tcl_Interp
*interp
){
146 Tcl_CreateObjCommand(interp
, "sqlite3_backup", backupTestInit
, 0, 0);