wasCSharpSQLite – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #define SQLITE_OS_WIN |
2 | using u32 = System.UInt32; |
||
3 | |||
4 | namespace Community.CsharpSqlite |
||
5 | { |
||
6 | public partial class Sqlite3 |
||
7 | { |
||
8 | /* |
||
9 | ** 2001 September 16 |
||
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 header file (together with is companion C source-code file |
||
21 | ** "os.c") attempt to abstract the underlying operating system so that |
||
22 | ** the SQLite library will work on both POSIX and windows systems. |
||
23 | ** |
||
24 | ** This header file is #include-ed by sqliteInt.h and thus ends up |
||
25 | ** being included by every source 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 !_SQLITE_OS_H_ |
||
35 | //#define _SQLITE_OS_H_ |
||
36 | |||
37 | /* |
||
38 | ** Figure out if we are dealing with Unix, Windows, or some other |
||
39 | ** operating system. After the following block of preprocess macros, |
||
40 | ** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER |
||
41 | ** will defined to either 1 or 0. One of the four will be 1. The other |
||
42 | ** three will be 0. |
||
43 | */ |
||
44 | //#if (SQLITE_OS_OTHER) |
||
45 | //# if SQLITE_OS_OTHER==1 |
||
46 | //# undef SQLITE_OS_UNIX |
||
47 | //# define SQLITE_OS_UNIX 0 |
||
48 | //# undef SQLITE_OS_WIN |
||
49 | //# define SQLITE_OS_WIN 0 |
||
50 | //# undef SQLITE_OS_OS2 |
||
51 | //# define SQLITE_OS_OS2 0 |
||
52 | //# else |
||
53 | //# undef SQLITE_OS_OTHER |
||
54 | //# endif |
||
55 | //#endif |
||
56 | //#if !(SQLITE_OS_UNIX) && !SQLITE_OS_OTHER) |
||
57 | //# define SQLITE_OS_OTHER 0 |
||
58 | //# ifndef SQLITE_OS_WIN |
||
59 | //# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) |
||
60 | //# define SQLITE_OS_WIN 1 |
||
61 | //# define SQLITE_OS_UNIX 0 |
||
62 | //# define SQLITE_OS_OS2 0 |
||
63 | //# elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__) |
||
64 | //# define SQLITE_OS_WIN 0 |
||
65 | //# define SQLITE_OS_UNIX 0 |
||
66 | //# define SQLITE_OS_OS2 1 |
||
67 | //# else |
||
68 | //# define SQLITE_OS_WIN 0 |
||
69 | //# define SQLITE_OS_UNIX 1 |
||
70 | //# define SQLITE_OS_OS2 0 |
||
71 | //# endif |
||
72 | //# else |
||
73 | //# define SQLITE_OS_UNIX 0 |
||
74 | //# define SQLITE_OS_OS2 0 |
||
75 | //# endif |
||
76 | //#else |
||
77 | //# ifndef SQLITE_OS_WIN |
||
78 | //# define SQLITE_OS_WIN 0 |
||
79 | //# endif |
||
80 | //#endif |
||
81 | |||
82 | const bool SQLITE_OS_WIN = true; |
||
83 | const bool SQLITE_OS_UNIX = false; |
||
84 | const bool SQLITE_OS_OS2 = false; |
||
85 | |||
86 | /* |
||
87 | ** Determine if we are dealing with WindowsCE - which has a much |
||
88 | ** reduced API. |
||
89 | */ |
||
90 | //#if (_WIN32_WCE) |
||
91 | //# define SQLITE_OS_WINCE 1 |
||
92 | //#else |
||
93 | //# define SQLITE_OS_WINCE 0 |
||
94 | //#endif |
||
95 | |||
96 | /* |
||
97 | ** Define the maximum size of a temporary filename |
||
98 | */ |
||
99 | #if SQLITE_OS_WIN |
||
100 | //# include <windows.h> |
||
101 | const int MAX_PATH = 260; |
||
102 | const int SQLITE_TEMPNAME_SIZE = ( MAX_PATH + 50 ); //# define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) |
||
103 | #elif SQLITE_OS_OS2 |
||
104 | # if FALSE //(__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && OS2_HIGH_MEMORY) |
||
105 | //# include <os2safe.h> /* has to be included before os2.h for linking to work */ |
||
106 | # endif |
||
107 | //# define INCL_DOSDATETIME |
||
108 | //# define INCL_DOSFILEMGR |
||
109 | //# define INCL_DOSERRORS |
||
110 | //# define INCL_DOSMISC |
||
111 | //# define INCL_DOSPROCESS |
||
112 | //# define INCL_DOSMODULEMGR |
||
113 | //# define INCL_DOSSEMAPHORES |
||
114 | //# include <os2.h> |
||
115 | //# include <uconv.h> |
||
116 | //# define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) |
||
117 | //#else |
||
118 | //# define SQLITE_TEMPNAME_SIZE 200 |
||
119 | #endif |
||
120 | |||
121 | /* If the SET_FULLSYNC macro is not defined above, then make it |
||
122 | ** a no-op |
||
123 | */ |
||
124 | //#if !SET_FULLSYNC |
||
125 | //# define SET_FULLSYNC(x,y) |
||
126 | //#endif |
||
127 | |||
128 | /* |
||
129 | ** The default size of a disk sector |
||
130 | */ |
||
131 | #if !SQLITE_DEFAULT_SECTOR_SIZE |
||
132 | const int SQLITE_DEFAULT_SECTOR_SIZE = 4096;//# define SQLITE_DEFAULT_SECTOR_SIZE 512 |
||
133 | #endif |
||
134 | |||
135 | /* |
||
136 | ** Temporary files are named starting with this prefix followed by 16 random |
||
137 | ** alphanumeric characters, and no file extension. They are stored in the |
||
138 | ** OS's standard temporary file directory, and are deleted prior to exit. |
||
139 | ** If sqlite is being embedded in another program, you may wish to change the |
||
140 | ** prefix to reflect your program's name, so that if your program exits |
||
141 | ** prematurely, old temporary files can be easily identified. This can be done |
||
142 | ** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line. |
||
143 | ** |
||
144 | ** 2006-10-31: The default prefix used to be "sqlite_". But then |
||
145 | ** Mcafee started using SQLite in their anti-virus product and it |
||
146 | ** started putting files with the "sqlite" name in the c:/temp folder. |
||
147 | ** This annoyed many windows users. Those users would then do a |
||
148 | ** Google search for "sqlite", find the telephone numbers of the |
||
149 | ** developers and call to wake them up at night and complain. |
||
150 | ** For this reason, the default name prefix is changed to be "sqlite" |
||
151 | ** spelled backwards. So the temp files are still identified, but |
||
152 | ** anybody smart enough to figure out the code is also likely smart |
||
153 | ** enough to know that calling the developer will not help get rid |
||
154 | ** of the file. |
||
155 | */ |
||
156 | #if !SQLITE_TEMP_FILE_PREFIX |
||
157 | const string SQLITE_TEMP_FILE_PREFIX = "etilqs_"; //# define SQLITE_TEMP_FILE_PREFIX "etilqs_" |
||
158 | #endif |
||
159 | |||
160 | /* |
||
161 | ** The following values may be passed as the second argument to |
||
162 | ** sqlite3OsLock(). The various locks exhibit the following semantics: |
||
163 | ** |
||
164 | ** SHARED: Any number of processes may hold a SHARED lock simultaneously. |
||
165 | ** RESERVED: A single process may hold a RESERVED lock on a file at |
||
166 | ** any time. Other processes may hold and obtain new SHARED locks. |
||
167 | ** PENDING: A single process may hold a PENDING lock on a file at |
||
168 | ** any one time. Existing SHARED locks may persist, but no new |
||
169 | ** SHARED locks may be obtained by other processes. |
||
170 | ** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks. |
||
171 | ** |
||
172 | ** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a |
||
173 | ** process that requests an EXCLUSIVE lock may actually obtain a PENDING |
||
174 | ** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to |
||
175 | ** sqlite3OsLock(). |
||
176 | */ |
||
177 | const int NO_LOCK = 0; |
||
178 | const int SHARED_LOCK = 1; |
||
179 | const int RESERVED_LOCK = 2; |
||
180 | const int PENDING_LOCK = 3; |
||
181 | const int EXCLUSIVE_LOCK = 4; |
||
182 | |||
183 | /* |
||
184 | ** File Locking Notes: (Mostly about windows but also some info for Unix) |
||
185 | ** |
||
186 | ** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because |
||
187 | ** those functions are not available. So we use only LockFile() and |
||
188 | ** UnlockFile(). |
||
189 | ** |
||
190 | ** LockFile() prevents not just writing but also reading by other processes. |
||
191 | ** A SHARED_LOCK is obtained by locking a single randomly-chosen |
||
192 | ** byte out of a specific range of bytes. The lock byte is obtained at |
||
193 | ** random so two separate readers can probably access the file at the |
||
194 | ** same time, unless they are unlucky and choose the same lock byte. |
||
195 | ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range. |
||
196 | ** There can only be one writer. A RESERVED_LOCK is obtained by locking |
||
197 | ** a single byte of the file that is designated as the reserved lock byte. |
||
198 | ** A PENDING_LOCK is obtained by locking a designated byte different from |
||
199 | ** the RESERVED_LOCK byte. |
||
200 | ** |
||
201 | ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available, |
||
202 | ** which means we can use reader/writer locks. When reader/writer locks |
||
203 | ** are used, the lock is placed on the same range of bytes that is used |
||
204 | ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme |
||
205 | ** will support two or more Win95 readers or two or more WinNT readers. |
||
206 | ** But a single Win95 reader will lock out all WinNT readers and a single |
||
207 | ** WinNT reader will lock out all other Win95 readers. |
||
208 | ** |
||
209 | ** The following #defines specify the range of bytes used for locking. |
||
210 | ** SHARED_SIZE is the number of bytes available in the pool from which |
||
211 | ** a random byte is selected for a shared lock. The pool of bytes for |
||
212 | ** shared locks begins at SHARED_FIRST. |
||
213 | ** |
||
214 | ** The same locking strategy and |
||
215 | ** byte ranges are used for Unix. This leaves open the possiblity of having |
||
216 | ** clients on win95, winNT, and unix all talking to the same shared file |
||
217 | ** and all locking correctly. To do so would require that samba (or whatever |
||
218 | ** tool is being used for file sharing) implements locks correctly between |
||
219 | ** windows and unix. I'm guessing that isn't likely to happen, but by |
||
220 | ** using the same locking range we are at least open to the possibility. |
||
221 | ** |
||
222 | ** Locking in windows is manditory. For this reason, we cannot store |
||
223 | ** actual data in the bytes used for locking. The pager never allocates |
||
224 | ** the pages involved in locking therefore. SHARED_SIZE is selected so |
||
225 | ** that all locks will fit on a single page even at the minimum page size. |
||
226 | ** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE |
||
227 | ** is set high so that we don't have to allocate an unused page except |
||
228 | ** for very large databases. But one should test the page skipping logic |
||
229 | ** by setting PENDING_BYTE low and running the entire regression suite. |
||
230 | ** |
||
231 | ** Changing the value of PENDING_BYTE results in a subtly incompatible |
||
232 | ** file format. Depending on how it is changed, you might not notice |
||
233 | ** the incompatibility right away, even running a full regression test. |
||
234 | ** The default location of PENDING_BYTE is the first byte past the |
||
235 | ** 1GB boundary. |
||
236 | ** |
||
237 | */ |
||
238 | #if SQLITE_OMIT_WSD |
||
239 | //# define PENDING_BYTE (0x40000000) |
||
240 | static int PENDING_BYTE = 0x40000000; |
||
241 | #else |
||
242 | //# define PENDING_BYTE sqlite3PendingByte |
||
243 | static int PENDING_BYTE = 0x40000000; |
||
244 | #endif |
||
245 | |||
246 | static int RESERVED_BYTE = ( PENDING_BYTE + 1 ); |
||
247 | static int SHARED_FIRST = ( PENDING_BYTE + 2 ); |
||
248 | static int SHARED_SIZE = 510; |
||
249 | |||
250 | /* |
||
251 | ** Wrapper around OS specific sqlite3_os_init() function. |
||
252 | */ |
||
253 | //int sqlite3OsInit(void); |
||
254 | |||
255 | /* |
||
256 | ** Functions for accessing sqlite3_file methods |
||
257 | */ |
||
258 | //int sqlite3OsClose(sqlite3_file); |
||
259 | //int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset); |
||
260 | //int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset); |
||
261 | //int sqlite3OsTruncate(sqlite3_file*, i64 size); |
||
262 | //int sqlite3OsSync(sqlite3_file*, int); |
||
263 | //int sqlite3OsFileSize(sqlite3_file*, i64 pSize); |
||
264 | //int sqlite3OsLock(sqlite3_file*, int); |
||
265 | //int sqlite3OsUnlock(sqlite3_file*, int); |
||
266 | //int sqlite3OsCheckReservedLock(sqlite3_file *id, int pResOut); |
||
267 | //int sqlite3OsFileControl(sqlite3_file*,int,void); |
||
268 | //#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 |
||
269 | const u32 SQLITE_FCNTL_DB_UNCHANGED = 0xca093fa0; |
||
270 | |||
271 | //int sqlite3OsSectorSize(sqlite3_file *id); |
||
272 | //int sqlite3OsDeviceCharacteristics(sqlite3_file *id); |
||
273 | //int sqlite3OsShmMap(sqlite3_file *,int,int,int,object volatile *); |
||
274 | //int sqlite3OsShmLock(sqlite3_file *id, int, int, int); |
||
275 | //void sqlite3OsShmBarrier(sqlite3_file *id); |
||
276 | //int sqlite3OsShmUnmap(sqlite3_file *id, int); |
||
277 | |||
278 | /* |
||
279 | ** Functions for accessing sqlite3_vfs methods |
||
280 | */ |
||
281 | //int sqlite3OsOpen(sqlite3_vfs *, string , sqlite3_file*, int, int ); |
||
282 | //int sqlite3OsDelete(sqlite3_vfs *, string , int); |
||
283 | //int sqlite3OsAccess(sqlite3_vfs *, string , int, int pResOut); |
||
284 | //int sqlite3OsFullPathname(sqlite3_vfs *, string , int, char ); |
||
285 | #if !SQLITE_OMIT_LOAD_EXTENSION |
||
286 | //void *sqlite3OsDlOpen(sqlite3_vfs *, string ); |
||
287 | //void sqlite3OsDlError(sqlite3_vfs *, int, char ); |
||
288 | //void (*sqlite3OsDlSym(sqlite3_vfs *, object *, string ))(void); |
||
289 | //void sqlite3OsDlClose(sqlite3_vfs *, object ); |
||
290 | #endif |
||
291 | //int sqlite3OsRandomness(sqlite3_vfs *, int, char ); |
||
292 | //int sqlite3OsSleep(sqlite3_vfs *, int); |
||
293 | //int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64); |
||
294 | |||
295 | /* |
||
296 | ** Convenience functions for opening and closing files using |
||
297 | ** sqlite3Malloc() to obtain space for the file-handle structure. |
||
298 | */ |
||
299 | //int sqlite3OsOpenMalloc(sqlite3_vfs *, string , sqlite3_file **, int,int); |
||
300 | //int sqlite3OsCloseFree(sqlite3_file ); |
||
301 | #endif // * _SQLITE_OS_H_ */ |
||
302 | |||
303 | } |
||
304 | } |