MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestBackupWithQuotedStrings

Function TestBackupWithQuotedStrings

backend/plugin/parser/tsql/backup_test.go:216–245  ·  view source on GitHub ↗

TestBackupWithQuotedStrings validates that single quotes in WHERE clauses are properly handled

(t *testing.T)

Source from the content-addressed store, hash-verified

214
215// TestBackupWithQuotedStrings validates that single quotes in WHERE clauses are properly handled
216func TestBackupWithQuotedStrings(t *testing.T) {
217 a := require.New(t)
218
219 // Test case with single quotes
220 input := `DELETE FROM AdminPosition WHERE positionName = 'BPM Admin';`
221
222 result, err := TransformDMLToSelect(context.Background(), base.TransformContext{},
223 input, "TestIdentityDB", "bbdataarchive", "backup")
224 a.NoError(err)
225 a.Len(result, 1)
226
227 stmt := result[0].Statement
228
229 // With simple SELECT INTO, quotes are handled naturally by SQL Server
230 // The WHERE clause should appear as-is
231 a.Contains(stmt, "WHERE positionName = 'BPM Admin'")
232
233 // Also test with apostrophes in the string
234 input2 := `UPDATE positions SET title = 'O''Reilly''s Manager' WHERE id = 1;`
235 result2, err := TransformDMLToSelect(context.Background(), base.TransformContext{},
236 input2, "db", "backup", "rollback")
237 a.NoError(err)
238 a.Len(result2, 1)
239
240 // For UPDATE, we only backup the rows that will be changed (WHERE clause)
241 // The SET clause is not part of the backup, only the WHERE clause matters
242 stmt2 := result2[0].Statement
243 // The WHERE clause should be present
244 a.Contains(stmt2, "WHERE id = 1")
245}
246
247// TestBackupSkipsTempTableTargets validates BYT-9359: prior backup must skip
248// any UPDATE/DELETE whose target table is a temp table (#name local, ##name

Callers

nothing calls this directly

Calls 2

LenMethod · 0.80
TransformDMLToSelectFunction · 0.70

Tested by

no test coverage detected