Index: driver/results.c =================================================================== --- driver/results.c (revision 596) +++ driver/results.c (working copy) @@ -532,7 +532,8 @@ printf( "[PAH][%s][%d][%s] type=%d\n", __FILE__, __LINE__, __FUNCTION__, type ); */ if ( pnColumnSize ) - *pnColumnSize = precision; + *pnColumnSize= (stmt->dbc->ado_flag && (precision > 2147483647L) ? + 2147483647L : precision); if ( pfSqlType ) *pfSqlType= type; if ( pibScale ) Index: driver/myodbc3.h =================================================================== --- driver/myodbc3.h (revision 596) +++ driver/myodbc3.h (working copy) @@ -224,8 +224,7 @@ pthread_mutex_t lock; #endif #if defined(_WIN32) || defined(WIN32) - /* old buffer to store memory pointer allocated previously in another heap */ - char *oldbuf; + bool ado_flag; #endif } DBC; Index: driver/connect.c =================================================================== --- driver/connect.c (revision 596) +++ driver/connect.c (working copy) @@ -113,6 +113,11 @@ { } } + /* ADO is not loaded by default */ + dbc->ado_flag= 0; +#ifdef WIN32 + dbc->ado_flag= (GetModuleHandle("msado15.dll") != NULL); +#endif return error; } Index: test/my_result.c =================================================================== --- test/my_result.c (revision 596) +++ test/my_result.c (working copy) @@ -1819,7 +1819,78 @@ return OK; } +/** +Bug #13776: Invalid string or buffer length error +*/ +DECLARE_TEST(t_bug13776) +{ +#ifdef WIN32 + /* Save the old handlers */ + SQLHENV old_henv= henv; + SQLHDBC old_hdbc= hdbc; + SQLHSTMT old_hstmt= hstmt; + HMODULE ado_dll; + SQLULEN pcColSz; + SQLCHAR szColName[MAX_NAME_LEN]; + SQLCHAR szData[MAX_ROW_DATA_LEN+1]; + SQLSMALLINT pfSqlType, pcbScale, pfNullable; + SQLCHAR *env_path= NULL; + SQLCHAR szFileToLoad[255]; + + /* + TODO: get the full path to the library using getenv + */ + env_path= getenv("CommonProgramFiles(x86)"); + if (!env_path) + env_path= getenv("CommonProgramFiles"); + + if (!env_path) + { + printf("# No path for CommonProgramFiles in %s on line %d\n", \ + __FILE__, __LINE__); \ + return FAIL; \ + } + + sprintf(szFileToLoad, "%s\\System\\ado\\msado15.dll", env_path); + + ado_dll= LoadLibrary(szFileToLoad); + if (!ado_dll) + { + printf("# Could load MSADO15.DLL in %s on line %d\n", \ + __FILE__, __LINE__); \ + return FAIL; \ + } + + /* Establish the new connection */ + alloc_basic_handles(&henv, &hdbc, &hstmt); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug13776"); + ok_sql(hstmt, "CREATE TABLE t_bug13776(ltext LONGTEXT)"); + ok_sql(hstmt, "INSERT INTO t_bug13776 VALUES ('long text test')"); + ok_sql(hstmt, "SELECT * FROM t_bug13776"); + ok_stmt(hstmt, SQLDescribeCol(hstmt, 1, szColName, MAX_NAME_LEN+1, NULL, + &pfSqlType, &pcColSz, &pcbScale, &pfNullable)); + + /* + IF adodb15.dll is loaded SQLDescribeCol should return the length of + LONGTEXT columns as 2G instead of 4G + */ + is(pcColSz == 2147483647); + + free_basic_handles(&henv, &hdbc, &hstmt); + + /* Restore the old handlers */ + henv= old_henv; + hdbc= old_hdbc; + hstmt= old_hstmt; +#endif + + /* 4G LONGTEXT has already been checked by t_desc_col test */ + return OK; +} + BEGIN_TESTS ADD_TEST(my_resultset) ADD_TEST(t_convert_type) @@ -1841,6 +1912,7 @@ ADD_TEST(t_bug27544) ADD_TEST(t_bug16817) ADD_TEST(bug6157) + ADD_TEST(t_bug13776) END_TESTS