MySQL Shell API 9.0.1
Unified development interface for MySQL Products
|
Enables interaction with a MySQL Server using the X Protocol. More...
Methods | |
Schema | create_schema (str name) |
Creates a schema on the database and returns the corresponding object. More... | |
Schema | get_schema (str name) |
Retrieves a Schema object from the current session through it's name. More... | |
Schema | get_default_schema () |
Retrieves the Schema configured as default for the session. More... | |
Schema | get_current_schema () |
Retrieves the active schema on the session. More... | |
Schema | set_current_schema (str name) |
Sets the current schema for this session, and returns the schema object for it. More... | |
list | get_schemas () |
Retrieves the Schemas available on the session. More... | |
str | get_uri () |
Retrieves the URI for the current session. More... | |
str | get_ssh_uri () |
Retrieves the URI for the current session. More... | |
int | get_connection_id () |
Retrieves the connection id for the current session. More... | |
None | close () |
Closes the session. More... | |
None | set_fetch_warnings (bool enable) |
Enables or disables warning generation. More... | |
Result | start_transaction () |
Starts a transaction context on the server. More... | |
Result | commit () |
Commits all the operations executed after a call to start_transaction(). More... | |
Result | rollback () |
Discards all the operations executed after a call to start_transaction(). More... | |
None | drop_schema (str name) |
Drops the schema with the specified name. More... | |
Bool | is_open () |
Returns true if session is known to be open. More... | |
SqlExecute | sql (str sql) |
Creates a SqlExecute object to allow running the received SQL statement on the target MySQL Server. More... | |
str | quote_name (str id) |
Escapes the passed identifier. More... | |
str | set_savepoint (str name="") |
Creates or replaces a transaction savepoint with the given name. More... | |
None | release_savepoint (str name) |
Removes a savepoint defined on a transaction. More... | |
None | rollback_to (str name) |
Rolls back the transaction to the named savepoint without terminating the transaction. More... | |
SqlResult | run_sql (str query, list args) |
Executes a query and returns the corresponding SqlResult object. More... | |
Properties | |
str | uri |
Retrieves the URI for the current session. | |
str | ssh_uri |
Retrieves the SSH URI for the current session. | |
Schema | default_schema |
Retrieves the Schema configured as default for the session. | |
Schema | current_schema |
Retrieves the active schema on the session. | |
int | connection_id |
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 create_schema | ( | str | 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 get_schema | ( | str | name | ) |
Schema get_default_schema | ( | ) |
std::string get_current_schema | ( | ) |
Retrieves the active schema on the session.
Schema set_current_schema | ( | str | 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>;
shcore::Array_t get_schemas | ( | ) |
Retrieves the Schemas available on the session.
str get_uri | ( | ) |
Retrieves the URI for the current session.
str get_ssh_uri | ( | ) |
Retrieves the URI for the current session.
Retrieves the SSH URI for the current session.
int get_connection_id | ( | ) |
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 get_table(name) or get_schemas().
std::shared_ptr< Result > set_fetch_warnings | ( | bool | 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.
void start_transaction | ( | ) |
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 start_transaction().
void commit | ( | ) |
Commits all the operations executed after a call to start_transaction().
All the operations executed after calling start_transaction() will take place when this function is called.
The server autocommit mode will return back to it's state before calling start_transaction().
void rollback | ( | ) |
Discards all the operations executed after a call to start_transaction().
All the operations executed after calling start_transaction() will be discarded when this function is called.
The server autocommit mode will return back to it's state before calling start_transaction().
None drop_schema | ( | str | name | ) |
Drops the schema with the specified name.
name | The name of the schema to be dropped. |
bool is_open | ( | ) |
Returns true if session is known to be open.
Returns true if the session is still open and false otherwise.
SqlExecute sql | ( | str | 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
str quote_name | ( | str | id | ) |
Escapes the passed identifier.
id | The identifier to be quoted. |
str set_savepoint | ( | str | 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.
None release_savepoint | ( | str | 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.
None rollback_to | ( | str | 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 run_sql | ( | str | query, |
list | 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. |