wasCSharpSQLite – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System.Diagnostics;
2 using va_list = System.Object;
3  
4 namespace Community.CsharpSqlite
5 {
6 public partial class Sqlite3
7 {
8 /*
9 ** 2004 May 22
10 **
11 ** The author disclaims copyright to this source code. In place of
12 ** a legal notice, here is a blessing:
13 **
14 ** May you do good and not evil.
15 ** May you find forgiveness for yourself and forgive others.
16 ** May you share freely, never taking more than you give.
17 **
18 ******************************************************************************
19 **
20 ** This file contains macros and a little bit of code that is common to
21 ** all of the platform-specific files (os_*.c) and is #included into those
22 ** files.
23 **
24 ** This file should be #included by the os_*.c files only. It is not a
25 ** general purpose header file.
26 *************************************************************************
27 ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
28 ** C#-SQLite is an independent reimplementation of the SQLite software library
29 **
30 ** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
31 **
32 *************************************************************************
33 */
34 //#if !_OS_COMMON_H_
35 //#define _OS_COMMON_H_
36 /*
37 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
38 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the
39 ** switch. The following code should catch this problem at compile-time.
40 */
41 //#if MEMORY_DEBUG
42 //# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
43 //#endif
44  
45 #if SQLITE_DEBUG || TRACE
46 static bool sqlite3OsTrace = false;
47 //#define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
48 static void OSTRACE( string X, params va_list[] ap )
49 {
50 if ( sqlite3OsTrace )
51 sqlite3DebugPrintf( X, ap );
52 }
53 #else
54 //#define OSTRACE(X)
55 static void OSTRACE( string X, params object[] ap) { }
56 #endif
57  
58 /*
59 ** Macros for performance tracing. Normally turned off. Only works
60 ** on i486 hardware.
61 */
62 #if SQLITE_PERFORMANCE_TRACE
63  
64 /*
65 ** hwtime.h contains inline assembler code for implementing
66 ** high-performance timing routines.
67 */
68 //#include "hwtime.h"
69  
70 static sqlite_u3264 g_start;
71 static sqlite_u3264 g_elapsed;
72 //#define TIMER_START g_start=sqlite3Hwtime()
73 //#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
74 //#define TIMER_ELAPSED g_elapsed
75 #else
76 const int TIMER_START = 0; //#define TIMER_START
77 const int TIMER_END = 0; //#define TIMER_END
78 const int TIMER_ELAPSED = 0; //#define TIMER_ELAPSED ((sqlite_u3264)0)
79 #endif
80  
81 /*
82 ** If we compile with the SQLITE_TEST macro set, then the following block
83 ** of code will give us the ability to simulate a disk I/O error. This
84 ** is used for testing the I/O recovery logic.
85 */
86 #if SQLITE_TEST
87  
88 #if !TCLSH
89 static int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */
90 static int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */
91 static int sqlite3_io_error_pending = 0; /* Count down to first I/O error */
92 static int sqlite3_io_error_persist = 0; /* True if I/O errors persist */
93 static int sqlite3_io_error_benign = 0; /* True if errors are benign */
94 static int sqlite3_diskfull_pending = 0;
95 static int sqlite3_diskfull = 0;
96 #else
97 static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_hit = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_hit" );
98 static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_hardhit = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_hardhit" );
99 static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_pending = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_pending" );
100 static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_persist = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_persist" );
101 static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_benign = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_benign" );
102 static tcl.lang.Var.SQLITE3_GETSET sqlite3_diskfull_pending = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_diskfull_pending" );
103 static tcl.lang.Var.SQLITE3_GETSET sqlite3_diskfull = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_diskfull" );
104 #endif
105 static void SimulateIOErrorBenign( int X )
106 {
107 #if !TCLSH
108 sqlite3_io_error_benign = ( X );
109 #else
110 sqlite3_io_error_benign.iValue = ( X );
111 #endif
112 }
113 //#define SimulateIOError(CODE) \
114 // if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
115 // || sqlite3_io_error_pending-- == 1 ) \
116 // { local_ioerr(); CODE; }
117 static bool SimulateIOError()
118 {
119 #if !TCLSH
120 if ( ( sqlite3_io_error_persist != 0 && sqlite3_io_error_hit != 0 )
121 || sqlite3_io_error_pending-- == 1 )
122 #else
123 if ( ( sqlite3_io_error_persist.iValue != 0 && sqlite3_io_error_hit.iValue != 0 )
124 || sqlite3_io_error_pending.iValue-- == 1 )
125 #endif
126 {
127 local_ioerr();
128 return true;
129 }
130 return false;
131 }
132  
133 static void local_ioerr()
134 {
135 #if TRACE
136 IOTRACE( "IOERR\n" );
137 #endif
138 #if !TCLSH
139 sqlite3_io_error_hit++;
140 if ( sqlite3_io_error_benign == 0 )
141 sqlite3_io_error_hardhit++;
142 #else
143 sqlite3_io_error_hit.iValue++;
144 if ( sqlite3_io_error_benign.iValue == 0 )
145 sqlite3_io_error_hardhit.iValue++;
146 #endif
147 }
148 //#define SimulateDiskfullError(CODE) \
149 // if( sqlite3_diskfull_pending ){ \
150 // if( sqlite3_diskfull_pending == 1 ){ \
151 // local_ioerr(); \
152 // sqlite3_diskfull = 1; \
153 // sqlite3_io_error_hit = 1; \
154 // CODE; \
155 // }else{ \
156 // sqlite3_diskfull_pending--; \
157 // } \
158 // }
159 static bool SimulateDiskfullError()
160 {
161 #if !TCLSH
162 if ( sqlite3_diskfull_pending != 0 )
163 {
164 if ( sqlite3_diskfull_pending == 1 )
165 {
166 #else
167 if ( sqlite3_diskfull_pending.iValue != 0 )
168 {
169 if ( sqlite3_diskfull_pending.iValue == 1 )
170 {
171 #endif
172 local_ioerr();
173 #if !TCLSH
174 sqlite3_diskfull = 1;
175 sqlite3_io_error_hit = 1;
176 #else
177 sqlite3_diskfull.iValue = 1;
178 sqlite3_io_error_hit.iValue = 1;
179 #endif
180 return true;
181 }
182 else
183 {
184 #if !TCLSH
185 sqlite3_diskfull_pending--;
186 #else
187 sqlite3_diskfull_pending.iValue--;
188 #endif
189 }
190 }
191 return false;
192 }
193 #else
194 static bool SimulateIOError() { return false; }
195 //#define SimulateIOErrorBenign(X)
196 static void SimulateIOErrorBenign( int x ) { }
197  
198 //#define SimulateIOError(A)
199 //#define SimulateDiskfullError(A)
200 #endif
201  
202 /*
203 ** When testing, keep a count of the number of open files.
204 */
205 #if SQLITE_TEST
206 #if !TCLSH
207 static int sqlite3_open_file_count = 0;
208 #else
209 static tcl.lang.Var.SQLITE3_GETSET sqlite3_open_file_count = new tcl.lang.Var.SQLITE3_GETSET( "sqlite3_open_file_count" );
210 #endif
211  
212 static void OpenCounter( int X )
213 {
214 #if !TCLSH
215 sqlite3_open_file_count += ( X );
216 #else
217 sqlite3_open_file_count.iValue += ( X );
218 #endif
219 }
220 #else
221 //#define OpenCounter(X)
222 #endif
223 //#endif //* !_OS_COMMON_H_) */
224 }
225 }