/SqliteWrapper

Simple RAII C++ Sqlite wrapper

Primary LanguageC++

SqliteWrapper

Simple RAII C++ Sqlite wrapper.

Important : This library only support inserting row and cannot read from database

Creating database

 std::string databaseLocation = "test.db3";

 SqliteConnection connection{databaseLocation};

 connection.exec("CREATE TABLE MyTable(Column1 text,Column2 real);")

Inserting rows

  std::string databaseLocation = "test.db3";

  SqliteConnection connection{databaseLocation};

  SqliteTransaction transaction{connection};

  SqliteStatement statement{connection,"INSERT INTO MyTable(Column1,Column2) VALUES(?,?);"};

  bool canCommit = true;

  //insert multiple row

  for(auto i=0;i<data.size();i++){

      //bind the parameter

      statement.bindString(1,data[i].getStr());
      statement.bindDouble(2,data[i].getDouble());

      //check whether we can insert row
      
      if(!statement.step()){

        canCommit = false;

        break;
      }

      statement.reset();
  }
  
  if(canCommit){
    //commit the transaction

    transaction.commit();
  }