-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (39 loc) · 1.21 KB
/
main.cpp
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 <mysql++.h>
#include <iostream>
#include <iomanip>
using namespace std;
int
main(int argc, char *argv[])
{
// Connect to the sample database.
mysqlpp::Connection conn(false);
mysqlpp::Query query = conn.query();
if (conn.connect("DBname", "Server_address",
"username", "password")) {
/*INSERT*/
query = conn.query("insert into events (date,time,event) values(\"2019.05.12\", \"23:40:00\", \"Event name\")");
query.execute();
/*ENDINSERT*/
/*READ*/
query = conn.query("select * from events");
if (mysqlpp::StoreQueryResult res = query.store()) {
mysqlpp::StoreQueryResult::const_iterator it;
for (it = res.begin(); it != res.end(); ++it) {
mysqlpp::Row row = *it;
cout << '\t' << row[0] << '\t' << row[1] << '\t' << row[2] << '\t' << row[3] << endl; //id date time event
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
}
/*ENDREAD*/
/*DELETE*/
query = conn.query("delete from events where id=3");
query.execute();
}
/*ENDDELETE*/
else {
cerr << "DB connection failed: " << conn.error() << endl;
}
return 0;
}