[freetds] Syntax Error

Igor Korot ikorot01 at gmail.com
Tue Dec 1 08:16:38 EST 2015


Hi,
Couple of questions:

On Sun, Nov 29, 2015 at 11:55 PM, Manasi Deshpande
<Manasi.Deshpande at renishaw.com> wrote:
> Hello,
>
> We are using UTF-8 encoding and it is char that we are using! We aren't using wide APIs on Linux!
>
> In the FreeTDS config file we are specifying the client charset as UTF-8.
>
> Strange thing I observed was after commenting the following code the SQLExecDirect executes with SUCCESS.

1. What did you observe?

>
>          // Specify the number of elements in each parameter array.
>          TRYODBC(hStmt, SQL_HANDLE_STMT, SQLSetStmtAttr(hStmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)idCount, 0));

2. What is TRYODBC()?

>
>             // Specify an array in which to return the status of each set of
>              // parameters.
>             TRYODBC(hStmt, SQL_HANDLE_STMT, SQLSetStmtAttr(hStmt, SQL_ATTR_PARAM_STATUS_PTR, ParamStatusArray, idCount));
>
>             // Specify an SQLUINTEGER value in which to return the number of sets of
>           // parameters processed.
>            TRYODBC(hStmt, SQL_HANDLE_STMT, SQLSetStmtAttr(hStmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &ParamsProcessed, 0));
>
>
> Also another point to notice is that, I have recently updated from freetds-0.91 and TDS version 7.1. The code worked seamlessly then!

3. What is your current freeTDS version and TDS protocol?

4. Did you turn on logging on the ODBC side and inspected the it? What
did you see in both versions?

Thank you.

>
> Regards,
> Manasi
>
> -----Original Message-----
> From: FreeTDS [mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of Frediano Ziglio
> Sent: 27 November 2015 20:19
> To: FreeTDS Development Group <freetds at lists.ibiblio.org>
> Subject: Re: [freetds] Syntax Error
>
> 2015-11-27 10:21 GMT+00:00 Manasi Deshpande <Manasi.Deshpande at renishaw.com>:
>> Hello,
>>
>> Environment:
>> Ubuntu 14.04
>> UnixOdbc-2.3.4
>> Built and installed from freetds-0.95.69 and TDS version is 7.3
>>
>> Issue:
>> In this we are trying to query DB with IDs to return a collection of items.
>>
>>             RETCODE RetCode;
>>             SQLSMALLINT sNumResults;
>>
>>             int idCount = 0;
>>             _INT64 *arrIds =ArrayOfIds.GetArray();
>>             U_stringstream idStr;
>>
>>             idStr << _U("(");
>>
>>             for (int i = 0; i < idCount; i++)
>>             {
>>                         idStr << arrIds[i];
>>                         if (i < idCount - 1)
>>                                     idStr << _U(",");
>>             }
>>
>>             idStr << _U(")");
>>             U_STRING idString = idStr.str();
>>
>>             SQLUSMALLINT ParamStatusArray[2];
>>             SQLULEN ParamsProcessed;
>>
>>             SQLHANDLE hStmt = dbCon.getStmtHandle();
>>             SQLHANDLE hConn = dbCon.getConnHandle();
>>
>>
>>             // Specify the number of elements in each parameter array.
>>             TRYODBC(hStmt, SQL_HANDLE_STMT, SQLSetStmtAttr(hStmt,
>> SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)idCount, 0));
>>
>>             // Specify an array in which to return the status of each set of
>>             // parameters.
>>             TRYODBC(hStmt, SQL_HANDLE_STMT, SQLSetStmtAttr(hStmt,
>> SQL_ATTR_PARAM_STATUS_PTR, ParamStatusArray, idCount));
>>
>>             // Specify an SQLUINTEGER value in which to return the number of sets of
>>             // parameters processed.
>>             TRYODBC(hStmt, SQL_HANDLE_STMT, SQLSetStmtAttr(hStmt,
>> SQL_ATTR_PARAMS_PROCESSED_PTR, &ParamsProcessed, 0));
>>
>>             //Bind Parameters
>>             //TRYODBC(hStmt, SQL_HANDLE_STMT, SQLBindParameter(hStmt,
>> 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, arrIds, 0, NULL));
>>
>>             U_STRING  query = _U("SELECT query WHERE ITEM.Id in ") +
>> idString + _U(" ORDER BY ITEM.Id ASC");
>>
>
> I would first try with an easy query like "SELECT 1"
>
>>             RetCode = SQLExecDirect(hStmt, (SQLTCHAR*)query.c_str(),
>> SQL_NTS);
>>
>
> In which encoding the U_STRING store the string. No, Unicode is not enough (if you don't specify the version).
>
> From the code above query.c_str() should return a NUL-terminated string encoded in UTF-16 or UCS-2 format (endian machine dependent).
>
> Should not be SQLExecDirectW or did you enabled UNICODE define in Makefile/project file(s) ?
>
>> The Execute statement returns the following error information.
>> [FreeTDS][SQL Server]Incorrect syntax near
>>
>> Any help/inputs appreciated!
>>
>> Thanks,
>> Manasi
>
> Frediano
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
> --------------------------------------------------------------------------------------------------
> This email and any attachments are confidential and are for the use of the
> addressee only. If you are not the addressee, you must not use or disclose the
> contents to any other person. Please immediately notify the sender and
> delete the email. Statements and opinions expressed here may not
> represent those of the company. Email correspondence is monitored by
> the company. This information may be subject to export control
> regulation. You are obliged to comply with such regulations.
>
> Renishaw plc (company number 1106260) and Wotton Travel Limited (company
> number 01973158) are companies registered in England and Wales with a registered office
> at New Mills, Wotton-under-Edge, Gloucestershire, GL12 8JR,
> United Kingdom, Telephone +44 1453 524524.
> --------------------------------------------------------------------------------------------------
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds


More information about the FreeTDS mailing list