@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/chdb-io/chdb-go/chdb"
13
13
"github.com/chdb-io/chdb-go/chdbstable"
14
+ "github.com/huandu/go-sqlbuilder"
14
15
"github.com/parquet-go/parquet-go"
15
16
16
17
"github.com/apache/arrow/go/v15/arrow/ipc"
@@ -196,9 +197,30 @@ func (c *conn) Query(query string, values []driver.Value) (driver.Rows, error) {
196
197
return c .QueryContext (context .Background (), query , namedValues )
197
198
}
198
199
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
+ }
200
217
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 )
202
224
if err != nil {
203
225
return nil , err
204
226
}
0 commit comments