.dbrw = NULL
};
+
+static ail_error_e db_do_prepare(sqlite3 *db, const char *query, sqlite3_stmt **stmt)
+{
+ int ret;
+
+ retv_if(!query, AIL_ERROR_INVALID_PARAMETER);
+ retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
+ retv_if(!db, AIL_ERROR_DB_FAILED);
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), stmt, NULL);
+ if (ret != SQLITE_OK) {
+ _E("%s\n", sqlite3_errmsg(db));
+ return AIL_ERROR_DB_FAILED;
+ } else
+ return AIL_ERROR_OK;
+}
+
ail_error_e db_open(db_open_mode mode)
{
int ret;
return AIL_ERROR_OK;
}
-
-
ail_error_e db_prepare(const char *query, sqlite3_stmt **stmt)
{
- int ret;
-
- retv_if(!query, AIL_ERROR_INVALID_PARAMETER);
- retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
- retv_if(!db_info.dbro, AIL_ERROR_DB_FAILED);
+ return db_do_prepare(db_info.dbro, query, stmt);
+}
- ret = sqlite3_prepare_v2(db_info.dbro, query, strlen(query), stmt, NULL);
- if (ret != SQLITE_OK) {
- _E("%s\n", sqlite3_errmsg(db_info.dbro));
- return AIL_ERROR_DB_FAILED;
- } else
- return AIL_ERROR_OK;
+ail_error_e db_prepare_rw(const char *query, sqlite3_stmt **stmt)
+{
+ return db_do_prepare(db_info.dbrw, query, stmt);
}
return AIL_ERROR_OK;
}
+ail_error_e db_bind_text(sqlite3_stmt *stmt, int idx, char* value)
+{
+ int ret;
+
+ retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
+
+ ret = sqlite3_bind_text(stmt, idx, value, strlen(value), 0);
+ retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
+
+ return AIL_ERROR_OK;
+}
ail_error_e db_step(sqlite3_stmt *stmt)
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
#define argsdelimiter " \t"
+#define SQL_INSERT_LOCALNAME_STR "insert into localname (package, locale, name) values "
+#define SQL_INSERT_LOCALNAME_STR_LEN (sizeof(SQL_INSERT_LOCALNAME_STR)-1)
+
+#define SQL_INSERT_LOCALNAME_INIT_STR SQL_INSERT_LOCALNAME_STR"( ?, ?, ?) "
+
+#define SQL_LOCALNAME_TRIPLET_STR ", ( ?, ?, ?)"
+#define SQL_LOCALNAME_TRIPLET_STR_LEN (sizeof(SQL_LOCALNAME_TRIPLET_STR)-1)
+
typedef enum {
NOTI_ADD,
NOTI_UPDATE,
return desktop;
}
+static inline int _bind_local_info(desktop_info_s* info, sqlite3_stmt * stmt)
+{
+ int ret = 0;
+ unsigned long i = 0;
+ struct name_item *item;
+ GSList* localname;
+ retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
+ retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
+ retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
+ localname = info->localname;
+ while (localname) {
+ item = (struct name_item *) localname->data;
+ if (item && item->locale && item->name) {
+ // Bind values for a triplet : package, locale, name
+ retv_if(db_bind_text(stmt, i+1, info->package) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+ retv_if(db_bind_text(stmt, i+2, item->locale) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+ retv_if(db_bind_text(stmt, i+3, item->name) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+ i += 3;
+ }
+ localname = g_slist_next(localname);
+ }
+ return AIL_ERROR_OK;
+}
+
+
+static inline int _len_local_info(desktop_info_s* info)
+{
+ int len = 0;
+ struct name_item *item;
+ GSList* localname;
+ retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
+ if(info->localname) {
+ localname = info->localname;
+ while (localname) {
+ item = (struct name_item *) localname->data;
+ if (item && item->locale && item->name)
+ len ++;
+ localname = g_slist_next(localname);
+ }
+ }
+ return len;
+}
+
+
+static inline int _insert_local_info(desktop_info_s* info)
+{
+ int len_query = SQL_INSERT_LOCALNAME_STR_LEN;
+ int nb_locale_args;
+ char *query;
+ int ret = AIL_ERROR_OK;
+ sqlite3_stmt *stmt = NULL;
+ int i = 0;
+ retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
+ retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
+ nb_locale_args = _len_local_info(info);
+
+ retv_if(!nb_locale_args, AIL_ERROR_INVALID_PARAMETER);
+
+ len_query += SQL_LOCALNAME_TRIPLET_STR_LEN*nb_locale_args +1;
+
+ query = (char *) malloc(len_query);
+ retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
+ stpncpy(query, SQL_INSERT_LOCALNAME_INIT_STR, len_query);
+ for (i = 0; i < nb_locale_args - 1; i++)
+ strcat(query, SQL_LOCALNAME_TRIPLET_STR);
+
+ do {
+ ret = db_prepare_rw(query, &stmt);
+ if (ret < 0) break;
+
+ ret = _bind_local_info(info, stmt);
+ if (ret < 0) {
+ _E("Can't bind locale information to this query - %s. ",query);
+ db_finalize(stmt);
+ break;
+ }
+ ret = db_step(stmt);
+ if (ret != AIL_ERROR_NO_DATA) {
+ /* Insert Request doesn't return any data.
+ * db_step should returns AIL_ERROR_NO_DATA in this case. */
+ _E("Can't execute this query - %s. ",query);
+ db_finalize(stmt);
+ break;
+ }
+ ret = db_finalize(stmt);
+ } while(0);
+
+ free(query);
+ return ret;
+}
static inline int _strlen_desktop_info(desktop_info_s* info)
{
}
ret = db_exec(query);
+ free(query);
retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
if (info->localname)
- g_slist_foreach(info->localname, _insert_localname, info);
+ _insert_local_info(info);
_D("Add (%s).", info->package);
}
if (info->localname)
- g_slist_foreach(info->localname, _insert_localname, info);
+ _insert_local_info(info);
_D("Update (%s).", info->package);