#ifndef _XMLHTTPDATABASE_H #define _XMLHTTPDATABASE_H /* Allows access to a database over HTTP/1.1 The socket connection is held open for subsequent requests (keep-alive) the normal SQL is passed to a recieving webpage that then runs it against the DB sHost is the URL of the webpage. The webpage itself handles the connection sDB, sUsername and sPassword should be passed through to the webpage which should use it to connect The Database maintains session between requests as an auth token */ #include "Database.h" #include "Protocols.h" #include "Domain.h" #include "DomainConnection.h" #include "InternetURIRequest.h" #include "XMLPage.h" #include //XMLHTTPDatabase is still a database linked to PostGRES in terms of SQL syntax class XMLHTTPRecordSet; //multiple XMLHTTPDatabase objects are acceptable. Each has its own buffer, mutex and DC //multiple requests on the *same* XMLHTTPDatabase are ok but the actual HTTP request is single threaded (mutex) //this is because the DB uses 1 HTTP persistent DC connection. class XMLHTTPDatabase: public Database { Domain m_domain; DomainConnection m_DC; bool m_connected; char *m_buffer; const size_t m_buffersize; pthread_mutex_t m_hSingleThreaded_mutex; //MUTEX to make this single threaded (and thus maintain connection) public: //throws an exception if it fails: XMLHTTPDatabase(const char *_host, const char *_db, const char *_username = 0, const char *_password = 0); ~XMLHTTPDatabase(); bool connect(); bool connected() const; int execute(const char *sql, RecordSet **result = 0, char **sError = 0, const bool manageResults = false); int execute(const char *procedure, const int argc, const char *argv[], const bool argt[], RecordSet **result=0, char **sError = 0, const bool manageResults = false); //had to explicitly in-line state these because the compiler was not spotting the int and char variations int execute(const char *sql, char **result, char **sError=0) {return Database::execute(sql, result, sError);} int execute(const char *sql, int *result, char **sError=0) {return Database::execute(sql, result, sError);} int execute(const char *procedure, const int argc, const char *argv[], const bool argt[], char **result, char **sError = 0) {return Database::execute(procedure, argc, argv, argt, result, sError);} int execute(const char *procedure, const int argc, const char *argv[], const bool argt[], int *result, char **sError = 0) {return Database::execute(procedure, argc, argv, argt, result, sError);} }; class XMLHTTPRecordSet: public RecordSet { InternetResource *m_xml; const bool m_manageBuffer; vector m_rowStarts; public: XMLHTTPRecordSet(InternetResource *_xml, const bool _manageResults = false, const bool manageBuffer = false); ~XMLHTTPRecordSet(); size_t size(); int value(char **value, const unsigned int row = 0, const unsigned int column = 0); int length(size_t *length, const unsigned int row = 0, const unsigned int column = 0); const char *raw(const unsigned int row = 0) {return m_rowStarts[row];} }; #endif