~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/evis/databaseconnection/evisdatabaseconnection.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** File: evisdatabaseconnection.h
 
3
** Author: Peter J. Ersts ( ersts at amnh.org )
 
4
** Creation Date: 2007-03-07
 
5
**
 
6
** Copyright ( c ) 2007, American Museum of Natural History. All rights reserved.
 
7
**
 
8
** This library/program is free software; you can redistribute it
 
9
** and/or modify it under the terms of the GNU Library General Public
 
10
** License as published by the Free Software Foundation; either
 
11
** version 2 of the License, or ( at your option ) any later version.
 
12
**
 
13
** This library/program is distributed in the hope that it will be useful,
 
14
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
** Library General Public License for more details.
 
17
**
 
18
** This work was made possible through a grant by the the John D. and
 
19
** Catherine T. MacArthur Foundation. Additionally, this program was prepared by
 
20
** the American Museum of Natural History under award No. NA05SEC46391002
 
21
** from the National Oceanic and Atmospheric Administration, U.S. Department
 
22
** of Commerce.  The statements, findings, conclusions, and recommendations
 
23
** are those of the author( s ) and do not necessarily reflect the views of the
 
24
** National Oceanic and Atmospheric Administration or the Department of Commerce.
 
25
**
 
26
**/
 
27
/*  $Id: $ */
 
28
#ifndef EVISDATABASECONNECTION_H
 
29
#define EVISDATABASECONNECTION_H
 
30
 
 
31
#include "evisquerydefinition.h"
 
32
 
 
33
#include <QStringList>
 
34
#include <QtSql/QSqlDatabase>
 
35
#include <QtSql/QSqlQuery>
 
36
#include <QtSql/QSqlError>
 
37
 
 
38
/**
 
39
* \class eVisDatabaseConnection
 
40
* \brief A class that provides the ability to connect to a variety of database types
 
41
* This class provides the ability to connect to a variety of database types
 
42
*/
 
43
class eVisDatabaseConnection
 
44
{
 
45
 
 
46
  public:
 
47
 
 
48
    /** \brief Enum containting the type of database supported by this class */
 
49
    enum DATABASE_TYPE
 
50
    {
 
51
      UNDEFINED,
 
52
      MSACCESS,
 
53
      QMYSQL,
 
54
      QPSQL,
 
55
      QODBC,
 
56
      QSQLITE
 
57
    } mDatabaseType;
 
58
 
 
59
    /** \brief Constructor */
 
60
    eVisDatabaseConnection( QString, int, QString, QString, QString, DATABASE_TYPE );
 
61
 
 
62
    /** \brief Public method that finalizes a connection to a databse */
 
63
    bool connect( );
 
64
 
 
65
    /** \brief Public method that passes an SQL statement to the database for execution */
 
66
    QSqlQuery* query( QString );
 
67
 
 
68
    /** \brief Public method for resetting the database connection parameters - equivalent to re running the constructor */
 
69
    void resetConnectionParameters( QString, int, QString, QString, QString, DATABASE_TYPE );
 
70
 
 
71
    /** \brief Returns a list of tables in the current database */
 
72
    QStringList tables( );
 
73
 
 
74
    /** \brief Accessor to the database type */
 
75
    DATABASE_TYPE databaseType( )
 
76
    {
 
77
      return mDatabaseType;
 
78
    }
 
79
 
 
80
    /** \brief Public method for closing the current database connection */
 
81
    void close( )
 
82
    {
 
83
      mDatabase.close( );
 
84
    }
 
85
 
 
86
    /** \brief Public method for requesting the last error reported by the database connect or query */
 
87
    QString lastError( )
 
88
    {
 
89
      return mLastError;
 
90
    }
 
91
 
 
92
    /** \brief Mutator for database type */
 
93
    void setDatabaseType( DATABASE_TYPE connectionType )
 
94
    {
 
95
      mDatabaseType = connectionType;
 
96
    }
 
97
 
 
98
  protected:
 
99
    /** \brief Variable used to store the query results */
 
100
    QSqlQuery mQuery;
 
101
 
 
102
  private:
 
103
    /** \brief Host name for the database server */
 
104
    QString mHostName;
 
105
 
 
106
    /** \brief Port number the database server is listenting to */
 
107
    int mPort;
 
108
 
 
109
    /** \brief Database name, can also be a filename in the case of SQLite or MSAccess */
 
110
    QString mDatabaseName;
 
111
 
 
112
    /** \brief Username for accessing the database */
 
113
    QString mUsername;
 
114
 
 
115
    /** \brief Password associated with the username for accessing the database */
 
116
    QString mPassword;
 
117
 
 
118
    /** \brief QString containing the last reported error message */
 
119
    QString mLastError;
 
120
 
 
121
    /** \brief The database object */
 
122
    QSqlDatabase mDatabase;
 
123
 
 
124
    /** \brief Sets the error messages */
 
125
    void setLastError( QString error )
 
126
    {
 
127
      mLastError = error;
 
128
    }
 
129
};
 
130
#endif