Advertisement
obernardovieira

Basic SQLite example

Apr 25th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include "sqlite3.h"   
  3.  
  4. int main() {
  5.     sqlite3* db;
  6.     sqlite3_open("database.db", &db);
  7.  
  8.     sqlite3_stmt* stmt;
  9.     sqlite3_prepare_v2(db, "SELECT name1, name2 FROM tablename", -1, &stmt, NULL);
  10.  
  11.     while (sqlite3_step(stmt) == SQLITE_ROW) {
  12.         std::cout << (char*)sqlite3_column_text(stmt, 0) << (char*)sqlite3_column_text(stmt, 1) << std::endl;
  13.     }
  14.  
  15.     sqlite3_finalize(stmt);
  16.     sqlite3_close(db);
  17.  
  18.     return 1;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement