Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterized queries are unsupported #27

Open
System-Glitch opened this issue Jan 13, 2025 · 0 comments
Open

Parameterized queries are unsupported #27

System-Glitch opened this issue Jan 13, 2025 · 0 comments
Assignees

Comments

@System-Glitch
Copy link

GORM Playground Link

Cannot provide a playground link because the playground doesn't support testing the bigquery driver

Here is instead a very simple way to reproduce:

package main

import (
    "gorm.io/driver/bigquery"
    "gorm.io/gorm"
    "log"
)


type ComplexRecord struct {
	Name   string           `gorm:"column:Name"`
	Record ComplexSubRecord `gorm:"column:Record:type:RECORD"`
}

type ComplexSubRecord struct {
	Name string `gorm:"column:Name"`
	Age  int    `gorm:"column:Age"`
}


func main() {
    // You can also pass custom endpoint and/or skip authentication by using query parameters like this:
    // bigquery://go-bigquery-driver/playground?endpoint=http://localhost:56758&disable_auth=true
    db, err := gorm.Open(bigquery.Open("bigquery://go-bigquery-driver/playground"), &gorm.Config{})
    if err != nil {
        log.Fatal(err)
    }

    var result *ComplexSubRecord

    // Delete complex record table if exists
    db.Migrator().DropTable(&ComplexRecord{})

    // Make sure we have a complex_records table
    db.AutoMigrate(&ComplexRecord{})

    // Insert new records to table
    db.Create(&ComplexRecord{Name: "test", Record: ComplexSubRecord{Name: "dd", Age: 1}})
    db.Create(&ComplexRecord{Name: "test2", Record: ComplexSubRecord{Name: "dd2", Age: 444}})

    // Select records from table
    err := db.Where("age", 444).First(&result).Error
    // Generated SQL: SELECT * FROM `complex_sub_records` WHERE `age` = ? LIMIT ?
    if err != nil {
        log.Fatal(err) // sql: expected 0 arguments, got 2
    }
}

Description

Parameterized queries are unsupported because bigQueryStatement.NumInput() always returns 0. It should return the actual number of parameters. (which should be equal to the count of unescaped question marks ?).

This would allow using where conditions, limits, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants