@@ -63,10 +63,18 @@ func reportError(err error, code int, reqIdx int, noFail bool, results []respons
6363// Processes a query, and returns a suitable responseItem
6464//
6565// This method is needed to execute properly the defers.
66- func processWithResultSet (tx * sql.Tx , query string , values map [ string ] interface {} ) (* responseItem , error ) {
66+ func processWithResultSet (tx * sql.Tx , query string , params requestParams ) (* responseItem , error ) {
6767 resultSet := make ([]orderedmap.OrderedMap , 0 )
6868
69- rows , err := tx .Query (query , vals2nameds (values )... )
69+ rows := (* sql .Rows )(nil )
70+ err := (error )(nil )
71+ if params .UnmarshalledDict == nil && params .UnmarshalledArray == nil {
72+ rows , err = nil , errors .New ("processWithResultSet unreachable code" )
73+ } else if params .UnmarshalledDict != nil {
74+ rows , err = tx .Query (query , vals2nameds (params .UnmarshalledDict )... )
75+ } else {
76+ rows , err = tx .Query (query , params .UnmarshalledArray ... )
77+ }
7078 if err != nil {
7179 return nil , err
7280 }
@@ -99,8 +107,16 @@ func processWithResultSet(tx *sql.Tx, query string, values map[string]interface{
99107}
100108
101109// Process a single statement, and returns a suitable responseItem
102- func processForExec (tx * sql.Tx , statement string , values map [string ]interface {}) (* responseItem , error ) {
103- res , err := tx .Exec (statement , vals2nameds (values )... )
110+ func processForExec (tx * sql.Tx , statement string , params requestParams ) (* responseItem , error ) {
111+ res := (sql .Result )(nil )
112+ err := (error )(nil )
113+ if params .UnmarshalledDict == nil && params .UnmarshalledArray == nil {
114+ res , err = nil , errors .New ("processWithResultSet unreachable code" )
115+ } else if params .UnmarshalledDict != nil {
116+ res , err = tx .Exec (statement , vals2nameds (params .UnmarshalledDict )... )
117+ } else {
118+ res , err = tx .Exec (statement , params .UnmarshalledArray ... )
119+ }
104120 if err != nil {
105121 return nil , err
106122 }
@@ -115,16 +131,24 @@ func processForExec(tx *sql.Tx, statement string, values map[string]interface{})
115131
116132// Process a batch statement, and returns a suitable responseItem.
117133// It prepares the statement, then executes it for each of the values' sets.
118- func processForExecBatch (tx * sql.Tx , q string , valuesBatch []map [ string ] interface {} ) (* responseItem , error ) {
134+ func processForExecBatch (tx * sql.Tx , q string , paramsBatch []requestParams ) (* responseItem , error ) {
119135 ps , err := tx .Prepare (q )
120136 if err != nil {
121137 return nil , err
122138 }
123139 defer ps .Close ()
124140
125141 var rowsUpdatedBatch []int64
126- for i := range valuesBatch {
127- res , err := ps .Exec (vals2nameds (valuesBatch [i ])... )
142+ for _ , params := range paramsBatch {
143+ res := (sql .Result )(nil )
144+ err := (error )(nil )
145+ if params .UnmarshalledDict == nil && params .UnmarshalledArray == nil {
146+ res , err = nil , errors .New ("processWithResultSet unreachable code" )
147+ } else if params .UnmarshalledDict != nil {
148+ res , err = tx .Exec (q , vals2nameds (params .UnmarshalledDict )... )
149+ } else {
150+ res , err = tx .Exec (q , params .UnmarshalledArray ... )
151+ }
128152 if err != nil {
129153 return nil , err
130154 }
@@ -215,7 +239,7 @@ func handler(databaseId string) func(c *fiber.Ctx) error {
215239
216240 hasResultSet := txItem .Query != ""
217241
218- if len (txItem .Values ) != 0 && len (txItem .ValuesBatch ) != 0 {
242+ if ! isEmptyRaw (txItem .Values ) && len (txItem .ValuesBatch ) != 0 {
219243 reportError (errors .New ("cannot specify both values and valuesBatch" ), fiber .StatusBadRequest , i , txItem .NoFail , ret .Results )
220244 continue
221245 }
@@ -256,18 +280,18 @@ func handler(databaseId string) func(c *fiber.Ctx) error {
256280
257281 if len (txItem .ValuesBatch ) > 0 {
258282 // Process a batch statement (multiple values)
259- var valuesBatch []map [ string ] interface {}
283+ var paramsBatch []requestParams
260284 for i2 := range txItem .ValuesBatch {
261- values , err := raw2vals (txItem .ValuesBatch [i2 ])
285+ params , err := raw2params (txItem .ValuesBatch [i2 ])
262286 if err != nil {
263287 reportError (err , fiber .StatusInternalServerError , i , txItem .NoFail , ret .Results )
264288 continue
265289 }
266290
267- valuesBatch = append (valuesBatch , values )
291+ paramsBatch = append (paramsBatch , * params )
268292 }
269293
270- retE , err := processForExecBatch (tx , sqll , valuesBatch )
294+ retE , err := processForExecBatch (tx , sqll , paramsBatch )
271295 if err != nil {
272296 reportError (err , fiber .StatusInternalServerError , i , txItem .NoFail , ret .Results )
273297 continue
@@ -276,7 +300,7 @@ func handler(databaseId string) func(c *fiber.Ctx) error {
276300 ret .Results [i ] = * retE
277301 } else {
278302 // At most one values set (be it query or statement)
279- values , err := raw2vals (txItem .Values )
303+ params , err := raw2params (txItem .Values )
280304 if err != nil {
281305 reportError (err , fiber .StatusInternalServerError , i , txItem .NoFail , ret .Results )
282306 continue
@@ -285,7 +309,7 @@ func handler(databaseId string) func(c *fiber.Ctx) error {
285309 if hasResultSet {
286310 // Query
287311 // Externalized in a func so that defer rows.Close() actually runs
288- retWR , err := processWithResultSet (tx , sqll , values )
312+ retWR , err := processWithResultSet (tx , sqll , * params )
289313 if err != nil {
290314 reportError (err , fiber .StatusInternalServerError , i , txItem .NoFail , ret .Results )
291315 continue
@@ -294,7 +318,7 @@ func handler(databaseId string) func(c *fiber.Ctx) error {
294318 ret .Results [i ] = * retWR
295319 } else {
296320 // Statement
297- retE , err := processForExec (tx , sqll , values )
321+ retE , err := processForExec (tx , sqll , * params )
298322 if err != nil {
299323 reportError (err , fiber .StatusInternalServerError , i , txItem .NoFail , ret .Results )
300324 continue
0 commit comments