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: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

SQLite pending

To all developer,

I'm having problem in using SQLite...

The problem is, sometimes when inserting or updating data, SQLite always pending and will procceed again after a few seconds.. This is became a problem if i'm using multithread function that have to insert data XML from web server..

Is there any solution?

 

For initial database, i'm using this code :

 

public static void initialDatabase()
{
  try {
    uri = URI.create(dbLocation + DB_NAME);
    if (!DatabaseFactory.exists(uri))
    {
	createDatabase(uri);
	isNull = true;
    }
    database = DatabaseFactory.open(uri);
  } catch (Exception e) {}
}
	
public static void createDatabase(URI uri)
{
  try {
    database = DatabaseFactory.create(uri, new DatabaseSecurityOptions(false));
    LocationDatabaseAdaptor.createTableLocation();
    VenueDatabaseAdaptor.createTableVenue();
    VenueCategoryAdaptor.createTableVenueCategory();
    UserInformationDatabaseAdaptor.createTableUserInformation();
  } catch (Exception e) 
  {
    e.printStackTrace();
  }
  finally
  {
    closeDatabase();
  }
}

 

 

and each of my database class adaptor, i'm using function like this :

 

public static boolean insertVenueCategory(CategoryVenueModel category)
{
  boolean pass = false;
  try
  {
    Statement st = DatabaseConnectionLibrary.database.createStatement("INSERT INTO  venueCategory VALUES(?,?,?,?,?)");
    st.prepare();
    st.bind(1, String.valueOf(category.getIdCategory()));
    st.bind(2, category.getName());
    st.bind(3, String.valueOf(category.getIdParentCategory()));
    st.bind(4, category.getPostDate());
    st.bind(5, category.isHaveSub());
    st.execute();
    st.close();
    pass = true;		
  }
  catch ( Exception e ){
  }
  return pass;
}

 

 

BlackBerry Development Advisor
Posts: 15,062
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: SQLite pending

What do you mean by pending?  Is it taking a few seconds to complete, blocking, etc...

 

I wouldn't recommend issuing inserts at the same time from multiple threads.  Instead, use a single thread and buffer the data you need to insert there.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: SQLite pending

When i'm debugging my application, i got SQLite Pending Operation in statement.prepare...

sometimes it takes a lot of time just to select 8 rows or update n insert to table...

n sometimes the application didn't insert the data to SQLite because of this behavior...

i want to use single thread but, the problem is my application using many function that will be runnning using thread...

So i can't make it to be a single thread..

For example, when i'm running my application, a thread for receive update category from web server and save it to database will be running, and another thread for getting data from database is also running...

 

i've already make a controller to queue all the thread for accessing SQLite using vector...

1. Create a vector for receive any insert, update & delete SQLite Thread

2. The vector will start the first thread

3. if the thread is done, it'll be removed form vector, then the vector start another thread..

But my problem is, it's not available if i want to SELECT the sqlite because thread doesnt make any return function..

Is there a better way to solved this problem?

BlackBerry Development Advisor
Posts: 15,062
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: SQLite pending

As long as you only have 1 thread inserting data at a time, you should be OK.

 

Have you read over this page?  

 

Performance of SQLite databases

http://docs.blackberry.com/en/developers/deliverables/17952/SQLite_database_performance_1228636_11.j...

 

Some details that apply to your scenario...

 

On a BlackBerry device, only one read-write database connection to an SQLite database can be made at a time. Other database connections are read-only. There is a limit of 16 concurrent database connections, and three to six of those are used by the media application.

 

Use explicit transactions

If you do not use explicit transactions, a transaction begins before each statement is executed and ends after the statement is executed. This default behavior is inefficient. It requires the opening, reopening, writing to, and closing of the journal file for each statement. With explicit transactions, you can group statements.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: SQLite pending

Hm... for my application, i'm just using 1 database connection actually, but all of my function will be use this database for creating the statement... is this the right way?

For large data manipulation, i'm also using beginTranscation for insert and update data...

 

Trusted Contributor
Posts: 141
Registered: ‎02-15-2012
My Device: 9800
My Carrier: Airtel

Re: SQLite pending

I got the exact solution for it.

It was causing when we are trying to call database operations from background thread. And in foreground, somewhere invalidate() or updateLayout() is called under paint and generating any deadlock.

Because of deadlock, it was blocking DB operaions in synchronized blocks.

 

If you have any query, message me.