qdataschema.h

00001 /****************************************************************************
00002 ** $Id: qdataschema.h,v 1.29 2007/02/25 18:05:57 leader Exp $
00003 **
00004 ** Header file of the ananas database of Ananas
00005 ** Designer and Engine applications
00006 **
00007 ** Created : 20031201
00008 **
00009 ** Copyright (C) 2003-2004 Leader InfoTech.  All rights reserved.
00010 **
00011 ** This file is part of the Library of the Ananas
00012 ** automation accounting system.
00013 **
00014 ** This file may be distributed and/or modified under the terms of the
00015 ** GNU General Public License version 2 as published by the Free Software
00016 ** Foundation and appearing in the file LICENSE.GPL included in the
00017 ** packaging of this file.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** See http://www.leaderit.ru/page=ananas or email sales@leaderit.ru
00023 ** See http://www.leaderit.ru/gpl/ for GPL licensing information.
00024 **
00025 ** Contact org@leaderit.ru if any conditions of this licensing are
00026 ** not clear to you.
00027 **
00028 **********************************************************************/
00029 
00030 #ifndef QDATASCHEMA_H
00031 #define QDATASCHEMA_H
00032 #include "qdataschemaglobal.h"
00033 
00034 #if defined(Q_OS_WIN32) && !defined(LIB_NO_DLL)
00035 #    define DB_IMPORT __declspec(dllimport)
00036 #else
00037 #       define DB_IMPORT
00038 #endif
00039 
00040 class QSqlCursor;
00041 class QDataSchemaDriver;
00042 
00043 class QDataSchema: public QObject
00044 {
00045 Q_OBJECT
00046 public:
00047     enum ConnectionType { CT_INTERNAL, CT_MYSQL, CT_POSTGRESQL };
00048 
00049     QDataSchema( ConnectionType ctype, const char *objname = 0 );
00050     ~QDataSchema();
00051 #if QT_VERSION<0x040000
00052     QString objectName() const { return name();};
00053     void setObjectName( const QString &newname ) { setName( newname );};
00054 #endif
00055 
00056     bool open( const QString &dbname,
00057             const QString &dbuser = "", const QString &dbpass = "",
00058             const QString &dbhost = "localhost", int dbport = 0 );
00059 
00060     bool open();
00061     void close();
00062 
00063     QSqlDatabase* db();
00064 
00065     bool databaseCreate( const QString &dbadmuser, const QString &dbadmpass );
00066     bool databaseDrop( const QString &dbadmuser, const QString &dbadmpass );
00067 
00068     int execList( const QStringList &query, bool inTransaction = false );
00069 
00070     // obsolete
00071 //    Q_ULLONG uid( int otype );
00072 //    int uidType ( Q_ULLONG uid );
00073 //    void markDeleted(Q_ULLONG uid);
00074 //    void deleteMarked();
00075 //    bool updateTable( const QString table, QString flddef, bool dropBefore = false );
00076     // end obsolete
00077 
00078 #if QT_VERSION<0x040000
00079     QSqlCursor *
00080 #else
00081     QSqlTableModel *
00082 #endif
00083             table( const QString &name = QString::null );
00084     QString tableName( const QString &name );
00085     QString tableNameStripPrefix( const QString &name );
00086 
00087     QString nameSpace() const;
00088     void setNameSpace( const QString &namesp );
00089 
00090     bool tableExists( const QString & name );
00091 
00092     static QStringList drivers();
00093     static bool isDriverAvailable ( const QString & name );
00094     QDataSchemaDriver *driver();
00095     void setDataDictionary( const QStringList &dd_new );
00096     QStringList dataDictionary();
00097     QStringList updateStructureQuery();
00098     QStringList verifyLog();
00099     int verifyStructure();
00100     int updateStructure();
00101 
00102     virtual int databaseExport( const QString &filename );
00103     virtual int databaseImport( const QString &filename, bool updateStruct = false );
00104 
00105 public slots:
00106 
00107 signals:
00108     void verifyMessage( QString op, QString value, QString oldvalue );
00109 
00110 protected:
00111     void verifyLogRecord(QString op, QString value, QString oldvalue = "" );
00112 
00113     QString ddRecord( int idx, bool d_sql = false );
00114     int ddCount( const QString &etype, bool d_sql = false );
00115     int ddIndex( const QString &etype, int num, bool d_sql = false );
00116     int ddIndex( const QString &etype, const QString &name, bool d_sql = false );
00117     int ddCountSub( int idx, const QString &etype, bool d_sql = false );
00118     int ddIndexSub( int idx, const QString &etype, int num, bool d_sql = false );
00119     int ddIndexSub( int idx, const QString &etype, const QString &name, bool d_sql = false );
00120     QString ddRecSection( const QString &rec, int secnum );
00121     QString ddRecType( const QString &rec );
00122     QString ddRecName( const QString &rec );
00123     void joinLists( QStringList &list, const QStringList &add );
00124     QStringList splitQString(const QString &div, const QString &str );
00125     QString lowerQString(const QString &str );
00126     QString trimmedQString(const QString &str);
00127     int checkSqlError( QSqlQuery &query );
00128     QString fieldTypeSql( const QString &tdef );
00129     virtual int createSystables();
00130 
00131 private:
00132     QStringList dd, dd_sql, dd_update, ql_update;
00133     QString dd_name, tablename_prefix;
00134     bool fVerified;
00135 
00136     QDataSchemaDriver *p_drv;
00137 
00138 #if QT_VERSION<0x040000
00139     QSqlDatabase *p_db;
00140 #else
00141     QSqlDatabase p_db;
00142 #endif
00143     QString v_dbname, v_dbuser, v_dbpass, v_dbtype, v_dbhost;
00144     int v_dbport;
00145 
00146     int readSqlDictionary();
00147     int writeSqlDictionary();
00148 };
00149 
00150 #endif
00151 

Generated on Sun Aug 26 05:37:07 2007 for QT Database Schema library. by  doxygen 1.5.1