Create, insert, UPDATE and delete: Use the Executeupdate method, while the query uses ExecuteQuery
1. Instantiating Fmdatabase
Paths:ios document Path, document is a writable and writable folder in iOS
Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
NSString *documentdirectory = [Paths objectatindex:0];
DbPath: The database path, in document.
NSString *dbpath = [documentdirectory stringbyappendingpathcomponent:@ "test.db"];
To create a DB instance, this is explained below: If a "test.db" file does not exist in the path, SQLite will automatically create "Test.db"
Fmdatabase *db= [Fmdatabase Databasewithpath:dbpath];
if (![ DB Open]) {
NSLog (@ "Could not open db.");
return;
}
2. Create a table
Create a table named user, with two fields of type Name,integer for string type
[DB executeupdate:@ "CREATE TABLE User (Name text,age integer)"];
3. Insert
Insert data using the type in OC text corresponds to nsstring integer corresponding to NSNumber for shaping
[DB executeupdate:@ INSERT into User (name,age) VALUES (?,?) "@" Zhang San ", [NSNumber numberwithint:20]];
4. Update
Update data Change "Zhang San" to "John Doe"
[DB executeupdate:@] UPDATE User SET Name =? WHERE Name =? @ "John Doe", @ "Zhang San"];
5. Delete
Delete data
[DB executeupdate:@ "DELETE from User WHERE Name =?", @ "Zhang San"];
6. Enquiry
Returns the first result in a database that satisfies a condition
NSString *aa=[db stringforquery:@ "Select Name from User WHERE age =?", @ "20"];
Return all query Results
Fmresultset *rs=[db executequery:@ "select * from User"];
Rs=[db executequery:@ "SELECT * from User WHERE age =?", @ "20"];
while ([Rs next]) {
NSLog (@ "%@%@", [rs stringforcolumn:@ "Name"],[rs stringforcolumn:@ "Age"]);
}
[Rs Close];
From: http://blog.sina.com.cn/s/blog_680a331e0100qkz3.html
"iOS development" uses SQLite database operations for FMDB encapsulation classes