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 #if defined(INCLUDE_SQLITE_TCL_H)
17 # include "sqlite_tcl.h"
20 # ifndef SQLITE_TCLAPI
21 # define SQLITE_TCLAPI
27 /* These functions are implemented in main.c. */
28 extern const char *sqlite3ErrName(int);
30 /* These functions are implemented in test1.c. */
31 extern int getDbPointer(Tcl_Interp
*, const char *, sqlite3
**);
33 static int SQLITE_TCLAPI
backupTestCmd(
34 ClientData clientData
,
39 enum BackupSubCommandEnum
{
40 BACKUP_STEP
, BACKUP_FINISH
, BACKUP_REMAINING
, BACKUP_PAGECOUNT
42 struct BackupSubCommand
{
44 enum BackupSubCommandEnum eCmd
;
48 {"step", BACKUP_STEP
, 1, "npage" },
49 {"finish", BACKUP_FINISH
, 0, "" },
50 {"remaining", BACKUP_REMAINING
, 0, "" },
51 {"pagecount", BACKUP_PAGECOUNT
, 0, "" },
55 sqlite3_backup
*p
= (sqlite3_backup
*)clientData
;
59 rc
= Tcl_GetIndexFromObjStruct(
60 interp
, objv
[1], aSub
, sizeof(aSub
[0]), "option", 0, &iCmd
65 if( objc
!=(2 + aSub
[iCmd
].nArg
) ){
66 Tcl_WrongNumArgs(interp
, 2, objv
, aSub
[iCmd
].zArg
);
70 switch( aSub
[iCmd
].eCmd
){
75 zCmdName
= Tcl_GetString(objv
[0]);
76 Tcl_GetCommandInfo(interp
, zCmdName
, &cmdInfo
);
77 cmdInfo
.deleteProc
= 0;
78 Tcl_SetCommandInfo(interp
, zCmdName
, &cmdInfo
);
79 Tcl_DeleteCommand(interp
, zCmdName
);
81 rc
= sqlite3_backup_finish(p
);
82 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
88 if( TCL_OK
!=Tcl_GetIntFromObj(interp
, objv
[2], &nPage
) ){
91 rc
= sqlite3_backup_step(p
, nPage
);
92 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
96 case BACKUP_REMAINING
:
97 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_backup_remaining(p
)));
100 case BACKUP_PAGECOUNT
:
101 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_backup_pagecount(p
)));
108 static void SQLITE_TCLAPI
backupTestFinish(ClientData clientData
){
109 sqlite3_backup
*pBackup
= (sqlite3_backup
*)clientData
;
110 sqlite3_backup_finish(pBackup
);
114 ** sqlite3_backup CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME
117 static int SQLITE_TCLAPI
backupTestInit(
118 ClientData clientData
,
123 sqlite3_backup
*pBackup
;
126 const char *zDestName
;
127 const char *zSrcName
;
132 interp
, 1, objv
, "CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME"
137 zCmd
= Tcl_GetString(objv
[1]);
138 getDbPointer(interp
, Tcl_GetString(objv
[2]), &pDestDb
);
139 zDestName
= Tcl_GetString(objv
[3]);
140 getDbPointer(interp
, Tcl_GetString(objv
[4]), &pSrcDb
);
141 zSrcName
= Tcl_GetString(objv
[5]);
143 pBackup
= sqlite3_backup_init(pDestDb
, zDestName
, pSrcDb
, zSrcName
);
145 Tcl_AppendResult(interp
, "sqlite3_backup_init() failed", 0);
149 Tcl_CreateObjCommand(interp
, zCmd
, backupTestCmd
, pBackup
, backupTestFinish
);
150 Tcl_SetObjResult(interp
, objv
[1]);
154 int Sqlitetestbackup_Init(Tcl_Interp
*interp
){
155 Tcl_CreateObjCommand(interp
, "sqlite3_backup", backupTestInit
, 0, 0);