1.创建表
CREATE TABLE IF NOT EXISTS UserTable (username TEXT primary key,password TEXT,email TEXT);
2.插入一条数据
INSERT OR REPLACE INTO UserTable (username , password,email) VALUES (?,?,?);
3.更新一条数据
UPDATE UserTable set password = '123456' where username = 'wxhl';
4.查询数据
SELECT username,password,email FROM UserTable where username = 'wxhl'
5.删除数据
DELETE FROM UserTable WHERE username='wxhl'
6.模糊查询
SELECT *FROM UserTable Where username is LIKE "流%"
7.倒叙排列(默认正)
SELECT *FROM UserTable ORDER BY sage DESC
//使用数据库的流程
/*
* 1、打开数据库
* 2、准备语句
* 3、读取(绑定)列
* 4、语句完结
* 5、关闭数据库
*/
//sqlite3.0 API
1.导入 libsqlite3.0.dylib
2. sqlite3_open() //打开数据库
3. sqlite3_close() //关闭数据库
4. sqlite3_exec() //执行sql语句,例如创建表
5. sqlite3_prepare_v2() //编译SQL语句
6. sqlite3_step() //执行SQL语句
7. sqlite3_finalize() //结束sql语句
8. sqlite3_bind_text() //往数据库占位符上填充数据
9. sqlite3_column_text() //查询字段上的数据
9. SQLITE_OK 执行结果成功、 SQLITE_ERROR 执行失败
实例:
1. sqlite3_open([sandboxPath UTF8String], &dbPointer);
2. sqlite3_close(dbPointer);
3. sqlite3_exec (database, [sql UTF8String],NULL, NULL, &errorMsg)
4. sqlite3_prepare_v2(contactDB, "SELECT *FROM contact1", -1, &stmt, NULL);
5. while (sqlite3_step(statement) == SQLITE_ROW) {
6. sqlite3_finalize(statement);
7. sqlite3_bind_text(stmt, 1, [address.name UTF8String], -1, NULL);
CREATE TABLE IF NOT EXISTS UserTable (username TEXT primary key,password TEXT,email TEXT);
2.插入一条数据
INSERT OR REPLACE INTO UserTable (username , password,email) VALUES (?,?,?);
3.更新一条数据
UPDATE UserTable set password = '123456' where username = 'wxhl';
4.查询数据
SELECT username,password,email FROM UserTable where username = 'wxhl'
5.删除数据
DELETE FROM UserTable WHERE username='wxhl'
6.模糊查询
SELECT *FROM UserTable Where username is LIKE "流%"
7.倒叙排列(默认正)
SELECT *FROM UserTable ORDER BY sage DESC
//使用数据库的流程
/*
* 1、打开数据库
* 2、准备语句
* 3、读取(绑定)列
* 4、语句完结
* 5、关闭数据库
*/
//sqlite3.0 API
1.导入 libsqlite3.0.dylib
2. sqlite3_open() //打开数据库
3. sqlite3_close() //关闭数据库
4. sqlite3_exec() //执行sql语句,例如创建表
5. sqlite3_prepare_v2() //编译SQL语句
6. sqlite3_step() //执行SQL语句
7. sqlite3_finalize() //结束sql语句
8. sqlite3_bind_text() //往数据库占位符上填充数据
9. sqlite3_column_text() //查询字段上的数据
9. SQLITE_OK 执行结果成功、 SQLITE_ERROR 执行失败
实例:
1. sqlite3_open([sandboxPath UTF8String], &dbPointer);
2. sqlite3_close(dbPointer);
3. sqlite3_exec (database, [sql UTF8String],NULL, NULL, &errorMsg)
4. sqlite3_prepare_v2(contactDB, "SELECT *FROM contact1", -1, &stmt, NULL);
5. while (sqlite3_step(statement) == SQLITE_ROW) {
6. sqlite3_finalize(statement);
7. sqlite3_bind_text(stmt, 1, [address.name UTF8String], -1, NULL);