Initial commit to git repository
[liteman.git] / src / database.h
blob6a3228ccae4598c4356301432451555f1903594c
1 /*
2 * This file is part of LineMan.
4 * Copyright 2006 Igor Khanin
6 * LiteMan is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * LiteMan is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with LiteMan; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef DATABASE_H
22 #define DATABASE_H
24 #include <QCoreApplication>
25 #include <QSqlDatabase>
26 #include <QStringList>
28 typedef struct
30 QString name;
31 QString type;
32 QString comment;
34 DatabaseTableField;
36 typedef QList<DatabaseTableField> FieldList;
38 /*!
39 * @brief An exception indicating %Database error
41 class DatabaseException
43 public:
44 DatabaseException(QString msg) { message = msg; }
46 QString message;
49 /*!
50 * @brief The database manager
52 * The %Database class represents a single database file/object, and provides convinient methods
53 * for accessing specific elements in it (currently only tables and views). Though the application
54 * still doesn't use this capability, it is completly safe to have multipile %Database object managing
55 * diffirent databases in the same time.
57 * Internally, the class uses the QtSQL API for manipulating the database.
59 class Database
61 Q_DECLARE_TR_FUNCTIONS(Database)
63 public:
64 Database(const QString & fileName);
65 ~Database();
67 bool isValid();
68 QString id();
71 // Table related methods
73 QStringList getTables();
75 void createTable(const QString & name, const FieldList & fields);
76 void renameTable(const QString & table, const QString & newName);
77 void dropTable(const QString & table);
79 FieldList tableFields(const QString & table);
82 // View related methods
84 QStringList getViews();
86 void createView(const QString & name, const QString & sql);
87 void dropView(const QString & view);
90 // Other methods
92 void exportSql(const QString & fileName);
94 private:
95 bool testDB();
97 bool valid;
98 QString databaseId;
101 #endif //DATABASE_H