TestProtocolExtendedQuery tests the extended query protocol (prepared statements)
(t *testing.T)
| 154 | |
| 155 | // TestProtocolExtendedQuery tests the extended query protocol (prepared statements) |
| 156 | func TestProtocolExtendedQuery(t *testing.T) { |
| 157 | t.Run("prepare_and_query", func(t *testing.T) { |
| 158 | stmt, err := testHarness.DuckgresDB.Prepare("SELECT $1::int + $2::int") |
| 159 | if err != nil { |
| 160 | t.Fatalf("Prepare failed: %v", err) |
| 161 | } |
| 162 | defer func() { _ = stmt.Close() }() |
| 163 | |
| 164 | var result int |
| 165 | err = stmt.QueryRow(10, 20).Scan(&result) |
| 166 | if err != nil { |
| 167 | t.Fatalf("QueryRow failed: %v", err) |
| 168 | } |
| 169 | if result != 30 { |
| 170 | t.Errorf("Expected 30, got %d", result) |
| 171 | } |
| 172 | }) |
| 173 | |
| 174 | t.Run("prepare_with_types", func(t *testing.T) { |
| 175 | skipIfKnown(t) |
| 176 | stmt, err := testHarness.DuckgresDB.Prepare("SELECT $1::text || ' ' || $2::text") |
| 177 | if err != nil { |
| 178 | t.Fatalf("Prepare failed: %v", err) |
| 179 | } |
| 180 | defer func() { _ = stmt.Close() }() |
| 181 | |
| 182 | var result string |
| 183 | err = stmt.QueryRow("hello", "world").Scan(&result) |
| 184 | if err != nil { |
| 185 | t.Fatalf("QueryRow failed: %v", err) |
| 186 | } |
| 187 | if result != "hello world" { |
| 188 | t.Errorf("Expected 'hello world', got %q", result) |
| 189 | } |
| 190 | }) |
| 191 | |
| 192 | t.Run("prepare_select_where", func(t *testing.T) { |
| 193 | stmt, err := testHarness.DuckgresDB.Prepare("SELECT name FROM users WHERE id = $1") |
| 194 | if err != nil { |
| 195 | t.Fatalf("Prepare failed: %v", err) |
| 196 | } |
| 197 | defer func() { _ = stmt.Close() }() |
| 198 | |
| 199 | var name string |
| 200 | err = stmt.QueryRow(1).Scan(&name) |
| 201 | if err != nil { |
| 202 | t.Fatalf("QueryRow failed: %v", err) |
| 203 | } |
| 204 | if name != "Alice" { |
| 205 | t.Errorf("Expected 'Alice', got %q", name) |
| 206 | } |
| 207 | }) |
| 208 | |
| 209 | t.Run("prepare_reuse", func(t *testing.T) { |
| 210 | stmt, err := testHarness.DuckgresDB.Prepare("SELECT $1::int * 2") |
| 211 | if err != nil { |
| 212 | t.Fatalf("Prepare failed: %v", err) |
| 213 | } |
nothing calls this directly
no test coverage detected