MySQL Shell API 8.0.36
Unified development interface for MySQL Products
Methods | Properties | List of all members
ClassicSession Class Reference

Enables interaction with a MySQL Server using the MySQL Protocol. More...

Methods

void close () override
 Closes the internal connection to the MySQL Server held on this session object.
 
void commit () override
 Commits all the operations executed after a call to startTransaction(). More...
 
void rollback () override
 Discards all the operations executed after a call to startTransaction(). More...
 
String getUri ()
 Retrieves the URI for the current session. More...
 
String getSshUri ()
 Retrieves the SSH URI for the current session. More...
 
ClassicResult runSql (String query, Array args=[])
 Executes a query and returns the corresponding ClassicResult object. More...
 
ClassicResult query (String query, Array args=[])
 Executes a query and returns the corresponding ClassicResult object. More...
 
ClassicResult startTransaction ()
 Starts a transaction context on the server. More...
 
Bool isOpen ()
 Returns true if session is known to be open. More...
 

Properties

String uri
 Retrieves the URI for the current session.
 
String sshUri
 Retrieves the SSH URI for the current session.
 

Detailed Description

Enables interaction with a MySQL Server using the MySQL Protocol.

Provides facilities to execute queries.

// Begins a transaction
classicSession.startTransaction();
// Inserts some records
var res1 = classicSession.runSql('insert into sample values ("john")');
var res2 = classicSession.runSql('insert into sample values ("carol")');
var res3 = classicSession.runSql('insert into sample values ("jack")');
// Commits the transaction
classicSession.commit();

Member Function Documentation

◆ commit()

void commit ( )
override

Commits all the operations executed after a call to startTransaction().

Returns
A ClassicResult object.

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().

◆ rollback()

void rollback ( )
override

Discards all the operations executed after a call to startTransaction().

Returns
A ClassicResult object.

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().

◆ getUri()

String getUri ( )

Retrieves the URI for the current session.

Returns
A string representing the connection data.

◆ getSshUri()

String getSshUri ( )

Retrieves the SSH URI for the current session.

Returns
A string representing the SSH connection data.

◆ runSql()

ClassicResult runSql ( String  query,
Array  args = [] 
)

Executes a query and returns the corresponding ClassicResult object.

Parameters
querythe SQL query to execute against the database.
argsOptional list of literals to use when replacing ? placeholders in the query string.
Returns
A ClassicResult object.
Exceptions
LogicErrorif there's no open session.
ArgumentErrorif the parameters are invalid.

◆ query()

ClassicResult query ( String  query,
Array  args = [] 
)

Executes a query and returns the corresponding ClassicResult object.

Parameters
querythe SQL query string to execute, with optional ? placeholders.
argsOptional list of literals to use when replacing ? placeholders in the query string.
Returns
A ClassicResult object.
Attention
This function will be removed in a future release, use the runSql function instead.
Exceptions
Anexception is thrown if an error occurs on the SQL execution.

◆ startTransaction()

ClassicResult startTransaction ( )

Starts a transaction context on the server.

Returns
A ClassicResult object.

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().

◆ isOpen()

Bool isOpen ( )

Returns true if session is known to be open.

Returns
A boolean value indicating if the session is still open.

Returns true if the session is still open and false otherwise.

Note
This function may return true if connection is lost.