开发者

Blackberry thread hanging on SQLite statement prepare

开发者 https://www.devze.com 2023-01-05 15:33 出处:网络
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.

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%开发者_JAVA百科' 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消