Commit Graph

167 Commits

Author SHA1 Message Date
Vasu Nori
7b04c4176d make disableWriteAheadLogging method public so apps can disable WAL
music2 app has the weird situation where it embeds the jumper C++ code
and that code uses its own version of sqlite.
so, java side may want to disable WAL to make c++ code work well with java
usage of sqlite.
since WAL is made default option for all apps, this CL makes it possible for
music2 app to disable WAL.

Change-Id: I39ddbc9b4648f12b206ff3e76d30341da5955bd4
2010-07-20 10:31:21 -07:00
Brad Fitzpatrick
d2f6c7fe73 am 3e5e21d4: am 1772c34e: Merge "StrictMode: gather and return violating stacks in Binder replies" into gingerbread
Merge commit '3e5e21d4dc74751e64d17379c5563ece39a7e35d'

* commit '3e5e21d4dc74751e64d17379c5563ece39a7e35d':
  StrictMode: gather and return violating stacks in Binder replies
2010-07-15 23:05:39 -07:00
Brad Fitzpatrick
3e5e21d4dc am 1772c34e: Merge "StrictMode: gather and return violating stacks in Binder replies" into gingerbread
Merge commit '1772c34e5331a6456c8a93051192d19ff873c062' into gingerbread-plus-aosp

* commit '1772c34e5331a6456c8a93051192d19ff873c062':
  StrictMode: gather and return violating stacks in Binder replies
2010-07-15 15:44:46 -07:00
Brad Fitzpatrick
5b747191ff StrictMode: gather and return violating stacks in Binder replies
Now, when Thread A has a strict mode policy in effect and does a
Binder call to Thread B (most likely in another process), the strict
mode policy is passed along, but with the GATHER penalty bit set which
overrides other policies and instead gathers all offending stack
traces to a threadlocal which are then written back in the Parcel's
reply header.

Change-Id: I7d4497032a0609b37b1a2a15855f5c929ba0584d
2010-07-15 13:18:05 -07:00
Mike Lockwood
9d9c1be296 SQLiteDatabase: Add mechanism for registering custom sqlite3 functions
This allows you to define a callback in Java that can be called from
sqlite3 database triggers.

Change-Id: I09fdbd38c9807b6b0dd19c2761b01e8db76f1adc
Signed-off-by: Mike Lockwood <lockwood@android.com>
2010-07-14 19:52:33 -04:00
Vasu Nori
e25539fdfd reduce locking when using SQLiteStatement
Do compiling of sql, binding of args and execution of the SQL
statement within one single database lock period.
This reduces the number of times the database lock
needs to be acquired during the course of compilation, binding
and execution of a SQLiteStatement.

Change-Id: I22b090ec9e10fc0aa2532a93bafe610af2546b58
2010-07-09 12:31:12 -07:00
Vasu Nori
b2d2ddc5ac reduce java locking on SQLiteDatabase if sql is already compiled
Change-Id: I6c2c593ba69aad201cedf097384d0b5d835c0839
2010-07-08 12:53:22 -07:00
Vasu Nori
57feb5d9a7 STOPSHIP CL in master - make sqlite WAL default for all apps
for testing the sqlite WAL feature in the next few weeks.

Change-Id: I07234647b5e90d9e3bb0a5310b6cc449d58db428
2010-07-08 11:41:52 -07:00
Vasu Nori
9bf225ef7b documentation about not using journal_mode if using WAL
apps should not setting journal_mode if the application is
using a connection pool for readers by calling the method
SQLiteDatabase.enableWriteAheadLogging()

Change-Id: I9ddb32638171c6277ca94381a1b5d4b39b92b386
2010-07-07 16:38:28 -07:00
Vasu Nori
2827d6d974 for WAL to work, can't keep prepared SQL stmt_id in SQLiteStatement
Some (including the Contacts app) do the following:
  1. Open database
  2. As part of database_connection.onCreate(),
       Create some SQLiteStatement objects to cache them in the process
  3. attach databases
WAL doesn't work with attached databases. so, apps doing the above
should enable WAL only if there are no attached databases.

But we would like to enable WAL automatically for all apps after step #1 above
and disable WAL if the app subsequently does 'attach database' SQL.

