char *dbname = “test.db”;
int rc = sqlite3_open(dbname, &db);
if (rc == SQLITE_OK)
{
char sql[256] = “select * from Images” ;
char** pResult;
int nRow;
int nCol;
rc = sqlite3_get_table(db, sql, &pResult, &nRow, &nCol, NULL);
if (rc == SQLITE_OK)
{
if (nRow >= 1){
...
}
}
sqlite3_free_table(pResult);
}
sqlite3_close(db);
//获取上图Figures表中create sql语句
string DB_GetFigureCreateSql()
{
string res = "";
int rc = sqlite3_open(dbname, &db);
if (rc == SQLITE_OK)
{
char *sql = "select sql from sqlite_master where tbl_name = 'Figures' and type = 'table'";
char** pResult;
int nRow;
int nCol;
rc = sqlite3_get_table(db, sql, &pResult, &nRow, &nCol, NULL);
if (rc == SQLITE_OK)
{
if (nRow >= 1)
{
res = pResult[nCol];
}
}
sqlite3_free_table(pResult);
}
sqlite3_close(db);
return res;
}
//解析字符串函数
std::vector<string> split(string str, string separator)
{
std::vector<string> result;
int cutAt;
while ((cutAt = str.find_first_of(separator)) != str.npos)
{
if (cutAt > 0)
{
result.push_back(str.substr(0, cutAt));
}
str = str.substr(cutAt + 1);
}
if (str.length() > 0)
{
result.push_back(str);
}
return result;
}
//获取表中字段名
std::vector<string> DB_GetKeyFieldName(string res)
{
std::vector<string> r = split(res, ",");
std::vector<string> keyField;
for (int i = 0; i < r.size(); ++i)
{
std::vector<string> tp = split(r[i], "\"");
if (tp.size() == 2)
{
keyField.push_back(tp[0]);
}
else if (tp.size() == 3)
{
keyField.push_back(tp[1]);
}
}
return keyField;
}
std::vector<string> FieldName = DB_GetKeyFieldName(DB_GetFigureCreateSql());
ALTER TABLE x ADD COLUMN "new_col",
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2026 源码网商城 (www.ymwmall.com) 版权所有