Uploaded image for project: 'MariaDB Connector/ODBC'
  1. MariaDB Connector/ODBC
  2. ODBC-51

SQLTables fails with HY090 "Invalid string or buffer length"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.11
    • Fix Version/s: 2.0.12
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux x86_64 CentOS 6.5

      Description

      Calling SQLTables fails with an error on invalid string error. It seems that it's the TABLE_COMMENT / REMARK column that fails in MADB_ConvertAnsi2Unicode. This has been tested and reproduces with MariaDB 10.2.1 and with MariaDB ColumnStore 1.0.2, but not on MariaDB 10.1.16. Looking at the ODBC Driver sources, I see that the REMARK column is sometimes mapped to NULL and sometimes to TABLE_COMMENT. As the ODBC driver is really important for MariaDB ColumnStore, this is significant. Running Business Objects on MariaDB CS is, due to this issue, not possible at this point in time.The following code illustrates the issue.

      #include <stdio.h>
      #include <sqlext.h>
       
      int main(int argc, char *argv[])
         {
         SQLHANDLE hEnv, hConn, hStmt;
         SQLRETURN nRet;
         SQLCHAR szErrMsg[256];
         SQLCHAR szErrState[5];
         SQLINTEGER nErrNative;
         SQLSMALLINT nErrMsgLen;
         SQLSMALLINT nDiagRec;
         SQLSMALLINT nCols;
         SQLCHAR szCatalog[64];
         SQLLEN iCatalog;
         SQLCHAR szSchema[64];
         SQLLEN iSchema;
         SQLCHAR szName[64];
         SQLLEN iName;
         SQLCHAR szType[64];
         SQLLEN iType;
         SQLCHAR szRemarks[3096];
         SQLLEN iRemarks;
       
         if(argc < 3)
            {
            fprintf(stderr, "Usage: %s <DSN> <user> <password>\n", argv[0]);
            return 1;
            }
       
         SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);
         SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
         SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hConn);
         if((nRet = SQLConnect(hConn, argv[1], SQL_NTS, argv[2], SQL_NTS, argv[3], SQL_NTS)) != SQL_SUCCESS)
            {
            SQLError(hEnv, hConn, SQL_NULL_HSTMT, NULL, NULL, szErrMsg, sizeof(szErrMsg), NULL);
            fprintf(stderr, "Error in connecting to MariaDB:\n%s\n", szErrMsg);
       
            return 1;
            }
       
         SQLAllocHandle(SQL_HANDLE_STMT, hConn, &hStmt);
         SQLBindCol(hStmt, 1, SQL_C_WCHAR, szCatalog, sizeof(szCatalog), &iCatalog);
         SQLBindCol(hStmt, 2, SQL_C_WCHAR, szSchema, sizeof(szSchema), &iSchema);
         SQLBindCol(hStmt, 3, SQL_C_WCHAR, szName, sizeof(szName), &iName);
         SQLBindCol(hStmt, 4, SQL_C_WCHAR, szType, sizeof(szType), &iType);
         SQLBindCol(hStmt, 5, SQL_C_WCHAR, szRemarks, sizeof(szRemarks), &iRemarks);
         if((nRet = SQLTables(hStmt, "test", SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS)) != SQL_SUCCESS)
            {
            SQLError(hEnv, hConn, hStmt, NULL, NULL, szErrMsg, sizeof(szErrMsg), NULL);
            fprintf(stderr, "Error in SQLTables:\n%s\n", szErrMsg);
       
            return 1;
            }
         SQLNumResultCols(hStmt, &nCols);
         printf("Cols: %d\n", nCols);
         while((nRet = SQLFetch(hStmt)) == SQL_SUCCESS)
            {
            }
         if(nRet != SQL_NO_DATA)
            {
            for(nDiagRec = 1; ; nDiagRec++)
               {
               if(SQLGetDiagRec(SQL_HANDLE_STMT, hStmt, nDiagRec, szErrState, &nErrNative,
                 szErrMsg, sizeof(szErrMsg), &nErrMsgLen) != SQL_SUCCESS)
                  break;
               fprintf(stderr, "Error %d in SQLFetch %d %.5s\n%.*s\n", nDiagRec, nErrNative,
                 szErrState, nErrMsgLen, szErrMsg);
               }
       
            return 1;
            }
         SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
         SQLFreeHandle(SQL_HANDLE_DBC, hConn);
         SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
       
         return 0;
         }
      

        Attachments

          Activity

            People

            Assignee:
            Lawrin Lawrin Novitsky
            Reporter:
            karlsson Anders Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration