int numInserts = 0; db.beginTransaction(); insertHelper = new DatabaseUtils.InsertHelper(db, th.getTableName()); try {
final int guiStrColumn = inserter.getColumnIndex(Guys.STRINGCOLUMNTYPE); final int guyDoubleColumn = inserter.getColumnIndex(Guys.DOUBLECOLUMNTYPE); final int guyIntColumn = inserter.getColumnIndex(Guys.INTEGERCOLUMUNTYPE); int len = values.length; for (int i = 0; i < len; i++) { inserter.prepareForInsert(); inserter.bind(guiStrColumn, guyID); inserter.bind(guyDoubleColumn, lat); inserter.bind(guyIntColumn, status); inserter.execute(); } finally { db.endTransaction(); inserter.close();
resources.openRawResource(coupleResourceFichier.resourceId)), 8 << 10); dataBaseHelper.beginTransaction(); final InsertHelper ih = new InsertHelper(db, table.getName()); try { final int arretIdCol = ih.getColumnIndex("arretId"); final int trajetIdCol = ih.getColumnIndex("trajetId"); final int heureDepartCol = ih.getColumnIndex("heureDepart"); final int stopSequenceCol = ih.getColumnIndex("stopSequence"); final int terminusCol = ih.getColumnIndex("terminus"); bufReader.close(); dataBaseHelper.endTransaction(); ih.close();
private void insertData(SQLiteDatabase db) { Pattern p = Pattern.compile("\t"); InsertHelper ih = new InsertHelper(db, Cities.TABLE_NAME); final int idColumn = ih.getColumnIndex(Cities._ID); final int nameColumn = ih.getColumnIndex(Cities.NAME); final int asciiNameColumn = ih.getColumnIndex(Cities.ASCII_NAME); final int latitudeColumn = ih.getColumnIndex(Cities.LATITUDE); final int longitudeColumn = ih.getColumnIndex(Cities.LONGITUDE); final int countryColumn = ih.getColumnIndex(Cities.COUNTRY); final int timezoneColumn = ih.getColumnIndex(Cities.TIMEZONE_ID); while (line != null) { ih.prepareForInsert(); ih.bind(idColumn, id++); ih.bind(nameColumn, rawValues[0]); ih.bind(asciiNameColumn, rawValues[1]); ih.bind(latitudeColumn, Double.parseDouble(rawValues[2])); ih.bind(longitudeColumn, Double.parseDouble(rawValues[3])); ih.bind(countryColumn, rawValues[4]); ih.bind(timezoneColumn, rawValues[5]); ih.execute(); throw new RuntimeException(e.getMessage(), e); } finally { ih.close();
List<MessageBean> msgList = list.getItemList(); DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), HomeOtherGroupTable.HomeOtherGroupDataTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.JSONDATA); final int groupidColumn = ih.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.GROUPID); ih.prepareForInsert(); if (msg != null) { ih.bind(mblogidColumn, msg.getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); ih.bind(groupidColumn, groupId); } else { ih.bind(mblogidColumn, "-1"); ih.bind(accountidColumn, accountId); ih.bind(jsondataColumn, ""); ih.bind(groupidColumn, groupId); ih.execute(); } finally { getWsd().endTransaction(); ih.close();
private static void add(List<FavBean> msgList, int page, String accountId) { Gson gson = new Gson(); DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), FavouriteTable.FavouriteDataTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(FavouriteTable.FavouriteDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(FavouriteTable.FavouriteDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(FavouriteTable.FavouriteDataTable.JSONDATA); ih.prepareForInsert(); ih.bind(mblogidColumn, msg.getStatus().getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); ih.execute(); ih.close();
/** * Efficiently insert a collection of entities using {@link InsertHelper}. * * @param many Collection of objects * @return count of inserted objects or -1 immediately if any errors */ public long insertMany(Iterable<T> many) { long numInserted = 0; InsertHelper insertHelper = new DatabaseUtils.InsertHelper(getWritableDb(), th.getTableName()); getWritableDb().beginTransaction(); try { for (T obj : many) { ContentValues cv = th.getEditableValues(obj); if (th.getId(obj) == 0) { // the default, remove from ContentValues to allow autoincrement cv.remove(th.getIdCol().toString()); } long id = insertHelper.insert(cv); if (id == -1) return -1; numInserted++; } getWritableDb().setTransactionSuccessful(); } finally { getWritableDb().endTransaction(); } return numInserted; }
int size = msgList.size(); DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), RepostsTable.RepostDataTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(RepostsTable.RepostDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(RepostsTable.RepostDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(RepostsTable.RepostDataTable.JSONDATA); ih.prepareForInsert(); if (msg != null) { ih.bind(mblogidColumn, msg.getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); } else { ih.bind(mblogidColumn, "-1"); ih.bind(accountidColumn, accountId); ih.bind(jsondataColumn, ""); ih.execute(); } finally { getWsd().endTransaction(); ih.close();
List<CommentBean> msgList = list.getItemList(); DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), CommentByMeTable.CommentByMeDataTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(CommentByMeTable.CommentByMeDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(CommentByMeTable.CommentByMeDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(CommentByMeTable.CommentByMeDataTable.JSONDATA); for (CommentBean msg : msgList) { ih.prepareForInsert(); if (msg != null) { ih.bind(mblogidColumn, msg.getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); } else { ih.bind(mblogidColumn, "-1"); ih.bind(accountidColumn, accountId); ih.bind(jsondataColumn, ""); ih.execute(); } finally { getWsd().endTransaction(); ih.close();
List<CommentBean> msgList = list.getItemList(); DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), CommentsTable.CommentsDataTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(CommentsTable.CommentsDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(CommentsTable.CommentsDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(CommentsTable.CommentsDataTable.JSONDATA); for (CommentBean msg : msgList) { ih.prepareForInsert(); if (msg != null) { ih.bind(mblogidColumn, msg.getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); ih.bind(mblogidColumn, "-1"); ih.bind(accountidColumn, accountId); ih.bind(jsondataColumn, ""); ih.execute(); } finally { getWsd().endTransaction(); ih.close();
DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), HomeTable.HomeDataTable.HOME_DATA_TABLE); final int mblogidColumn = ih.getColumnIndex(HomeTable.HomeDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(HomeTable.HomeDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(HomeTable.HomeDataTable.JSONDATA); try { getWsd().beginTransaction(); for (int i = 0; i < msgList.size(); i++) { MessageBean msg = msgList.get(i); ih.prepareForInsert(); if (msg != null) { ih.bind(mblogidColumn, msg.getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); } else { ih.bind(mblogidColumn, "-1"); ih.bind(accountidColumn, accountId); ih.bind(jsondataColumn, ""); ih.execute(); } finally { getWsd().endTransaction(); ih.close();
DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), MyStatusTable.StatusDataTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(MyStatusTable.StatusDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(MyStatusTable.StatusDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(MyStatusTable.StatusDataTable.JSONDATA); try { getWsd().beginTransaction(); for (int i = 0; i < msgList.size(); i++) { MessageBean msg = msgList.get(i); ih.prepareForInsert(); if (msg != null) { ih.bind(mblogidColumn, msg.getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); } else { ih.bind(mblogidColumn, "-1"); ih.bind(accountidColumn, accountId); ih.bind(jsondataColumn, ""); ih.execute(); } finally { getWsd().endTransaction(); ih.close();
public static void addCommentLineMsg(CommentListBean list, String accountId) { Gson gson = new Gson(); List<CommentBean> msgList = list.getItemList(); DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), MentionCommentsTable.MentionCommentsDataTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(MentionCommentsTable.MentionCommentsDataTable.MBLOGID); final int accountidColumn = ih.getColumnIndex(MentionCommentsTable.MentionCommentsDataTable.ACCOUNTID); final int jsondataColumn = ih.getColumnIndex(MentionCommentsTable.MentionCommentsDataTable.JSONDATA); try { getWsd().beginTransaction(); for (CommentBean msg : msgList) { ih.prepareForInsert(); ih.bind(mblogidColumn, msg.getId()); ih.bind(accountidColumn, accountId); String json = gson.toJson(msg); ih.bind(jsondataColumn, json); ih.execute(); } getWsd().setTransactionSuccessful(); } catch (SQLException e) { } finally { getWsd().endTransaction(); ih.close(); } reduceCommentTable(accountId); }
private static void add(String accountId, List<String> list) { if (list == null || list.size() == 0) { return; } DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), TopicTable.TABLE_NAME); final int accountidColumn = ih.getColumnIndex(TopicTable.ACCOUNTID); final int nameColumn = ih.getColumnIndex(TopicTable.TOPIC_NAME); try { getWsd().beginTransaction(); for (int i = 0; i < list.size(); i++) { String name = list.get(i); ih.prepareForInsert(); ih.bind(accountidColumn, accountId); ih.bind(nameColumn, name); ih.execute(); } getWsd().setTransactionSuccessful(); } catch (SQLException e) { } finally { getWsd().endTransaction(); ih.close(); } }
public static void addUnreadNotification(String accountId, ArrayList<String> msgIds, UnreadDBType type) { DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), NotificationTable.TABLE_NAME); final int mblogidColumn = ih.getColumnIndex(NotificationTable.MSGID); final int accountidColumn = ih.getColumnIndex(NotificationTable.ACCOUNTID); final int typeColumn = ih.getColumnIndex(NotificationTable.TYPE); try { getWsd().beginTransaction(); for (String msg : msgIds) { ih.prepareForReplace(); ih.bind(mblogidColumn, msg); ih.bind(accountidColumn, accountId); ih.bind(typeColumn, type.getValue()); ih.execute(); } getWsd().setTransactionSuccessful(); } catch (SQLException ignored) { } finally { getWsd().endTransaction(); ih.close(); } }
public static void addFilterKeyword(int type, Collection<String> words) { DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), FilterTable.TABLE_NAME); final int nameColumn = ih.getColumnIndex(FilterTable.NAME); final int activeColumn = ih.getColumnIndex(FilterTable.ACTIVE); final int typeColumn = ih.getColumnIndex(FilterTable.TYPE); try { getWsd().beginTransaction(); for (String word : words) { ih.prepareForInsert(); ih.bind(nameColumn, word); ih.bind(activeColumn, true); ih.bind(typeColumn, type); ih.execute(); } getWsd().setTransactionSuccessful(); } catch (SQLException e) { } finally { getWsd().endTransaction(); ih.close(); } }
/** * Parse the values in a CSV row, map them to the table column * order, and insert. Uses {@link InsertHelper} so it may be * called repeatedly within a transaction for max performance. * * @param csvRow * @return row ID of the newly inserted row or -1 */ private long parseAndInsertRow(String csvRow) { List<String> textValues = CsvUtils.getValues(csvRow); insertHelper.prepareForInsert(); String[] rowValues = textValues.toArray(new String[textValues.size()]); th.bindRowValues(insertHelper, rowValues); return insertHelper.execute(); }
database.beginTransaction(); DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(database,TABLE_NAME); final int column = ih.getColumnIndex(COLUMN_NAME); ih.prepareForInsert(); ih.bind(column, columnData); ih.execute(); ih.close(); database.setTransactionSuccessful(); database.endTransaction();}