Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This API prepares a statement to execute.

You

...

only need to prepare a statement if you have parameter markers, identified by ? (question mark) symbols, in the SQL

...

. You may use pjs.executeDirect() otherwise.

...

Parameter
Info

This API can accept an optional database connection definition object to select between multiple database connections. To select the database connection, call pjs.getDB() and pass the result as the first parameter, followed by the parameters documented below. If a database connection definition object is not passed, the default database connection is used.

  1. SQL statement string
      Cursor name
      1. The SQL statement must be valid for the database you are using

    Return Value

    This method will return a handle which much be used again in other statements.

    Exception Handling

    An Error instance will be thrown with the following properties:

    ...

    SQL diagnostics are reported in the SQLCA:

    https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/db2/rbafzfielddescsqlca.htm

    SQLCA fields are defined in Profound.js programs with the names in lowercase. sqlcode will be set to zero if execution was successful.

    Example
    Code Block
    languagejavascript
    var table = "productsp";
     
    pjs.define("productsp_out", { type: 'data structure', qualified: true, dim: 50, elements: {
      "prid": { type: "packed decimal", length: 5, decimals: 0, initValue: 105 },
      "prname": { type: "char", length: 30 },
      "prdesc": { type: "char", length: 60 }
    }})
     
    extName: table  });
    pjs.define("searchQuery", { type: "char", length: 30 });
     
    var
    c1; pjs.connect("*LOCAL");
    pjs.clear(productsp_out);
    
    
    searchQuery = '%' + 'Garmin' + '%';
    var c1 = pjs.prepare("selectSELECT prid, prname, prdesc from demolib/productsp where* FROM productsp WHERE prdesc likeLIKE ? orderORDER byBY prid", "c1");
    pjsc1.bindParameters(c1, [
      [searchQuery.trim(), pjs.SQL_PARAM_INPUT]
    ]);
    pjsc1.execute(c1);
     
    pjs.fetch(c1, productsp_out, 50);
     
    pjsc1.close(c1);
    pjs.disconnect();


    Requirements

    This When using an IBM i database, this API requires the Profound.js Connector module.