Ananas Library 0.9.5
aExtSQL Class Reference

#include <aextsql.h>

Inheritance diagram for aExtSQL:
AExtension

Public Slots

QSqlSelectCursor * Cursor () const
 Return inner cursor which contains result of last call method ExecQuery or ExecScalar.
QVariant Value (int col) const
int Size () const
 Return record count in result. .
int Count () const
 Return column count in result. .
bool ExecQuery (const QString &query)
 Function for query execution.
QVariant ExecScalar (const QString &query)
 This function similar to described above ExecQuery(),.
bool First ()
 Make first record of result as current.
bool Next ()
 Make next record of result as current.
bool Last ()
 Make last record of result as current.
bool Prev ()
 Make previous record of result as current.
QString SqlFieldName (aObject *obj, const QString &userFieldName, const QString &tableType="") const
 Gets sql name of field by its user name.
QString SqlTableName (aObject *obj, const QString &tableType="") const
QString SqlTableName (const QString &objName) const
 Not implemented yet. .
QString SqlFieldName (const QString &fieldName) const
 Not implemented yet. .
QString LastError () const
 Returns text representation last error or emty text, if no error occured.

Public Member Functions

 aExtSQL ()
 Constructor .
virtual int init (aDatabase *database)
 Init function, owerrides function in base class, creates inner database specific object and variables. .
 ~aExtSQL ()
 Destructor .
Public Member Functions inherited from AExtension
 AExtension (const char *name=0)

Additional Inherited Members

Signals inherited from AExtension
void event (const QString &data)
Public Attributes inherited from AExtension
aDatabasedb

Detailed Description

Constructor & Destructor Documentation

◆ aExtSQL()

aExtSQL::aExtSQL ( )

Constructor .

◆ ~aExtSQL()

aExtSQL::~aExtSQL ( )

Destructor .

Member Function Documentation

◆ Count

int aExtSQL::Count ( ) const
slot

Return column count in result. .

◆ Cursor

QSqlSelectCursor * aExtSQL::Cursor ( ) const
slot

Return inner cursor which contains result of last call method ExecQuery or ExecScalar.

for bindings to external table (QDataTable etc.). Don't delete this cursor after use!

Returns
Inner cursor.
See also
aExtSQL::ExecQuery()
aExtSQL::ExecScalar()

◆ ExecQuery

bool aExtSQL::ExecQuery ( const QString & query)
slot

Function for query execution.

    Only select statement supported. If any error occured, returns false. Fom move to result records use First(), Next(), Last() and Prev() functions. For get information about last error occured use LastError() function.
    \param query (in) - sql query for execution. 
    \return true, if no error occured. 
var sql = new SQL();
if( !sql.ExecQuery("select * from a_journ") )
{
sys.Message(1,"Ошибка в вашем sql запросе:" + sql.LastError());
return;
}
if(sql.First())
{
do{
sys.Message(0, sql.Value(0));
} while(sql.Next());
}
See also
aExtSQL::ExecScalar()
aExtSQL::Value()
aExtSQL::LastError()

◆ ExecScalar

QVariant aExtSQL::ExecScalar ( const QString & query)
slot

This function similar to described above ExecQuery(),.

    but return only first cell in first record or QVariant::Invalid, if no recornds returned or error occured. 
    But if you know, that more than one record returned, you can navigate throw thouse records use function First(), Next() ...
    \param query (in) - sql query for execution. 
    \return Query result or QVariant::Invalid 
var sql = new SQL();
var res = sql.ExecScalar("select count(*) from a_journ") )
sys.Message(0, res + "records in system journal");
See also
aExtSQL::ExecQuery()

◆ First

bool aExtSQL::First ( )
slot

Make first record of result as current.

    You should first call ExecQuery for call this function have sence.
    \return true if success  
See also
aExtSQL::ExecuteQuery()

◆ init()

int aExtSQL::init ( aDatabase * database)
virtual

Init function, owerrides function in base class, creates inner database specific object and variables. .

Reimplemented from AExtension.

References aDatabase::db().

◆ Last

bool aExtSQL::Last ( )
slot

Make last record of result as current.

Returns
true if success
See also
aExtSQL::ExecuteQuery()

◆ LastError

