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.
16 #include "tclsqlite.h"
20 /* These functions are implemented in main.c. */
21 extern const char *sqlite3ErrName(int);
23 /* These functions are implemented in test1.c. */
24 extern int getDbPointer(Tcl_Interp
*, const char *, sqlite3
**);
26 static int SQLITE_TCLAPI
backupTestCmd(
27 ClientData clientData
,
32 enum BackupSubCommandEnum
{
33 BACKUP_STEP
, BACKUP_FINISH
, BACKUP_REMAINING
, BACKUP_PAGECOUNT
35 struct BackupSubCommand
{
37 enum BackupSubCommandEnum eCmd
;
41 {"step", BACKUP_STEP
, 1, "npage" },
42 {"finish", BACKUP_FINISH
, 0, "" },
43 {"remaining", BACKUP_REMAINING
, 0, "" },
44 {"pagecount", BACKUP_PAGECOUNT
, 0, "" },
48 sqlite3_backup
*p
= (sqlite3_backup
*)clientData
;
52 rc
= Tcl_GetIndexFromObjStruct(
53 interp
, objv
[1], aSub
, sizeof(aSub
[0]), "option", 0, &iCmd
58 if( objc
!=(2 + aSub
[iCmd
].nArg
) ){
59 Tcl_WrongNumArgs(interp
, 2, objv
, aSub
[iCmd
].zArg
);
63 switch( aSub
[iCmd
].eCmd
){
68 zCmdName
= Tcl_GetString(objv
[0]);
69 Tcl_GetCommandInfo(interp
, zCmdName
, &cmdInfo
);
70 cmdInfo
.deleteProc
= 0;
71 Tcl_SetCommandInfo(interp
, zCmdName
, &cmdInfo
);
72 Tcl_DeleteCommand(interp
, zCmdName
);
74 rc
= sqlite3_backup_finish(p
);
75 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
81 if( TCL_OK
!=Tcl_GetIntFromObj(interp
, objv
[2], &nPage
) ){
84 rc
= sqlite3_backup_step(p
, nPage
);
85 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
89 case BACKUP_REMAINING
:
90 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_backup_remaining(p
)));
93 case BACKUP_PAGECOUNT
:
94 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_backup_pagecount(p
)));
101 static void SQLITE_TCLAPI
backupTestFinish(ClientData clientData
){
102 sqlite3_backup
*pBackup
= (sqlite3_backup
*)clientData
;
103 sqlite3_backup_finish(pBackup
);
107 ** sqlite3_backup CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME
110 static int SQLITE_TCLAPI
backupTestInit(
111 ClientData clientData
,
116 sqlite3_backup
*pBackup
;
119 const char *zDestName
;
120 const char *zSrcName
;
125 interp
, 1, objv
, "CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME"
130 zCmd
= Tcl_GetString(objv
[1]);
131 getDbPointer(interp
, Tcl_GetString(objv
[2]), &pDestDb
);
132 zDestName
= Tcl_GetString(objv
[3]);
133 getDbPointer(interp
, Tcl_GetString(objv
[4]), &pSrcDb
);
134 zSrcName
= Tcl_GetString(objv
[5]);
136 pBackup
= sqlite3_backup_init(pDestDb
, zDestName
, pSrcDb
, zSrcName
);
138 Tcl_AppendResult(interp
, "sqlite3_backup_init() failed", 0);
142 Tcl_CreateObjCommand(interp
, zCmd
, backupTestCmd
, pBackup
, backupTestFinish
);
143 Tcl_SetObjResult(interp
, objv
[1]);
147 int Sqlitetestbackup_Init(Tcl_Interp
*interp
){
148 Tcl_CreateObjCommand(interp
, "sqlite3_backup", backupTestInit
, 0, 0);