Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:22:20+00:00 2026-05-30T02:22:20+00:00

I’m having problems getting this code to populate output parameters with MSSQL ODBC 10.0

  • 0

I’m having problems getting this code to populate output parameters with MSSQL ODBC 10.0 client driver and 9.0 as well. I can confirm my binding direction is being set properly.

I am also calling SQLMoreResults, my stored procedure has NOCOUNT set and works fine under another ODBC-based library.

Unfortunately once I get to my execute statement, it succeeds but SQLMoreResults always says there are no more results, and I realize that those parameters aren’t populated until it has gone through all of the result sets. The one output parameter I use is a bigint.

Unfortunately I don’t know all of the intricacies of ODBC development and there must be something important I’m missing. I do try to reuse my statement handle but I reset it after my first call to SQLProcedureColumns and remove bound variables. Then I rebind.

Any ideas as to where I’m going astray?

bool ODBCConnection::Execute()
{
    LLOG("Execute " << (void *)this << " " << (void *)session);
    if(session->hstmt == SQL_NULL_HANDLE)
        return false;
    if(IsCurrent())
        session->current = NULL;
    session->FlushConnections();
    last_insert_table.Clear();
    number.Clear();
    text.Clear();
    time.Clear();
    CParser p(statement);

    /* parse for stored procedure */

    bool isStoredProcedure = false;

    if (p.Char('{'))
    {
        p.Spaces();

          String procedure_name;

          p.Id("?");
          p.Id("=");

        if (p.Id("call") || p.Id("CALL")) {
            procedure_name = p.ReadId();
            isStoredProcedure = true;
            //Cout() << "Proc name: " << procedure_name << "\n";
        }

        SQLSetEnvAttr(session->henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER);

        SDWORD      cbValue5;
        SDWORD      cbValue4;
        SQLSMALLINT ParameterType = SQL_PARAM_INPUT;

        if (!IsOk(SQLProcedureColumns (
                      session->hstmt,
                      NULL,
                      0,
                      NULL,
                      0,
                      (SQLCHAR *)~procedure_name,
                      procedure_name.GetLength(),
                      NULL,
                      0
                  ))) {
            SQLFreeStmt(session->hstmt, SQL_CLOSE);
            return false;
        }

        char parameter_name [20];

        if (!IsOk(SQLBindCol(
                      session->hstmt,
                      4, // Column 4 returns column name
                      SQL_C_CHAR,
                      parameter_name,
                      sizeof(parameter_name),
                      &cbValue4
                  ))) {
        }

        if (!IsOk(SQLBindCol(
                      session->hstmt,
                      5, // Column 5 returns whether parameter is input or output
                      SQL_C_SHORT,
                      &ParameterType,
                      0,
                      &cbValue5
                  ))) {
        }

        int i = 0;
        while (SQLFetch(session->hstmt) == SQL_SUCCESS) {
            Param& p = param[i];

            Cout() << ParameterType << "\n";    

            /*switch (ParameterType) {
                case SQL_PARAM_INPUT:
                case SQL_PARAM_OUTPUT:
                case SQL_PARAM_INPUT_OUTPUT:
                    p.direction = ParameterType;
                    break;

                case 5:
                    p.direction = SQL_PARAM_OUTPUT;
                    break;
                default:
                    break;
            }*/

            if(ParameterType == 5)
                p.direction = SQL_PARAM_OUTPUT;
            else
                p.direction = ParameterType;

            i++;
        }

        SQLFreeStmt(session->hstmt, SQL_CLOSE);
        SQLFreeStmt(session->hstmt, SQL_RESET_PARAMS);
        SQLFreeStmt(session->hstmt, SQL_UNBIND);
    }

    if((p.Id("insert") || p.Id("INSERT")) && (p.Id("into") || p.Id("INTO")) && p.IsId())
        last_insert_table = p.ReadId();

    if(!IsOk(SQLPrepare(session->hstmt, (SQLCHAR *)~statement, statement.GetCount())))
            return false;

    parse = false;
    bparam = param;
    param.Clear();

    for(int i = 0; i < bparam.GetCount(); i++) {
        Param& p = bparam[i];
        SQLSMALLINT     DataType;
        SQLULEN         ParameterSize;
        SQLSMALLINT     DecimalDigits;
        SQLSMALLINT     Nullable;

        Cout() << "Direction: " << p.direction << "\n";
        Cout() << "Length: " << p.li << "\n";

        if(!IsOk(SQLDescribeParam(session->hstmt, i + 1, &DataType, &ParameterSize, &DecimalDigits, &Nullable)))
            return false;
        if(!IsOk(SQLBindParameter(session->hstmt, i + 1, p.direction, p.ctype, DataType,
                                  ParameterSize, DecimalDigits, (SQLPOINTER)~p.data, p.data.GetLength(),
                                  &p.li)))
            return false;
    }
    SQLSMALLINT ncol;


    if(!isStoredProcedure)
    {

        if(!IsOk(SQLExecute(session->hstmt)) || !IsOk(SQLNumResultCols(session->hstmt, &ncol))) {
            Cout() << "SQLExecute crashed\n";
            SQLFreeStmt(session->hstmt, SQL_CLOSE);
            return false;
        }
    }
    else
    {
        Cout() << "statement: " << statement << "\n";

        if(!IsOk(SQLExecute(session->hstmt))) {
            Cout() << "SQLExecute crashed\n";
            SQLFreeStmt(session->hstmt, SQL_CLOSE);
            return false;
        }

        Cout() << "Calling SQLMoreResults...\n";

        //SQLFreeStmt(session->hstmt, SQL_CLOSE);
        int iReturn = SQLMoreResults(session->hstmt); 

        Cout() << "SQLMoreResults return code: " << iReturn << "\n";

        while (iReturn == SQL_SUCCESS || iReturn == SQL_SUCCESS_WITH_INFO) 
        { 
            iReturn = SQLMoreResults(session->hstmt); 
        } ;
        //SQLFreeStmt(session->hstmt, SQL_RESET_PARAMS);
        //SQLFreeStmt(session->hstmt, SQL_UNBIND);
        ncol = 0;
    }

    session->current = this;
    info.Clear();
    binary.Clear();
    for(int i = 1; i <= ncol; i++) {
        SQLCHAR      ColumnName[256];
        SQLSMALLINT  NameLength;
        SQLSMALLINT  DataType;
        SQLULEN      ColumnSize;
        SQLSMALLINT  DecimalDigits;
        SQLSMALLINT  Nullable;
        if(!IsOk(SQLDescribeCol(session->hstmt, i, ColumnName, 255, &NameLength, &DataType,
                                &ColumnSize, &DecimalDigits, &Nullable)))
            return false;
        binary.Add(false);
        SqlColumnInfo& f = info.Add();
        f.nullable = Nullable != SQL_NO_NULLS;
        f.binary = false;
        f.precision = DecimalDigits;
        f.scale = 0;
        f.width = ColumnSize;
        f.name = (char *)ColumnName;
        switch(DataType) {
        case SQL_DECIMAL:
        case SQL_NUMERIC:
        case SQL_SMALLINT:
        case SQL_INTEGER:
        case SQL_REAL:
        case SQL_FLOAT:
        case SQL_DOUBLE:
        case SQL_BIT:
        case SQL_TINYINT:
            f.type = DOUBLE_V;
            break;
        case SQL_BIGINT:
            f.type = INT64_V;
            break;
        case SQL_TYPE_DATE:
        case SQL_TYPE_TIMESTAMP:
            f.type = TIME_V;
            break;
        case SQL_BINARY:
        case SQL_VARBINARY:
        case SQL_LONGVARBINARY:
            f.type = STRING_V;
            f.binary = true;
            binary.Top() = true;
            break;
        default:
            f.type = STRING_V;
            break;
        }
    }
    SQLLEN rc;
    SQLRowCount(session->hstmt, &rc);
    rowsprocessed = rc;


    return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:22:22+00:00Added an answer on May 30, 2026 at 2:22 am

    Never mind, I was being stupid. My parameter binding was actually bound to a copy of the data and not the actual data itself. Thanks to everyone who tried to help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.