From: Bert Hubert Date: Thu, 19 Dec 2002 16:28:31 +0000 (+0000) Subject: don't try this at home X-Git-Tag: pdns-2.9.3~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=572a3ab331bbbc5c6f3b5a461151d924f4192fa8;p=thirdparty%2Fpdns.git don't try this at home git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@88 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/modules/gmysqlbackend/Makefile.am b/modules/gmysqlbackend/Makefile.am index c7fb489883..e750045dfd 100644 --- a/modules/gmysqlbackend/Makefile.am +++ b/modules/gmysqlbackend/Makefile.am @@ -1,5 +1,7 @@ lib_LTLIBRARIES = libgmysqlbackend.la +EXTRA_DIST=OBJECTFILES OBJECTLIBS + INCLUDES=-I@MYSQL_incdir@ libgmysqlbackend_la_SOURCES=gmysqlbackend.cc gmysqlbackend.hh \ diff --git a/modules/gmysqlbackend/Makefile.in b/modules/gmysqlbackend/Makefile.in index 875e01758b..0080470278 100644 --- a/modules/gmysqlbackend/Makefile.in +++ b/modules/gmysqlbackend/Makefile.in @@ -85,16 +85,17 @@ VERSION = @VERSION@ YACC = @YACC@ am__include = @am__include@ am__quote = @am__quote@ -domysql = @domysql@ -dopgsql = @dopgsql@ install_sh = @install_sh@ moduledirs = @moduledirs@ modulelibs = @modulelibs@ moduleobjects = @moduleobjects@ +programdescend = @programdescend@ socketdir = @socketdir@ lib_LTLIBRARIES = libgmysqlbackend.la +EXTRA_DIST = OBJECTFILES OBJECTLIBS + INCLUDES = -I@MYSQL_incdir@ libgmysqlbackend_la_SOURCES = gmysqlbackend.cc gmysqlbackend.hh \ diff --git a/modules/gmysqlbackend/gmysqlbackend.hh b/modules/gmysqlbackend/gmysqlbackend.hh index f1af223689..d30999eaea 100644 --- a/modules/gmysqlbackend/gmysqlbackend.hh +++ b/modules/gmysqlbackend/gmysqlbackend.hh @@ -1,6 +1,6 @@ #include #include -#include "ssql.hh" + #include "pdns/backends/gsql/gsqlbackend.hh" using namespace std; diff --git a/modules/gmysqlbackend/smysql.hh b/modules/gmysqlbackend/smysql.hh index 9ceacd02fa..30c4ad7758 100644 --- a/modules/gmysqlbackend/smysql.hh +++ b/modules/gmysqlbackend/smysql.hh @@ -1,11 +1,11 @@ /* Copyright 2001 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE for more information. - $Id: smysql.hh,v 1.2 2002/11/29 15:20:08 ahu Exp $ */ + $Id: smysql.hh,v 1.3 2002/12/19 16:28:31 ahu Exp $ */ #ifndef SMYSQL_HH #define SMYSQL_HH #include -#include "ssql.hh" +#include "pdns/backends/gsql/ssql.hh" class SMySQL : public SSql { diff --git a/modules/gmysqlbackend/spgsql.cc b/modules/gmysqlbackend/spgsql.cc deleted file mode 100644 index fe0617538a..0000000000 --- a/modules/gmysqlbackend/spgsql.cc +++ /dev/null @@ -1,105 +0,0 @@ -/* Copyright 200w Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE - for more information. - $Id: spgsql.cc,v 1.2 2002/12/16 18:02:24 ahu Exp $ */ -#include "spgsql.hh" -#include -#include -#include "pdns/logger.hh" -#include "pdns/dns.hh" -using namespace std; - -bool SPgSQL::s_dolog; - -SPgSQL::SPgSQL(const string &database, const string &host, const string &msocket, const string &user, - const string &password) -{ - string connectstr; - - connectstr="dbname="; - connectstr+=database; - connectstr+=" user="; - connectstr+=user; - - if(!host.empty()) - connectstr+=" host="+host; - - if(!password.empty()) - connectstr+=" password="+password; - - d_db=new PgDatabase(connectstr.c_str()); - - // Check to see that the backend connection was successfully made - if (d_db->ConnectionBad() ) { - throw sPerrorException("Unable to connect to database"); - } - -} - -void SPgSQL::setLog(bool state) -{ - s_dolog=state; -} - -SPgSQL::~SPgSQL() -{ - delete d_db; -} - -SSqlException SPgSQL::sPerrorException(const string &reason) -{ - return SSqlException(reason+string(": ")+d_db->ErrorMessage()); -} - -int SPgSQL::doQuery(const string &query) -{ - if(s_dolog) - L<Exec(query.c_str())) { - throw sPerrorException("PostgreSQL failed to execute command"); - } - d_count=0; - return 0; -} - -int SPgSQL::doQuery(const string &query, result_t &result) -{ - result.clear(); - if(s_dolog) - L<ExecTuplesOk(query.c_str())) - throw sPerrorException("gPgSQLBackend failed to execute command that expected results"); - d_count=0; - - row_t row; - while(getRow(row)) - result.push_back(row); - - return result.size(); -} - -bool SPgSQL::getRow(row_t &row) -{ - row.clear(); - - if(d_count>=d_db->Tuples()) - return false; - - for(int i=0;iFields();i++) - row.push_back(d_db->GetValue(d_count,i) ?: ""); - d_count++; - return true; -} - -string SPgSQL::escape(const string &name) -{ - string a; - - for(string::const_iterator i=name.begin();i!=name.end();++i) { - if(*i=='\'' || *i=='\\') - a+='\\'; - a+=*i; - } - return a; -} diff --git a/modules/gmysqlbackend/spgsql.hh b/modules/gmysqlbackend/spgsql.hh deleted file mode 100644 index b9d8d17f6f..0000000000 --- a/modules/gmysqlbackend/spgsql.hh +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2001 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE - for more information. - $Id: spgsql.hh,v 1.1 2002/11/27 15:23:16 ahu Exp $ */ -#ifndef SPGSQL_HH -#define SPGSQL_HH -#include -#include "ssql.hh" - -class SPgSQL : public SSql -{ -public: - SPgSQL(const string &database, const string &host="", - const string &msocket="",const string &user="", - const string &password=""); - - ~SPgSQL(); - - SSqlException sPerrorException(const string &reason); - int doQuery(const string &query, result_t &result); - int doQuery(const string &query); - bool getRow(row_t &row); - string escape(const string &str); - void setLog(bool state); -private: - PgDatabase *d_db; - int d_count; - static bool s_dolog; -}; - -#endif /* SPGSQL_HH */ diff --git a/modules/gmysqlbackend/ssql.hh b/modules/gmysqlbackend/ssql.hh deleted file mode 100644 index 9837466883..0000000000 --- a/modules/gmysqlbackend/ssql.hh +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2001 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE - for more information. - $Id: ssql.hh,v 1.1 2002/11/27 15:23:16 ahu Exp $ */ -#ifndef SSQL_HH -#define SSQL_HH - -#include -#include -using namespace std; - - -class SSqlException -{ -public: - SSqlException(const string &reason) - { - d_reason=reason; - } - - string txtReason() - { - return d_reason; - } -private: - string d_reason; -}; - -class SSql -{ -public: - typedef vector row_t; - typedef vector result_t; - virtual SSqlException sPerrorException(const string &reason)=0; - virtual int doQuery(const string &query, result_t &result)=0; - virtual int doQuery(const string &query)=0; - virtual bool getRow(row_t &row)=0; - virtual string escape(const string &name)=0; - virtual void setLog(bool state){} - virtual ~SSql(){}; -}; - -#endif /* SSQL_HH */