Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-49863

[UDF] SyntaxError: Unexpected identifier with insert with implicit name parameter

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: User Error
    • Neo
    • Neo
    • js-evaluator
    • 7.1.0-1801
    • Untriaged
    • 1
    • Unknown

    Description

      The following explicit syntax for insert with name parameters works:

      # cat insert1.js 
      function sp_insert(num) {
        try {
          var insert = N1QL('INSERT INTO default (KEY, VALUE) VALUES ("k002", {"num_col1": $num })', {"num": num});
          return "Succeeded.";
        } catch (error) {
          return "Failed: " + error;
        }
      }
       
      # curl -s -k -X POST http://172.23.104.91:8093/evaluator/v1/libraries/use_cases -u Administrator:password -H 'content-type: application/json' -d@insert1.js
       

      but following (implicit) fails:

      # cat insert2.js 
      function sp_insert(num) {
        try {
          var insert = INSERT INTO default (KEY, VALUE) VALUES ("k003", {"num_col1": $num });
          return "Succeeded.";
        } catch (error) {
          return "Failed: " + error;
        }
      }
       
      # curl -s -k -X POST http://172.23.104.91:8093/evaluator/v1/libraries/use_cases -u Administrator:password -H 'content-type: application/json' -d@insert2.js
      Error while compiling library. Cause:
      compilation failed:
      Exception: SyntaxError: Unexpected identifier
      Location: functions/use_cases.js:1 
      Code: function sp_insert(num) {  try {    var insert = INSERT INTO default (KEY, VALUE) VALUES ("k003", {"num_col1": $num });    return "Succeeded.";  } catch (error) {    return "Failed: " + error;  }}
      SyntaxError: Unexpected identifier
       
       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          Pierre Regazzoni In the following statement:

          var insert = INSERT INTO default (KEY, VALUE) VALUES ("k003", {"num_col1": $num });
          

          "insert" is keyword which will trigger the transpiler, just in any language where you cannot name a variable int / long / char etc.

          The above example works without issues by naming the query with a non-keyword.
          As a guide, any string that matches the following regex: https://regex101.com/r/R7jCcd/1 is a keyword.

          Resolving, as it's expected behaviour.

          abhishek.jindal Abhishek Jindal added a comment - Pierre Regazzoni In the following statement: var insert = INSERT INTO default (KEY, VALUE) VALUES ("k003", {"num_col1": $num }); "insert" is keyword which will trigger the transpiler, just in any language where you cannot name a variable int / long / char etc. The above example works without issues by naming the query with a non-keyword. As a guide, any string that matches the following regex: https://regex101.com/r/R7jCcd/1 is a keyword. Resolving, as it's expected behaviour.

          People

            pierre.regazzoni Pierre Regazzoni
            pierre.regazzoni Pierre Regazzoni
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty