/* ************************************************************************
* Filename: sqlite3_demo.cpp
* g++ sqlite3_demo.cpp -lsqlite3
* ************************************************************************/
#include <string.h>
#include <stdio.h>
#include <map>
#include <sqlite3.h>
#include <stdint.h>
#include <iostream>
using namespace std;
#define INSTALL_APP_RESULT_DATABASE_TYPE 0x01
#define DEVICE_INFO_DATABASE_TYPE 0x02
#define CRG_FAIL 0x0000
#define CRG_SUCCESS 0x0001
#define CRG_INVALID_PARAM 0x0002
#define MAX_BUFF_LEN 260
#define SQLITE3_DEMO "sqlite3_demo.db3"
typedef struct _INSTALL_APP_RESULT_LOG_STRUCT_
{
uint32_t dw_dev_type;
char sz_log_times[MAX_BUFF_LEN];
}install_app_result_log_info, *p_install_app_result_log_info;
typedef struct _DEVICE_LOG_INFO_STRUCT_
{
uint32_t dw_dev_type;
char sz_log_times[MAX_BUFF_LEN];
}device_log_info, *p_device_log_info;
typedef map <int, install_app_result_log_info> install_app_result_log_info_map;
typedef map <int, device_log_info> device_log_info_map;
pthread_mutex_t device_info_database_mutex;
pthread_mutex_t install_app_result_database_mutex;
sqlite3 * gp_db;
static string get_insert_sql_for_install_app_result()
{
return ("insert into AppResultLog(DevType, LogTimes) \
values(?,?)");
}
static string get_insert_sql_for_device_info()
{
return ("insert into DeviceInfoLog(DevType, LogTimes) \
values(?,?)");
}
static string get_select_sql_for_install_app_result()
{
return ("SELECT Id, DevType, LogTimes \
FROM AppResultLog");
}
static string get_select_sql_for_Device_info()
{
return ("SELECT Id, DevType, LogTimes \
FROM DeviceInfoLog");
}
static string get_delete_sql_for_install_app_result(int dw_id)
{
char sz_del[MAX_BUFF_LEN] = { 0 };
snprintf(sz_del, MAX_BUFF_LEN, "DELETE FROM AppResultLog where Id = %d", dw_id);
return string(sz_del);
}
static string get_delete_sql_for_device_info(int dw_id)
{
cha
Linux c/c++ sqlite3 实用demo
最新推荐文章于 2024-03-26 11:28:14 发布