28 #include "dbprocessor.h" |
28 #include "dbprocessor.h" |
29 #include "exception.h" |
29 #include "exception.h" |
30 #include "logs.h" |
30 #include "logs.h" |
31 #include "util.h" |
31 #include "util.h" |
32 #include "symbiantypes.h" |
32 #include "symbiantypes.h" |
33 #include "utf8_wrapper.h" |
33 |
34 #include "../sisxlibrary/utility.h" |
|
35 #include <string> |
34 #include <string> |
36 #include <cassert> |
35 #include <cassert> |
37 |
36 |
38 #ifdef __linux__ |
37 TDbLibrary* iLibraryHandler = NULL; |
39 #include <dlfcn.h> |
38 |
40 |
39 TDbLibrary::TDbLibrary(const std::string& aDllPath) |
41 |
40 { |
42 void* GetProcAddress(HINSTANCE aHandle, const char* aSymbol) |
41 LoadSqlLibrary(aDllPath); |
43 { |
42 LoadFunctions(); |
44 return dlsym(aHandle, aSymbol); |
43 } |
45 } |
44 |
46 |
45 /** |
47 HINSTANCE LoadLibraryA(const char* aLibraryName) |
46 * Failing to unload the library is not really a critical failure, when a dll is unloaded the |
48 { |
47 * current process sends a notification to the dll to detach itself from the process, which |
49 HINSTANCE handleUsingDefaultSearchPath = dlopen(aLibraryName, RTLD_LAZY); |
48 * means the dll can process memory cleanup operations before it unloads. The only case where |
50 |
49 * freelibrary might throw an error is if the library was not loaded in the first place, an |
51 if( handleUsingDefaultSearchPath == NULL ) |
50 * error which would be caught beforehand. Hence if the library cannot be unloaded corresponding |
52 { |
51 * error message is logged. |
53 // Once the dlopen() fails by not finding the aLibraryName in the default |
52 */ |
54 // path specified by LD_LIBRARY_PATH, we will look in the epoc32/tools |
53 TDbLibrary::~TDbLibrary() |
55 // path as the second option. |
54 { |
56 |
55 int retCode = FreeLibrary(sqLiteHndl); |
57 const char* epocRoot = getenv("EPOCROOT"); |
56 if(retCode == 0) |
58 if(NULL == epocRoot) |
57 { |
59 { |
58 LPCVOID lpMsgBuf; |
60 throw CException("EPOCROOT environment variable not specified.", ExceptionCodes::EEnvNotSpecified); |
59 |
61 } |
60 DWORD err = GetLastError(); |
62 std::string epocRootStr(epocRoot); |
61 FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | |
63 |
62 FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, |
64 std::string absPathToLibrary = epocRootStr + std::string("epoc32/tools/") + std::string(aLibraryName); |
63 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, |
65 HINSTANCE handleUsingAbsSearchPath = dlopen(absPathToLibrary.c_str(), RTLD_LAZY); |
64 0, NULL |
66 |
65 ); |
67 return handleUsingAbsSearchPath; |
66 std::wstring wErrMsg((wchar_t*)lpMsgBuf); |
68 } |
67 std::string errMsg = Util::wstring2string(wErrMsg); |
69 |
68 //LOGERROR(errMsg); |
70 return handleUsingDefaultSearchPath; |
69 |
71 } |
70 } |
72 |
71 } |
73 int FreeLibrary(HINSTANCE aHandle) |
72 |
74 { |
73 void TDbLibrary::LoadSqlLibrary(const std::string& aDllPath) |
75 // FreeLibrary returns non-zero value on success whereas |
74 { |
76 // dlcose returns zero on success. |
75 sqLiteHndl = LoadLibraryA(aDllPath.c_str()); |
77 return (dlclose(aHandle) == 0)? true: false; |
76 |
78 } |
77 // Check to see if the library was loaded successfully |
79 |
78 |
80 std::string GetErrorMessage() |
79 if (sqLiteHndl != 0) |
81 { |
80 { |
82 return dlerror(); |
81 //LOGINFO("Library successfully loaded!"); |
83 } |
82 } |
84 |
83 else |
85 static utf16WString utf32WString2utf16WString(std::wstring& aParameter) |
84 { |
86 { |
85 std::string errMsg("Failed to load SQLite library - "); |
87 int strLen = aParameter.length(); |
86 errMsg.append(aDllPath); |
88 const wchar_t * source = aParameter.c_str(); |
87 //LOGERROR(errMsg); |
89 unsigned short int* buffer = new unsigned short int[(strLen + 1) * 2]; |
88 throw CException(errMsg,ExceptionCodes::ELibraryLoadError); |
90 |
89 } |
91 // Using a temp variable in place of buffer as ConvertUTF32toUTF16 modifies the source pointer passed. |
90 } |
92 unsigned short int* temp = buffer; |
91 |
93 |
92 void TDbLibrary::LoadFunctions() |
94 ConvertUTF32toUTF16(&source, source + strLen, &temp, temp + strLen, lenientConversion); |
93 { |
95 |
94 sqlite3_open = (FnPtr_sqlite3_open)GetProcAddress(sqLiteHndl,"sqlite3_open"); |
96 // Appending NUL to the converted buffer. |
95 VerifyLoadedFunction(sqlite3_open); |
97 *temp = 0; |
96 |
98 |
97 sqlite3_prepare_v2 = (FnPtr_sqlite3_prepare_v2) GetProcAddress(sqLiteHndl,"sqlite3_prepare_v2"); |
99 utf16WString utf16Ws; |
98 VerifyLoadedFunction(sqlite3_prepare_v2); |
100 utf16Ws.resize(strLen); |
99 |
101 |
100 sqlite3_step = (FnPtr_sqlite3_step) GetProcAddress(sqLiteHndl,"sqlite3_step"); |
102 // The built-in basic_string template class copy operation |
101 VerifyLoadedFunction(sqlite3_step); |
103 // truncates when a NUL is encountered when a c_str() is |
102 |
104 // used to construct the required string. |
103 sqlite3_finalize = (FnPtr_sqlite3_finalize) GetProcAddress(sqLiteHndl,"sqlite3_finalize"); |
105 // So, if aParameter is any hashable string having the |
104 VerifyLoadedFunction(sqlite3_finalize); |
106 // syntax : swtypeName + L'\0' + someId then, we will end |
105 |
107 // up returning only part of the converted UTF-16 string. |
106 sqlite3_bind_text = (FnPtr_sqlite3_bind_text) GetProcAddress(sqLiteHndl,"sqlite3_bind_text"); |
108 // Hence, we resort to the explicit copy operation with |
107 VerifyLoadedFunction(sqlite3_bind_text); |
109 // two bytes at a time. |
108 |
110 while( strLen-- ) |
109 sqlite3_bind_text16 = (FnPtr_sqlite3_bind_text16) GetProcAddress(sqLiteHndl,"sqlite3_bind_text16"); |
111 { |
110 VerifyLoadedFunction(sqlite3_bind_text16); |
112 utf16Ws[ strLen ] = buffer[ strLen ]; |
111 |
113 } |
112 sqlite3_bind_int = (FnPtr_sqlite3_bind_int) GetProcAddress(sqLiteHndl,"sqlite3_bind_int"); |
114 |
113 VerifyLoadedFunction(sqlite3_bind_int); |
115 delete[] buffer; |
114 |
116 |
115 sqlite3_reset = (FnPtr_sqlite3_reset) GetProcAddress(sqLiteHndl,"sqlite3_reset"); |
117 return utf16Ws; |
116 VerifyLoadedFunction(sqlite3_reset); |
118 } |
117 |
119 |
118 sqlite3_clear_bindings = (FnPtr_sqlite3_clear_bindings) GetProcAddress(sqLiteHndl,"sqlite3_clear_bindings"); |
120 static std::wstring utf16WString2utf32WString(utf16WString& aParameter) |
119 VerifyLoadedFunction(sqlite3_clear_bindings); |
121 { |
120 |
122 int strLen = aParameter.length(); |
121 sqlite3_last_insert_rowid = (FnPtr_sqlite3_last_insert_rowid) GetProcAddress(sqLiteHndl,"sqlite3_last_insert_rowid"); |
123 const unsigned short int* source = aParameter.c_str(); |
122 VerifyLoadedFunction(sqlite3_last_insert_rowid); |
124 wchar_t* buffer = new wchar_t[ strLen + 1 ]; |
123 |
125 |
124 sqlite3_extended_result_codes = (FnPtr_sqlite3_extended_result_codes) GetProcAddress(sqLiteHndl, "sqlite3_extended_result_codes" ); |
126 // Using a temp variable in place of buffer as ConvertUTF16toUCS4 modifies the source pointer passed. |
125 VerifyLoadedFunction(sqlite3_extended_result_codes); |
127 wchar_t* temp = buffer; |
126 |
128 |
127 sqlite3_close = (FnPtr_sqlite3_close)GetProcAddress(sqLiteHndl,"sqlite3_close"); |
129 ConvertUTF16toUCS4(&source, source + strLen, &temp, temp + strLen); |
128 VerifyLoadedFunction(sqlite3_close); |
130 |
129 |
131 // Appending NUL to the converted buffer. |
130 sqlite3_errmsg = (FnPtr_sqlite3_errmsg)GetProcAddress(sqLiteHndl,"sqlite3_errmsg"); |
132 *temp = 0; |
131 VerifyLoadedFunction(sqlite3_errmsg); |
133 |
132 |
134 std::wstring utf32Ws(buffer); |
133 sqlite3_errcode = (FnPtr_sqlite3_errcode)GetProcAddress(sqLiteHndl,"sqlite3_errcode"); |
135 |
134 VerifyLoadedFunction(sqlite3_errcode); |
136 delete[] buffer; |
135 |
137 |
136 sqlite3_bind_int64 = (FnPtr_sqlite3_bind_int64)GetProcAddress(sqLiteHndl,"sqlite3_bind_int64"); |
138 return utf32Ws; |
137 VerifyLoadedFunction(sqlite3_bind_int64); |
139 } |
138 |
140 |
139 sqlite3_column_text16 = (FnPtr_sqlite3_column_text16)GetProcAddress(sqLiteHndl,"sqlite3_column_text16"); |
141 #else |
140 VerifyLoadedFunction(sqlite3_column_text16); |
142 std::string GetErrorMessage() |
141 |
143 { |
142 sqlite3_column_bytes16 = (FnPtr_sqlite3_column_bytes16)GetProcAddress(sqLiteHndl,"sqlite3_column_bytes16"); |
|
143 VerifyLoadedFunction(sqlite3_column_bytes16); |
|
144 |
|
145 sqlite3_column_int64 = (FnPtr_sqlite3_column_int64)GetProcAddress(sqLiteHndl,"sqlite3_column_int64"); |
|
146 VerifyLoadedFunction(sqlite3_column_int64); |
|
147 |
|
148 sqlite3_column_int = (FnPtr_sqlite3_column_int)GetProcAddress(sqLiteHndl,"sqlite3_column_int"); |
|
149 VerifyLoadedFunction(sqlite3_column_int); |
|
150 |
|
151 sqlite3_column_count = (FnPtr_sqlite3_column_count)GetProcAddress(sqLiteHndl,"sqlite3_column_count"); |
|
152 VerifyLoadedFunction(sqlite3_column_count); |
|
153 |
|
154 sqlite3_column_type = (FnPtr_sqlite3_column_type)GetProcAddress(sqLiteHndl,"sqlite3_column_type"); |
|
155 VerifyLoadedFunction(sqlite3_column_type); |
|
156 |
|
157 sqlite3_prepare16_v2 = (FnPtr_sqlite3_prepare16_v2)GetProcAddress(sqLiteHndl,"sqlite3_prepare16_v2"); |
|
158 VerifyLoadedFunction(sqlite3_prepare16_v2); |
|
159 |
|
160 sqlite3_bind_blob = (FnPtr_sqlite3_bind_blob)GetProcAddress(sqLiteHndl,"sqlite3_bind_blob"); |
|
161 VerifyLoadedFunction(sqlite3_bind_blob); |
|
162 |
|
163 } |
|
164 |
|
165 void TDbLibrary::VerifyLoadedFunction(void* aFnPtr) |
|
166 { |
|
167 if(aFnPtr != NULL) |
|
168 return; |
|
169 |
144 LPCVOID lpMsgBuf; |
170 LPCVOID lpMsgBuf; |
145 |
171 |
146 DWORD err = GetLastError(); |
172 DWORD err = GetLastError(); |
147 FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | |
173 FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | |
148 FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, |
174 FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, |
149 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, |
175 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, |
150 0, NULL |
176 0, NULL |
151 ); |
177 ); |
152 std::wstring wErrMsg((wchar_t*)lpMsgBuf); |
178 std::wstring wErrMsg((wchar_t*)lpMsgBuf); |
153 return wstring2string(wErrMsg); |
179 std::string errMsg = Util::wstring2string(wErrMsg); |
154 } |
|
155 #endif // __linux__ |
|
156 |
|
157 TDbLibrary* iLibraryHandler = NULL; |
|
158 |
|
159 TDbLibrary::TDbLibrary(const std::string& aDllPath) |
|
160 { |
|
161 LoadSqlLibrary(aDllPath); |
|
162 LoadFunctions(); |
|
163 } |
|
164 |
|
165 /** |
|
166 * Failing to unload the library is not really a critical failure, when a dll is unloaded the |
|
167 * current process sends a notification to the dll to detach itself from the process, which |
|
168 * means the dll can process memory cleanup operations before it unloads. The only case where |
|
169 * freelibrary might throw an error is if the library was not loaded in the first place, an |
|
170 * error which would be caught beforehand. Hence if the library cannot be unloaded corresponding |
|
171 * error message is logged. |
|
172 */ |
|
173 TDbLibrary::~TDbLibrary() |
|
174 { |
|
175 int retCode = FreeLibrary(sqLiteHndl); |
|
176 if(retCode == 0) |
|
177 { |
|
178 //LOGERROR(GetErrorMessage()); |
|
179 } |
|
180 } |
|
181 |
|
182 void TDbLibrary::LoadSqlLibrary(const std::string& aDllPath) |
|
183 { |
|
184 sqLiteHndl = LoadLibraryA(aDllPath.c_str()); |
|
185 |
|
186 // Check to see if the library was loaded successfully |
|
187 |
|
188 if (sqLiteHndl != 0) |
|
189 { |
|
190 //LOGINFO("Library successfully loaded!"); |
|
191 } |
|
192 else |
|
193 { |
|
194 std::string errMsg("Failed to load SQLite library - "); |
|
195 errMsg.append(aDllPath); |
|
196 //LOGERROR(errMsg); |
|
197 throw CException(errMsg,ExceptionCodes::ELibraryLoadError); |
|
198 } |
|
199 } |
|
200 |
|
201 void TDbLibrary::LoadFunctions() |
|
202 { |
|
203 sqlite3_open = (FnPtr_sqlite3_open)GetProcAddress(sqLiteHndl,"sqlite3_open"); |
|
204 VerifyLoadedFunction(sqlite3_open); |
|
205 |
|
206 sqlite3_prepare_v2 = (FnPtr_sqlite3_prepare_v2) GetProcAddress(sqLiteHndl,"sqlite3_prepare_v2"); |
|
207 VerifyLoadedFunction(sqlite3_prepare_v2); |
|
208 |
|
209 sqlite3_step = (FnPtr_sqlite3_step) GetProcAddress(sqLiteHndl,"sqlite3_step"); |
|
210 VerifyLoadedFunction(sqlite3_step); |
|
211 |
|
212 sqlite3_finalize = (FnPtr_sqlite3_finalize) GetProcAddress(sqLiteHndl,"sqlite3_finalize"); |
|
213 VerifyLoadedFunction(sqlite3_finalize); |
|
214 |
|
215 sqlite3_bind_text = (FnPtr_sqlite3_bind_text) GetProcAddress(sqLiteHndl,"sqlite3_bind_text"); |
|
216 VerifyLoadedFunction(sqlite3_bind_text); |
|
217 |
|
218 sqlite3_bind_text16 = (FnPtr_sqlite3_bind_text16) GetProcAddress(sqLiteHndl,"sqlite3_bind_text16"); |
|
219 VerifyLoadedFunction(sqlite3_bind_text16); |
|
220 |
|
221 sqlite3_bind_int = (FnPtr_sqlite3_bind_int) GetProcAddress(sqLiteHndl,"sqlite3_bind_int"); |
|
222 VerifyLoadedFunction(sqlite3_bind_int); |
|
223 |
|
224 sqlite3_reset = (FnPtr_sqlite3_reset) GetProcAddress(sqLiteHndl,"sqlite3_reset"); |
|
225 VerifyLoadedFunction(sqlite3_reset); |
|
226 |
|
227 sqlite3_clear_bindings = (FnPtr_sqlite3_clear_bindings) GetProcAddress(sqLiteHndl,"sqlite3_clear_bindings"); |
|
228 VerifyLoadedFunction(sqlite3_clear_bindings); |
|
229 |
|
230 sqlite3_last_insert_rowid = (FnPtr_sqlite3_last_insert_rowid) GetProcAddress(sqLiteHndl,"sqlite3_last_insert_rowid"); |
|
231 VerifyLoadedFunction(sqlite3_last_insert_rowid); |
|
232 |
|
233 sqlite3_extended_result_codes = (FnPtr_sqlite3_extended_result_codes) GetProcAddress(sqLiteHndl, "sqlite3_extended_result_codes" ); |
|
234 VerifyLoadedFunction(sqlite3_extended_result_codes); |
|
235 |
|
236 sqlite3_close = (FnPtr_sqlite3_close)GetProcAddress(sqLiteHndl,"sqlite3_close"); |
|
237 VerifyLoadedFunction(sqlite3_close); |
|
238 |
|
239 sqlite3_errmsg = (FnPtr_sqlite3_errmsg)GetProcAddress(sqLiteHndl,"sqlite3_errmsg"); |
|
240 VerifyLoadedFunction(sqlite3_errmsg); |
|
241 |
|
242 sqlite3_errcode = (FnPtr_sqlite3_errcode)GetProcAddress(sqLiteHndl,"sqlite3_errcode"); |
|
243 VerifyLoadedFunction(sqlite3_errcode); |
|
244 |
|
245 sqlite3_bind_int64 = (FnPtr_sqlite3_bind_int64)GetProcAddress(sqLiteHndl,"sqlite3_bind_int64"); |
|
246 VerifyLoadedFunction(sqlite3_bind_int64); |
|
247 |
|
248 sqlite3_column_text16 = (FnPtr_sqlite3_column_text16)GetProcAddress(sqLiteHndl,"sqlite3_column_text16"); |
|
249 VerifyLoadedFunction(sqlite3_column_text16); |
|
250 |
|
251 sqlite3_column_bytes16 = (FnPtr_sqlite3_column_bytes16)GetProcAddress(sqLiteHndl,"sqlite3_column_bytes16"); |
|
252 VerifyLoadedFunction(sqlite3_column_bytes16); |
|
253 |
|
254 sqlite3_column_int64 = (FnPtr_sqlite3_column_int64)GetProcAddress(sqLiteHndl,"sqlite3_column_int64"); |
|
255 VerifyLoadedFunction(sqlite3_column_int64); |
|
256 |
|
257 sqlite3_column_int = (FnPtr_sqlite3_column_int)GetProcAddress(sqLiteHndl,"sqlite3_column_int"); |
|
258 VerifyLoadedFunction(sqlite3_column_int); |
|
259 |
|
260 sqlite3_column_count = (FnPtr_sqlite3_column_count)GetProcAddress(sqLiteHndl,"sqlite3_column_count"); |
|
261 VerifyLoadedFunction(sqlite3_column_count); |
|
262 |
|
263 sqlite3_column_type = (FnPtr_sqlite3_column_type)GetProcAddress(sqLiteHndl,"sqlite3_column_type"); |
|
264 VerifyLoadedFunction(sqlite3_column_type); |
|
265 |
|
266 sqlite3_prepare16_v2 = (FnPtr_sqlite3_prepare16_v2)GetProcAddress(sqLiteHndl,"sqlite3_prepare16_v2"); |
|
267 VerifyLoadedFunction(sqlite3_prepare16_v2); |
|
268 |
|
269 sqlite3_bind_blob = (FnPtr_sqlite3_bind_blob)GetProcAddress(sqLiteHndl,"sqlite3_bind_blob"); |
|
270 VerifyLoadedFunction(sqlite3_bind_blob); |
|
271 |
|
272 } |
|
273 |
|
274 void TDbLibrary::VerifyLoadedFunction(void* aFnPtr) |
|
275 { |
|
276 if(aFnPtr != NULL) |
|
277 return; |
|
278 |
|
279 std::string errMsg = GetErrorMessage(); |
|
280 //LOGERROR(errMsg); |
180 //LOGERROR(errMsg); |
281 throw CException(errMsg,ExceptionCodes::ELibraryLoadError); |
181 throw CException(errMsg,ExceptionCodes::ELibraryLoadError); |
282 } |
182 } |
283 |
183 |
284 |
184 |
460 { |
360 { |
461 TInt err = iLibraryHandler.sqlite3_bind_int64(iStmtHandle, aParameterIndex, aParameterValue); |
361 TInt err = iLibraryHandler.sqlite3_bind_int64(iStmtHandle, aParameterIndex, aParameterValue); |
462 CheckSqlErrCode(err); |
362 CheckSqlErrCode(err); |
463 } |
363 } |
464 |
364 |
465 |
|
466 #ifdef __TOOLS2_LINUX__ |
|
467 void CStatement::BindStr(TInt aParameterIndex, const std::wstring &aParameterStr, int aConvertSlash=allowSlashConversion) |
|
468 #else |
|
469 void CStatement::BindStr(TInt aParameterIndex, const std::wstring &aParameterStr) |
365 void CStatement::BindStr(TInt aParameterIndex, const std::wstring &aParameterStr) |
470 #endif |
366 { |
471 { |
|
472 /* |
|
473 * Under LINUX : Because of the UTF-32 format of wstring, we can't directly use the sqlite3_bind_text16() which |
|
474 * requires UTF-16 format. So, we convert the UTF-32 data into UTF-16 before using it. |
|
475 * |
|
476 * Under WINDOWS : No conversion required since wstring will be in UTF-16 format itself. |
|
477 */ |
|
478 |
|
479 #ifdef __LINUX__ |
|
480 // Make sure that the wstring passed to this function is not having any trailing |
|
481 // explicit NUL( Preferably, pass c_str() part of wstring ). |
|
482 // |
|
483 // Only case in which you shouldn't pass c_str() is that the wstring has NUL as |
|
484 // part of its actual string content(like swtypename + L'\0' + someID etc). |
|
485 |
|
486 // In order to maintain the consistency of DB contents across the WINDOWS and LINUX platforms, before interacting |
|
487 // with the DB we convert the local paths into WINDOWS specific paths. |
|
488 // |
|
489 // If aParameterStr is not a PATH but contains a forward slash, we should restrain |
|
490 // from the slash conversion. One such instance is MimeType. |
|
491 // |
|
492 std::wstring temp = aParameterStr; |
|
493 if( aConvertSlash == allowSlashConversion ) |
|
494 { |
|
495 ConvertToWindowsSpecificPaths(temp); |
|
496 } |
|
497 |
|
498 utf16WString utf16s = utf32WString2utf16WString(temp); |
|
499 |
|
500 TInt err = iLibraryHandler.sqlite3_bind_text16(iStmtHandle, aParameterIndex, utf16s.c_str(), aParameterStr.size()*2, SQLITE_TRANSIENT); |
|
501 |
|
502 #else |
|
503 TInt err = iLibraryHandler.sqlite3_bind_text16(iStmtHandle, aParameterIndex, aParameterStr.c_str(), aParameterStr.size()*2, SQLITE_TRANSIENT); |
367 TInt err = iLibraryHandler.sqlite3_bind_text16(iStmtHandle, aParameterIndex, aParameterStr.c_str(), aParameterStr.size()*2, SQLITE_TRANSIENT); |
504 #endif |
|
505 // The fifth argument has the value SQLITE_TRANSIENT, it means that SQLite makes its own private copy of the data immediately |
368 // The fifth argument has the value SQLITE_TRANSIENT, it means that SQLite makes its own private copy of the data immediately |
506 CheckSqlErrCode(err); |
369 CheckSqlErrCode(err); |
507 } |
370 } |
508 |
371 |
509 void CStatement::BindBinary(TInt aParameterIndex, const std::string &aParameterStr) |
372 void CStatement::BindBinary(TInt aParameterIndex, const std::string &aParameterStr) |
510 { |
373 { |
511 TInt err = iLibraryHandler.sqlite3_bind_blob(iStmtHandle, aParameterIndex, aParameterStr.c_str(), aParameterStr.size(), SQLITE_TRANSIENT); |
374 TInt err = iLibraryHandler.sqlite3_bind_blob(iStmtHandle, aParameterIndex, aParameterStr.c_str(), aParameterStr.size(), SQLITE_TRANSIENT); |
512 // The fifth argument has the value SQLITE_TRANSIENT, it means that SQLite makes its own private copy of the data immediately |
|
513 CheckSqlErrCode(err); |
|
514 } |
|
515 |
|
516 void CStatement::BindBinary(TInt aParameterIndex, const std::wstring &aParameterStr) |
|
517 { |
|
518 #ifdef __LINUX__ |
|
519 // To maintain consistency of the binary equivalent of the wstring |
|
520 // being binded, we convert the wstring with UTF-32 encoding under LINUX |
|
521 // to UTF-16 encoding which is same as that of wstring under WINDOWS. |
|
522 |
|
523 std::wstring temp = aParameterStr; |
|
524 utf16WString utf16s = utf32WString2utf16WString(temp); |
|
525 |
|
526 TInt err = iLibraryHandler.sqlite3_bind_blob(iStmtHandle, aParameterIndex, utf16s.c_str(), aParameterStr.size()*2, SQLITE_TRANSIENT); |
|
527 #else |
|
528 TInt err = iLibraryHandler.sqlite3_bind_blob(iStmtHandle, aParameterIndex, aParameterStr.c_str(), aParameterStr.size()*2, SQLITE_TRANSIENT); |
|
529 #endif |
|
530 |
|
531 // The fifth argument has the value SQLITE_TRANSIENT, it means that SQLite makes its own private copy of the data immediately |
375 // The fifth argument has the value SQLITE_TRANSIENT, it means that SQLite makes its own private copy of the data immediately |
532 CheckSqlErrCode(err); |
376 CheckSqlErrCode(err); |
533 } |
377 } |
534 |
378 |
535 void CStatement::Reset() |
379 void CStatement::Reset() |