SQLiteDatabase compileStatement - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SQLiteDatabase compileStatement method.

This code example shows how to use the following methods:close, beginTransaction, compileStatement, endTransaction, isOpen
	} 
 
	public DataManager(Context context, boolean useDebugDb) {
		this.context = context;
		this.useDebugDb = useDebugDb;
	} 
 
	private boolean isOpenDb() { 
		return (db != null && db.isOpen());
	} 
 
	private boolean closeDb() { 
		if (isOpenDb()) { 
			try { 
				db.close();
				 
				db = null;
				rpgCharacterDao = null;
				 
				return true; 

7
CodeRank
This code example shows how to use the following methods:compileStatement, execSQL
		String sql = "SELECT in1,in2,ideal1 FROM xor ORDER BY rowid";
		String dbName = "encog-test.db";
		AndroidSqliteCODEC androidCodec = new AndroidSqliteCODEC(this.getContext(), dbName, sql, 2, 1);
		SQLiteDatabase db = androidCodec.getDatabase();
		 
		db.execSQL("delete from xor");
		 
		SQLiteStatement insertStmt = db.compileStatement("INSERT INTO xor(in1,in2,ideal1) VALUES(0,0,0)");
		insertStmt.executeInsert();
		insertStmt = db.compileStatement("INSERT INTO xor(in1,in2,ideal1) VALUES(1,0,1)");
		insertStmt.executeInsert();
		insertStmt = db.compileStatement("INSERT INTO xor(in1,in2,ideal1) VALUES(0,1,1)");
		insertStmt.executeInsert();
		insertStmt = db.compileStatement("INSERT INTO xor(in1,in2,ideal1) VALUES(1,1,0)");
		insertStmt.executeInsert();
		 
		CodecMLDataSet data = new CodecMLDataSet(androidCodec);
		 
		XOR.testXORDataSet((MLDataSet)data);
		 
7
CodeRank
This code example shows how to use the following methods:compileStatement
  /*package*/ void insertRaw(SQLiteDatabase database, ContentValues contentValues) {
    database.insert(TABLE_NAME, null, contentValues);
  } 
 
  /*package*/ SQLiteStatement createInsertStatement(SQLiteDatabase database) {
    return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " +
                                                                      PERSON + ", " +
                                                                      DATE_SENT + ", " +
                                                                      DATE_RECEIVED  + ", " +
                                                                      PROTOCOL + ", " +
                                                                      READ + ", " +
                                                                      STATUS + ", " +
                                                                      TYPE + ", " +
                                                                      REPLY_PATH_PRESENT + ", " +
                                                                      SUBJECT + ", " +
                                                                      BODY + ", " +
                                                                      SERVICE_CENTER +
                                                                      ", THREAD_ID) " + 
                                     " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 
  } 
6
CodeRank
This code example shows how to use the following methods:close, beginTransaction, compileStatement, endTransaction
		 
		SQLiteDatabase db = getReadableDatabase();
		 
		String sql = "UPDATE targetLists SET listName = ?, listDescription = ? where _id = ?";
		 
		SQLiteStatement sqlStatement = db.compileStatement(sql);
			sqlStatement.bindString(1, listName);
			sqlStatement.bindString(2, listDescription);
			sqlStatement.bindLong(3, id);
		 
		db.beginTransaction();
		try 
		{ 
			sqlStatement.execute();
			db.setTransactionSuccessful();
			success = true;
		} 
		catch (SQLException ex)
		{ 
			ex.printStackTrace();

6
CodeRank
This code example shows how to use the following methods:close, beginTransaction, compileStatement, endTransaction, setTransactionSuccessful
	public boolean addEyepieceData(String type, String focalLength){
		boolean success = false;
		 
		SQLiteDatabase db = getReadableDatabase();
		 
		SQLiteStatement sqlStatement = db.compileStatement("INSERT INTO eyepieces (type, focalLength) VALUES (?, ?)");
			sqlStatement.bindString(1, type);
			sqlStatement.bindString(2, focalLength);
		 
		db.beginTransaction();
		try 
		{ 
			sqlStatement.execute();
			db.setTransactionSuccessful();
			success = true;
		} 
		catch (SQLException ex)
		{ 
			ex.printStackTrace();
		} 

6
CodeRank
This code example shows how to use the following methods:compileStatement
This code example shows how to use the following methods:compileStatement, execSQL
        statement.close();
    } 
 
    @MediumTest 
    public void testSimpleQuery() throws Exception { 
        mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL, str TEXT NOT NULL);");
        mDatabase.execSQL("INSERT INTO test VALUES (1234, 'hello');");
        SQLiteStatement statement1 =
                mDatabase.compileStatement("SELECT num FROM test WHERE str = ?");
        SQLiteStatement statement2 =
                mDatabase.compileStatement("SELECT str FROM test WHERE num = ?");
 
        try { 
            statement1.bindString(1, "hello");
            long value = statement1.simpleQueryForLong();
            assertEquals(1234, value);
 
            statement1.bindString(1, "world");
            statement1.simpleQueryForLong();
            fail("shouldn't get here");
5
CodeRank
This code example shows how to use the following methods:close, compileStatement
		 
		String sql = "INSERT INTO tip (tip_creator, symbol, target_price, reason) VALUES (?, ?, ?, ?)";
		 
		StockDatabase dbHelper = new StockDatabase(this.getApplicationContext());
		SQLiteDatabase db = dbHelper.openDatabase();
		SQLiteStatement stmt = db.compileStatement(sql);
		stmt.bindString(1, "USERNAME");
		stmt.bindString(2, symbol);
		stmt.bindDouble(3, targetPrice);
		stmt.bindString(4, reason);
		stmt.execute();
		stmt.close();
		 
		db.close();
		 
		tvTipStatus.setText("Tip saved!");
	} 
} 
5
CodeRank
This code example shows how to use the following methods:compileStatement
		database.close();
	} 
	 
	public long insert(BaseDBObject baseDBObject)
	{ 
		SQLiteStatement statement = database.compileStatement(baseDBObject.getInsertStatement());     	                    
		 
		baseDBObject.bindInsert(statement);
		 
		long lastId = statement.executeInsert(); 
		 
		statement.close(); 
	 
		return lastId;
	} 
	 
	public void update(BaseDBObject baseDBObject)
	{ 
		SQLiteStatement statement = database.compileStatement(baseDBObject.getUpdateStatement());     	                    
		 
5
CodeRank
This code example shows how to use the following methods:beginTransaction, compileStatement, endTransaction, query, setTransactionSuccessful
			sql = "insert into options (option,value) values ('" + option + "',?)";
		else 
			sql = "update options set value = ? where option = '" + option + "'";
 
		SQLiteDatabase lootDB = Database.getDatabase();
		lootDB.beginTransaction();
 
		SQLiteStatement stmt = lootDB.compileStatement(sql);
		stmt.bindBlob(1, value);
		 
		try 
		{ 
			stmt.execute();
			lootDB.setTransactionSuccessful();
		} 
		catch ( SQLException e )
		{ 
			return false; 
		} 
		finally 

5
CodeRank
This code example shows how to use the following methods:compileStatement, execSQL
 
	private SQLiteDatabase mDB;
 
	public void init(final SQLiteDatabase db) {
	    mDB = db;
		mInsertReading = mDB.compileStatement(INSERT_READING);
	} 
 
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE " +
						TABLE_NAME + "(" +
						"id INTEGER PRIMARY KEY, " + 
						"gas_use REAL, " + 
						"break_use REAL, " + 
						"money_saved REAL, " + 
						"drive_number INTEGER, " + 
						"time INTEGER" +						 
						")"); 
	      init(db);
	} 
5
CodeRank
This code example shows how to use the following methods:beginTransaction, compileStatement, endTransaction, setTransactionSuccessful
                null, null); 
    } 
 
    public boolean executeSql(String sql) {
 
        database.beginTransaction();
        SQLiteStatement sqlStmt = database.compileStatement(sql);
        try { 
            sqlStmt.execute();
            database.setTransactionSuccessful();
 
        } catch (SQLiteException ex) {
 
            ex.printStackTrace();
            return false; 
 
        } finally { 
            database.endTransaction();
        } 
 

5
CodeRank
This code example shows how to use the following methods:compileStatement
  private String tableName; 
 
  public AbstractDao(SQLiteDatabase db, String tableName, String insertStatement) { 
    this.db = db; 
    this.tableName = tableName; 
    this.insert = db.compileStatement(insertStatement); 
  } 
 
  public abstract int save(T model); 
 
  public int update(T model) { 
    return 0; 
  } 
 
  public boolean delete(T model) { 
    int rowsDeleted = db.delete(tableName, BaseColumns._ID + " = ?", 
        new String[] { String.valueOf(model.getTmdbId()) }); 
    return rowsDeleted > 0; 
  } 
 
4
CodeRank
This code example shows how to use the following methods:compileStatement
	} 
 
	public long getSize() { 
 
		String sql = "SELECT COUNT(*) FROM " + DATABASE_TABLE;
		SQLiteStatement statement = ourDatabase.compileStatement(sql);
		long count = statement.simpleQueryForLong();
		return count;
	} 
 
	public String getKEY_TEST(long l) throws SQLException {
		// TODO Auto-generated method stub 
		String[] columns = new String[] { KEY_ROWID, KEY_TEST, KEY_A_answer,
				KEY_B_answer, KEY_C_answer, KEY_D_answer, KEY_E_answer,
				KEY_CORRECT, KEY_IFEEXISTS };
		Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "="
				+ l, null, null, null, null);
		if (c != null) {
			c.moveToFirst();
			String data = c.getString(1);
4
CodeRank
This code example shows how to use the following methods:compileStatement
	 
	private SQLiteDB(Context context) {
		mCtx = context;
		mFingerprintDBOpenHelper = new FingerprintDBOpenHelper(context);
		mFingerprintDb = mFingerprintDBOpenHelper.getWritableDatabase();
		mInsertFingerprint = mFingerprintDb.compileStatement("insert into " + TABLE_NAME + "(" + COL_MAPID + "," + COL_X + "," + COL_Y + "," + COL_ANGLE + "," + COL_DATETIME + "," + COL_SAMPLENAME + "," + COL_FINGERPRINTJSON + ") " + " values (?, ?, ?, ?, ?, ?, ?)");
		 
		try { 
			FileWriter dbPathLogger = new FileWriter(new File(Environment.getExternalStorageDirectory() + File.separator + "samples", "dbpath.txt"));
			dbPathLogger.write(mFingerprintDb.getPath());
			dbPathLogger.append('\n');
			dbPathLogger.flush();
			dbPathLogger.close();
		} catch(IOException e) {
			e.printStackTrace();
			Log.e(TAG, "data directory log failed!", e);
			throw new RuntimeException(e);
		} 
	} 
	 
4
CodeRank
This code example shows how to use the following methods:compileStatement
	} 
 
	private int getRowsCount(SQLiteDatabase db, String table) {
		SQLiteStatement sqlCount = null;
		try { 
			sqlCount = db.compileStatement("SELECT COUNT(*) FROM " + table);
			return (int) sqlCount.simpleQueryForLong();
		} 
		finally { 
			if (sqlCount != null) {
				sqlCount.close();
			} 
		} 
	} 
 
	/** 
	 * Update a record in the database. 
	 *  
	 * @see android.content.ContentProvider#update(android.net.Uri, 
	 *      android.content.ContentValues, java.lang.String, java.lang.String[]) 
4
CodeRank
This code example shows how to use the following methods:compileStatement
		ItemCollectionsColumns.NAME, 
		ItemCollectionsColumns.DESCRIPTION }; 
 
	public ItemCollectionDao(SQLiteDatabase db) {
		this.db = db;
		insertStatement = db.compileStatement(INSERT);
	} 
 
	public long save(ItemCollection collection) {
		insertStatement.clearBindings();
		insertStatement.bindString(1, collection.getName());
		insertStatement.bindString(2, collection.getDescription());
		return insertStatement.executeInsert();
	} 
 
	public void update(ItemCollection collection) {
		final ContentValues values = new ContentValues();
		values.put(ItemCollectionsColumns.NAME, collection.getName());
		values.put(ItemCollectionsColumns.DESCRIPTION,
				collection.getDescription());
4
CodeRank
This code example shows how to use the following methods:compileStatement
	private SQLiteDatabase db;
	private SQLiteStatement insertStatement;
 
	public PlayerRoundDAO(SQLiteDatabase db) {
		this.db = db;
		insertStatement = db.compileStatement(INSERT);
	} 
 
	@Override 
	public long save(PlayerRound playerRound) {
		if (!exists(playerRound)) {
			insertStatement.clearBindings();
			insertStatement.bindLong(1, playerRound.getRoundId());
			insertStatement.bindLong(2, playerRound.getPlayer().getId());
			insertStatement.bindLong(3, playerRound.getBet());
			insertStatement.bindLong(4, playerRound.getWins());
			playerRound.setId(insertStatement.executeInsert());
		} else { 
			update(playerRound);
		} 
5
CodeRank
This code example shows how to use the following methods:beginTransaction, compileStatement, endTransaction
		return cursor;
	} 
 
	public boolean executeSql(String sql) {
 
		database.beginTransaction();
		SQLiteStatement sqlStmt = database.compileStatement(sql);
		try { 
			sqlStmt.execute();
			database.setTransactionSuccessful();
 
		} catch (SQLiteException ex) {
 
			ex.printStackTrace();
			return false; 
 
		} finally { 
			database.endTransaction();
		} 
 

4
CodeRank
This code example shows how to use the following methods:compileStatement
  
   public CopyOfDataHelper(Context context) {
      this.context = context;
      OpenHelper openHelper = new OpenHelper(this.context);
      this.db = openHelper.getWritableDatabase();
      this.insertStmt = this.db.compileStatement(INSERT);
     // this.ins_bookmark_stmt = this.db.compileStatement(INSERT_BOOKMARK); 
   } 
  
   public long insert_bookmark(int id_book,int page,String desc) {
      this.ins_bookmark_stmt.bindLong(1,  id_book);
      this.ins_bookmark_stmt.bindLong(2, page);
      this.ins_bookmark_stmt.bindString(3, desc);
      return this.ins_bookmark_stmt.executeInsert();
   } 
   public long insert(byte[] bMapArray,double zoom) {
	      this.insertStmt.bindBlob(1,  bMapArray);
	      this.insertStmt.bindDouble(2, zoom);
	      return this.insertStmt.executeInsert();
	   } 
4
CodeRank
This code example shows how to use the following methods:compileStatement
        mDeleteStatement.execute();
    } 
 
    public void deleteAllHistory() { 
        if (mDeleteAllStatement == null) {
            mDeleteAllStatement = mDb.compileStatement("DELETE FROM "+ TABLE_NAME);
        } 
        mDeleteAllStatement.execute();
    } 
 
    /** 
     * Database helper that creates and maintains the SQLite database. 
     */ 
    static class DatabaseHelper extends SQLiteOpenHelper {
        public DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        } 
 
        @Override 
        public void onCreate(SQLiteDatabase db) {
4
CodeRank
This code example shows how to use the following methods:compileStatement
 
   public DataHelper(Context context) {
      this.context = context;
      OpenHelper openHelper = new OpenHelper(this.context);
      this.db = openHelper.getWritableDatabase();
      this.insertStmt = this.db.compileStatement(INSERT);
   } 
 
   public long insert(String name, String pkey, String ip, String mac) {
      this.insertStmt.bindString(1, name);
      this.insertStmt.bindString(2, pkey);
      this.insertStmt.bindString(3, ip);
      this.insertStmt.bindString(4, mac);
      return this.insertStmt.executeInsert();
   } 
    
   public String isSaved(String pkey) {
	   Cursor cursor = this.db.query(TABLE_NAME, new String[] {"name", "mac", "last_ip"}, "pkey = " + "'"+ pkey +"'", null, null, null, null);
	   if(cursor.moveToFirst()) {
		   String name = cursor.getString(0);
4
CodeRank
This code example shows how to use the following methods:beginTransaction, compileStatement, endTransaction, execSQL, getVersion
	private final SQLiteStatement myUnsetValueStatement;
	private final SQLiteStatement myDeleteGroupStatement;
 
	public ZLSQLiteConfig(Context context) {
		myDatabase = context.openOrCreateDatabase("config.db", Context.MODE_PRIVATE, null);
		switch (myDatabase.getVersion()) {
			case 0: 
				myDatabase.execSQL("CREATE TABLE config (groupName VARCHAR, name VARCHAR, value VARCHAR, PRIMARY KEY(groupName, name) )");
				break; 
			case 1: 
				myDatabase.beginTransaction();
				SQLiteStatement removeStatement = myDatabase.compileStatement(
					"DELETE FROM config WHERE name = ? AND groupName LIKE ?" 
				); 
				removeStatement.bindString(2, "/%");
				removeStatement.bindString(1, "Size"); removeStatement.execute();
				removeStatement.bindString(1, "Title"); removeStatement.execute();
				removeStatement.bindString(1, "Language"); removeStatement.execute();
				removeStatement.bindString(1, "Encoding"); removeStatement.execute();
				removeStatement.bindString(1, "AuthorSortKey"); removeStatement.execute();

4
CodeRank
This code example shows how to use the following methods:beginTransaction, compileStatement, endTransaction, execSQL, getVersion
	private static ZLConfig ourInstance;
 
	public ZLConfig(Context context) {
		ourInstance = this;
		myDatabase = context.openOrCreateDatabase("config.db", Context.MODE_PRIVATE, null);
		switch (myDatabase.getVersion()) {
			case 0: 
				myDatabase.execSQL("CREATE TABLE config (groupName VARCHAR, name VARCHAR, value VARCHAR, PRIMARY KEY(groupName, name) )");
				break; 
			case 1: 
				myDatabase.beginTransaction();
				SQLiteStatement removeStatement = myDatabase.compileStatement(
					"DELETE FROM config WHERE name = ? AND groupName LIKE ?" 
				); 
				removeStatement.bindString(2, "/%");
				removeStatement.bindString(1, "Size"); removeStatement.execute();
				removeStatement.bindString(1, "Title"); removeStatement.execute();
				removeStatement.bindString(1, "Language"); removeStatement.execute();
				removeStatement.bindString(1, "Encoding"); removeStatement.execute();
				removeStatement.bindString(1, "AuthorDisplayName"); removeStatement.execute();

4
CodeRank

Related SQLiteDatabase compileStatement Questions & Answers:

compileStatement Method Overview
Compiles an SQL statement into a reusable pre-compiled statement object.
See Code Examples for other Android SQLiteDatabase Methods: