SqlDatabaseInterface Class Reference

#include <sqldatabase.h>

Inheritance diagram for SqlDatabaseInterface:

Detailed Description

This class provides SQL database functionality. With it it's possible to query sql databases. E.g. Result<SqlDatabaseRef> mySql = SqlDatabaseClasses::MySql().Create(); provides access to mysql databases.

Public Member Functions

MAXON_METHOD Result< void > Init (const String &sqlServer, Int sqlServerPort, const String &sqlUserName, const String &sqlPasswd, const String &sqlDatabase)
 
MAXON_METHOD Result< void > Init (const Url &sqlFile, const String &sqlDatabase)
 
MAXON_METHOD Bool IsConnected () const
 
MAXON_METHOD Result< void > QuerySQL (const String &query, Int64 *insertId=nullptr, const ValueReceiver< const BaseArray< String > & > &result={})
 
MAXON_METHOD Result< void > ExecuteSQLQuery (const String &query, const Block< ConstDataPtr > &arguments={}, Int64 *insertId=nullptr, const ValueReceiver< BaseArray< Data > && > &result={}, const ValueReceiver< const String & > &columnTitles={})
 
MAXON_METHOD Result< StringQuotedString (const String &text) const
 
MAXON_METHOD Result< StringReplaceString (const String &text) const
 
MAXON_METHOD Result< void > StartTransactions (const TimeValue &delayCommitTime, Int maxExecutes)
 
MAXON_METHOD Result< void > CommitTransactions ()
 

Private Member Functions

 MAXON_INTERFACE (SqlDatabaseInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.sqldatabase")
 

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( SqlDatabaseInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.sqldatabase"   
)
private

◆ Init() [1/2]

MAXON_METHOD Result<void> Init ( const String sqlServer,
Int  sqlServerPort,
const String sqlUserName,
const String sqlPasswd,
const String sqlDatabase 
)

Opens the connection to a.

Parameters
[in]sqlServerIP address of the sql server.
[in]sqlServerPortPort of the sql server.
[in]sqlUserNameUser name at the given sql server.
[in]sqlPasswdPassword of the user.
[in]sqlDatabaseOpens this database within the sql database on the server. This parameter is optional.
Returns
Returns true if opening the database was successful. @MAXON_ANNOTATION{returnsThis}

◆ Init() [2/2]

MAXON_METHOD Result<void> Init ( const Url sqlFile,
const String sqlDatabase 
)

Opens a connection to a database file.

Parameters
[in]sqlFileFile to open.
[in]sqlDatabaseOpens this database within the sql database on the server. This parameter is optional.
Returns
Returns true if opening the database was successful. @MAXON_ANNOTATION{returnsThis}

◆ IsConnected()

MAXON_METHOD Bool IsConnected ( ) const

Determines if the connection to the database has been established.

Returns
Returns true if the connection is open, otherwise false.

◆ QuerySQL()

MAXON_METHOD Result<void> QuerySQL ( const String query,
Int64 insertId = nullptr,
const ValueReceiver< const BaseArray< String > & > &  result = {} 
)

Sends a query to the database.

Parameters
[in]queryThe sql request string. E.g. "SELECT * from mydatabase".
[out]insertIdIf the query inserted data into the database, this pointer returns the insert id in the database. This parameter is optional.
[out]resultIf the query returns data it will be filled into this array. This parameter is optional. The outer array contains the number of lines returned by this query. The first line contains the field header names. The inner array the fields per line returned by this query.
Returns
Returns true if the query was successful, otherwise false.

◆ ExecuteSQLQuery()

MAXON_METHOD Result<void> ExecuteSQLQuery ( const String query,
const Block< ConstDataPtr > &  arguments = {},
Int64 insertId = nullptr,
const ValueReceiver< BaseArray< Data > && > &  result = {},
const ValueReceiver< const String & > &  columnTitles = {} 
)

ExecuteSQLQuery description.

Parameters
[in]queryThe sql request string. E.g. "SELECT * from mydatabase".
[in]argumentsIf the select statement contains "?" the arguments will be populated from the arguments array. e.g. "SELECT * from table WHERE col1 = ?"
[out]insertIdIf the query inserted data into the database, this pointer returns the insert id in the database. This parameter is optional.
[out]resultIf the query returns data it will be filled into this array. This parameter is optional. The outer array contains the number of lines returned by this query. The inner array the fields per line returned by this query.
[out]columnTitlesDelegate to receive the column titles. This is called once.
Returns
OK on success.

◆ QuotedString()

MAXON_METHOD Result<String> QuotedString ( const String text) const

This functions returns a quoted string usable for sql queries. This function calls internally ReplaceString() to make the given text sql conform.

Parameters
[in]textThe given text the has to be converted.
Returns
The converted string.

◆ ReplaceString()

MAXON_METHOD Result<String> ReplaceString ( const String text) const

This functions converts a string into usable style for sql queries.

Parameters
[in]textThe given text the has to be converted.
Returns
The converted string.

◆ StartTransactions()

MAXON_METHOD Result<void> StartTransactions ( const TimeValue delayCommitTime,
Int  maxExecutes 
)

StartTransactions calls "BEGIN TRANSACTION" to collect the next calls. After the given time the commit is done.

Parameters
[in]delayCommitTimeTime after which the commit should be called. Disabled if value == TIMEVALUE_INFINITE
[in]maxExecutesMaximum Number of executes after commit should be called. Disabled if maxExecutes == NOTOK
Returns
OK on success.

◆ CommitTransactions()

MAXON_METHOD Result<void> CommitTransactions ( )

CommitTransactions force to commit the changes since the last start of StartTransactions(). Does nothing if not in transaction mode

Returns
OK on success.