Linux c/c++ sqlite3 实用demo

/* ************************************************************************
 *       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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值