Documentation Home
MySQL 9.1 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.3Mb
PDF (A4) - 40.5Mb
Man Pages (TGZ) - 259.3Kb
Man Pages (Zip) - 366.4Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


27.3.6.1 Session Object

The Session object is always available as the session property of the global object. Session has the methods listed here:

  • getOption(String name): Gets the value of statement option name. Returns a string or a true-false value depending on the option type.

  • prepare(String sql, {passResultToClient: Bool, charsetName: String}): Enables the execution of a prepared statements; takes an SQL statement and returns a PreparedStatement object.

    Calling this method is equivalent to executing a PREPARE statement in the mysql client.

  • quoteName(String name): Returns name, after escaping it.

  • runSql(String query[[, Array statementParameters], Options options]): Executes a query, with any options specified, and using an optional list of statement parameters; it returns an SqlResult.

  • setOptions(Object options): Sets statement option defaults. Options not specified assume their default values.

  • sql(String sql, {passResultToClient: Bool, charsetName: String, integerType: IntegerType}): Executes a simple SQL statement. Can also be used to provide attributes overriding the passResultlToClient and charsetName values set in the session. Returns an SqlExecute object.

    IntegerType consists of a JSON key-value pair whose key is IntegerType, and whose possible values and their effects are listed here:

    • mysql.IntegerType.BIGINT: Convert all MySQL integer values to JavaScript BigInt.

    • mysql.IntegerType.STRING: Convert all MySQL integer values to JavaScript String

    • mysql.IntegerType.UNSAFE_BIGINT: If the MySQL value is safe, convert it to JavaScript Number; otherwise convert it to JavaScript BigInt. If the value is safe, convert to JavaScript Number; otherwise convert to JavaScript String. This is the default behavior if no rule is specified.

    • mysql.IntegerType.UNSAFE_STRING: If the MySQL value is safe, convert it to JavaScript Number; otherwise convert it to JavaScript String. This is the default behavior if no rule is specified.

    The rule set by this value determines how MySQL integer values are converted to JavaScript by this SQL statement. Their names (less object references) correspond to those for the used with the integer_type key used with mle_set_session_state(). The default behavior is equivalent to having set mysql.IntegerType.UNSAFE_STRING, or called mle_set_session_state('{"integer_type":"STRING"}').

    This option can also be set for a given statement using runSQL() or prepare().