OSDN Git Service

ファイル作成関数作成中
[nlite/nlite.git] / sqlite3 / sqliteMangaer.c
1 #include "sqlite3.h"
2 #include "sqliteManager.h"
3
4  INLINE int SqliteManager_open(sqlite3 **pDb,LPCWSTR fileName,int flags,const char* zVfs){
5
6         int rc;
7         char fileNameMB[_MAX_PATH];
8
9         WideToMB(CP_UTF8,fileName,fileNameMB,sizeof(fileNameMB));
10
11         rc = sqlite3_open_v2( fileNameMB,pDb, flags, zVfs);
12         
13         
14         if ( SQLITE_OK != rc )  {
15                 SqliteManager_close(pDb);
16                 goto end;
17         }
18
19         sqlite3_busy_timeout(*pDb,2000);
20
21 end:
22
23
24         return rc;
25
26 }
27
28 INLINE VOID SqliteManager_close(sqlite3 **pDb){
29
30         sqlite3_stmt *stmt = (sqlite3_stmt*)NULL, *next = (sqlite3_stmt*)NULL;
31
32         if (sqlite3_close( *pDb ) != SQLITE_OK )  { /* \83f\81[\83^\83x\81[\83X\82ð\90³\8fí\82É\83N\83\8d\81[\83Y\82Å\82«\82È\82¯\82ê\82Î\88È\89º\82ð\8eÀ\8ds */
33
34           /*** \8ec\82è\82Ì\90Ý\92è\8dÏ\82Ý\83v\83\8a\83y\83A\81[\83h\83X\83e\81[\83g\83\81\83\93\83g\82Ésqlite3_finalize\82ð\8eÀ\8ds ***/
35           stmt = sqlite3_next_stmt( *pDb, next );   /* \8dÅ\8f\89\82Ì\83v\83\8a\83y\83A\81[\83h\83X\83e\81[\83g\83\81\83\93\83g */
36           while( NULL != stmt )  {
37                 next = sqlite3_next_stmt( *pDb, stmt ); /* \8e\9f\82Ì\83v\83\8a\83y\83A\81[\83h\83X\83e\81[\83g\83\81\83\93\83g */
38                 sqlite3_finalize( stmt );                       /* \83\81\83\82\83\8a\97Ì\88æ\82ð\8aJ\95ú */
39
40                 stmt = next;
41           }
42           sqlite3_close( *pDb );  /* \83f\81[\83^\83x\81[\83X\82ð\83N\83\8d\81[\83Y */
43         }
44
45         *pDb = (sqlite3*)NULL;
46
47 }
48
49  INLINE int SqliteManager_prepare(sqlite3 *db, const void *sql, int bytes,sqlite3_stmt **stmt, const void **tail){
50
51         int rc;
52         if((rc = sqlite3_prepare16_v2( db, sql, bytes, stmt,tail)) != SQLITE_OK){
53
54                 sqlite3_finalize(*stmt);
55                 *stmt = (sqlite3_stmt*)NULL;
56
57         }
58
59
60         return rc;
61
62 }