需要注意的是这里使用的某些方法名称是基于笔者以前开发DISCUT!NT时使用的DBHelper.cs类时使用的名称,这也是让团队里的老成员能很快适应这个框架的一个原因。
上面基本上就是对数据库及数据表(DataTable)进行基本操作的封装。而数据表及数据行的定义如下:
- typedef class CppSQLite3Table
- {
- public:
- CppSQLite3Table();
- CppSQLite3Table(const CppSQLite3Table& rTable);
- CppSQLite3Table(char** paszResults, int nRows, int nCols);
- virtual ~CppSQLite3Table();
- CppSQLite3Table& operator=(const CppSQLite3Table& rTable);
- int fieldsCount();
- int rowsCount();
- const char* fieldName(int nCol);
- const char* fieldValue(int nField);
- const char* operator[](int nField);
- const char* fieldValue(const char* szField);
- const char* operator[](const char* szField);
- int getIntField(int nField, int nNullValue=0);
- int getIntField(const char* szField, int nNullValue=0);
- double getFloatField(int nField, double fNullValue=0.0);
- double getFloatField(const char* szField, double fNullValue=0.0);
- const char* getStringField(int nField, const char* szNullValue="");
- const char* getStringField(const char* szField, const char* szNullValue="");
- bool fieldIsNull(int nField);
- bool fieldIsNull(const char* szField);
- void setRow(int nRow);
- const CppSQLite3TableRow getRow(int nRow);
- void finalize();
- private:
- void checkResults();
- int mnCols;
- int mnRows;
- int mnCurrentRow;
- char** mpaszResults;
- } Table;
- typedef class CppSQLite3TableRow
- {
- private:
- Table& inTable;
- public:
- const char* operator[](int nField);
- const char* operator[](const char* szField);
- CppSQLite3TableRow( Table& table):inTable(table){}
- virtual ~CppSQLite3TableRow(void)
- {};
- } Row;
