Index: driver/utility.c =================================================================== --- driver/utility.c (revision 1012) +++ driver/utility.c (working copy) @@ -571,7 +571,7 @@ @return The column size of the field */ -SQLLEN get_column_size(STMT *stmt __attribute__((unused)), MYSQL_FIELD *field, +SQLLEN get_column_size(STMT *stmt, MYSQL_FIELD *field, my_bool actual) { CHARSET_INFO *charset= get_charset(field->charsetnr, MYF(0)); @@ -643,7 +643,8 @@ case MYSQL_TYPE_BLOB: case MYSQL_TYPE_GEOMETRY: if (field->charsetnr == 63) - return length; + return (stmt->dbc->flag && FLAG_COLUMN_SIZE_S32) ? + (length > INT_MAX32 ? INT_MAX32 : length) : length; else return length / mbmaxlen; } Index: test/my_catalog.c =================================================================== --- test/my_catalog.c (revision 1012) +++ test/my_catalog.c (working copy) @@ -1129,6 +1129,71 @@ } +/** + Bug #12805: LONGBLOB Problem +*/ +DECLARE_TEST(t_bug12805) +{ + HDBC hdbc1; + HSTMT hstmt1; + + SQLCHAR conn[256], conn_out[256]; + SQLSMALLINT conn_out_len; + SQLULEN length; + + /* Limit column size to a signed 32-bit value */ + sprintf(conn, "DRIVER=%s;USER=%s;PASSWORD=%s;" + "DATABASE=%s;SERVER=%s;OPTION=67108864", + mydriver, myuid, mypwd, mydb, myserver); + + if (mysock != NULL) + { + strcat((char *)conn, ";SOCKET="); + strcat((char *)conn, (char *)mysock); + } + + ok_env(henv, SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1)); + + ok_con(hdbc1, SQLDriverConnect(hdbc1, NULL, conn, sizeof(conn), conn_out, + sizeof(conn_out), &conn_out_len, + SQL_DRIVER_NOPROMPT)); + ok_con(hdbc1, SQLAllocStmt(hdbc1, &hstmt1)); + + ok_sql(hstmt1, "DROP TABLE IF EXISTS bug12805"); + ok_sql(hstmt1, "CREATE TABLE bug12805("\ + "id INT PRIMARY KEY auto_increment,"\ + "longimagedata LONGBLOB NULL)"); + + ok_stmt(hstmt1, SQLColumns(hstmt1, NULL, 0, NULL, 0, + (SQLCHAR *)"bug12805", SQL_NTS, + (SQLCHAR *)"longimagedata", SQL_NTS)); + + ok_stmt(hstmt1, SQLFetch(hstmt1)); + ok_stmt(hstmt1, SQLGetData(hstmt1, 7, SQL_C_ULONG, &length, + sizeof(SQLULEN), NULL)); + is_num(length, 2147483647); + ok_stmt(hstmt1, SQLFreeStmt(hstmt1, SQL_CLOSE)); + + ok_con(hdbc1, SQLDisconnect(hdbc1)); + ok_con(hdbc1, SQLFreeConnect(hdbc1)); + + /* Check without the 32-bit signed flag */ + ok_stmt(hstmt, SQLColumns(hstmt, NULL, 0, NULL, 0, + (SQLCHAR *)"bug12805", SQL_NTS, + (SQLCHAR *)"longimagedata", SQL_NTS)); + + ok_stmt(hstmt, SQLFetch(hstmt)); + ok_stmt(hstmt, SQLGetData(hstmt, 7, SQL_C_ULONG, &length, + sizeof(SQLULEN), NULL)); + is_num(length, 4294967295); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + ok_sql(hstmt, "DROP TABLE bug12805"); + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_columns_null) ADD_TEST(my_drop_table) @@ -1151,6 +1216,7 @@ ADD_TEST(t_bug26934) ADD_TEST(t_bug29888) ADD_TEST(t_bug14407) + ADD_TEST(t_bug12805) END_TESTS