-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (41 loc) · 1.41 KB
/
main.cpp
File metadata and controls
45 lines (41 loc) · 1.41 KB
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
#include "sqlite3.h"
#include <sstream>
#include <iostream>
int sqltest()
{
sqlite3 *db;
//char *errMsg = 0;
//int rc;
// Open a database connection
sqlite3_open("example.db", &db);
// Create a table
const char *sqlCreateTable = "CREATE TABLE IF NOT EXISTS company("
"id INT PRIMARY KEY NOT NULL,"
"name TEXT NOT NULL,"
"age INT NOT NULL,"
"address CHAR(50),"
"salary REAL );";
sqlite3_exec(db, sqlCreateTable, 0, 0, 0);
sqlite3_exec(db, "BEGIN TRANSACTION;", 0, 0, 0);
std::ostringstream oStringStream;
for (int i = 1; i <= 1000; ++i)
{
oStringStream << "INSERT OR IGNORE INTO company (id, name, age, address, salary) "
<< "VALUES (" << i << ", 'Name" << i << "', " << (20 + i % 50) << ", 'Address" << i << "', " << (30000 + i * 100) << "); ";
}
std::cout << oStringStream.str() << "\n";
std::string sqlInsert = oStringStream.str(); //.str() is from sstream
sqlite3_exec(db, sqlInsert.c_str(), 0, 0, 0);
sqlite3_exec(db, "COMMIT;", 0, 0, 0);
sqlite3_close(db);
return 0;
}
// TODO:
// (1) Grabbing values from the database
// (2) delete values from the database
// (3) modify values from database
int main ()
{
std::cout << "Program Ran Successfully!\n";
return 0;
}