#define MC_DB_NAME ".media_controller.db"
+/* TABLE */
#define MC_DB_TABLE_SERVER_LIST "server_list"
#define MC_DB_TABLE_LATEST_SERVER "latest_server"
#define MC_DB_TABLE_PLAYLIST "server_playlist"
#define MC_DB_TABLE_CLIENT_LIST "client_list"
+/* TRIGGER */
+#define MC_DB_TRIGGER_PLAYLIST "cleanup_playlist"
+
/* QUERY SET */
#define SELECT_KEY_FROM_SERVER "SELECT %q FROM %Q"
#define SELECT_NAME_FROM_LATEST "SELECT server_name FROM %Q"
#define SELECT_COUNT_FROM_SERVER "SELECT COUNT(*) FROM '%q' WHERE server_name='%q'"
#define SELECT_NAME_FROM_SERVER "SELECT server_name FROM %Q"
+#define SELECT_ALL_SERVER_LIST_EXCEPT_LATEST "SELECT name FROM SQLITE_MASTER WHERE type='table' AND (name != '%q') AND (name NOT IN (SELECT server_name FROM "MC_DB_TABLE_LATEST_SERVER"))"
+#define INSERT_TO_SERVER_LIST "INSERT OR IGNORE INTO "MC_DB_TABLE_SERVER_LIST" (server_name) VALUES ('%q')"
+#define INSERT_TO_CLIENT_LIST "INSERT OR IGNORE INTO "MC_DB_TABLE_CLIENT_LIST" (client_name) VALUES ('%q')"
+#define DELETE_FROM_SERVER_LIST "DELETE FROM "MC_DB_TABLE_SERVER_LIST" WHERE (server_name = '%q')"
+#define DELETE_FROM_CLIENT_LIST "DELETE FROM "MC_DB_TABLE_CLIENT_LIST" WHERE (client_name = '%q')"
+#define UPDATE_STATE_PLAYBACK "UPDATE '%q' SET server_state=%d, playback_state=%d"
+#define DROP_TABLE "DROP TABLE IF EXISTS '%q'"
+#define META_LIST "title, artist, album, author, genre, duration, date, copyright, description, track_num, picture, season, episode, resolution"
+#define META_FIELD "title TEXT, artist TEXT, album TEXT, author TEXT, genre TEXT, duration INTEGER DEFAULT 0, date TEXT, copyright TEXT, description TEXT, track_num TEXT, picture TEXT, season TEXT, episode TEXT, resolution TEXT, "
+#define CREATE_SERVER_TABLE "DROP TABLE IF EXISTS '%q'; CREATE TABLE IF NOT EXISTS '%q' (\
+ server_name TEXT PRIMARY KEY, \
+ server_state INTEGER DEFAULT 1, \
+ playback_state INTEGER DEFAULT 0, \
+ playback_position INTEGER DEFAULT 0, \
+ playlist_name TEXT, \
+ playlist_index TEXT, \
+ playback_content_type INTEGER DEFAULT 4, \
+ age_rating INTEGER DEFAULT 0, \
+ %s \
+ shuffle_mode INTEGER DEFAULT 1, \
+ repeat_mode INTEGER DEFAULT 1, \
+ icon_uri TEXT, \
+ ability_decided INTEGER DEFAULT 0, \
+ ability_supported INTEGER DEFAULT 0 \
+ );INSERT INTO '%q' (server_name) VALUES ('%q');"
+
#define SQLITE3_SAFE_FREE(sql_string) {if (sql_string) { sqlite3_free(sql_string); sql_string = NULL; } }
#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); }
#include "media_controller_db_util.h"
#include "mc_util.h"
-
-#define MC_DB_TRIGGER_PLAYLIST "cleanup_playlist"
-#define DB_SELECT_ALL_SERVER_LIST_EXCEPT_LATEST "SELECT name FROM SQLITE_MASTER WHERE type='table' AND (name != '%q') AND (name NOT IN (SELECT server_name FROM "MC_DB_TABLE_LATEST_SERVER"));"
-#define DB_INSERT_TO_SERVER_LIST "INSERT OR IGNORE INTO "MC_DB_TABLE_SERVER_LIST" (server_name) VALUES ('%q');"
-#define DB_INSERT_TO_CLIENT_LIST "INSERT OR IGNORE INTO "MC_DB_TABLE_CLIENT_LIST" (client_name) VALUES ('%q');"
-#define DB_DELETE_FROM_SERVER_LIST "DELETE FROM "MC_DB_TABLE_SERVER_LIST" WHERE (server_name = '%q');"
-#define DB_DELETE_FROM_CLIENT_LIST "DELETE FROM "MC_DB_TABLE_CLIENT_LIST" WHERE (client_name = '%q');"
-#define DB_UPDATE_STATE_PLAYBACK "UPDATE '%q' SET server_state=%d, playback_state=%d;"
-#define DB_DROP_TABLE "DROP TABLE IF EXISTS '%q';"
-#define DB_META_LIST "title, artist, album, author, genre, duration, date, copyright, description, track_num, picture, season, episode, resolution"
-#define DB_META_FIELD "title TEXT, artist TEXT, album TEXT, author TEXT, genre TEXT, duration INTEGER DEFAULT 0, date TEXT, copyright TEXT, description TEXT, track_num TEXT, picture TEXT, season TEXT, episode TEXT, resolution TEXT, "
-#define DB_CREATE_SERVER_TABLE "DROP TABLE IF EXISTS '%q'; CREATE TABLE IF NOT EXISTS '%q' (\
- server_name TEXT PRIMARY KEY, \
- server_state INTEGER DEFAULT 1, \
- playback_state INTEGER DEFAULT 0, \
- playback_position INTEGER DEFAULT 0, \
- playlist_name TEXT, \
- playlist_index TEXT, \
- playback_content_type INTEGER DEFAULT 4, \
- age_rating INTEGER DEFAULT 0, \
- %s \
- shuffle_mode INTEGER DEFAULT 1, \
- repeat_mode INTEGER DEFAULT 1, \
- icon_uri TEXT, \
- ability_decided INTEGER DEFAULT 0, \
- ability_supported INTEGER DEFAULT 0 \
- );INSERT INTO '%q' (server_name) VALUES ('%q');"
-
-#define MC_DB_NAME ".media_controller.db"
#define REGULAR_USER 5000
static GMutex tzplatform_mutex;
mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
- sql_str = sqlite3_mprintf(DB_SELECT_ALL_SERVER_LIST_EXCEPT_LATEST, MC_DB_TABLE_LATEST_SERVER);
+ sql_str = sqlite3_mprintf(SELECT_ALL_SERVER_LIST_EXCEPT_LATEST, MC_DB_TABLE_LATEST_SERVER);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = sqlite3_prepare_v2(handle, sql_str, strlen(sql_str), &stmt, NULL);
mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
- sql_str = sqlite3_mprintf(DB_DROP_TABLE, server_name);
+ sql_str = sqlite3_mprintf(DROP_TABLE, server_name);
ret = mc_db_util_update_db(handle, sql_str);
if (MEDIA_CONTROLLER_ERROR_NONE != ret)
item_index TEXT, \
%s \
unique(server_name, playlist_name, item_index));",
- MC_DB_TABLE_PLAYLIST, DB_META_FIELD);
+ MC_DB_TABLE_PLAYLIST, META_FIELD);
ret = mc_db_util_update_db(handle, sql_str);
SQLITE3_SAFE_FREE(sql_str);
/* Update DB */
if (handle) {
- sql_str = sqlite3_mprintf(DB_UPDATE_STATE_PLAYBACK, server_name, server_state, playback_state);
+ sql_str = sqlite3_mprintf(UPDATE_STATE_PLAYBACK, server_name, server_state, playback_state);
ret = mc_db_util_update_db(handle, sql_str);
SQLITE3_SAFE_FREE(sql_str);
mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "fail to mc_db_util_update_db [%d]", ret);
if (__mc_db_is_latest(db_handle, app_id)) {
ret = __mc_update_latest_server_info(db_handle, app_id, MC_SERVER_STATE_ACTIVATE, MC_PLAYBACK_STATE_STOPPED, FALSE);
} else {
- sql_str = sqlite3_mprintf(DB_CREATE_SERVER_TABLE, app_id, app_id, DB_META_FIELD, app_id, app_id);
+ sql_str = sqlite3_mprintf(CREATE_SERVER_TABLE, app_id, app_id, META_FIELD, app_id, app_id);
ret = mc_db_util_update_db(db_handle, sql_str);
SQLITE3_SAFE_FREE(sql_str);
}
mc_secure_debug("app_id: %s, priv_type: %d", app_id, priv_type);
if (priv_type == MC_PRIV_TYPE_SERVER) {
- sql_str = sqlite3_mprintf(DB_INSERT_TO_SERVER_LIST, app_id, app_id);
+ sql_str = sqlite3_mprintf(INSERT_TO_SERVER_LIST, app_id, app_id);
} else if (priv_type == MC_PRIV_TYPE_CLIENT) {
- sql_str = sqlite3_mprintf(DB_INSERT_TO_CLIENT_LIST, app_id, app_id);
+ sql_str = sqlite3_mprintf(INSERT_TO_CLIENT_LIST, app_id, app_id);
} else {
mc_error("invalid priv_type (%d)", priv_type);
mc_debug_fleave();
mc_secure_debug("app_id: %s, priv_type: %d", app_id, priv_type);
if (priv_type == MC_PRIV_TYPE_SERVER) {
- sql_str = sqlite3_mprintf(DB_DELETE_FROM_SERVER_LIST, app_id);
+ sql_str = sqlite3_mprintf(DELETE_FROM_SERVER_LIST, app_id);
} else if (priv_type == MC_PRIV_TYPE_CLIENT) {
- sql_str = sqlite3_mprintf(DB_DELETE_FROM_CLIENT_LIST, app_id);
+ sql_str = sqlite3_mprintf(DELETE_FROM_CLIENT_LIST, app_id);
} else {
mc_error("invalid priv_type (%d)", priv_type);
mc_debug_fleave();
mc_retm_if(params == NULL, "invalid playlist data");
sql_str = sqlite3_mprintf("INSERT INTO '%q' (server_name, playlist_name, item_index, %s) VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);",
- MC_DB_TABLE_PLAYLIST, DB_META_LIST, g_list_nth_data(*query_list, 0), g_list_nth_data(*query_list, 1), key,
+ MC_DB_TABLE_PLAYLIST, META_LIST, g_list_nth_data(*query_list, 0), g_list_nth_data(*query_list, 1), key,
__replace_null(params[0]), __replace_null(params[1]), __replace_null(params[2]), __replace_null(params[3]), __replace_null(params[4]),
__replace_null(params[5]), __replace_null(params[6]), __replace_null(params[7]), __replace_null(params[8]), __replace_null(params[9]),
__replace_null(params[10]), __replace_null(params[11]), __replace_null(params[12]), __replace_null(params[13]));