Code example for SQLiteDatabase

Methods: compileStatementexecSQL

0
	private final SQLiteStatement myInsertPortsStatement;
	private final SQLiteStatement myDeletePortsStatement;
 
	SQLiteCookieDatabase(Context context) {
		myDatabase = context.getApplicationContext().openOrCreateDatabase("cookie.db", Context.MODE_PRIVATE, null);
		myDatabase.execSQL(
			"CREATE TABLE IF NOT EXISTS Cookie(" + 
				"cookie_id INTEGER PRIMARY KEY," + 
				"host TEXT NOT NULL," + 
				"path TEXT," + 
				"name TEXT NOT NULL," + 
				"value TEXT NOT NULL," + 
				"date_of_expiration INTEGER," + 
				"secure INTEGER," + 
				"CONSTRAINT Cookie_Unique UNIQUE(host,path,name))" 
		); 
		myDatabase.execSQL(
			"CREATE TABLE IF NOT EXISTS CookiePort(" + 
				"cookie_id INTEGER NOT NULL REFERENCES Cookie(cookie_id)," + 
				"port INTEGER NOT NULL," + 
				"CONSTRAINT CookiePort_Unique UNIQUE(cookie_id,port))" 
		); 
 
		myInsertStatement = myDatabase.compileStatement(
			"INSERT OR REPLACE INTO Cookie (host,path,name,value,date_of_expiration,secure) " + 
			"VALUES (?,?,?,?,?,?)" 
		); 
		myInsertPortsStatement = myDatabase.compileStatement(
			"INSERT OR IGNORE INTO CookiePort (cookie_id,port) VALUES (?,?)" 
		); 
		myDeletePortsStatement = myDatabase.compileStatement(
			"DELETE FROM CookiePort WHERE cookie_id = ?" 
		); 
 
		removeObsolete(new Date()); 
	} 
 
	@Override 
	protected void removeObsolete(Date date) { 
		final long time = date.getTime();
		myDatabase.execSQL(
			"DELETE FROM CookiePort WHERE cookie_id IN " + 
			"(SELECT cookie_id FROM Cookie WHERE date_of_expiration <= " + time + ")"
		); 
		myDatabase.execSQL(
			"DELETE FROM Cookie WHERE date_of_expiration <= " + time
		); 
	} 
 
	@Override