[freetds] Syntax Error

Manasi Deshpande Manasi.Deshpande at Renishaw.com
Fri Nov 27 05:21:45 EST 2015


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");

            RetCode = SQLExecDirect(hStmt, (SQLTCHAR*)query.c_str(), SQL_NTS);

The Execute statement returns the following error information.
[FreeTDS][SQL Server]Incorrect syntax near

Any help/inputs appreciated!

Thanks,
Manasi
--------------------------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------------------------


More information about the FreeTDS mailing list