int main(int argc,char **argv) { int rc,i,id,cid; char *name; char *sql; char *zErr; sqlite3 *db; sqlite3_stmt *stmt; sql="select id,name,cid from episodes"; //打开数据库 sqlite3_open("test.db",&db); //编译sql语句 sqlite3_prepare(db,sql,strlen(sql),&stmt,NULL); //调用VM,执行VDBE程序 rc = sqlite3_step(stmt); while(rc == sqlITE_ROW) { id = sqlite3_column_int(stmt,0); name = (char *)sqlite3_column_text(stmt,1); cid = sqlite3_column_int(stmt,2); if(name != NULL){ fprintf(stderr,"Row: id=%i,cid=%i,name='%s'\n",cid,name); } else { /* Field is NULL */ fprintf(stderr,name=NULL\n",cid); } rc = sqlite3_step(stmt); } //释放资源 sqlite3_finalize(stmt); //关闭数据库 sqlite3_close(db); return 0; }
原文链接:https://www.f2er.com/sqlite/201754.html