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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execSQL

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: