Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
Public Member Functions | List of all members
Ilwis::DatabaseTable Class Reference

#include <databasetable.h>

Inheritance diagram for Ilwis::DatabaseTable:
Ilwis::BaseTable Ilwis::Table Ilwis::IlwisObject Ilwis::Identity

Public Member Functions

 DatabaseTable ()
 
 DatabaseTable (const Resource &resource)
 
void setDatabase (const QSqlDatabase &base)
 
QSqlDatabase database () const
 
bool createTable ()
 
bool addColumn (const QString &name, const IDomain &domain)
 
bool prepare ()
 
bool isValid () const
 
QString internalName () const
 
template<class T >
bool insertColumn (const QString &col, const QVector< T > &values, const IDomain &dom)
 
template<class T >
bool updateColumn (const QString &col, const QVector< T > &values)
 
std::vector< QVariant > record (quint32 n) const
 
void record (quint32 rec, const std::vector< QVariant > &vars, quint32 offset=0)
 
std::vector< QVariant > column (const QString &nme, quint32 start=0, quint32 stop=2e9) const
 
std::vector< QVariant > column (quint32 index, quint32 start=0, quint32 stop=2e9) const
 
void column (const QString &nme, const std::vector< QVariant > &vars, quint32 offset=0)
 
void column (quint32 index, const std::vector< QVariant > &vars, quint32 offset)
 
QVariant cell (const QString &col, quint32 rec, bool asRaw=true) const
 
QVariant cell (quint32, quint32 rec, bool asRaw=true) const
 
void setCell (const QString &col, quint32 rec, const QVariant &inputvar)
 
void setCell (quint32, quint32 rec, const QVariant &var)
 
void drop ()
 
IlwisTypes ilwisType () const
 
std::vector< quint32 > select (const QString &conditions) const
 
IlwisObjectclone ()
 
void newRecord ()
 
- Public Member Functions inherited from Ilwis::BaseTable
 BaseTable ()
 
 BaseTable (const Resource &resource)
 
virtual quint32 recordCount () const
 
virtual quint32 columnCount () const
 
virtual void recordCount (quint32 r)
 
virtual bool addColumn (const QString &name, const QString &domainname)
 
virtual bool addColumn (const ColumnDefinition &def)
 
ColumnDefinition columndefinition (const QString &nme) const
 
ColumnDefinition columndefinition (quint32 index) const
 
ColumnDefinitioncolumndefinition (quint32 index)
 
void columndefinition (const ColumnDefinition &coldef)
 
bool merge (const IlwisObject *obj, int options)
 
void dataLoaded (bool yesno)
 
bool isDataLoaded () const
 

Additional Inherited Members

- Public Types inherited from Ilwis::IlwisObject
enum  ConnectorMode { cmINPUT =1, cmOUTPUT =2, cmEXTENDED =4 }
 The ConnectorMode enum Describes the state of the instance of the connector. More...
 
enum  StoreMode { smMETADATA =1, smBINARYDATA =2 }
 
- Static Public Member Functions inherited from Ilwis::IlwisObject
template<typename T >
static T create (const QString &def)
 
template<typename T >
static T create (quint64 id)
 
static IlwisObjectcreate (const Resource &source, const PrepareOptions &options=PrepareOptions())
 
static IlwisTypes findType (const QString &source)
 findType More...
 
static QString type2Name (IlwisTypes t)
 
static IlwisTypes name2Type (const QString &name)
 
static void addTypeFunction (IlwisTypeFunction)
 addTypeFunction More...
 
static IlwisTypes name2ExtendedType (const QString &dname)
 
- Protected Member Functions inherited from Ilwis::BaseTable
virtual void adjustRange (int index)
 
void copyTo (IlwisObject *obj)
 
quint32 columnIndex (const QString &nme) const
 
void columnCount (int cnt)
 
QVariant checkInput (const QVariant &inputVar, quint32 columnIndex)
 
void initValuesColumn (const ColumnDefinition &def)
 
void initRecord (std::vector< QVariant > &values) const
 
- Protected Attributes inherited from Ilwis::BaseTable
QHash< QString, ColumnDefinition_columnDefinitionsByName
 
QHash< quint32, ColumnDefinition_columnDefinitionsByIndex
 

Detailed Description

Represents a table in the database Ilwis-Objects uses. In the default implementation it uses the internal sqllite database that qt has.

Constructor & Destructor Documentation

DatabaseTable::DatabaseTable ( )

Constructs an empty DatabaseTable and sets the sql create flag to false.

DatabaseTable::DatabaseTable ( const Resource resource)

The constructor for a DatabaseTable with a a Resource that is registered in the mastercatalog.
This resource must have a name and an Id.
Code and description are optional.
And sets the sql create flag to false.

See Also
IlwisObject
Resource
Parameters
sourceResource that has to be used

Member Function Documentation

bool DatabaseTable::addColumn ( const QString &  name,
const IDomain domain 
)
virtual

adds a column to the current set of columns of this table
the name string must be unique and the domain must be valid.
if this collumn creates a duplicate nothing will happen.
the collumn will be filled with appropriate defaults depending on the domain

See Also
IDomain
Parameters
namethe name of a column must be unique among the columns
domainthe domain of the new column
Returns
true if the column is succesfully added, false if some error occurred. The nature of the error can be found in the issue logger

Reimplemented from Ilwis::BaseTable.

QVariant DatabaseTable::cell ( const QString &  col,
quint32  rec,
bool  asRaw = true 
) const
virtual

returns the value of a single record/field combination ( a cell).
Disabling asRaw (setting it to false) has negative effects on performance.

Parameters
colcolumn name
recrecord number
asRawwhen set to false it will return the String value on Thematic and Identifier domains
Returns
the value of the cell or an invalid qvariant if an error occured. The nature of the error can be found in the issue logger

Implements Ilwis::Table.

QVariant DatabaseTable::cell ( quint32  index,
quint32  rec,
bool  asRaw = true 
) const
virtual

returns the value of a single record/field combination ( a cell).
Disabling asRaw (setting it to false) has negative effects on performance.

Parameters
indexcolumn index
asRawwhen set to false it will return the String value on Thematic and Identifier domains
recrecord number
Returns
the value of the cell or an invalid qvariant if an error occured. The nature of the error can be found in the issue logger

Implements Ilwis::Table.

std::vector< QVariant > DatabaseTable::column ( const QString &  nme,
quint32  start = 0,
quint32  stop = 2e9 
) const
virtual

returns the content of a column with a name in a vector. Will return an empty vector if there is no collumn with that name

Parameters
nmename of the column to be returned
startThe index at which it should start returning values(within the collumn)
stopThe index at which it should stop returning values(within the collumn)
Returns
A filled variantlist or an empty list if an error occurred. The nature of the error can be found in the issue logger

Implements Ilwis::Table.

std::vector< QVariant > DatabaseTable::column ( quint32  index,
quint32  start = 0,
quint32  stop = 2e9 
) const
virtual

returns the content of a column at a index in a vector. Will return an empty vector if there is no column with that name

Parameters
indexthe index of the column to be returned
startThe index at which it should start returning values(within the collumn)
stopThe index at which it should stop returning values(within the collumn)
Returns
A filled variantlist or an empty list if an error occurred. The nature of the error can be found in the issue logger

Implements Ilwis::Table.

void DatabaseTable::column ( const QString &  nme,
const std::vector< QVariant > &  vars,
quint32  offset = 0 
)
virtual

sets a column with values from variantlist. The list doesnt need to contain all the rows in a column but may contain a subset.
Note that the rows are in consecutive order.

Parameters
nmename of the column to be set
varsvalues of the rows
offsetstarting row form where the values are set. If the number of values to be added goes beyond the size of the table, new records will be added

Implements Ilwis::Table.

void DatabaseTable::column ( quint32  index,
const std::vector< QVariant > &  vars,
quint32  offset 
)
virtual

sets a column with values from variantlist. The list doesnt need to contain all the rows in a column but may contain a subset.
Note that the rows are in consecutive order.

Parameters
indexindex of the column to be set
varsvalues of the rows
offsetstarting row form where the values are set. If the number of values to be added goes beyond the size of the table, new records will be added

Implements Ilwis::Table.

bool DatabaseTable::createTable ( )
virtual

Creates a table based on the definitions in the columndefinition members. Will load the data in the specified amount of collumns and rows

Returns
true if succesfull

Reimplemented from Ilwis::BaseTable.

void DatabaseTable::drop ( )

Drops the data in this DatabaseTable.
Also removes it from the database, and sets dataloaded and sql create to false.
If anything fails the error can be found on the issuelogger

IlwisTypes DatabaseTable::ilwisType ( ) const
virtual

Gives the IlwisTypes of this object

See Also
IlwisObject
Returns
the IlwisTypes of this IlwisObject

Reimplemented from Ilwis::BaseTable.

QString DatabaseTable::internalName ( ) const

Will try to construct the name of this table using the resource of this DatabaseTable.
The String will be of the following form : "<name>_<id>".
If it fails sUNDEF will be returned.

Returns
String representation of the name of this DatabaseTable
bool DatabaseTable::isValid ( ) const
virtual

a BaseTable is valid if it has rows and columns

Returns
true when valid.

Reimplemented from Ilwis::BaseTable.

void DatabaseTable::newRecord ( )
virtual

Adds a new record to this table It will be filled with appropriate default values depending on the domain(s)

Implements Ilwis::Table.

bool DatabaseTable::prepare ( )
virtual

tries to Prepares this ilwisobject for use

Returns
true when the prepare succeeded

Reimplemented from Ilwis::BaseTable.

std::vector< QVariant > DatabaseTable::record ( quint32  n) const
virtual

retrieves a record from a table. A record contains all the fields for one row. This method is implemented in the derivatives
of table as how records are organized is quite different between the derivatives

Parameters
nthe row/record number of the record
Returns
A filled variantlist or an empty list if an error occurred. The nature of the error can be found in the issue logger

Implements Ilwis::Table.

void DatabaseTable::record ( quint32  rec,
const std::vector< QVariant > &  vars,
quint32  offset = 0 
)
virtual

sets a record with values from variantlist. The list doesnt need to contain all the fields in a record but may contain a subset.
Note that the fields are in consecutive order. It is up to the programmer that the order of fields in the list match the order of fields in the table

Parameters
recrecord that has to be updated. If the record number is beyond the last record or the record is iUNDEF, the record will appended to the end
varsthe list values to be set
offsetstarting point of the field to be set

Implements Ilwis::Table.

std::vector< quint32 > DatabaseTable::select ( const QString &  conditions) const
virtual

Selects the indices of all collumns that meet the conditions specified in the conditions String
so for example: if conditions is

col1 < 5 AND col2 == "two"


it will return all indices at which collumns 1 and 2 meet the requirements

This function is still under development, only the most basic expressions are implemented at this time

Parameters
conditions
Returns

Implements Ilwis::Table.

void DatabaseTable::setCell ( const QString &  col,
quint32  rec,
const QVariant &  var 
)
virtual

Sets the value of a single cell

Parameters
colcolumn name of the cell to be set
recrecord number of the cell to be set
varthe new value of the cell

Implements Ilwis::Table.

void DatabaseTable::setCell ( quint32  col,
quint32  rec,
const QVariant &  var 
)
virtual

Sets the value of a single cell

Parameters
colindex of the column of the cell to be set
recrecord number of the cell to be set
varthe new value of the cell

Implements Ilwis::Table.


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