-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotlodbc.cpp
74 lines (60 loc) · 1.99 KB
/
otlodbc.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define OTL_ODBC // CompileOTL 4.0/ODBC
#define OTL_ODBC_UNIX // uncomment this line if UnixODBC is used
//#define OTL_UNICODE // Compile OTL with Unicode --->屏蔽 使用时中文显示乱码
#include "otlv4.h" // include the OTL 4.0 header file
otl_connect db; // connect object
void select()
{
try{
otl_stream ostream1(500, // buffer size
"select * from otluser.company;",// SELECT statement
db // connect object
);
// create select stream
int id;
int age;
unsigned char name[255];
unsigned char address[255];
double salary;
while(!ostream1.eof())
{ // while not end-of-data
//ostream1>>id>>user>>name;
ostream1>>id;
ostream1>>name;
ostream1>>age;
ostream1>>address;
ostream1>>salary;
cout<<"id="<<id<<endl;
cout<<"age="<<age<<endl;
cout<<"name="<<name<<endl;
}
}
catch(otl_exception& p)
{ // intercept OTL exceptions
cout<<"otl_exception:"<<endl;
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
cerr<<p.var_info<<endl; // print out the variable that caused the error
}
}
int main()
{
otl_connect::otl_initialize(); // initialize the database API environment
try{
db.rlogon("DSN=pgsql;UID=postgres;PWD=postgres;database=otlodbc"); // connect to the database
select(); // select records from table
}
catch(otl_exception& p){ // intercept OTL exceptions
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
cerr<<p.var_info<<endl; // print out the variable that caused the error
}
db.logoff(); // disconnect from the database
return 0;
}