I am trying to run a query from java with the couchbase sdk. The query below has fields with “annotation” to signify insert through a JsonObject. When I run one parameter through a JsonObject it works fine, but when I increase the number of parameters it does not seem to work. Can anyone help? NOTE: teh query runs sucessfully, but it returns empty values, if I hard code the values it returns a result set.
String query = " SELECT t.Number AS acct, t.sCode AS ps, t.AcctBasedInfo.HtusCode AS hs,
t.tusCode AS ss, t.Cat AS pcode, COUNT(1) AS cnts
FROM testBucket AS t
WHERE t.Number IN [“00100GH123”]
AND ((t.Date BETWEEN $startDate AND $endDate) OR t.Date = “1900-01-01”)
GROUP BY t.tusCode, t.Number, t.Cat,
t.HtusCode, t.tusCode";
The paths can’t be parameterized any where in query. The only values can be parametrized any where in the query.
If really need this you should try this.
SELECT t.[$number] AS acct, t.[$code] AS ps, t.[$info].[$hcode] AS hs
$number = "Number"
$code = "sCode"
$info = "AcctBasedInfo"
$hcode = "HtusCode "
In above case t.[$number] (As you note after dot array bracket starts no filed name) . The expression inside the array bracket is evaluated and must result in string. The result is converted into fieldname so it becomes t.Number then it evaluate as t.Number
This allows indirectly reference dynamic field
SELECT RAW t.[t.name] FROM [{"name":"firstname", "firstname":"fname"}, {"name":"lastname", "lastname":"lname"}] AS t;
"results": [
"fname",
"lname"
]