libasynql  3.2.0
Asynchronous MySQL access library for PocketMine plugins.
DataConnectorImpl Class Reference
Inheritance diagram for DataConnectorImpl:
DataConnector

Public Member Functions

 __construct (Plugin $plugin, SqlThread $thread, ?string $placeHolder, bool $logQueries=false)
 
 setLoggingQueries (bool $loggingQueries)
 
 isLoggingQueries ()
 
 loadQueryFile ($fh, string $fileName=null)
 
 loadQuery (GenericStatement $stmt)
 
 executeGeneric (string $queryName, array $args=[], ?callable $onSuccess=null, ?callable $onError=null)
 
 executeGenericRaw (string $query, array $args=[], ?callable $onSuccess=null, ?callable $onError=null)
 
 executeChange (string $queryName, array $args=[], ?callable $onSuccess=null, ?callable $onError=null)
 
 executeChangeRaw (string $query, array $args=[], ?callable $onSuccess=null, ?callable $onError=null)
 
 executeInsert (string $queryName, array $args=[], ?callable $onInserted=null, ?callable $onError=null)
 
 executeInsertRaw (string $query, array $args=[], ?callable $onInserted=null, ?callable $onError=null)
 
 executeSelect (string $queryName, array $args=[], ?callable $onSelect=null, ?callable $onError=null)
 
 executeSelectRaw (string $query, array $args=[], ?callable $onSelect=null, ?callable $onError=null)
 
 waitAll ()
 
 checkResults ()
 
 close ()
 

Detailed Description

Definition at line 48 of file DataConnectorImpl.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Plugin  $plugin,
SqlThread  $thread,
?string  $placeHolder,
bool  $logQueries = false 
)
Parameters
Plugin$plugin
SqlThread$threadthe backend SqlThread to connect with
null | string$placeHolderthe backend-implementation-dependent placeholder. "?" for mysqli-based backends, null for PDO-based and SQLite3-based backends.
bool$logQueries

Definition at line 69 of file DataConnectorImpl.php.

Member Function Documentation

◆ checkResults()

checkResults ( )

Definition at line 261 of file DataConnectorImpl.php.

◆ close()

close ( )

Closes the connection and/or all child connections. Remember to call this method when the plugin is disabled or the data provider is switched.

Implements DataConnector.

Definition at line 265 of file DataConnectorImpl.php.

◆ executeChange()

executeChange ( string  $queryName,
array  $args = [],
?callable  $onSuccess = null,
?callable  $onError = null 
)

Executes a query that changes data.

Parameters
string$queryNamethe GenericPreparedStatement query name
mixed[]$args the variables as defined in the GenericPreparedStatement
callable | null$onSuccessan optional callback when the query has succeeded: function(int $affectedRows) : void{}
callable | null$onErroran optional callback when the query has failed: function(SqlError $error) : void{}

Implements DataConnector.

Definition at line 118 of file DataConnectorImpl.php.

◆ executeChangeRaw()

executeChangeRaw ( string  $query,
array  $args = [],
?callable  $onSuccess = null,
?callable  $onError = null 
)

Implements DataConnector.

Definition at line 126 of file DataConnectorImpl.php.

◆ executeGeneric()

executeGeneric ( string  $queryName,
array  $args = [],
?callable  $onSuccess = null,
?callable  $onError = null 
)

Executes a generic query that either succeeds or fails.

Parameters
string$queryNamethe GenericPreparedStatement query name
mixed[]$args the variables as defined in the GenericPreparedStatement
callable | null$onSuccessan optional callback when the query has succeeded: function() : void{}
callable | null$onErroran optional callback when the query has failed: function(SqlError $error) : void{}

Implements DataConnector.

Definition at line 102 of file DataConnectorImpl.php.

◆ executeGenericRaw()

executeGenericRaw ( string  $query,
array  $args = [],
?callable  $onSuccess = null,
?callable  $onError = null 
)

Implements DataConnector.

Definition at line 110 of file DataConnectorImpl.php.

◆ executeInsert()

executeInsert ( string  $queryName,
array  $args = [],
?callable  $onInserted = null,
?callable  $onError = null 
)

Executes an insert query that results in an insert ID.

Parameters
string$queryNamethe GenericPreparedStatement query name
mixed[]$args the variables as defined in the GenericPreparedStatement
callable | null$onInsertedan optional callback when the query has succeeded: function(int $insertId, callable $affectedRows) : void{}
callable | null$onErroran optional callback when the query has failed: function(SqlError $error) : void{}

Implements DataConnector.

Definition at line 134 of file DataConnectorImpl.php.

◆ executeInsertRaw()

executeInsertRaw ( string  $query,
array  $args = [],
?callable  $onInserted = null,
?callable  $onError = null 
)

Implements DataConnector.

Definition at line 142 of file DataConnectorImpl.php.

◆ executeSelect()

executeSelect ( string  $queryName,
array  $args = [],
?callable  $onSelect = null,
?callable  $onError = null 
)

Executes a select query that returns an SQL result set. This does not strictly need to be SELECT queries – reflection queries like MySQL's SHOW TABLES query are also allowed.

Parameters
string$queryNamethe GenericPreparedStatement query name
mixed[]$args the variables as defined in the GenericPreparedStatement
callable | null$onSelectan optional callback when the query has succeeded: function(array[] $rows, SqlColumnInfo $columns) : void{}
callable | null$onErroran optional callback when the query has failed: function(SqlError $error) : void{}

Implements DataConnector.

Definition at line 150 of file DataConnectorImpl.php.

◆ executeSelectRaw()

executeSelectRaw ( string  $query,
array  $args = [],
?callable  $onSelect = null,
?callable  $onError = null 
)

Implements DataConnector.

Definition at line 158 of file DataConnectorImpl.php.

◆ isLoggingQueries()

isLoggingQueries ( )

Returns whether the queries are being logged. Always returns false when libasynql is packaged.

Returns
bool

Implements DataConnector.

Definition at line 83 of file DataConnectorImpl.php.

◆ loadQuery()

loadQuery ( GenericStatement  $stmt)

Loads a pre-formatted query.

Parameters
GenericStatement$stmt
Exceptions
InvalidArgumentExceptionif the statement duplicates the name of one previously loaded

Implements DataConnector.

Definition at line 95 of file DataConnectorImpl.php.

◆ loadQueryFile()

loadQueryFile (   $fh,
string  $fileName = null 
)

Loads pre-formatted queries from a readable stream resource.

The implementation will close the stream after reading.

Parameters
resource$fha stream that supports feof(), fgets() and fclose().
string$fileNamethe filename providing the stream, only used for debugging and documentation purposes
Exceptions
GenericStatementFileParseExceptionif the file contains a syntax error or compile error
InvalidArgumentExceptionif the file introduces statements that duplicate the names of those previously loaded

Implements DataConnector.

Definition at line 87 of file DataConnectorImpl.php.

◆ setLoggingQueries()

setLoggingQueries ( bool  $loggingQueries)

Sets whether the queries are being logged. Only effective when libasynql is not packaged; does nothing if libasynql is packaged.

Parameters
bool$loggingQueries

Implements DataConnector.

Definition at line 79 of file DataConnectorImpl.php.

◆ waitAll()

waitAll ( )

This function waits all pending queries to complete then returns. This is as if the queries were executed in blocking mode (not async).

This method should only under very rare events like server start/stop. This should not be run trivially (e.g. every time player joins), because otherwise this is not async.

Implements DataConnector.

Definition at line 254 of file DataConnectorImpl.php.


The documentation for this class was generated from the following file: