DBDataSource Class Reference

[DataWidget Index] [DataWidget Hierarchy]


General part of the manager More...

#include <dbdatasource.h>

Inherits: QObject

Public Members

Public Slots

Protected Members

Protected Slots

Signals


Detailed Description

General part of the manager. The manager consists of two classes. DBDatasource keeps track of the state and emits the signals. A class derrived from DBRecord handles the database connection.


DBDataSource(DBRecord *rec)

The constructor expects a record created with new. The destructor will delete the record.

virtual ~DBDataSource()

Destructor.

virtual void setQuery(const QString query, bool removeTables = false)

Thin wrapper for DBRecord::setQuery

See Also:
DBRecord

virtual void addTable(const char *table, const char *primaries, const char *columns)

Thin wrapper for DBRecord::setTable

See Also:
DBRecord

virtual void setMaster(DBDataSource *master, const char *join, const char *init = 0, bool cascadeRemove = false)

Restricts the dataset to the correspontin detail-recors of the master-record. You have to call setQuery with a proper select statement. It must include parameters for the foreign keys eg. "select * from order where custid = ?"

Parameters:
join This string describes the foreign keys of the select statement. Pairs of index=index seperated by blanks eg. "1=0 2=1". The first one is the index of the field of the master datasource. The second is the index of the parameter.
cascadeRemove If true, removeing a master record also removes the detail records.
init Appending a new record will initialize the foreign keys from the corresonding fields. Pairs of index=index seperated by blanks eg. "1=0 2=1". The first one is the index of the field of the master datasource. The second is the index of the field of this source.
master The master of this detail datasource.

int getNumCols()

Thin wrapper for DBRecord::getNumCols

const char *getColumnName(int col)

Thin wrapper for DBRecord::getColumnName

const char *getColumnQualifierName(int col)

Thin wrapper for DBRecord::getColumnQualifierName

int getColumnType(int col)

Thin wrapper for DBRecord::getColumnType

Returns:
DBTypes::TypeLong DBTypes::TypeDouble DBTypes::TypeDate DBTypes::TypeTime DBTypes::TypeDateTime DBTypes::TypeBinary DBTypes::TypeString

const char *getColumnTypeName(int col)

Thin wrapper for DBRecord::getColumnTypeName

long getColumnLength(int col)

Thin wrapper for DBRecord::getColumnLength

int getColumnPrecision(int col)

Thin wrapper for DBRecord::getColumnPrecision

int getColumnScale(int col)

Thin wrapper for DBRecord::getColumnScale

long getColumnDisplaySize(int col)

Thin wrapper for DBRecord::getColumnDisplaySize

int getColumnNullable(int col)

Thin wrapper for DBRecord::getColumnNullable

int getColumnUnsigned(int col)

Thin wrapper for DBRecord::getColumnUnsigned

int getColumnMoney(int col)

Thin wrapper for DBRecord::getColumnMoney

int getColumnUpdatable(int col)

Thin wrapper for DBRecord::getColumnUpdatable

int getColumnAutoIncrement(int col)

Thin wrapper for DBRecord::getColumnAutoIncrement

long getNumRows()

Thin wrapper for DBRecord::getNumRows

bool isActive()

The datasource is active.

bool isError()

An error occured.

bool isEditMode()

A value of the record was changed but not posted to the database.

bool isInsertMode()

A record was appended but not posted to the database.

bool hasRecord()

You can call setValue / getValue.

bool isReadOnly()

You cal call post

bool isEditable()

A widget may offer editing.

bool isAutoEdit()

SetValue will switch to edit mode.

bool isAutoPost()

Changed fields will be written to the database before changing the database cursor.

state getState()

Returns the state: Inactive, Error, Browse, Edit, Insert, CalcFields

const char *getStateName(state s)

Translates the state id to a string representation.

const QString &getErrorInfo()

Thin wrapper for DBRecord::getErrorInfo

long getCursor()

Thin wrapper for DBRecord::getCursor

bool isBOF()

Is the cursor before th first record ?

bool isEOF()

Is the cursor behind the last record ?

QString getQString(int col, const char *format = 0)

Wrapper for DBRecord::getValue

Parameters:
format A printf or strftime format string. WARNING the resust string must not exeed 8000 bytes! The format must correspond to getColumnType()
typecalled by
DBTypes::TypeLongsprintf(buf, format, *(long *)buffer);
DBTypes::TypeDoublesprintf(buf, format, *(double*)buffer);
DBTypes::TypeDatestrftime(buf, 99, format &t);
DBTypes::TypeTimestrftime(buf, 99, format &t);
DBTypes::TypeDateTimestrftime(buf, 99, format &t);
DBTypes::TypeBinarysprintf(buf, format, (char *)buffer);
DBTypes::TypeStringsprintf(buf, format, (char *)buffer);
col the column index, 0 based

QDate getQDate(int col)

Wrapper for DBRecord::getValue

QTime getQTime(int col)

Wrapper for DBRecord::getValue

QDateTime getQDateTime(int col)

Wrapper for DBRecord::getValue

double getDouble(int col)

Wrapper for DBRecord::getValue

long getLong(int col)

