Comments (3)
Check the example here #216 (comment)
from nanodbc.
I'm working on figuring this out as well. I think what is meant here is a return value for a stored procedure, rather than a parameter for a stored procedure that is listed as output.
In MSSQL, you can use the return statement to return a value to the caller.
If you raiseerror (don't know about throw yet, as I'm on 2008) then the return value of your procedure is negative and depends on the argument you used.
If you don't specify a return value and it succeeds, the return value is zero. This so thread summarizes that:
I've been using the other syntax for calling my procedures rather than execute, and I found this page that suggests using
{? = CALL procname (?,?)}
But when I bind the first question mark as an int, I get Invalid parameter type
in the catch
Here's an example if it helps.
try {
nanodbc::connection connection(get_connection_string(),5);
nanodbc::statement statement(connection);
statement.timeout(5);
prepare(statement,"{? = CALL [test_nanodbc](?)};");
int returnVal;
statement.bind(0,&returnVal);
char outParam[50];
statement.bind_strings(1,outParam,(size_t)50,(size_t)1,nanodbc::statement::PARAM_OUT);
nanodbc::result r = statement.execute();
if(outParam!= "test") print(outParam);
if(returnVal == 0) print("success");
else print("Failure");
}
catch(const std::exception& e) {
print("Could not call procedure %s", e.what());
}
from nanodbc.
Okay, I wasn't binding it as a return param, but the syntax using the question marks and binding works. Try something like this:
nanodbc::connection connection(get_connection_string(),5);
nanodbc::statement statement(connection);
statement.timeout(5);
prepare(statement,"{? = CALL [test_nanodbc](?)};");
int returnVal;
statement.bind(0,&returnVal,nanodbc::statement::PARAM_RETURN);
char outParam[50];
statement.bind_strings(1,outParam,(size_t)50,(size_t)1,nanodbc::statement::PARAM_OUT);
try {
nanodbc::result r = statement.execute();
}
catch(const std::exception& e){}
print(returnVal);
Do note, however (for MSSQL Server 2008 at least) that if ANSI null warnings are produced by your stored procedure, then it messes with the return value of the stored procedure and will even prevent nanodbc from raising an exception. I'm trying to figure that out right now and I'll try to post back if I figure that out.
from nanodbc.
Related Issues (20)
- Cannot compile to C++17 standard without -fpermissive HOT 4
- result::get<nanodbc::string>(string const& column_name) truncat to 255 bytes HOT 3
- Connection busy error in test program HOT 1
- value exception throws when using batch-insert to insert one row HOT 3
- build fails as git submodule
- Add support for SQL_DRIVER_VER HOT 1
- The long string in the result read from the parquet file will be truncated. HOT 1
- Request advice on serializing result-sets to JSON HOT 6
- Encoding for query on SQLServer break characters
- nanodbc exceptions not containing all function output messages HOT 2
- error C2665: 'std::list<nanodbc::connection::attribute,std::allocator<nanodbc::connection::attribute>>::push_back': no overloaded function could convert all the argument types HOT 7
- Add CI jobs using Visual Studio 2022
- Invalid parameter number when using placeholder within a Common Table Expression HOT 1
- "Fetch type out of range" error when calling result.prior(), result.first(), result.last() or result.at_end() HOT 1
- Improve auto_bind_columns to recognise fine-grained types
- docs: Explore migration to hdoc.io for API reference
- FR: support sql-server datetimeoffset HOT 4
- Remove #if __GNUC__ conditions and its cases
- Compilation fails due to the use of deprecated features HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanodbc.