![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
1. how to get the autoincreasing identity immediately after inserting a row? I how you can give me the answer within mysql and sqlserver. |
|
2. why the following code is error with "invalid cursor state"? the source code is like this. |
#3
| |||
| |||
|
|
white_ideal (whiteideal (AT) gmail (DOT) com) writes: 1. how to get the autoincreasing identity immediately after inserting a row? I how you can give me the answer within mysql and sqlserver. In SQL Server, use scope_identity(), which must be in the same batch as the INSERT statement. For MySQL, you need to ask in an MySQL forum. 2. why the following code is error with "invalid cursor state"? the source code is like this. I will have to admit that I have never seen this OTL before. ^^^ |
#4
| |||
| |||
|
|
On Mon, 13 Jun 2011 07:23:03 +0000 (UTC), Erland Sommarskog esquel (AT) sommarskog (DOT) se> wrote: I will have to admit that I have never seen this OTL before. ^^^ What is this abbrev, please? |
#5
| |||
| |||
|
|
hi, everyone, thanks for your reading. I have met with some problem when using otl to program for the database. And my development environment is sqlserver2000 plus vs2008. 1. how to get the autoincreasing identity immediately after inserting a row? I how you can give me the answer within mysql and sqlserver. 2. why the following code is error with "invalid cursor state"? * * * * * * * * the source code is like this. * * * * * * * * * * * * * * * * ////////////////////////////////// * * * * * * * * * * * * * * * * #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; * * * * * * * * * * * * * * * * } and the result after running is shown in the following. * * * * * * * * * * * * * * * * ===> 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 . . . * * * * * * * * * * * * * * * * I hope these two problems can be resoved as soon as possible. And very thanks for your helps in advance. |
|
1. how to get the autoincreasing identity immediately after inserting a row? I how you can give me the answer within mysql and sqlserver. In SQL Server, use scope_identity(), which must be in the same batch as the INSERT statement. I know how to get the identity of course by using sql. But don't know |
|
2. why the following code is error with "invalid cursor state"? ? ? ? ? ? the source code is like this. I will have to admit that I have never seen this OTL before. As i said above, it's a c++ template lib for odbc. and the website is |
#6
| |||
| |||
|
|
Hey, if, you do, can you report your findings, unless white_ideal comes back and tell us? |
#7
| |||
| |||
|
|
I know how to get the identity of course by using sql. But don't know how to get it using the interface from otl. It's so difficult to implement in otl. And I am a little regret to use otl in my project, but i have no choice at present. |
#8
| |||
| |||
|
|
white_ideal (whiteid... (AT) gmail (DOT) com) writes: I know how to get the identity of course by using sql. But don't know how to get it using the interface from otl. It's so difficult to implement in otl. And I am a little regret to use otl in my project, but i have no choice at present. So the question boils down to "how do I receive a result set through OTL"or "how do I receive an output parameter through OTL". There is nothing special with regards to the IDENTITY value. I see that they have a discussion board on the OTL web site, you may find better answers there. -- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Links for SQL Server Books Online: SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx |
#9
| |||
| |||
|
|
On 615, 5ʱ39, Erland Sommarskog <esq.... (AT) sommarskog (DOT) se> wrote: white_ideal (whiteid... (AT) gmail (DOT) com) writes: I know how to get the identity of course by using sql. But don't know how to get it using the interface from otl. It's so difficult to implement in otl. And I am a little regret to use otl in my project, but i have no choice at present. So the question boils down to "how do I receive a result set through OTL" or "how do I receive an output parameter through OTL". There is nothing special with regards to the IDENTITY value. I see that they have a discussion board on the OTL web site, you may find better answers there. -- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Links for SQL Server Books Online: SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx Yeah, that discussion board is create by myself. and the great SKuchin has emailed with me about this problem, but there is no answer at present. I'll tell you all guys the results if it's resolved. |
tl_initialize(); // initialize ODBC environment
tl_initialize(); // initialize ODBC environment![]() |
| Thread Tools | |
| Display Modes | |
| |