#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define OTL_ODBC_MULTI_MODE // Compile OTL 4.0/ODBC multi-mode
// #define OTL_ODBC_UNIX // uncomment this line if UnixODBC is used
#include <otlv4.h> // include the OTL 4.0 header file
otl_connect db; // connect object
void insert(const int buf_size)
// insert rows into table
{
otl_stream o(buf_size,
"insert into test_tab values(:f1<int>,:f2<char[31]>)",
// SQL statement
db // connect object
);
char tmp[32];
for(int i=1;i<=100;++i){
#if defined(_MSC_VER)
#if (_MSC_VER >= 1400) // VC++ 8.0 or higher
sprintf_s(tmp,sizeof(tmp),"Name%d",i);
#else
sprintf(tmp,"Name%d",i);
#endif
#else
sprintf(tmp,"Name%d",i);
#endif
o<<i<<tmp;
}
}
void update(const int af1, const int buf_size)
// insert rows into table
{
otl_stream o(buf_size,
"UPDATE test_tab "
" SET f2=:f2<char[31]> "
" WHERE f1=:f1<int>",
// UPDATE statement
db // connect object
);
o.set_commit(0); // turn OFF the stream's "auto-commit"
o<<"Name changed"<<af1;
o<<otl_null()<<af1+1; // set f2 to NULL
}
void select(const int af1, const int buf_size)
{
otl_stream i(buf_size,
"select * from test_tab "
"where f1>=:f11<int> "
" and f1<=:f12<int>*2",
// SELECT statement
db // connect object
);
// create select stream
int f1;
char f2[31];
i<<af1<<af1; // :f11 = af1, :f12 = af1
while(!i.eof()){ // while not end-of-data
i>>f1;
cout<<"f1="<<f1<<", f2=";
i>>f2;
if(i.is_null())
cout<<"NULL";
else
cout<<f2;
cout<<endl;
}
}
int main()
{
otl_connect::otl_initialize(); // initialize ODBC environment
try{
// ===================== Sybase via ODBC ======================================
db.set_connection_mode(OTL_DEFAULT_ODBC_CONNECT);
db.rlogon("scott/tigger@sybsql");
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 int, f2 varchar(30))"
); // create table
db.commit();
cout<<"============== Sybase via ODBC ====================="<<endl;
insert(10); // insert records into the table
update(10,10); // update records in the table
select(8,10); // select records from the table
cout<<"===================================================="<<endl;
db.logoff(); // disconnect from ODBC
// ===================== TimesTen via ODBC ======================================
db.set_connection_mode(OTL_TIMESTEN_ODBC_CONNECT);
db.rlogon("scott/tiger@TT_tt70_32");
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 int, f2 varchar(30))"
); // create table
db.commit();
cout<<"============== TimesTen via TimesTen ODBC driver ==================="<<endl;
insert(10); // insert records into the table
update(10,10); // update records in the table
select(8,1); // select records from the table,
// stream buffer size should be set to 1
// when connected to TimesTen via TimesTen ODBC driver
cout<<"===================================================================="<<endl;
db.logoff(); // disconnect from ODBC
// ===================== MS SQL 2005 via ODBC ==============================
db.set_connection_mode(OTL_MSSQL_2005_ODBC_CONNECT);
db.rlogon("scott/tiger@mssql");
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 int, f2 varchar(30))"
); // create table
db.commit();
cout<<"=========== MS SQL 2005 via ODBC ==================="<<endl;
insert(10); // insert records into the table
update(10,10); // update records in the table
select(8,10); // select records from the table
cout<<"===================================================="<<endl;
db.logoff(); // disconnect from ODBC
// ===================== PostgreSQL via ODBC ==============================
db.set_connection_mode(OTL_POSTGRESQL_ODBC_CONNECT);
db.rlogon("scott/tiger@postgresql");
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 int, f2 varchar(30))"
); // create table
db.commit();
cout<<"=========== PostgreSQL via ODBC ==================="<<endl;
insert(10); // insert records into the table
update(10,10); // update records in the table
select(8,10); // select records from the table
cout<<"===================================================="<<endl;
db.logoff(); // disconnect from ODBC
// ===================== EntipriseDB via ODBC ==============================
db.set_connection_mode(OTL_ENTERPRISE_DB_ODBC_CONNECT);
db.rlogon("scott/tiger@edbsql");
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 int, f2 varchar(30))"
); // create table
db.commit();
cout<<"=========== Enterprise DB via ODBC ================="<<endl;
insert(10); // insert records into the table
update(10,10); // update records in the table
select(8,10); // select records from the table
cout<<"===================================================="<<endl;
db.logoff(); // disconnect from ODBC
// ===================== MySQL via ODBC ==============================
db.set_connection_mode(OTL_MYODBC35_ODBC_CONNECT);
db.rlogon("scott/tiger@mysql35");
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 int, f2 varchar(30))"
); // create table
db.commit();
cout<<"=========== MySQL via MyODBC 3.5 ==================="<<endl;
insert(1); // insert records into the table, stream buffer size should be set to 1
update(10,1); // update records in the table, stream buffer size should be set to 1
select(8,10); // select records from the table
cout<<"===================================================="<<endl;
db.logoff(); // disconnect from ODBC
}
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.sqlstate<<endl; // print out SQLSTATE message
cerr<<p.var_info<<endl; // print out the variable that caused the error
}
db.logoff(); // disconnect from ODBC
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
OTL4 example (681个子文件)
ex675_odbc.cpp 7KB
ex585_oci9.cpp 7KB
ex153_oci8.cpp 7KB
ex473_oci7.cpp 7KB
ex391_odbc.cpp 6KB
ex387_db2.cpp 6KB
ex393_odbc.cpp 6KB
ex390_odbc.cpp 6KB
ex389_odbc.cpp 6KB
ex395_odbc.cpp 6KB
ex392_odbc.cpp 6KB
ex444_odbc.cpp 6KB
ex445_odbc.cpp 6KB
ex394_odbc.cpp 6KB
ex498_odbc.cpp 6KB
ex388_db2.cpp 6KB
ex128_odbc.cpp 6KB
ex497_odbc.cpp 6KB
ex129_odbc.cpp 6KB
ex151_oci8.cpp 6KB
ex346_odbc.cpp 6KB
ex345_odbc.cpp 6KB
ex318_odbc.cpp 6KB
ex317_odbc.cpp 6KB
ex125_odbc.cpp 6KB
ex124_odbc.cpp 6KB
ex500_odbc.cpp 6KB
ex441_odbc.cpp 6KB
ex501_odbc.cpp 6KB
ex440_odbc.cpp 6KB
ex413_odbc.cpp 6KB
ex337_odbc.cpp 6KB
ex412_odbc.cpp 6KB
ex338_odbc.cpp 6KB
ex319_db2.cpp 6KB
ex320_db2.cpp 6KB
ex126_db2.cpp 6KB
ex127_db2.cpp 6KB
ex208_oci8.cpp 6KB
ex315_oci8.cpp 6KB
ex316_oci8.cpp 6KB
ex122_oci8.cpp 5KB
ex123_oci8.cpp 5KB
ex258_oci8.cpp 5KB
ex257_oci7.cpp 5KB
ex643_odbc.cpp 5KB
ex385_oci8.cpp 5KB
ex386_oci8.cpp 5KB
ex531_odbc.cpp 5KB
ex120_odbc.cpp 5KB
ex378_oci8.cpp 5KB
ex604_odbc.cpp 5KB
ex119_oci8.cpp 5KB
ex42_oci8_odbc.cpp 5KB
ex246_oci8.cpp 5KB
ex652_odbc.cpp 5KB
ex247_odbc.cpp 5KB
ex411_odbc.cpp 5KB
ex245_oci8.cpp 5KB
ex121_db2.cpp 5KB
ex383_odbc.cpp 5KB
ex613_odbc.cpp 5KB
ex248_db2.cpp 5KB
ex244_oci7.cpp 5KB
ex150_oci8.cpp 5KB
ex432_odbc.cpp 5KB
ex199_oci9.cpp 5KB
ex185_oci8.cpp 5KB
ex381_odbc.cpp 5KB
ex515_odbc.cpp 5KB
ex523_odbc.cpp 5KB
ex184_oci8.cpp 5KB
ex198_oci9.cpp 5KB
ex384_odbc.cpp 5KB
ex382_odbc.cpp 5KB
ex644_odbc.cpp 4KB
ex205_oci8.cpp 4KB
ex380_db2.cpp 4KB
ex379_oci8.cpp 4KB
ex171_db2.cpp 4KB
ex57_oci8.cpp 4KB
ex431_odbc.cpp 4KB
ex56_oci8.cpp 4KB
ex605_odbc.cpp 4KB
ex131_odbc.cpp 4KB
ex207_db2.cpp 4KB
ex130_oci8.cpp 4KB
ex574_odbc.cpp 4KB
ex414_odbc.cpp 4KB
ex206_odbc.cpp 4KB
ex132_db2.cpp 4KB
ex113_oci8.cpp 4KB
ex423_odbc.cpp 4KB
ex149_oci8.cpp 4KB
ex609_odbc.cpp 4KB
ex560_odbc.cpp 4KB
ex648_odbc.cpp 4KB
ex641_odbc.cpp 4KB
ex115_db2.cpp 4KB
ex114_odbc.cpp 4KB
共 681 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
guan01517
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论3