TerraLib 4.1
TeSQLite Class Reference

SQLite database access class. More...

#include <TeSQLite.h>

Inheritance diagram for TeSQLite:
TeDatabase

List of all members.

Public Member Functions

 TeSQLite ()
 Constructor.
virtual ~TeSQLite ()
 Destructor.
virtual bool insertRasterBlock (const string &table, const string &blockId, const TeCoord2D &ll, const TeCoord2D &ur, unsigned char *buf, unsigned long size, int band=0, unsigned int res=1, unsigned int subband=0)
 Insert a raster block into the database.
virtual string getSQLTime (const TeTime &time) const
 Returns a valid SQL time string.
virtual std::string getSQLOrderBy (const TeGeomRep &rep) const
virtual string errorMessage ()
 Returns the error message from the server.
int getLastInsertedSerial ()
Database

Methods related to database and connection creation. These methods return TRUE when the operation was successfull. Otherwise return FALSE and when possible an error message is captured.

virtual bool newDatabase (const string &database, const string &user, const string &password, const string &host, const int &port=-1, bool terralibModel=true, const std::string &characterSet="")
 Creates a new database and open a connection to it.
virtual bool connect (const string &host, const string &user, const string &password, const string &database, int port=-1)
 Opens a conection to a database server.
virtual void close (void)
 Closes the conection.
virtual bool tableExist (const string &table)
 Verifies if a table exist in the database.
virtual bool columnExist (const string &table, const string &column, TeAttribute &attr)
 Verifies if a table has a column.
virtual bool createTable (const string &table, TeAttributeList &attr)
 Creates a table.
virtual bool addColumn (const string &table, TeAttributeRep &rep)
 Adds a column to a table.
virtual bool alterTable (const string &tableName, TeAttributeRep &rep, const string &oldColName="")
 Alter a property of a table.
virtual bool alterTable (const string &oldTableName, const string &newTablename)
 Alter the table name.
virtual bool getIndexesFromTable (const string &tableName, std::vector< TeDatabaseIndex > &vecIndexes)
 Return a TeDatabaseIndex vector from a table.
virtual bool createRelation (const string &relName, const string &table, const string &fieldName, const string &relatedTable, const string &relatedField, bool cascadeDeletion)
 Creates a reationship between two tables.
virtual TeDBRelationType existRelation (const string &tableName, const string &relName)
 Checks if a relation exist.
virtual bool insertProject (TeProject *project)
 Insert information about a project.
virtual bool insertRelationInfo (const int tableId, const string &tField, const string &rTable, const string &rField, int &relId)
 Inserts information about a link to an external table.
virtual bool insertTableInfo (int layerId, TeTable &table, const string &user="")
 Inserts information about an attribute table.
virtual bool insertBlob (const string &tableName, const string &columnBlob, const string &whereClause, unsigned char *data, int size)
 Saves a large binary objects (BLOB) in a row table.
Projection

Accessing/Inserting/Modifying projection information into the database.

virtual bool insertProjection (TeProjection *proj)
 Insert information about a geographical projection.
Layers

Retrieving/Inserting/Modifying/Deleting layers in the database.

virtual bool insertLayer (TeLayer *layer)
 Insert information about a layer.
Representation

Retrieving/Inserting/Modifying/Deleting representations in the database.

virtual bool insertRepresentation (int layerId, TeRepresentation &rep)
 Inserts information about a geometrical representation.
Views

Retrieving/Inserting/Modifying/Deleting views in the database.

virtual bool insertView (TeView *view)
 Inserts a view.
virtual bool insertViewTree (TeViewTree *tree)
 Recursive inserting of a view tree.
Themes

Retrieving/Inserting/Modifying/Deleting themes and group of themes in the database.

virtual bool insertThemeGroup (TeViewTree *tree)
 Inserts a group of themes in the database.
virtual bool generateLabelPositions (TeTheme *theme, const std::string &objectId="")
 Generates the label position (x,y) to each object of a theme or of a particular object.
