Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

out of memory in sqlite

Hi. I hae this code :

public Vector getListConsulta() {
  Vector result = new Vector();
  Statement stmt = null;
  Cursor cursor = null;

try {
  stmt = mDB.createStatement("SELECT fecha, xml FROM consulta ORDER BY fecha DESC");
  stmt.prepare();
  cursor = stmt.getCursor();
  while (cursor.next()) {
    Row row = cursor.getRow();
    ConsultaXMLBean bean = new ConsultaXMLBean(row.getString(0),row.getString(1));
    result.addElement(bean);
  }
} catch (Exception ex) {
  ex.printStackTrace();
} finally {
   mDBHelper.closeQuietly(cursor);
   mDBHelper.closeQuietly(stmt);
}

		return result;
	}

 And I got net.rim.device.api.database.DatabaseOutOfMemoryException: : out of memory exception in line "while (cursor.getNext()).

 

I use the "SQLIdemo" approach to use one connection open for all the database work.

 

Any hint, please ?

TIA

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: out of memory in sqlite

it getting worse...!!!!

In methods that return one record, throws the same exception :

For example. this method returns only one record:

 

public ConsultaXMLBean getNewestConsulta() {
	ConsultaXMLBean result = new ConsultaXMLBean();
	Statement stmt = null;
	Cursor cursor = null;

	try {
		stmt = mDB.createStatement("SELECT fecha, xml FROM consulta ORDER BY fecha DESC LIMIT 1");
		stmt.prepare();

		cursor = stmt.getCursor();
		if (cursor.first()) {
			Row row = cursor.getRow();
			result.setFecha(row.getString(0));
			result.setXml(row.getString(1));
		}

	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		mDBHelper.closeQuietly(cursor);
		mDBHelper.closeQuietly(stmt);
	}

	return result;

}

 And i got the same exception in line "if (cursor.first()) {....

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: out of memory in sqlite

Hi, Anyone can help me with this issue ? It looks like only happend with cursos...

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: out of memory in sqlite

I found the error source.. In my table i have two TEXT fields, one of them is an XML, so it could be a long string. It look like that cursor.first() or cursor.next() allocates memory to get all the data. It should be only a pointer and getRow() or getDataType(field_index) must read the final data...

 

Is there a way to do that ? or myabe I can use BLOB to store the long text as workaround ?

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: out of memory in sqlite

Another option that you can try is to keep your XML data as file(s) and its meta data in the DB.

 

An SQLite data is basically a file so it's not very recommended for large amount of data.

 

E.

Highlighted
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: out of memory in sqlite

Thanks. I already think on you suggestion as an alternative solution...

Again, thanks a lot...