Example #1
0
  /** @inheritdoc */
  @Override
  protected void bindValues(SQLiteStatement stmt, SqliteMaster entity) {
    stmt.clearBindings();

    String type = entity.getType();
    if (type != null) {
      stmt.bindString(1, type);
    }

    String name = entity.getName();
    if (name != null) {
      stmt.bindString(2, name);
    }

    String tableName = entity.getTableName();
    if (tableName != null) {
      stmt.bindString(3, tableName);
    }

    Long rootpage = entity.getRootpage();
    if (rootpage != null) {
      stmt.bindLong(4, rootpage);
    }

    String sql = entity.getSql();
    if (sql != null) {
      stmt.bindString(5, sql);
    }
  }
 /**
  * Performs an insert, adding a new row with the given values.
  *
  * @param values the set of values with which to populate the new row
  * @param allowReplace if true, the statement does "INSERT OR REPLACE" instead of "INSERT",
  *     silently deleting any previously existing rows that would cause a conflict
  * @return the row ID of the newly inserted row, or -1 if an error occurred
  */
 private synchronized long insertInternal(ContentValues values, boolean allowReplace) {
   try {
     SQLiteStatement stmt = getStatement(allowReplace);
     stmt.clearBindings();
     if (LOCAL_LOGV) Log.v(TAG, "--- inserting in table " + mTableName);
     for (Map.Entry<String, Object> e : values.valueSet()) {
       final String key = e.getKey();
       int i = getColumnIndex(key);
       DatabaseUtils.bindObjectToProgram(stmt, i, e.getValue());
       if (LOCAL_LOGV) {
         Log.v(TAG, "binding " + e.getValue() + " to column " + i + " (" + key + ")");
       }
     }
     return stmt.executeInsert();
   } catch (SQLException e) {
     Log.e(TAG, "Error inserting " + values + " into table  " + mTableName, e);
     return -1;
   }
 }
 /**
  * Prepare the InsertHelper for a replace. The pattern for this is:
  *
  * <ul>
  *   <li>prepareForReplace()
  *   <li>bind(index, value);
  *   <li>bind(index, value);
  *   <li>...
  *   <li>bind(index, value);
  *   <li>execute();
  * </ul>
  */
 public void prepareForReplace() {
   mPreparedStatement = getStatement(true);
   mPreparedStatement.clearBindings();
 }
 /**
  * Prepare the InsertHelper for an insert. The pattern for this is:
  *
  * <ul>
  *   <li>prepareForInsert()
  *   <li>bind(index, value);
  *   <li>bind(index, value);
  *   <li>...
  *   <li>bind(index, value);
  *   <li>execute();
  * </ul>
  */
 public void prepareForInsert() {
   mPreparedStatement = getStatement(false);
   mPreparedStatement.clearBindings();
 }