@@ -50,9 +50,13 @@ func ctxDriverPrepare(ctx context.Context, ci driver.Conn, query string) (driver
50
50
}
51
51
}
52
52
53
- func ctxDriverExec (ctx context.Context , execer driver.Execer , query string , dargs []driver.Value ) (driver.Result , error ) {
53
+ func ctxDriverExec (ctx context.Context , execer driver.Execer , query string , nvdargs []driver.NamedValue ) (driver.Result , error ) {
54
54
if execerCtx , is := execer .(driver.ExecerContext ); is {
55
- return execerCtx .ExecContext (ctx , query , dargs )
55
+ return execerCtx .ExecContext (ctx , query , nvdargs )
56
+ }
57
+ dargs , err := namedValueToValue (nvdargs )
58
+ if err != nil {
59
+ return nil , err
56
60
}
57
61
if ctx .Done () == context .Background ().Done () {
58
62
return execer .Exec (query , dargs )
@@ -90,9 +94,13 @@ func ctxDriverExec(ctx context.Context, execer driver.Execer, query string, darg
90
94
}
91
95
}
92
96
93
- func ctxDriverQuery (ctx context.Context , queryer driver.Queryer , query string , dargs []driver.Value ) (driver.Rows , error ) {
97
+ func ctxDriverQuery (ctx context.Context , queryer driver.Queryer , query string , nvdargs []driver.NamedValue ) (driver.Rows , error ) {
94
98
if queryerCtx , is := queryer .(driver.QueryerContext ); is {
95
- return queryerCtx .QueryContext (ctx , query , dargs )
99
+ return queryerCtx .QueryContext (ctx , query , nvdargs )
100
+ }
101
+ dargs , err := namedValueToValue (nvdargs )
102
+ if err != nil {
103
+ return nil , err
96
104
}
97
105
if ctx .Done () == context .Background ().Done () {
98
106
return queryer .Query (query , dargs )
@@ -130,9 +138,13 @@ func ctxDriverQuery(ctx context.Context, queryer driver.Queryer, query string, d
130
138
}
131
139
}
132
140
133
- func ctxDriverStmtExec (ctx context.Context , si driver.Stmt , dargs []driver.Value ) (driver.Result , error ) {
141
+ func ctxDriverStmtExec (ctx context.Context , si driver.Stmt , nvdargs []driver.NamedValue ) (driver.Result , error ) {
134
142
if siCtx , is := si .(driver.StmtExecContext ); is {
135
- return siCtx .ExecContext (ctx , dargs )
143
+ return siCtx .ExecContext (ctx , nvdargs )
144
+ }
145
+ dargs , err := namedValueToValue (nvdargs )
146
+ if err != nil {
147
+ return nil , err
136
148
}
137
149
if ctx .Done () == context .Background ().Done () {
138
150
return si .Exec (dargs )
@@ -170,9 +182,13 @@ func ctxDriverStmtExec(ctx context.Context, si driver.Stmt, dargs []driver.Value
170
182
}
171
183
}
172
184
173
- func ctxDriverStmtQuery (ctx context.Context , si driver.Stmt , dargs []driver.Value ) (driver.Rows , error ) {
185
+ func ctxDriverStmtQuery (ctx context.Context , si driver.Stmt , nvdargs []driver.NamedValue ) (driver.Rows , error ) {
174
186
if siCtx , is := si .(driver.StmtQueryContext ); is {
175
- return siCtx .QueryContext (ctx , dargs )
187
+ return siCtx .QueryContext (ctx , nvdargs )
188
+ }
189
+ dargs , err := namedValueToValue (nvdargs )
190
+ if err != nil {
191
+ return nil , err
176
192
}
177
193
if ctx .Done () == context .Background ().Done () {
178
194
return si .Query (dargs )
@@ -253,3 +269,14 @@ func ctxDriverBegin(ctx context.Context, ci driver.Conn) (driver.Tx, error) {
253
269
return r .txi , r .err
254
270
}
255
271
}
272
+
273
+ func namedValueToValue (named []driver.NamedValue ) ([]driver.Value , error ) {
274
+ dargs := make ([]driver.Value , len (named ))
275
+ for n , param := range named {
276
+ if len (param .Name ) > 0 {
277
+ return nil , errors .New ("sql: driver does not support the use of Named Parameters" )
278
+ }
279
+ dargs [n ] = param .Value
280
+ }
281
+ return dargs , nil
282
+ }
0 commit comments