@@ -3,6 +3,7 @@ package dbsql
33import (
44 "context"
55 "database/sql/driver"
6+ "fmt"
67 "time"
78
89 "github.com/databricks/databricks-sql-go/driverctx"
@@ -103,6 +104,7 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
103104 if len (args ) > 0 {
104105 return nil , dbsqlerrint .NewDriverError (ctx , dbsqlerr .ErrParametersNotSupported , nil )
105106 }
107+
106108 exStmtResp , opStatusResp , err := c .runQuery (ctx , query , args )
107109
108110 if exStmtResp != nil && exStmtResp .OperationHandle != nil {
@@ -145,6 +147,7 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam
145147 if len (args ) > 0 {
146148 return nil , dbsqlerrint .NewDriverError (ctx , dbsqlerr .ErrParametersNotSupported , nil )
147149 }
150+
148151 // first we try to get the results synchronously.
149152 // at any point in time that the context is done we must cancel and return
150153 exStmtResp , opStatusResp , err := c .runQuery (ctx , query , args )
@@ -284,6 +287,7 @@ func (c *conn) executeStatement(ctx context.Context, query string, args []driver
284287 MaxRows : int64 (c .cfg .MaxRows ),
285288 },
286289 CanDecompressLZ4Result_ : & c .cfg .UseLz4Compression ,
290+ Parameters : namedValuesToTSparkParams (args ),
287291 }
288292
289293 if c .cfg .UseArrowBatches {
@@ -337,6 +341,83 @@ func (c *conn) executeStatement(ctx context.Context, query string, args []driver
337341 return resp , err
338342}
339343
344+ func namedValuesToTSparkParams (args []driver.NamedValue ) []* cli_service.TSparkParameter {
345+ var ts []string = []string {"STRING" , "DOUBLE" , "BOOLEAN" }
346+ var params []* cli_service.TSparkParameter
347+ for i := range args {
348+ arg := args [i ]
349+ param := cli_service.TSparkParameter {Value : & cli_service.TSparkParameterValue {}}
350+ if arg .Name != "" {
351+ param .Name = & arg .Name
352+ } else {
353+ i := int32 (arg .Ordinal )
354+ param .Ordinal = & i
355+ }
356+
357+ switch t := arg .Value .(type ) {
358+ case bool :
359+ b := arg .Value .(bool )
360+ param .Value .BooleanValue = & b
361+ param .Type = & ts [2 ]
362+ case string :
363+ s := arg .Value .(string )
364+ param .Value .StringValue = & s
365+ param .Type = & ts [0 ]
366+ case int :
367+ f := float64 (t )
368+ param .Value .DoubleValue = & f
369+ param .Type = & ts [1 ]
370+ case uint :
371+ f := float64 (t )
372+ param .Value .DoubleValue = & f
373+ param .Type = & ts [1 ]
374+ case int8 :
375+ f := float64 (t )
376+ param .Value .DoubleValue = & f
377+ param .Type = & ts [1 ]
378+ case uint8 :
379+ f := float64 (t )
380+ param .Value .DoubleValue = & f
381+ param .Type = & ts [1 ]
382+ case int16 :
383+ f := float64 (t )
384+ param .Value .DoubleValue = & f
385+ param .Type = & ts [1 ]
386+ case uint16 :
387+ f := float64 (t )
388+ param .Value .DoubleValue = & f
389+ param .Type = & ts [1 ]
390+ case int32 :
391+ f := float64 (t )
392+ param .Value .DoubleValue = & f
393+ param .Type = & ts [1 ]
394+ case uint32 :
395+ f := float64 (t )
396+ param .Value .DoubleValue = & f
397+ param .Type = & ts [1 ]
398+ case int64 :
399+ f := float64 (t )
400+ param .Value .DoubleValue = & f
401+ param .Type = & ts [1 ]
402+ case uint64 :
403+ f := float64 (t )
404+ param .Value .DoubleValue = & f
405+ param .Type = & ts [1 ]
406+ case float32 :
407+ f := float64 (t )
408+ param .Value .DoubleValue = & f
409+ param .Type = & ts [1 ]
410+ default :
411+ s := fmt .Sprintf ("%s" , arg .Value )
412+ param .Value .StringValue = & s
413+ param .Type = & ts [0 ]
414+ }
415+
416+ params = append (params , & param )
417+ }
418+ return params
419+ }
420+
340421func (c * conn ) pollOperation (ctx context.Context , opHandle * cli_service.TOperationHandle ) (* cli_service.TGetOperationStatusResp , error ) {
341422 corrId := driverctx .CorrelationIdFromContext (ctx )
342423 log := logger .WithContext (c .id , corrId , client .SprintGuid (opHandle .OperationId .GUID ))
0 commit comments