Created
December 12, 2013 02:14
-
-
Save arvinboggs/7922214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package arvin; | |
import java.io.Closeable; | |
import java.io.IOException; | |
import java.net.InetSocketAddress; | |
import java.net.Socket; | |
import java.net.URLDecoder; | |
import java.util.Date; | |
import java.util.Locale; | |
import java.util.Map; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import fi.iki.elonen.NanoHTTPD; | |
import fi.iki.elonen.NanoHTTPD.Method; | |
import fi.iki.elonen.NanoHTTPD.Response; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteDatabase.CursorFactory; | |
import android.database.sqlite.SQLiteOpenHelper; | |
import android.util.Log; | |
import android.view.Menu; | |
import arvin.nanohttpdsqlite.R; | |
public class NanoHttpdSqliteActivity extends Activity { | |
final Activity MyActivity = this; | |
MySqliteHelper MySqlite; | |
MyNanoHTTPD MyNano; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// setContentView(R.layout.activity_nano_httpd_sqlite); // optional | |
MySqlite = new MySqliteHelper(); | |
MyNano = new MyNanoHTTPD(); | |
try { | |
MyNano.start(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
private class MyNanoHTTPD extends NanoHTTPD { | |
int mCount; | |
public MyNanoHTTPD() { | |
super(8888); | |
} | |
@Override | |
public Response serve(String uri, Method method, | |
Map<String, String> headers, Map<String, String> parms, | |
Map<String, String> files) { | |
try { | |
if (mCount == 0) | |
MySqlite.BeginTransaction(); | |
else | |
MySqlite.TestSelect(); | |
mCount++; | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return new Response("from MyNanoHTTPD"); | |
} | |
} // END private class MyNanoHTTPD | |
private class MySqliteHelper extends SQLiteOpenHelper implements Closeable { | |
private SQLiteDatabase mDB; | |
public MySqliteHelper() { | |
super(MyActivity, "MyDB.db", null, 1); | |
try { | |
mDB = this.getWritableDatabase(); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void onCreate(SQLiteDatabase arg0) { | |
// mandatory override. just do nothing here | |
} | |
@Override | |
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) { | |
// mandatory override. just do nothing here | |
} | |
public void BeginTransaction() { | |
mDB.beginTransaction(); | |
} | |
public void TestSelect() { | |
// breakpoint here | |
mDB.rawQuery("SELECT 1", null); | |
// code below will not execute | |
} | |
} | |
} // END public class NanoHttpdSqliteActivity extends Activity { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment