设为首页 加入收藏

TOP

当C++遇到IOS应用开发(三)
2013-01-01 14:51:34 来源: 作者: 【 】 浏览:779
Tags:遇到 IOS 应用开发

 

  [cpp]

  int nRowsToCreate(50000);

  cout 《 endl 《 "Transaction test, creating " 《 nRowsToCreate;

  cout 《 " rows please wait…" 《 endl;

  DBHelper::execNoQuery("begin transaction;");

  for (int i = 0; i < nRowsToCreate; i++)

  {

  char buf[128];

  sprintf(buf, "insert into emp values (%d, 'Empname%06d');", i, i);

  DBHelper::execNoQuery(buf);

  }

  DBHelper::execNoQuery("commit transaction;");

  进行select count操作:

  [cpp]

  cout 《 DBHelper::execScalar("select count(*) from emp;") 《 " rows in emp table in ";

  使用Buffer进行SQL语句构造:

  [cpp]

  Buffer bufSQL;

  bufSQL.format("insert into emp (empname) values (%Q);", "He's bad");

  cout 《 (const char*)bufSQL 《 endl;

  DBHelper::execNoQuery(bufSQL);

  DBHelper::execNoQuery(bufSQL);

  bufSQL.format("insert into emp (empname) values (%Q);", NULL);

  cout 《 (const char*)bufSQL 《 endl;

  DBHelper::execNoQuery(bufSQL);

  遍历数据集方式1:

  [cpp]

  Query q = DBHelper::execQuery("select * from emp order by 1;");

  for (int fld = 0; fld < q.fieldsCount(); fld++){

  cout 《 q.fieldName(fld) 《 "(" 《 q.fieldDeclType(fld) 《 ")|";

  }

  cout 《 endl;

  while (!q.eof()){

  cout 《 q.fieldValue(0) 《 "|" ;

  cout 《 q.fieldValue(1) 《 "|" 《 endl;

  cout 《 q.fieldValue("empno") 《 "||" ;

  cout 《 q.fieldValue("empname") 《 "||" 《 endl;

  //或使用[]索引,效果同q.fieldValue

  cout 《 q[0] 《 "|" ;

  cout 《 q 《 "|" 《 endl;

  cout 《 q["empno"] 《 "||" ;

  cout 《 q["empname"] 《 "||" 《 endl;

  q.nextRow();

  }

  遍历数据集方式2:

  [cpp]

  Table t = DBHelper::getTable("select * from emp order by 1;");

  for (int fld = 0; fld < t.fieldsCount(); fld++){

  cout 《 t.fieldName(fld) 《 "|";

  }

  for (int row = 0; row < t.rowsCount(); row++){

  Row r= t.getRow(row);

  cout 《 r["empno"] 《 " " 《 r["empname"] 《 "|";

  cout 《 endl;

  }

  预编译Statements测试(使用场景不多):

  [cpp]

  cout 《 endl 《 "Transaction test, creating " 《 nRowsToCreate;

  cout 《 " rows please wait…" 《 endl;

  DBHelper::execNoQuery("drop table emp;");

  DBHelper::execNoQuery("create table emp(empno int, empname char(20));");

  DBHelper::execNoQuery("begin transaction;");

  Statement stmt = DBHelper::compileStatement("insert into emp values (?, );");

  for (int i = 0; i < nRowsToCreate; i++){

  char buf[16];

  sprintf(buf, "EmpName%06d", i);

  stmt.bind(1, i);

  stmt.bind(2, buf);

  stmt.execDML();

  stmt.reset();

  }

  DBHelper::execNoQuery("commit transaction;");

  最后我们只要找一个相应的。m文件改成。mm后缀,将上面测试语句执行一下,就可以了。

        

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇关于大数据批量更新的问题 下一篇The Hamming Distance&..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: