source: svn/trunk/zasc/app_c/DST_DB_Engine.c @ 45

Last change on this file since 45 was 2, checked in by jglee, 11 years ago

first commit

File size: 5.8 KB
Line 
1//#include "DST_DB_Engine.h"
2//#include "dst_eroum_interface.h"
3//#include <sqlite3.h>
4//
5//#define DB_ENGINE_DEBUG 1
6//sqlite3 *g_db =0;
7//
8//static void Lock(bool bLock)
9//{
10//      static DS_U32 sema4 = 0;
11//      if (sema4== 0) sema4 = DST_OS_CreateLock((char*)"db");
12//      bLock ? DST_OS_Lock(sema4) : DST_OS_Unlock(sema4);
13//}
14//
15//
16//void CDB_Destructor(CDB* this)
17//{
18//      if (this->mResult)
19//      {
20//              int i;
21//              for ( i = 0; i < ((this->mRow)+1)*(this->mCol); i++) DST_OS_Free(&(this->mResult[i]));
22//              DST_OS_Free(&(this->mResult));
23//              this->mRow = 0;
24//              this->mCol = 0;                         
25//      }
26//}
27//
28//int CDB_Query(CDB* this, const char* strSQL, ...)
29//{
30//      if (g_db == 0 || strSQL == 0) return 0;
31//      if (this->mResult)
32//      {
33//              int i;
34//              for ( i = 0; i < ((this->mRow)+1)*(this->mCol); i++) DST_OS_Free(&(this->mResult[i]));
35//              DST_OS_Free(&(this->mResult));
36//              this->mRow = 0;
37//              this->mCol = 0;                         
38//      }
39//
40//      Lock(true);
41//      va_list ap;
42//      char *z;
43//      va_start(ap, strSQL);
44//      z = sqlite3_vmprintf(strSQL, ap);
45//      va_end(ap);
46//#if DB_ENGINE_DEBUG
47//      if (strlen(z) < 500)
48//      {
49//              DST_Printf("%s|%s\n", __func__, z);
50//      }
51//      else
52//      {
53//              DST_Printf("%s|%d\n", __func__, strlen(z));
54//      }
55//#endif
56//      char *ErrMsg = 0;
57//
58//      int rc = sqlite3_exec(g_db, z, 0, 0, &ErrMsg);
59//     
60//      if (rc)
61//      {
62//              DST_Printf("CT_Query|%s\n", z);
63//              DST_Printf("CT_Query|%d|%s\n", rc, ErrMsg);
64//              sqlite3_free(ErrMsg);
65//      }
66//      sqlite3_free(z);
67//      Lock(false);
68//  return rc;
69//}
70//
71//int CDB_GetTable(CDB *this, const char* strSQL, ...)
72//{
73//      if (g_db == 0 || strSQL == 0) return 0;
74//      if (this->mResult)
75//      {
76//              int i;
77//              for ( i = 0; i < ((this->mRow)+1)*(this->mCol); i++) DST_OS_Free(&(this->mResult[i]));
78//              DST_OS_Free(&(this->mResult));
79//              this->mRow = 0;
80//              this->mCol = 0;                         
81//      }
82//
83//      Lock(true);
84//
85//      va_list ap;
86//      char *z;
87//      va_start(ap, strSQL);
88//      z = sqlite3_vmprintf(strSQL, ap);
89//      va_end(ap);
90//#if DB_ENGINE_DEBUG
91//      if (strlen(z) < 500)
92//      {
93//              DST_Printf("%s|%s\n", __func__, z);
94//      }
95//      else
96//      {
97//              DST_Printf("%s|%d\n", __func__, strlen(z));
98//      }
99//#endif
100//      char *ErrMsg = 0;
101//     
102//      char **mResult1 = 0;   
103//      int rc = sqlite3_get_table(g_db, z, &mResult1, &(this->mRow), &(this->mCol), &ErrMsg);
104//     
105//      if (rc)
106//      {
107//              DST_Printf("CT_GetTable|%s\n", z);
108//              DST_Printf("CT_GetTable|%d|%s\n", rc, ErrMsg);
109//              sqlite3_free(ErrMsg);
110//      }
111//      else
112//      {
113//              if (mResult1)
114//              {
115//                      this->mResult = (char**)DST_OS_Calloc(((this->mRow)+1)*(this->mCol), sizeof(char*));   
116//                      int i;
117//                      for ( i = 0; i < ((this->mRow)+1)*(this->mCol); i++)                         
118//                      {
119//                              unsigned nLen = 0;
120//                              if (mResult1[i]) nLen = strlen(mResult1[i]);                                                                 
121//                              if (nLen == 0) continue;                                       
122//                              this->mResult[i] = (char*)DST_OS_Calloc(nLen+1,1);                     
123//                              strcpy(this->mResult[i], mResult1[i]);     
124//                              //DST_Printf("\t%s", this->mResult[i]);                         
125//                      }
126//                      //DST_Printf("\n");
127//              }                                                               
128//      }
129//      if (mResult1) sqlite3_free_table(mResult1);
130//      sqlite3_free(z);
131//      Lock(false);
132//  return rc;
133//}
134//
135//int CDB_GetRow(CDB* this)
136//{
137//      return this->mRow;
138//}
139//
140//int CDB_GetCol(CDB* this)
141//{
142//      return this->mCol;
143//}
144//
145//char* CDB_GetResult(CDB* this, int i)
146//{
147//      static char* strNull =(char*)"";
148//      if(i >= ((this->mRow)+1)*(this->mCol))
149//      {
150//              DST_Printf("%s|%d|Out of range. mRow:%d ,mCol:%d, i:%d\n", __func__, __LINE__,this->mRow,this->mCol,i);
151//              return (char*)"";
152//      }
153//      return (this->mResult[i]) == 0 ? strNull : this->mResult[i];
154//}
155//
156////CDB::CDB()
157//void NewCDB(CDB* p)
158//{
159//      p->mRow = 0;
160//      p->mCol = 0;
161//      p->mResult = 0;
162//      p->Destructor = CDB_Destructor;
163//      p->Query = CDB_Query;
164//      p->GetTable = CDB_GetTable;
165//      p->GetRow = CDB_GetRow;
166//      p->GetCol = CDB_GetCol;
167//      p->GetResult = CDB_GetResult;
168//}
169//
170//void DeleteCDB(CDB* p)
171//{
172//      if (p == 0) return;
173//      if (p->Destructor) p->Destructor(p);
174//}
175//
176//#ifdef SQLITE_OS_OTHER
177//
178//int dst_sqlite_randomness(sqlite3_vfs* p, int nByte, char *zOut)
179//{
180//      memset(zOut, 0, nByte);
181//      return nByte;
182//}
183//
184///*extern "C" */SQLITE_API int sqlite3_os_init(void)
185//{
186//  static sqlite3_vfs aVfs = {                       
187//    3,                    /* iVersion */                   
188//    0,     /* szOsFile */                   
189//    255,         /* mxPathname */                 
190//    0,                    /* pNext */                       
191//    0,              /* zName */                       
192//    0,       /* pAppData */                   
193//    0,             /* xOpen */                       
194//    0,           /* xDelete */                     
195//    0,           /* xAccess */                     
196//    0,     /* xFullPathname */               
197//    0,           /* xDlOpen */                     
198//    0,          /* xDlError */                   
199//    0,            /* xDlSym */                     
200//    0,          /* xDlClose */                   
201//    dst_sqlite_randomness,       /* xRandomness */                 
202//    0,            /* xSleep */                     
203//    0,      /* xCurrentTime */               
204//    0,     /* xGetLastError */               
205//    0, /* xCurrentTimeInt64 */           
206//    0,    /* xSetSystemCall */             
207//    0,    /* xGetSystemCall */             
208//    0   /* xNextSystemCall */             
209//  };
210//      sqlite3_vfs_register(&aVfs,1);
211//     
212//     
213//  return SQLITE_OK;
214//}
215//
216///*extern "C" */SQLITE_API int sqlite3_os_end(void)
217//{
218//  return SQLITE_OK;
219//}
220//
221//#endif
Note: See TracBrowser for help on using the repository browser.