TestProtocolSimpleQuery tests the simple query protocol
(t *testing.T)
| 67 | |
| 68 | // TestProtocolSimpleQuery tests the simple query protocol |
| 69 | func TestProtocolSimpleQuery(t *testing.T) { |
| 70 | t.Run("select_literal", func(t *testing.T) { |
| 71 | var val int |
| 72 | err := testHarness.DuckgresDB.QueryRow("SELECT 42").Scan(&val) |
| 73 | if err != nil { |
| 74 | t.Fatalf("Query failed: %v", err) |
| 75 | } |
| 76 | if val != 42 { |
| 77 | t.Errorf("Expected 42, got %d", val) |
| 78 | } |
| 79 | }) |
| 80 | |
| 81 | t.Run("select_multiple_columns", func(t *testing.T) { |
| 82 | var a, b, c int |
| 83 | err := testHarness.DuckgresDB.QueryRow("SELECT 1, 2, 3").Scan(&a, &b, &c) |
| 84 | if err != nil { |
| 85 | t.Fatalf("Query failed: %v", err) |
| 86 | } |
| 87 | if a != 1 || b != 2 || c != 3 { |
| 88 | t.Errorf("Expected 1,2,3 got %d,%d,%d", a, b, c) |
| 89 | } |
| 90 | }) |
| 91 | |
| 92 | t.Run("select_string", func(t *testing.T) { |
| 93 | var val string |
| 94 | err := testHarness.DuckgresDB.QueryRow("SELECT 'hello world'").Scan(&val) |
| 95 | if err != nil { |
| 96 | t.Fatalf("Query failed: %v", err) |
| 97 | } |
| 98 | if val != "hello world" { |
| 99 | t.Errorf("Expected 'hello world', got %q", val) |
| 100 | } |
| 101 | }) |
| 102 | |
| 103 | t.Run("select_null", func(t *testing.T) { |
| 104 | var val sql.NullString |
| 105 | err := testHarness.DuckgresDB.QueryRow("SELECT NULL").Scan(&val) |
| 106 | if err != nil { |
| 107 | t.Fatalf("Query failed: %v", err) |
| 108 | } |
| 109 | if val.Valid { |
| 110 | t.Errorf("Expected NULL, got valid value") |
| 111 | } |
| 112 | }) |
| 113 | |
| 114 | t.Run("select_multiple_rows", func(t *testing.T) { |
| 115 | rows, err := testHarness.DuckgresDB.Query("SELECT * FROM users ORDER BY id LIMIT 5") |
| 116 | if err != nil { |
| 117 | t.Fatalf("Query failed: %v", err) |
| 118 | } |
| 119 | defer func() { _ = rows.Close() }() |
| 120 | |
| 121 | count := 0 |
| 122 | for rows.Next() { |
| 123 | count++ |
| 124 | } |
| 125 | if err := rows.Err(); err != nil { |
| 126 | t.Fatalf("Row iteration error: %v", err) |