Re: [sqlite] Header pointers in table callback
On 7/11/2011 11:04 AM, Prakash Reddy Bande wrote: > We were looking at the ways we can optimize our application. Our app > does a simple sqlite3_exec and sends the callback as below. The data > is just a map > > > int sqlite3TableCallback(void* data, int ncols, char** values, char** headers) > > { > map >& table = *(( map vector >*) data); > for (int i = 0; i< ncols; i++) > { >if(values[i]) > table.Data[headers[i]].push_back(string(values[i])); >else > table.Data[headers[i]].push_back(string()); > } > return 0; > } > > Here, we wanted to optimize the string construction of string in > table.Data[headers[i]]. We were happy to notice that the headers were > pointing to the same address, hence we are planning to enhance the > callback data so that it can track map, and then in > the table.Data[headers[i]] we can pass reference to the string > preventing its construction and destruction. Agreed, there will be > another look-up in the map, for char* to string. Personally, I'd build a vector >, just assigning sequential numbers of columns. You could also build a vector containing column names the first time the callback is called. With these two in hand, it's trivial to build a map > : for (int i = 0; i < data.size(); ++i) { mymap[headers[i]].swap(data[i]); } Actually, I'd not use sqlite3_exec at all, but instead a loop based on sqlite3_prepare and sqlite3_step. -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Header pointers in table callback
On Mon, Jul 11, 2011 at 11:04 AM, Prakash Reddy Bande wrote: > > Well, the bottom line, is it safe to assume that char** headers will be > pointing to the same address through out the query (i.e. each time callback > is called for a matching row). > We cannot positively, absolutely guarantee that this will never change, since it is not part of the spec. But SQLite has always worked as you describe and we have no plans to change it. I'd say you are reasonably safe to make the optimization. -- D. Richard Hipp d...@sqlite.org ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Header pointers in table callback
Hi, We were looking at the ways we can optimize our application. Our app does a simple sqlite3_exec and sends the callback as below. The data is just a map > int sqlite3TableCallback(void* data, int ncols, char** values, char** headers) { map >& table = *(( map >*) data); for (int i = 0; i < ncols; i++) { if(values[i]) table.Data[headers[i]].push_back(string(values[i])); else table.Data[headers[i]].push_back(string()); } return 0; } Here, we wanted to optimize the string construction of string in table.Data[headers[i]]. We were happy to notice that the headers were pointing to the same address, hence we are planning to enhance the callback data so that it can track map, and then in the table.Data[headers[i]] we can pass reference to the string preventing its construction and destruction. Agreed, there will be another look-up in the map, for char* to string. Well, the bottom line, is it safe to assume that char** headers will be pointing to the same address through out the query (i.e. each time callback is called for a matching row). Regards, Prakash Bande Altair Engg. Inc. Troy MI Ph: 248-614-2400 ext 489 Cell: 248-404-0292 ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users