-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.cpp
More file actions
68 lines (54 loc) · 1.85 KB
/
test.cpp
File metadata and controls
68 lines (54 loc) · 1.85 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* File: test.cpp
*/
#include <iostream>
#include "Attachment.h"
#include "Transaction.h"
#include "Statement.h"
#define SERVER ...
#define DATABASE ...
/*
*
*/
int main() {
Attachment attachment;
Transaction transaction;
Statement statement;
attachment.createDatabase(SERVER, DATABASE, "sysdba", "masterkey", "UTF8");
attachment.connect();
transaction.setAttachment(&attachment);
statement.setSql("CREATE TABLE TEST (ID INTEGER PRIMARY KEY, DESC VARCHAR(10))");
statement.setTransaction(&transaction);
statement.execute();
transaction.commitRetain();
statement.setSql("INSERT INTO TEST(ID, DESC) VALUES (1, 'AAA')");
statement.execute();
statement.setSql("INSERT INTO TEST(ID, DESC) VALUES (2, 'BBB')");
statement.execute();
statement.setSql("INSERT INTO TEST(ID, DESC) VALUES (3, 'CCC')");
statement.execute();
statement.setSql("INSERT INTO TEST(ID, DESC) VALUES (4, 'DDD')");
statement.execute();
statement.setSql("INSERT INTO TEST(ID, DESC) VALUES (5, 'EEE')");
statement.execute();
transaction.commitRetain();
statement.setSql("SELECT * FROM TEST WHERE ID >= :ID");
statement.paramByName("ID").setInt(3);
statement.open();
while(statement.fetch()){
std::cout << "ID: " << statement.fieldByName("ID").asInteger();
std::cout << " DESC: " << statement.fieldByName("DESC").asString() << std::endl;
}
statement.close();
std::cout << std::endl;
statement.setSql("SELECT * FROM TEST WHERE ID <= ?");
statement.parameter(0).setInt(2);
statement.open();
while(statement.fetch()){
std::cout << "ID: " << statement.field(0).asInteger();
std::cout << " DESC: " << statement.field(1).asString() << std::endl;
}
statement.close();
attachment.disconnect();
return 0;
}