Commit 27d31fea authored by jan.koester's avatar jan.koester
Browse files

sql reconnect method implemented

parent cf9015c1
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -336,6 +336,15 @@ void blogi::Blogi::RequestEvent(netplus::con *curcon){
    }catch(libhttppp::HTTPException &e){
        if(e.getErrorType() == libhttppp::HTTPException::Note || e.getErrorType() == libhttppp::HTTPException::Warning)
            return;

        if(!PlgArgs->database->isConnected()){
            PlgArgs->database->reset();
            if(PlgArgs->database->isConnected()){
                RequestEvent(curcon);
                return;
            }
        }

        std::string output;
        libhtmlpp::HtmlString err,hreason;
        libhtmlpp::HtmlEncode(e.what(),hreason);
+2 −0
Original line number Diff line number Diff line
@@ -114,5 +114,7 @@ namespace blogi {
        virtual int exec(SQL *sql,DBResult &res)=0;
        virtual const char *getDriverName()=0;
        virtual const char *autoincrement()=0;
        virtual bool isConnected()=0;
        virtual void reset() =0;
    };
};
+13 −2
Original line number Diff line number Diff line
@@ -85,13 +85,24 @@ namespace blogi {
            return rcount;
        };

        const char *getDriverName(){
        const char *getDriverName() override{
            return "pgsql";
        };

        const char *autoincrement(){
        const char *autoincrement() override{
            return "GENERATED BY DEFAULT AS IDENTITY";
        }

        bool isConnected() override{
            if(PQstatus(_dbconn)==CONNECTION_CONSUME)
                return true;
            return false;
        }

        void reset() override{
            PQresetPoll(_dbconn);
        }

    private:
        PGconn      *_dbconn;
    };
+14 −2
Original line number Diff line number Diff line
@@ -123,14 +123,26 @@ namespace blogi {
            return rcount;
        };

        const char *getDriverName(){
        const char *getDriverName() override{
            return "sqlite";
        };

        const char *autoincrement(){
        const char *autoincrement() override{
            return "AUTOINCREMENT";
        }

        bool isConnected() override{
            int current,high;
            if(sqlite3_db_status(_dbconn,0,&current,&high,0)==SQLITE_OK)
                return true;
            return false;
        }

        void reset() override{
            int current,high;
            sqlite3_db_status(_dbconn,0,&current,&high,1);
        }

    private:

        sqlite3  *_dbconn;