wasCSharpSQLite – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using ClientData = System.Object;
2  
3 namespace Community.CsharpSqlite
4 {
5 #if TCLSH
6 using tcl.lang;
7 using Tcl_Interp = tcl.lang.Interp;
8 using Tcl_Obj = tcl.lang.TclObject;
9  
10  
11 public partial class Sqlite3
12 {
13 /*
14 ** 2009 January 28
15 **
16 ** The author disclaims copyright to this source code. In place of
17 ** a legal notice, here is a blessing:
18 **
19 ** May you do good and not evil.
20 ** May you find forgiveness for yourself and forgive others.
21 ** May you share freely, never taking more than you give.
22 **
23 *************************************************************************
24 ** This file contains test logic for the sqlite3_backup() interface.
25 *************************************************************************
26 ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
27 ** C#-SQLite is an independent reimplementation of the SQLite software library
28 **
29 ** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
30 **
31 *************************************************************************
32 */
33 //#include "tcl.h"
34 //#include <sqlite3.h>
35 //#include <assert.h>
36  
37 /* These functions are implemented in test1.c. */
38 //int getDbPointer(Tcl_Interp *, string , sqlite3 *);
39 //string sqlite3TestErrorName(int);
40  
41 enum BackupSubCommandEnum
42 {
43 BACKUP_STEP,
44 BACKUP_FINISH,
45 BACKUP_REMAINING,
46 BACKUP_PAGECOUNT
47 };
48  
49 struct BackupSubCommand
50 {
51 public string zCmd;
52 public BackupSubCommandEnum eCmd;
53 public int nArg;
54 public string zArg;
55  
56 public BackupSubCommand( string zCmd, BackupSubCommandEnum eCmd, int nArg, string zArg )
57 {
58 this.zCmd = zCmd;
59 this.eCmd = eCmd;
60 this.nArg = nArg;
61 this.zArg = zArg;
62 }
63 }
64  
65 static int Tcl_GetIndexFromObjStruct( Interp interp, TclObject to, BackupSubCommand[] table, int len, string msg, int flags, out int index )
66 {
67 string zCmd = to.ToString();
68 for ( index = 0; index < len; index++ )
69 {
70 if ( zCmd == table[index].zCmd )
71 return 0;
72 }
73 return 1;
74 }
75  
76 static int backupTestCmd(
77 ClientData clientData,
78 Tcl_Interp interp,
79 int objc,
80 Tcl_Obj[] objv
81 )
82 {
83 BackupSubCommand[] aSub = new BackupSubCommand[] {
84 new BackupSubCommand("step", BackupSubCommandEnum.BACKUP_STEP , 1, "npage" ),
85 new BackupSubCommand("finish", BackupSubCommandEnum.BACKUP_FINISH , 0, "" ),
86 new BackupSubCommand("remaining", BackupSubCommandEnum.BACKUP_REMAINING , 0, "" ),
87 new BackupSubCommand("pagecount", BackupSubCommandEnum.BACKUP_PAGECOUNT , 0, "" ),
88 new BackupSubCommand(null,0,0,null)
89 };
90  
91 sqlite3_backup p = (sqlite3_backup)clientData;
92 int iCmd = 0;
93 int rc;
94  
95 rc = Tcl_GetIndexFromObjStruct(
96 interp, objv[1], aSub, aSub.Length, "option", 0, out iCmd
97 );
98 if ( rc != TCL.TCL_OK )
99 {
100 return rc;
101 }
102 if ( objc != ( 2 + aSub[iCmd].nArg ) )
103 {
104 TCL.Tcl_WrongNumArgs( interp, 2, objv, aSub[iCmd].zArg );
105 return TCL.TCL_ERROR;
106 }
107  
108 switch ( aSub[iCmd].eCmd )
109 {
110  
111 case BackupSubCommandEnum.BACKUP_FINISH:
112 {
113 string zCmdName;
114 WrappedCommand cmdInfo = null;
115 zCmdName = TCL.Tcl_GetString( objv[0] );
116 TCL.Tcl_GetCommandInfo( interp, zCmdName, out cmdInfo );
117 cmdInfo.deleteProc = null;
118 TCL.Tcl_SetCommandInfo( interp, zCmdName, cmdInfo );
119 TCL.Tcl_DeleteCommand( interp, zCmdName );
120  
121 rc = sqlite3_backup_finish( p );
122 TCL.Tcl_SetResult( interp, sqlite3TestErrorName( rc ), TCL.TCL_STATIC );
123 break;
124 }
125  
126 case BackupSubCommandEnum.BACKUP_STEP:
127 {
128 int nPage = 0;
129 if ( TCL.TCL_OK != TCL.Tcl_GetIntFromObj( interp, objv[2], out nPage ) )
130 {
131 return TCL.TCL_ERROR;
132 }
133 rc = sqlite3_backup_step( p, nPage );
134 TCL.Tcl_SetResult( interp, sqlite3TestErrorName( rc ), TCL.TCL_STATIC );
135 break;
136 }
137  
138 case BackupSubCommandEnum.BACKUP_REMAINING:
139 TCL.Tcl_SetObjResult( interp, TCL.Tcl_NewIntObj( sqlite3_backup_remaining( p ) ) );
140 break;
141  
142 case BackupSubCommandEnum.BACKUP_PAGECOUNT:
143 TCL.Tcl_SetObjResult( interp, TCL.Tcl_NewIntObj( sqlite3_backup_pagecount( p ) ) );
144 break;
145 }
146  
147 return TCL.TCL_OK;
148 }
149  
150 static void backupTestFinish( ref ClientData clientData )
151 {
152 sqlite3_backup pBackup = (sqlite3_backup)clientData;
153 sqlite3_backup_finish( pBackup );
154 }
155  
156 /*
157 ** sqlite3_backup CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME
158 **
159 */
160 static int backupTestInit(
161 ClientData clientData,
162 Tcl_Interp interp,
163 int objc,
164 Tcl_Obj[] objv
165 )
166 {
167 sqlite3_backup pBackup;
168 sqlite3 pDestDb = null;
169 sqlite3 pSrcDb = null;
170 string zDestName;
171 string zSrcName;
172 string zCmd;
173  
174 if ( objc != 6 )
175 {
176 TCL.Tcl_WrongNumArgs(
177 interp, 1, objv, "CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME"
178 );
179 return TCL.TCL_ERROR;
180 }
181  
182 zCmd = TCL.Tcl_GetString( objv[1] );
183 getDbPointer( interp, TCL.Tcl_GetString( objv[2] ), out pDestDb );
184 zDestName = TCL.Tcl_GetString( objv[3] );
185 getDbPointer( interp, TCL.Tcl_GetString( objv[4] ), out pSrcDb );
186 zSrcName = TCL.Tcl_GetString( objv[5] );
187  
188 pBackup = sqlite3_backup_init( pDestDb, zDestName, pSrcDb, zSrcName );
189 if ( null == pBackup )
190 {
191 TCL.Tcl_AppendResult( interp, "sqlite3_backup_init() failed" );
192 return TCL.TCL_ERROR;
193 }
194  
195 TCL.Tcl_CreateObjCommand( interp, zCmd, (Interp.dxObjCmdProc)backupTestCmd, pBackup, (Interp.dxCmdDeleteProc)backupTestFinish );
196 TCL.Tcl_SetObjResult( interp, objv[1] );
197 return TCL.TCL_OK;
198 }
199  
200 public static int Sqlitetestbackup_Init( Tcl_Interp interp )
201 {
202 TCL.Tcl_CreateObjCommand( interp, "sqlite3_backup", backupTestInit, 0, null );
203 return TCL.TCL_OK;
204 }
205 }
206 #endif
207 }