List of usage examples for android.database.sqlite SQLiteDatabase insert
public long insert(String table, String nullColumnHack, ContentValues values)
From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java
protected static void createFetchLog(Context context, PublicScript script, String trollId, String uuid) { String format = "Create fetch log for script=%s and troll=%s"; String message = String.format(format, script, trollId); Log.d(TAG, message);// w ww . j a va 2 s . c o m MhDlaSQLHelper helper = new MhDlaSQLHelper(context); SQLiteDatabase database = helper.getWritableDatabase(); ContentValues values = new ContentValues(6); long now = System.currentTimeMillis(); values.put(MhDlaSQLHelper.SCRIPTS_ID_COLUMN, uuid); values.put(MhDlaSQLHelper.SCRIPTS_START_DATE_COLUMN, now); values.put(MhDlaSQLHelper.SCRIPTS_SCRIPT_COLUMN, script.name()); values.put(MhDlaSQLHelper.SCRIPTS_CATEGORY_COLUMN, script.category.name()); values.put(MhDlaSQLHelper.SCRIPTS_TROLL_COLUMN, trollId); values.put(MhDlaSQLHelper.SCRIPTS_STATUS_COLUMN, "PENDING"); database.insert(MhDlaSQLHelper.SCRIPTS_TABLE, null, values); database.close(); }
From source file:Main.java
/** * Add an entry to the database/*www .j av a 2 s . c o m*/ * * @param db * pointer to database * @param recordLine * String with a record * format: yy,mm,dd,hh:mm,light,solar,consumption * e.g.: "15,08,13,13:54,35000,613.456,-120.22" */ public static void addDay(SQLiteDatabase db, String recordLine) { /* Parse the string into its single values */ String[] valuesPerLine = recordLine.split(","); if (valuesPerLine.length == 1) { return; } /** String list with hour & minute values */ String[] hourSplit = valuesPerLine[3].split(":"); /** ContentValues to hold the measured and calculated values to be added to the database */ ContentValues values = new ContentValues(14); values.put("year", Integer.parseInt(valuesPerLine[0])); values.put("month", Integer.parseInt(valuesPerLine[1])); values.put("day", Integer.parseInt(valuesPerLine[2])); values.put("hour", Integer.parseInt(hourSplit[0])); values.put("minute", Integer.parseInt(hourSplit[1])); values.put("solar", Double.parseDouble(valuesPerLine[5])); values.put("cons", Double.parseDouble(valuesPerLine[6])); values.put("light", Long.parseLong(valuesPerLine[4])); db.insert(TABLE_NAME, null, values); }
From source file:Main.java
static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception { File extdir = Environment.getExternalStorageDirectory(); File tmp_top = new File(extdir, "tmp_LongText"); if (!tmp_top.exists()) { if (!tmp_top.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); }/*from w ww .j a va 2s .co m*/ if (!tmp_top.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); File tmpdir; Random r = new Random(); do { tmpdir = new File(tmp_top, String.format("%d", r.nextInt())); } while (tmpdir.exists()); if (!tmpdir.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); if (!tmpdir.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); ContentValues v = new ContentValues(); v.put("pid", Process.myPid()); v.put("tmpdir", tmpdir.getPath()); v.put("ctime", System.currentTimeMillis()); db.insert("tmpdir", null, v); return tmpdir; }
From source file:com.onesignal.NotificationBundleProcessor.java
private static void saveNotification(Context context, Bundle bundle, boolean opened, int notificationId) { try {//from w ww. ja va 2 s. co m JSONObject customJSON = new JSONObject(bundle.getString("custom")); OneSignalDbHelper dbHelper = new OneSignalDbHelper(context); SQLiteDatabase writableDb = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(NotificationTable.COLUMN_NAME_NOTIFICATION_ID, customJSON.getString("i")); if (bundle.containsKey("grp")) values.put(NotificationTable.COLUMN_NAME_GROUP_ID, bundle.getString("grp")); values.put(NotificationTable.COLUMN_NAME_OPENED, opened ? 1 : 0); if (!opened) values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, notificationId); if (bundle.containsKey("title")) values.put(NotificationTable.COLUMN_NAME_TITLE, bundle.getString("title")); values.put(NotificationTable.COLUMN_NAME_MESSAGE, bundle.getString("alert")); values.put(NotificationTable.COLUMN_NAME_FULL_DATA, bundleAsJSONObject(bundle).toString()); writableDb.insert(NotificationTable.TABLE_NAME, null, values); // Clean up old records that have been dismissed or opened already after 1 week. writableDb.delete(NotificationTable.TABLE_NAME, NotificationTable.COLUMN_NAME_CREATED_TIME + " < " + ((System.currentTimeMillis() / 1000) - 604800) + " AND " + "(" + NotificationTable.COLUMN_NAME_DISMISSED + " = 1 OR " + NotificationTable.COLUMN_NAME_OPENED + " = 1" + ")", null); writableDb.close(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static long insertOfflineSentPost(Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("foo", 1); long ret = dbwrite.insert("offline_sent_posts", null, cv); dbwrite.close();/*from w w w .j av a 2 s. c o m*/ db.close(); return ret; }
From source file:net.survivalpad.android.entity.AbsData.java
public long insert(SQLiteDatabase db) { ContentValues values = new ContentValues(); write(values);//w ww .ja v a 2 s . c om id = db.insert(getTableName(), null, values); return id; }
From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java
public static void saveVerses(SQLiteDatabase db, String translationShortName, int bookIndex, int chapterIndex, JSONObject versesObject) throws Exception { final ContentValues versesValues = new ContentValues(4); versesValues.put(DatabaseHelper.COLUMN_BOOK_INDEX, bookIndex); versesValues.put(DatabaseHelper.COLUMN_CHAPTER_INDEX, chapterIndex); final JSONArray paragraphArray = versesObject.getJSONArray("verses"); final int paragraphCount = paragraphArray.length(); boolean hasNonEmptyVerse = false; for (int verseIndex = 0; verseIndex < paragraphCount; ++verseIndex) { versesValues.put(DatabaseHelper.COLUMN_VERSE_INDEX, verseIndex); final String verse = paragraphArray.getString(verseIndex); if (!hasNonEmptyVerse && !TextUtils.isEmpty(verse)) hasNonEmptyVerse = true;//w ww. j a v a 2 s . co m versesValues.put(DatabaseHelper.COLUMN_TEXT, verse); db.insert(translationShortName, null, versesValues); } if (!hasNonEmptyVerse) { throw new Exception( String.format("Empty chapter: %s %d-%d", translationShortName, bookIndex, chapterIndex)); } }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void subscribeGroup(String group, Context context) { DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbwrite = dbhelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("profile_id", 1); cv.put("name", group); cv.put("lastFetched", -1); cv.put("unread_count", -1); dbwrite.insert("subscribed_groups", null, cv); dbwrite.close();/* w w w. jav a 2 s . com*/ dbhelper.close(); }
From source file:DictionaryDatabase.java
public long addRecord(String word, String definition) { SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(); values.put(FIELD_WORD, word);// ww w . j a v a 2 s . c o m values.put(FIELD_DEFINITION, definition); return db.insert(TABLE_DICTIONARY, null, values); }
From source file:com.manning.androidhacks.hack043.provider.BatchNumbersContentProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { ContentValues values;/*w ww . j a va 2s .c o m*/ if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } String table = null; String nullableCol = null; switch (sUriMatcher.match(uri)) { case ITEM: table = TABLE_NAME; break; default: new RuntimeException("Invalid URI for inserting: " + uri); } SQLiteDatabase db = dbHelper.getWritableDatabase(); long rowId = db.insert(table, nullableCol, values); if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(uri, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }