@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/chdb-io/chdb-go/chdb"
1313 "github.com/chdb-io/chdb-go/chdbstable"
14+ "github.com/huandu/go-sqlbuilder"
1415 "github.com/parquet-go/parquet-go"
1516
1617 "github.com/apache/arrow/go/v15/arrow/ipc"
@@ -196,9 +197,30 @@ func (c *conn) Query(query string, values []driver.Value) (driver.Rows, error) {
196197 return c .QueryContext (context .Background (), query , namedValues )
197198}
198199
199- func (c * conn ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (driver.Rows , error ) {
200+ func (c * conn ) compileArguments (query string , args []driver.NamedValue ) (string , error ) {
201+ var compiledQuery string
202+ if len (args ) > 0 {
203+ compiledArgs := make ([]interface {}, len (args ))
204+ for idx := range args {
205+ compiledArgs [idx ] = args [idx ].Value
206+ }
207+ compiled , err := sqlbuilder .ClickHouse .Interpolate (query , compiledArgs )
208+ if err != nil {
209+ return "" , err
210+ }
211+ compiledQuery = compiled
212+ } else {
213+ compiledQuery = query
214+ }
215+ return compiledQuery , nil
216+ }
200217
201- result , err := c .QueryFun (query , c .driverType .String (), c .udfPath )
218+ func (c * conn ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (driver.Rows , error ) {
219+ compiledQuery , err := c .compileArguments (query , args )
220+ if err != nil {
221+ return nil , err
222+ }
223+ result , err := c .QueryFun (compiledQuery , c .driverType .String (), c .udfPath )
202224 if err != nil {
203225 return nil , err
204226 }
0 commit comments