GithubHelp home page GithubHelp logo

Comments (3)

mloskot avatar mloskot commented on June 1, 2024

Check the example here #216 (comment)

from nanodbc.

thebyohazard avatar thebyohazard commented on June 1, 2024

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.

thebyohazard avatar thebyohazard commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.