| 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/Firebird/TeFirebird.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 *************************************************************************************/
    00026 #ifndef  __TERRALIB_INTERNAL_FIREBIRD_H
    00027 #define  __TERRALIB_INTERNAL_FIREBIRD_H
    00028
    00029 #ifdef WIN32
    00030 #include <winsock.h>
    00031 #endif
    00032
    00033 #include <TeTable.h>
    00034 #include <TeDatabase.h>
    00035 #include <TeDatabaseFactory.h>
    00036
    00037 #ifdef IBPP_WINDOWS
    00038 #include <windows.h>
    00039 #endif
    00040
    00041 #include <ibpp/core/ibpp.h>
    00042
    00043 #include "TeFirebirdDefines.h"
    00044 #include "TeFirebirdConnection.h"
    00045
    00046 #ifdef IBPP_UNIX
    00047 #include <unistd.h>
    00048 #define DeleteFile(x) unlink(x)
    00049 #define Sleep(x) usleep(1000 * x)
    00050 #endif
    00051
    00052 #ifdef HAS_HDRSTOP
    00053 #pragma hdrstop
    00054 #endif
    00055
    00057 class TLFIREBIRD_DLL TeFirebird : public TeDatabase
    00058 {
    00059 friend class TeFirebirdPortal;
    00060
    00061 public:
    00062
    00063            TeFirebird();
    00064
    00065            virtual ~TeFirebird();
    00066
    00067            IBPP::Database getIBPPFirebird();
    00068
    00069            string  escapeSequence(const string& from);
    00070
    00071            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 = "");
    00072
    00073            bool connect (const string& host, const string& user, const string& password, const string& database, int port=-1);
    00074
    00075            bool showDatabases (const string& host, const string& user, const string& password, vector<string>& dbNames, int port=-1);
    00076
    00077            void close();
    00078
    00079            bool tableExist(const string& table);
    00080
    00081            bool columnExist(const string& table, const string& column, TeAttribute& attr);
    00082
    00083            bool addColumn (const string& table,TeAttributeRep &rep);
    00084
    00085            bool createRelation (const string& /* relName */, const string& /* table */, const string& /* fieldName */,
    00086                                                                   const string& /* relatedTable */, const string& /* relatedField */, bool /* cascadeDeletion */)
    00087            { return true; }
    00088
    00089            TeDBRelationType existRelation(const string& /* tableName */, const string& /* relName */)
    00090
    00091            {          return TeNoRelation; }
    00092
    00093            bool execute ( const string &q);
    00094
    00095            bool createTable(const string& table, TeAttributeList &attr);
    00096
    00097            bool alterTable(const string& tableName, TeAttributeRep& rep, const string& oldColName = "");
    00098
    00099            virtual TeDatabasePortal* getPortal ();
    00100
    00101 // specific TerraLib database access methods
    00102
    00103            bool insertProjection (TeProjection *proj);
    00104            bool updateProjection (TeProjection *proj);
    00105
    00107            virtual bool layerExist          (string layerName);
    00108
    00109            bool insertLayer(TeLayer* layer);
    00110            bool updateLayer(TeLayer *layer);
    00111
    00112            bool insertProject(TeProject* project);
    00113            bool insertRepresentation(int layerId, TeRepresentation& rep);
    00114            bool insertTable(TeTable &table);
    00115            bool updateTable      (TeTable &table);
    00116            bool insertTableInfo (int layerId, TeTable &table, const string& user="");
    00117            bool insertRelationInfo(const int tableId, const string& tField,
    00118                                                                       const string& eTable, const string& eField, int& relId);
    00119            bool insertView (TeView *view);
    00120            bool insertViewTree (TeViewTree *tree);
    00121            bool insertTheme(TeAbstractTheme *theme);
    00122            bool insertThemeGroup (TeViewTree* tree);
    00123            bool generateLabelPositions (TeTheme *theme, const std::string& objectId = "");
    00124            bool updateTheme (TeAbstractTheme *theme);
    00125            bool insertThemeTable (int themeId, int tableId, int relationId, int tableOrder);
    00126            bool updateRepresentation (int layerId, TeRepresentation& rep);
    00127
    00129            virtual bool getIndexesFromTable(const string& tableName, std::vector<TeDatabaseIndex>& vecIndexes);
    00130
    00135
    00136
    00141            bool insertRasterGeometry(const string& tableName, TeRasterParams& par, const string& objectId = "");
    00143
    00145
    00150            virtual bool updateRasterRepresentation(int layerId, TeRasterParams& par, const string& objectId="");
    00151
    00152            bool insertLegend (TeLegendEntry *legend);
    00153            virtual bool insertPolygon       (const string& table, TePolygon &p);
    00154            virtual bool updatePolygon       (const string& table, TePolygon &p);
    00155            virtual bool insertLine (const string&  table, TeLine2D &l);
    00156            virtual bool updateLine (const string& table, TeLine2D &l);
    00157            bool insertPoint (const string& table, TePoint &p);
    00158            bool insertText (const string& table, TeText &t);
    00159            bool insertArc (const string& table,TeArc &arc);
    00160            bool insertNode       (const string& table, TeNode &node);
    00161            bool insertCell       (const string& table, TeCell &c);
    00162
    00163            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);
    00164
    00165            string getSQLTime(const TeTime& time) const;
    00166            string getSQLTemporalWhere(int time1, int time2, TeChronon chr, TeTemporalRelation rel,
    00167                                                                      const string& initialTime, const string& finalTime);
    00168
    00169            bool inClauseValues(const string& query, const string& attribute, vector<string>& inClauseVector);
    00170
    00171            bool insertBlob (const string& tableName, const string& columnBlob, const string& whereClause, unsigned char* data, int size);
    00172
    00174            string concatValues(vector<string>& values, const string& unionString);
    00175
    00176            bool updateLayerBox(TeLayer* layer);
    00177
    00179            string toUpper(const string& value);
    00180
    00181            string getConcatFieldsExpression(const vector<string>& fNamesVec);
    00182
    00183            bool beginTransaction();
    00184     bool commitTransaction();
    00185     bool rollbackTransaction();
    00186
    00187            virtual std::string mapToFirebirdType(const TeAttribute& teRep) const;
    00188
    00190            virtual bool createSpatialIndex(const string& table, const string& columns, TeSpatialIndexType /*type*/ = TeRTREE,short /* level */ =0,short /* tile */ =0);
    00191
    00192            bool createAutoIncrement(const std::string& table, const std::string& column);
    00193
    00194            int getLastGeneratedAutoNumber(const std::string& table);
    00195
    00197            virtual bool getAttributeList(const string& tableName,TeAttributeList& attList);
    00198
    00203
    00205    virtual void setConnection(TeConnection* c);
    00206
    00210    virtual TeConnection* getConnection();
    00211
    00213
    00214 protected :
    00215            IBPP::Database firebird_;
    00216            IBPP::Database firebird_ref_;
    00217            IBPP::Transaction transaction_;
    00218
    00220            bool createDescIndex(const string& tableName, const string& indexName, const string& columnsName);
    00221 };
    00222
    00224 class TLFIREBIRD_DLL TeFirebirdPortal  : public TeDatabasePortal
    00225 {
    00226 private:
    00227
    00228 public :
    00229
    00230 // Constructor / Destructor
    00231
    00232            TeFirebirdPortal (TeFirebird* firebird);
    00233
    00234            TeFirebirdPortal (const TeFirebirdPortal& p);
    00235
    00236            virtual ~TeFirebirdPortal ();
    00237
    00238 // Basic database methods
    00239
    00240            bool query (const string &qry, TeCursorLocation l = TeSERVERSIDE, TeCursorType t = TeUNIDIRECTIONAL, TeCursorEditType e = TeREADONLY, TeCursorDataType dt = TeTEXTCURSOR );
    00241
    00242            bool fetchRow ();
    00243
    00244            bool fetchRow (int i);
    00245
    00246            void freeResult ();
    00247
    00248 // specific SQL SELECT command methods
    00249
    00250            char*                 getData (int i);
    00251            char*                 getData (const string& s);
    00252            double                getDouble (int i);
    00253            double                getDouble (const string& s);
    00254            int                              getInt (int i);
    00255            int                              getInt (const string& s);
    00256            bool                  getBool (const string& s);
    00257            bool                  getBool (int i);
    00258
    00259            virtual bool fetchGeometry(TePolygon& pol);
    00260            virtual bool fetchGeometry(TeLine2D& line);
    00261            bool fetchGeometry(TeNode& n);
    00262            bool fetchGeometry(TePoint& p);
    00263            virtual bool fetchGeometry(TePolygon& pol, const unsigned int& initIndex);
    00264            virtual bool fetchGeometry(TeLine2D& line, const unsigned int& initIndex);
    00265            bool fetchGeometry(TeNode& n, const unsigned int& initIndex);
    00266            bool fetchGeometry(TePoint& p, const unsigned int& initIndex);
    00267
    00268            bool setData (int /* field */, string /* val */)
    00269            {return true; }
    00270
    00271            bool getBlob (const int& column, unsigned char* &data, unsigned long& size);
    00272            bool getBlob (const string& s, unsigned char* &data, long& size);
    00273            bool getRasterBlock(unsigned long& size, unsigned char* ptData);
    00274
    00275            TeTime getDate (int i);
    00276            TeTime getDate (const string& s);
    00277
    00278            string getDateAsString(int i);
    00279            string getDateAsString(const string& s);
    00280
    00281 protected:
    00282            virtual TeLinearRing getLinearRing (int &ni);
    00283
    00284            IBPP::Database firebird_;
    00285            IBPP::Statement result_;
    00286            IBPP::Transaction transaction_;
    00287            std::string data_,
    00288                                             query_;
    00289            int currRow_;
    00290 };
    00291
    00292
    00298 class TLFIREBIRD_DLL TeFirebirdFactory : public TeDatabaseFactory
    00299 {
    00300   public :
    00301
    00305     TeFirebirdFactory() : TeDatabaseFactory( std::string( "Firebird" ) ) {};
    00306
    00310     ~TeFirebirdFactory() {};
    00311
    00312   protected :
    00313
    00321     TeDatabase* build( const TeDatabaseFactoryParams& arg )
    00322     {
    00323       TeFirebird* instance_ptr = new TeFirebird();
    00324
    00325       if( arg.host_ != "" ) {
    00326         instance_ptr->connect( arg.host_, arg.user_, arg.password_,
    00327           arg.database_, arg.port_ );
    00328       }
    00329
    00330       return (TeDatabase*)instance_ptr;
    00331     }
    00332 };
    00333
    00334 namespace {
    00335   static TeFirebirdFactory TeFirebirdFactory_instance;
    00336 };
    00337
    00338 #endif
    00339

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines