狩猎者

欲师者,温故而知新;欲达者,吐故而纳新。

在这里记录下平时开发遇到的问题,方便日后查阅


欢迎您的到访!

sqlite ios api函数说明

iOS sqlite API函数说明

打开数据库

int sqlite3_open(
 const char *filename, /* Database filename (UTF-8) */
 sqlite3 **ppDb   /* OUT: SQLite db handle */
);
filename:数据库文件路径
ppDb:sqlite3*类型的变量的地址
返回值是int,如果正常就会返回 SQLITE_OK变量,如果错误,会返回一个错误码。常见的错误类型:SQLITE_ERROR代表数据库文件没有找到,SQLITE_CANTOPEN代表因为某些原因数据库文件无法打开

关闭数据库

int sqlite3_close(sqlite3*);
参数:sqlite3*的数据库文件
返回值:状态码

SQL语句封装函数

int sqlite3_prepare_v2(
  sqlite3 *db,            /* Database handle */
  const char *zSql,       /* SQL statement, UTF-8 encoded */
  int nByte,              /* Maximum length of zSql in bytes. */
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
);
db:数据库文件
zSql:UTF-8格式的SQL语句
nByte:该SQL语句的最大长度或-1(表明读取到第一个null终止符)
ppStmt:sqlite3_stmt *变量的地址
pzTail:指向该SQL语句第一个字节的指针或此处使用NULL
返回值:SQLITE_OK或者错误码(详见返回状态码)

数据库查询函数

int sqlite3_step(sqlite3_stmt*);
参数:sqlite3_stmt*变量
返回值:SQLITE_OK或者错误码
如果返回SQLITE_OK,可以利用下面的一些函数获取结果集中的内容
const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
double sqlite3_column_double(sqlite3_stmt*, int iCol);
int sqlite3_column_int(sqlite3_stmt*, int iCol);
sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
int sqlite3_column_type(sqlite3_stmt*, int iCol);
sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
参数1:sqlite3_stmt*变量
iCol:想要获取的字段在SQL语句中的索引(索引从0开始)

数据库操作返回状态码

#define SQLITE_OK           0   /* Successful result */
/* beginning-of-error-codes */
#define SQLITE_ERROR        1   /* SQL error or missing database */
#define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
#define SQLITE_PERM         3   /* Access permission denied */
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
#define SQLITE_BUSY         5   /* The database file is locked */
#define SQLITE_LOCKED       6   /* A table in the database is locked */
#define SQLITE_NOMEM        7   /* A malloc() failed */
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
#define SQLITE_FULL        13   /* Insertion failed because database is full */
#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
#define SQLITE_EMPTY       16   /* Database is empty */
#define SQLITE_SCHEMA      17   /* The database schema changed */
#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
#define SQLITE_MISMATCH    20   /* Data type mismatch */
#define SQLITE_MISUSE      21   /* Library used incorrectly */
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
#define SQLITE_AUTH        23   /* Authorization denied */
#define SQLITE_FORMAT      24   /* Auxiliary database format error */
#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
#define SQLITE_NOTICE      27   /* Notifications from sqlite3_log() */
#define SQLITE_WARNING     28   /* Warnings from sqlite3_log() */
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
最近的文章

Xcode 官网下载地址

下载地址…

继续阅读
更早的文章

Hello World - Vno

What’s thisVno Jekyll is a theme for Jekyll. It is a port of my Ghost theme vno, which is originally developed from Dale Anthony’s Uno.Usage$ git clone https://github.com/onevcat/vno-jekyll.git your_site$ cd your_site$ bundler install$ bundler exe...…

继续阅读