Today finally spent a little time on the previous project used in the SQLite operation of the method to organize and upload the github, download the address: (Https://github.com/peanutNote/QYSQLiteManagerDemo.git).
As with other third-party purposes, the main purpose is to make the code relevant to the SQLite operation simple, specific use:
Add the Qysqlitemanager file to your project, adding #import "Qysqlitemanager" to the class that you want to operate on SQLite.
//INSERT statement-(void) inserttable {//Create SQL statement NSString *sql = @ "INSERT into teacher (Name,id) VALUES (
?,?)";
Immutable parameters//BOOL IsOK = [Qysqlitemanager inserttablewithsqlstring:sql andarray:@[@ "Xiaoming", @115]];
Variable parameter BOOL IsOK = [Qysqlitemanager inserttablewithsqlstring:sql andobjects:@ "xiaoming", @ "to be", nil];
if (IsOK) {NSLog (@ "data inserted successfully");
else {NSLog (@ "Data insert failed");
}//Query statement-(void) selecttable {nsstring *sql = @ "SELECT * from teacher"; [Qysqlitemanager selecttablewithsqlstring:sql didfinishedblock:^ (Nsarray *datalist, NSString *error)
{NSLog (@ "%@", dataList);
} Andobjects:nil];
}//Modify table statement-(void) altertable {nsstring *sql = @ "ALTER TABLE teacher add column pwd integer";
if ([Qysqlitemanager Altertablewithsqlstring:sql]) {NSLog (@ "modified successfully");
}//Update data statement-(void) updatetable {nsstring *sql = @ "Update teacher set name =? where id =?";
if ([Qysqlitemanager updatetablewithsqlstring:sql andarray:@[@ "Xiaoming", @115]]) {NSLog (@ "update succeeded"); }
}
For the data type returned by the query, students who need it can find "Sqlite3_bind_text" in "qysqlitemanager.m" on their own, and then in the following
for (int i = 0; i < Column_count i++) {
//Get field name
char * keyname = (char *) sqlite3_column_name (stmt, i);
NSString *key = [NSString stringwithutf8string:keyname];
if (Sqlite3_column_type (stmt, i) = = Sqlite_text) {///When the field data is ' TEXT '/
/get the corresponding data
char *valuename = (char *) sqlite3 _column_text (stmt, i);
NSString *value = [NSString stringwithutf8string:valuename];
[Datadic Setobject:value Forkey:key];
} else {//When field data is integer
int value = Sqlite3_column_int (stmt, i);
[Datadic setobject:@ (value) Forkey:key];
}
Modify the data type you want.
The above content is small make up to everybody daily collects and arranges the iOS SQLite to the database all sorts of operation, hope to be helpful to everybody