this works only if there are no SQLiteStatement objects created in step # 2,
because SQLiteStatements cwmaintain a hard-reference to the database connection
for life and also to the prepared SQL statement id.
It is quite difficult to disable WAL in step # 3
    if it is enabled in step # 1
    and then a connection pool gets used by step # 2

would make WAL disabling easier if SQLiteStatement refers to prepared SQL
statement id only when it is needed (during binding and execute calls)
and thus NOT tied to a spacific database conenction.

also, from the standpoint of not blocking readers, it helps NOT to have
SQLiteStatement be married to a database connection and prepared SQL statement
id for life.

Change-Id: I464d57042965a28d2bde88e0f44b66ec119b40dc
2010-07-07 15:33:42 -07:00
Vasu Nori
6ac21d30be unittests for DatabaseConnectionPool (and fix bugs)
Change-Id: I6f251b4bdd472bd840ea1be6497660f8c31cd3e3
2010-07-07 14:26:10 -07:00
Vasu Nori
59d60420ba deprecate method returning prepared sql statement id
this method causes sql statement in a SQLiteProgram object to be never
re-compiled. thats not desirable, is it?
there should be no need for this method.

Change-Id: I207fad6415c1e2ef4097ee65a3ff347b5435b994
2010-07-03 16:31:35 -07:00
Vasu Nori
cd815158a4 Merge "some refactoring and multi-threading fixes" 2010-07-02 11:01:50 -07:00
Vasu Nori
7501010b71 some refactoring and multi-threading fixes
Change-Id: I7a0497dc2ed7b1e21471d71532558ef243eb9f73
2010-07-02 10:58:29 -07:00
Vasu Nori
cc08bb8884 fix broken-build
Change-Id: I0f956d87c26100ddb12e1736a0ec02e1b17e166f
2010-07-01 18:55:30 -07:00
Jeff Hamilton
f1a4a0a5b7 More cleanup after removing the Cursor update logic.
Change-Id: I4f407d3205cf97260bf3c3f3df4a0e2c533acab8
2010-06-30 17:14:50 -05:00
The Android Open Source Project
7701041955 am 7e343b8d: merge from froyo-plus-aosp
Merge commit '7e343b8d39309d2c9d73cc5d1ec2434e666ae48b'

* commit '7e343b8d39309d2c9d73cc5d1ec2434e666ae48b':
  fillWindow's start position must be smaller than getCount value
2010-06-25 14:22:06 -07:00
The Android Open Source Project
7e343b8d39 merge from froyo-plus-aosp
Change-Id: Ic1d0535cb746af0c53a5277b008061f7a2d973a2
2010-06-25 11:20:45 -07:00
Vasu Nori
6188c2746d remove some not-so-useful-logging
the sql statement is already printed if SqlStatements is set to VERBOSE
anyway. so no need for this extra logging
Change-Id: Id0e6c5acbbbd453ea45f08bcb802213bc22896fc
2010-06-25 11:10:54 -07:00
Dianne Hackborn
36e5f667bc resolved conflicts for merge of 2eb12a47 to master
Change-Id: I79eb9d9f083e51ec1b99145d81632683669e7a99
2010-06-24 16:29:54 -07:00
Dianne Hackborn
01e4cfc47d Some ActivityThread/ActivityManager cleanup.
- Move PackageInfo out of ActivityThread, renaming to LoadedApk.
- Rename some of the other PacakgeInfo inner classes to better
  represent what they are.
- Rename HistoryRecord to ActivityRecord.
- Introduce AppGlobals, to eventually let ActivityThread become
  package scoped.

Change-Id: Ib714c54ceb3cdbb525dce3db9505f31042e88cf0
2010-06-24 15:20:48 -07:00
Vasu Nori
8d1110383d if attach database sql statement is exec'ed, disable write WAL
an app can execute 'attach database..' statement anytime after WAL is
enabled. since WAL doesn't work with atatched databases,
disable WAL whenever the caller executes 'attach database'
sql statement.

Change-Id: I77dfcb744b59476c357d44296c14d63455985a7b
2010-06-22 18:34:21 -07:00
Vasu Nori
a98cb2632d for memory databases, don't set journal_mode and don't allow WAL
WAL and journal_mode are not applicable to memory databases

