关键词不能为空

当前您在: 主页 > 英语 >

FMDatabase 的使用方法

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-07 10:02
tags:

-

2021年2月7日发(作者:analysed)


FMDatabase



的使用方法








FMDatabase



的使用方法



- (NSString*) getPath {




NSArray* paths


=NSSearchPath ForDirectoriesInDomains(NSDocumentDirector

< br>y,NSUserDomainMask, YES)




return


[[pathsob jectAtIndex:0]stringByAppendingPathComponent:@


MyTable



.


创 建数据库


-(void)CreateTable;{dataBase =


[FMDatabasedatabaseWithPath:[selfgetPath]];





if


(![dataBase open])








NSLog(@





}













[dataBaseexecut eUpdate:@


MyTable(aa float,bb text,cc integer,dd integer,ee text)





[dataBaseclose];}



.


查询数据


-(void)Que ryData{//


获取数据





recordArray = [[NSMutableArrayalloc]init];








db =


[[FMDatabas ealloc]initWithPath:[selfgetPath]];









if ([db


open]) {








FMResultSet *rs =


[dbexecuteQuery:@









while ([rs next]){













OneRecord = [[OneRecord


alloc]init];













=


[NSNumbernumberWithFloat:[rs doubleForColumn:@













= [rs stringForColumn:@













= [NSNumbernumberWithInt:[rs


intForColumn:@













=


[NSNumbernumberWithInt:[rs intForColumn:@













= [rs stringForColumn:@













[recordArrayaddObject: OneRecord];













[OneRecordrelease];









}









[rs close];









[dbclose];}



.


更新数据


-(void)UpdateData{if ([dbopen])


{










[dbbeginTransaction];










[dbexecuteUpdate:@


date = ?










[dbexecuteUpdate:@


MyTable SET bb = ? WHERE date = ?










[dbexecuteUpdate:@


date = ?










[dbexecuteUpdate:@


MyTable SET dd = ? WHERE date = ?










[dbcommit];










db close];




}


}


4。插入数据


-(void)insertData{//


插入数据库






[dbbeginTransaction];





[dbexecuteUpdate:@


MyTable (aa,bb,cc,dd,ee) V


ALUES (?,?,?,?,?)





NSNumber


numberWithFloat:aa],bb,cc,dd,ee];





db commit];





db


close];


}


5。官方的使用方法为:



UsageThere are three main classes in FMDB:FMDatabase -


Represents a single SQLite database. Used for executing SQL


ltSet - Represents the results of executing a


query on baseQueue - If you're wanting


to perform queries and updates on multiple threads, you'll want


to use this class. It's described in the


se CreationAn FMDatabase is created with a path


to a SQLite database file. This path can be one of these three:A


file system path. The file does not have to exist on disk. If it


does not exist, it is created for empty string (@


empty database is created at a temporary location. This database


is deleted with theFMDatabase connection is . An


in-memory database is created. This database will be destroyed


with theFMDatabase connection is closed.(For more


information on temporary and in-memory databases, read the


sqlite documentation on the


subject:/)FMDatabase


*db = [FMDatabase


databaseWithPath:@


interact with the database, it must be opened. Opening fails if


there are insufficient resources or permissions to open and/or


create the (![db open]) {





[db release];





return;}Executing UpdatesAny sort of SQL statement which is


not a SELECT statement qualifies as an update. This includes


CREATE, PRAGMA,UPDATE, INSERT, ALTER,COMMIT,


BEGIN, DETACH,DELETE, DROP, END,EXPLAIN,


V


ACUUM, and REPLACE statements (plus many more).


Basically, if your SQL statement does not begin withSELECT, it


is an update ing updates returns a single value,


a BOOL. A return value of YES means the update was


successfully executed, and a return value of NO means that


some error was encountered. If you use the -[FMDatabase

executeUpdate:error:withArgumentsInArray:orV


AList:] method


to execute an update, you may supply anNSError ** that will be


filled in if execution fails. Otherwise you may invoke


the-lastErrorMessage and-lastErrorCode methods to retrieve


more ing QueriesA SELECT statement is a


query and is executed via one of the- executeQuery...


ing queries returns an FMResultSet object if


successful, and nil upon failure. Like executing updates, there is


a variant that accepts anNSError ** parameter. Otherwise you


should use the-lastErrorMessage and-lastErrorCode methods to


determine why a query order to iterate through the

-


-


-


-


-


-


-


-



本文更新与2021-02-07 10:02,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/607892.html

FMDatabase 的使用方法的相关文章

  • 爱心与尊严的高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊严高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊重的作文题库

    1.作文关爱与尊重议论文 如果说没有爱就没有教育的话,那么离开了尊重同样也谈不上教育。 因为每一位孩子都渴望得到他人的尊重,尤其是教师的尊重。可是在现实生活中,不时会有

    小学作文
  • 爱心责任100字作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任心的作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文