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.
16 * @file DTapps2SqliteDB.cpp
19 #include "DTapps2SqliteDB.h"
24 /* Define EXPORT_API temporary */
26 #define EXPORT_API __attribute__((visibility("default")))
29 static dtapps_mutex_t dtapps_sqlite_db_mutex = PTHREAD_MUTEX_INITIALIZER;
31 typedef long int dtappsThreadID;
33 class DtappsDBConnectionInfo {
35 DtappsDBConnectionInfo();
36 int countOpenConnection;
37 sqlite3 *pDBConnection;
41 static std::map<dtappsThreadID, std::unique_ptr<DtappsDBConnectionInfo>>
42 g_dtapps_sqlite_connection_table;
44 DtappsDBConnectionInfo::DtappsDBConnectionInfo()
46 countOpenConnection = 0;
50 class TAPPSDbApiLock {
56 TAPPSDbApiLock::TAPPSDbApiLock()
58 DRM_TAPPS_FRQ_LOG("LOCK by TID = %ld", drmgettid());
60 if (0 != dtapps_mutex_lock(&dtapps_sqlite_db_mutex))
61 DRM_TAPPS_EXCEPTION("Error while mutex locking.");
64 TAPPSDbApiLock::~TAPPSDbApiLock()
66 DRM_TAPPS_FRQ_LOG("UNLOCK by TID = %ld", drmgettid());
68 if (0 != dtapps_mutex_unlock(&dtapps_sqlite_db_mutex))
69 DRM_TAPPS_EXCEPTION("Error while mutex unlocking");
72 #define __DTAPPS_DB_SQLITE_RETRY__ (10)
74 #define DTAPPS_SQLITE3_SQL_BEGIN_IMMEDIATE "BEGIN IMMEDIATE TRANSACTION"
75 #define DTAPPS_SQLITE3_SQL_COMMIT "COMMIT TRANSACTION"
76 #define DTAPPS_SQLITE3_SQL_ROLLBACK "ROLLBACK TRANSACTION"
78 /* DataBase Related API Wrappers */
79 BOOL DTappsDBOpen(void *&pDb, const char *CallingFun)
81 DRM_TAPPS_LOG("[%s]: started.Calling function = %s", __func__, CallingFun);
83 TAPPSDbApiLock Dblock;
84 dtappsThreadID id_curr_thread = drmgettid();
86 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
88 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
90 if (it != g_dtapps_sqlite_connection_table.end()) {
91 DRM_TAPPS_FRQ_LOG("Connection already exists..");
92 auto &pDBConnectionInfo = it->second;
93 DRM_TAPPS_FRQ_LOG("pDBConnectionInfo=[0x%x]", pDBConnectionInfo.get());
95 if (pDBConnectionInfo == NULL || pDBConnectionInfo->pDBConnection == NULL)
98 DRM_TAPPS_FRQ_LOG("pDBConnectionInfo->countOpenConnection=[%d], "
99 "pDBConnectionInfo->pDBConnection=[0x%x]",
100 pDBConnectionInfo->countOpenConnection,
101 pDBConnectionInfo->pDBConnection);
103 ++(pDBConnectionInfo->countOpenConnection);
104 pDb = pDBConnectionInfo->pDBConnection;
106 DRM_TAPPS_LOG("no connection exists..");
107 std::unique_ptr<DtappsDBConnectionInfo> pDBConnectionInfo;
109 pDBConnectionInfo.reset(new DtappsDBConnectionInfo);
110 } catch (const std::bad_alloc &) {
114 DRM_TAPPS_FRQ_LOG("Opening DB connection.");
116 sqlite3 *h_db = NULL;
117 int result = sqlite3_open(DTAPPS_DB_NAME, &h_db);
119 if (result != SQLITE_OK) {
120 DRM_TAPPS_EXCEPTION("sqlite msg :[%d]%s", result, sqlite3_errmsg(h_db));
121 DRM_TAPPS_SECURE_LOG("db name :%s", DTAPPS_DB_NAME);
125 DRM_TAPPS_FRQ_LOG("sqlite3_open() is success. h_db:%x", h_db);
127 pDBConnectionInfo->countOpenConnection = 1;
128 pDBConnectionInfo->pDBConnection = h_db;
130 pDb = pDBConnectionInfo->pDBConnection;
133 DRM_TAPPS_FRQ_LOG("pDBConnectionInfo->countOpenConnection=[%d], "
134 "pDBConnectionInfo->pDBConnection=[0x%x]",
135 pDBConnectionInfo->countOpenConnection,
136 pDBConnectionInfo->pDBConnection);
138 g_dtapps_sqlite_connection_table.emplace(
139 std::make_pair(id_curr_thread, std::move(pDBConnectionInfo)));
142 DRM_TAPPS_LOG("This fn finishes successfully.");
147 BOOL DTappsDBGet(void *&pDBConnection)
149 DRM_TAPPS_LOG("Inside %s", __func__);
151 TAPPSDbApiLock Dblock;
152 dtappsThreadID id_curr_thread = drmgettid();
153 pDBConnection = NULL;
155 DRM_TAPPS_LOG("id_curr_thread=[%ld]", id_curr_thread);
157 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
159 if (it == g_dtapps_sqlite_connection_table.end() ||
160 it->second == NULL ||
161 it->second->pDBConnection == NULL)
164 auto &pDBConnectionInfo = it->second;
165 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
166 pDBConnectionInfo->countOpenConnection,
167 pDBConnectionInfo->pDBConnection);
169 pDBConnection = pDBConnectionInfo->pDBConnection;
174 BOOL DTappsDBClose(const char *CallingFun)
176 DRM_TAPPS_LOG("Inside %s Calling function = %s", __func__, CallingFun);
178 TAPPSDbApiLock Dblock;
179 dtappsThreadID id_curr_thread = drmgettid();
181 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
183 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
185 if (it == g_dtapps_sqlite_connection_table.end()) {
187 } else if (it->second == NULL || it->second->pDBConnection == NULL) {
188 g_dtapps_sqlite_connection_table.erase(it);
192 auto &pDBConnectionInfo = it->second;
193 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
194 pDBConnectionInfo->countOpenConnection,
195 pDBConnectionInfo->pDBConnection);
197 int countConnection = --(pDBConnectionInfo->countOpenConnection);
199 DRM_TAPPS_LOG(" countConnection=[%d] ", countConnection);
201 if (countConnection != 0)
204 DRM_TAPPS_LOG("closing DB connection info ");
206 sqlite3 *pDBConnection = it->second->pDBConnection;
208 DRM_TAPPS_LOG("finalizing all statements..pDBConnection=[0x%x]", pDBConnection);
209 sqlite3_stmt *pstmt = NULL;
211 while ((pstmt = sqlite3_next_stmt(pDBConnection, pstmt)) != NULL) {
212 DRM_TAPPS_LOG("finalizing DB statement..pstmt=[0x%x]", pstmt);
213 sqlite3_finalize(pstmt);
218 DRM_TAPPS_LOG(" Closing DB connection..pDBConnection=[0x%x]", pDBConnection);
220 if (sqlite3_close(pDBConnection) != SQLITE_OK) {
221 DRM_TAPPS_EXCEPTION("sqlite3_close failed. errmsg:%s",
222 sqlite3_errmsg(pDBConnection));
226 // erase map element regardless sqlite handle resource releasement
227 // because it's not usable anymore.
228 DRM_TAPPS_LOG("erasing map entry..pDBConnection=[0x%x]", pDBConnection);
229 g_dtapps_sqlite_connection_table.erase(it);
234 BOOL DTappsDBBeginImmedTrans(const char *CallingFun)
236 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__, CallingFun);
238 dtappsThreadID id_curr_thread = drmgettid();
240 int count_try_db = 0, rc = -1;
242 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
244 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
246 if (it == g_dtapps_sqlite_connection_table.end())
249 auto &pDBConnectionInfo = it->second;
250 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], DBConnection=[0x%x]",
251 pDBConnectionInfo->countOpenConnection,
252 pDBConnectionInfo->pDBConnection);
254 auto pDBConnection = pDBConnectionInfo->pDBConnection;
256 DRM_TAPPS_LOG("Beginning DB operations..pDBConnection=[0x%x]", pDBConnection);
259 DRM_TAPPS_LOG("START BEGIN");
260 rc = sqlite3_exec(pDBConnection, DTAPPS_SQLITE3_SQL_BEGIN_IMMEDIATE, NULL, NULL,
263 DRM_TAPPS_FRQ_LOG("START BEGIN rc=%d", rc);
265 if (rc != SQLITE_OK) {
266 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc,
267 sqlite3_errmsg(pDBConnection));
269 if (rc == SQLITE_BUSY) {
271 DRM_TAPPS_FRQ_LOG("Tried [%d] times to begin", count_try_db);
274 if (count_try_db >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
275 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
277 sqlite3_errmsg(pDBConnection));
281 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
283 sqlite3_errmsg(pDBConnection));
287 DRM_TAPPS_LOG("begin SUCCESS count_try_db=%d", count_try_db);
292 DRM_TAPPS_LOG("This fn finishes successfully..pDBConnection=[0x%x]",
298 DRM_TAPPS_EXCEPTION("This fn fails.. pDBConnection=[0x%x]", pDBConnection);
302 BOOL DTappsDBCommit(const char *CallingFun)
304 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__, CallingFun);
305 dtappsThreadID id_curr_thread = drmgettid();
307 int count_try_db_commit = 0, rc = -1;
309 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
311 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
313 if (it == g_dtapps_sqlite_connection_table.end())
316 auto &pDBConnectionInfo = it->second;
317 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
318 pDBConnectionInfo->countOpenConnection,
319 pDBConnectionInfo->pDBConnection);
321 auto pDBConnection = pDBConnectionInfo->pDBConnection;
323 DRM_TAPPS_LOG("Commiting DB operations..pDBConnection=[0x%x]", pDBConnection);
326 DRM_TAPPS_FRQ_LOG("START Commit");
327 rc = sqlite3_exec(pDBConnection, DTAPPS_SQLITE3_SQL_COMMIT, NULL, NULL, NULL);
328 DRM_TAPPS_FRQ_LOG("START Commit rc=%d", rc);
330 if (rc != SQLITE_OK) {
331 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc,
332 sqlite3_errmsg(pDBConnection));
334 if (rc == SQLITE_BUSY) {
336 DRM_TAPPS_FRQ_LOG("Tried [%d] times to Commit", count_try_db_commit);
337 count_try_db_commit++;
339 if (count_try_db_commit >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
340 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
342 sqlite3_errmsg(pDBConnection));
346 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
348 sqlite3_errmsg(pDBConnection));
352 DRM_TAPPS_FRQ_LOG("Commit SUCCESS count_try_db_commit=%d",
353 count_try_db_commit);
358 DRM_TAPPS_LOG("Finishes successfully..pDBConnection=[0x%x]", pDBConnection);
363 DRM_TAPPS_EXCEPTION("Fails.. pDBConnection=[0x%x]", pDBConnection);
368 BOOL DTappsDBRollback(const char *CallingFun)
370 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__, CallingFun);
372 dtappsThreadID id_curr_thread = drmgettid();
374 int count_try_db_rollback = 0, rc = -1;
376 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
378 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
380 if (it == g_dtapps_sqlite_connection_table.end())
383 auto &pDBConnectionInfo = it->second;
384 DRM_TAPPS_SECURE_LOG("[%s] countOpenConnection=[%d], pDBConnection=[0x%x]",
385 __func__, pDBConnectionInfo->countOpenConnection,
386 pDBConnectionInfo->pDBConnection);
388 auto pDBConnection = pDBConnectionInfo->pDBConnection;
390 DRM_TAPPS_LOG("Rollback DB operations..pDBConnection=[0x%x]", pDBConnection);
393 DRM_TAPPS_FRQ_LOG("START Rollback");
394 rc = sqlite3_exec(pDBConnection, DTAPPS_SQLITE3_SQL_ROLLBACK, NULL, NULL, NULL);
395 DRM_TAPPS_FRQ_LOG("START Rollback rc=%d", rc);
397 if (rc != SQLITE_OK) {
398 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc,
399 sqlite3_errmsg(pDBConnection));
401 if (rc == SQLITE_BUSY) {
403 DRM_TAPPS_FRQ_LOG("Tried [%d] times to Rollback", count_try_db_rollback);
404 count_try_db_rollback++;
406 if (count_try_db_rollback >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
407 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
409 sqlite3_errmsg(pDBConnection));
413 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
415 sqlite3_errmsg(pDBConnection));
419 DRM_TAPPS_FRQ_LOG("Rollback SUCCESS count_try_db_rollback=%d",
420 count_try_db_rollback);
425 DRM_TAPPS_LOG("This fn finishes successfully..pDBConnection=[0x%x]",
431 DRM_TAPPS_EXCEPTION("This fn fails.. pDBConnection=[0x%x]", pDBConnection);
437 BOOL DTappsExecuteSQL(void *pDB, const char *query)
439 int count_try_db_exe = 0, rc = 0;
440 sqlite3 *h_db = (sqlite3 *)pDB;
442 TAPPSDbApiLock Dblock;
445 rc = sqlite3_exec(h_db, query, NULL, NULL, NULL);
446 DRM_TAPPS_FRQ_LOG("EXECUTE rc=%d", rc);
448 if (rc != SQLITE_OK) {
449 if (rc == SQLITE_BUSY) {
451 DRM_TAPPS_FRQ_LOG("Tried [%d] times to execute", count_try_db_exe);
454 if (count_try_db_exe >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
455 DRM_TAPPS_EXCEPTION("h_db=0x%x rc=%d ErrMsg:%s count_try_db_exe=%d",
456 h_db, rc, sqlite3_errmsg(h_db), count_try_db_exe);
457 DRM_TAPPS_EXCEPTION("query=[%s]", query);
461 DRM_TAPPS_EXCEPTION("h_db=0x%x rc=%d ErrMsg:%s", h_db, rc,
462 sqlite3_errmsg(h_db));
463 DRM_TAPPS_EXCEPTION("query=[%s]", query);
467 DRM_TAPPS_FRQ_LOG("EXECUTE SUCCESS count_try_db_exe=%d", count_try_db_exe);
476 BOOL DTappsSQLGetTable(void *pDB, const char *query,
477 TAPPSSqliteSelectTable *select_table)
480 sqlite3 *h_db = (sqlite3 *)pDB;
482 DRM_TAPPS_FRQ_LOG("h_db=0x%x query=%s", h_db, query);
483 TAPPSDbApiLock Dblock;
484 select_table->handle = h_db;
486 DRM_TAPPS_FRQ_LOG("select_table->handle=%x", select_table->handle);
488 int count_try_db_select = 0;
491 rc = sqlite3_get_table(h_db, query, &select_table->result,
492 &select_table->n_rows, &select_table->n_cols, NULL);
494 DRM_TAPPS_FRQ_LOG("SELECT rc=%d", rc);
496 if (rc != SQLITE_OK) {
497 if (rc == SQLITE_BUSY) {
499 DRM_TAPPS_FRQ_LOG("SELECT Tried [%d] times to select",
500 count_try_db_select);
502 count_try_db_select++;
504 if (count_try_db_select >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
505 DRM_TAPPS_EXCEPTION("SELECT h_db=0x%x rc=%d ErrMsg:%s "
506 "count_try_db_select=%d",
507 h_db, rc, sqlite3_errmsg(h_db),
508 count_try_db_select);
509 DRM_TAPPS_EXCEPTION("query=[%s]", query);
514 DRM_TAPPS_EXCEPTION("SELECT h_db=0x%x rc=%d ErrMsg:%s", h_db, rc,
515 sqlite3_errmsg(h_db));
516 DRM_TAPPS_EXCEPTION("query=[%s]", query);
521 DRM_TAPPS_FRQ_LOG("SELECT SUCCESS count_try_db_select=%d",
522 count_try_db_select);
527 DRM_TAPPS_FRQ_LOG("n_rows=%d n_cols=%d", select_table->n_rows,
528 select_table->n_cols);
533 extern const char *dtappsCreateTableSQLData[];
535 char *DTappsGetSQLCreateTable(const char *tableName)
542 DRM_TAPPS_FRQ_LOG("tableName = %s", tableName);
544 while (dtappsCreateTableSQLData[index]) {
545 if (TAPPS_strnicmp(dtappsCreateTableSQLData[index], tableName,
546 TAPPS_STRLEN(tableName)) == 0) {
547 char *sql = (char *)dtappsCreateTableSQLData[index];
548 sql = sql + TAPPS_STRLEN(dtappsCreateTableSQLData[index]) + 1;
550 DRM_TAPPS_FRQ_LOG("sql query = %s", sql);
558 DRM_TAPPS_EXCEPTION("Specified Table Name is not Valid!!!");
563 void *DTappsStmtPrepare(void *pDB, const char *query)
566 sqlite3 *h_db = (sqlite3 *)pDB;
567 sqlite3_stmt *stmt = 0;
569 DRM_TAPPS_FRQ_LOG("h_db=0x%x query=%s", h_db, query);
571 TAPPSDbApiLock Dblock;
573 if (0 == TAPPS_strnicmp(query, "SELECT", 6)) {
574 DRM_TAPPS_EXCEPTION("Doesn't support 'Select' query h_db=0x%x query=%s",
579 rc = sqlite3_prepare(h_db, query, -1, &stmt, NULL);
581 DRM_TAPPS_FRQ_LOG("%s: rc=%d query=%s stmt=0x%x", __func__, rc, query, stmt);
583 if (rc != SQLITE_OK) {
584 DRM_TAPPS_EXCEPTION("DTappsStmtPrepare: h_db=0x%x err: %s", h_db,
585 sqlite3_errmsg(h_db));
586 DRM_TAPPS_EXCEPTION("DTappsStmtPrepare: query: %s", query);
594 int DTappsStmtBindParam(void *pStmt, unsigned int dIdx, unsigned int Type,
595 void *pParam, unsigned int dParamSize)
598 sqlite3_stmt *stmt = (sqlite3_stmt *)pStmt;
600 DRM_TAPPS_FRQ_LOG("Enter");
602 TAPPSDbApiLock Dblock;
605 DRM_TAPPS_EXCEPTION("DTappsStmtBindParam: stmt is NULL");
611 * 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", rc, Type, *(int *)pParam);
625 case TAPPSDB_TYPE_DATETIME:
626 case TAPPSDB_TYPE_CHAR:
627 case TAPPSDB_TYPE_VARCHAR:
628 rc = sqlite3_bind_text(stmt, dIdx + 1, (char *)pParam, dParamSize,
630 DRM_TAPPS_FRQ_LOG("rc=%d type=%d dParamSize=%d pParam=%s", rc, Type,
635 case TAPPSDB_TYPE_BINARY:
636 case TAPPSDB_TYPE_BLOB:
639 char *packet64 = NULL;
640 unsigned int packet64_size = 0;
642 if (CMStringUtil::GetBase64Encode((unsigned char *)pParam, dParamSize,
643 &packet64) == true) {
644 packet64_size = MSTRLEN(packet64);
645 rc = sqlite3_bind_blob(stmt, dIdx + 1, packet64, packet64_size,
647 DRM_OMA_FRQ_LOG("%s: rc=%d type=%d packet64_size=%d packet64=%s \n", __func__,
648 rc, Type, packet64_size, packet64);
650 if (packet64) MDELETES0(packet64);
657 case TAPPSDB_TYPE_UNKNOWN:
662 if (rc != SQLITE_OK) {
663 DRM_TAPPS_EXCEPTION("DTappsStmtBindParam: errno: %d", rc);
671 int DTappsStmtExecute(void *pStmt)
673 int CntTryStmtExe = 0, rc = -1;
674 sqlite3_stmt *stmt = (sqlite3_stmt *)pStmt;
676 DRM_TAPPS_FRQ_LOG("%s:stmt=0x%x", __func__, stmt);
678 TAPPSDbApiLock Dblock;
681 DRM_TAPPS_EXCEPTION("stmt is NULL");
686 rc = sqlite3_step(stmt);
688 DRM_TAPPS_FRQ_LOG("rc=%d", rc);
690 if (rc != SQLITE_DONE) {
691 if (rc == SQLITE_BUSY) {
693 DRM_TAPPS_FRQ_LOG("Tried [%d] times to execute stmt", CntTryStmtExe);
697 if (CntTryStmtExe >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
698 DRM_TAPPS_EXCEPTION("stmt=0x%x rc=%d CntTryStmtExe=%d", stmt, rc,
703 DRM_TAPPS_EXCEPTION("stmt=0x%x rc=%d", stmt, rc);
707 DRM_TAPPS_FRQ_LOG("STMT EXECUTE SUCCESS CntTryStmtExe=%d", CntTryStmtExe);
713 int DTappsStmtRelease(void *pStmt)
716 sqlite3_stmt *stmt = (sqlite3_stmt *)pStmt;
717 DRM_TAPPS_FRQ_LOG("%s:Enter", __func__);
718 TAPPSDbApiLock Dblock;
723 rc = sqlite3_finalize(stmt);
725 DRM_TAPPS_FRQ_LOG("rc=%d", rc);
727 if (rc != SQLITE_OK) {
728 DRM_TAPPS_EXCEPTION("DTappsStmtRelease() Errmsg : %d", rc);
736 BOOL DTapps_DB_Install(const char *sql_query)
739 BOOL ret_value = FALSE;
741 if (sql_query == NULL) {
742 DRM_TAPPS_EXCEPTION("Parameter NULL!!!, sql_query = %p", sql_query);
746 DRM_TAPPS_LOG("Open DB......");
748 ret_value = DTappsDBOpen(pDb, __func__);
750 if (ret_value != TRUE) {
751 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
755 DRM_TAPPS_LOG("Begin Transaction........");
757 ret_value = DTappsDBBeginImmedTrans(__func__);
759 if (ret_value != TRUE) {
760 DRM_TAPPS_EXCEPTION("DB Begin Transaction ret_value = %d", ret_value);
764 DRM_TAPPS_LOG("Execute SQL to Insert Contents into Table........");
766 ret_value = DTappsExecuteSQL(pDb, sql_query);
768 if (ret_value != TRUE) {
769 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! ret_value = %d", ret_value);
773 DRM_TAPPS_LOG("Commit DB........");
775 ret_value = DTappsDBCommit(__func__);
777 if (ret_value != TRUE) {
778 DRM_TAPPS_EXCEPTION("Commit DB Failed!! ret_value = %d", ret_value);
782 DRM_TAPPS_LOG("Close DB........");
784 ret_value = DTappsDBClose(__func__);
786 if (ret_value != TRUE) {
787 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
791 DRM_TAPPS_LOG("Install DB Operartion Successful!!!");
797 ret_value = DTappsDBRollback(__func__);
799 if (ret_value != TRUE)
800 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d", ret_value);
802 ret_value = DTappsDBClose(__func__);
804 if (ret_value != TRUE)
805 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
810 BOOL DTapps_Read_DB(const char *sql_query, TAPPSSqliteSelectTable *select_table)
813 BOOL ret_value = FALSE;
815 if (sql_query == NULL || select_table == NULL) {
816 DRM_TAPPS_EXCEPTION("Parameters NULL, sql_query = %p, select_table = %p",
817 sql_query, select_table);
821 DRM_TAPPS_LOG("Open DB......");
823 ret_value = DTappsDBOpen(pDb, __func__);
825 if (ret_value != TRUE) {
826 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
830 DRM_TAPPS_LOG("Begin Transaction........");
832 ret_value = DTappsDBBeginImmedTrans(__func__);
834 if (ret_value != TRUE) {
835 DRM_TAPPS_EXCEPTION("DB Begin Transaction Failed!! ret_value = %d", ret_value);
839 DRM_TAPPS_LOG("Get the Result Table........");
841 ret_value = DTappsSQLGetTable(pDb, sql_query, select_table);
843 if (ret_value != TRUE) {
844 DRM_TAPPS_EXCEPTION("DB Get Table failed!! ret_value = %d", ret_value);
848 DRM_TAPPS_LOG("Close DB........");
850 ret_value = DTappsDBClose(__func__);
852 if (ret_value != TRUE) {
853 DRM_TAPPS_EXCEPTION("DB Close failed!! ret_value = %d", ret_value);
857 DRM_TAPPS_LOG("Reading from DB Successful!!!");
863 ret_value = DTappsDBRollback(__func__);
865 if (ret_value != TRUE)
866 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d", ret_value);
868 ret_value = DTappsDBClose(__func__);
870 if (ret_value != TRUE)
871 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
873 DRM_TAPPS_EXCEPTION("Reading DB function failed!!!");