Monday, December 19, 2011

Misleading "Out of Memory" Error in SQLite3

(Please take a look at our crowd-funding campaign at

The following is recorded in the hope that it may save someone else the hassle of tracking down this kind of error.

While working on Serval 0.08 I have been working with SQLite3 for the first time.

I had the following fairly innocent query causing SQLite to report an "out of memory" error:

int count=sqlite_exec_int64("SELECT COUNT(*) FROM FILES WHERE id='%s' AND datavalid<>0;",hash); 

After spending a bit of time hunting everywhere to find where I could possibly have leaked enough RAM for SQLite3 to get upset, I finally realised that the column datavalid did not exist in the FILES table.  I had meant to update the CREATE TABLE statement, but obviously hadn't gotten around to it.

I updated the CREATE TABLE statement to include a definition for the datavalid column, and the "out of memory" errors are now a thing of the past.

I can only guess that somewhere in SQLite3 when it tries to find the column, it gets a NULL pointer returned, which some other part of itself then interprets as a failure to allocate memory to retrieve the column, rather than the failure of the column itself to exist.


  1. I had the same problem. I tried so many ways to solve it but failed. At last i found the reason and i wondered. In my case the reason for the error was i was printing the entire response string in log cat. That was the reason for that.

  2. Same problem here... DB was not opened yet