-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cc
61 lines (56 loc) · 1.78 KB
/
main.cc
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
/*
* $Id: main.cc,v 1.6 2005/10/20 11:27:42 martin Exp $
* Copyright (c) 2004, 2005, Voidsoft AB
*/
#include <stdio.h>
#include <string.h>
#include <ctpublic.h>
#include <iostream>
#include <typeinfo>
#include "tdspp.hh"
using namespace std;
int main(int argc, char **argv) {
TDSPP *db = new TDSPP();
try {
/* Connect to database. */
db->connect("localhost:1433", "admin", "12345678");
/* Execute command. */
db->execute("use master");
/* Create query. */
Query *q = db->sql("select getdate() datetime_type, current_timestamp right_now, 1 integer_type, 0.1 float_type");
try {
/* Execute SQL query. */
q->execute();
/* Print table headers, ie column names. */
q->rows->printheader();
cout << "Results:" << endl;
while (!q->eof()) {
cout << "| ";
for (int i=0; i < q->fieldcount; i++) {
auto fd = q->fields(i);
auto v = fd->to_int();
auto int_t = typeid(long).hash_code();
const auto& ti = typeid(v);
string v_t = ti.name();
auto v_h = ti.hash_code();
auto v1 = fd->to_double();
auto v1_t = typeid(v1).hash_code();
auto v2 = fd->to_str();
auto v2_t = typeid(v2).hash_code();
cout << v2 << " | ";
}
cout << endl;
q->next();
}
}
catch(TDSPP::Exception &e) {
cerr << e.message << endl;
}
delete q;
}
catch(TDSPP::Exception &e) {
cerr << e.message << endl;
}
delete db;
return 0;
}