MySQL Shell API 9.1.0
Unified development interface for MySQL Products
|
Enables interaction with a MySQL Server using the X Protocol. More...
Methods | |
Schema | createSchema (String name) |
Creates a schema on the database and returns the corresponding object. More... | |
Schema | getSchema (String name) |
Retrieves a Schema object from the current session through it's name. More... | |
Schema | getDefaultSchema () |
Retrieves the Schema configured as default for the session. More... | |
Schema | getCurrentSchema () |
Retrieves the active schema on the session. More... | |
Schema | setCurrentSchema (String name) |
Sets the current schema for this session, and returns the schema object for it. More... | |
List | getSchemas () |
Retrieves the Schemas available on the session. More... | |
String | getUri () |
Retrieves the URI for the current session. More... | |
String | getSshUri () |
Retrieves the URI for the current session. More... | |
Integer | getConnectionId () |
Retrieves the connection id for the current session. More... | |
Undefined | close () |
Closes the session. More... | |
Undefined | setFetchWarnings (Boolean enable) |
Enables or disables warning generation. More... | |
Result | startTransaction () |
Starts a transaction context on the server. More... | |
Result | commit () |
Commits all the operations executed after a call to startTransaction(). More... | |
Result | rollback () |
Discards all the operations executed after a call to startTransaction(). More... | |
Undefined | dropSchema (String name) |
Drops the schema with the specified name. More... | |
Bool | isOpen () |
Returns true if session is known to be open. More... | |
SqlExecute | sql (String sql) |
Creates a SqlExecute object to allow running the received SQL statement on the target MySQL Server. More... | |
String | quoteName (String id) |
Escapes the passed identifier. More... | |
String | setSavepoint (String name="") |
Creates or replaces a transaction savepoint with the given name. More... | |
Undefined | releaseSavepoint (String name) |
Removes a savepoint defined on a transaction. More... | |
Undefined | rollbackTo (String name) |
Rolls back the transaction to the named savepoint without terminating the transaction. More... | |
SqlResult | runSql (String query, Array args) |
Executes a query and returns the corresponding SqlResult object. More... | |
Properties | |
String | uri |
Retrieves the URI for the current session. | |
String | sshUri |
Retrieves the SSH URI for the current session. | |
Schema | defaultSchema |
Retrieves the Schema configured as default for the session. | |
Schema | currentSchema |
Retrieves the active schema on the session. | |
Integer | connectionId |
Retrieves the connection id for the current session. | |
Enables interaction with a MySQL Server using the X Protocol.
Document Store functionality can be used through this object, in addition to SQL.
This class allows performing database operations such as:
Schema createSchema | ( | String | name | ) |
Creates a schema on the database and returns the corresponding object.
name | A string value indicating the schema name. |
A | MySQL error is thrown if fails creating the schema. |
Schema getSchema | ( | String | name | ) |
Schema getDefaultSchema | ( | ) |
Schema getCurrentSchema | ( | ) |
Retrieves the active schema on the session.
Schema setCurrentSchema | ( | String | name | ) |
Sets the current schema for this session, and returns the schema object for it.
name | the name of the new schema to switch to. |
At the database level, this is equivalent at issuing the following SQL query:
use <new-default-schema>;
List getSchemas | ( | ) |
Retrieves the Schemas available on the session.
String getUri | ( | ) |
Retrieves the URI for the current session.
String getSshUri | ( | ) |
Retrieves the URI for the current session.
Retrieves the SSH URI for the current session.
Integer getConnectionId | ( | ) |
Retrieves the connection id for the current session.
void close | ( | ) |
Closes the session.
After closing the session it is still possible to make read only operations to gather metadata info, like getTable(name) or getSchemas().
Result setFetchWarnings | ( | Boolean | enable | ) |
Enables or disables warning generation.
enable | Boolean value to enable or disable the warnings. |
Warnings are generated sometimes when database operations are executed, such as SQL statements.
On a Node session the warning generation is disabled by default. This function can be used to enable or disable the warning generation based on the received parameter.
When warning generation is enabled, the warnings will be available through the result object returned on the executed operation.
Result startTransaction | ( | ) |
Starts a transaction context on the server.
Calling this function will turn off the autocommit mode on the server.
All the operations executed after calling this function will take place only when commit() is called.
All the operations executed after calling this function, will be discarded if rollback() is called.
When commit() or rollback() are called, the server autocommit mode will return back to it's state before calling startTransaction().
void commit | ( | ) |
Commits all the operations executed after a call to startTransaction().
All the operations executed after calling startTransaction() will take place when this function is called.
The server autocommit mode will return back to it's state before calling startTransaction().
void rollback | ( | ) |
Discards all the operations executed after a call to startTransaction().
All the operations executed after calling startTransaction() will be discarded when this function is called.
The server autocommit mode will return back to it's state before calling startTransaction().
Undefined dropSchema | ( | String | name | ) |
Drops the schema with the specified name.
name | The name of the schema to be dropped. |
Bool isOpen | ( | ) |
Returns true if session is known to be open.
Returns true if the session is still open and false otherwise.
SqlExecute sql | ( | String | sql | ) |
Creates a SqlExecute object to allow running the received SQL statement on the target MySQL Server.
sql | A string containing the SQL statement to be executed. |
This method creates an SqlExecute object which is a SQL execution handler.
The SqlExecute class has functions that allow defining the way the statement will be executed and allows doing parameter binding.
The received SQL is set on the execution handler.
JavaScript Example
String quoteName | ( | String | id | ) |
Escapes the passed identifier.
id | The identifier to be quoted. |
String setSavepoint | ( | String | name = "" | ) |
Creates or replaces a transaction savepoint with the given name.
name | Optional string with the name to be assigned to the transaction save point. |
When working with transactions, using savepoints allows rolling back operations executed after the savepoint without terminating the transaction.
Use this function to set a savepoint within a transaction.
If this function is called with the same name of another savepoint set previously, the original savepoint will be deleted and a new one will be created.
If the name is not provided an auto-generated name as 'TXSP#' will be assigned, where # is a consecutive number that guarantees uniqueness of the savepoint at Session level.
Undefined releaseSavepoint | ( | String | name | ) |
Removes a savepoint defined on a transaction.
name | string with the name of the savepoint to be removed. |
Removes a named savepoint from the set of savepoints defined on the current transaction. This does not affect the operations executed on the transaction since no commit or rollback occurs.
It is an error trying to remove a savepoint that does not exist.
Undefined rollbackTo | ( | String | name | ) |
Rolls back the transaction to the named savepoint without terminating the transaction.
name | string with the name of the savepoint for the rollback operation. |
Modifications that the current transaction made to rows after the savepoint was defined will be rolled back.
The given savepoint will not be removed, but any savepoint defined after the given savepoint was defined will be removed.
It is an error calling this operation with an unexisting savepoint.
SqlResult runSql | ( | String | query, |
Array | args | ||
) |
Executes a query and returns the corresponding SqlResult object.
query | the SQL query to execute against the database. |
args | Optional list of literals to use when replacing ? placeholders in the query string. |
LogicError | if there's no open session. |
ArgumentError | if the parameters are invalid. |