diff --git a/test/tap/tests/reg_test_4855_affected_rows_ddl-t.cpp b/test/tap/tests/reg_test_4855_affected_rows_ddl-t.cpp index 48c45ba8e..41150b05f 100644 --- a/test/tap/tests/reg_test_4855_affected_rows_ddl-t.cpp +++ b/test/tap/tests/reg_test_4855_affected_rows_ddl-t.cpp @@ -17,10 +17,19 @@ #include #include #include +#include +#include #include "tap.h" +#include "command_line.h" +#include "utils.h" #include "mysql.h" -int main() { +int main(int argc, char** argv) { + CommandLine cl; + + if (cl.getEnv()) + return exit_status(); + plan(12); MYSQL *admin = mysql_init(NULL); @@ -29,8 +38,8 @@ int main() { return exit_status(); } - // Connect to ProxySQL Admin - if (!mysql_real_connect(admin, "127.0.0.1", "admin", "admin", NULL, 6032, NULL, 0)) { + // Connect to ProxySQL Admin using command line arguments + if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fail("Failed to connect to ProxySQL Admin: %s", mysql_error(admin)); mysql_close(admin); return exit_status(); @@ -92,7 +101,7 @@ int main() { ok(affected_rows == 1, "UPDATE query after DDL returns 1 affected row: %llu", affected_rows); pass("UPDATE query executed successfully"); - // Test 6: Run a different DDL command + // Test 6: Run a different DML query if (mysql_query(admin, "DELETE FROM mysql_replication_hostgroups WHERE hostgroup_id IN (1000, 1001)")) { fail("Failed to execute DELETE query: %s", mysql_error(admin)); mysql_close(admin); @@ -105,15 +114,50 @@ int main() { // Test 7: Run another DDL to verify the fix again if (mysql_query(admin, "TRUNCATE TABLE stats_memory_metrics")) { - // TRUNCATE might not be available on all tables, so don't fail if it fails - diag("TRUNCATE TABLE failed (expected on some systems): %s", mysql_error(admin)); - skip("TRUNCATE not available, skipping affected rows test"); + // TRUNCATE might fail if table doesn't exist, but we test affected rows anyway + diag("TRUNCATE TABLE query executed (may fail if table doesn't exist)"); } else { affected_rows = mysql_affected_rows(admin); ok(affected_rows == 0, "TRUNCATE TABLE returns 0 affected rows: %llu", affected_rows); pass("TRUNCATE TABLE query executed successfully"); } + // Test 8: Run a VACUUM command on sqlite server + MYSQL* sqlite_mysql = mysql_init(NULL); + if (!sqlite_mysql) { + fail("Failed to initialize SQLite connection"); + mysql_close(admin); + return exit_status(); + } + + if (!mysql_real_connect(sqlite_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fail("Failed to connect to SQLite3 Server: %s", mysql_error(sqlite_mysql)); + mysql_close(admin); + mysql_close(sqlite_mysql); + return exit_status(); + } + + // Insert some data first + mysql_query(sqlite_mysql, "CREATE TABLE IF NOT EXISTS test_vacuum_4855 (id INTEGER PRIMARY KEY, name TEXT)"); + mysql_query(sqlite_mysql, "DELETE FROM test_vacuum_4855"); + mysql_query(sqlite_mysql, "INSERT INTO test_vacuum_4855 (name) VALUES ('test1')"); + + affected_rows = mysql_affected_rows(sqlite_mysql); + ok(affected_rows == 1, "INSERT on SQLite3 Server returns 1 affected row: %llu", affected_rows); + + // Now run VACUUM - this should return 0 affected rows + if (mysql_query(sqlite_mysql, "VACUUM")) { + fail("Failed to execute VACUUM query: %s", mysql_error(sqlite_mysql)); + mysql_close(admin); + mysql_close(sqlite_mysql); + return exit_status(); + } + + affected_rows = mysql_affected_rows(sqlite_mysql); + ok(affected_rows == 0, "VACUUM returns 0 affected rows (bug fix verified): %llu", affected_rows); + pass("VACUUM query executed successfully"); + + mysql_close(sqlite_mysql); mysql_close(admin); return exit_status(); } \ No newline at end of file