Best code examples for Android SQLiteDatabase class (android.database.sqlite.SQLiteDatabase)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SQLiteDatabase class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android SQLiteDatabase examples from Open Source projects
Examples using Android SQLiteDatabase execSQL method:
This code example shows how to use the following methods: execSQL
49:	db.execSQL("CREATE TABLE orgs (id INTEGER PRIMARY KEY);"); 
50:	db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, avatarurl TEXT);"); 
51:	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);"); 
-
57:	db.execSQL("DROP TABLE IF EXISTS orgs"); 
58:	db.execSQL("DROP TABLE IF EXISTS users"); 
59:	db.execSQL("DROP TABLE IF EXISTS repos"); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: execSQL, setVersion
62:	db.execSQL(queryBuilder.toString()); 
63:	db.setVersion(DB_VERSION); 
-
72:	db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: execSQL, insert
69:	userDao.save(sqLiteDatabase, account.getUser()); 
-
76:	clearDeletedAccount(sqLiteDatabase, account); // 确保一个帐号在数据库中只有一条记录,一个状态 
-
78:	long rowId = sqLiteDatabase.insert(TABLE, null, values); 
-
94:	sqLiteDatabase.execSQL(sql.toString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: beginTransaction, endTransaction, setTransactionSuccessful
129:	db.beginTransaction(); 
-
131:	persistableResource.store(db, items); 
132:	db.setTransactionSuccessful(); 
-
134:	db.endTransaction(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: beginTransaction, endTransaction, setTransactionSuccessful, update
126:	db.beginTransaction(); 
-
129:	int count = db.update("tests", values, newSelection, selectionArgs); 
130:	db.setTransactionSuccessful(); 
-
134:	db.endTransaction(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: beginTransaction, delete, endTransaction, setTransactionSuccessful
281:	db.beginTransaction(); 
282:	db.delete(TABLE, COLUMN_USERID + "='" + userId + "'", null); 
283:	db.setTransactionSuccessful(); 
-
285:	db.endTransaction(); 
Full Snippet Info
7
CodeRank
Examples using Android SQLiteDatabase delete method:
This code example shows how to use the following methods: delete, insert, query, close
100:	db.delete(TABLE_PLAYLIST, "PlaylistName = ?", whereArgs); 
-
102:	db.close(); 
-
311:	Cursor query = db.query(TABLE_PLAYLIST, columns, "PlaylistName = ?", selectionArgs, null, null, null); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: delete, execSQL, rawQuery
448:	database.delete("exectable", null, null); 
-
450:	Cursor cursor = database.rawQuery("select * from exectable", null); 
-
454:	database.execSQL("insert into exectable (first_column) values (?);", new String[]{}); 
455:	Cursor cursor2 = database.rawQuery("select * from exectable", new String[]{null}); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: beginTransaction, endTransaction, getVersion, setTransactionSuccessful, setVersion
121:	int version = db.getVersion(); 
-
123:	db.beginTransaction(); 
-
126:	onCreate(db); 
-
128:	onUpgrade(db, version, mNewVersion); 
-
130:	db.setVersion(mNewVersion); 
131:	db.setTransactionSuccessful(); 
-
133:	db.endTransaction(); 
-
152:	db.close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: beginTransaction, endTransaction, setTransactionSuccessful
49:	db.beginTransaction(); 
50:	createTables(db); 
51:	initTables(db); 
52:	db.setTransactionSuccessful(); 
53:	db.endTransaction(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: beginTransaction, compileStatement, endTransaction, isOpen, close
31:	} 
-
34:	return (db != null && db.isOpen()); 
-
40:	db.close(); 
-
79:	db.beginTransaction(); 
-
87:	db.endTransaction(); 
Full Snippet Info
7
CodeRank
Examples using Android SQLiteDatabase insert method:
This code example shows how to use the following methods: put, insert
46:	ContentValues cv=new ContentValues(); 
-
48:	cv.put("name", name); 
49:	cv.put("address", address); 
50:	cv.put("type", type); 
51:	cv.put("notes", notes); 
-
53:	getWritableDatabase().insert("restaurants", "name", cv); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: insert
118:	mDb.insert(table, null, cv); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: execSQL, insert
84:	db.execSQL( 
-
95:	db.execSQL("CREATE INDEX lookup_identity ON identity(" + 
-
98:	db.execSQL( 
-
106:	db.execSQL("CREATE INDEX lookup_feature ON feature(" + 
-
114:	db.insert("identity", "_id", values); 
-
120:	db.insert("feature", "_id", values); 
-
122:	db.insert("feature", "_id", values); 
Full Snippet Info
7
CodeRank
Examples using Android SQLiteDatabase isOpen method:
This code example shows how to use the following methods: isOpen, isReadOnly, close
81:	if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) { 
-
129:	try { mDatabase.close(); } catch (Exception e) { } 
-
152:	if (mDatabase != null && mDatabase.isOpen()) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: isOpen, isReadOnly, close
112:	if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) { 
-
164:	try { mDatabase.close(); } catch (Exception e) { } 
-
191:	if (mDatabase != null && mDatabase.isOpen()) { 
Full Snippet Info
7
CodeRank
Examples using Android SQLiteDatabase update method:
This code example shows how to use the following methods: beginTransaction, update
101:	db.beginTransaction(); 
-
103:	retval = db.update(table, values, selection, selectionArgs); 
Full Snippet Info
7
CodeRank
Examples using Android SQLiteDatabase rawQuery method:
This code example shows how to use the following methods: execSQL, rawQuery
80:	Cursor res = database.rawQuery("select name from sqlite_master where type = 'table' and name = 'dict_tbl'", null); 
-
86:	database.execSQL("insert into cards (ordinal, question, answer, note)" + 
-
92:	Cursor result = database.rawQuery("SELECT _id FROM dict_tbl", null); 
-
95:	result = database.rawQuery("SELECT _id FROM learn_tbl", null); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: execSQL, rawQuery, close
23:	droidsniffDB.execSQL(CREATE_PREFERENCES); 
24:	droidsniffDB.execSQL(CREATE_BLACKLIST); 
-
120:	Cursor cur = droidsniffDB.rawQuery("SELECT count(id) as count FROM DROIDSNIFF_PREFERENCES where name = 'update';", new String[] {}); 
-
124:	droidsniffDB.execSQL("INSERT INTO DROIDSNIFF_PREFERENCES (name, value) values ('update', ?);", 
-
127:	droidsniffDB.execSQL("UPDATE DROIDSNIFF_PREFERENCES SET value=? WHERE name='update';", 
-
130:	droidsniffDB.close(); 
Full Snippet Info
6
CodeRank
Examples using Android SQLiteDatabase setVersion method:
This code example shows how to use the following methods: execSQL, setVersion
101:	db.execSQL(PROFILES_TABLE_UPGRADE_6_7_1); 
102:	db.execSQL(PROFILES_TABLE_UPGRADE_6_7_2); 
103:	db.execSQL(PROFILES_TABLE_UPGRADE_6_7_3); 
104:	db.execSQL(PROFILES_TABLE_UPGRADE_6_7_4); 
-
114:	db.execSQL(PROFILES_TABLE_UPGRADE_3_4); 
115:	db.execSQL(PROFILES_TABLE_UPGRADE_4_5); 
116:	db.execSQL(PROFILES_TABLE_UPGRADE_5_6); 
-
118:	db.setVersion(DATABASE_VERSION); 
-
120:	db.execSQL(PROFILES_TABLE_UPGRADE_3_4); 
121:	db.execSQL(PROFILES_TABLE_UPGRADE_4_5); 
122:	db.execSQL(PROFILES_TABLE_UPGRADE_5_6); 
-
124:	db.setVersion(DATABASE_VERSION); 
-
126:	db.execSQL(PROFILES_TABLE_UPGRADE_4_5); 
127:	db.execSQL(PROFILES_TABLE_UPGRADE_5_6); 
-
129:	db.setVersion(DATABASE_VERSION); 
-
131:	db.execSQL(PROFILES_TABLE_UPGRADE_5_6); 
-
133:	db.setVersion(DATABASE_VERSION); 
-
136:	db.setVersion(DATABASE_VERSION); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: execSQL, setVersion
62:	db.execSQL(queryBuilder.toString()); 
63:	db.setVersion(DB_VERSION); 
-
72:	db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); 
Full Snippet Info
7
CodeRank
Examples using Android SQLiteDatabase query method:
This code example shows how to use the following methods: execSQL, insert, query
95:	Cursor c = 
-
136:	db.execSQL(DBVERSION_CREATE); 
-
139:	db.insert(TABLE_DBVERSION, null, args); 
-
141:	db.execSQL(TABLE_CREATE); 
-
158:	db.insert(TABLE_DBVERSION, null, args); 
Full Snippet Info
7
CodeRank
Examples for other Android SQLiteDatabase methods:
Related Android SQLiteDatabase Questions & Answers:
Other Android SQLiteDatabase Examples
1:		public void closeDB() {
2:			SQLiteDatabase db = this.getReadableDatabase();
3:			if (db != null && db.isOpen())
4:				db.close();

Read More

2:		 */
3:		public void deleteToDo(long tado_id) {
4:			SQLiteDatabase db = this.getWritableDatabase();
5:			db.delete(TABLE_TODO, KEY_ID + " = ?",
6:					new String[] { String.valueOf(tado_id) });

Read More

1:		public void deleteContact(Contact contact) {
2:			SQLiteDatabase db = this.getWritableDatabase();
3:			db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
4:					new String[] { String.valueOf(contact.getID()) });

Read More

SQLiteDatabase Class Overview
Exposes methods to manage a SQLite database.

SQLiteDatabase has methods to create, delete, execute SQL commands, and perform other common database management tasks. See the Notepad sample application in the SDK for an example of creating and managing a database. Database names must be unique within an application, not across all applications. In addition to SQLite's default BINARY collator, Android supplies two more, LOCALIZED, which changes with the system's current locale, and UNICODE, which is the Unicode Co...
Methods
  • compileStatement
    Compiles an SQL statement into a reusable pre-compiled statement object.
  • delete
    Convenience method for deleting rows in the database.
  • execSQL
    Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
  • getPath
    Gets the path to the database file.
  • inTransaction
    Returns true if the current thread has a transaction pending.
  • insert
    Convenience method for inserting a row into the database.
  • insertOrThrow
    Convenience method for inserting a row into the database.
  • isOpen
    Returns true if the database is currently open.
  • isReadOnly
    Returns true if the database is opened as read only.
  • query
    Query the given table, returning a Cursor over the result set.
  • rawQuery
    Runs the provided SQL and returns a Cursor over the result set.
  • replace
    Convenience method for replacing a row in the database.
  • setLockingEnabled
    This method was deprecated in API level 16. This method now does nothing. Do not use.
  • update
    Convenience method for updating rows in the database.