hello to all,

i am new to sqlite. working with it for two month now. but i'm a big fan yet. how i couldn't?

last week i've started to write my own c++ sqlite wrapper class (CSQLiteDatabase). it is working, but i think it isn't very performant yet. so i hope somebody can help me to make it more performant.

the structure of my wrapper is:
//sqldatabase.h
#pragma once

#include "stdafx.h"
#include "sqlite.h"
#include "sqlresult.h"

class CSQLDatabase
{
/////////////////////////////////////////////////////////////////////////////////
//  EIGENSCHAFTEN:

/////////////////////////////////////////////////////////////////////////////////
//sqlite objekte
/////////////////////////////////////////////////////////////////////////////////
        sqlite *db;
        CString ErrorMessage;
        int rc;
        CString db_file;

/////////////////////////////////////////////////////////////////////////////////
//hilfsobjekte
/////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////// // METHODEN:

/////////////////////////////////////////////////////////////////////////////////
//standard constructor/destructor
/////////////////////////////////////////////////////////////////////////////////
public:
        CSQLDatabase(void);
        ~CSQLDatabase(void);

/////////////////////////////////////////////////////////////////////////////////
//verbindungsauf- und abbau
/////////////////////////////////////////////////////////////////////////////////
public:
        void setDatabase(CString db_file_string);       //zuweisund der datenbank datei
        bool connect(void);                                                     
//verbindung erstellen
        void close(void);                                                       
//verbindung herstellen

/////////////////////////////////////////////////////////////////////////////////
//absetzen eines queries mit:
//                      CSQLResult* query(CString query_string);
//als rückgabe kommt ein zeiger auf ein CSQLResult objekt.
//siehe CSQLResult deklaration.
/////////////////////////////////////////////////////////////////////////////////
public:
        CSQLResult* query(CString query_string);

/////////////////////////////////////////////////////////////////////////////////
//absetzen eines queries ohne rückgabe von daten:
/////////////////////////////////////////////////////////////////////////////////
public:
        bool exec(CString query_string);


///////////////////////////////////////////////////////////////////////////////// //balast,text,debug,... ///////////////////////////////////////////////////////////////////////////////// public: bool running(void); };

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////








///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// //sqlresult.h #pragma once

#include "sqlite.h"

/*
TODO:

[x] sqlite_seek -- Springe auf eine bestimmte Zeilennummer
*/

class CSQLResult
{
/////////////////////////////////////////////////////////////////////////////////
// EIGENSCHAFTEN:

/////////////////////////////////////////////////////////////////////////////////
//objekte
/////////////////////////////////////////////////////////////////////////////////
        char    **resultp;                                                      //char 
*[] mit der rückgabe

/////////////////////////////////////////////////////////////////////////////////
//indezes / dimensionen
/////////////////////////////////////////////////////////////////////////////////
private:
        int             nrow;                                                          
 //anzahl der zeilen
        int             ncol;                                                          
 //anzahl der spalten

int current; //nummer der aktuellen zeile

        bool    atbegin;
        bool    atend;

/////////////////////////////////////////////////////////////////////////////////
// METHODEN:

/////////////////////////////////////////////////////////////////////////////////
//standard constructor/destructor
/////////////////////////////////////////////////////////////////////////////////
public:
                        CSQLResult(char **pResultp, int pNrow, int pNcolumn);          
                         
                        ~CSQLResult(void);      

/////////////////////////////////////////////////////////////////////////////////
//speicher freigeben:
/////////////////////////////////////////////////////////////////////////////////
private:
        void    free_result(void);

/////////////////////////////////////////////////////////////////////////////////
//anfragen
/////////////////////////////////////////////////////////////////////////////////
public:
        int             num_rows(void)                                          
//anzahl der zeilen im
                                                                                       
         //query - result.
        { return nrow; }

        int             num_col(void)                                           
//anzahl der spalten im
                                                                                       
         //query - result.
        { return ncol; }

        bool    end(void)                                                       
//interner zeiger am ende?
        { return atend; }

        bool    begin(void)                                                     
//interner zeiger am anfang?
        { return atbegin; }

/////////////////////////////////////////////////////////////////////////////////
//navigation
/////////////////////////////////////////////////////////////////////////////////
public:
        bool    next(void);                                                     
//navigation vorwärts
        bool    prev(void);                                                     
//navigation rückwärts

bool seek(int row); //springe zu einem bestimmten datensatz

        void    first(void);                                            //navigation 
zum anfang
        void    last(void);                                                     
//navigation zum ende

/////////////////////////////////////////////////////////////////////////////////
//daten
/////////////////////////////////////////////////////////////////////////////////
public:
CString row(CString pColumn); //inhalt der zelle (x|y) =
//(CSQLResult::current|pColumn)
/*
* CString row(CString pColumn)
* falls pColumn mit keinem spaltennamen übereinstimmt wird "ZERO" zurückgegeben.
* dies dient lediglich zum debuggen. der stift sollte schon die richtigen
* spaltennamen angeben!
*/
CString row(int pColumn); //inhalt der zelle (x|y) =
//(CSQLResult::current|pColumn)
/*
* CString row(int pColumn)
* falls pColumn einen nicht im spaltenbereich liegt wird "ZERO" zurückgegeben.
* dies dient lediglich zum debuggen. der stift sollte schon die richtigen
* spaltennummern angeben!
*/


};

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

to receive data i use the CSQLResult class. this can be used as easy as the php api. and i like it.

but this is not a very good solution, i think. and i read, that using of callback function is much better, but i don't know how. and i hope you excuse me, but i don't know what a callback function should do.


so here is my query methode (see below). it returns a pointer of a result object. the result object gets the resultp from sqlite_get_table(...).
my question is, how to make it more performant with a callback function?




CSQLResult* CSQLDatabase::query(CString query_string)
{
char *zErrMsg = 0;
char **resultp; /* Result written to a char *[] that this points to */
int nrow; /* Number of result rows written here */
int ncolumn;


        rc =    sqlite_get_table(
                        db,                                                            
 /* An open database */
                        query_string,                                   /* SQL to be 
executed */
                        &resultp,                                           /* Result 
written to a char *[]  that this points to */
                        &nrow,                                                      /* 
Number of result rows written here */
                        &ncolumn,                                           /* Number 
of result columns written here */
                        &zErrMsg                                            /* Error 
msg written here */
                        );

if( rc!=SQLITE_OK )
{
AfxMessageBox("FEHLER: CSQLDatabase::query(CString query_string)");
return NULL;
}else
{
CSQLResult* result = new CSQLResult(resultp,nrow,ncolumn);
/*debug*/
//AfxMessageBox("CSQLResult* result = new CSQLResult(resultp,nrow,ncolumn); YEAHH!!!");
/*debug*/
return result;
}
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to