Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include "sqlite3.h"
- #include <iostream>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- sqlite3 *db;
- const char *filename;
- filename = "My First Database";
- int rc;
- char *error;
- rc = sqlite3_open(filename, &db);
- if (rc){
- cerr << "Error opening SQLite3 database: " << sqlite3_errmsg(db) << endl << endl;
- sqlite3_close(db);
- return 1;
- }
- else
- cout << "Opened MyDb.db." << endl << endl;
- const char *sqlCreateTable = "CREATE TABLE fuasaks(name varchar(10) PRIMARY KEY, age int);";
- rc = sqlite3_exec(db, sqlCreateTable, NULL, NULL, &error);
- if (rc){
- cerr << "Error executing SQLite3 statement: " << sqlite3_errmsg(db) << endl << endl;
- sqlite3_free(error);
- }
- else
- cout << "Created MyTable." << endl << endl;
- // Execute SQL
- cout << "Inserting a value into MyTable ..." << endl;
- const char *sqlInsert = "INSERT INTO fuasaks VALUES('Ray Fausak', 22);";
- rc = sqlite3_exec(db, sqlInsert, NULL, NULL, &error);
- if (rc){
- cout << "Error executing SQLite3 statement: " << sqlite3_errmsg(db) << endl << endl;
- sqlite3_free(error);
- }
- else
- cout << "Inserted a value into fausaks.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment