If I understand you right then try it:
static int add_value( void *st, int, char **value, char ** )
{
storage_t * storage = (storage_t*) st;
st->push( value[ 0 ] );
return SQLITE_OK;
};
class storage_t {
public:
storage_t()
: m_db( 0 )
{
sqlite3_open( "your_database.db", &m_db );
};
virtual ~storage_t()
{
sqlite3_close( m_db );
};
void push( const std::string & v )
{
m_buff.push_back( v );
}
void read_table()
{
sqlite3_exec( m_db, "SELECT * FROM some_table",
add_value, this, NULL );
}
private:
sqlite3 * m_db;
std::vector< std::string > m_buff;
};
This is very simple example, but it can help you I think.
Stephen Sutherland wrote:
Hi
I am using the 'quick start' C-styled code for sqlite3 http://www.sqlite.org/quickstart.html
I think I'm running into a problem trying to put it in classes to make it somewhat object oriented. So I'm asking for help about how to make it object-oriented - or to confirm whether what I'm doing is object oriented.
Here is the code:
[code]
//callback function
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
};
// this callback is referenced here.
void MyClass::executeSQLStatement()
{
rc = sqlite3_exec(db, "select * from table1" , callback, 0, &zErrMsg);
};
[/code]
However I am trying to add a vector in the callback function to store the results. When I put the vector in it seems I am forced to do something like this:
[code]
vector vecX;
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
vecX.push_back(argv[3]);
printf("\n");
return 0;
};
[/code]
Now this doesn't seem object oriented ?
Nor do I understand how I would access this vector from other classes ?
And I don't know how this vector which I created can be considered part of the class ? it seems to me to only have page scope.
Any advice on how to make my vector object oriented or accessible by other classes ?
Thanks in Advance
Stephen
---------------------------------
Pinpoint customers who are looking for what you sell.
--
Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------