Change-Id: I06fcbfe9ce76878c57d1542efe9cc060598262ff
2010-06-22 15:52:12 -07:00
Vasu Nori
5666170c1e when corruption occurs, not clsing the db is casuing stack overflow
due to a bug in DefaultDatabaseErrorHandler, if the corruption is
so bad that the list of attached databases can't even be retrieved,
then database is not closed in DefaultDatabaseErrorHandler,
this causes the corrupted file to remain on disk.
this causes corruption detection to occur forever until the stack
overflows.

Change-Id: I9896bee220231cbde0b1620ad0a617420424967c
2010-06-22 12:22:31 -07:00
Andrew Stadler
359cf08fb6 Merge "Add getWrappedCursor, and update the JavaDoc." 2010-06-21 11:35:51 -07:00
Vasu Nori
194897da94 journal_mode should be set only on non-memory databases
setting journal_mode to TRUNCATE on memory databases causes an error message
to be displayed by SQLIteDatabase.

Change-Id: Ie8b8ae22cb9fba99cee59dba35b260195c63eadc
2010-06-21 10:41:14 -07:00
Andrew Stadler
46baf533f5 Add getWrappedCursor, and update the JavaDoc.
Change-Id: I7d0513056b4d83b457374d783465fe848b7e530c
2010-06-21 10:23:52 -07:00
The Android Open Source Project
e5a023bfbb merge from open-source master
Change-Id: I8e7ccd470e8b90347686985aa2d8337d0c38900c
2010-06-18 12:40:42 -07:00
Vasu Nori
daa4e4faff throw correct exception
when an argument is incorrect, throw IllegalArgumentException
not IllegalStateException

Change-Id: I9a33410617ab6a00147c3ab2010ed31251983329
2010-06-15 11:32:27 -07:00
Vasu Nori
d127fb69ae Merge "fix bugs introduced by I3ef1bcdb2eb1c45f68e829ccb6e3ecde28076591" 2010-06-14 17:11:20 -07:00
Vasu Nori
ad239ab8fa when closing db, close all pending statements also
Change-Id: Ia543933e0cd70852c4e60623de698bb51b976900
2010-06-14 16:58:47 -07:00
Vasu Nori
0a2c6cc013 fix bugs introduced by I3ef1bcdb2eb1c45f68e829ccb6e3ecde28076591
two bugs were introduced by the above CL
1. to test if the column value is NULL, getType_native() should check if
the columnindiex is valid. (it seems sometimes callers could ask if a
given non-existent column is null - and the answer should be true.)
2. if a column is null and isBlob_native, isString_native methods should
return true - not false.

Change-Id: I64df75d0a3840a4502c00db8759c66ba4b268a26
2010-06-14 15:57:30 -07:00
Vasu Nori
6c354da943 read old version of data and use multiple connections to db
cts tests are in Change-Id: Ifcc89b4ff484c7c810fd2d450ded212a43360dda
dependency on: Change-Id: I938c42afc3fb50f5296d01c55ffcf4a102d8b0cb

1. Use sqlite's work-in-progress writeahead logging feature to read old
     versions of data and thus increase concurrency of readers
     even when there is a writer on the database
2. New API executeQueriesInParallel() sets up a database connecion pool
     automatically created and managed by sqlite java layer
3. To increase reader concurrency, add an option to do BEGIN IMMEDIATE xaction
     instead of BEGIN EXCLUSIVE

Change-Id: I3ce55a8a7cba538f01f731736e7de8ae1e2a8a1f
2010-06-14 14:50:03 -07:00
Vasu Nori
49686ea3ed NPE in database corruption handler if attached database list is null
sometimes the database can be so corrupt that it cannot even be queried
for attached database list.

Change-Id: Ib8fe3bd94157acab3fbf1011c3f8a532ef5019f4
2010-06-10 17:40:01 -07:00
Brad Fitzpatrick
37d33a546b am 599f7287: am 9ac3743d: Merge "Log.wtf when databases go to be downgraded." into kraken 2010-06-08 12:40:57 -07:00
Brad Fitzpatrick
44dc76a8a7 Log.wtf when databases go to be downgraded.
BUG=2734435

