手机版
你好,游客 登录 注册
背景:
阅读新闻

当C++遇到iOS应用开发---SQLite篇

[日期:2012-11-07] 来源:www.cnblogs.com/daizhj  作者:daizhj, 代震军 [字体:大 中 小]

需要注意的是这里使用的某些方法名称是基于笔者以前开发DISCUT!NT时使用的DBHelper.cs类时使用的名称,这也是让团队里的老成员能很快适应这个框架的一个原因。

上面基本上就是对数据库及数据表(DataTable)进行基本操作的封装。而数据表及数据行的定义如下:

  1. typedef class CppSQLite3Table 
  2. { 
  3. public: 
  4.  
  5.     CppSQLite3Table(); 
  6.  
  7.     CppSQLite3Table(const CppSQLite3Table& rTable); 
  8.  
  9.     CppSQLite3Table(char** paszResults, int nRows, int nCols); 
  10.  
  11.     virtual ~CppSQLite3Table(); 
  12.  
  13.     CppSQLite3Table& operator=(const CppSQLite3Table& rTable); 
  14.  
  15.     int fieldsCount(); 
  16.  
  17.     int rowsCount(); 
  18.  
  19.     const char* fieldName(int nCol); 
  20.  
  21.     const char* fieldValue(int nField); 
  22.     const char* operator[](int nField); 
  23.  
  24.     const char* fieldValue(const char* szField); 
  25.     const char* operator[](const char* szField); 
  26.          
  27.     int getIntField(int nField, int nNullValue=0); 
  28.     int getIntField(const char* szField, int nNullValue=0); 
  29.  
  30.     double getFloatField(int nField, double fNullValue=0.0); 
  31.     double getFloatField(const char* szField, double fNullValue=0.0); 
  32.  
  33.     const char* getStringField(int nField, const char* szNullValue=""); 
  34.     const char* getStringField(const char* szField, const char* szNullValue=""); 
  35.  
  36.     bool fieldIsNull(int nField); 
  37.     bool fieldIsNull(const char* szField); 
  38.  
  39.     void setRow(int nRow); 
  40.     const CppSQLite3TableRow getRow(int nRow); 
  41.  
  42.     void finalize(); 
  43.  
  44. private: 
  45.  
  46.     void checkResults(); 
  47.  
  48.     int mnCols; 
  49.     int mnRows; 
  50.     int mnCurrentRow; 
  51.     char** mpaszResults; 
  52. } Table; 
  53.  
  54. typedef class CppSQLite3TableRow 
  55. { 
  56. private: 
  57.     Table& inTable; 
  58. public: 
  59.     const char* operator[](int nField); 
  60.     const char* operator[](const char* szField); 
  61.     CppSQLite3TableRow( Table& table):inTable(table){} 
  62.     virtual ~CppSQLite3TableRow(void) 
  63.     {}; 
  64.  
  65. } Row; 
linux
相关资讯       C++  iOS应用开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款