2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file DTapps2SqliteDB.cpp
19 * @brief This file includes functions relating to DataBase.
22 #include "DTapps2SqliteDB.h"
27 /* Define EXPORT_API temporary */
29 #define EXPORT_API __attribute__((visibility("default")))
32 static dtapps_mutex_t dtapps_sqlite_db_mutex = PTHREAD_MUTEX_INITIALIZER;
34 typedef long int dtappsThreadID;
36 class DtappsDBConnectionInfo
39 DtappsDBConnectionInfo();
40 int countOpenConnection;
41 sqlite3 *pDBConnection;
45 static std::map<dtappsThreadID, std::unique_ptr<DtappsDBConnectionInfo>> g_dtapps_sqlite_connection_table;
47 DtappsDBConnectionInfo::DtappsDBConnectionInfo()
49 countOpenConnection=0;
60 TAPPSDbApiLock::TAPPSDbApiLock()
62 DRM_TAPPS_FRQ_LOG("LOCK by TID = %ld",drmgettid());
63 if (0 != dtapps_mutex_lock (&dtapps_sqlite_db_mutex))
65 DRM_TAPPS_EXCEPTION("Error while mutex locking.");
69 TAPPSDbApiLock::~TAPPSDbApiLock()
71 DRM_TAPPS_FRQ_LOG("UNLOCK by TID = %ld",drmgettid());
72 if (0 != dtapps_mutex_unlock(&dtapps_sqlite_db_mutex))
74 DRM_TAPPS_EXCEPTION("Error while mutex unlocking");
78 #define __DTAPPS_DB_SQLITE_RETRY__ (10)
80 #define DTAPPS_SQLITE3_SQL_BEGIN_IMMEDIATE "BEGIN IMMEDIATE TRANSACTION"
81 #define DTAPPS_SQLITE3_SQL_COMMIT "COMMIT TRANSACTION"
82 #define DTAPPS_SQLITE3_SQL_ROLLBACK "ROLLBACK TRANSACTION"
84 /* DataBase Related API Wrappers */
85 BOOL DTappsDBOpen(void *&pDb, const char* CallingFun)
87 DRM_TAPPS_LOG("[%s]: started.Calling function = %s",__func__,CallingFun);
89 TAPPSDbApiLock Dblock;
90 dtappsThreadID id_curr_thread = drmgettid();
92 DRM_TAPPS_SECURE_LOG("DB-OPEN-CLOSE [%s]Parent Process ID=[%ld]:Process-ID=[%ld]:Thread-ID=[%ld], id_curr_thread=[%ld]",__func__,getppid(),getpid(),drmgettid(), id_curr_thread);
94 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
95 if (it != g_dtapps_sqlite_connection_table.end()) {
96 DRM_TAPPS_FRQ_LOG("Connection already exists..");
97 auto &pDBConnectionInfo = it->second;
98 DRM_TAPPS_FRQ_LOG("pDBConnectionInfo=[0x%x]", pDBConnectionInfo.get());
100 if (pDBConnectionInfo == NULL || pDBConnectionInfo->pDBConnection == NULL)
103 DRM_TAPPS_FRQ_LOG("pDBConnectionInfo->countOpenConnection=[%d], pDBConnectionInfo->pDBConnection=[0x%x]", pDBConnectionInfo->countOpenConnection, pDBConnectionInfo->pDBConnection);
105 ++(pDBConnectionInfo->countOpenConnection);
106 pDb = pDBConnectionInfo->pDBConnection;
108 DRM_TAPPS_LOG("no connection exists..");
109 std::unique_ptr<DtappsDBConnectionInfo> pDBConnectionInfo(
110 new(std::nothrow) DtappsDBConnectionInfo);
111 if (pDBConnectionInfo == NULL)
114 DRM_TAPPS_FRQ_LOG("Opening DB connection.");
116 sqlite3 *h_db = NULL;
117 int result = db_util_open(DTAPPS_DB_NAME, &h_db, 0);
118 if (result != SQLITE_OK) {
119 DRM_TAPPS_EXCEPTION("sqlite msg :[%d]%s",result, sqlite3_errmsg(h_db));
120 DRM_TAPPS_SECURE_LOG("db name :%s", DTAPPS_DB_NAME);
124 DRM_TAPPS_FRQ_LOG("sqlite3_open() is success. h_db:%x", h_db);
126 pDBConnectionInfo->countOpenConnection = 1;
127 pDBConnectionInfo->pDBConnection = h_db;
129 pDb = pDBConnectionInfo->pDBConnection;
132 DRM_TAPPS_FRQ_LOG("pDBConnectionInfo->countOpenConnection=[%d], pDBConnectionInfo->pDBConnection=[0x%x]", pDBConnectionInfo->countOpenConnection, pDBConnectionInfo->pDBConnection);
134 g_dtapps_sqlite_connection_table.emplace(
135 std::make_pair(id_curr_thread, std::move(pDBConnectionInfo)));
138 DRM_TAPPS_LOG("This fn finishes successfully.");
143 BOOL DTappsDBGet(void *& pDBConnection)
145 DRM_TAPPS_LOG("Inside %s", __func__);
147 TAPPSDbApiLock Dblock;
148 dtappsThreadID id_curr_thread = drmgettid();
149 pDBConnection = NULL;
151 DRM_TAPPS_LOG("Parent Process ID=[%ld]:Process-ID=[%ld]:Thread-ID=[%ld], id_curr_thread=[%ld]",getppid(),getpid(),drmgettid(), id_curr_thread);
153 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
154 if (it == g_dtapps_sqlite_connection_table.end() ||
155 it->second == NULL ||
156 it->second->pDBConnection == NULL)
159 auto &pDBConnectionInfo = it->second;
160 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
161 pDBConnectionInfo->countOpenConnection, pDBConnectionInfo->pDBConnection);
163 pDBConnection = pDBConnectionInfo->pDBConnection;
168 BOOL DTappsDBClose(const char* CallingFun)
170 DRM_TAPPS_LOG("Inside %s Calling function = %s", __func__, CallingFun);
172 TAPPSDbApiLock Dblock;
173 dtappsThreadID id_curr_thread = drmgettid();
175 DRM_TAPPS_SECURE_LOG(
176 "DB-OPEN-CLOSE [%s]Parent Process ID=[%ld]:Process-ID=[%ld]"
177 ":Thread-ID=[%ld], id_curr_thread=[%ld]",
178 __func__, getppid(), getpid(), drmgettid(), id_curr_thread);
180 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
181 if (it == g_dtapps_sqlite_connection_table.end()) {
183 } else if (it->second == NULL || it->second->pDBConnection == NULL) {
184 g_dtapps_sqlite_connection_table.erase(it);
188 auto &pDBConnectionInfo = it->second;
189 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
190 pDBConnectionInfo->countOpenConnection, pDBConnectionInfo->pDBConnection);
192 int countConnection = --(pDBConnectionInfo->countOpenConnection);
194 DRM_TAPPS_LOG(" countConnection=[%d] ", countConnection);
195 if (countConnection != 0)
198 DRM_TAPPS_LOG("closing DB connection info ");
200 sqlite3 *pDBConnection = it->second->pDBConnection;
202 DRM_TAPPS_LOG("finalizing all statements..pDBConnection=[0x%x]", pDBConnection);
203 sqlite3_stmt *pstmt = NULL;
204 while ((pstmt = sqlite3_next_stmt(pDBConnection, pstmt)) != NULL) {
205 DRM_TAPPS_LOG("finalizing DB statement..pstmt=[0x%x]", pstmt);
206 sqlite3_finalize(pstmt);
211 DRM_TAPPS_LOG(" Closing DB connection..pDBConnection=[0x%x]", pDBConnection);
212 if (db_util_close(pDBConnection) != SQLITE_OK) {
213 DRM_TAPPS_EXCEPTION("db_util_close failed. errmsg:%s",
214 sqlite3_errmsg(pDBConnection));
218 // erase map element regardless sqlite handle resource releasement
219 // because it's not usable anymore.
220 DRM_TAPPS_LOG("erasing map entry..pDBConnection=[0x%x]", pDBConnection);
221 g_dtapps_sqlite_connection_table.erase(it);
226 BOOL DTappsDBBeginImmedTrans (const char* CallingFun)
228 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__, CallingFun);
230 dtappsThreadID id_curr_thread = drmgettid();
232 int count_try_db=0,rc = -1;
234 DRM_TAPPS_SECURE_LOG("DB-OPEN-CLOSE-BEG-COM-RB [%s]Parent Process ID=[%ld]:Process-ID=[%ld]:Thread-ID=[%ld], id_curr_thread=[%ld]",__func__,getppid(),getpid(),drmgettid(), id_curr_thread);
236 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
237 if (it == g_dtapps_sqlite_connection_table.end())
240 auto &pDBConnectionInfo = it->second;
241 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], DBConnection=[0x%x]", __func__, pDBConnectionInfo->countOpenConnection, pDBConnectionInfo->pDBConnection);
243 auto pDBConnection = pDBConnectionInfo->pDBConnection;
245 DRM_TAPPS_LOG("Beginning DB operations..pDBConnection=[0x%x]", pDBConnection);
248 DRM_TAPPS_LOG("START BEGIN");
249 rc = sqlite3_exec (pDBConnection, DTAPPS_SQLITE3_SQL_BEGIN_IMMEDIATE, NULL, NULL, NULL);
251 DRM_TAPPS_FRQ_LOG("START BEGIN rc=%d", rc);
254 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc, sqlite3_errmsg(pDBConnection));
255 if (rc == SQLITE_BUSY)
258 DRM_TAPPS_FRQ_LOG("Tried [%d] times to begin", count_try_db);
261 if (count_try_db >= (int)__DTAPPS_DB_SQLITE_RETRY__)
263 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc, sqlite3_errmsg(pDBConnection));
269 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc, sqlite3_errmsg(pDBConnection));
275 DRM_TAPPS_LOG("begin SUCCESS count_try_db=%d", count_try_db);
280 DRM_TAPPS_LOG("This fn finishes successfully..pDBConnection=[0x%x]", pDBConnection);
285 DRM_TAPPS_EXCEPTION("This fn fails.. pDBConnection=[0x%x]", pDBConnection);
289 BOOL DTappsDBCommit(const char* CallingFun)
291 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__,CallingFun);
292 dtappsThreadID id_curr_thread = drmgettid();
294 int count_try_db_commit=0,rc = -1;
296 DRM_TAPPS_SECURE_LOG("DB-OPEN-CLOSE-BEG-COM-RB [%s]Parent Process ID=[%ld]:Process-ID=[%ld]:Thread-ID=[%ld], id_curr_thread=[%ld]",__func__,getppid(),getpid(),drmgettid(), id_curr_thread);
298 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
299 if (it == g_dtapps_sqlite_connection_table.end())
302 auto &pDBConnectionInfo = it->second;
303 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]", pDBConnectionInfo->countOpenConnection, pDBConnectionInfo->pDBConnection);
305 auto pDBConnection = pDBConnectionInfo->pDBConnection;
307 DRM_TAPPS_LOG("Commiting DB operations..pDBConnection=[0x%x]", pDBConnection);
310 DRM_TAPPS_FRQ_LOG("START Commit");
311 rc = sqlite3_exec (pDBConnection, DTAPPS_SQLITE3_SQL_COMMIT, NULL, NULL, NULL);
312 DRM_TAPPS_FRQ_LOG("START Commit rc=%d", rc);
316 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc, sqlite3_errmsg(pDBConnection));
318 if (rc == SQLITE_BUSY)
321 DRM_TAPPS_FRQ_LOG("Tried [%d] times to Commit", count_try_db_commit);
322 count_try_db_commit++;
323 if (count_try_db_commit >= (int)__DTAPPS_DB_SQLITE_RETRY__)
325 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc, sqlite3_errmsg(pDBConnection));
331 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc, sqlite3_errmsg(pDBConnection));
337 DRM_TAPPS_FRQ_LOG("Commit SUCCESS count_try_db_commit=%d", count_try_db_commit);
342 DRM_TAPPS_LOG("This fn finishes successfully..pDBConnection=[0x%x]", pDBConnection);
347 DRM_TAPPS_EXCEPTION("[%s] This fn fails.. pDBConnection=[0x%x]", pDBConnection);
352 BOOL DTappsDBRollback (const char* CallingFun)
354 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__,CallingFun);
356 dtappsThreadID id_curr_thread = drmgettid();
358 int count_try_db_rollback = 0, rc = -1;
360 DRM_TAPPS_SECURE_LOG("DB-OPEN-CLOSE-BEG-COM-RB [%s]Parent Process ID=[%ld]:Process-ID=[%ld]:Thread-ID=[%ld], id_curr_thread=[%ld]",__func__,getppid(),getpid(),drmgettid(), id_curr_thread);
362 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
363 if (it == g_dtapps_sqlite_connection_table.end())
366 auto &pDBConnectionInfo = it->second;
367 DRM_TAPPS_SECURE_LOG("[%s] countOpenConnection=[%d], pDBConnection=[0x%x]", __func__, pDBConnectionInfo->countOpenConnection, pDBConnectionInfo->pDBConnection);
369 auto pDBConnection = pDBConnectionInfo->pDBConnection;
371 DRM_TAPPS_LOG("Rollback DB operations..pDBConnection=[0x%x]", pDBConnection);
374 DRM_TAPPS_FRQ_LOG("START Rollback");
375 rc = sqlite3_exec (pDBConnection, DTAPPS_SQLITE3_SQL_ROLLBACK, NULL, NULL, NULL);
376 DRM_TAPPS_FRQ_LOG("START Rollback rc=%d",rc);
380 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s",pDBConnection,rc,sqlite3_errmsg(pDBConnection));
382 if(rc == SQLITE_BUSY)
385 DRM_TAPPS_FRQ_LOG("Tried [%d] times to Rollback",count_try_db_rollback);
386 count_try_db_rollback++;
387 if(count_try_db_rollback >= (int)__DTAPPS_DB_SQLITE_RETRY__)
389 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",pDBConnection,rc,sqlite3_errmsg(pDBConnection));
395 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",pDBConnection,rc,sqlite3_errmsg(pDBConnection));
401 DRM_TAPPS_FRQ_LOG("Rollback SUCCESS count_try_db_rollback=%d",count_try_db_rollback);
406 DRM_TAPPS_LOG("This fn finishes successfully..pDBConnection=[0x%x]", pDBConnection);
411 DRM_TAPPS_EXCEPTION("This fn fails.. pDBConnection=[0x%x]", pDBConnection);
417 BOOL DTappsExecuteSQL(void* pDB, const char* query)
419 int count_try_db_exe = 0, rc = 0;
420 sqlite3* h_db = (sqlite3*)pDB;
422 TAPPSDbApiLock Dblock;
426 rc = sqlite3_exec (h_db, query, NULL, NULL, NULL);
427 DRM_TAPPS_FRQ_LOG("EXECUTE rc=%d", rc);
431 if (rc == SQLITE_BUSY)
434 DRM_TAPPS_FRQ_LOG("Tried [%d] times to execute",count_try_db_exe);
437 if (count_try_db_exe >= (int)__DTAPPS_DB_SQLITE_RETRY__)
439 DRM_TAPPS_EXCEPTION("h_db=0x%x rc=%d ErrMsg:%s count_try_db_exe=%d",h_db,rc,sqlite3_errmsg(h_db),count_try_db_exe);
440 DRM_TAPPS_EXCEPTION("query=[%s]",query);
446 DRM_TAPPS_EXCEPTION("h_db=0x%x rc=%d ErrMsg:%s", h_db, rc, sqlite3_errmsg(h_db));
447 DRM_TAPPS_EXCEPTION("query=[%s]", query);
453 DRM_TAPPS_FRQ_LOG("EXECUTE SUCCESS count_try_db_exe=%d", count_try_db_exe);
462 BOOL DTappsSQLGetTable(void* pDB, const char* query, TAPPSSqliteSelectTable* select_table)
465 sqlite3* h_db = (sqlite3*)pDB;
467 DRM_TAPPS_FRQ_LOG("h_db=0x%x query=%s", h_db,query);
468 TAPPSDbApiLock Dblock;
469 select_table->handle = h_db;
471 DRM_TAPPS_FRQ_LOG("select_table->handle=%x", select_table->handle);
473 int count_try_db_select = 0;
477 rc = sqlite3_get_table(h_db, query, &select_table->result, &select_table->n_rows, &select_table->n_cols, NULL);
479 DRM_TAPPS_FRQ_LOG("SELECT rc=%d", rc);
483 if (rc == SQLITE_BUSY)
486 DRM_TAPPS_FRQ_LOG("SELECT Tried [%d] times to select \n",count_try_db_select);
488 count_try_db_select++;
490 if(count_try_db_select >= (int)__DTAPPS_DB_SQLITE_RETRY__)
492 DRM_TAPPS_EXCEPTION("SELECT h_db=0x%x rc=%d ErrMsg:%s count_try_db_select=%d \n",h_db,rc,sqlite3_errmsg(h_db),count_try_db_select);
493 DRM_TAPPS_EXCEPTION("query=[%s] \n",query);
500 DRM_TAPPS_EXCEPTION("SELECT h_db=0x%x rc=%d ErrMsg:%s \n",h_db,rc,sqlite3_errmsg(h_db));
501 DRM_TAPPS_EXCEPTION("%s query=[%s] \n",query);
508 DRM_TAPPS_FRQ_LOG("SELECT SUCCESS count_try_db_select=%d \n",count_try_db_select);
514 DRM_TAPPS_FRQ_LOG("n_rows=%d n_cols=%d \n",select_table->n_rows, select_table->n_cols);
519 extern const char* dtappsCreateTableSQLData[];
521 char* DTappsGetSQLCreateTable(const char* tableName)
530 DRM_TAPPS_FRQ_LOG("tableName = %s",tableName);
532 while(dtappsCreateTableSQLData[index])
534 if(TAPPS_strnicmp( dtappsCreateTableSQLData[index],tableName,TAPPS_STRLEN(tableName))==0)
536 char* sql = (char*)dtappsCreateTableSQLData[index];
537 sql = sql + TAPPS_STRLEN(dtappsCreateTableSQLData[index])+1;
539 DRM_TAPPS_FRQ_LOG("sql query = %s",sql);
549 DRM_TAPPS_EXCEPTION("Specified Table Name is not Valid!!!");
554 void* DTappsStmtPrepare(void* pDB, const char* query)
557 sqlite3* h_db = (sqlite3*)pDB;
558 sqlite3_stmt* stmt = 0;
560 DRM_TAPPS_FRQ_LOG("h_db=0x%x query=%s \n",h_db,query);
562 TAPPSDbApiLock Dblock;
564 if(0 == TAPPS_strnicmp(query, "SELECT", 6))
566 DRM_TAPPS_EXCEPTION("Doesn't support 'Select' query h_db=0x%x query=%s \n",h_db,query);
571 rc = sqlite3_prepare( h_db, query, -1, &stmt, NULL);
573 DRM_TAPPS_FRQ_LOG("%s: rc=%d query=%s stmt=0x%x \n",__func__,rc,query,stmt);
577 DRM_TAPPS_EXCEPTION("DTappsStmtPrepare: h_db=0x%x err: %s \n",h_db,sqlite3_errmsg(h_db));
578 DRM_TAPPS_EXCEPTION("DTappsStmtPrepare: query: %s\n", query);
587 int DTappsStmtBindParam (
592 unsigned int dParamSize )
595 sqlite3_stmt* stmt = (sqlite3_stmt*)pStmt;
597 DRM_TAPPS_FRQ_LOG("Enter \n");
599 TAPPSDbApiLock Dblock;
603 DRM_TAPPS_EXCEPTION("DTappsStmtBindParam: stmt is NULL \n");
610 * The parameter index in SQL starts from 1 in sqlite3.
614 case TAPPSDB_TYPE_NONE:
615 rc = sqlite3_bind_null( stmt, dIdx+1);
619 case TAPPSDB_TYPE_INT:
620 rc = sqlite3_bind_int( stmt, dIdx+1, *(int*)pParam);
621 DRM_TAPPS_FRQ_LOG(" rc=%d type=%d pParam=%d \n",rc,Type,*(int*)pParam);
625 case TAPPSDB_TYPE_DATETIME:
627 case TAPPSDB_TYPE_CHAR:
629 case TAPPSDB_TYPE_VARCHAR:
630 rc = sqlite3_bind_text( stmt, dIdx+1, (char*)pParam, dParamSize, SQLITE_TRANSIENT);
631 DRM_TAPPS_FRQ_LOG("rc=%d type=%d dParamSize=%d pParam=%s \n",rc,Type,dParamSize,pParam);
635 case TAPPSDB_TYPE_BINARY:
637 case TAPPSDB_TYPE_BLOB:
641 unsigned int packet64_size=0;
642 if(CMStringUtil::GetBase64Encode((unsigned char*)pParam,dParamSize, &packet64) == true)
644 packet64_size = MSTRLEN(packet64);
645 rc = sqlite3_bind_blob( stmt, dIdx+1, packet64, packet64_size, SQLITE_TRANSIENT);
646 DRM_OMA_FRQ_LOG("%s: rc=%d type=%d packet64_size=%d packet64=%s \n",__func__,rc,Type,packet64_size,packet64);
647 if(packet64) MDELETES0(packet64);
653 case TAPPSDB_TYPE_UNKNOWN:
661 DRM_TAPPS_EXCEPTION("DTappsStmtBindParam: errno: %d\n", rc);
670 int DTappsStmtExecute (void* pStmt)
672 int CntTryStmtExe=0, rc =-1;
673 sqlite3_stmt* stmt = (sqlite3_stmt*)pStmt;
675 DRM_TAPPS_FRQ_LOG("%s:stmt=0x%x \n",__func__,stmt);
677 TAPPSDbApiLock Dblock;
681 DRM_TAPPS_EXCEPTION("stmt is NULL \n");
688 rc = sqlite3_step(stmt);
690 DRM_TAPPS_FRQ_LOG(" rc=%d \n",rc);
692 if ( rc != SQLITE_DONE )
694 if(rc == SQLITE_BUSY)
697 DRM_TAPPS_FRQ_LOG("Tried [%d] times to execute stmt \n",CntTryStmtExe);
701 if(CntTryStmtExe >= (int)__DTAPPS_DB_SQLITE_RETRY__)
703 DRM_TAPPS_EXCEPTION("stmt=0x%x rc=%d CntTryStmtExe=%d \n",stmt,rc,CntTryStmtExe);
710 DRM_TAPPS_EXCEPTION("stmt=0x%x rc=%d \n",stmt,rc);
717 DRM_TAPPS_FRQ_LOG("STMT EXECUTE SUCCESS CntTryStmtExe=%d \n",CntTryStmtExe);
725 int DTappsStmtRelease (void* pStmt)
728 sqlite3_stmt* stmt = (sqlite3_stmt*)pStmt;
729 DRM_TAPPS_FRQ_LOG("%s:Enter \n",__func__);
730 TAPPSDbApiLock Dblock;
736 rc = sqlite3_finalize (stmt);
738 DRM_TAPPS_FRQ_LOG("rc=%d \n",rc);
740 if ( rc != SQLITE_OK )
742 DRM_TAPPS_EXCEPTION("DTappsStmtRelease() Errmsg ; %d \n", rc);
751 BOOL DTapps_DB_Install(const char* sql_query)
754 BOOL ret_value = FALSE;
756 if(sql_query == NULL)
758 DRM_TAPPS_EXCEPTION("Parameter NULL!!!, sql_query = %p",sql_query);
763 DRM_TAPPS_LOG("Open DB......");
765 ret_value = DTappsDBOpen(pDb,__func__);
767 if(ret_value != TRUE)
769 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d",ret_value);
774 DRM_TAPPS_LOG("Begin Transaction........");
776 ret_value = DTappsDBBeginImmedTrans(__func__);
778 if(ret_value != TRUE)
780 DRM_TAPPS_EXCEPTION("DB Begin Transaction ret_value = %d",ret_value);
785 DRM_TAPPS_LOG("Execute SQL to Insert Contents into Table........");
787 ret_value = DTappsExecuteSQL(pDb,sql_query);
789 if(ret_value != TRUE)
791 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! ret_value = %d",ret_value);
796 DRM_TAPPS_LOG("Commit DB........");
798 ret_value = DTappsDBCommit(__func__);
800 if(ret_value != TRUE)
802 DRM_TAPPS_EXCEPTION("Commit DB Failed!! ret_value = %d",ret_value);
807 DRM_TAPPS_LOG("Close DB........");
809 ret_value = DTappsDBClose(__func__);
811 if(ret_value != TRUE)
813 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d",ret_value);
818 DRM_TAPPS_LOG("Install DB Operartion Successful!!!");
824 ret_value = DTappsDBRollback (__func__);
826 if(ret_value != TRUE)
828 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d",ret_value);
831 ret_value = DTappsDBClose(__func__);
833 if(ret_value != TRUE)
835 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d",ret_value);
841 BOOL DTapps_Read_DB(const char* sql_query, TAPPSSqliteSelectTable* select_table)
844 BOOL ret_value = FALSE;
846 if(sql_query == NULL || select_table == NULL)
848 DRM_TAPPS_EXCEPTION("Parameters NULL, sql_query = %p, select_table = %p",sql_query,select_table);
853 DRM_TAPPS_LOG("Open DB......");
855 ret_value = DTappsDBOpen(pDb,__func__);
857 if(ret_value != TRUE)
859 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d",ret_value);
864 DRM_TAPPS_LOG("Begin Transaction........");
866 ret_value = DTappsDBBeginImmedTrans(__func__);
868 if(ret_value != TRUE)
870 DRM_TAPPS_EXCEPTION("DB Begin Transaction Failed!! ret_value = %d",ret_value);
875 DRM_TAPPS_LOG("Get the Result Table........");
877 ret_value = DTappsSQLGetTable(pDb,sql_query,select_table);
879 if(ret_value != TRUE)
881 DRM_TAPPS_EXCEPTION("DB Get Table failed!! ret_value = %d",ret_value);
886 DRM_TAPPS_LOG("Close DB........");
888 ret_value = DTappsDBClose(__func__);
890 if(ret_value != TRUE)
892 DRM_TAPPS_EXCEPTION("DB Close failed!! ret_value = %d",ret_value);
897 DRM_TAPPS_LOG("Reading from DB Successful!!!");
903 ret_value = DTappsDBRollback (__func__);
905 if(ret_value != TRUE)
907 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d",ret_value);
910 ret_value = DTappsDBClose(__func__);
912 if(ret_value != TRUE)
914 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d",ret_value);
917 DRM_TAPPS_EXCEPTION("Reading DB function failed!!!");