views:

16

answers:

1

Hi Gurus.

I'm developing an application that implements an EditField in which you can type a word and while typing the application will filter the contents that are being shown on screen.

For this, I'm starting a new thread when the user types. This thread extracts the information from a SQLite table and then shows it on the UI.

I use SQLite for other things in the application and every statement works great.

THE PROBLEM is that when I use the Statement.prepare() method in the Filtering thread, it hangs!

To make this simpler, lets suppose the user only typed 1 letter in the EditField.

The idea of the code is something like this:

I start the thread after the user typed a letter:

            mThread = new Thread(){                 
                  public void run(){filtrarListaRecolecciones();}                     
            };
            mThread.setPriority(Thread.MAX_PRIORITY);
            mThread.start();

And at filtrarListaRecolecciones I run:

mStatement = mBD.createStatement("SELECT COUNT(*) FROM Recolecciones WHERE Nombre LIKE '%a%' AND Status=3");
mStatement.prepare();

And the thread hangs at the prepare statement.

It used to get the result after about 1 minute but now it just hangs.

The table has only 1 record so it shouldn't be because of that.

Any help would be greatly appreciated!

Thanks!

A: 

The problem with SQLite in Blackberry is that you can't share a SQL Connection over threads, you have to connect to the DB file, query and close all in the same thread.

SQLite is threadsafe but only if you use different connection objects through different threads.

Curro