#include "ua-manager-common.h"
#include "ua-manager-database.h"
-/*
-#define SELECT_ALL_PAYLOADS "SELECT payload_number, payload_name, " \
- "cycle, presence_threshold, absence_threshold FROM payloads"
-
-#define SELECT_PAYLOAD "SELECT payload_number, payload_name, " \
- "cycle, presence_threshold, absence_threshold FROM payloads " \
- "where payload_name = ?"
-*/
+#define SELECT_ALL_PAYLOADS "SELECT primary_key, secondary_key, " \
+ "device_uid, device_icon FROM payloads"
#define SELECT_PAYLOAD_DEVICE "SELECT device_number FROM payloads " \
"where primary_key = ? AND secondary_key = ? AND device_uid = ?"
"secondary_key, device_uid, device_icon, device_number)" \
"values (?, ?, ?, ?, ?)"
-/*
-#define UPDATE_PAYLOAD "UPDATE payloads SET (presence_threshold, absence_threshold) " \
- "= (?, ?) WHERE payload_name = ?"
-*/
-
#define DELETE_ALL_PAYLOADS "delete from payloads"
-/*
-#define DELETE_PAYLOAD_INFO "delete from payloads WHERE payload_name = ?"
-*/
-
/* DELETE statements */
static sqlite3_stmt *delete_all_payloads;
-//static sqlite3_stmt *delete_payload_info;
/* SELECT statements */
-//static sqlite3_stmt *select_all_payloads;
-//static sqlite3_stmt *select_payload;
+static sqlite3_stmt *select_all_payloads;
static sqlite3_stmt *select_payload_device;
static sqlite3_stmt *select_payload_number;
/* UPDATE statements */
-//static sqlite3_stmt *update_cycle;
//static sqlite3_stmt *update_payload_info;
/* INSERT statements */
FUNC_ENTRY;
// FINALIZE(select_all_payloads);
-// FINALIZE(select_payload);
FINALIZE(select_payload_device);
FINALIZE(select_payload_number);
return SQLITE_OK;
}
-// PREPARE_QUERY(rc, db, select_all_payloads,
-// SELECT_ALL_PAYLOADS, __uam_payload_finalize_select);
-// PREPARE_QUERY(rc, db, select_payload,
-// SELECT_PAYLOAD, __uam_payload_finalize_select);
+ PREPARE_QUERY(rc, db, select_all_payloads,
+ SELECT_ALL_PAYLOADS, __uam_payload_finalize_select);
PREPARE_QUERY(rc, db, select_payload_device,
SELECT_PAYLOAD_DEVICE, __uam_payload_finalize_select);
PREPARE_QUERY(rc, db, select_payload_number,
return error_code;
}
+GSList *_uam_db_get_all_payloads(void)
+{
+ FUNC_ENTRY;
+ sqlite3_stmt *stmt = select_all_payloads;
+ GSList *payload_list = NULL;
+ db_payload_info_t *info = NULL;
+ int sql_ret = SQLITE_OK;
+ char *buf = NULL;
+
+ do {
+ sql_ret = sqlite3_step(stmt);
+ switch (sql_ret) {
+ case SQLITE_DONE:
+ break;
+ case SQLITE_ROW:
+ info = g_new0(db_payload_info_t, 1);
+ memset(info->payload_info.device_uid, 0, UAM_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
+
+ buf = (char *)sqlite3_column_text(stmt, 0);
+ info->payload_info.primary_key = buf ? *buf : 13;
+ buf = (char *)sqlite3_column_text(stmt, 1);
+ info->payload_info.secondary_key = buf ? *buf : 1;
+ if ((char*)sqlite3_column_text(stmt, 2))
+ memcpy(info->payload_info.device_uid, (char *)sqlite3_column_text(stmt, 11),
+ UAM_BLE_PAYLOAD_DEVICE_UID_LEN);
+ buf = (char *)sqlite3_column_text(stmt, 3);
+ info->payload_info.device_icon = buf ? *buf : 1;
+
+ UAM_INFO("primary key: %d secondary key: %d",
+ info->payload_info.primary_key,
+ info->payload_info.secondary_key);
+
+ payload_list = g_slist_append(payload_list, info);
+ break;
+ case SQLITE_ERROR:
+ default:
+ UAM_ERR("Failed to enumerate payload info [%d:%s]",
+ sql_ret, sqlite3_errmsg(database_handle));
+ }
+ } while (sql_ret == SQLITE_ROW);
+
+ sqlite3_reset(stmt);
+ FUNC_EXIT;
+ return payload_list;
+}
+
/*
int _uam_db_update_payload_info(uam_db_payload_info_t *svc)
{
FUNC_EXIT;
return error_code;
}
-
-GSList *_uam_payload_db_get_all_payloads(void)
-{
- FUNC_ENTRY;
- sqlite3_stmt *stmt = select_all_payloads;
- GSList *payload_list = NULL;
- db_payload_info_t *info = NULL;
- int sql_ret = SQLITE_OK;
-
- do {
- sql_ret = sqlite3_step(stmt);
- switch (sql_ret) {
- case SQLITE_DONE:
- break;
- case SQLITE_ROW:
- info = g_new0(db_payload_info_t, 1);
- info->payload_number = sqlite3_column_int(stmt, 0);
- g_strlcpy(info->payload_name, (char *)sqlite3_column_text(stmt, 1),
- UAM_PAYLOAD_MAX_STRING_LEN);
- info->cycle = sqlite3_column_int(stmt, 2);
- info->presence_threshold = sqlite3_column_int(stmt, 3);
- info->absence_threshold = sqlite3_column_int(stmt, 4);
-
- UAM_INFO("%d-%s-%d-%d-%d", info->payload_number, info->payload_name,
- info->cycle, info->presence_threshold, info->absence_threshold);
-
- payload_list = g_slist_append(payload_list, info);
- break;
- case SQLITE_ERROR:
- default:
- UAM_ERR("Failed to enumerate payload info [%d:%s]",
- sql_ret, sqlite3_errmsg(database_handle));
- }
- } while (sql_ret == SQLITE_ROW);
-
- sqlite3_reset(stmt);
- FUNC_EXIT;
- return payload_list;
-}
*/