author | ffxbld |
Tue, 18 Oct 2016 06:07:00 -0700 (2016-10-18) | |
changeset 318318 | 01ab78dd98805e150b0311cce2351d5b408f3001 |
parent 316504 | 7914b9afee68281e449f0c709b2b5ac0760ee2d1 |
child 393698 | 0a9114d2b98858fc53e087428a467b6f568cc57b |
permissions | -rw-r--r-- |
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this file, |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
3 |
* You can obtain one at http://mozilla.org/MPL/2.0/. */ |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
4 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
5 |
package org.mozilla.gecko.db; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
6 |
|
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
7 |
import android.annotation.TargetApi; |
249825
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
8 |
import android.database.DatabaseUtils; |
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
9 |
import android.database.sqlite.SQLiteDatabase; |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
10 |
import android.database.sqlite.SQLiteStatement; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
11 |
import android.os.Build; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
12 |
import org.mozilla.gecko.AppConstants; |
92518
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
13 |
import org.mozilla.gecko.GeckoAppShell; |
223531
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
14 |
import org.mozilla.gecko.GeckoProfile; |
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
15 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
16 |
import android.content.ContentValues; |
194308
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
17 |
import android.database.Cursor; |
92518
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
18 |
import android.database.sqlite.SQLiteOpenHelper; |
223531
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
19 |
import android.net.Uri; |
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
20 |
import android.text.TextUtils; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
21 |
import android.util.Log; |
257208
11024b678090604c2f37a96e776855f1ef012f4d
Bug 1191872 - Move annotations to org.mozilla.gecko.annotation package, r=jchen
Mark Capella <markcapella@twcny.rr.com>
parents:
249825
diff
changeset
|
22 |
import org.mozilla.gecko.annotation.RobocopTarget; |
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
23 |
import org.mozilla.gecko.Telemetry; |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
24 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
25 |
import java.util.Map; |
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
26 |
|
99615
a0e708ee19528559cef4b5f6bdbea262fc17eecb
Backout 844444ca8feb (Bug 709230) r=bustage
Chris Peterson <cpeterson@mozilla.com>
parents:
99597
diff
changeset
|
27 |
public class DBUtils { |
92518
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
28 |
private static final String LOGTAG = "GeckoDBUtils"; |
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
29 |
|
293795
851f85403d6e4a419b09ec1334ab439ee0b4e2d3
Bug 1046709 - Part 2: CRUD for Visits - query/insert/delete; tests. r=nalexander,rnewman
Grigory Kruglov <gkruglov@mozilla.com>
parents:
292000
diff
changeset
|
30 |
public static final int SQLITE_MAX_VARIABLE_NUMBER = 999; |
851f85403d6e4a419b09ec1334ab439ee0b4e2d3
Bug 1046709 - Part 2: CRUD for Visits - query/insert/delete; tests. r=nalexander,rnewman
Grigory Kruglov <gkruglov@mozilla.com>
parents:
292000
diff
changeset
|
31 |
|
99615
a0e708ee19528559cef4b5f6bdbea262fc17eecb
Backout 844444ca8feb (Bug 709230) r=bustage
Chris Peterson <cpeterson@mozilla.com>
parents:
99597
diff
changeset
|
32 |
public static final String qualifyColumn(String table, String column) { |
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
33 |
return table + "." + column; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
34 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
35 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
36 |
// This is available in Android >= 11. Implemented locally to be |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
37 |
// compatible with older versions. |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
38 |
public static String concatenateWhere(String a, String b) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
39 |
if (TextUtils.isEmpty(a)) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
40 |
return b; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
41 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
42 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
43 |
if (TextUtils.isEmpty(b)) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
44 |
return a; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
45 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
46 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
47 |
return "(" + a + ") AND (" + b + ")"; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
48 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
49 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
50 |
// This is available in Android >= 11. Implemented locally to be |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
51 |
// compatible with older versions. |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
52 |
public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
53 |
if (originalValues == null || originalValues.length == 0) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
54 |
return newValues; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
55 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
56 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
57 |
if (newValues == null || newValues.length == 0) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
58 |
return originalValues; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
59 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
60 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
61 |
String[] result = new String[originalValues.length + newValues.length]; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
62 |
System.arraycopy(originalValues, 0, result, 0, originalValues.length); |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
63 |
System.arraycopy(newValues, 0, result, originalValues.length, newValues.length); |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
64 |
|
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
65 |
return result; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
66 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
67 |
|
286032
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
68 |
/** |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
69 |
* Concatenate multiple lists of selection arguments. <code>values</code> may be <code>null</code>. |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
70 |
*/ |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
71 |
public static String[] concatenateSelectionArgs(String[]... values) { |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
72 |
// Since we're most likely to be concatenating a few arrays of many values, it is most |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
73 |
// efficient to iterate over the arrays once to obtain their lengths, allowing us to create one target array |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
74 |
// (as opposed to copying arrays on every iteration, which would result in many more copies). |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
75 |
int totalLength = 0; |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
76 |
for (String[] v : values) { |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
77 |
if (v != null) { |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
78 |
totalLength += v.length; |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
79 |
} |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
80 |
} |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
81 |
|
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
82 |
String[] result = new String[totalLength]; |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
83 |
|
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
84 |
int position = 0; |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
85 |
for (String[] v: values) { |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
86 |
if (v != null) { |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
87 |
int currentLength = v.length; |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
88 |
System.arraycopy(v, 0, result, position, currentLength); |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
89 |
position += currentLength; |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
90 |
} |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
91 |
} |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
92 |
|
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
93 |
return result; |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
94 |
} |
f0d9ab6ffd64bd61e90dc2a13120df985c91c823
Bug 760956 - Part 1: Introduce variadic concatenateSelectionArgs r=rnewman
Andrzej Hunt <ahunt@mozilla.com>
parents:
275696
diff
changeset
|
95 |
|
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
96 |
public static void replaceKey(ContentValues aValues, String aOriginalKey, |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
97 |
String aNewKey, String aDefault) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
98 |
String value = aDefault; |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
99 |
if (aOriginalKey != null && aValues.containsKey(aOriginalKey)) { |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
100 |
value = aValues.get(aOriginalKey).toString(); |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
101 |
aValues.remove(aOriginalKey); |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
102 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
103 |
|
88837
9d643d069d11d68546f2fac0c91210408b711be0
Bug 718760 - Crypto for the java passwords provider. r=blassey,bsmith
Wes Johnston <wjohnston@mozilla.com>
parents:
88835
diff
changeset
|
104 |
if (!aValues.containsKey(aNewKey)) { |
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
105 |
aValues.put(aNewKey, value); |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
106 |
} |
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
107 |
} |
92518
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
108 |
|
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
109 |
private static String HISTOGRAM_DATABASE_LOCKED = "DATABASE_LOCKED_EXCEPTION"; |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
110 |
private static String HISTOGRAM_DATABASE_UNLOCKED = "DATABASE_SUCCESSFUL_UNLOCK"; |
92518
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
111 |
public static void ensureDatabaseIsNotLocked(SQLiteOpenHelper dbHelper, String databasePath) { |
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
112 |
final int maxAttempts = 5; |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
113 |
int attempt = 0; |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
114 |
SQLiteDatabase db = null; |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
115 |
for (; attempt < maxAttempts; attempt++) { |
122475
b79b4213e3b2921a90ff9e3b0d3d8e36ee4aead6
Bug 843029 - Add more retries to ensureDatabaseIsNotLocked r=blassey r=lucasr
Mark Finkle <mfinkle@mozilla.com>
parents:
99615
diff
changeset
|
116 |
try { |
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
117 |
// Try a simple test and exit the loop. |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
118 |
db = dbHelper.getWritableDatabase(); |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
119 |
break; |
122475
b79b4213e3b2921a90ff9e3b0d3d8e36ee4aead6
Bug 843029 - Add more retries to ensureDatabaseIsNotLocked r=blassey r=lucasr
Mark Finkle <mfinkle@mozilla.com>
parents:
99615
diff
changeset
|
120 |
} catch (Exception e) { |
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
121 |
// We assume that this is a android.database.sqlite.SQLiteDatabaseLockedException. |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
122 |
// That class is only available on API 11+. |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
123 |
Telemetry.addToHistogram(HISTOGRAM_DATABASE_LOCKED, attempt); |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
124 |
|
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
125 |
// Things could get very bad if we don't find a way to unlock the DB. |
122475
b79b4213e3b2921a90ff9e3b0d3d8e36ee4aead6
Bug 843029 - Add more retries to ensureDatabaseIsNotLocked r=blassey r=lucasr
Mark Finkle <mfinkle@mozilla.com>
parents:
99615
diff
changeset
|
126 |
Log.d(LOGTAG, "Database is locked, trying to kill any zombie processes: " + databasePath); |
b79b4213e3b2921a90ff9e3b0d3d8e36ee4aead6
Bug 843029 - Add more retries to ensureDatabaseIsNotLocked r=blassey r=lucasr
Mark Finkle <mfinkle@mozilla.com>
parents:
99615
diff
changeset
|
127 |
GeckoAppShell.killAnyZombies(); |
b79b4213e3b2921a90ff9e3b0d3d8e36ee4aead6
Bug 843029 - Add more retries to ensureDatabaseIsNotLocked r=blassey r=lucasr
Mark Finkle <mfinkle@mozilla.com>
parents:
99615
diff
changeset
|
128 |
try { |
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
129 |
Thread.sleep(attempt * 100); |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
130 |
} catch (InterruptedException ie) { |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
131 |
} |
122475
b79b4213e3b2921a90ff9e3b0d3d8e36ee4aead6
Bug 843029 - Add more retries to ensureDatabaseIsNotLocked r=blassey r=lucasr
Mark Finkle <mfinkle@mozilla.com>
parents:
99615
diff
changeset
|
132 |
} |
92518
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
133 |
} |
221192
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
134 |
|
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
135 |
if (db == null) { |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
136 |
Log.w(LOGTAG, "Failed to unlock database."); |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
137 |
GeckoAppShell.listOfOpenFiles(); |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
138 |
return; |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
139 |
} |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
140 |
|
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
141 |
// If we needed to retry, but we succeeded, report that in telemetry. |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
142 |
// Failures are indicated by a lower frequency of UNLOCKED than LOCKED. |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
143 |
if (attempt > 1) { |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
144 |
Telemetry.addToHistogram(HISTOGRAM_DATABASE_UNLOCKED, attempt - 1); |
6441c30a1317a3a5f20d0011a826168ba127503d
Bug 1115075 - Part 1: add telemetry for DBUtils.ensureDatabaseIsNotLocked. r=mfinkle
Richard Newman <rnewman@mozilla.com>
parents:
194308
diff
changeset
|
145 |
} |
92518
e2e9bb4029fd92156990553c680cd8fee3d769e8
Bug 741224 - Move database unlock function to DBUtils (r=blassey)
Lucas Rocha <lucasr@mozilla.com>
parents:
88837
diff
changeset
|
146 |
} |
168801
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
147 |
|
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
148 |
/** |
249825
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
149 |
* Copies a table <b>between</b> database files. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
150 |
* |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
151 |
* This method assumes that the source table and destination table already exist in the |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
152 |
* source and destination databases, respectively. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
153 |
* |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
154 |
* The table is copied row-by-row in a single transaction. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
155 |
* |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
156 |
* @param source The source database that the table will be copied from. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
157 |
* @param sourceTableName The name of the source table. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
158 |
* @param destination The destination database that the table will be copied to. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
159 |
* @param destinationTableName The name of the destination table. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
160 |
* @return true if all rows were copied; false otherwise. |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
161 |
*/ |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
162 |
public static boolean copyTable(SQLiteDatabase source, String sourceTableName, |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
163 |
SQLiteDatabase destination, String destinationTableName) { |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
164 |
Cursor cursor = null; |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
165 |
try { |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
166 |
destination.beginTransaction(); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
167 |
|
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
168 |
cursor = source.query(sourceTableName, null, null, null, null, null, null); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
169 |
Log.d(LOGTAG, "Trying to copy " + cursor.getCount() + " rows from " + sourceTableName + " to " + destinationTableName); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
170 |
|
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
171 |
final ContentValues contentValues = new ContentValues(); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
172 |
while (cursor.moveToNext()) { |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
173 |
contentValues.clear(); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
174 |
DatabaseUtils.cursorRowToContentValues(cursor, contentValues); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
175 |
destination.insert(destinationTableName, null, contentValues); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
176 |
} |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
177 |
|
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
178 |
destination.setTransactionSuccessful(); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
179 |
Log.d(LOGTAG, "Successfully copied " + cursor.getCount() + " rows from " + sourceTableName + " to " + destinationTableName); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
180 |
return true; |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
181 |
} catch (Exception e) { |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
182 |
Log.w(LOGTAG, "Got exception copying rows from " + sourceTableName + " to " + destinationTableName + "; ignoring.", e); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
183 |
return false; |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
184 |
} finally { |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
185 |
destination.endTransaction(); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
186 |
if (cursor != null) { |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
187 |
cursor.close(); |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
188 |
} |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
189 |
} |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
190 |
} |
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
191 |
|
6b80a1818bf1c0a88015471a36d6d0bb27248ebc
Bug 1172077 - Merge tabs.db into browser.db. r=nalexander a=KWierso
Ahmed Khalil <ahmedibrahimkhali>
parents:
238878
diff
changeset
|
192 |
/** |
168801
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
193 |
* Verifies that 0-byte arrays aren't added as favicon or thumbnail data. |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
194 |
* @param values ContentValues of query |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
195 |
* @param columnName Name of data column to verify |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
196 |
*/ |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
197 |
public static void stripEmptyByteArray(ContentValues values, String columnName) { |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
198 |
if (values.containsKey(columnName)) { |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
199 |
byte[] data = values.getAsByteArray(columnName); |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
200 |
if (data == null || data.length == 0) { |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
201 |
Log.w(LOGTAG, "Tried to insert an empty or non-byte-array image. Ignoring."); |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
202 |
values.putNull(columnName); |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
203 |
} |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
204 |
} |
02e2d24da0bd71108977e8768dd43c669e2edb80
Bug 961238 - Make an abstract ContentProvider class. r=margaret
Sola Ogunsakin <oogunsakin@mozilla.com>
parents:
168334
diff
changeset
|
205 |
} |
194308
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
206 |
|
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
207 |
/** |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
208 |
* Builds a selection string that searches for a list of arguments in a particular column. |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
209 |
* For example URL in (?,?,?). Callers should pass the actual arguments into their query |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
210 |
* as selection args. |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
211 |
* @para columnName The column to search in |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
212 |
* @para size The number of arguments to search for |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
213 |
*/ |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
214 |
public static String computeSQLInClause(int items, String field) { |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
215 |
final StringBuilder builder = new StringBuilder(field); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
216 |
builder.append(" IN ("); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
217 |
int i = 0; |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
218 |
for (; i < items - 1; ++i) { |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
219 |
builder.append("?, "); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
220 |
} |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
221 |
if (i < items) { |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
222 |
builder.append("?"); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
223 |
} |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
224 |
builder.append(")"); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
225 |
return builder.toString(); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
226 |
} |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
227 |
|
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
228 |
/** |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
229 |
* Turn a single-column cursor of longs into a single SQL "IN" clause. |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
230 |
* We can do this without using selection arguments because Long isn't |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
231 |
* vulnerable to injection. |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
232 |
*/ |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
233 |
public static String computeSQLInClauseFromLongs(final Cursor cursor, String field) { |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
234 |
final StringBuilder builder = new StringBuilder(field); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
235 |
builder.append(" IN ("); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
236 |
final int commaLimit = cursor.getCount() - 1; |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
237 |
int i = 0; |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
238 |
while (cursor.moveToNext()) { |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
239 |
builder.append(cursor.getLong(0)); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
240 |
if (i++ < commaLimit) { |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
241 |
builder.append(", "); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
242 |
} |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
243 |
} |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
244 |
builder.append(")"); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
245 |
return builder.toString(); |
0814bb0f08d097ee4eb0bd7b2e5794357f76c766
Bug 1014712 - Store ms tile image information for showing on about:home. r=rnewman,lucasr
Wes Johnston <wjohnston@mozilla.com>
parents:
168801
diff
changeset
|
246 |
} |
223531
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
247 |
|
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
248 |
public static Uri appendProfile(final String profile, final Uri uri) { |
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
249 |
return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, profile).build(); |
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
250 |
} |
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
251 |
|
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
252 |
public static Uri appendProfileWithDefault(final String profile, final Uri uri) { |
292000
1c0b058b86beb6c7543f0d13073d747243e792a1
Bug 1247469 - Fix testFilterOpenTab; r=me
Jim Chen <nchen@mozilla.com>
parents:
286032
diff
changeset
|
253 |
if (profile == null) { |
223531
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
254 |
return appendProfile(GeckoProfile.DEFAULT_PROFILE, uri); |
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
255 |
} |
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
256 |
return appendProfile(profile, uri); |
3fc5da45d29e8bc823395b289c82a69000dffb1a
Bug 1077590 - Part 1: make all per-profile DB access go through a profile. r=wesj
Richard Newman <rnewman@mozilla.com>
parents:
223283
diff
changeset
|
257 |
} |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
258 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
259 |
/** |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
260 |
* Use the following when no conflict action is specified. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
261 |
*/ |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
262 |
private static final int CONFLICT_NONE = 0; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
263 |
private static final String[] CONFLICT_VALUES = new String[] {"", " OR ROLLBACK ", " OR ABORT ", " OR FAIL ", " OR IGNORE ", " OR REPLACE "}; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
264 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
265 |
/** |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
266 |
* Convenience method for updating rows in the database. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
267 |
* |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
268 |
* @param table the table to update in |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
269 |
* @param values a map from column names to new column values. null is a |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
270 |
* valid value that will be translated to NULL. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
271 |
* @param whereClause the optional WHERE clause to apply when updating. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
272 |
* Passing null will update all rows. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
273 |
* @param whereArgs You may include ?s in the where clause, which |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
274 |
* will be replaced by the values from whereArgs. The values |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
275 |
* will be bound as Strings. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
276 |
* @return the number of rows affected |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
277 |
*/ |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
278 |
@RobocopTarget |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
279 |
public static int updateArrays(SQLiteDatabase db, String table, ContentValues[] values, UpdateOperation[] ops, String whereClause, String[] whereArgs) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
280 |
return updateArraysWithOnConflict(db, table, values, ops, whereClause, whereArgs, CONFLICT_NONE, true); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
281 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
282 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
283 |
public static void updateArraysBlindly(SQLiteDatabase db, String table, ContentValues[] values, UpdateOperation[] ops, String whereClause, String[] whereArgs) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
284 |
updateArraysWithOnConflict(db, table, values, ops, whereClause, whereArgs, CONFLICT_NONE, false); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
285 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
286 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
287 |
@RobocopTarget |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
288 |
public enum UpdateOperation { |
238878
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
289 |
/** |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
290 |
* ASSIGN is the usual update: replaces the value in the named column with the provided value. |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
291 |
* |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
292 |
* foo = ? |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
293 |
*/ |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
294 |
ASSIGN, |
238878
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
295 |
|
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
296 |
/** |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
297 |
* BITWISE_OR applies the provided value to the existing value with a bitwise OR. This is useful for adding to flags. |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
298 |
* |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
299 |
* foo |= ? |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
300 |
*/ |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
301 |
BITWISE_OR, |
238878
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
302 |
|
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
303 |
/** |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
304 |
* EXPRESSION is an end-run around the API: it allows callers to specify a fragment of SQL to splice into the |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
305 |
* SET part of the query. |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
306 |
* |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
307 |
* foo = $value |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
308 |
* |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
309 |
* Be very careful not to use user input in this. |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
310 |
*/ |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
311 |
EXPRESSION, |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
312 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
313 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
314 |
/** |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
315 |
* This is an evil reimplementation of SQLiteDatabase's methods to allow for |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
316 |
* smarter updating. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
317 |
* |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
318 |
* Each ContentValues has an associated enum that describes how to unify input values with the existing column values. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
319 |
*/ |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
320 |
private static int updateArraysWithOnConflict(SQLiteDatabase db, String table, |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
321 |
ContentValues[] values, |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
322 |
UpdateOperation[] ops, |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
323 |
String whereClause, |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
324 |
String[] whereArgs, |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
325 |
int conflictAlgorithm, |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
326 |
boolean returnChangedRows) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
327 |
if (values == null || values.length == 0) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
328 |
throw new IllegalArgumentException("Empty values"); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
329 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
330 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
331 |
if (ops == null || ops.length != values.length) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
332 |
throw new IllegalArgumentException("ops and values don't match"); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
333 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
334 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
335 |
StringBuilder sql = new StringBuilder(120); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
336 |
sql.append("UPDATE "); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
337 |
sql.append(CONFLICT_VALUES[conflictAlgorithm]); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
338 |
sql.append(table); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
339 |
sql.append(" SET "); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
340 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
341 |
// move all bind args to one array |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
342 |
int setValuesSize = 0; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
343 |
for (int i = 0; i < values.length; i++) { |
238878
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
344 |
// EXPRESSION types don't contribute any placeholders. |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
345 |
if (ops[i] != UpdateOperation.EXPRESSION) { |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
346 |
setValuesSize += values[i].size(); |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
347 |
} |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
348 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
349 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
350 |
int bindArgsSize = (whereArgs == null) ? setValuesSize : (setValuesSize + whereArgs.length); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
351 |
Object[] bindArgs = new Object[bindArgsSize]; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
352 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
353 |
int arg = 0; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
354 |
for (int i = 0; i < values.length; i++) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
355 |
final ContentValues v = values[i]; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
356 |
final UpdateOperation op = ops[i]; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
357 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
358 |
// Alas, code duplication. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
359 |
switch (op) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
360 |
case ASSIGN: |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
361 |
for (Map.Entry<String, Object> entry : v.valueSet()) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
362 |
final String colName = entry.getKey(); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
363 |
sql.append((arg > 0) ? "," : ""); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
364 |
sql.append(colName); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
365 |
bindArgs[arg++] = entry.getValue(); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
366 |
sql.append("= ?"); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
367 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
368 |
break; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
369 |
case BITWISE_OR: |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
370 |
for (Map.Entry<String, Object> entry : v.valueSet()) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
371 |
final String colName = entry.getKey(); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
372 |
sql.append((arg > 0) ? "," : ""); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
373 |
sql.append(colName); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
374 |
bindArgs[arg++] = entry.getValue(); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
375 |
sql.append("= ? | "); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
376 |
sql.append(colName); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
377 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
378 |
break; |
238878
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
379 |
case EXPRESSION: |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
380 |
// Treat each value as a literal SQL string. |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
381 |
for (Map.Entry<String, Object> entry : v.valueSet()) { |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
382 |
final String colName = entry.getKey(); |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
383 |
sql.append((arg > 0) ? "," : ""); |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
384 |
sql.append(colName); |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
385 |
sql.append(" = "); |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
386 |
sql.append(entry.getValue()); |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
387 |
} |
87ffd97560378f8e97d6c6cce25b6cfa1bea04d3
Bug 1153357 - Don't set SYNC_STATUS_MODIFIED unless an update touches fields that we sync. r=nalexander
Richard Newman <rnewman@mozilla.com>
parents:
230061
diff
changeset
|
388 |
break; |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
389 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
390 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
391 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
392 |
if (whereArgs != null) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
393 |
for (arg = setValuesSize; arg < bindArgsSize; arg++) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
394 |
bindArgs[arg] = whereArgs[arg - setValuesSize]; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
395 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
396 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
397 |
if (!TextUtils.isEmpty(whereClause)) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
398 |
sql.append(" WHERE "); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
399 |
sql.append(whereClause); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
400 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
401 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
402 |
// What a huge pain in the ass, all because SQLiteDatabase doesn't expose .executeSql, |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
403 |
// and we can't get a DB handle. Nor can we easily construct a statement with arguments |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
404 |
// already bound. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
405 |
final SQLiteStatement statement = db.compileStatement(sql.toString()); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
406 |
try { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
407 |
bindAllArgs(statement, bindArgs); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
408 |
if (!returnChangedRows) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
409 |
statement.execute(); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
410 |
return 0; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
411 |
} |
316504
7914b9afee68281e449f0c709b2b5ac0760ee2d1
Bug 1261041 - Remove feature11Plus-feature15Plus flags. r=sebastian
Tushar Saini (:shatur) <tushar.saini1285@gmail.com>
parents:
293795
diff
changeset
|
412 |
// This is a separate method so we can annotate it with @TargetApi. |
7914b9afee68281e449f0c709b2b5ac0760ee2d1
Bug 1261041 - Remove feature11Plus-feature15Plus flags. r=sebastian
Tushar Saini (:shatur) <tushar.saini1285@gmail.com>
parents:
293795
diff
changeset
|
413 |
return executeStatementReturningChangedRows(statement); |
230061
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
414 |
} finally { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
415 |
statement.close(); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
416 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
417 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
418 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
419 |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
420 |
private static int executeStatementReturningChangedRows(SQLiteStatement statement) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
421 |
return statement.executeUpdateDelete(); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
422 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
423 |
|
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
424 |
// All because {@link SQLiteProgram#bind(integer, Object)} is private. |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
425 |
private static void bindAllArgs(SQLiteStatement statement, Object[] bindArgs) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
426 |
if (bindArgs == null) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
427 |
return; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
428 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
429 |
for (int i = bindArgs.length; i != 0; i--) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
430 |
Object v = bindArgs[i - 1]; |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
431 |
if (v == null) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
432 |
statement.bindNull(i); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
433 |
} else if (v instanceof String) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
434 |
statement.bindString(i, (String) v); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
435 |
} else if (v instanceof Double) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
436 |
statement.bindDouble(i, (Double) v); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
437 |
} else if (v instanceof Float) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
438 |
statement.bindDouble(i, (Float) v); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
439 |
} else if (v instanceof Long) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
440 |
statement.bindLong(i, (Long) v); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
441 |
} else if (v instanceof Integer) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
442 |
statement.bindLong(i, (Integer) v); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
443 |
} else if (v instanceof Byte) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
444 |
statement.bindLong(i, (Byte) v); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
445 |
} else if (v instanceof byte[]) { |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
446 |
statement.bindBlob(i, (byte[]) v); |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
447 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
448 |
} |
821a440f3d4b9895672805012fc02d272c1fe1af
Bug 1135086 - Implement in-place computed UPDATE in DBUtils. r=margaret
Richard Newman <rnewman@mozilla.com>
parents:
223531
diff
changeset
|
449 |
} |
86535
85346ae0ea9942f1ac9cff829f2f588fd8deff19
Bug 704682 - Add passwords content provider. r=blassey,gpascutto
Wes Johnston <wjohnston@mozilla.com>
parents:
diff
changeset
|
450 |
} |