00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef RTKINPUTSQL_H
00021 #define RTKINPUTSQL_H
00022
00023 #include <qsqldatabase.h>
00024 #include <qsqlquery.h>
00025 #include <qsqlerror.h>
00026
00027 #include "rtkinput.h"
00028
00029
00030 namespace RTK
00031 {
00032
00033 class InputSql : public Input
00034 {
00035
00036 public:
00037 InputSql(const String& sqldriver = String::null, const String& host = String::null,
00038 int port = 0, const String& user = String::null, const String& password = String::null,
00039 const String& database = String::null, const String& from = String::null, const String& where = String::null, const String& orderby = String::null,
00040 const String& name = String::null, const String& driver = String::null)
00041 :Input(name, driver),
00042 mSqlDriver(sqldriver), mHost(host),
00043 mPort(port), mUser(user), mPassword(password),
00044 mDatabase(database), mFrom(from), mWhere(where), mOrderBy(orderby)
00045
00046 , pQuery( 0 ), mExternalQuery( false )
00047 {};
00048
00049 ~InputSql();
00050
00051 virtual void setQuery( QSqlQuery *query );
00052 virtual bool init();
00053 virtual bool next();
00054 virtual Variant getValue( uint i );
00055 virtual Variant getValue( const String & );
00056
00057
00058 public:
00059 const String& getSqlDriver() const { return mSqlDriver; };
00060 void setSqlDriver(const String& sqldriver) { mSqlDriver = sqldriver; };
00061 const String& getHost() const { return mHost; };
00062 void setHost(const String& host) { mHost = host; };
00063 int getPort() const { return mPort; };
00064 void setPort(int port) { mPort = port; };
00065 const String& getUser() const { return mUser; };
00066 void setUser(const String& user) { mUser = user; };
00067 const String& getPassword() const { return mPassword; };
00068 void setPassword(const String& password) { mPassword = password; };
00069 const String& getDatabase() const { return mDatabase; };
00070 void setDatabase(const String& database) { mDatabase = database; };
00071 const String& getFrom() const { return mFrom; };
00072 void setFrom(const String& from) { mFrom = from; };
00073 const String& getWhere() const { return mWhere; };
00074 void setWhere(const String& where) { mWhere = where; };
00075 const String& getOrderBy() const { return mOrderBy; };
00076 void setOrderBy(const String& orderby) { mOrderBy = orderby; };
00077 protected:
00078 String mSqlDriver;
00079 String mHost;
00080 int mPort;
00081 String mUser;
00082 String mPassword;
00083 String mDatabase;
00084 String mFrom;
00085 String mWhere;
00086 String mOrderBy;
00087
00088 private:
00089 int fieldPos( const String &name ) const;
00090
00091 QSqlQuery *pQuery;
00092 bool mExternalQuery;
00093 int handleError( QSqlDatabase *db, QSqlError dberr );
00094 QValueList<String>mFieldNames;
00095 QValueList<Variant::Type>mFieldTypes;
00096
00097 };
00098
00099 };
00100
00101 #endif
00102