| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/drivers/SQLite/TeSQLite.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00028 /*
    00029  * TODO: 01. Implementar o alterTable que nao pode simplesmente alterar o tipo da coluna
    00030  *                     02. No metodo query do portal, determinar os campos que fazem parte da chave primaria
    00031  *
    00032  */
    00033
    00034 #ifndef  __TERRALIB_INTERNAL_SQLITE_H
    00035 #define  __TERRALIB_INTERNAL_SQLITE_H
    00036
    00037 #include "TeSQLiteDefines.h"
    00038 #include "../../kernel/TeDatabase.h"
    00039 #include "../../kernel/TeDatabaseFactory.h"
    00040
    00041 class TeSQLitePortal;
    00042 struct sqlite3;
    00043 struct sqlite3_stmt;
    00044
    00046
    00051 class TLSQLITE_DLL TeSQLite : public TeDatabase
    00052 {
    00053            friend class TeSQLitePortal;
    00054
    00055            public:
    00056
    00058                       TeSQLite();
    00059
    00061                       virtual ~TeSQLite();
    00062
    00069
    00070                       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 = "");
    00071
    00073                       virtual bool connect(const string& host, const string& user, const string& password, const string& database, int port = -1);
    00074
    00076                       virtual void close(void);
    00077
    00079                       virtual bool tableExist(const string& table);
    00080
    00082                       virtual bool columnExist(const string& table, const string& column, TeAttribute& attr);
    00083
    00085
    00089                       virtual bool createTable(const string& table, TeAttributeList &attr);
    00090
    00092
    00096                       virtual bool addColumn (const string& table, TeAttributeRep &rep);
    00097
    00099                       virtual bool alterTable(const string& tableName, TeAttributeRep& rep, const string& oldColName="");
    00100
    00102                       virtual bool alterTable(const string& oldTableName, const string& newTablename);
    00103
    00105                       virtual bool getIndexesFromTable(const string& tableName, std::vector<TeDatabaseIndex>& vecIndexes);
    00106
    00107
    00109
    00117                       virtual bool createRelation (const string& relName, const string& table, const string& fieldName,
    00118                                                                              const string& relatedTable, const string& relatedField, bool cascadeDeletion);
    00119
    00121
    00125                       virtual TeDBRelationType existRelation(const string& tableName, const string& relName);
    00126
    00128                       virtual bool insertProject(TeProject *project);
    00129
    00131                       /*
    00132                                  \param tableId table identification (from te_layer_table)
    00133                                  \param tField link column name of the static table
    00134                                  \param eTable name of the external table
    00135                                  \param eField name of the link column of the related table
    00136                                  \param relId returns the identification of the relation
    00137                       */
    00138                       virtual bool insertRelationInfo(const int tableId, const string& tField, const string& rTable, const string& rField, int& relId);
    00139
    00141                       virtual bool insertTableInfo(int layerId, TeTable &table, const string& user="");
    00142
    00144                       virtual bool insertBlob(const string& tableName, const string& columnBlob, const string& whereClause, unsigned char* data, int size);
    00145
    00147
    00152
    00154                       virtual bool insertProjection (TeProjection *proj);
    00156
    00161
    00162                       virtual bool insertLayer(TeLayer *layer);
    00164
    00169
    00170                       virtual bool insertRepresentation(int layerId, TeRepresentation& rep);
    00172
    00177
    00178                       virtual bool insertView (TeView *view);
    00179
    00181                       virtual bool insertViewTree(TeViewTree *tree);
    00183
    00188
    00189                       virtual bool insertThemeGroup(TeViewTree* tree);
    00190
    00192                       virtual bool generateLabelPositions(TeTheme *theme, const std::string& objectId = "");
    00193
    00195                       virtual bool insertTheme(TeAbstractTheme *theme);
    00196
    00198                       virtual bool insertThemeTable(int themeId, int tableId, int relationId, int tableOrder);
    00200
    00205
    00206                       virtual bool insertLegend(TeLegendEntry *legend);
    00208
    00213
    00214                       virtual bool insertPolygon(const string& table, TePolygon &p);
    00215
    00217                       virtual bool updatePolygon(const string& table, TePolygon &p);
    00219
    00224
    00225                       virtual bool insertLine(const string& table, TeLine2D &l);
    00226
    00228                       virtual bool updateLine(const string& table, TeLine2D &l);
    00230
    00235                       virtual bool insertPoint(const string& table, TePoint &p);
    00237
    00242                       virtual bool insertText(const string& table, TeText &t);
    00244
    00249
    00250                       virtual bool insertArc(const string& table,TeArc &arc);
    00252
    00257                       virtual bool insertNode(const string& table, TeNode &node);
    00259
    00264                       virtual bool insertCell(const string& table, TeCell &c);
    00266
    00268
    00279                       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);
    00280
    00285
    00286                       virtual bool execute ( const string &sql);
    00287
    00289                       bool beginTransaction();
    00290
    00292                       bool commitTransaction();
    00293
    00295                       bool rollbackTransaction();
    00296
    00298
    00302                       virtual TeDatabasePortal* getPortal ();
    00303
    00305
    00310
    00312                       virtual string escapeSequence(const string& from);
    00313
    00315                       virtual bool getAttributeList(const string& tableName,TeAttributeList& attList);
    00316
    00318                       virtual string concatValues(vector<string>& values, const string& unionString);
    00319
    00321                       virtual string toUpper(const string& value);
    00322
    00324
    00326                       virtual string getSQLTime(const TeTime& time) const;
    00327
    00329                       virtual std::string getSQLOrderBy(const TeGeomRep& rep) const;
    00330
    00332                       virtual string errorMessage();
    00333
    00334                       int getLastInsertedSerial();
    00335
    00336
    00337            protected:
    00338
    00339                       sqlite3*   _conn;
    00340                       int                              _transactionCounter;
    00341 };
    00342
    00343 class TLSQLITE_DLL TeSQLitePortal : public TeDatabasePortal
    00344 {
    00345            public:
    00346
    00348                       TeSQLitePortal();
    00349
    00351                       TeSQLitePortal(TeDatabase* pDatabase);
    00352
    00354                       virtual ~TeSQLitePortal();
    00355
    00356                       virtual bool query ( const string &qry, TeCursorLocation l = TeSERVERSIDE, TeCursorType t = TeUNIDIRECTIONAL, TeCursorEditType e = TeREADONLY, TeCursorDataType dt = TeTEXTCURSOR );
    00357
    00359                       virtual bool fetchRow ();
    00360
    00362                       virtual bool fetchRow (int i);
    00363
    00365                       virtual void freeResult ();
    00366
    00368                       virtual char* getData (int i);
    00369
    00371                       virtual char* getData (const string& s);
    00372
    00374                       virtual int getInt (int i);
    00375
    00377                       virtual int getInt (const string& s);
    00378
    00380                       virtual bool getBool (const string& s);
    00381
    00383                       virtual bool getBool (int i);
    00384
    00386                       virtual TeTime getDate (int i);
    00387
    00389                       virtual TeTime getDate (const string& s);
    00390
    00392                       virtual string getDateAsString(int i);
    00393
    00395                       virtual string getDateAsString(const string& s);
    00396
    00398                       virtual bool getBlob(const string& s, unsigned char* &data, long& size);
    00399
    00400                       virtual bool getRasterBlock(unsigned long& size, unsigned char* ptData);
    00401
    00403                       int getColumnIndex (const string& s);
    00404
    00414                       virtual    bool fetchGeometry(TePolygon& geom);
    00415                       virtual    bool fetchGeometry(TePolygon& geom, const unsigned int& initIndex);
    00416                       virtual    bool fetchGeometry(TeLine2D& geom);
    00417                       virtual    bool fetchGeometry(TeLine2D& geom, const unsigned int& initIndex);
    00418                       virtual    bool fetchGeometry(TeNode& geom);
    00419                       virtual    bool fetchGeometry(TeNode& geom, const unsigned int& initIndex);
    00420                       virtual    bool fetchGeometry(TePoint& geom);
    00421                       virtual    bool fetchGeometry(TePoint& geom, const unsigned int& initIndex);
    00422
    00424
    00425                       virtual string errorMessage();
    00426
    00427            protected:
    00428
    00429                       sqlite3*              _conn;
    00430                       sqlite3_stmt*         _recordSet;
    00431                       bool                             _skipFirstFetch;
    00432                       bool                             _firstFetchResult;
    00433                       int                                         _currentRow;
    00434                       std::string                                 _query;
    00435
    00436                       std::map<std::string, int>                  _mapColumnNames;
    00437 };
    00438
    00444 class TLSQLITE_DLL TeSQLiteFactory : public TeDatabaseFactory
    00445 {
    00446   public :
    00447
    00451     TeSQLiteFactory() : TeDatabaseFactory(
    00452       std::string( "SQLite" ) ) {};
    00453
    00457     ~TeSQLiteFactory() {};
    00458
    00459   protected :
    00460
    00468     TeDatabase* build( const TeDatabaseFactoryParams& arg )
    00469     {
    00470                       TeSQLite* instance_ptr = new TeSQLite();
    00471
    00472                       //if( arg.host_ != "" )
    00473                       //{
    00474                                  instance_ptr->connect( arg.host_, arg.user_, arg.password_, arg.database_, arg.port_ );
    00475                       //}
    00476
    00477                       return (TeDatabase*)instance_ptr;
    00478     }
    00479 };
    00480
    00481 namespace
    00482 {
    00483            static TeSQLiteFactory TeSQLiteFactory_instance;
    00484 };
    00485
    00486 #endif //__TERRALIB_INTERNAL_SQLITE_H

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines