1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #include <iostream>
#include <string>
#include <cstdio>
#include "../../../../Sqlite/sqlite3.h"
using namespace std;
static int callback(void* data, int argc, char** argv, char** azColName)
{
fprintf(stderr, "%s: ", (const char*)data);
for (int i = 0; i < argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char** argv)
{
sqlite3* DB;
char* messaggeError;
int exit = sqlite3_open("C:/Users/Dell/Desktop/sqlite_project/mabase.db", &DB);
string query = "SELECT * FROM PERSON;";
cout << "STATE OF TABLE BEFORE INSERT" << endl;
sqlite3_exec(DB, query.c_str(), callback, NULL, NULL);
string sql("INSERT INTO PERSON VALUES(1, 'jul', 'GATES', 30, 'PALO ALTO', 1000.0);"
"INSERT INTO PERSON VALUES(2, 'BILL', 'ALLEN', 20, 'SEATTLE', 300.22);"
"INSERT INTO PERSON VALUES(3, 'PAUL', 'JOBS', 24, 'SEATTLE', 9900.0);");
exit = sqlite3_exec(DB, sql.c_str(), NULL, 0, &messaggeError);
if (exit != SQLITE_OK) {
cerr << "Error Insert" << endl;
sqlite3_free(messaggeError);
}
else
cout << "Records created Successfully!" << endl;
cout << "STATE OF TABLE AFTER INSERT" << endl;
sqlite3_exec(DB, query.c_str(), callback, NULL, NULL);
sql = "DELETE FROM PERSON WHERE ID = 2;";
exit = sqlite3_exec(DB, sql.c_str(), NULL, 0, &messaggeError);
if (exit != SQLITE_OK) {
cerr << "Error DELETE" << endl;
sqlite3_free(messaggeError);
}
else
cout << "Record deleted Successfully!" << endl;
cout << "STATE OF TABLE AFTER DELETE OF ELEMENT" << endl;
sqlite3_exec(DB, query.c_str(), callback, NULL, NULL);
sqlite3_close(DB);
return (0);
} |
Partager