string path = MGBundle::mainBundle()->userFilePathWithFileName("brush_data.db");
sqlite3 *pDB;
char *errMsg;
if(!Utility::isFileORDirExist(path))
{
int res = sqlite3_open(path.c_str(), &pDB);
if(res != SQLITE_OK)
{
MGLogD("brushdata db open fail");
sqlite3_close(pDB);
return;
}
string sql = "create table brush_data(white text, wounded text, kiss text, date_str text);";
res = sqlite3_exec(pDB, sql.c_str(), 0, 0, &errMsg);
sqlite3_close(pDB);
}
int res = sqlite3_open(path.c_str(), &pDB);
if(res != SQLITE_OK)
{
MGLogD("brushdata db open fail");
sqlite3_close(pDB);
return;
}
//数据库表条件查询
int row = 0, column = 0;
char **result;
string sql = "select * from brush_data order by date_str desc,date_str limit 0,1;";
res = sqlite3_get_table(pDB, sql.c_str(), &result, &row, &column, &errMsg);
int i = 0;
for(i = column; i < (row + 1) * column; i ++)
MGLogD("reslut:%s", result[i]);
sqlite3_free_table(result);
sqlite3_close(pDB);
string path = MGBundle::mainBundle()->userFilePathWithFileName("brush_data.db");
sqlite3 *pDB;
char *errMsg;
if(!Utility::isFileORDirExist(path))
{
int res = sqlite3_open(path.c_str(), &pDB);
if(res != SQLITE_OK)
{
MGLogD("brushdata db open fail");
sqlite3_close(pDB);
return;
}
string sql = "create table brush_data(white text, wounded text, kiss text, date_str text);";
res = sqlite3_exec(pDB, sql.c_str(), 0, 0, &errMsg);
sqlite3_close(pDB);
}
int res = sqlite3_open(path.c_str(), &pDB);
if(res != SQLITE_OK)
{
MGLogD("brushdata db open fail");
sqlite3_close(pDB);
return;
}
//数据表记录删除和插入
string tmp = TimeState::getCurrentTime().getTimeString("111000");
for(auto it = v_syn_records.begin(); it != v_syn_records.end(); ++ it)
{
string sql = "delete from brush_data where date_str like '" + (*it).date_time.getTimeString("111000");
sql += "%';";
res = sqlite3_exec(pDB, sql.c_str(), 0, 0, &errMsg);
string w_value = Utility::BuiltInTypeToString<int>((*it).white_value);
string wo_value = Utility::BuiltInTypeToString<int>((*it).wounded_value);
string k_value = Utility::BuiltInTypeToString<int>((*it).kiss_value);
string d_value = (*it).date_time.getTimeString("111111");
sql = "insert into brush_data values('" + w_value +"','"+ wo_value + "','"+ k_value + "','"+ d_value + "');";
res = sqlite3_exec(pDB, sql.c_str(), 0, 0, &errMsg);
}
sqlite3_close(pDB);