title: How to execute a query with IF and ELSE in Android sqlite?
body: <p>I'm programming a method insertOrUpdate in my android application and I can't do this:</p>
  
  <pre><code>database.execSQL('IF (select count(*) from RegNascimento where codigoAnimal = ?) &gt; 0 then begin update RegNascimento set cgnRegNascimento = ? where codigoAnimal = ?; end else begin insert into RegNascimento(cgnRegNascimento, dataInspecaoRegNascimento) values (?,?); end;');
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>06-26 09:24:58.835: E/SQLiteLog(3924): (1) near "if": syntax error
  06-26 09:24:58.835: W/System.err(3924): android.database.sqlite.SQLiteException: near "if": syntax error (code 1): , while compiling: if (select count(*) from RegDefinitivo where codigoAnimal = ?) &gt; 0 then begin update RegDefinitivo set cgdRegDefinitivo = ?, seloRegDefinitivo = ? where codigoAnimal = ?; end else begin insert into RegDefinitivo(cgdRegDefinitivo, seloRegDefinitivo, dataInspecaoRegDefinitivo) values (?,?,?); end;
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1013)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:624)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
  06-26 09:24:58.835: W/System.err(3924):     at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
  06-26 09:24:58.840: W/System.err(3924):     at org.apache.cordova.Storage.executeSql(Storage.java:173)
  06-26 09:24:58.840: W/System.err(3924):     at org.apache.cordova.Storage.execute(Storage.java:83)
  06-26 09:24:58.840: W/System.err(3924):     at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:66)
  06-26 09:24:58.840: W/System.err(3924):     at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
  06-26 09:24:58.840: W/System.err(3924):     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:51)
  06-26 09:24:58.840: W/System.err(3924):     at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
  06-26 09:24:58.840: W/System.err(3924):     at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
  06-26 09:24:58.840: W/System.err(3924):     at android.webkit.JWebCoreJavaBridge.fireSharedTimer(JWebCoreJavaBridge.java:92)
  06-26 09:24:58.840: W/System.err(3924):     at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:108)
  06-26 09:24:58.840: W/System.err(3924):     at android.os.Handler.dispatchMessage(Handler.java:99)
  06-26 09:24:58.840: W/System.err(3924):     at android.os.Looper.loop(Looper.java:137)
  06-26 09:24:58.840: W/System.err(3924):     at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:1064)
  06-26 09:24:58.840: W/System.err(3924):     at java.lang.Thread.run(Thread.java:856)
  </code></pre>
  
  <p>PS: I'm using sencha touch, but the sql is being executed in android via plugin.
  Thanks</p>