Index: driver/catalog.c =================================================================== --- driver/catalog.c (revision 553) +++ driver/catalog.c (working copy) @@ -370,8 +370,7 @@ *TableName, *TableType; STMT FAR *stmt= (STMT FAR*) hstmt; - MYSQL_RES *result, *sys_result; - my_bool all_dbs= 1, sys_tables, user_tables, views; + my_bool all_dbs= 1, user_tables, views; MYODBCDbgEnter; @@ -445,23 +444,19 @@ SQLTABLES_fields, SQLTABLES_FIELDS)); } - sys_result= result= NULL; - escape_input_parameter(&stmt->dbc->mysql, TableType); user_tables= check_table_type(TableType, "TABLE", 5); views= check_table_type(TableType, "VIEW", 4); - sys_tables= (check_table_type(TableType, "SYSTEM TABLE", 12) || - check_table_type(TableType, "SYSTEM", 6)); /* If no types specified, we want tables and views. */ - if (!user_tables && !sys_tables && !views) + if (!user_tables && !views) { if (!szTableType || !cbTableType) user_tables= views= 1; } - if ((TableType[0] && !views && !user_tables && !sys_tables) || + if ((TableType[0] && !views && !user_tables) || (TableQualifier[0] && strcmp(TableQualifier,"%") && TableOwner[0] && strcmp(TableOwner,"%") && strcmp(TableOwner, stmt->dbc->database))) @@ -474,10 +469,10 @@ if (user_tables || views) { pthread_mutex_lock(&stmt->dbc->lock); - result= mysql_table_status(stmt, szTableQualifier, cbTableQualifier, - szTableName, cbTableName, TRUE); + stmt->result= mysql_table_status(stmt, szTableQualifier, cbTableQualifier, + szTableName, cbTableName, TRUE); - if (!result && mysql_errno(&stmt->dbc->mysql)) + if (!stmt->result && mysql_errno(&stmt->dbc->mysql)) { SQLRETURN rc; /* unknown DB will return empty set from SQLTables */ @@ -495,49 +490,21 @@ pthread_mutex_unlock(&stmt->dbc->lock); } - /* System tables with type as 'SYSTEM' or 'SYSTEM TABLE' */ - if (sys_tables) - { - pthread_mutex_lock(&stmt->dbc->lock); - sys_result= mysql_table_status(stmt, (SQLCHAR *)"mysql", 5, - szTableName, cbTableName, TRUE); - - if (!sys_result && mysql_errno(&stmt->dbc->mysql)) - { - SQLRETURN rc= handle_connection_error(stmt); - pthread_mutex_unlock(&stmt->dbc->lock); - MYODBCDbgReturnReturn(rc); - } - pthread_mutex_unlock(&stmt->dbc->lock); - } - - if (!result && !sys_result) + if (!stmt->result) goto empty_set; /* assemble final result set */ { MYSQL_ROW data= 0, row; char *db; - my_ulonglong row_count= 0; + my_ulonglong row_count= stmt->result->row_count; - if (sys_result) + if (!row_count) { - stmt->result= sys_result; - row_count= sys_result->row_count; + mysql_free_result(stmt->result); + goto empty_set; } - if (result) - { - row_count+= result->row_count; - if (!sys_result) - { - stmt->result= result; - } - } - - if (!row_count) - goto empty_set; - if (!(stmt->result_array= (char **)my_malloc((uint)(sizeof(char *) * SQLTABLES_FIELDS * row_count), @@ -549,68 +516,31 @@ data= stmt->result_array; - if (sys_result) - { - char buff[NAME_LEN+7]; + if (option_flag(stmt, FLAG_NO_CATALOG)) + db= ""; + else + db= (is_default_db(stmt->dbc->mysql.db, TableQualifier) ? + stmt->dbc->mysql.db : strdup_root(&stmt->result->field_alloc, + TableQualifier)); - if (option_flag(stmt, FLAG_NO_CATALOG)) - db= ""; - else - db= "mysql"; - - /* - Prefix all system tables with 'mysql.', so that they can - be used directly in describing columns related information - - Must needed like this inorder to make system tables editable - by ODBC tools - */ - while ((row= mysql_fetch_row(sys_result))) - { - data[0]= db; - data[1]= ""; - sprintf(buff, "mysql.%s", row[0]); - data[2]= strdup_root(&stmt->result->field_alloc, buff); - data[3]= "SYSTEM TABLE"; - if (sys_result->field_count == 18) - data[4]= strdup_root(&stmt->result->field_alloc, row[17]); - else - data[4]= strdup_root(&stmt->result->field_alloc, row[15]); - - data+= SQLTABLES_FIELDS; - } - } - - if (result) + while ((row= mysql_fetch_row(stmt->result))) { - if (option_flag(stmt, FLAG_NO_CATALOG)) - db= ""; - else - db= (is_default_db(stmt->dbc->mysql.db, TableQualifier) ? - stmt->dbc->mysql.db : strdup_root(&stmt->result->field_alloc, - TableQualifier)); + int comment_index= (stmt->result->field_count == 18) ? 17 : 15; + my_bool view= (!row[1] && + myodbc_casecmp(row[comment_index], "view", 4) == 0); - while ((row= mysql_fetch_row(result))) + if ((view && !views) || (!view && !user_tables)) { - int comment_index= (result->field_count == 18) ? 17 : 15; - my_bool view= (!row[1] && - myodbc_casecmp(row[comment_index], "view", 4) == 0); - - if ((view && !views) || (!view && !user_tables)) - { - row_count--; - continue; - } - - data[0]= db; - data[1]= ""; - data[2]= strdup_root(&stmt->result->field_alloc, row[0]); - data[3]= view ? "VIEW" : "TABLE"; - data[4]= strdup_root(&stmt->result->field_alloc, row[comment_index]); - data+= SQLTABLES_FIELDS; + row_count--; + continue; } - if (sys_result) - mysql_free_result(result); + + data[0]= db; + data[1]= ""; + data[2]= strdup_root(&stmt->result->field_alloc, row[0]); + data[3]= view ? "VIEW" : "TABLE"; + data[4]= strdup_root(&stmt->result->field_alloc, row[comment_index]); + data+= SQLTABLES_FIELDS; } stmt->result->row_count= row_count; @@ -621,7 +551,8 @@ MYODBCDbgReturnReturn(SQL_SUCCESS); empty_set: - MYODBCDbgReturnReturn(create_empty_fake_resultset(stmt, (gptr) SQLTABLES_values, + MYODBCDbgReturnReturn(create_empty_fake_resultset(stmt, + (gptr)SQLTABLES_values, sizeof(SQLTABLES_values), SQLTABLES_fields, SQLTABLES_FIELDS)); Index: test/my_catalog.c =================================================================== --- test/my_catalog.c (revision 553) +++ test/my_catalog.c (working copy) @@ -736,10 +736,7 @@ r = SQLTables(hstmt,NULL,0,NULL,0,NULL,0,"'system table'",SQL_NTS); mystmt(hstmt,r); - if (driver_min_version(hdbc,"03.51.07",8)) - myassert(myresult(hstmt) != 0); - else - myassert(0 == myresult(hstmt)); + is_num(myresult(hstmt), 0); r = SQLFreeStmt(hstmt, SQL_CLOSE); mystmt(hstmt,r); Index: test/my_keys.c =================================================================== --- test/my_keys.c (revision 553) +++ test/my_keys.c (working copy) @@ -543,158 +543,9 @@ } -DECLARE_TEST(my_tables) -{ - SQLHDBC hdbc1; - SQLHSTMT hstmt1; - SQLRETURN rc; - SQLCHAR conn[256], conn_out[256]; - SQLSMALLINT conn_out_len; - - SQLExecDirect(hstmt,"DROP DATABASE my_tables_test_db",SQL_NTS); - rc = SQLExecDirect(hstmt,"CREATE DATABASE my_tables_test_db",SQL_NTS); - mystmt(hstmt,rc); - - sprintf(conn,"DSN=%s;UID=%s;PASSWORD=%s;DATABASE=%s", - mydsn,myuid,mypwd,"my_tables_test_db"); - if (mysock != NULL) - { - strcat(conn, ";SOCKET="); - strcat(conn, mysock); - } - rc = SQLAllocConnect(henv,&hdbc1); - myenv(henv,rc); - - rc = SQLDriverConnect(hdbc1,NULL,conn,sizeof(conn), - conn_out,sizeof(conn_out),&conn_out_len, - SQL_DRIVER_NOPROMPT); - mycon(hdbc1,rc); - - rc = SQLAllocStmt(hdbc1,&hstmt1); - mycon(hdbc1,rc); - - rc = SQLExecDirect(hstmt1, - "CREATE TABLE my_tables_test1(\ - A INTEGER NOT NULL,B INTEGER NOT NULL)",SQL_NTS); - mystmt(hstmt1,rc); - - rc = SQLExecDirect(hstmt1, - "CREATE TABLE my_tables_test2(\ - A INTEGER NOT NULL,B INTEGER NOT NULL)",SQL_NTS); - mystmt(hstmt1,rc); - - SQLEndTran(SQL_HANDLE_DBC,hdbc1,SQL_COMMIT); - - rc = SQLTables(hstmt1,"non_existing_junk",SQL_NTS, - NULL,0, - "my_tables_test1",SQL_NTS, - "TABLE",SQL_NTS); - mystmt(hstmt1,rc); - myassert(0 == my_print_non_format_result(hstmt1)); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,"my_tables_test_db",SQL_NTS, - NULL,0, - "my_tables_test1",SQL_NTS, - "TABLE",SQL_NTS); - mystmt(hstmt1,rc); - myassert(1 == my_print_non_format_result(hstmt1)); - SQLFreeStmt(hstmt,SQL_CLOSE); - - rc = SQLTables(hstmt1,"my_tables_test_db",SQL_NTS, - NULL,0, - "my_tables_test1",15, - "TABLE",SQL_NTS); - mystmt(hstmt1,rc); - myassert(1 == my_print_non_format_result(hstmt1)); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,"my_tables_test_db",SQL_NTS, - NULL,0, - NULL,0, - "TABLE",SQL_NTS); - mystmt(hstmt1,rc); - myassert(2 == my_print_non_format_result(hstmt1)); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,"my_tables_test_db",SQL_NTS, - NULL,0, - NULL,0, - "`TABLE`",SQL_NTS); - mystmt(hstmt1,rc); - if (!driver_min_version(hdbc,"03.51.07",8)) - myassert(0 == my_print_non_format_result(hstmt1)); - else - myassert(0 != my_print_non_format_result(hstmt1)); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,NULL,0, - NULL,0, - NULL,0, - "SYSTEM TABLE",SQL_NTS); - mystmt(hstmt1,rc); - if (!driver_min_version(hdbc,"03.51.07",8)) - myassert(0 == my_print_non_format_result(hstmt1)); - else - myassert(my_print_non_format_result(hstmt1) != 0); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,NULL,0, - NULL,0, - NULL,0, - "TABLE,SYSTEM TABLE",SQL_NTS); - mystmt(hstmt1,rc); - if (!driver_min_version(hdbc,"03.51.07",8)) - myassert(2 == my_print_non_format_result(hstmt1)); - else - myassert(my_print_non_format_result(hstmt1) > 2); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,NULL,0, - NULL,0, - NULL,0, - "TABLE,VIEW,SYSTEM TABLE",SQL_NTS); - mystmt(hstmt1,rc); - if (!driver_min_version(hdbc,"03.51.07",8)) - myassert(2 == my_print_non_format_result(hstmt1)); - else - myassert(my_print_non_format_result(hstmt1) > 2); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,NULL,0, - NULL,0, - NULL,0, - "'TABLE','VIEW','SYSTEM TABLE'",SQL_NTS); - mystmt(hstmt1,rc); - if (!driver_min_version(hdbc,"03.51.07",8)) - myassert(2 == my_print_non_format_result(hstmt1)); - else - myassert(my_print_non_format_result(hstmt1) > 2); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - rc = SQLTables(hstmt1,NULL,0, - NULL,0, - NULL,0, - "'TABLE',",SQL_NTS); - mystmt(hstmt1,rc); - myassert(2 == my_print_non_format_result(hstmt1)); - SQLFreeStmt(hstmt1,SQL_CLOSE); - - SQLExecDirect(hstmt1,"DROP DATABASE my_tables_test_db",SQL_NTS); - SQLEndTran(SQL_HANDLE_DBC,hdbc1,SQL_COMMIT); - - SQLFreeStmt(hstmt1,SQL_CLOSE); - SQLDisconnect(hdbc1); - SQLFreeConnect(hdbc1); - - return OK; -} - - BEGIN_TESTS ADD_TEST(my_no_keys) ADD_TEST(my_foreign_keys) - ADD_TEST(my_tables) END_TESTS