Wrapper for DBRecord::getValue

bool isNull(int col)

Has column a null value

bool setValue(const QString &str, int column)

Wrapper for DBRecord::setValue Switches to edit mode, if autoedit is set.

bool setValue(const QDate &val, int column)

Wrapper for DBRecord::setValue Switches to edit mode, if autoedit is set.

bool setValue(const QTime &val, int column)

Wrapper for DBRecord::setValue Switches to edit mode, if autoedit is set.

bool setValue(const QDateTime &val, int column)

Wrapper for DBRecord::setValue Switches to edit mode, if autoedit is set.

bool setValue(double num, int column)

Wrapper for DBRecord::setValue Switches to edit mode, if autoedit is set.

bool setValue(long num, int column)

Wrapper for DBRecord::setValue Switches to edit mode, if autoedit is set.

bool setNull(int column)

sets the value to null Switches to edit mode, if autoedit is set.

bool setParameter(const QString &str, int column)

Wrapper for DBRecord::setParameter

bool setParameter(const QDate &val, int column)

Wrapper for DBRecord::setParameter

bool setParameter(const QTime &val, int column)

Wrapper for DBRecord::setParameter

bool setParameter(const QDateTime &val, int column)

Wrapper for DBRecord::setParameter

bool setParameter(double val, int column)

Wrapper for DBRecord::setParameter

bool setParameter(long val, int column)

Wrapper for DBRecord::setParameter

int getColumnIdx(char *column)

Get the column index of the column, 0 based

Parameters:
column the name of the column

int getColumnIdx(char *table, char *column)

Get the column index of the column, 0 based

Parameters:
table the name of the table respectively the alias (Id did'n work for me, the mysql odbc driver hides the tablename ???)
column the name of the column

virtual bool open()

Opens the DBRecord.

virtual void close()

Closes the DBRecord.

virtual void setAutoEdit(bool on)

SetValue will switch to edit mode, default: false.

virtual void setAutoPost(bool on)

Changed fields will be written to the database before changing the database cursor, default false.

virtual void setAutoRefresh(bool on)

Fetch resultset from database after post, default true.

virtual void setReadOnly(bool on)

Marks datasource as readonly. If the DBRecord is readonly the datasource will stay readonly!

virtual bool edit()

Switches to edit mode.

virtual bool append()

Apends a record and initializes it with 0 resp. "". Switches to insert mode.

Parameters:
setNull True: init with null values if column allows it. False init with 0 or "".

virtual bool copy()

Apends a record and initializes it from the current record. Switches to insert mode.

virtual bool remove()

Deletes the current record from the database.

virtual bool post()

Insert the current record if the datasource is in insert mode. Updates the database if the datasource is in edit mode.

virtual bool refresh()

Fetch resultset from database.

virtual bool cancel()

Cancels the last edit/append/copy

virtual void abort()

If you call abort from a slot connected to a beforeXXX signel, it will stop the operation.

virtual bool first()

Wrapper for DBRecord::first

virtual bool prior()

Wrapper for DBRecord::prior

virtual bool next()

Wrapper for DBRecord::next

virtual bool last()

Wrapper for DBRecord::last

virtual bool moveBy(long)

Wrapper for DBRecord::moveBy

virtual bool moveTo(long)

Wrapper for DBRecord::moveTo

virtual void disableWidgets()

This method saves the current state and suspresses all signals.

virtual void enableWidgets()

This method resores the state.

void stateChanged()

The state of the datasource changed.

void cursorChanged()

The position of the database cursor changed. If an operation changes the state and the cursor stateChanged is emited first. The datasource also emits cursorChanged if the set changed.

void dataChanged(int column)

A value of a field changed. If the change is caused by a cursor movement, only cursorChanged is emited.

void beforeEdit()

Something wants to switch to edit mode. You can call abort to keep the old state.

void afterEdit()

The datasource is now in edit mode.

void beforeAppend(bool isCopy)

Something wants to switch to insert mode. You can call abort to keep the old state.

Parameters:
isCopy True if the new record will be initialized from the current record.

void afterAppend(bool isCopy)

The datasource is now in insert mode.

Parameters:
isCopy True if the new record was initialized from the current record.

void beforeRemove()

Something wants to delete the current record from the database. You can call abort to keep the old state.

void afterRemove()

The database record is deleted and the next current record is now the current one.

void beforePost(bool isInsert)

Sonething wants to post the current record to the database. You can call abort to keep the old state.

void afterPost(bool isInsert)

The chaned values have been written to the database.

void beforeCancel()

Sonething wants to cancel the edit/append/copy call. You can call abort to keep the old state.

void afterCancel()

The edit/append/copy is canceled.

void aborted()

A beforeXXX slot aborted an operation.

void calcFields()

The dataset fetched a record from the database. A setValue call will not be mark the record for update.

void newRecord(bool isCopy)

A append or copy created a new record. A setValue call will not be mark the record for insert.


  • Author: Edwin Glaser
  • Version: $Name: $ $Date: 2000/02/07 21:41:55 $
  • Documentation generated by eg@wonko on Sam Feb 19 00:09:53 MET 2000
Kdoc