@@ -58,6 +58,11 @@ public abstract class SQLiteProgram extends SQLiteClosable {
58
58
@ Deprecated
59
59
protected long nStatement = 0 ;
60
60
61
+ /**
62
+ * Indicates whether {@link #close()} has been called.
63
+ */
64
+ boolean mClosed = false ;
65
+
61
66
/* package */ SQLiteProgram (SQLiteDatabase db , String sql ) {
62
67
mDatabase = db ;
63
68
mSql = sql .trim ();
@@ -142,7 +147,7 @@ private void releaseCompiledSqlIfNotInCache() {
142
147
// it is in compiled-sql cache. reset its CompiledSql#mInUse flag
143
148
mCompiledSql .release ();
144
149
}
145
- }
150
+ }
146
151
}
147
152
148
153
/**
@@ -177,6 +182,9 @@ protected void compile(String sql, boolean forceCompilation) {
177
182
* @param index The 1-based index to the parameter to bind null to
178
183
*/
179
184
public void bindNull (int index ) {
185
+ if (mClosed ) {
186
+ throw new IllegalStateException ("program already closed" );
187
+ }
180
188
if (!mDatabase .isOpen ()) {
181
189
throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
182
190
}
@@ -196,6 +204,9 @@ public void bindNull(int index) {
196
204
* @param value The value to bind
197
205
*/
198
206
public void bindLong (int index , long value ) {
207
+ if (mClosed ) {
208
+ throw new IllegalStateException ("program already closed" );
209
+ }
199
210
if (!mDatabase .isOpen ()) {
200
211
throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
201
212
}
@@ -215,6 +226,9 @@ public void bindLong(int index, long value) {
215
226
* @param value The value to bind
216
227
*/
217
228
public void bindDouble (int index , double value ) {
229
+ if (mClosed ) {
230
+ throw new IllegalStateException ("program already closed" );
231
+ }
218
232
if (!mDatabase .isOpen ()) {
219
233
throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
220
234
}
@@ -237,6 +251,9 @@ public void bindString(int index, String value) {
237
251
if (value == null ) {
238
252
throw new IllegalArgumentException ("the bind value at index " + index + " is null" );
239
253
}
254
+ if (mClosed ) {
255
+ throw new IllegalStateException ("program already closed" );
256
+ }
240
257
if (!mDatabase .isOpen ()) {
241
258
throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
242
259
}
@@ -259,6 +276,9 @@ public void bindBlob(int index, byte[] value) {
259
276
if (value == null) {
260
277
throw new IllegalArgumentException ("the bind value at index " + index + " is null" );
261
278
}
279
+ if (mClosed ) {
280
+ throw new IllegalStateException ("program already closed" );
281
+ }
262
282
if (!mDatabase .isOpen ()) {
263
283
throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
264
284
}
@@ -274,6 +294,9 @@ public void bindBlob(int index, byte[] value) {
274
294
* Clears all existing bindings. Unset bindings are treated as NULL.
275
295
*/
276
296
public void clearBindings () {
297
+ if (mClosed ) {
298
+ throw new IllegalStateException ("program already closed" );
299
+ }
277
300
if (!mDatabase .isOpen ()) {
278
301
throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
279
302
}
@@ -289,6 +312,9 @@ public void clearBindings() {
289
312
* Release this program's resources, making it invalid.
290
313
*/
291
314
public void close () {
315
+ if (mClosed ) {
316
+ return ;
317
+ }
292
318
if (!mDatabase .isOpen ()) {
293
319
return ;
294
320
}
@@ -298,6 +324,7 @@ public void close() {
298
324
} finally {
299
325
mDatabase .unlock ();
300
326
}
327
+ mClosed = true ;
301
328
}
302
329
303
330
/**
0 commit comments