MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestDMLUpdate

Function TestDMLUpdate

tests/integration/dml_test.go:171–241  ·  view source on GitHub ↗

TestDMLUpdate tests UPDATE variations

(t *testing.T)

Source from the content-addressed store, hash-verified

169
170// TestDMLUpdate tests UPDATE variations
171func TestDMLUpdate(t *testing.T) {
172 // Create and populate test table
173 mustExec(t, testHarness.DuckgresDB, "CREATE TABLE dml_update_test (id INTEGER, name TEXT, status TEXT, counter INTEGER)")
174 mustExec(t, testHarness.DuckgresDB, `
175 INSERT INTO dml_update_test VALUES
176 (1, 'Alice', 'active', 10),
177 (2, 'Bob', 'active', 20),
178 (3, 'Charlie', 'inactive', 30),
179 (4, 'Diana', 'active', 40),
180 (5, 'Eve', 'inactive', 50)
181 `)
182
183 t.Run("update_single_column", func(t *testing.T) {
184 result, err := testHarness.DuckgresDB.Exec("UPDATE dml_update_test SET status = 'updated' WHERE id = 1")
185 if err != nil {
186 t.Fatalf("Update failed: %v", err)
187 }
188 affected, _ := result.RowsAffected()
189 if affected != 1 {
190 t.Errorf("Expected 1 row affected, got %d", affected)
191 }
192 })
193
194 t.Run("update_multiple_columns", func(t *testing.T) {
195 result, err := testHarness.DuckgresDB.Exec("UPDATE dml_update_test SET status = 'modified', counter = 100 WHERE id = 2")
196 if err != nil {
197 t.Fatalf("Update failed: %v", err)
198 }
199 affected, _ := result.RowsAffected()
200 if affected != 1 {
201 t.Errorf("Expected 1 row affected, got %d", affected)
202 }
203 })
204
205 t.Run("update_with_expression", func(t *testing.T) {
206 _, err := testHarness.DuckgresDB.Exec("UPDATE dml_update_test SET counter = counter + 5 WHERE id = 3")
207 if err != nil {
208 t.Fatalf("Update with expression failed: %v", err)
209 }
210 // Verify
211 result, _ := ExecuteQuery(testHarness.DuckgresDB, "SELECT counter FROM dml_update_test WHERE id = 3")
212 if result.Rows[0][0].(int64) != 35 {
213 t.Errorf("Expected counter=35, got %v", result.Rows[0][0])
214 }
215 })
216
217 t.Run("update_multiple_rows", func(t *testing.T) {
218 result, err := testHarness.DuckgresDB.Exec("UPDATE dml_update_test SET status = 'batch_updated' WHERE status = 'inactive'")
219 if err != nil {
220 t.Fatalf("Batch update failed: %v", err)
221 }
222 affected, _ := result.RowsAffected()
223 if affected < 1 {
224 t.Errorf("Expected at least 1 row affected, got %d", affected)
225 }
226 })
227
228 t.Run("update_all_rows", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

mustExecFunction · 0.85
ExecuteQueryFunction · 0.85
RunMethod · 0.65
ExecMethod · 0.65
RowsAffectedMethod · 0.65

Tested by

no test coverage detected