Skip to Content.
Sympa Menu

freetds - Re: [freetds] Syntax Error

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddy77 AT gmail.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Syntax Error
  • Date: Fri, 27 Nov 2015 14:48:50 +0000

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




Archive powered by MHonArc 2.6.24.

Top of Page