Skip to content

Commit

Permalink
Fix string datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
bonkzero404 committed Mar 13, 2024
1 parent 9bae885 commit ad26bb0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 13 additions & 1 deletion jql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,17 +1153,29 @@ func TestRawFunction(t *testing.T) {
"operator": "=",
"operand": "AND",
"value": 15
},
{
"isStatic": true,
"datatype": "string",
"clause": "v_transaction_redemptions.customer_name",
"operator": "=",
"operand": "AND",
"value": "MAHMUD"
}
],
"table": "v_transaction_redemptions"
}
`

jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithSanitizedInjection: true})
sql, _, _ := jql.Generate()
sql, par, _ := jql.Generate()

fmt.Println(sql)

for _, p := range par {
fmt.Println("PARAM ==>", p, reflect.TypeOf(p))
}

// strExpectation := "SELECT table_1.a, table_1.b AS foo_bar, (SELECT * FROM table_4 WHERE a = ? LIMIT 1) AS baz, table_2.b, table_3.a, table_3.b FROM table_1 JOIN table_2 ON table_2.a = table_1.a LEFT JOIN table_3 ON table_3.a = table_2.a WHERE table_1.a = ? AND table_1.b = ? AND table_2.a > sum(?) AND table_2.b = (SELECT * FROM table_4 WHERE a = ? LIMIT 1) OR (table_3.a BETWEEN ? AND ? AND table_3.b = ?) GROUP BY table_1.a HAVING COUNT(table_2.a) > ? ORDER BY table_1.a, table_2.a ASC LIMIT 1 OFFSET 0"
// assert.Equal(t, strExpectation, sql)
// assert.Equal(t, []interface{}{float64(1), "foo", true, float64(100), float64(1), "2020-01-01", "2023-01-01", "2", float64(10)}, filter)
Expand Down
6 changes: 4 additions & 2 deletions sql_datatype.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ func ExtractValueByDataType(datatype SQLDataTypeEnum, value json.RawMessage, isS
switch datatype {
case String:
json.Unmarshal(value, &valueString)
return jqlFlagOpen + "'" + valueString + "'" + jqlFlagClose
if isStatic {
return jqlFlagOpen + "'" + valueString + "'" + jqlFlagClose
}
return jqlFlagOpen + valueString + jqlFlagClose
case Boolean:
var valueBool bool

Expand All @@ -112,7 +115,6 @@ func ExtractValueByDataType(datatype SQLDataTypeEnum, value json.RawMessage, isS
json.Unmarshal(value, &valueNumber)
return jqlFlagOpen + string(value) + jqlFlagClose
case Raw:
// fmt.Println("YAP", jqlFlagOpen+strings.Trim(string(value), `"`)+jqlFlagClose)
return jqlFlagOpen + strings.Trim(string(value), `"`) + jqlFlagClose
case Array:
return ArrayConversionToStringExpression(value, isStatic)
Expand Down

0 comments on commit ad26bb0

Please sign in to comment.