@@ -58,6 +58,11 @@ public abstract class SQLiteProgram extends SQLiteClosable {
5858 @ Deprecated
5959 protected long nStatement = 0 ;
6060
61+ /**
62+ * Indicates whether {@link #close()} has been called.
63+ */
64+ boolean mClosed = false ;
65+
6166 /* package */ SQLiteProgram (SQLiteDatabase db , String sql ) {
6267 mDatabase = db ;
6368 mSql = sql .trim ();
@@ -142,7 +147,7 @@ private void releaseCompiledSqlIfNotInCache() {
142147 // it is in compiled-sql cache. reset its CompiledSql#mInUse flag
143148 mCompiledSql .release ();
144149 }
145- }
150+ }
146151 }
147152
148153 /**
@@ -177,6 +182,9 @@ protected void compile(String sql, boolean forceCompilation) {
177182 * @param index The 1-based index to the parameter to bind null to
178183 */
179184 public void bindNull (int index ) {
185+ if (mClosed ) {
186+ throw new IllegalStateException ("program already closed" );
187+ }
180188 if (!mDatabase .isOpen ()) {
181189 throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
182190 }
@@ -196,6 +204,9 @@ public void bindNull(int index) {
196204 * @param value The value to bind
197205 */
198206 public void bindLong (int index , long value ) {
207+ if (mClosed ) {
208+ throw new IllegalStateException ("program already closed" );
209+ }
199210 if (!mDatabase .isOpen ()) {
200211 throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
201212 }
@@ -215,6 +226,9 @@ public void bindLong(int index, long value) {
215226 * @param value The value to bind
216227 */
217228 public void bindDouble (int index , double value ) {
229+ if (mClosed ) {
230+ throw new IllegalStateException ("program already closed" );
231+ }
218232 if (!mDatabase .isOpen ()) {
219233 throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
220234 }
@@ -237,6 +251,9 @@ public void bindString(int index, String value) {
237251 if (value == null ) {
238252 throw new IllegalArgumentException ("the bind value at index " + index + " is null" );
239253 }
254+ if (mClosed ) {
255+ throw new IllegalStateException ("program already closed" );
256+ }
240257 if (!mDatabase .isOpen ()) {
241258 throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
242259 }
@@ -259,6 +276,9 @@ public void bindBlob(int index, byte[] value) {
259276 if (value == null ) {
260277 throw new IllegalArgumentException ("the bind value at index " + index + " is null" );
261278 }
279+ if (mClosed ) {
280+ throw new IllegalStateException ("program already closed" );
281+ }
262282 if (!mDatabase .isOpen ()) {
263283 throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
264284 }
@@ -274,6 +294,9 @@ public void bindBlob(int index, byte[] value) {
274294 * Clears all existing bindings. Unset bindings are treated as NULL.
275295 */
276296 public void clearBindings () {
297+ if (mClosed ) {
298+ throw new IllegalStateException ("program already closed" );
299+ }
277300 if (!mDatabase .isOpen ()) {
278301 throw new IllegalStateException ("database " + mDatabase .getPath () + " already closed" );
279302 }
@@ -289,6 +312,9 @@ public void clearBindings() {
289312 * Release this program's resources, making it invalid.
290313 */
291314 public void close () {
315+ if (mClosed ) {
316+ return ;
317+ }
292318 if (!mDatabase .isOpen ()) {
293319 return ;
294320 }
@@ -298,6 +324,7 @@ public void close() {
298324 } finally {
299325 mDatabase .unlock ();
300326 }
327+ mClosed = true ;
301328 }
302329
303330 /**
0 commit comments