[unixODBC-dev] Calling a store procedure

Jaime Stuardo jstuardo at desytec.com
Thu Feb 23 03:05:22 GMT 2012


Hello
 I am trying to call a SQL Server 2005 stored procedure by mean of a
C++ application running under RedHat Linux. unixODBC is installed correctly
since I can connect to the database.

 

When I run SQLExecDirect, the returned value is an error. So, here are the
questions:

 

·         Why does an error occur?

·         Why does the SQLGetDiagRec function cannot return the actual
error? If I generate an error passing a string instead of a date in the
second parameter, the error is: [FreeTDS][SQL Server]Error converting data
type varchar to datetime. That means ExtractError function I implemented is
correct.

 

This is the code with SQLExecDirect:

 

    ret = SQLExecDirect(stmt, (SQLCHAR *) query.c_str(), SQL_NTS);

    if (!SQL_SUCCEEDED(ret)) {

        StoreSocket::ExtractError("SQLExecDirect", stmt, SQL_HANDLE_STMT);

        return false;

    }

 

Where query is:

execute usp_contrato_actualiza_aclaracion 'uno', '2012-02-22', 'dos',
'tres', 'cuatro', '2012-02-14', 'cinco', 'seis', 'siete', 'ocho', 'nueve',
'diez', 'once'

 

And the body of ExtractError is:

 

**************************

void StoreSocket::ExtractError(

        char *fn,

        SQLHANDLE handle,

        SQLSMALLINT type) {

    SQLINTEGER i = 0;

    SQLINTEGER native;

    SQLCHAR state[ 7 ];

    SQLCHAR text[256];

    SQLSMALLINT len;

    SQLRETURN ret;

 

    do {

        ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,

                sizeof (text), &len);

        if (SQL_SUCCEEDED(ret)) {

            printf("%s:%ld:%ld:%s\n", state, i, native, text);

        }

    } while (ret == SQL_SUCCESS);

}

**************************

 

Any help will be greatly appreciated,

 


Jaime Stuardo - Gerente General

DESYTEC - Development, Systems & Technologies

 


http://www.coralina.gov.co/intranet/templates/ja_sargas/images/con_address.p
ng   La Concepción 81 Of. 608, Providencia, Santiago

http://solution.weborama.com/img/phone.png   + 56 2 264 9399
http://www.at4wireless.com/imagenes/icons/fax.png   + 56 2 264 1558

http://www.path.org.uk/webpage.gif    <http://www.desytec.com/>
http://www.desytec.com

desytec-assembla

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20120223/c2a85b96/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 179 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20120223/c2a85b96/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1096 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20120223/c2a85b96/attachment-0003.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 634 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20120223/c2a85b96/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 428 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20120223/c2a85b96/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1015 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20120223/c2a85b96/attachment-0004.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 6024 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20120223/c2a85b96/attachment-0005.gif>


More information about the unixODBC-dev mailing list