From f4d23fa2491f185031254197d0d8da472275e4fc Mon Sep 17 00:00:00 2001 From: "Aaron M. Ucko" Date: Mon, 13 May 2024 16:41:58 -0400 Subject: [PATCH] odbc stats.c: Stick fully with the designated database. The precise database name has no bearing on this test's effectiveness. However, the test cases that explicitly specified a catalog (in ODBC parlance) to TestTable historically insisted on using freetds_test, and this test's only provision for lacking such a database was attempting to create it itself despite not necessarily having sufficient privileges. Bypass potential optimizations by formally changing to master before explicitly supplying the specified database name, with the help of a set_dbname copied from connect2.c. Signed-off-by: Aaron M. Ucko --- src/odbc/unittests/stats.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/odbc/unittests/stats.c b/src/odbc/unittests/stats.c index 942536dc76..675ef9bb37 100644 --- a/src/odbc/unittests/stats.c +++ b/src/odbc/unittests/stats.c @@ -89,6 +89,13 @@ str(char *buf, int n) return buf; } +static void +set_dbname(const char *dbname) +{ + CHKSetConnectAttr(SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER) T(dbname), + strlen(dbname)*sizeof(SQLTCHAR), "SI"); +} + int main(void) { @@ -97,13 +104,10 @@ main(void) odbc_use_version3 = 0; odbc_connect(); - /* try to create test database if not existing */ - odbc_command("IF DB_ID('freetds_test') IS NULL " - "CREATE DATABASE freetds_test"); - TestProc(NULL, "DATETIME", STR(SQL_TIMESTAMP)); TestTable(NULL, "DATETIME", STR(SQL_TIMESTAMP)); - TestTable("freetds_test", "DATETIME", STR(SQL_TIMESTAMP)); + set_dbname("master"); + TestTable(odbc_database, "DATETIME", STR(SQL_TIMESTAMP)); odbc_disconnect(); @@ -113,7 +117,8 @@ main(void) TestProc(NULL, "DATETIME", STR(SQL_TYPE_TIMESTAMP)); TestTable(NULL, "DATETIME", STR(SQL_TYPE_TIMESTAMP)); - TestTable("freetds_test", "DATETIME", STR(SQL_TYPE_TIMESTAMP)); + set_dbname("master"); + TestTable(odbc_database, "DATETIME", STR(SQL_TYPE_TIMESTAMP)); odbc_disconnect();