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(
108 new(std::nothrow) DtappsDBConnectionInfo);
110 if (pDBConnectionInfo == NULL)
113 DRM_TAPPS_FRQ_LOG("Opening DB connection.");
115 sqlite3 *h_db = NULL;
116 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], "
133 "pDBConnectionInfo->pDBConnection=[0x%x]",
134 pDBConnectionInfo->countOpenConnection,
135 pDBConnectionInfo->pDBConnection);
137 g_dtapps_sqlite_connection_table.emplace(
138 std::make_pair(id_curr_thread, std::move(pDBConnectionInfo)));
141 DRM_TAPPS_LOG("This fn finishes successfully.");
146 BOOL DTappsDBGet(void *&pDBConnection)
148 DRM_TAPPS_LOG("Inside %s", __func__);
150 TAPPSDbApiLock Dblock;
151 dtappsThreadID id_curr_thread = drmgettid();
152 pDBConnection = NULL;
154 DRM_TAPPS_LOG("id_curr_thread=[%ld]", id_curr_thread);
156 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
158 if (it == g_dtapps_sqlite_connection_table.end() ||
159 it->second == NULL ||
160 it->second->pDBConnection == NULL)
163 auto &pDBConnectionInfo = it->second;
164 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
165 pDBConnectionInfo->countOpenConnection,
166 pDBConnectionInfo->pDBConnection);
168 pDBConnection = pDBConnectionInfo->pDBConnection;
173 BOOL DTappsDBClose(const char *CallingFun)
175 DRM_TAPPS_LOG("Inside %s Calling function = %s", __func__, CallingFun);
177 TAPPSDbApiLock Dblock;
178 dtappsThreadID id_curr_thread = drmgettid();
180 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
182 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
184 if (it == g_dtapps_sqlite_connection_table.end()) {
186 } else if (it->second == NULL || it->second->pDBConnection == NULL) {
187 g_dtapps_sqlite_connection_table.erase(it);
191 auto &pDBConnectionInfo = it->second;
192 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
193 pDBConnectionInfo->countOpenConnection,
194 pDBConnectionInfo->pDBConnection);
196 int countConnection = --(pDBConnectionInfo->countOpenConnection);
198 DRM_TAPPS_LOG(" countConnection=[%d] ", countConnection);
200 if (countConnection != 0)
203 DRM_TAPPS_LOG("closing DB connection info ");
205 sqlite3 *pDBConnection = it->second->pDBConnection;
207 DRM_TAPPS_LOG("finalizing all statements..pDBConnection=[0x%x]", pDBConnection);
208 sqlite3_stmt *pstmt = NULL;
210 while ((pstmt = sqlite3_next_stmt(pDBConnection, pstmt)) != NULL) {
211 DRM_TAPPS_LOG("finalizing DB statement..pstmt=[0x%x]", pstmt);
212 sqlite3_finalize(pstmt);
217 DRM_TAPPS_LOG(" Closing DB connection..pDBConnection=[0x%x]", pDBConnection);
219 if (db_util_close(pDBConnection) != SQLITE_OK) {
220 DRM_TAPPS_EXCEPTION("db_util_close failed. errmsg:%s",
221 sqlite3_errmsg(pDBConnection));
225 // erase map element regardless sqlite handle resource releasement
226 // because it's not usable anymore.
227 DRM_TAPPS_LOG("erasing map entry..pDBConnection=[0x%x]", pDBConnection);
228 g_dtapps_sqlite_connection_table.erase(it);
233 BOOL DTappsDBBeginImmedTrans(const char *CallingFun)
235 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__, CallingFun);
237 dtappsThreadID id_curr_thread = drmgettid();
239 int count_try_db = 0, rc = -1;
241 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
243 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
245 if (it == g_dtapps_sqlite_connection_table.end())
248 auto &pDBConnectionInfo = it->second;
249 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], DBConnection=[0x%x]",
250 pDBConnectionInfo->countOpenConnection,
251 pDBConnectionInfo->pDBConnection);
253 auto pDBConnection = pDBConnectionInfo->pDBConnection;
255 DRM_TAPPS_LOG("Beginning DB operations..pDBConnection=[0x%x]", pDBConnection);
258 DRM_TAPPS_LOG("START BEGIN");
259 rc = sqlite3_exec(pDBConnection, DTAPPS_SQLITE3_SQL_BEGIN_IMMEDIATE, NULL, NULL,
262 DRM_TAPPS_FRQ_LOG("START BEGIN rc=%d", rc);
264 if (rc != SQLITE_OK) {
265 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc,
266 sqlite3_errmsg(pDBConnection));
268 if (rc == SQLITE_BUSY) {
270 DRM_TAPPS_FRQ_LOG("Tried [%d] times to begin", count_try_db);
273 if (count_try_db >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
274 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
276 sqlite3_errmsg(pDBConnection));
280 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
282 sqlite3_errmsg(pDBConnection));
286 DRM_TAPPS_LOG("begin SUCCESS count_try_db=%d", count_try_db);
291 DRM_TAPPS_LOG("This fn finishes successfully..pDBConnection=[0x%x]",
297 DRM_TAPPS_EXCEPTION("This fn fails.. pDBConnection=[0x%x]", pDBConnection);
301 BOOL DTappsDBCommit(const char *CallingFun)
303 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__, CallingFun);
304 dtappsThreadID id_curr_thread = drmgettid();
306 int count_try_db_commit = 0, rc = -1;
308 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
310 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
312 if (it == g_dtapps_sqlite_connection_table.end())
315 auto &pDBConnectionInfo = it->second;
316 DRM_TAPPS_FRQ_LOG("countOpenConnection=[%d], pDBConnection=[0x%x]",
317 pDBConnectionInfo->countOpenConnection,
318 pDBConnectionInfo->pDBConnection);
320 auto pDBConnection = pDBConnectionInfo->pDBConnection;
322 DRM_TAPPS_LOG("Commiting DB operations..pDBConnection=[0x%x]", pDBConnection);
325 DRM_TAPPS_FRQ_LOG("START Commit");
326 rc = sqlite3_exec(pDBConnection, DTAPPS_SQLITE3_SQL_COMMIT, NULL, NULL, NULL);
327 DRM_TAPPS_FRQ_LOG("START Commit rc=%d", rc);
329 if (rc != SQLITE_OK) {
330 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc,
331 sqlite3_errmsg(pDBConnection));
333 if (rc == SQLITE_BUSY) {
335 DRM_TAPPS_FRQ_LOG("Tried [%d] times to Commit", count_try_db_commit);
336 count_try_db_commit++;
338 if (count_try_db_commit >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
339 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
341 sqlite3_errmsg(pDBConnection));
345 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
347 sqlite3_errmsg(pDBConnection));
351 DRM_TAPPS_FRQ_LOG("Commit SUCCESS count_try_db_commit=%d",
352 count_try_db_commit);
357 DRM_TAPPS_LOG("Finishes successfully..pDBConnection=[0x%x]", pDBConnection);
362 DRM_TAPPS_EXCEPTION("Fails.. pDBConnection=[0x%x]", pDBConnection);
367 BOOL DTappsDBRollback(const char *CallingFun)
369 DRM_TAPPS_LOG("Inside %s, Calling function = %s", __func__, CallingFun);
371 dtappsThreadID id_curr_thread = drmgettid();
373 int count_try_db_rollback = 0, rc = -1;
375 DRM_TAPPS_SECURE_LOG("id_curr_thread=[%ld]", id_curr_thread);
377 auto it = g_dtapps_sqlite_connection_table.find(id_curr_thread);
379 if (it == g_dtapps_sqlite_connection_table.end())
382 auto &pDBConnectionInfo = it->second;
383 DRM_TAPPS_SECURE_LOG("[%s] countOpenConnection=[%d], pDBConnection=[0x%x]",
384 __func__, pDBConnectionInfo->countOpenConnection,
385 pDBConnectionInfo->pDBConnection);
387 auto pDBConnection = pDBConnectionInfo->pDBConnection;
389 DRM_TAPPS_LOG("Rollback DB operations..pDBConnection=[0x%x]", pDBConnection);
392 DRM_TAPPS_FRQ_LOG("START Rollback");
393 rc = sqlite3_exec(pDBConnection, DTAPPS_SQLITE3_SQL_ROLLBACK, NULL, NULL, NULL);
394 DRM_TAPPS_FRQ_LOG("START Rollback rc=%d", rc);
396 if (rc != SQLITE_OK) {
397 DRM_TAPPS_FRQ_LOG("pDBConnection=0x%x rc=%d ErrMsg:%s", pDBConnection, rc,
398 sqlite3_errmsg(pDBConnection));
400 if (rc == SQLITE_BUSY) {
402 DRM_TAPPS_FRQ_LOG("Tried [%d] times to Rollback", count_try_db_rollback);
403 count_try_db_rollback++;
405 if (count_try_db_rollback >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
406 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
408 sqlite3_errmsg(pDBConnection));
412 DRM_TAPPS_EXCEPTION("Error pDBConnection=0x%x rc=%d ErrMsg:%s",
414 sqlite3_errmsg(pDBConnection));
418 DRM_TAPPS_FRQ_LOG("Rollback SUCCESS count_try_db_rollback=%d",
419 count_try_db_rollback);
424 DRM_TAPPS_LOG("This fn finishes successfully..pDBConnection=[0x%x]",
430 DRM_TAPPS_EXCEPTION("This fn fails.. pDBConnection=[0x%x]", pDBConnection);
436 BOOL DTappsExecuteSQL(void *pDB, const char *query)
438 int count_try_db_exe = 0, rc = 0;
439 sqlite3 *h_db = (sqlite3 *)pDB;
441 TAPPSDbApiLock Dblock;
444 rc = sqlite3_exec(h_db, query, NULL, NULL, NULL);
445 DRM_TAPPS_FRQ_LOG("EXECUTE rc=%d", rc);
447 if (rc != SQLITE_OK) {
448 if (rc == SQLITE_BUSY) {
450 DRM_TAPPS_FRQ_LOG("Tried [%d] times to execute", count_try_db_exe);
453 if (count_try_db_exe >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
454 DRM_TAPPS_EXCEPTION("h_db=0x%x rc=%d ErrMsg:%s count_try_db_exe=%d",
455 h_db, rc, sqlite3_errmsg(h_db), count_try_db_exe);
456 DRM_TAPPS_EXCEPTION("query=[%s]", query);
460 DRM_TAPPS_EXCEPTION("h_db=0x%x rc=%d ErrMsg:%s", h_db, rc,
461 sqlite3_errmsg(h_db));
462 DRM_TAPPS_EXCEPTION("query=[%s]", query);
466 DRM_TAPPS_FRQ_LOG("EXECUTE SUCCESS count_try_db_exe=%d", count_try_db_exe);
475 BOOL DTappsSQLGetTable(void *pDB, const char *query,
476 TAPPSSqliteSelectTable *select_table)
479 sqlite3 *h_db = (sqlite3 *)pDB;
481 DRM_TAPPS_FRQ_LOG("h_db=0x%x query=%s", h_db, query);
482 TAPPSDbApiLock Dblock;
483 select_table->handle = h_db;
485 DRM_TAPPS_FRQ_LOG("select_table->handle=%x", select_table->handle);
487 int count_try_db_select = 0;
490 rc = sqlite3_get_table(h_db, query, &select_table->result,
491 &select_table->n_rows, &select_table->n_cols, NULL);
493 DRM_TAPPS_FRQ_LOG("SELECT rc=%d", rc);
495 if (rc != SQLITE_OK) {
496 if (rc == SQLITE_BUSY) {
498 DRM_TAPPS_FRQ_LOG("SELECT Tried [%d] times to select",
499 count_try_db_select);
501 count_try_db_select++;
503 if (count_try_db_select >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
504 DRM_TAPPS_EXCEPTION("SELECT h_db=0x%x rc=%d ErrMsg:%s "
505 "count_try_db_select=%d",
506 h_db, rc, sqlite3_errmsg(h_db),
507 count_try_db_select);
508 DRM_TAPPS_EXCEPTION("query=[%s]", query);
513 DRM_TAPPS_EXCEPTION("SELECT h_db=0x%x rc=%d ErrMsg:%s", h_db, rc,
514 sqlite3_errmsg(h_db));
515 DRM_TAPPS_EXCEPTION("query=[%s]", query);
520 DRM_TAPPS_FRQ_LOG("SELECT SUCCESS count_try_db_select=%d",
521 count_try_db_select);
526 DRM_TAPPS_FRQ_LOG("n_rows=%d n_cols=%d", select_table->n_rows,
527 select_table->n_cols);
532 extern const char *dtappsCreateTableSQLData[];
534 char *DTappsGetSQLCreateTable(const char *tableName)
541 DRM_TAPPS_FRQ_LOG("tableName = %s", tableName);
543 while (dtappsCreateTableSQLData[index]) {
544 if (TAPPS_strnicmp(dtappsCreateTableSQLData[index], tableName,
545 TAPPS_STRLEN(tableName)) == 0) {
546 char *sql = (char *)dtappsCreateTableSQLData[index];
547 sql = sql + TAPPS_STRLEN(dtappsCreateTableSQLData[index]) + 1;
549 DRM_TAPPS_FRQ_LOG("sql query = %s", sql);
557 DRM_TAPPS_EXCEPTION("Specified Table Name is not Valid!!!");
562 void *DTappsStmtPrepare(void *pDB, const char *query)
565 sqlite3 *h_db = (sqlite3 *)pDB;
566 sqlite3_stmt *stmt = 0;
568 DRM_TAPPS_FRQ_LOG("h_db=0x%x query=%s", h_db, query);
570 TAPPSDbApiLock Dblock;
572 if (0 == TAPPS_strnicmp(query, "SELECT", 6)) {
573 DRM_TAPPS_EXCEPTION("Doesn't support 'Select' query h_db=0x%x query=%s",
578 rc = sqlite3_prepare(h_db, query, -1, &stmt, NULL);
580 DRM_TAPPS_FRQ_LOG("%s: rc=%d query=%s stmt=0x%x", __func__, rc, query, stmt);
582 if (rc != SQLITE_OK) {
583 DRM_TAPPS_EXCEPTION("DTappsStmtPrepare: h_db=0x%x err: %s", h_db,
584 sqlite3_errmsg(h_db));
585 DRM_TAPPS_EXCEPTION("DTappsStmtPrepare: query: %s", query);
593 int DTappsStmtBindParam(void *pStmt, unsigned int dIdx, unsigned int Type,
594 void *pParam, unsigned int dParamSize)
597 sqlite3_stmt *stmt = (sqlite3_stmt *)pStmt;
599 DRM_TAPPS_FRQ_LOG("Enter");
601 TAPPSDbApiLock Dblock;
604 DRM_TAPPS_EXCEPTION("DTappsStmtBindParam: stmt is NULL");
610 * The parameter index in SQL starts from 1 in sqlite3.
613 case TAPPSDB_TYPE_NONE:
614 rc = sqlite3_bind_null(stmt, dIdx + 1);
618 case TAPPSDB_TYPE_INT:
619 rc = sqlite3_bind_int(stmt, dIdx + 1, *(int *)pParam);
620 DRM_TAPPS_FRQ_LOG("rc=%d type=%d pParam=%d", rc, Type, *(int *)pParam);
624 case TAPPSDB_TYPE_DATETIME:
625 case TAPPSDB_TYPE_CHAR:
626 case TAPPSDB_TYPE_VARCHAR:
627 rc = sqlite3_bind_text(stmt, dIdx + 1, (char *)pParam, dParamSize,
629 DRM_TAPPS_FRQ_LOG("rc=%d type=%d dParamSize=%d pParam=%s", rc, Type,
634 case TAPPSDB_TYPE_BINARY:
635 case TAPPSDB_TYPE_BLOB:
638 char *packet64 = NULL;
639 unsigned int packet64_size = 0;
641 if (CMStringUtil::GetBase64Encode((unsigned char *)pParam, dParamSize,
642 &packet64) == true) {
643 packet64_size = MSTRLEN(packet64);
644 rc = sqlite3_bind_blob(stmt, dIdx + 1, packet64, packet64_size,
646 DRM_OMA_FRQ_LOG("%s: rc=%d type=%d packet64_size=%d packet64=%s \n", __func__,
647 rc, Type, packet64_size, packet64);
649 if (packet64) MDELETES0(packet64);
656 case TAPPSDB_TYPE_UNKNOWN:
661 if (rc != SQLITE_OK) {
662 DRM_TAPPS_EXCEPTION("DTappsStmtBindParam: errno: %d", 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", __func__, stmt);
677 TAPPSDbApiLock Dblock;
680 DRM_TAPPS_EXCEPTION("stmt is NULL");
685 rc = sqlite3_step(stmt);
687 DRM_TAPPS_FRQ_LOG("rc=%d", rc);
689 if (rc != SQLITE_DONE) {
690 if (rc == SQLITE_BUSY) {
692 DRM_TAPPS_FRQ_LOG("Tried [%d] times to execute stmt", CntTryStmtExe);
696 if (CntTryStmtExe >= (int)__DTAPPS_DB_SQLITE_RETRY__) {
697 DRM_TAPPS_EXCEPTION("stmt=0x%x rc=%d CntTryStmtExe=%d", stmt, rc,
702 DRM_TAPPS_EXCEPTION("stmt=0x%x rc=%d", stmt, rc);
706 DRM_TAPPS_FRQ_LOG("STMT EXECUTE SUCCESS CntTryStmtExe=%d", CntTryStmtExe);
712 int DTappsStmtRelease(void *pStmt)
715 sqlite3_stmt *stmt = (sqlite3_stmt *)pStmt;
716 DRM_TAPPS_FRQ_LOG("%s:Enter", __func__);
717 TAPPSDbApiLock Dblock;
722 rc = sqlite3_finalize(stmt);
724 DRM_TAPPS_FRQ_LOG("rc=%d", rc);
726 if (rc != SQLITE_OK) {
727 DRM_TAPPS_EXCEPTION("DTappsStmtRelease() Errmsg : %d", rc);
735 BOOL DTapps_DB_Install(const char *sql_query)
738 BOOL ret_value = FALSE;
740 if (sql_query == NULL) {
741 DRM_TAPPS_EXCEPTION("Parameter NULL!!!, sql_query = %p", sql_query);
745 DRM_TAPPS_LOG("Open DB......");
747 ret_value = DTappsDBOpen(pDb, __func__);
749 if (ret_value != TRUE) {
750 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
754 DRM_TAPPS_LOG("Begin Transaction........");
756 ret_value = DTappsDBBeginImmedTrans(__func__);
758 if (ret_value != TRUE) {
759 DRM_TAPPS_EXCEPTION("DB Begin Transaction ret_value = %d", ret_value);
763 DRM_TAPPS_LOG("Execute SQL to Insert Contents into Table........");
765 ret_value = DTappsExecuteSQL(pDb, sql_query);
767 if (ret_value != TRUE) {
768 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! ret_value = %d", ret_value);
772 DRM_TAPPS_LOG("Commit DB........");
774 ret_value = DTappsDBCommit(__func__);
776 if (ret_value != TRUE) {
777 DRM_TAPPS_EXCEPTION("Commit DB Failed!! ret_value = %d", ret_value);
781 DRM_TAPPS_LOG("Close DB........");
783 ret_value = DTappsDBClose(__func__);
785 if (ret_value != TRUE) {
786 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
790 DRM_TAPPS_LOG("Install DB Operartion Successful!!!");
796 ret_value = DTappsDBRollback(__func__);
798 if (ret_value != TRUE)
799 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d", ret_value);
801 ret_value = DTappsDBClose(__func__);
803 if (ret_value != TRUE)
804 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
809 BOOL DTapps_Read_DB(const char *sql_query, TAPPSSqliteSelectTable *select_table)
812 BOOL ret_value = FALSE;
814 if (sql_query == NULL || select_table == NULL) {
815 DRM_TAPPS_EXCEPTION("Parameters NULL, sql_query = %p, select_table = %p",
816 sql_query, select_table);
820 DRM_TAPPS_LOG("Open DB......");
822 ret_value = DTappsDBOpen(pDb, __func__);
824 if (ret_value != TRUE) {
825 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
829 DRM_TAPPS_LOG("Begin Transaction........");
831 ret_value = DTappsDBBeginImmedTrans(__func__);
833 if (ret_value != TRUE) {
834 DRM_TAPPS_EXCEPTION("DB Begin Transaction Failed!! ret_value = %d", ret_value);
838 DRM_TAPPS_LOG("Get the Result Table........");
840 ret_value = DTappsSQLGetTable(pDb, sql_query, select_table);
842 if (ret_value != TRUE) {
843 DRM_TAPPS_EXCEPTION("DB Get Table failed!! ret_value = %d", ret_value);
847 DRM_TAPPS_LOG("Close DB........");
849 ret_value = DTappsDBClose(__func__);
851 if (ret_value != TRUE) {
852 DRM_TAPPS_EXCEPTION("DB Close failed!! ret_value = %d", ret_value);
856 DRM_TAPPS_LOG("Reading from DB Successful!!!");
862 ret_value = DTappsDBRollback(__func__);
864 if (ret_value != TRUE)
865 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d", ret_value);
867 ret_value = DTappsDBClose(__func__);
869 if (ret_value != TRUE)
870 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
872 DRM_TAPPS_EXCEPTION("Reading DB function failed!!!");