Accessibility

Table of Contents

User experience considerations with SQLite operations

Processing data

In addition to the time spent executing a database operation, regardless of the execution mode, trying to process too much returned data at once can lead to user experience issues. The application code that iterates over a SQLResult is running in the application thread which means that if it needs to loop over hundreds of records and manipulate each one, the time spent processing is not being used to handle effects or user gestures. The primary means to avoid this situation is to divide the data processing into smaller pieces. Between processing each group of data the application thread is allowed to execute code that handles other UI tasks and thus the application remains responsive. The primary technique for dividing up the work on a connection is to use the SQLStatement.execute() method's prefetch argument and the corresponding next() method. An alternative technique can be to manually divide up processing the results using techniques like an enter frame handler, callLater(), or a Timer.

The first optional parameter to the execute() method on a SQLStatement is a prefetch size. If it is unspecified, all records matching the query will be returned. If a prefetch is specified, no more than the number of records specified will be returned. The SQLResult.complete property indicates whether there are additional records that could be returned. To divide up the data processing, all of the records returned in a single request are processed and then the same SQLStatement is used to fetch the next set of records. The next() method also takes a prefetch argument, letting the application divide up the remaining records in the best possible way. This method of dividing up the processing by using a prefetch limit is best suited for an asynchronous connection because the application can process other events while the system thread is gathering the next set of results. If a synchronous connection is used, the calls to next() should be divided up using one of the methods mentioned below.

To manually divide up the processing of a large set of results an enter frame handler, callLater(), or a Timer can be used. Each time an enter frame or time event fires, the application processes a fixed amount of the remaining data and then stops until the next event fires. This same approach applies to callLater() but instead of waiting for an event, the application supplies a function to continue processing the work. Each time the data processing stops to wait for the next batch other application code activities for updating the user interface or handling user gestures get processed keeping the user interface responsive. Details on using each of these techniques can be found in the Adobe Flex documentation.