candyapplecorn

Untitled

Jun 27th, 2014
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include "sqlite3.h"
  8. #include <iostream>
  9. using namespace std;
  10.  
  11.  
  12. int _tmain(int argc, _TCHAR* argv[])
  13. {
  14.     sqlite3 *db;
  15.     const char *filename;
  16.     filename = "My First Database";
  17.     int rc;
  18.     char *error;
  19.     rc = sqlite3_open(filename, &db);
  20.  
  21.     if (rc){
  22.         cerr << "Error opening SQLite3 database: " << sqlite3_errmsg(db) << endl << endl;
  23.         sqlite3_close(db);
  24.         return 1;
  25.     }
  26.     else
  27.         cout << "Opened MyDb.db." << endl << endl;
  28.  
  29.     const char *sqlCreateTable = "CREATE TABLE fuasaks(name varchar(10) PRIMARY KEY, age int);";
  30.     rc = sqlite3_exec(db, sqlCreateTable, NULL, NULL, &error);
  31.  
  32.     if (rc){
  33.         cerr << "Error executing SQLite3 statement: " << sqlite3_errmsg(db) << endl << endl;
  34.         sqlite3_free(error);
  35.     }
  36.     else
  37.         cout << "Created MyTable." << endl << endl;
  38.  
  39.     // Execute SQL
  40.     cout << "Inserting a value into MyTable ..." << endl;
  41.     const char *sqlInsert = "INSERT INTO fuasaks VALUES('Ray Fausak', 22);";
  42.     rc = sqlite3_exec(db, sqlInsert, NULL, NULL, &error);
  43.     if (rc){
  44.         cout << "Error executing SQLite3 statement: " << sqlite3_errmsg(db) << endl << endl;
  45.         sqlite3_free(error);
  46.     }
  47.     else
  48.         cout << "Inserted a value into fausaks.";
  49.    
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment