MeVisLab Scripting Reference
MLABSqlQuery Class Reference

Inherits QObject.

Public Slots

Send SQL statements


bool exec (const QString &sqlStatement)
 
bool execQuery (const QString &sqlStatement)
 
bool exec ()
 
bool execQuery ()
 
bool prepare (const QString &sqlStatement)
 
void bindValue (const QString &name, const QVariant &value)
 
void bindValue (int i, const QVariant &value)
 
bool isActive ()
 
bool isSelect ()
 
bool isValid ()
 
int rowsAffected ()
 
int size ()
 
QVariant lastInsertId ()
 
QString lastQuery ()
 
QSqlQuery * getQSqlQuery ()
 
QSqlDatabase * getQSqlDatabase ()
 
QSqlRecord * getQSqlRecord ()
 
Navigate query results.


bool next ()
 
bool prev ()
 
bool first ()
 
bool last ()
 
Reading the current selected record.


QVariant value (int i)
 
QList< QVariant > values ()
 
QList< QVariant > allValues ()
 
int numValues ()
 
QStringList fieldNames ()
 
QMap< QString, QVariant > record ()
 
int indexOfField (const QString &name)
 
QVariant valueOfField (const QString &name)
 

Detailed Description

MLABSqlQuery.

The MLABSqlQuery object can be used to query an associated database.

Member Function Documentation

◆ allValues

QList<QVariant> MLABSqlQuery::allValues ( )
slot

Returns all records as a list of QValueList<QVariant>.

◆ bindValue [1/2]

void MLABSqlQuery::bindValue ( const QString &  name,
const QVariant &  value 
)
slot

Binds the value of placeholder name.

◆ bindValue [2/2]

void MLABSqlQuery::bindValue ( int  i,
const QVariant &  value 
)
slot

Binds the value of placeholder i (starting from 0).

◆ exec [1/2]

bool MLABSqlQuery::exec ( )
slot

Executes a prepared query.

◆ exec [2/2]

bool MLABSqlQuery::exec ( const QString &  sqlStatement)
slot

Executes the given SQL statement, returns whether it was successful.

Note that using "SELECT table.*" is a bad idea because the indexes of the fields will not have any order.

◆ execQuery [1/2]

bool MLABSqlQuery::execQuery ( )
slot

Executes a prepared query like exec() but with an aliased name because exec is a reserved keyword in Python.

◆ execQuery [2/2]

bool MLABSqlQuery::execQuery ( const QString &  sqlStatement)
slot

Executes the given SQL statement, returns whether it was successful.

Note that using "SELECT table.*" is a bad idea because the indexes of the fields will not have any order. Executes the given SQL statement like exec() but with an aliased name because exec is a reserved keyword in Python.

◆ fieldNames

QStringList MLABSqlQuery::fieldNames ( )
slot

Returns the names of the fields in the record.

◆ first

bool MLABSqlQuery::first ( )
slot

Sets cursor to first result record of a select (returns false if no first record is available).

◆ getQSqlDatabase

QSqlDatabase* MLABSqlQuery::getQSqlDatabase ( )
inlineslot

Returns the underlying QSqlDatabase instance.

◆ getQSqlQuery

QSqlQuery* MLABSqlQuery::getQSqlQuery ( )
inlineslot

Returns the underlying QSqlQuery instance.

◆ getQSqlRecord

QSqlRecord* MLABSqlQuery::getQSqlRecord ( )
inlineslot

Returns the current QSqlRecord instance.

◆ indexOfField

int MLABSqlQuery::indexOfField ( const QString &  name)
slot

Returns the value index of the given field for usage with "value".

◆ isActive

bool MLABSqlQuery::isActive ( )
slot

Returns whether a select statement is active and successful.

◆ isSelect

bool MLABSqlQuery::isSelect ( )
slot

Returns whether the query is a select statement.

◆ isValid

bool MLABSqlQuery::isValid ( )
slot

Returns whether the query is positioned on a valid record.

◆ last

bool MLABSqlQuery::last ( )
slot

Sets cursor to last result record of a select (returns false if no last record is available).

◆ lastInsertId

QVariant MLABSqlQuery::lastInsertId ( )
slot

Returns the object ID of the most recent inserted row if the database supports it.

An invalid QVariant will be returned if the query did not insert any value or if the database does not report the id back. If more than one row was touched by the insert, the behavior is undefined.

◆ lastQuery

QString MLABSqlQuery::lastQuery ( )
slot

Returns the text of the current query being used, or an empty string if there is no current query text.

◆ next

bool MLABSqlQuery::next ( )
slot

Sets cursor to next result record of a select (returns false if no next record is available).

◆ numValues

int MLABSqlQuery::numValues ( )
slot

Returns the number of values in the record.

◆ prepare

bool MLABSqlQuery::prepare ( const QString &  sqlStatement)
slot

Sets a prepared statement, use execQuery() to execute the statement.

Example 1 (with named placeholders and indices):

query.prepare( "INSERT INTO atable (id, forename, surname) VALUES (:id, :forename, :surname)" )
query.bindValue( 0, 1001 )
query.bindValue( 1, "Bart" )
query.bindValue( 2, "Simpson" )
query.execQuery()

Example 2 (with named placeholder):

query.prepare( "INSERT INTO atable (id, forename, surname) VALUES (:id, :forename, :surname)" )
query.bindValue( ":id", 1001 )
query.bindValue( ":forename", "Bart" )
query.bindValue( ":surname", "Simpson" )
query.execQuery()

Example 3 (with question mark placeholders):

query.prepare( "INSERT INTO atable (id, forename, surname) VALUES (?, ?, ?)" )
query.bindValue( 0, 1001 )
query.bindValue( 1, "Bart" )
query.bindValue( 2, "Simpson" )
query.execQuery()

◆ prev

bool MLABSqlQuery::prev ( )
slot

Sets cursor to previous result record of a select (returns false if no previous record is available).

◆ record

QMap<QString,QVariant> MLABSqlQuery::record ( )
slot

Returns the current record of a select as map (fieldnames->values).

◆ rowsAffected

int MLABSqlQuery::rowsAffected ( )
slot

Returns the number of rows that where affected by the exec statement (NOT the number of records found with SELECT).

◆ size

int MLABSqlQuery::size ( )
slot

Returns the size of the resulting records of a SELECT statement (-1 if size is unknown).

◆ value

QVariant MLABSqlQuery::value ( int  i)
slot

Returns the field's value at position i of the current record of the select statement (in order of appearance in the select statement).

◆ valueOfField

QVariant MLABSqlQuery::valueOfField ( const QString &  name)
slot

Returns the value for the named field in the current record.

◆ values

QList<QVariant> MLABSqlQuery::values ( )
slot

Returns the values of the fields of the current record.