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

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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, delete, insert, query
		if(fileName != null)
			mActivity.deleteFile(fileName);
		//mActivity.openFileOutput(fileName, Context.MODE_PRIVATE).getFD(). 
 
		String[] whereArgs = {playlistName};
		db.delete(TABLE_PLAYLIST, "PlaylistName = ?", whereArgs);
 
		db.close();
	} 
 
	@Override 
	public ArrayList<String> getAvailablePlaylists() {
		ArrayList<String> playlists = new ArrayList<String>(); 
		SQLiteDatabase db = mActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
 
		String[] columns = {"PlaylistName"};
		Cursor query = db.query(TABLE_PLAYLIST, columns, null, null, null, null, "PlaylistName ASC");
 
		if(query != null){
			query.moveToFirst();

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:execSQL, insert
     * Called when a new database is created. 
     * @param db The database to initialize. 
     */ 
    @Override 
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(
            "CREATE TABLE identity(" + 
                "_id INTEGER," + 
                "category TEXT NOT NULL," + 
                "type TEXT NOT NULL," + 
                "lang TEXT NOT NULL DEFAULT ''," + 
                "name TEXT NOT NULL DEFAULT ''," + 
                "jid TEXT," + 
                "PRIMARY KEY(_id)" + 
            ")" 
        ); 
        db.execSQL("CREATE INDEX lookup_identity ON identity(" +
                   "category ASC, type ASC, lang ASC, name ASC, _id ASC" + 
                   ")"); 
        db.execSQL(

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:execSQL, insert, query
			m_db = myCtx.openOrCreateDatabase(DATABASE_NAME, 0,null);
 
			// Check for the existence of the DBVERSION table 
			// If it doesn't exist than create the overall data, 
			// otherwise double check the version 
			Cursor c =
				m_db.query("sqlite_master", new String[] { "name" },
						"type='table' and name='"+TABLE_DBVERSION+"'", null, null, null, null);
			int numRows = c.getCount();
			if (numRows < 1)
			{ 
				CreateDatabase(m_db);
			} 
			else 
			{ 
				int version=0;
				Cursor vc = m_db.query(true, TABLE_DBVERSION, new String[] {"version"},
						null, null, null, null, null,null); 
				if(vc.getCount() > 0) {
				    vc.moveToLast();

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:execSQL, insert
     * Called when a new database is created. 
     * @param db The database to initialize. 
     */ 
    @Override 
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(
            "CREATE TABLE identity(" + 
                "_id INTEGER," + 
                "category TEXT NOT NULL," + 
                "type TEXT NOT NULL," + 
                "lang TEXT NOT NULL DEFAULT ''," + 
                "name TEXT NOT NULL DEFAULT ''," + 
                "jid TEXT," + 
                "PRIMARY KEY(_id)" + 
            ")" 
        ); 
        db.execSQL("CREATE INDEX lookup_identity ON identity(" +
                   "category ASC, type ASC, lang ASC, name ASC, _id ASC" + 
                   ")"); 
        db.execSQL(

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:insert
 
    public void insertAbstractResult(AbstractResult result, String table) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_PATH, result.getRelativePath());
        cv.put(KEY_BYTES, result.getBytes());
        mDb.insert(table, null, cv);
    } 
 
    public Cursor getAbstractResults(String table) throws SQLException {
        return mDb.query(false, table, new String[] {KEY_BYTES}, null, null, null, null,
                KEY_PATH + " ASC", null);
    } 
 
    public static AbstractResult getAbstractResult(Cursor cursor) {
        return AbstractResult.create(cursor.getBlob(cursor.getColumnIndex(KEY_BYTES)));
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:delete, insert, query
    @Test 
    public void testDeleteAll() throws Exception { 
        addChuck(); 
        addJulie(); 
 
        int deleted = database.delete("table_name", "1", null);
        assertThat(deleted).isEqualTo(2);
 
        assertEmptyDatabase(); 
    } 
 
 
    @Test 
    public void testExecSQL() throws Exception { 
        Statement statement;
        ResultSet resultSet;
 
        database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");
 
        statement = shadowOf(database).getConnection().createStatement();

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:beginTransaction, insert
	} 
 
	public synchronized Uri insert(final Context context,
			final SQLiteDatabase db) {
		Uri retval = null;
		db.beginTransaction();
		try { 
			beforeInsert(context, db);
 
			final long id = db.insert(getTableName(), null, getContent());
 
			if (id == -1) {
				throw new SQLException("Insert failed in " + getTableName());
			} 
			else { 
				_id = id;
				afterInsert(context, db);
				db.setTransactionSuccessful();
				retval = getUri();
			} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:execSQL, insert
            "SELECT count(*)" 
                    + " FROM " + SYNC_STATE_TABLE
                    + " WHERE " + SyncStateContract.Columns._ID + "=?";
 
    public void createDatabase(SQLiteDatabase db) {
        db.execSQL("DROP TABLE IF EXISTS " + SYNC_STATE_TABLE);
        db.execSQL("CREATE TABLE " + SYNC_STATE_TABLE + " ("
                + SyncStateContract.Columns._ID + " INTEGER PRIMARY KEY,"
                + SyncStateContract.Columns.ACCOUNT_NAME + " TEXT NOT NULL,"
                + SyncStateContract.Columns.ACCOUNT_TYPE + " TEXT NOT NULL,"
                + SyncStateContract.Columns.DATA + " TEXT,"
                + "UNIQUE(" + SyncStateContract.Columns.ACCOUNT_NAME + ", "
                + SyncStateContract.Columns.ACCOUNT_TYPE + "));");
 
        db.execSQL("DROP TABLE IF EXISTS " + SYNC_STATE_META_TABLE);
        db.execSQL("CREATE TABLE " + SYNC_STATE_META_TABLE + " ("
                + SYNC_STATE_META_VERSION_COLUMN + " INTEGER);");
        ContentValues values = new ContentValues();
        values.put(SYNC_STATE_META_VERSION_COLUMN, DB_VERSION);
        db.insert(SYNC_STATE_META_TABLE, SYNC_STATE_META_VERSION_COLUMN, values);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:put, insert
											args));
	} 
	 
	public void insert(String name, String address,
										 String type, String notes) {
		ContentValues cv=new ContentValues();
					 
		cv.put("name", name);
		cv.put("address", address);
		cv.put("type", type);
		cv.put("notes", notes);
		 
		getWritableDatabase().insert("restaurants", "name", cv);
	} 
	 
	public void update(String id, String name, String address,
										 String type, String notes) {
		ContentValues cv=new ContentValues();
		String[] args={id};
		 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related SQLiteDatabase insert Questions & Answers:

Other SQLiteDatabase insert Examples

68:			if (!isSiteExists(db, site.getRSSLink())) {
69:				// site not existed, create a new row
70:				db.insert(TABLE_RSS, null, values);
71:				db.close();
72:			} else {

Read More

62:	
63:			// Inserting Row
64:			db.insert(TABLE_CONTACTS, null, values);
65:			db.close(); // Closing database connection
66:		}

Read More

7:	
8:			// Inserting Row
9:			db.insert(TABLE_CONTACTS, null, values);
10:			db.close(); // Closing database connection
11:		}

Read More

insert Method Overview
Convenience method for inserting a row into the database.
See Code Examples for other Android SQLiteDatabase Methods: