Skip to content

Commit cd681ad

Browse files
committed
Merge branch 'master' of ssh://git.zetetic.net/sqlcipher-android
2 parents 99c48d5 + badfe79 commit cd681ad

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher_cts/SupportHelperTest.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void shouldCreateDatabaseNormallyWithInitialVersion() {
4848
}
4949

5050
@Test
51-
public void shouldRunUpgradeFromVersion1ToVersion2() {
51+
public void shouldRunUpgradeFromVersion1ToVersion2WhenMinSupportedVersionIsProvided() {
5252
FakeCallback initialCallback = new FakeCallback(1);
5353

5454
SupportHelper initialHelper = new SupportHelper(createConfiguration(initialCallback), null, null, true);
@@ -71,6 +71,29 @@ public void shouldRunUpgradeFromVersion1ToVersion2() {
7171
assertEquals(1, callbackWrapper.callbackCount[UPGRADE_INDEX]);
7272
}
7373

74+
@Test
75+
public void shouldRunUpgradeFromVersion1ToVersion2() {
76+
FakeCallback initialCallback = new FakeCallback(1);
77+
78+
SupportHelper initialHelper = new SupportHelper(createConfiguration(initialCallback), null, null, true);
79+
80+
initialHelper.getWritableDatabase();
81+
initialHelper.close();
82+
83+
assertEquals(1, initialCallback.callbackCount[CREATION_INDEX]);
84+
assertEquals(0, initialCallback.callbackCount[UPGRADE_INDEX]);
85+
86+
FakeCallback callbackWrapper = new FakeCallback(2);
87+
88+
SupportHelper helper = new SupportHelper(createConfiguration(callbackWrapper), null, null, true);
89+
90+
helper.getWritableDatabase();
91+
helper.close();
92+
93+
assertEquals(0, callbackWrapper.callbackCount[CREATION_INDEX]);
94+
assertEquals(1, callbackWrapper.callbackCount[UPGRADE_INDEX]);
95+
}
96+
7497
private SupportSQLiteOpenHelper.Configuration createConfiguration(SupportSQLiteOpenHelper.Callback callback) {
7598
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
7699
return SupportSQLiteOpenHelper.Configuration.builder(context)

sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteDatabase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ public long insert(String table, String nullColumnHack, ContentValues values) {
16341634
try {
16351635
return insertWithOnConflict(table, nullColumnHack, values, CONFLICT_NONE);
16361636
} catch (SQLException e) {
1637-
Log.e(TAG, "Error inserting " + values, e);
1637+
Log.e(TAG, "Error inserting", e);
16381638
return -1;
16391639
}
16401640
}
@@ -1682,7 +1682,7 @@ public long replace(String table, String nullColumnHack, ContentValues initialVa
16821682
return insertWithOnConflict(table, nullColumnHack, initialValues,
16831683
CONFLICT_REPLACE);
16841684
} catch (SQLException e) {
1685-
Log.e(TAG, "Error inserting " + initialValues, e);
1685+
Log.e(TAG, "Error inserting", e);
16861686
return -1;
16871687
}
16881688
}

sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SupportHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class SupportHelper implements SupportSQLiteOpenHelper {
1010

1111
public SupportHelper(final Configuration configuration, byte[] password, SQLiteDatabaseHook hook,
1212
boolean enableWriteAheadLogging) {
13-
this(configuration, password, hook, enableWriteAheadLogging, configuration.callback.version);
13+
this(configuration, password, hook, enableWriteAheadLogging, 0);
1414
}
1515

1616
public SupportHelper(final Configuration configuration, byte[] password, SQLiteDatabaseHook hook,

0 commit comments

Comments
 (0)