Change-Id: I686d6d9415f3081544c3fbe379287c31e0ecec20
2010-06-08 12:20:51 -07:00
Tatsuo Nagamatsu
6d3acde839 fillWindow's start position must be smaller than getCount value
Change-Id: I3664ae8f6172f02bf6e2472320e79e3bf8683cc0
2010-06-07 02:07:51 +09:00
Vasu Nori
f9e2bd085f when database is opened, set journal_mode to TRAUNCATE
this journal_mode is more efficnent than the default journal_mode (DELETE)

Change-Id: I8879d3fe8dda410f4674ead9270aa7ecdaf91b5e
2010-06-04 17:08:31 -07:00
Brad Fitzpatrick
e407a608b0 resolved conflicts for merge of 7d6362de to master
Change-Id: Ic26dd6d617f0edba549c992256511613df00caa6
2010-06-03 17:15:48 -07:00
Vasu Nori
2134369e80 set some members to final, set database errorhandler to default if null.
Change-Id: I1c2d8181e7fe60c869178a43dcc00519dd0072c7
2010-06-03 16:01:39 -07:00
Brad Fitzpatrick
cfda9f3a47 Sprinkle new BlockGuard around SQLiteDatabase.
SQLite is JNI to native code and doesn't go via IFileSystem, so it
needs custom sprinkling, at least for now.

Change-Id: Ic7fded1b64a4f483dfc17b3a7b136c803df1e111
2010-06-03 12:52:54 -07:00
Vasu Nori
74f170f946 new API in Context. on openDatabase, new param DatabaseErrorHandler
add new method openOrCreateDatabase in Context.java to allow
callers specify a DatabaseErrorHandler object to be used when
database corruption occurs.
add new constructor in SQLiteOpenHelper to accept DatabaseErrorHandler
as an additional param to be used when SQLiteDatabase instance is
created.

Change-Id: I912a0202a74510f9ca0206dd8101c4abab9102ae
2010-06-03 12:38:11 -07:00
Vasu Nori
ac7ae9cc91 Merge "add API to Cursor to get column value type" 2010-06-03 11:46:03 -07:00
Vasu Nori
ccd954480c cleanup some small but ugly things. all minor things.
Change-Id: I6a3ea9ad563ea895e7f3c37647bdadd2cfa8fc29
2010-06-03 11:06:47 -07:00
Vasu Nori
8b0dd7da36 add API to Cursor to get column value type
Change-Id: I3ef1bcdb2eb1c45f68e829ccb6e3ecde28076591
2010-06-02 17:40:41 -07:00
Vasu Nori
a8c24904eb set sqlite pagesize to the size, in bytes, of a block on "/data"
Change-Id: I40b2bdac348a611eb9fe12ea05b6bd9a87f2310a
2010-06-01 13:03:32 -07:00
Vasu Nori
fea6f6dcb7 sqlite crashes when closing the database
A change was made in the last CL to ask sqlite for all unfinalized statements
and then finalizing them before closing the database.
But this crashes sqlite! because sqlite's FTS3
module keeps some prepared statements around and they should not
be finalized before closing the database.
(when sqlite is asked for all unfianlized statements, it also returns
the FTS3's reserved prepared statements which should not be
finalized!!)

Change-Id: I141ab4563985b8cd1305a1228c4cb01bc7281bcb
2010-05-21 15:41:58 -07:00
Vasu Nori
6f37f83a48 close() on anything other than database shouldn't acquire db lock.
bug:2683001
implmentation details:
 1.close() on any sql statement is should simply queued up for finalization
    to be performed later. caller doesn't acquire database lock.
 2. the only effect of NOT close immediately is non-release of some memory.
 3. all such queued-up-finalizations are performed whenever there is
    another execute() of some sql statement on that database from ANY
    thread in the process.
 4. database close() automatically releases all unfinalized statements
    before closing the database.

Change-Id: If4c9c7fde6b8945a41abc6c8b992aa8c69854512
2010-05-20 12:35:17 -07:00
Vasu Nori
85f08f9eae DatabaseCorruptionHandler causes NPE
it is trying to get attachedDb list (by executing a pragma) after closing
the database.
also added unittests.

Change-Id: I7dce665ec7354402cdef6fbe055455f5798e123c
2010-05-19 13:55:09 -07:00
Jeff Hamilton
7cd51efcbd Remove the deprecated cursor methods.
Change-Id: Ie3571fea9f36996c31c327240b11086f8cc487f0
2010-05-13 23:44:09 -05:00