Test_MultilineSQLStatement tests that multi-line SQL statements are properly supported. This test verifies that newlines and tabs in SQL queries are preserved, which is essential for readability and proper SQL statement handling.
(t *testing.T)
| 76 | // This test verifies that newlines and tabs in SQL queries are preserved, |
| 77 | // which is essential for readability and proper SQL statement handling. |
| 78 | func Test_MultilineSQLStatement(t *testing.T) { |
| 79 | table := "A_tables" |
| 80 | createInitTable(table) |
| 81 | defer dropTable(table) |
| 82 | |
| 83 | gtest.C(t, func(t *gtest.T) { |
| 84 | // Test multi-line SELECT statement with newlines and indentation |
| 85 | multilineSql := ` |
| 86 | SELECT |
| 87 | id, |
| 88 | account_name, |
| 89 | attr_index |
| 90 | FROM A_tables |
| 91 | WHERE id = ? |
| 92 | AND account_name = ? |
| 93 | ` |
| 94 | result, err := db.GetAll(ctx, multilineSql, 1, "name_1") |
| 95 | t.AssertNil(err) |
| 96 | t.Assert(len(result), 1) |
| 97 | t.Assert(result[0]["ID"].Int(), 1) |
| 98 | t.Assert(result[0]["ACCOUNT_NAME"].String(), "name_1") |
| 99 | }) |
| 100 | |
| 101 | gtest.C(t, func(t *gtest.T) { |
| 102 | // Test multi-line SELECT with tabs |
| 103 | multilineSql := `SELECT |
| 104 | id, |
| 105 | account_name, |
| 106 | attr_index |
| 107 | FROM A_tables |
| 108 | WHERE id IN (?, ?) |
| 109 | ORDER BY id` |
| 110 | result, err := db.GetAll(ctx, multilineSql, 2, 3) |
| 111 | t.AssertNil(err) |
| 112 | t.Assert(len(result), 2) |
| 113 | t.Assert(result[0]["ID"].Int(), 2) |
| 114 | t.Assert(result[1]["ID"].Int(), 3) |
| 115 | }) |
| 116 | |
| 117 | gtest.C(t, func(t *gtest.T) { |
| 118 | // Test that newlines in values don't cause issues |
| 119 | multilineSql := ` |
| 120 | SELECT * |
| 121 | FROM A_tables |
| 122 | WHERE id = ?` |
| 123 | result, err := db.GetAll(ctx, multilineSql, 5) |
| 124 | t.AssertNil(err) |
| 125 | t.Assert(len(result), 1) |
| 126 | t.Assert(result[0]["ID"].Int(), 5) |
| 127 | t.Assert(result[0]["ACCOUNT_NAME"].String(), "name_5") |
| 128 | }) |
| 129 | |
| 130 | gtest.C(t, func(t *gtest.T) { |
| 131 | // Test multi-line INSERT with newlines |
| 132 | multilineSql := ` |
| 133 | INSERT INTO A_tables |
| 134 | (ID, ACCOUNT_NAME, ATTR_INDEX, CREATED_TIME, UPDATED_TIME) |
| 135 | VALUES |
nothing calls this directly
no test coverage detected
searching dependent graphs…