0

I am trying to use parameterized N1QL Query but its not recognizing the json place holders and throwing incorrect syntax exception.

Code:

public static final String LMR_DETAILS 
    = "SELECT * FROM $bucketName WHERE lmr.lmrStatusDescriptionTe ='PENDING'and STR_TO_MILLIS(lmr.recordExpirationTs) BETWEEN STR_TO_MILLIS($startTime) AND STR_TO_MILLIS($endTime)";

String bucketName = bucket.bucketManager().info().name();
                    JsonObject placeHolders = JsonObject.create().put("bucketName", bucketName).put("startTime", reqDates[0]).put("endTime", reqDates[1]);
                    N1qlQuery query = N1qlQuery.parameterized(QueryString.LMR_DETAILS, placeHolders);
                    N1qlQueryResult result = bucket.query(query);
Sree
  • 1
  • 2

1 Answers1

0

After FROM clause requires as static identifier refer to bucket or subquery, It can't be parameterized variable. Remove $bucketName as parameterized variable and replaces with actual bucket name by constructing LMR_DETAILS dynamically.

vsr
  • 7,149
  • 1
  • 11
  • 10
  • Thank you @vsr. But I have to pass Bucket Name Dynamically as I am having many Environments with different buck names. How can I do that – Sree Jul 27 '17 at 17:21
  • String LMR_DETAILS = "SELECT * FROM " + bucket.bucketManager().info().name() + " WHERE lmr.lmrStatusDescriptionTe ='PENDING'and STR_TO_MILLIS(lmr.recordExpirationTs) BETWEEN STR_TO_MILLIS($startTime) AND STR_TO_MILLIS($endTime)"; – vsr Jul 27 '17 at 20:01