@@ -113,20 +113,19 @@ func Query(db *sql.DB) RequestProcessFunc {
113
113
colData [columnNames [i ]] = sqlVal .String
114
114
}
115
115
case * []byte :
116
- // TODO (carlosms) this may not always be a JSON array, it could
117
- // be a JSON object
118
-
119
- // DatabaseTypeName JSON is used for arrays, but we don't know the
120
- // type of each element. We try with uast node first and text later
116
+ // DatabaseTypeName JSON is used for arrays of uast nodes and
117
+ // arrays of strings, but we don't know the exact type.
118
+ // We try with arry of uast nodes first and any JSON later
121
119
nodes , err := unmarshallUAST (val )
122
120
if err == nil {
123
121
colData [columnNames [i ]] = nodes
124
122
} else {
125
- var strings []string
126
- if err := json .Unmarshal (* val .(* []byte ), & strings ); err != nil {
123
+ var data interface {}
124
+
125
+ if err := json .Unmarshal (* val .(* []byte ), & data ); err != nil {
127
126
return nil , err
128
127
}
129
- colData [columnNames [i ]] = strings
128
+ colData [columnNames [i ]] = data
130
129
}
131
130
}
132
131
}
@@ -185,11 +184,9 @@ func unmarshallUAST(data interface{}) ([]*uast.Node, error) {
185
184
// addLimit adds LIMIT to the query, performing basic tests to skip it
186
185
// for DESCRIBE TABLE, SHOW TABLES, and avoid '; limit'
187
186
func addLimit (query string , limit int ) string {
188
- upper : = strings .ToUpper ( query )
189
- if strings .Contains ( upper , "DESCRIBE" ) || strings .Contains ( upper , "SHOW " ) {
190
- return query
187
+ query = strings .TrimRight ( strings . TrimSpace ( query ), ";" )
188
+ if strings .HasPrefix ( strings .ToUpper ( query ) , "SELECT " ) {
189
+ return fmt . Sprintf ( "%s LIMIT %d" , query , limit )
191
190
}
192
-
193
- trimmed := strings .TrimRight (strings .TrimSpace (query ), ";" )
194
- return fmt .Sprintf ("%s LIMIT %d" , trimmed , limit )
191
+ return query
195
192
}
0 commit comments