wasCSharpSQLite – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System.Diagnostics; |
2 | |||
3 | using sqlite_int64 = System.Int64; |
||
4 | using sqlite3_int64 = System.Int64; |
||
5 | |||
6 | namespace Community.CsharpSqlite |
||
7 | { |
||
8 | #if TCLSH |
||
9 | using tcl.lang; |
||
10 | using sqlite3_stmt = Community.CsharpSqlite.Sqlite3.Vdbe; |
||
11 | using Tcl_Interp = tcl.lang.Interp; |
||
12 | using Tcl_Obj = tcl.lang.TclObject; |
||
13 | using System.Text; |
||
14 | using System; |
||
15 | |||
16 | public partial class Sqlite3 |
||
17 | { |
||
18 | /* |
||
19 | ** 2011 March 16 |
||
20 | ** |
||
21 | ** The author disclaims copyright to this source code. In place of |
||
22 | ** a legal notice, here is a blessing: |
||
23 | ** |
||
24 | ** May you do good and not evil. |
||
25 | ** May you find forgiveness for yourself and forgive others. |
||
26 | ** May you share freely, never taking more than you give. |
||
27 | ** |
||
28 | ****************************************************************************** |
||
29 | ** |
||
30 | ** This file contains code implements a VFS shim that writes diagnostic |
||
31 | ** output for each VFS call, similar to "strace". |
||
32 | ** |
||
33 | ** USAGE: |
||
34 | ** |
||
35 | ** This source file exports a single symbol which is the name of a |
||
36 | ** function: |
||
37 | ** |
||
38 | ** int vfstrace_register( |
||
39 | ** string zTraceName, // Name of the newly constructed VFS |
||
40 | ** string zOldVfsName, // Name of the underlying VFS |
||
41 | ** int (*xOut)(const char*,void), // Output routine. ex: fputs |
||
42 | ** void pOutArg, // 2nd argument to xOut. ex: stderr |
||
43 | ** int makeDefault // Make the new VFS the default |
||
44 | ** ); |
||
45 | ** |
||
46 | ** Applications that want to trace their VFS usage must provide a callback |
||
47 | ** function with this prototype: |
||
48 | ** |
||
49 | ** int traceOutput(string zMessage, object pAppData); |
||
50 | ** |
||
51 | ** This function will "output" the trace messages, where "output" can |
||
52 | ** mean different things to different applications. The traceOutput function |
||
53 | ** for the command-line shell (see shell.c) is "fputs" from the standard |
||
54 | ** library, which means that all trace output is written on the stream |
||
55 | ** specified by the second argument. In the case of the command-line shell |
||
56 | ** the second argument is stderr. Other applications might choose to output |
||
57 | ** trace information to a file, over a socket, or write it into a buffer. |
||
58 | ** |
||
59 | ** The vfstrace_register() function creates a new "shim" VFS named by |
||
60 | ** the zTraceName parameter. A "shim" VFS is an SQLite backend that does |
||
61 | ** not really perform the duties of a true backend, but simply filters or |
||
62 | ** interprets VFS calls before passing them off to another VFS which does |
||
63 | ** the actual work. In this case the other VFS - the one that does the |
||
64 | ** real work - is identified by the second parameter, zOldVfsName. If |
||
65 | ** the the 2nd parameter is NULL then the default VFS is used. The common |
||
66 | ** case is for the 2nd parameter to be NULL. |
||
67 | ** |
||
68 | ** The third and fourth parameters are the pointer to the output function |
||
69 | ** and the second argument to the output function. For the SQLite |
||
70 | ** command-line shell, when the -vfstrace option is used, these parameters |
||
71 | ** are fputs and stderr, respectively. |
||
72 | ** |
||
73 | ** The fifth argument is true (non-zero) to cause the newly created VFS |
||
74 | ** to become the default VFS. The common case is for the fifth parameter |
||
75 | ** to be true. |
||
76 | ** |
||
77 | ** The call to vfstrace_register() simply creates the shim VFS that does |
||
78 | ** tracing. The application must also arrange to use the new VFS for |
||
79 | ** all database connections that are created and for which tracing is |
||
80 | ** desired. This can be done by specifying the trace VFS using URI filename |
||
81 | ** notation, or by specifying the trace VFS as the 4th parameter to |
||
82 | ** sqlite3_open_v2() or by making the trace VFS be the default (by setting |
||
83 | ** the 5th parameter of vfstrace_register() to 1). |
||
84 | ** |
||
85 | ** |
||
86 | ** ENABLING VFSTRACE IN A COMMAND-LINE SHELL |
||
87 | ** |
||
88 | ** The SQLite command line shell implemented by the shell.c source file |
||
89 | ** can be used with this module. To compile in -vfstrace support, first |
||
90 | ** gather this file (test_vfstrace.c), the shell source file (shell.c), |
||
91 | ** and the SQLite amalgamation source files (sqlite3.c, sqlite3.h) into |
||
92 | ** the working directory. Then compile using a command like the following: |
||
93 | ** |
||
94 | ** gcc -o sqlite3 -Os -I. -DSQLITE_ENABLE_VFSTRACE \ |
||
95 | ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE \ |
||
96 | ** -DHAVE_READLINE -DHAVE_USLEEP=1 \ |
||
97 | ** shell.c test_vfstrace.c sqlite3.c -ldl -lreadline -lncurses |
||
98 | ** |
||
99 | ** The gcc command above works on Linux and provides (in addition to the |
||
100 | ** -vfstrace option) support for FTS3 and FTS4, RTREE, and command-line |
||
101 | ** editing using the readline library. The command-line shell does not |
||
102 | ** use threads so we added -DSQLITE_THREADSAFE=0 just to make the code |
||
103 | ** run a little faster. For compiling on a Mac, you'll probably need |
||
104 | ** to omit the -DHAVE_READLINE, the -lreadline, and the -lncurses options. |
||
105 | ** The compilation could be simplified to just this: |
||
106 | ** |
||
107 | ** gcc -DSQLITE_ENABLE_VFSTRACE \ |
||
108 | ** shell.c test_vfstrace.c sqlite3.c -ldl -lpthread |
||
109 | ** |
||
110 | ** In this second example, all unnecessary options have been removed |
||
111 | ** Note that since the code is now threadsafe, we had to add the -lpthread |
||
112 | ** option to pull in the pthreads library. |
||
113 | ** |
||
114 | ** To cross-compile for windows using MinGW, a command like this might |
||
115 | ** work: |
||
116 | ** |
||
117 | ** /opt/mingw/bin/i386-mingw32msvc-gcc -o sqlite3.exe -Os -I \ |
||
118 | ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_VFSTRACE \ |
||
119 | ** shell.c test_vfstrace.c sqlite3.c |
||
120 | ** |
||
121 | ** Similar compiler commands will work on different systems. The key |
||
122 | ** invariants are (1) you must have -DSQLITE_ENABLE_VFSTRACE so that |
||
123 | ** the shell.c source file will know to include the -vfstrace command-line |
||
124 | ** option and (2) you must compile and link the three source files |
||
125 | ** shell,c, test_vfstrace.c, and sqlite3.c. |
||
126 | */ |
||
127 | //#include <stdlib.h> |
||
128 | //#include <string.h> |
||
129 | //#include "sqlite3.h" |
||
130 | |||
131 | /* |
||
132 | ** An instance of this structure is attached to the each trace VFS to |
||
133 | ** provide auxiliary information. |
||
134 | */ |
||
135 | //typedef struct vfstrace_info vfstrace_info; |
||
136 | class vfstrace_info { |
||
137 | public sqlite3_vfs pRootVfs; /* The underlying real VFS */ |
||
138 | public smdxFunctionArg xOut;//int (*xOut)(const char*, void); /* Send output here */ |
||
139 | public object pOutArg; /* First argument to xOut */ |
||
140 | public string zVfsName; /* Name of this trace-VFS */ |
||
141 | public sqlite3_vfs pTraceVfs; /* Pointer back to the trace VFS */ |
||
142 | }; |
||
143 | |||
144 | /* |
||
145 | ** The sqlite3_file object for the trace VFS |
||
146 | */ |
||
147 | //typedef struct vfstrace_file vfstrace_file; |
||
148 | class vfstrace_file : sqlite3_file |
||
149 | { |
||
150 | //public sqlite3_file base; /* Base class. Must be first */ |
||
151 | public vfstrace_info pInfo; /* The trace-VFS to which this file belongs */ |
||
152 | public string zFName; /* Base name of the file */ |
||
153 | public sqlite3_file pReal; /* The real underlying file */ |
||
154 | }; |
||
155 | |||
156 | /* |
||
157 | ** Method declarations for vfstrace_file. |
||
158 | */ |
||
159 | //static int vfstraceClose(sqlite3_file); |
||
160 | //static int vfstraceRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
||
161 | //static int vfstraceWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64); |
||
162 | //static int vfstraceTruncate(sqlite3_file*, sqlite3_int64 size); |
||
163 | //static int vfstraceSync(sqlite3_file*, int flags); |
||
164 | //static int vfstraceFileSize(sqlite3_file*, sqlite3_int64 pSize); |
||
165 | //static int vfstraceLock(sqlite3_file*, int); |
||
166 | //static int vfstraceUnlock(sqlite3_file*, int); |
||
167 | //static int vfstraceCheckReservedLock(sqlite3_file*, int ); |
||
168 | //static int vfstraceFileControl(sqlite3_file*, int op, object pArg); |
||
169 | //static int vfstraceSectorSize(sqlite3_file); |
||
170 | //static int vfstraceDeviceCharacteristics(sqlite3_file); |
||
171 | //static int vfstraceShmLock(sqlite3_file*,int,int,int); |
||
172 | //static int vfstraceShmMap(sqlite3_file*,int,int,int, object volatile *); |
||
173 | //static void vfstraceShmBarrier(sqlite3_file); |
||
174 | //static int vfstraceShmUnmap(sqlite3_file*,int); |
||
175 | |||
176 | /* |
||
177 | ** Method declarations for vfstrace_vfs. |
||
178 | */ |
||
179 | //static int vfstraceOpen(sqlite3_vfs*, string , sqlite3_file*, int , int ); |
||
180 | //static int vfstraceDelete(sqlite3_vfs*, string zName, int syncDir); |
||
181 | //static int vfstraceAccess(sqlite3_vfs*, string zName, int flags, int ); |
||
182 | //static int vfstraceFullPathname(sqlite3_vfs*, string zName, int, char ); |
||
183 | //static void vfstraceDlOpen(sqlite3_vfs*, string zFilename); |
||
184 | //static void vfstraceDlError(sqlite3_vfs*, int nByte, string zErrMsg); |
||
185 | //static void (*vfstraceDlSym(sqlite3_vfs*,void*, string zSymbol))(void); |
||
186 | //static void vfstraceDlClose(sqlite3_vfs*, void); |
||
187 | //static int vfstraceRandomness(sqlite3_vfs*, int nByte, string zOut); |
||
188 | //static int vfstraceSleep(sqlite3_vfs*, int microseconds); |
||
189 | //static int vfstraceCurrentTime(sqlite3_vfs*, double); |
||
190 | //static int vfstraceGetLastError(sqlite3_vfs*, int, char); |
||
191 | //static int vfstraceCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64); |
||
192 | //static int vfstraceSetSystemCall(sqlite3_vfs*,const char*, sqlite3_syscall_ptr); |
||
193 | //static sqlite3_syscall_ptr vfstraceGetSystemCall(sqlite3_vfs*, string ); |
||
194 | //static string vfstraceNextSystemCall(sqlite3_vfs*, string zName); |
||
195 | |||
196 | /* |
||
197 | ** Return a pointer to the tail of the pathname. Examples: |
||
198 | ** |
||
199 | ** /home/drh/xyzzy.txt . xyzzy.txt |
||
200 | ** xyzzy.txt . xyzzy.txt |
||
201 | */ |
||
202 | static string fileTail(string z){ |
||
203 | int i; |
||
204 | if( String.IsNullOrEmpty(z) ) return ""; |
||
205 | i = z.Length - 1;// strlen( z ) - 1; |
||
206 | Debugger.Break(); |
||
207 | //while( i>0 && z[i-1]!='/' ){ i--; } |
||
208 | //return &z[i]; |
||
209 | return ""; |
||
210 | } |
||
211 | |||
212 | /* |
||
213 | ** Send trace output defined by zFormat and subsequent arguments. |
||
214 | */ |
||
215 | static void vfstrace_printf( |
||
216 | vfstrace_info pInfo, |
||
217 | string zFormat, |
||
218 | params object[]ap |
||
219 | ){ |
||
220 | //va_list ap; |
||
221 | string zMsg; |
||
222 | va_start(ap, zFormat); |
||
223 | zMsg = sqlite3_vmprintf(zFormat, ap); |
||
224 | va_end(ref ap); |
||
225 | Debugger.Break(); |
||
226 | //pInfo.xOut( zMsg, pInfo.pOutArg ); |
||
227 | //sqlite3_free(zMsg); |
||
228 | } |
||
229 | |||
230 | /* |
||
231 | ** Convert value rc into a string and print it using zFormat. zFormat |
||
232 | ** should have exactly one %s |
||
233 | */ |
||
234 | static void vfstrace_print_errcode( |
||
235 | vfstrace_info pInfo, |
||
236 | string zFormat, |
||
237 | int rc |
||
238 | ){ |
||
239 | StringBuilder zBuf = new StringBuilder(50);//char zBuf[50]; |
||
240 | string zVal; |
||
241 | switch( rc ){ |
||
242 | case SQLITE_OK: zVal = "SQLITE_OK"; break; |
||
243 | case SQLITE_ERROR: zVal = "SQLITE_ERROR"; break; |
||
244 | case SQLITE_PERM: zVal = "SQLITE_PERM"; break; |
||
245 | case SQLITE_ABORT: zVal = "SQLITE_ABORT"; break; |
||
246 | case SQLITE_BUSY: zVal = "SQLITE_BUSY"; break; |
||
247 | case SQLITE_NOMEM: zVal = "SQLITE_NOMEM"; break; |
||
248 | case SQLITE_READONLY: zVal = "SQLITE_READONLY"; break; |
||
249 | case SQLITE_INTERRUPT: zVal = "SQLITE_INTERRUPT"; break; |
||
250 | case SQLITE_IOERR: zVal = "SQLITE_IOERR"; break; |
||
251 | case SQLITE_CORRUPT: zVal = "SQLITE_CORRUPT"; break; |
||
252 | case SQLITE_FULL: zVal = "SQLITE_FULL"; break; |
||
253 | case SQLITE_CANTOPEN: zVal = "SQLITE_CANTOPEN"; break; |
||
254 | case SQLITE_PROTOCOL: zVal = "SQLITE_PROTOCOL"; break; |
||
255 | case SQLITE_EMPTY: zVal = "SQLITE_EMPTY"; break; |
||
256 | case SQLITE_SCHEMA: zVal = "SQLITE_SCHEMA"; break; |
||
257 | case SQLITE_CONSTRAINT: zVal = "SQLITE_CONSTRAINT"; break; |
||
258 | case SQLITE_MISMATCH: zVal = "SQLITE_MISMATCH"; break; |
||
259 | case SQLITE_MISUSE: zVal = "SQLITE_MISUSE"; break; |
||
260 | case SQLITE_NOLFS: zVal = "SQLITE_NOLFS"; break; |
||
261 | case SQLITE_IOERR_READ: zVal = "SQLITE_IOERR_READ"; break; |
||
262 | case SQLITE_IOERR_SHORT_READ: zVal = "SQLITE_IOERR_SHORT_READ"; break; |
||
263 | case SQLITE_IOERR_WRITE: zVal = "SQLITE_IOERR_WRITE"; break; |
||
264 | case SQLITE_IOERR_FSYNC: zVal = "SQLITE_IOERR_FSYNC"; break; |
||
265 | case SQLITE_IOERR_DIR_FSYNC: zVal = "SQLITE_IOERR_DIR_FSYNC"; break; |
||
266 | case SQLITE_IOERR_TRUNCATE: zVal = "SQLITE_IOERR_TRUNCATE"; break; |
||
267 | case SQLITE_IOERR_FSTAT: zVal = "SQLITE_IOERR_FSTAT"; break; |
||
268 | case SQLITE_IOERR_UNLOCK: zVal = "SQLITE_IOERR_UNLOCK"; break; |
||
269 | case SQLITE_IOERR_RDLOCK: zVal = "SQLITE_IOERR_RDLOCK"; break; |
||
270 | case SQLITE_IOERR_DELETE: zVal = "SQLITE_IOERR_DELETE"; break; |
||
271 | case SQLITE_IOERR_BLOCKED: zVal = "SQLITE_IOERR_BLOCKED"; break; |
||
272 | case SQLITE_IOERR_NOMEM: zVal = "SQLITE_IOERR_NOMEM"; break; |
||
273 | case SQLITE_IOERR_ACCESS: zVal = "SQLITE_IOERR_ACCESS"; break; |
||
274 | case SQLITE_IOERR_CHECKRESERVEDLOCK: |
||
275 | zVal = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break; |
||
276 | case SQLITE_IOERR_LOCK: zVal = "SQLITE_IOERR_LOCK"; break; |
||
277 | case SQLITE_IOERR_CLOSE: zVal = "SQLITE_IOERR_CLOSE"; break; |
||
278 | case SQLITE_IOERR_DIR_CLOSE: zVal = "SQLITE_IOERR_DIR_CLOSE"; break; |
||
279 | case SQLITE_IOERR_SHMOPEN: zVal = "SQLITE_IOERR_SHMOPEN"; break; |
||
280 | case SQLITE_IOERR_SHMSIZE: zVal = "SQLITE_IOERR_SHMSIZE"; break; |
||
281 | case SQLITE_IOERR_SHMLOCK: zVal = "SQLITE_IOERR_SHMLOCK"; break; |
||
282 | case SQLITE_LOCKED_SHAREDCACHE: zVal = "SQLITE_LOCKED_SHAREDCACHE"; break; |
||
283 | case SQLITE_BUSY_RECOVERY: zVal = "SQLITE_BUSY_RECOVERY"; break; |
||
284 | case SQLITE_CANTOPEN_NOTEMPDIR: zVal = "SQLITE_CANTOPEN_NOTEMPDIR"; break; |
||
285 | default: { |
||
286 | sqlite3_snprintf(zBuf.Capacity, zBuf, "%d", rc); |
||
287 | zVal = zBuf.ToString(); |
||
288 | break; |
||
289 | } |
||
290 | } |
||
291 | vfstrace_printf(pInfo, zFormat, zVal); |
||
292 | } |
||
293 | |||
294 | /* |
||
295 | ** Append to a buffer. |
||
296 | */ |
||
297 | static void strappend(string z, int pI, string zAppend){ |
||
298 | int i = pI; |
||
299 | Debugger.Break(); |
||
300 | // |
||
301 | //while( zAppend[0] ){ z[i++] = *(zAppend++); } |
||
302 | //z[i] = 0; |
||
303 | pI = i; |
||
304 | } |
||
305 | |||
306 | /* |
||
307 | ** Close an vfstrace-file. |
||
308 | */ |
||
309 | static int vfstraceClose(sqlite3_file pFile){ |
||
310 | vfstrace_file p = (vfstrace_file )pFile; |
||
311 | vfstrace_info pInfo = p.pInfo; |
||
312 | int rc; |
||
313 | vfstrace_printf(pInfo, "%s.xClose(%s)", pInfo.zVfsName, p.zFName); |
||
314 | rc = p.pReal.pMethods.xClose(p.pReal); |
||
315 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
316 | if( rc==SQLITE_OK ){ |
||
317 | //sqlite3_free(p._base.pMethods); |
||
318 | p.pMethods = null;//p.base.pMethods = 0; |
||
319 | } |
||
320 | return rc; |
||
321 | } |
||
322 | |||
323 | /* |
||
324 | ** Read data from an vfstrace-file. |
||
325 | */ |
||
326 | static int vfstraceRead( |
||
327 | sqlite3_file pFile, |
||
328 | string zBuf, |
||
329 | int iAmt, |
||
330 | sqlite_int64 iOfst |
||
331 | ){ |
||
332 | vfstrace_file p = (vfstrace_file )pFile; |
||
333 | vfstrace_info pInfo = p.pInfo; |
||
334 | int rc=0; |
||
335 | vfstrace_printf(pInfo, "%s.xRead(%s,n=%d,ofst=%lld)", |
||
336 | pInfo.zVfsName, p.zFName, iAmt, iOfst); |
||
337 | Debugger.Break(); |
||
338 | // rc = p.pReal.pMethods.xRead(p.pReal, zBuf, iAmt, iOfst); |
||
339 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
340 | return rc; |
||
341 | } |
||
342 | |||
343 | /* |
||
344 | ** Write data to an vfstrace-file. |
||
345 | */ |
||
346 | static int vfstraceWrite( |
||
347 | sqlite3_file pFile, |
||
348 | string zBuf, |
||
349 | int iAmt, |
||
350 | sqlite_int64 iOfst |
||
351 | ){ |
||
352 | vfstrace_file p = (vfstrace_file )pFile; |
||
353 | vfstrace_info pInfo = p.pInfo; |
||
354 | int rc=0; |
||
355 | vfstrace_printf(pInfo, "%s.xWrite(%s,n=%d,ofst=%lld)", |
||
356 | pInfo.zVfsName, p.zFName, iAmt, iOfst); |
||
357 | Debugger.Break();//TODO |
||
358 | //rc = p.pReal.pMethods.xWrite( p.pReal, zBuf, iAmt, iOfst ); |
||
359 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
360 | return rc; |
||
361 | } |
||
362 | |||
363 | /* |
||
364 | ** Truncate an vfstrace-file. |
||
365 | */ |
||
366 | static int vfstraceTruncate(sqlite3_file pFile, sqlite_int64 size){ |
||
367 | vfstrace_file p = (vfstrace_file )pFile; |
||
368 | vfstrace_info pInfo = p.pInfo; |
||
369 | int rc=0; |
||
370 | vfstrace_printf(pInfo, "%s.xTruncate(%s,%lld)", pInfo.zVfsName, p.zFName, |
||
371 | size); |
||
372 | rc = p.pReal.pMethods.xTruncate(p.pReal, size); |
||
373 | vfstrace_printf(pInfo, " . %d\n", rc); |
||
374 | return rc; |
||
375 | } |
||
376 | |||
377 | /* |
||
378 | ** Sync an vfstrace-file. |
||
379 | */ |
||
380 | static int vfstraceSync(sqlite3_file pFile, int flags){ |
||
381 | vfstrace_file p = (vfstrace_file )pFile; |
||
382 | vfstrace_info pInfo = p.pInfo; |
||
383 | int rc; |
||
384 | //int i; |
||
385 | StringBuilder zBuf = new StringBuilder(100);//char zBuf[100]; |
||
386 | zBuf.Append( "|0" );// memcpy( zBuf, "|0", 3 ); |
||
387 | if( (flags & SQLITE_SYNC_FULL )!=0) zBuf.Append( "|FULL"); |
||
388 | else if( (flags & SQLITE_SYNC_NORMAL )!=0) zBuf.Append( "|NORMAL"); |
||
389 | if( (flags & SQLITE_SYNC_DATAONLY ) !=0) zBuf.Append("|DATAONLY"); |
||
390 | if ( ( flags & ~( SQLITE_SYNC_FULL | SQLITE_SYNC_DATAONLY ) ) != 0 ) |
||
391 | { |
||
392 | //sqlite3_snprintf(sizeof(zBuf)-i, &zBuf[i], "|0x%x", flags); |
||
393 | Debugger.Break();//TODO |
||
394 | //zBuf.Append( sqlite3_printf( "|0x%x", flags ) ); |
||
395 | } |
||
396 | Debugger.Break();//TODO |
||
397 | // vfstrace_printf(pInfo, "%s.xSync(%s,%s)", pInfo.zVfsName, p.zFName, |
||
398 | // zBuf.ToString().StartsWith(1)); |
||
399 | rc = p.pReal.pMethods.xSync(p.pReal, flags); |
||
400 | vfstrace_printf(pInfo, " . %d\n", rc); |
||
401 | return rc; |
||
402 | } |
||
403 | |||
404 | /* |
||
405 | ** Return the current file-size of an vfstrace-file. |
||
406 | */ |
||
407 | static int vfstraceFileSize(sqlite3_file pFile, sqlite_int64 pSize){ |
||
408 | vfstrace_file p = (vfstrace_file )pFile; |
||
409 | vfstrace_info pInfo = p.pInfo; |
||
410 | int rc=0; |
||
411 | vfstrace_printf(pInfo, "%s.xFileSize(%s)", pInfo.zVfsName, p.zFName); |
||
412 | Debugger.Break();//TODO |
||
413 | //rc = p.pReal.pMethods.xFileSize(p.pReal, pSize); |
||
414 | vfstrace_print_errcode(pInfo, " . %s,", rc); |
||
415 | vfstrace_printf(pInfo, " size=%lld\n", pSize); |
||
416 | return rc; |
||
417 | } |
||
418 | |||
419 | /* |
||
420 | ** Return the name of a lock. |
||
421 | */ |
||
422 | static string lockName( int eLock ) |
||
423 | { |
||
424 | string[] azLockNames = new string[] { |
||
425 | "NONE", "SHARED", "RESERVED", "PENDING", "EXCLUSIVE" |
||
426 | }; |
||
427 | if ( eLock < 0 || eLock >= azLockNames.Length )//sizeof(azLockNames)/sizeof(azLockNames[0]) ){ |
||
428 | { |
||
429 | return "???"; |
||
430 | } |
||
431 | else |
||
432 | { |
||
433 | return azLockNames[eLock]; |
||
434 | } |
||
435 | } |
||
436 | |||
437 | /* |
||
438 | ** Lock an vfstrace-file. |
||
439 | */ |
||
440 | static int vfstraceLock(sqlite3_file pFile, int eLock){ |
||
441 | vfstrace_file p = (vfstrace_file )pFile; |
||
442 | vfstrace_info pInfo = p.pInfo; |
||
443 | int rc; |
||
444 | vfstrace_printf(pInfo, "%s.xLock(%s,%s)", pInfo.zVfsName, p.zFName, |
||
445 | lockName(eLock)); |
||
446 | rc = p.pReal.pMethods.xLock(p.pReal, eLock); |
||
447 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
448 | return rc; |
||
449 | } |
||
450 | |||
451 | /* |
||
452 | ** Unlock an vfstrace-file. |
||
453 | */ |
||
454 | static int vfstraceUnlock(sqlite3_file pFile, int eLock){ |
||
455 | vfstrace_file p = (vfstrace_file )pFile; |
||
456 | vfstrace_info pInfo = p.pInfo; |
||
457 | int rc; |
||
458 | vfstrace_printf(pInfo, "%s.xUnlock(%s,%s)", pInfo.zVfsName, p.zFName, |
||
459 | lockName(eLock)); |
||
460 | rc = p.pReal.pMethods.xUnlock(p.pReal, eLock); |
||
461 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
462 | return rc; |
||
463 | } |
||
464 | |||
465 | /* |
||
466 | ** Check if another file-handle holds a RESERVED lock on an vfstrace-file. |
||
467 | */ |
||
468 | static int vfstraceCheckReservedLock(sqlite3_file pFile, int pResOut){ |
||
469 | vfstrace_file p = (vfstrace_file )pFile; |
||
470 | vfstrace_info pInfo = p.pInfo; |
||
471 | int rc=0; |
||
472 | vfstrace_printf(pInfo, "%s.xCheckReservedLock(%s,%d)", |
||
473 | pInfo.zVfsName, p.zFName); |
||
474 | Debugger.Break();//TODO |
||
475 | //rc = p.pReal.pMethods.xCheckReservedLock(p.pReal, pResOut); |
||
476 | vfstrace_print_errcode(pInfo, " . %s", rc); |
||
477 | vfstrace_printf(pInfo, ", ref=%d\n", pResOut); |
||
478 | return rc; |
||
479 | } |
||
480 | |||
481 | /* |
||
482 | ** File control method. For custom operations on an vfstrace-file. |
||
483 | */ |
||
484 | static int vfstraceFileControl(sqlite3_file pFile, int op, object pArg){ |
||
485 | vfstrace_file p = (vfstrace_file )pFile; |
||
486 | vfstrace_info pInfo = p.pInfo; |
||
487 | int rc=0; |
||
488 | Debugger.Break(); //TODO |
||
489 | //StringBuilder zBuf = new StringBuilder(100); |
||
490 | //string zOp; |
||
491 | //switch( op ){ |
||
492 | // case SQLITE_FCNTL_LOCKSTATE: zOp = "LOCKSTATE"; break; |
||
493 | // case SQLITE_GET_LOCKPROXYFILE: zOp = "GET_LOCKPROXYFILE"; break; |
||
494 | // case SQLITE_SET_LOCKPROXYFILE: zOp = "SET_LOCKPROXYFILE"; break; |
||
495 | // case SQLITE_LAST_ERRNO: zOp = "LAST_ERRNO"; break; |
||
496 | // case SQLITE_FCNTL_SIZE_HINT: { |
||
497 | // sqlite3_snprintf(sizeof(zBuf), zBuf, "SIZE_HINT,%lld", |
||
498 | // *(sqlite3_int64)pArg); |
||
499 | // zOp = zBuf; |
||
500 | // break; |
||
501 | // } |
||
502 | // case SQLITE_FCNTL_CHUNK_SIZE: { |
||
503 | // sqlite3_snprintf(sizeof(zBuf), zBuf, "CHUNK_SIZE,%d", *(int)pArg); |
||
504 | // zOp = zBuf; |
||
505 | // break; |
||
506 | // } |
||
507 | // case SQLITE_FCNTL_FILE_POINTER: zOp = "FILE_POINTER"; break; |
||
508 | // case SQLITE_FCNTL_SYNC_OMITTED: zOp = "SYNC_OMITTED"; break; |
||
509 | // case 0xca093fa0: zOp = "DB_UNCHANGED"; break; |
||
510 | // default: { |
||
511 | // sqlite3_snprintf(zBuf.Capacity, zBuf, "%d", op); |
||
512 | // zOp = zBuf.ToString(); |
||
513 | // break; |
||
514 | // } |
||
515 | //} |
||
516 | //vfstrace_printf(pInfo, "%s.xFileControl(%s,%s)", |
||
517 | // pInfo.zVfsName, p.zFName, zOp); |
||
518 | //rc = p.pReal.pMethods.xFileControl(p.pReal, op, pArg); |
||
519 | //vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
520 | return rc; |
||
521 | } |
||
522 | |||
523 | /* |
||
524 | ** Return the sector-size in bytes for an vfstrace-file. |
||
525 | */ |
||
526 | static int vfstraceSectorSize(sqlite3_file pFile){ |
||
527 | vfstrace_file p = (vfstrace_file )pFile; |
||
528 | vfstrace_info pInfo = p.pInfo; |
||
529 | int rc; |
||
530 | vfstrace_printf(pInfo, "%s.xSectorSize(%s)", pInfo.zVfsName, p.zFName); |
||
531 | rc = p.pReal.pMethods.xSectorSize(p.pReal); |
||
532 | vfstrace_printf(pInfo, " . %d\n", rc); |
||
533 | return rc; |
||
534 | } |
||
535 | |||
536 | /* |
||
537 | ** Return the device characteristic flags supported by an vfstrace-file. |
||
538 | */ |
||
539 | static int vfstraceDeviceCharacteristics(sqlite3_file pFile){ |
||
540 | vfstrace_file p = (vfstrace_file )pFile; |
||
541 | vfstrace_info pInfo = p.pInfo; |
||
542 | int rc; |
||
543 | vfstrace_printf(pInfo, "%s.xDeviceCharacteristics(%s)", |
||
544 | pInfo.zVfsName, p.zFName); |
||
545 | rc = p.pReal.pMethods.xDeviceCharacteristics(p.pReal); |
||
546 | vfstrace_printf(pInfo, " . 0x%08x\n", rc); |
||
547 | return rc; |
||
548 | } |
||
549 | |||
550 | /* |
||
551 | ** Shared-memory operations. |
||
552 | */ |
||
553 | static int vfstraceShmLock(sqlite3_file pFile, int ofst, int n, int flags){ |
||
554 | vfstrace_file p = (vfstrace_file )pFile; |
||
555 | vfstrace_info pInfo = p.pInfo; |
||
556 | int rc; |
||
557 | StringBuilder zLck = new StringBuilder(100); |
||
558 | //int i = 0; |
||
559 | zLck.Append("|0");//memcpy( zLck, "|0", 3 ); |
||
560 | if ( ( flags & SQLITE_SHM_UNLOCK ) != 0 ) |
||
561 | zLck.Append( "|UNLOCK" );//strappend(zLck, &i, "|UNLOCK"); |
||
562 | if ( ( flags & SQLITE_SHM_LOCK ) != 0 ) |
||
563 | zLck.Append( "|LOCK" );//strappend(zLck, &i, "|LOCK"); |
||
564 | if ( ( flags & SQLITE_SHM_SHARED ) != 0 ) |
||
565 | zLck.Append( "|SHARED" );//strappend(zLck, &i, "|SHARED"); |
||
566 | if ( ( flags & SQLITE_SHM_EXCLUSIVE ) != 0 ) |
||
567 | zLck.Append( "|EXCLUSIVE" );//strappend(zLck, &i, "|EXCLUSIVE"); |
||
568 | if ( ( flags & ~( 0xf ) ) != 0 ) |
||
569 | { |
||
570 | Debugger.Break();//TODO |
||
571 | //zLck.Append( sqlite3_printf( "|0x%x", flags ) );//sqlite3_snprintf(sizeof(zLck)-i, &zLck[i], "|0x%x", flags); |
||
572 | } |
||
573 | //vfstrace_printf(pInfo, "%s.xShmLock(%s,ofst=%d,n=%d,%s)", |
||
574 | // pInfo.zVfsName, p.zFName, ofst, n, &zLck[1]); |
||
575 | rc = p.pReal.pMethods.xShmLock(p.pReal, ofst, n, flags); |
||
576 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
577 | return rc; |
||
578 | } |
||
579 | static int vfstraceShmMap( |
||
580 | sqlite3_file pFile, |
||
581 | int iRegion, |
||
582 | int szRegion, |
||
583 | int isWrite, |
||
584 | object pp |
||
585 | ){ |
||
586 | vfstrace_file p = (vfstrace_file )pFile; |
||
587 | vfstrace_info pInfo = p.pInfo; |
||
588 | int rc=0; |
||
589 | vfstrace_printf(pInfo, "%s.xShmMap(%s,iRegion=%d,szRegion=%d,isWrite=%d,)", |
||
590 | pInfo.zVfsName, p.zFName, iRegion, szRegion, isWrite); |
||
591 | Debugger.Break(); |
||
592 | //rc = p.pReal.pMethods.xShmMap( p.pReal, iRegion, szRegion, isWrite, pp ); |
||
593 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
594 | return rc; |
||
595 | } |
||
596 | static void vfstraceShmBarrier(sqlite3_file pFile){ |
||
597 | vfstrace_file p = (vfstrace_file )pFile; |
||
598 | vfstrace_info pInfo = p.pInfo; |
||
599 | vfstrace_printf(pInfo, "%s.xShmBarrier(%s)\n", pInfo.zVfsName, p.zFName); |
||
600 | p.pReal.pMethods.xShmBarrier(p.pReal); |
||
601 | } |
||
602 | static int vfstraceShmUnmap(sqlite3_file pFile, int delFlag){ |
||
603 | vfstrace_file p = (vfstrace_file )pFile; |
||
604 | vfstrace_info pInfo = p.pInfo; |
||
605 | int rc; |
||
606 | vfstrace_printf(pInfo, "%s.xShmUnmap(%s,delFlag=%d)", |
||
607 | pInfo.zVfsName, p.zFName, delFlag); |
||
608 | rc = p.pReal.pMethods.xShmUnmap(p.pReal, delFlag); |
||
609 | vfstrace_print_errcode(pInfo, " . %s\n", rc); |
||
610 | return rc; |
||
611 | } |
||
612 | |||
613 | |||
614 | |||
615 | /* |
||
616 | ** Open an vfstrace file handle. |
||
617 | */ |
||
618 | static int vfstraceOpen( |
||
619 | sqlite3_vfs pVfs, |
||
620 | string zName, |
||
621 | sqlite3_file pFile, |
||
622 | int flags, |
||
623 | int pOutFlags |
||
624 | ){ |
||
625 | int rc=0; |
||
626 | Debugger.Break(); //TODO |
||
627 | // vfstrace_file p = (vfstrace_file )pFile; |
||
628 | // vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
629 | // sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
630 | // p.pInfo = pInfo; |
||
631 | // p.zFName = zName ? fileTail(zName) : "<temp>"; |
||
632 | // p.pReal = (sqlite3_file )&p[1]; |
||
633 | // rc = pRoot.xOpen(pRoot, zName, p.pReal, flags, pOutFlags); |
||
634 | // vfstrace_printf(pInfo, "%s.xOpen(%s,flags=0x%x)", |
||
635 | // pInfo.zVfsName, p.zFName, flags); |
||
636 | // if( p.pReal.pMethods ){ |
||
637 | // sqlite3_io_methods pNew = new sqlite3_io_methods();//sqlite3_malloc( sizeof(*pNew) ); |
||
638 | // sqlite3_io_methods pSub = p.pReal.pMethods; |
||
639 | // //memset(pNew, 0, sizeof(*pNew)); |
||
640 | // pNew.iVersion = pSub.iVersion; |
||
641 | // pNew.xClose = vfstraceClose; |
||
642 | // pNew.xRead = vfstraceRead; |
||
643 | // pNew.xWrite = vfstraceWrite; |
||
644 | // pNew.xTruncate = vfstraceTruncate; |
||
645 | // pNew.xSync = vfstraceSync; |
||
646 | // pNew.xFileSize = vfstraceFileSize; |
||
647 | // pNew.xLock = vfstraceLock; |
||
648 | // pNew.xUnlock = vfstraceUnlock; |
||
649 | // pNew.xCheckReservedLock = vfstraceCheckReservedLock; |
||
650 | // pNew.xFileControl = vfstraceFileControl; |
||
651 | // pNew.xSectorSize = vfstraceSectorSize; |
||
652 | // pNew.xDeviceCharacteristics = vfstraceDeviceCharacteristics; |
||
653 | // if( pNew.iVersion>=2 ){ |
||
654 | // pNew.xShmMap = pSub.xShmMap ? vfstraceShmMap : 0; |
||
655 | // pNew.xShmLock = pSub.xShmLock ? vfstraceShmLock : 0; |
||
656 | // pNew.xShmBarrier = pSub.xShmBarrier ? vfstraceShmBarrier : 0; |
||
657 | // pNew.xShmUnmap = pSub.xShmUnmap ? vfstraceShmUnmap : 0; |
||
658 | // } |
||
659 | // pFile.pMethods = pNew; |
||
660 | // } |
||
661 | // vfstrace_print_errcode(pInfo, " . %s", rc); |
||
662 | // if( pOutFlags ){ |
||
663 | // vfstrace_printf(pInfo, ", refFlags=0x%x\n", pOutFlags); |
||
664 | // }else{ |
||
665 | // vfstrace_printf(pInfo, "\n"); |
||
666 | // } |
||
667 | return rc; |
||
668 | } |
||
669 | |||
670 | /* |
||
671 | ** Delete the file located at zPath. If the dirSync argument is true, |
||
672 | ** ensure the file-system modifications are synced to disk before |
||
673 | ** returning. |
||
674 | */ |
||
675 | static int vfstraceDelete( sqlite3_vfs pVfs, string zPath, int dirSync ) |
||
676 | { |
||
677 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
678 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
679 | int rc; |
||
680 | vfstrace_printf( pInfo, "%s.xDelete(\"%s\",%d)", |
||
681 | pInfo.zVfsName, zPath, dirSync ); |
||
682 | rc = pRoot.xDelete( pRoot, zPath, dirSync ); |
||
683 | vfstrace_print_errcode( pInfo, " . %s\n", rc ); |
||
684 | return rc; |
||
685 | } |
||
686 | |||
687 | /* |
||
688 | ** Test for access permissions. Return true if the requested permission |
||
689 | ** is available, or false otherwise. |
||
690 | */ |
||
691 | static int vfstraceAccess( |
||
692 | sqlite3_vfs pVfs, |
||
693 | string zPath, |
||
694 | int flags, |
||
695 | int pResOut |
||
696 | ){ |
||
697 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
698 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
699 | int rc; |
||
700 | vfstrace_printf(pInfo, "%s.xDelete(\"%s\",%d)", |
||
701 | pInfo.zVfsName, zPath, flags); |
||
702 | rc = pRoot.xAccess( pRoot, zPath, flags, out pResOut ); |
||
703 | vfstrace_print_errcode(pInfo, " . %s", rc); |
||
704 | vfstrace_printf(pInfo, ", ref=%d\n", pResOut); |
||
705 | return rc; |
||
706 | } |
||
707 | |||
708 | /* |
||
709 | ** Populate buffer zOut with the full canonical pathname corresponding |
||
710 | ** to the pathname in zPath. zOut is guaranteed to point to a buffer |
||
711 | ** of at least (DEVSYM_MAX_PATHNAME+1) bytes. |
||
712 | */ |
||
713 | static int vfstraceFullPathname( |
||
714 | sqlite3_vfs pVfs, |
||
715 | string zPath, |
||
716 | int nOut, |
||
717 | StringBuilder zOut |
||
718 | ){ |
||
719 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
720 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
721 | int rc; |
||
722 | vfstrace_printf(pInfo, "%s.xFullPathname(\"%s\")", |
||
723 | pInfo.zVfsName, zPath); |
||
724 | rc = pRoot.xFullPathname(pRoot, zPath, nOut, zOut); |
||
725 | vfstrace_print_errcode(pInfo, " . %s", rc); |
||
726 | vfstrace_printf(pInfo, ", ref=\"%.*s\"\n", nOut, zOut); |
||
727 | return rc; |
||
728 | } |
||
729 | |||
730 | /* |
||
731 | ** Open the dynamic library located at zPath and return a handle. |
||
732 | */ |
||
733 | static void vfstraceDlOpen(sqlite3_vfs pVfs, string zPath){ |
||
734 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
735 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
736 | vfstrace_printf(pInfo, "%s.xDlOpen(\"%s\")\n", pInfo.zVfsName, zPath); |
||
737 | Debugger.Break();//TODO |
||
738 | //return pRoot.xDlOpen(pRoot, zPath); |
||
739 | return; |
||
740 | } |
||
741 | |||
742 | /* |
||
743 | ** Populate the buffer zErrMsg (size nByte bytes) with a human readable |
||
744 | ** utf-8 string describing the most recent error encountered associated |
||
745 | ** with dynamic libraries. |
||
746 | */ |
||
747 | static void vfstraceDlError(sqlite3_vfs pVfs, int nByte, string zErrMsg){ |
||
748 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
749 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
750 | vfstrace_printf(pInfo, "%s.xDlError(%d)", pInfo.zVfsName, nByte); |
||
751 | pRoot.xDlError(pRoot, nByte, zErrMsg); |
||
752 | vfstrace_printf(pInfo, " . \"%s\"", zErrMsg); |
||
753 | } |
||
754 | |||
755 | /* |
||
756 | ** Return a pointer to the symbol zSymbol in the dynamic library pHandle. |
||
757 | */ |
||
758 | static void vfstraceDlSym(sqlite3_vfs pVfs,object p,string zSym){ |
||
759 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
760 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
761 | vfstrace_printf(pInfo, "%s.xDlSym(\"%s\")\n", pInfo.zVfsName, zSym); |
||
762 | Debugger.Break(); |
||
763 | //return pRoot.xDlSym(pRoot, p, zSym); |
||
764 | return; |
||
765 | } |
||
766 | |||
767 | /* |
||
768 | ** Close the dynamic library handle pHandle. |
||
769 | */ |
||
770 | static void vfstraceDlClose(sqlite3_vfs pVfs, object pHandle){ |
||
771 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
772 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
773 | vfstrace_printf(pInfo, "%s.xDlOpen()\n", pInfo.zVfsName); |
||
774 | Debugger.Break(); |
||
775 | // pRoot.xDlClose( pRoot, pHandle ); |
||
776 | } |
||
777 | |||
778 | /* |
||
779 | ** Populate the buffer pointed to by zBufOut with nByte bytes of |
||
780 | ** random data. |
||
781 | */ |
||
782 | static int vfstraceRandomness(sqlite3_vfs pVfs, int nByte, byte[] zBufOut){ |
||
783 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
784 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
785 | vfstrace_printf(pInfo, "%s.xRandomness(%d)\n", pInfo.zVfsName, nByte); |
||
786 | return pRoot.xRandomness( pRoot, nByte, zBufOut ); |
||
787 | } |
||
788 | |||
789 | /* |
||
790 | ** Sleep for nMicro microseconds. Return the number of microseconds |
||
791 | ** actually slept. |
||
792 | */ |
||
793 | static int vfstraceSleep(sqlite3_vfs pVfs, int nMicro){ |
||
794 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
795 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
796 | return pRoot.xSleep(pRoot, nMicro); |
||
797 | } |
||
798 | |||
799 | /* |
||
800 | ** Return the current time as a Julian Day number in pTimeOut. |
||
801 | */ |
||
802 | static int vfstraceCurrentTime(sqlite3_vfs pVfs, double pTimeOut){ |
||
803 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
804 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
805 | return pRoot.xCurrentTime(pRoot, ref pTimeOut); |
||
806 | } |
||
807 | static int vfstraceCurrentTimeInt64(sqlite3_vfs pVfs, sqlite_int64 pTimeOut){ |
||
808 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
809 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
810 | return pRoot.xCurrentTimeInt64(pRoot, ref pTimeOut); |
||
811 | } |
||
812 | |||
813 | /* |
||
814 | ** Return th3 emost recent error code and message |
||
815 | */ |
||
816 | static int vfstraceGetLastError(sqlite3_vfs pVfs, int iErr, string zErr){ |
||
817 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
818 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
819 | Debugger.Break(); |
||
820 | //return pRoot.xGetLastError(pRoot, iErr, zErr); |
||
821 | return 0; |
||
822 | } |
||
823 | |||
824 | /* |
||
825 | ** Override system calls. |
||
826 | */ |
||
827 | static int vfstraceSetSystemCall( |
||
828 | sqlite3_vfs pVfs, |
||
829 | string zName, |
||
830 | sqlite3_int64 pFunc //sqlite3_syscall_ptr pFunc |
||
831 | ){ |
||
832 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
833 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
834 | return pRoot.xSetSystemCall(pRoot, zName, pFunc); |
||
835 | } |
||
836 | static sqlite3_int64 vfstraceGetSystemCall(//sqlite3_syscall_ptr vfstraceGetSystemCall( |
||
837 | sqlite3_vfs pVfs, |
||
838 | string zName |
||
839 | ){ |
||
840 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
841 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
842 | Debugger.Break(); |
||
843 | //return pRoot.xGetSystemCall(pRoot, zName); |
||
844 | return 0; |
||
845 | } |
||
846 | static string vfstraceNextSystemCall(sqlite3_vfs pVfs, string zName){ |
||
847 | vfstrace_info pInfo = (vfstrace_info)pVfs.pAppData; |
||
848 | sqlite3_vfs pRoot = pInfo.pRootVfs; |
||
849 | Debugger.Break(); |
||
850 | //return pRoot.xNextSystemCall(pRoot, zName); |
||
851 | return ""; |
||
852 | } |
||
853 | |||
854 | |||
855 | /* |
||
856 | ** Clients invoke this routine to construct a new trace-vfs shim. |
||
857 | ** |
||
858 | ** Return SQLITE_OK on success. |
||
859 | ** |
||
860 | ** SQLITE_NOMEM is returned in the case of a memory allocation error. |
||
861 | ** SQLITE_NOTFOUND is returned if zOldVfsName does not exist. |
||
862 | */ |
||
863 | int vfstrace_register( |
||
864 | string zTraceName, /* Name of the newly constructed VFS */ |
||
865 | string zOldVfsName, /* Name of the underlying VFS */ |
||
866 | smdxFunction xOut,//int (*xOut)(const char*,void), /* Output routine. ex: fputs */ |
||
867 | object pOutArg, /* 2nd argument to xOut. ex: stderr */ |
||
868 | int makeDefault /* True to make the new VFS the default */ |
||
869 | ){ |
||
870 | sqlite3_vfs pNew; |
||
871 | sqlite3_vfs pRoot; |
||
872 | vfstrace_info pInfo; |
||
873 | int nName; |
||
874 | int nByte; |
||
875 | |||
876 | Debugger.Break();//TODO |
||
877 | //pRoot = sqlite3_vfs_find(zOldVfsName); |
||
878 | //if( pRoot==null ) return SQLITE_NOTFOUND; |
||
879 | //nName = strlen(zTraceName); |
||
880 | ////nByte = sizeof(*pNew) + sizeof(*pInfo) + nName + 1; |
||
881 | //pNew = new sqlite3_vfs();//sqlite3_malloc( nByte ); |
||
882 | ////if( pNew==0 ) return SQLITE_NOMEM; |
||
883 | ////memset(pNew, 0, nByte); |
||
884 | //pInfo = new vfstrace_info();//( vfstrace_info ) & pNew[1]; |
||
885 | //pNew.iVersion = pRoot.iVersion; |
||
886 | //pNew.szOsFile = pRoot.szOsFile + sizeof(vfstrace_file); |
||
887 | //pNew.mxPathname = pRoot.mxPathname; |
||
888 | ////pNew.zName = (char)&pInfo[1]; |
||
889 | //pNew.zName = zTraceName;//memcpy( (char)&pInfo[1], zTraceName, nName + 1 ); |
||
890 | //pNew.pAppData = pInfo; |
||
891 | //pNew.xOpen = vfstraceOpen; |
||
892 | //pNew.xDelete = vfstraceDelete; |
||
893 | //pNew.xAccess = vfstraceAccess; |
||
894 | //pNew.xFullPathname = vfstraceFullPathname; |
||
895 | //pNew.xDlOpen = pRoot.xDlOpen==null ? null : vfstraceDlOpen; |
||
896 | //pNew.xDlError = pRoot.xDlError==null ? null : vfstraceDlError; |
||
897 | //pNew.xDlSym = pRoot.xDlSym==null ? null : vfstraceDlSym; |
||
898 | //pNew.xDlClose = pRoot.xDlClose==null ? null : vfstraceDlClose; |
||
899 | //pNew.xRandomness = vfstraceRandomness; |
||
900 | //pNew.xSleep = vfstraceSleep; |
||
901 | //pNew.xCurrentTime = vfstraceCurrentTime; |
||
902 | //pNew.xGetLastError = pRoot.xGetLastError == null ? (dxGetLastError)null : vfstraceGetLastError; |
||
903 | //if( pNew.iVersion>=2 ){ |
||
904 | // pNew.xCurrentTimeInt64 = pRoot.xCurrentTimeInt64==null ? null : |
||
905 | // vfstraceCurrentTimeInt64; |
||
906 | // if( pNew.iVersion>=3 ){ |
||
907 | // pNew.xSetSystemCall = pRoot.xSetSystemCall==null ? (dxSetSystemCall)null : |
||
908 | // vfstraceSetSystemCall; |
||
909 | // pNew.xGetSystemCall = pRoot.xGetSystemCall == null ? (dxGetSystemCall)null : |
||
910 | // vfstraceGetSystemCall; |
||
911 | // pNew.xNextSystemCall = pRoot.xNextSystemCall == null ? (dxNextSystemCall)null : |
||
912 | // vfstraceNextSystemCall; |
||
913 | // } |
||
914 | //} |
||
915 | //pInfo.pRootVfs = pRoot; |
||
916 | //pInfo.xOut = xOut; |
||
917 | //pInfo.pOutArg = pOutArg; |
||
918 | //pInfo.zVfsName = pNew.zName; |
||
919 | //pInfo.pTraceVfs = pNew; |
||
920 | //vfstrace_printf(pInfo, "%s.enabled_for(\"%s\")\n", |
||
921 | // pInfo.zVfsName, pRoot.zName); |
||
922 | //return sqlite3_vfs_register(pNew, makeDefault); |
||
923 | return 0; |
||
924 | } |
||
925 | } |
||
926 | #endif |
||
927 | } |