The formatting on part of my response didn't turn out as I expected. I'll try that part again:
Think of a vRecordset vector like this, as a vector of vRecord vectors: vRecord0< Field0, Field1, Field2, FieldN > vRecord1< Field0, Field1, Field2, FieldN > vRecord2< Field0, Field1, Field2, FieldN > vRecord3< Field0, Field1, Field2, FieldN > vRecord4< Field0, Field1, Field2, FieldN > vRecord5< Field0, Field1, Field2, FieldN > vRecord6< Field0, Field1, Field2, FieldN > vRecord7< Field0, Field1, Field2, FieldN > Lee Crain ______________________________________________________ -----Original Message----- From: Lee Crain [mailto:[EMAIL PROTECTED] Sent: Thursday, August 09, 2007 1:45 PM To: sqlite-users@sqlite.org Subject: RE: [sqlite] Object Oriented Question About Adding a vector inside the callback function Stephen, I was faced with a similar problem while writing a SQLite API wrapper for our application programmers. My solution was this: > I created a Field class that is a container than can hold ONE of several different data types. > I created a Record class that consists of a vector of Fields and supporting vector access services. (vector<Field> vRecord) > I created a vector of Records as my Recordset. (vector<Record> vRecordset) Think of a vRecordset vector like this, as a vector of vRecord vectors: vRecord0< Field0, Field1, Field2, FieldN > vRecord1< Field0, Field1, Field2, FieldN > vRecord2< Field0, Field1, Field2, FieldN > vRecord3< Field0, Field1, Field2, FieldN > vRecord4< Field0, Field1, Field2, FieldN > vRecord5< Field0, Field1, Field2, FieldN > vRecord6< Field0, Field1, Field2, FieldN > vRecord7< Field0, Field1, Field2, FieldN > The x axis consists of the Field containers loaded into the vRecord vector. The y axis consists of the vRecord vectors loaded into the vRecordset vector. The Recordset vector is instantiated on the stack in application code and before the SQLite API wrapper call. Then its ADDRESS is passed as an argument to my SQLite API wrapper class method calls. Those calls store the pointer to the vRecordset vector in a static vRecordset vector pointer, then execute the "sqlite3_exec()" function call which triggers the static callback function (at global scope) to read back the data from the SQL queries. The callback function populates a Field class object for each field in the received data. After all fields have been received (1 row per callback), each of the Field class objects is loaded into a vRecord vector which is loaded into the vRecordset vector ("pushback()" calls). I don't see a way to make the callback function non-static. So, I didn't try. OO programming is type specific. That presented a problem in the static callback function because the data coming back is not type specific. So, I solved that problem by creating a Field container that could hold any datatype. For each query executed, I programmed my solution to know exactly the order of (left to right) and the expected datatypes for each field that is returned, so that the callback function can translate the returned data to its correct datatype before loading that data into a Field container. That way, when the application code receives a vRecordset back from a read operation, it doesn't have to deal with the datatypes; they're already correctly set inside each Field container. With the exception of the static parts of my implementation, everything is strictly OO. The breakthrough for me was to create a Field container that could hold any datatype. Now, I have an interface that is not bound to any particular tables or fields, which can receive and hold the data results from any query. Even if our underlying database changes, my SQLite API wrapper source code will not. I hope this helps, Lee Crain -----Original Message----- From: Stephen Sutherland [mailto:[EMAIL PROTECTED] Sent: Thursday, August 09, 2007 1:06 PM To: sqlite-users@sqlite.org Subject: [sqlite] Object Oriented Question About Adding a vector inside the callback function 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. -------------------------------------------------------------------------- --- To unsubscribe, send email to [EMAIL PROTECTED] -------------------------------------------------------------------------- --- ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------