• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

E:/sqlmaster/src/connection.h

Go to the documentation of this file.
00001 #ifndef CONNECTION_H
00002 #define CONNECTION_H
00003 
00004 #include <QSqlDatabase>
00005 #include <QSqlError>
00006 #include <QSqlQuery>
00007 #include <QtGui>
00008 #include <QString>
00009 
00010 static bool createConnection()
00011 {
00012     {
00013         QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
00014         db.setDatabaseName(qApp->tr("%1/db.db").arg(qApp->applicationDirPath()));
00015         if (!db.open()) {
00016             QMessageBox::critical(0, qApp->tr("Cannot open database"),
00017                                   qApp->tr("Unable to establish a database connection.\n"
00018                                            "This application needs SQLite support."
00019                                            "\n\n"
00020                                            "Click Cancel to exit."), QMessageBox::Cancel);
00021             return false;
00022         }
00023     }
00024     {
00025         QSqlQuery query;
00026         query.exec("create table if not exists connections (id integer primary key autoincrement, "
00027                    "connectionName varchar(50), serverName varchar(20), "
00028                    "userName varchar(50), password varchar(50))");
00029     }
00030     return true;
00031 }
00032 
00033 static void test() {
00034     if (createConnection()) {
00035         test();
00036     }
00037 }
00038 
00039 #endif

Generated on Wed Dec 1 2010 08:43:39 for SQL Master by  doxygen 1.7.2