qdataschema.h

00001 /****************************************************************************
00002 ** $Id: qdataschema.h,v 1.28 2007/01/29 15:06:29 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 <qobject.h>
00033 #include <qsqldatabase.h>
00034 #include "qdataschemaglobal.h"
00035 
00036 #if defined(Q_OS_WIN32) && !defined(LIB_NO_DLL)
00037 #    define DB_IMPORT __declspec(dllimport)
00038 #else
00039 #       define DB_IMPORT
00040 #endif
00041 
00042 class QSqlCursor;
00043 class QDataSchemaDriver;
00044 
00045 class QDataSchema: public QObject
00046 {
00047 Q_OBJECT
00048 public:
00049     enum ConnectionType { CT_INTERNAL, CT_MYSQL, CT_POSTGRESQL };
00050 
00051     QDataSchema( ConnectionType ctype, const char *objname = 0 );
00052     ~QDataSchema();
00053 
00054     bool open( const QString &dbname,
00055             const QString &dbuser = "", const QString &dbpass = "",
00056             const QString &dbhost = "localhost", int dbport = 0 );
00057 
00058     bool open();
00059     void close();
00060 
00061     QSqlDatabase* db();
00062 
00063     bool databaseCreate( const QString &dbadmuser, const QString &dbadmpass );
00064     bool databaseDrop( const QString &dbadmuser, const QString &dbadmpass );
00065 
00066     int execList( const QStringList &query, bool inTransaction = false );
00067 
00068     // obsolete
00069 //    Q_ULLONG uid( int otype );
00070 //    int uidType ( Q_ULLONG uid );
00071 //    void markDeleted(Q_ULLONG uid);
00072 //    void deleteMarked();
00073 //    bool updateTable( const QString table, QString flddef, bool dropBefore = false );
00074     // end obsolete
00075 
00076     QSqlCursor *table( const QString &name = QString::null );
00077     QString tableName( const QString &name );
00078     QString tableNameStripPrefix( const QString &name );
00079 
00080     QString nameSpace() const;
00081     void setNameSpace( const QString &namesp );
00082 
00083     bool tableExists( const QString & name );
00084 
00085     static QStringList drivers();
00086     static bool isDriverAvailable ( const QString & name );
00087     QDataSchemaDriver *driver();
00088     void setDataDictionary( const QStringList &dd_new );
00089     QStringList dataDictionary();
00090     QStringList updateStructureQuery();
00091     QStringList verifyLog();
00092     int verifyStructure();
00093     int updateStructure();
00094 
00095     virtual int databaseExport( const QString &filename );
00096     virtual int databaseImport( const QString &filename, bool updateStruct = false );
00097 
00098 public slots:
00099 
00100 signals:
00101     void verifyMessage( QString op, QString value, QString oldvalue );
00102 
00103 protected:
00104     void verifyLogRecord(QString op, QString value, QString oldvalue = "" );
00105 
00106     QString ddRecord( int idx, bool d_sql = false );
00107     int ddCount( const QString &etype, bool d_sql = false );
00108     int ddIndex( const QString &etype, int num, bool d_sql = false );
00109     int ddIndex( const QString &etype, const QString &name, bool d_sql = false );
00110     int ddCountSub( int idx, const QString &etype, bool d_sql = false );
00111     int ddIndexSub( int idx, const QString &etype, int num, bool d_sql = false );
00112     int ddIndexSub( int idx, const QString &etype, const QString &name, bool d_sql = false );
00113     QString ddRecSection( const QString &rec, int secnum );
00114     QString ddRecType( const QString &rec );
00115     QString ddRecName( const QString &rec );
00116     void joinLists( QStringList &list, const QStringList &add );
00117     int checkSqlError( QSqlQuery &query );
00118     QString fieldTypeSql( const QString &tdef );
00119     virtual int createSystables();
00120 
00121 private:
00122     QStringList dd, dd_sql, dd_update, ql_update;
00123     QString dd_name, tablename_prefix;
00124     bool fVerified;
00125 
00126     QDataSchemaDriver *p_drv;
00127     QSqlDatabase *p_db;
00128     QString v_dbname, v_dbuser, v_dbpass, v_dbtype, v_dbhost;
00129     int v_dbport;
00130 
00131     int readSqlDictionary();
00132     int writeSqlDictionary();
00133 };
00134 
00135 #endif
00136 

Документация по Библиотека QT для работы со схемой базы данных.. Последние изменения: Wed Feb 21 09:36:10 2007. Создано системой  doxygen 1.5.1