QString aExtSQL::LastError ( ) const
slot

Returns text representation last error or emty text, if no error occured.

Returns driver text only.

◆ Next

bool aExtSQL::Next ( )
slot

Make next record of result as current.

Returns
true if success
See also
aExtSQL::ExecuteQuery()

◆ Prev

bool aExtSQL::Prev ( )
slot

Make previous record of result as current.

Returns
true if success
See also
aExtSQL::ExecuteQuery()

◆ Size

int aExtSQL::Size ( ) const
slot

Return record count in result. .

◆ SqlFieldName [1/2]

QString aExtSQL::SqlFieldName ( aObject * obj,
const QString & userFieldName,
const QString & tableType = "" ) const
slot

Gets sql name of field by its user name.

To every Ananas object user can add his own fields. Unfortunatly when you generate SQL query you should use sql field name instead of user field name. This function help do it easy. All what you need - create new object you want use in query, specify user field name and table (primary or one of secondary). See SqlTableName() for details about table naming. However, every sql table contains some system fields. That fields also can be used in query. See documentation on ananas object for details.

Parameters
obj(in) - Ananas object. Using as contex for field search.
userFieldName(in) - User field name
tableType(optional) - Table type. For catalogue group table mapped to "group" alias, For accumulation register every saldo table mapped to dimension user name alias.
Returns
sql field name
var sql = new SQL();
var cat = new Catalogue("Goods");
sys.Message(0, sql.SqlFieldName(cat, "Full name"); // uf203
sys.Message(0, sql.SqlFieldName(cat, "Group name", "group") //uf304
var doc = new Document("Order");
sys.Message(0, sql.SqlFieldName(doc, "Organization"); //uf449
var reg = new ARegister("Grossbuch");
sys.Message(0, sql.SqlFieldName(reg, "Good"); // uf333
See also
aExtSQL::SqlTableName()

References aObject::table().

◆ SqlFieldName [2/2]

QString aExtSQL::SqlFieldName ( const QString & fieldName) const
slot

Not implemented yet. .

References aCfg::find(), aCfg::id(), and aCfg::objClass().

◆ SqlTableName [1/2]

QString aExtSQL::SqlTableName ( aObject * obj,
const QString & tableType = "" ) const
slot
\if english
   \brief Gets SQL name of primary or one of secondary object tables.

           All Ananas objects except Report store theyr values in sql tables. For Catalogue this is group table and element table (pri), for Document - data header table, for Journal - always system journal table, for IRegister - one table for all data, for ARegister - main table for store operations (pri) and X table for store saldo, where X - dimensions count. So if you want get name of primary table, leave parameter \atableType or set in to empty string. If you want get name of secondary table, set parameter \atableType to "group" for catalogue group table or dimension user name for accumulation register saldo table for that dimension.
   \param obj (in) -  Object for getting table name. 
   \param tableType (optional) - Table type 
   \return sql table name 
var sql = new SQL();
var cat = new Catalogue("Goods");
sys.Message(0, sql.SqlTableName(cat)); //ce101
sys.Message(0, sql.SqlTableName(cat, "")); //ce101
sys.Message(0, sql.SqlTableName(cat, "group")); //cg105
var doc = new Document("Order");
sys.Message(0, sql.SqlTableName(doc)); //dh130
var journ = new Journal("main journal");
sys.Message(0, sql.SqlTableName(journ)); // a_journ
var ireg = new IRegister("Info register"));
sys.Message(0, sql.SqlTableName(ireg)); // ra303
var areg = new ARegister("Acc Register");
sys.Message(0, sql.SqlTableName(areg)); // ra330
sys.Message(0, sql.SqlTableName(areg),"Goods") //ra330_d445
See also
aExtSQL::SqlFieldName()

References aObject::table().

◆ SqlTableName [2/2]

QString aExtSQL::SqlTableName ( const QString & objName) const
slot

Not implemented yet. .

References aCfg::find(), aCfg::objClass(), and aDatabase::tableDbName().

◆ Value

QVariant aExtSQL::Value ( int col) const
slot

Gets value of column number \acol (zero based) from current record or QVariant::Invalid if error occured or \acol value out of range.

Parameters
col(in) - Column Index
Returns
Column value
See also
aExtSQL::Count()

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