Sqlite3示例
跳到导航
跳到搜索
#include <stdio.h> #include <sqlite3.h> typedef struct SINFO { ... }SINFO_tdef; static int callback(void *Result, int argc, char **argv, char **azColName){ int i; for(i=0; i<argc; i++){ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); SINFO_tdef* ptTblSINFO=(SINFO_tdef*)Result; ptTblSINFO->... return 0; } int main(int argc, char **argv){ sqlite3 *db; char *zErrMsg = 0; int rc; SINFO_tdef TblSINFO; if( argc!=3 ){ fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); return(1); } rc = sqlite3_open(argv[1], &db); if( rc ){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return(1); } rc = sqlite3_exec(db, argv[2], callback, &TblSINFO, &zErrMsg); if( rc!=SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } sqlite3_close(db); return 0; }