SQLiteDatabase execSQL - 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 execSQL method.

This code example shows how to use the following methods: execSQL
        super(context, NAME, null, VERSION);
    } 
 
    @Override 
    public void onCreate(final SQLiteDatabase db) {
        db.execSQL("CREATE TABLE orgs (id INTEGER PRIMARY KEY);");
        db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, avatarurl TEXT);");
        db.execSQL("CREATE TABLE repos (id INTEGER PRIMARY KEY, repoId INTEGER, orgId INTEGER, name TEXT, ownerId INTEGER, private INTEGER, fork INTEGER, description TEXT, forks INTEGER, watchers INTEGER, language TEXT, hasIssues INTEGER, mirrorUrl TEXT);");
    } 
 
    @Override 
    public void onUpgrade(final SQLiteDatabase db, final int oldVersion,
            final int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS orgs");
        db.execSQL("DROP TABLE IF EXISTS users");
        db.execSQL("DROP TABLE IF EXISTS repos");
        onCreate(db);
    } 
} 
Full Snippet Info
10
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: delete, execSQL, rawQuery
 
    @Test(expected = Exception.class) 
    public void testExecSQLInsertNullShouldBeException() throws Exception { 
        //this inserts null in android, but it when it happens it is likely an error.  H2 throws an exception.  So we'll make Robolectric expect an Exception so that the error can be found. 
 
        database.delete("exectable", null, null);
 
        Cursor cursor = database.rawQuery("select * from exectable", null);
        cursor.moveToFirst();
        assertThat(cursor.getCount()).isEqualTo(0);
 
        database.execSQL("insert into exectable (first_column) values (?);", new String[]{});
        Cursor cursor2 = database.rawQuery("select * from exectable", new String[]{null});
        cursor.moveToFirst();
        assertThat(cursor2.getCount()).isEqualTo(1);
 
    } 
 
    @Test 
    public void testExecSQLAutoIncrementSQLite() throws Exception { 
Full Snippet Info
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execSQL, setVersion
            StringBuilder queryBuilder = new StringBuilder();
            queryBuilder.append(String.format("CREATE TABLE %s (", TABLE_NAME));
            TrackerEntry.buildCreationString(queryBuilder);
 
            queryBuilder.append(");");
            db.execSQL(queryBuilder.toString());
            db.setVersion(DB_VERSION);
        } 
 
        @Override 
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO: reimplement this when dB version changes 
            Log.w(LOG_TAG, "Upgrading database from version " + oldVersion
                            + " to " + newVersion
                            + ", which will destroy all old data"); 
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
            onCreate(db);
        } 
    } 
 
    private DatabaseHelper mOpenHelper;
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execSQL, insert
		values.put("Search_Proxy_Url", account.getSearchProxyUrl());
		values.put("Token_Expired_At",
				account.getTokenExpiredAt() == null? -1L : account.getTokenExpiredAt().getTime());
 
		if (account.getUser() != null) {
			userDao.save(sqLiteDatabase, account.getUser());
		} 
		 
		if (account.isDefault()) {
			resetDefaultAccount(sqLiteDatabase);  // 清除原有的默认帐号状态设置
		} 
		 
		clearDeletedAccount(sqLiteDatabase, account); // 确保一个帐号在数据库中只有一条记录,一个状态
 
		long rowId = sqLiteDatabase.insert(TABLE, null, values);
		//You can access the ROWID of an SQLite table using one the special 
		//column names ROWID, _ROWID_, or OID. 
		//If a table contains a column of type INTEGER PRIMARY KEY, 
		//then that column becomes an alias for the ROWID. 
		//You can then access the ROWID using any of four different names, 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execSQL
