- 3
- 0
- 约3.41千字
- 约 3页
- 2021-11-14 发布于江苏
- 举报
//database operation 打开数据库
-(bool) opendatabase{
nsarray*paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask,yes);
nsstring *documentsdirectory = [pathsobjectatindex:0];
nsstring *path = [documentsdirectorystringbyappendingpathcomponent:@mydb.sql]; nsfilemanager*filemanager = [nsfilemanagerdefaultmanager];
bool find = [filemanagerfileexistsatpath:path];
//找到数据库文件 mydb.sql if (find) {
nslog(@database file have already existed.); if(sqlite3_open([pathutf8string], amp;database_) !=sqlite_ok) { sqlite3_close(database_);
nslog(@error: open database file.); return no;
}
return yes;
}
if(sqlite3_open([path utf8string], amp;database_) ==sqlite_ok) {
//bfirstcreate_ = yes;
[selfcreatechannelstable:datab在as后e_面];实//现函数 createchannelstable return yes;
}else { sqlite3_close(database_);
nslog(@error: open database file.); return no;
}
return no;
}
创建表
- (bool) createchannelstable:(sqlite3*)db{
char*sql = create table reports (id integer primary key,stime text,stitle text,scal text,sru text);
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(db, sql, -1, amp;statement,nil) !=sqlite_ok) { nslog(@error: failed to prepare statement:create reports table); return no;
}
int success =sqlite3_step(statement); sqlite3_finalize(statement);
if ( success !=sqlite_done) {
nslog(@error: failed to dehydrate:create table reports); return no;
}
nslog(@create table reports successed.); return yes;
}
插入表
- (bool)insertonechannel:(nsstring*)msyttiimtele:(nsstring*)stmiytclael:(nsstring*)scal myruntime:(nsstring*)sruntime
{
sqlite3_stmt *statement;
staticchar*sql = insert into reports (id,stime,stitle,scal,sruntime) values(null,?,?,?,?);
//问号的个数要和(cid,title,imagedata,ima里ge面le字n)段的个数匹配,代表未知的值,将在下面将值和字段关 联。
int success =sqlite3_prepare_v2(database_, sql, -1, amp;statement,null); if (success !=sqlite_ok) {
nslog(@error: failed to insert:channels); return no;
}
//这里的数字 1,2,3,4 代表第几个问号
//sqlite3_bind_text(statement, 1, stime, -1, sqlite_transient); char*p = [stime cstringusing
您可能关注的文档
最近下载
- 村文艺演出村支书讲话稿范文十篇.docx VIP
- 《GB_T 32800.11-2023手持式非电类动力工具 安全要求 第11部分:冲剪机和剪刀》专题研究报告.pptx VIP
- 《2025中国临床肿瘤学会淋巴瘤诊疗指南》.docx VIP
- 2025年互联网营销师用户分层与内容营销策略专题试卷及解析.pdf VIP
- 2025年特许金融分析师变动股利政策与DDM估值专题试卷及解析.pdf VIP
- 2025年信息系统安全专家漏洞管理与其他安全流程(如事件响应)的集成专题试卷及解析.pdf VIP
- 2025年无人机驾驶员执照无人机适航管理中的适航性检查单专题试卷及解析.pdf VIP
- 2022年宁夏中考数学试卷.pdf VIP
- 浙科版综合实践活动七年级下册全册教学设计教案.pdf
- 2025年拍卖师贵金属价格波动对珠宝拍卖底价的影响专题试卷及解析.pdf VIP
原创力文档

文档评论(0)