René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback
 

SQLite Wrapper, test 4

This test demonstrates how values can be selected from a table using SQLiteWrapper::Statement(), SQLiteWrapper::NextRow(), SQLiteWrapper::DataType() and SQLiteWrapper::ValueString().
Statement() returns a pointer to a SQLiteStatement. The values for the the select statement can then be retrieved through that returned class.
NextRow() returns true as long as there are still records to be fetched.
DataType() returns the datatype for the passed column.
ValueString() returns the value as std::string.
It is assumed that a database with the name SQLiteWrapper.db is already created and that it contains a table named foo. (This is done with test 1, test 2 and test 3).
test_4.cpp
#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("select * from foo");

  while (stmt->NextRow()) {
    std::cout << stmt->DataType   (0) << " - " << stmt->DataType   (1) << " | " <<
                 stmt->ValueString(0) << " - " << stmt->ValueString(1) << std::endl;
  }

  return 0;
}