This code example shows how to use the following methods: execSQL
		super(context, DB_NAME, null, DB_VERSION);
	} 
	 
	@Override 
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_BOOKMARKS_TABLE);
		db.execSQL(CREATE_TAGS_TABLE);
		db.execSQL(CREATE_BOOKMARK_TAG_TABLE);
      db.execSQL(BOOKMARK_TAGS_INDEX);
	} 
 
	@Override 
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	   if (newVersion <= oldVersion) {
	      Log.w(TAG, "Can't downgrade from version " +
                 oldVersion + " to version " + newVersion);
	      return; 
	   } 
      Log.i(TAG, "Upgrading database from version " +
              oldVersion + " to version " + newVersion);
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execSQL
    } 
 
    @Override 
    public void onCreate(SQLiteDatabase db) {
 
        db.execSQL(CREATE_ACCOUNT_TABLE_SQL);
 
        createOtherTable(db);
    } 
 
    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        switch (oldVersion) {
            case 19: 
                deleteAllTable(db);
                onCreate(db);
            default: 
                deleteAllTableExceptAccount(db);
                createOtherTable(db);
        } 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execSQL
        return mStoreDB.query(KEYVAL_TABLE_NAME, KEYVAL_COLUMNS, null, null, null, null, null);
    } 
 
    @Deprecated 
    private void createDatabaseTables(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + KEYVAL_TABLE_NAME + "(" +
                KEYVAL_COLUMN_KEY + " TEXT PRIMARY KEY, " +
                KEYVAL_COLUMN_VAL + " TEXT)");
 
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + GOOGLE_MANAGED_ITEMS_TABLE_NAME + "(" +
                GOOGLE_MANAGED_ITEMS_COLUMN_PRODUCT_ID + " TEXT PRIMARY KEY)");
 
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + VIRTUAL_CURRENCY_TABLE_NAME + "(" +
                VIRTUAL_CURRENCY_COLUMN_ITEM_ID + " TEXT PRIMARY KEY, " +
                VIRTUAL_CURRENCY_COLUMN_BALANCE + " TEXT)");
 
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + VIRTUAL_GOODS_TABLE_NAME + "(" +
                VIRTUAL_GOODS_COLUMN_ITEM_ID + " TEXT PRIMARY KEY, " +
                VIRTUAL_GOODS_COLUMN_BALANCE + " TEXT, " +
                VIRTUAL_GOODS_COLUMN_EQUIPPED + " TEXT)");

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execSQL
	 
	 
	@Override 
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub 
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_TM_NAME);
		db.execSQL("DROP TABLE IF EXISTS "+GOODS_CATEGORY_TM_NAME);
		db.execSQL("DROP TABLE IF EXISTS "+GOODS_TM_NAME);
		db.execSQL("DROP TABLE IF EXISTS "+ELE_CART_TM_NAME);
        onCreate(db);
	} 
 
} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: execSQL, rawQuery
        } 
    } 
 
    /* Convert database from AnyMemo < 9.0 */ 
    private void convertOldDatabase(SQLiteDatabase database) {
        Cursor res = database.rawQuery("select name from sqlite_master where type = 'table' and name = 'dict_tbl'", null);
        boolean isOldDatabase = res.getCount() > 0;
        res.close();
        // This is old database 
        if (isOldDatabase) {
            // copy all cards 
            database.execSQL("insert into cards (ordinal, question, answer, note)" +
                    " select _id as ordinal, question, answer, note from dict_tbl"); 
 
 
            // Make sure the count matches in old database; 
            int count_dict = 0, count_learn = 0;
            Cursor result = database.rawQuery("SELECT _id FROM dict_tbl", null);
            count_dict = result.getCount();
            result.close();

5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related SQLiteDatabase execSQL Questions & Answers:

Other SQLiteDatabase execSQL Examples

38:					+ " TEXT," + KEY_RSS_LINK + " TEXT," + KEY_DESCRIPTION
39:					+ " TEXT" + ")";
40:			db.execSQL(CREATE_RSS_TABLE);
41:		}
42:	
-
45:		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
46:			// Drop older table if existed
47:			db.execSQL("DROP TABLE IF EXISTS " + TABLE_RSS);
48:	
49:			// Create tables again

Read More

36:					+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
37:					+ KEY_PH_NO + " TEXT" + ")";
38:			db.execSQL(CREATE_CONTACTS_TABLE);
39:		}
40:	
-
43:		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
44:			// Drop older table if existed
45:			db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
46:	
47:			// Create tables again

Read More

25:					+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
26:					+ KEY_PH_NO + " TEXT" + ")";
27:			db.execSQL(CREATE_CONTACTS_TABLE);
28:		}
29:	
-
32:		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
33:			// Drop older table if existed
34:			db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
35:	
36:			// Create tables again

Read More

execSQL Method Overview
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
See Code Examples for other Android SQLiteDatabase Methods: