求助: 请用过otl的xdjm们帮帮忙
我在用otl做数据库开发的时候碰到了以下问题需要解决,请有经验的xdjm们帮帮忙。谢谢了先。
1. 我想在insert的同时获得表里面的自增的key,用otl应该怎么实现?
比如说表是这样的: create table mytable(f1 int not null identity, f2 int);
其中f1是自增的,我想在insert一个f2的时候就获得这个自增的f1,该使用什么办法呢?
2. 如下代码会报错,我快晕了,为这个事情我搞了好几天了,还没有解决。
代码如下(开发环境:vs2008+sqlserver2000, 已经编译通过):
#include <iostream>
using namespace std;
#include <stdio.h>
#define OTL_ODBC // Compile OTL 4/ODBC, MS SQL 2008
#include "otlv4.h" // include the OTL 4.0 header file
otl_connect db; // connect object
int main()
{
otl_connect:tl_initialize(); // initialize ODBC environment
try{
db.rlogon("dev/11111111@mssql_dev"; // connect to ODBC
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)"
); // create table
otl_cursor::direct_exec(db, "DROP PROCEDURE my_insert", 0);
otl_cursor::direct_exec(db,
"CREATE PROCEDURE my_insert "
"@F1 int "
"as "
"set nocount on "
"insert into test_tab(f1) values(@F1) "
);
otl_stream i(50, // buffer size
" exec my_insert :f1<int,in> ",
db, // connect object
otl_implicit_select // implicit SELECT statement
);
int f1=20;
try{
i<<f1;
}catch(otl_exception& p){
cerr<<"===> A database exception is caught: "<<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
cerr<<"===> Cleaning up the stream's error flags"<<endl;
i.clean();
}
}
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 ODBC
return 0;
}
所得到的错误结果如下:
===> A database exception is caught:
[Microsoft][ODBC SQL Server Driver]Invalid cursor state
exec my_insert ?
===> Cleaning up the stream's error flags
Press any key to continue . . .
这样的情况相当郁闷,老是搞不定,快奔溃了,请有经验的xdjm们给点意见,谢谢啦。
1. 我想在insert的同时获得表里面的自增的key,用otl应该怎么实现?
比如说表是这样的: create table mytable(f1 int not null identity, f2 int);
其中f1是自增的,我想在insert一个f2的时候就获得这个自增的f1,该使用什么办法呢?
2. 如下代码会报错,我快晕了,为这个事情我搞了好几天了,还没有解决。
代码如下(开发环境:vs2008+sqlserver2000, 已经编译通过):
#include <iostream>
using namespace std;
#include <stdio.h>
#define OTL_ODBC // Compile OTL 4/ODBC, MS SQL 2008
#include "otlv4.h" // include the OTL 4.0 header file
otl_connect db; // connect object
int main()
{
otl_connect:tl_initialize(); // initialize ODBC environment
try{
db.rlogon("dev/11111111@mssql_dev"; // connect to ODBC
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)"
); // create table
otl_cursor::direct_exec(db, "DROP PROCEDURE my_insert", 0);
otl_cursor::direct_exec(db,
"CREATE PROCEDURE my_insert "
"@F1 int "
"as "
"set nocount on "
"insert into test_tab(f1) values(@F1) "
);
otl_stream i(50, // buffer size
" exec my_insert :f1<int,in> ",
db, // connect object
otl_implicit_select // implicit SELECT statement
);
int f1=20;
try{
i<<f1;
}catch(otl_exception& p){
cerr<<"===> A database exception is caught: "<<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
cerr<<"===> Cleaning up the stream's error flags"<<endl;
i.clean();
}
}
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 ODBC
return 0;
}
所得到的错误结果如下:
===> A database exception is caught:
[Microsoft][ODBC SQL Server Driver]Invalid cursor state
exec my_insert ?
===> Cleaning up the stream's error flags
Press any key to continue . . .
这样的情况相当郁闷,老是搞不定,快奔溃了,请有经验的xdjm们给点意见,谢谢啦。
作者: white_ideal 发布时间: 2011-06-13
没想到表情会自动插到文字里面,重发一遍。
我在用otl做数据库开发的时候碰到了以下问题需要解决,请有经验的xdjm们帮帮忙。谢谢了先。
1. 我想在insert的同时获得表里面的自增的key,用otl应该怎么实现?
比如说表是这样的: create table mytable(f1 int not null identity, f2 int);
其中f1是自增的,我想在insert一个f2的时候就获得这个自增的f1,该使用什么办法呢?
2. 如下处理会报错,我快晕了,为这个事情我搞了好几天了,还没有解决。
代码如下(开发环境:vs2008+sqlserver2000, 已经编译通过):
#include <iostream>
using namespace std;
#include <stdio.h>
#define OTL_ODBC // Compile OTL 4/ODBC, MS SQL 2008
#include "otlv4.h" // include the OTL 4.0 header file
otl_connect db; // connect object
int main()
{
otl_connect:: otl_initialize(); // initialize ODBC environment
try{
db.rlogon("dev/11111111@mssql_dev" ) ; // connect to ODBC
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)"
); // create table
otl_cursor::direct_exec(db, "DROP PROCEDURE my_insert", 0);
otl_cursor::direct_exec(db,
"CREATE PROCEDURE my_insert "
"@F1 int "
"as "
"set nocount on "
"insert into test_tab(f1) values(@F1) "
);
otl_stream i(50, // buffer size
" exec my_insert :f1<int,in> ",
db, // connect object
otl_implicit_select // implicit SELECT statement
);
int f1=20;
try{
i<<f1;
}catch(otl_exception& p){
cerr<<"===> A database exception is caught: "<<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
cerr<<"===> Cleaning up the stream's error flags"<<endl;
i.clean();
}
}
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 ODBC
return 0;
}
所得到的错误结果如下:
===> A database exception is caught:
[Microsoft][ODBC SQL Server Driver]Invalid cursor state
exec my_insert ?
===> Cleaning up the stream's error flags
Press any key to continue . . .
这样的情况相当郁闷,老是搞不定,快奔溃了,请有经验的xdjm们给点意见,谢谢啦。
我在用otl做数据库开发的时候碰到了以下问题需要解决,请有经验的xdjm们帮帮忙。谢谢了先。
1. 我想在insert的同时获得表里面的自增的key,用otl应该怎么实现?
比如说表是这样的: create table mytable(f1 int not null identity, f2 int);
其中f1是自增的,我想在insert一个f2的时候就获得这个自增的f1,该使用什么办法呢?
2. 如下处理会报错,我快晕了,为这个事情我搞了好几天了,还没有解决。
代码如下(开发环境:vs2008+sqlserver2000, 已经编译通过):
#include <iostream>
using namespace std;
#include <stdio.h>
#define OTL_ODBC // Compile OTL 4/ODBC, MS SQL 2008
#include "otlv4.h" // include the OTL 4.0 header file
otl_connect db; // connect object
int main()
{
otl_connect:: otl_initialize(); // initialize ODBC environment
try{
db.rlogon("dev/11111111@mssql_dev" ) ; // connect to ODBC
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)"
); // create table
otl_cursor::direct_exec(db, "DROP PROCEDURE my_insert", 0);
otl_cursor::direct_exec(db,
"CREATE PROCEDURE my_insert "
"@F1 int "
"as "
"set nocount on "
"insert into test_tab(f1) values(@F1) "
);
otl_stream i(50, // buffer size
" exec my_insert :f1<int,in> ",
db, // connect object
otl_implicit_select // implicit SELECT statement
);
int f1=20;
try{
i<<f1;
}catch(otl_exception& p){
cerr<<"===> A database exception is caught: "<<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
cerr<<"===> Cleaning up the stream's error flags"<<endl;
i.clean();
}
}
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 ODBC
return 0;
}
所得到的错误结果如下:
===> A database exception is caught:
[Microsoft][ODBC SQL Server Driver]Invalid cursor state
exec my_insert ?
===> Cleaning up the stream's error flags
Press any key to continue . . .
这样的情况相当郁闷,老是搞不定,快奔溃了,请有经验的xdjm们给点意见,谢谢啦。
作者: white_ideal 发布时间: 2011-06-13