On Thu, Jan 24, 2013 at 10:31 AM, Frank Chang <frankchan...@gmail.com> wrote: > Could anyone suggest which C++ data structure to use to cache a sqlite > query result? Thank you for your help
Because of the strong typing benefits of C++, it makes little sense (to me) to store the result in a container of a different type. A vector of strings would work to store anything, but that would require lots of conversion. A struct containing only data members would be a better fit to avoid conversion. But a class with members is the way to go. Let the class take care of getting the values, converting them, let the object update its own data on the database. Objects contain data and offer services, objects have a lifetime. class Human { int age; string name; public: ... bool TryToRob( int amount ); }; class Imagine the following "pseudo C++ code": void CancelCourse(string School, int Course) { StudentList s = PeopleList(STUDENT).Filter(SCHOOLNAME, School).Filter(COURSEID, Course); for_each(s.begin(), s.end(), inform_student_of_course_cancelation ); TeacherList t = PeopleList(TEACHER).Filter...; if ( t.size() != 1 ) throw course_has_invalid_number_of_teachers; t[0]->RemoveFromCourse(Course); t[0]->AdjustSchedule(); if ( t[0]->Courses.size() == 0 ) t[0]->SendOnVacation(); } In this code, the fact we're using a database and make queries has been succesfully abstracted. The way a teacher's schedule is handled is probably different from how a student's is. Also, the teacher gets paid while the student pays, only students can cheat, but both can be absent. The data that holds this information can be stored in one single table if it makes sense, but they are two different objects in C++. It depends on the context, but a query that joins two table (ie persons attributes and a person address for instance) could be viewed as a derived object (it is still a person, but now it has an address also and supports shipping). In C++ it is probably best to work as close to the problem domain you're dealing with (teachers, courses, students) rather than remain at the lower-level where queries are made in certain ways to emulate the higher level tasks. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users