test3.cpp

来自「这是一个文件型数据库的学习资料」· C++ 代码 · 共 61 行

CPP
61
字号
#include <iostream>

#include "SQLiteWrapper.h"

int main() {
  SQLiteWrapper sqlite;
  if (sqlite.Open("SQLiteWrapper.db")) {
    std::cout << "SQLiteWrapper.db created or opened" << std::endl;
  }
  else {
    std::cout << "couldn't open SQLiteWrapper.db"     << std::endl;
  }

  SQLiteStatement* stmt = sqlite.Statement("insert into foo values (?, ?)");

  if (stmt->Bind(0, 3)) {
    std::cout << "value 3 successfully bound at pos 0" << std::endl;
  }
  else {
    std::cout << "value 3 NOT successfully bound at pos 0: " << sqlite.LastError() << std::endl;
  }
  if (stmt->Bind(1, 4)) {
    std::cout << "value 4 successfully bound at pos 1" << std::endl;
  }
  else {
    std::cout << "value 4 NOT successfully bound at pos 1:" << sqlite.LastError() << std::endl;
  }

  // ******************************** Executing 1st time
  if (stmt->Execute()) {
    std::cout << "statement executed" << std::endl;
  }
  else {
    std::cout << "error executing statement: " << sqlite.LastError() << std::endl;
  }

  if (stmt->Bind(0, 5)) {
    std::cout << "value 5 successfully bound at pos 0" << std::endl;
  }
  else {
    std::cout << "value 5 NOT successfully bound at pos 0" << std::endl;
  }

  if (stmt->Bind(1, 6)) {
    std::cout << "value 6 successfully bound at pos 1" << std::endl;
  }
  else {
    std::cout << "value 6 NOT successfully bound at pos 1" << std::endl;
  }

  // ******************************** Executing 2nd time
  if (stmt->Execute()) {
    std::cout << "statement executed" << std::endl;
  }
  else {
    std::cout << "error executing statement: " << sqlite.LastError() << std::endl;
  }

  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?