content-values

How to insert a SQLite record with a datetime set to 'now' in Android application?

风格不统一 提交于 2019-12-17 04:11:44
问题 Say, we have a table created as: create table notes (_id integer primary key autoincrement, created_date date) To insert a record, I'd use ContentValues initialValues = new ContentValues(); initialValues.put("date_created", ""); long rowId = mDb.insert(DATABASE_TABLE, null, initialValues); But how to set the date_created column to now ? To make it clear, the initialValues.put("date_created", "datetime('now')"); Is not the right solution. It just sets the column to "datetime('now')" text. 回答1:

Error casting Object[] to ContentValues[]

早过忘川 提交于 2019-12-10 23:34:01
问题 I'm following a tutorial about content providers and, in a specific code, they inserted some data using a bulkInsert method. They also used a Vector variable ( cVVector ) to store all the ContentValues . Code that was mentioned: if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Then, I tried to reduce the code by casting cVVector.toArray() to

How to insert a SQLite record with a datetime set to 'now' in Android application?

别等时光非礼了梦想. 提交于 2019-11-26 18:11:42
Say, we have a table created as: create table notes (_id integer primary key autoincrement, created_date date) To insert a record, I'd use ContentValues initialValues = new ContentValues(); initialValues.put("date_created", ""); long rowId = mDb.insert(DATABASE_TABLE, null, initialValues); But how to set the date_created column to now ? To make it clear, the initialValues.put("date_created", "datetime('now')"); Is not the right solution. It just sets the column to "datetime('now')" text. e-satis You cannot use the datetime function using the Java wrapper "ContentValues". Either you can use :