virtual bool insertTheme (TeAbstractTheme *theme)
 Inserts an abstract theme in the database.
virtual bool insertThemeTable (int themeId, int tableId, int relationId, int tableOrder)
 Inserts information about a table used by a theme.
Legend

Retrieving/Inserting/Modifying/Deleting legends in the database.

virtual bool insertLegend (TeLegendEntry *legend)
 Inserts legend in the database.
Polygon

Accessing/Inserting/Modifying polygon geometries into the database

virtual bool insertPolygon (const string &table, TePolygon &p)
 Inserts a polygon in a geometry table.
virtual bool updatePolygon (const string &table, TePolygon &p)
 Updates a polygon in a geometry table.
Line

Accessing/Inserting/Modifying Line geometries into the database.

virtual bool insertLine (const string &table, TeLine2D &l)
 Inserts a line in a geometry table.
virtual bool updateLine (const string &table, TeLine2D &l)
 Updates a line in a geometry table.
Point

Accessing/Inserting/Modifying Point geometries into the database.

virtual bool insertPoint (const string &table, TePoint &p)
Text

Accessing/Inserting/Modifying Text geometries into the database.

virtual bool insertText (const string &table, TeText &t)
Arc

Accessing/Inserting/Modifying Arc geometries into the database.

virtual bool insertArc (const string &table, TeArc &arc)
 Inserts an arc geometry in the database.
Node

Accessing/Inserting/Modifying Node geometries into the database.

virtual bool insertNode (const string &table, TeNode &node)
Cell

Accessing/Inserting/Modifying Cell geometries into the database.

virtual bool insertCell (const string &table, TeCell &c)
Query

Methods related to query the database

virtual bool execute (const string &sql)
 Executes a SQL command that doesnt return a record set. Tipically a data definition comand.
bool beginTransaction ()
 Begins a transaction.
bool commitTransaction ()
 Commits a transaction.
bool rollbackTransaction ()
 Rollbacks a transaction.
virtual TeDatabasePortalgetPortal ()
 Returns a database portal.
specifics SQLs

return SQL strings

virtual string escapeSequence (const string &from)
 Escape special characters in a string to be used in a SQL statement.
virtual bool getAttributeList (const string &tableName, TeAttributeList &attList)
 Gets the list of attributes of a table.
virtual string concatValues (vector< string > &values, const string &unionString)
 Concat values in a vector using unionString as the join between each value.
virtual string toUpper (const string &value)
 Returns the SQL function for upper case.

Protected Attributes

sqlite3_conn
int _transactionCounter

Friends

class TeSQLitePortal

Detailed Description

SQLite database access class.

This class contains the implementation of common methods for TerraLib access SQLite. //

Author:
Mario Rocco Pettinati <mario@funcate.org.br>

Constructor & Destructor Documentation

TeSQLite::TeSQLite ( )

Constructor.

TeSQLite::~TeSQLite ( ) [virtual]

Destructor.


Member Function Documentation

bool TeSQLite::addColumn ( const string table,
TeAttributeRep rep 
) [virtual]

Adds a column to a table.

Parameters:
tabletable name
reprepresentation of the column being created

Implements TeDatabase.

bool TeSQLite::alterTable ( const string tableName,
TeAttributeRep rep,
const string oldColName = "" 
) [virtual]

Alter a property of a table.

Reimplemented from TeDatabase.

bool TeSQLite::alterTable ( const string oldTableName,
const string newTablename 
) [virtual]

Alter the table name.

Reimplemented from TeDatabase.

bool TeSQLite::beginTransaction ( void  ) [virtual]

Begins a transaction.

Reimplemented from TeDatabase.

void TeSQLite::close ( void  ) [virtual]

Closes the conection.

Implements TeDatabase.

bool TeSQLite::columnExist ( const string table,
const string column,
TeAttribute attr 
) [virtual]

Verifies if a table has a column.

Implements TeDatabase.

bool TeSQLite::commitTransaction ( void  ) [virtual]

Commits a transaction.

Reimplemented from TeDatabase.

string TeSQLite::concatValues ( vector< string > &  values,
const string unionString 
) [virtual]

Concat values in a vector using unionString as the join between each value.

Implements TeDatabase.

bool TeSQLite::connect ( const string host,
const string user,
const string password,
const string database,
int  port = -1 
) [virtual]

Opens a conection to a database server.

Implements TeDatabase.

bool TeSQLite::createRelation ( const string relName,
const string table,
const string fieldName,
const string relatedTable,
const string relatedField,
bool  cascadeDeletion 
) [virtual]

Creates a reationship between two tables.

Parameters:
relNamerelationship name
tabletable that will receive the foreign key
fieldNamecolumn that will be foreign key
relatedTabletable that exports the foreign key
relatedFieldfield that will the exported foreign key
cascadeDeletionflag that indicates if the deletion should be propagated

Implements TeDatabase.

bool TeSQLite::createTable ( const string table,
TeAttributeList attr 
) [virtual]

Creates a table.

Parameters:
tabletable name
attrtable list of attributes

Implements TeDatabase.

string TeSQLite::errorMessage ( ) [virtual]

Returns the error message from the server.

Reimplemented from TeDatabase.

string TeSQLite::escapeSequence ( const string from) [virtual]

Escape special characters in a string to be used in a SQL statement.

Implements TeDatabase.

bool TeSQLite::execute ( const string sql) [virtual]

Executes a SQL command that doesnt return a record set. Tipically a data definition comand.

Implements TeDatabase.

TeDBRelationType TeSQLite::existRelation ( const string tableName,
const string relName 
) [virtual]

Checks if a relation exist.

Parameters:
tableNametable where the relashionship exists
relNamerelationship name

Implements TeDatabase.

bool TeSQLite::generateLabelPositions ( TeTheme theme,
const std::string objectId = "" 
) [virtual]

Generates the label position (x,y) to each object of a theme or of a particular object.

Reimplemented from TeDatabase.

bool TeSQLite::getAttributeList ( const string tableName,
TeAttributeList attList 
) [virtual]

Gets the list of attributes of a table.

Reimplemented from TeDatabase.

bool TeSQLite::getIndexesFromTable ( const string tableName,
std::vector< TeDatabaseIndex > &  vecIndexes 
) [virtual]

Return a TeDatabaseIndex vector from a table.

Reimplemented from TeDatabase.

int TeSQLite::getLastInsertedSerial ( )
TeDatabasePortal * TeSQLite::getPortal ( ) [virtual]

Returns a database portal.

A database portal is used to submit queries to the database and to navigate over the resulting record set

Implements TeDatabase.

std::string TeSQLite::getSQLOrderBy ( const TeGeomRep rep) const [virtual]

Reimplemented from TeDatabase.

string TeSQLite::getSQLTime ( const TeTime time) const [virtual]

Returns a valid SQL time string.

Returns a string SQL to be used in the ORDER BY clause when querying geometries.

Reimplemented from TeDatabase.

bool TeSQLite::insertArc ( const string table,
TeArc arc 
) [virtual]

Inserts an arc geometry in the database.

Implements TeDatabase.

bool TeSQLite::insertBlob ( const string tableName,
const string columnBlob,
const string whereClause,
unsigned char *  data,
int  size 
) [virtual]

Saves a large binary objects (BLOB) in a row table.

Implements TeDatabase.

bool TeSQLite::insertCell ( const string table,
TeCell c 
) [virtual]

Implements TeDatabase.

bool TeSQLite::insertLayer ( TeLayer layer) [virtual]

Insert information about a layer.

Implements TeDatabase.

bool TeSQLite::insertLegend ( TeLegendEntry legend) [virtual]

Inserts legend in the database.

Implements TeDatabase.

bool TeSQLite::insertLine ( const string table,
TeLine2D l 
) [virtual]

Inserts a line in a geometry table.

Implements TeDatabase.

bool TeSQLite::insertNode ( const string table,
TeNode node 
) [virtual]

Implements TeDatabase.

bool TeSQLite::insertPoint ( const string table,
TePoint p 
) [virtual]

Implements TeDatabase.

bool TeSQLite::insertPolygon ( const string table,
TePolygon p 
) [virtual]

Inserts a polygon in a geometry table.

Implements TeDatabase.

bool TeSQLite::insertProject ( TeProject project) [virtual]

Insert information about a project.

Implements TeDatabase.

bool TeSQLite::insertProjection ( TeProjection proj) [virtual]

Insert information about a geographical projection.

Implements TeDatabase.

bool TeSQLite::insertRasterBlock ( const string table,
const string blockId,
const TeCoord2D ll,
const TeCoord2D ur,
unsigned char *  buf,
unsigned long  size,
int  band = 0,
unsigned int  res = 1,
unsigned int  subband = 0 
) [virtual]

Insert a raster block into the database.

Parameters:
tabletable name
blockIdblock unique identifier
llblock lower left coordinate
urblock upper right coordinate
bufblock binary data
sizeblock size
bandblock band
resblock resolution factor
subbandsub band definitiion

Implements TeDatabase.

bool TeSQLite::insertRelationInfo ( const int  tableId,
const string tField,
const string rTable,
const string rField,
int &  relId 
) [virtual]

Inserts information about a link to an external table.

Implements TeDatabase.

bool TeSQLite::insertRepresentation ( int  layerId,
TeRepresentation rep 
) [virtual]

Inserts information about a geometrical representation.

Implements TeDatabase.

bool TeSQLite::insertTableInfo ( int  layerId,
TeTable table,
const string user = "" 
) [virtual]

Inserts information about an attribute table.

Implements TeDatabase.

bool TeSQLite::insertText ( const string table,
TeText t 
) [virtual]

Implements TeDatabase.

bool TeSQLite::insertTheme ( TeAbstractTheme theme) [virtual]

Inserts an abstract theme in the database.

Implements TeDatabase.

bool TeSQLite::insertThemeGroup ( TeViewTree tree) [virtual]

Inserts a group of themes in the database.

Implements TeDatabase.

bool TeSQLite::insertThemeTable ( int  themeId,
int  tableId,
int  relationId,
int  tableOrder 
) [virtual]

Inserts information about a table used by a theme.

Implements TeDatabase.

bool TeSQLite::insertView ( TeView view) [virtual]

Inserts a view.

Implements TeDatabase.

bool TeSQLite::insertViewTree ( TeViewTree tree) [virtual]

Recursive inserting of a view tree.

Implements TeDatabase.

bool TeSQLite::newDatabase ( const string database,
const string user,
const string password,
const string host,
const int &  port = -1,
bool  terralibModel = true,
const std::string characterSet = "" 
) [virtual]

Creates a new database and open a connection to it.

Implements TeDatabase.

bool TeSQLite::rollbackTransaction ( ) [virtual]

Rollbacks a transaction.

Reimplemented from TeDatabase.

bool TeSQLite::tableExist ( const string table) [virtual]

Verifies if a table exist in the database.

Implements TeDatabase.

string TeSQLite::toUpper ( const string value) [virtual]

Returns the SQL function for upper case.

Implements TeDatabase.

bool TeSQLite::updateLine ( const string table,
TeLine2D l 
) [virtual]

Updates a line in a geometry table.

Implements TeDatabase.

bool TeSQLite::updatePolygon ( const string table,
TePolygon p 
) [virtual]

Updates a polygon in a geometry table.

Implements TeDatabase.


Friends And Related Function Documentation

friend class TeSQLitePortal [friend]

Member Data Documentation

sqlite3* TeSQLite::_conn [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines