这一篇博客主要讲如何使用SQLite有关库函数去管理数据库中的一张表。
主要用到的函数:
SQLITE_API int sqlite3_get_table
(
sqlite3 *db, /* The database on which the SQL executes */
const char *zSql, /* The SQL to be executed */
char ***pazResult, /* Write the result table here */
int *pnRow, /* Write the number of rows in the result here */
int *pnColumn, /* Write the number of columns of result here */
char **pzErrMsg /* Write error messages here */
)
比较难理解的是第三个参数,是一个三重指针。pazResult指向的是一个一维指针数组,char*result[Num];在SQLite中所有的字段都是被解释为字符串类型存储的,采用的是UTF8编码方式。并且将一个二维表存储在了一维数组中,就是将一个一维数组分割成了mnRows个段,每一段代表二维表中的一行,一行有mnCols个元素。只要给出确切的行值与列值,就能根据公式算出在一位数组中的索引下标。
class CppSQLite3Table
{
private:
int mnCurrentRow;
int mnRows;
int mnCols;
char **mpaszResults;
void CheckResluts();
public:
CppSQLite3Table();
CppSQLite3Table(const CppSQLite3Table &rTable);
CppSQLite3Table(char **paszResults, int nRows, int nCols);
~CppSQLite3Table();
CppSQLite3Table&