title: Android onUpgrade Database call of endTransaction causes illegalStateException
body: <p>Some while ago I posted this question: 
  <a href="https://stackoverflow.com/questions/13482781/android-onupgrade-database-causing-illegalstateexception">Android onUpgrade Database causing IllegalStateException</a></p>
  
  <p>the soultion was to stop and restart transaction in on db upgrade:</p>
  
  <pre><code>public void onUpgrade(SQLiteDatabase db,
          int oldVersion, int newVersion) {
  
  db.endTransaction();
  //updgading the db
  db.beginTransaction();
  }
  </code></pre>
  
  <p>This was working on my test system but now I get permanent error traces from my life system.
  Seems on most systems it is working, but on not one some.</p>
  
  <pre><code>java.lang.RuntimeException: An error occured while executing doInBackground()
  at android.os.AsyncTask$3.done(AsyncTask.java:278)
  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  at java.lang.Thread.run(Thread.java:856)
  Caused by: java.lang.IllegalStateException: no transaction pending
  at net.sqlcipher.database.SQLiteDatabase.endTransaction(SourceFile:640)
  at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SourceFile:128)
  at com.myApp.j.q(SourceFile:339) ...
  </code></pre>
  
  <p>what is wrong here?
  thanks tata</p>
  
  <p>edit: this is where the crash occurs.
  SQLiteOpenHelper.getWritableDatabase(SourceFile:128)</p>
  
  <pre><code>int version = db.getVersion();
              if (version != mNewVersion) {
                  db.beginTransaction();
                  try {
                      if (version == 0) {
                          onCreate(db);
                      } else {
                          onUpgrade(db, version, mNewVersion);
                      }
                      db.setVersion(mNewVersion);
                      db.setTransactionSuccessful();
                  } finally {
                      db.endTransaction(); //L. 128 crash
                  }
              }
  </code></pre>