@SuppressWarnings("StringConcatenationInsideStringBufferAppend") public long insertWithOnConflict(String table,String nullColumnHack,ContentValues initialValues,@ConflictAlgorithm int conflictAlgorithm){
  acquireReference();
  try {
    StringBuilder sql=new StringBuilder();
    sql.append("INSERT");
    sql.append(CONFLICT_VALUES[conflictAlgorithm]);
    sql.append(" INTO ");
    sql.append(table);
    sql.append('(');
    Object[] bindArgs=null;
    int size=(initialValues != null && initialValues.size() > 0) ? initialValues.size() : 0;
    if (size > 0) {
      bindArgs=new Object[size];
      int i=0;
      for (      Map.Entry<String,Object> entry : initialValues.valueSet()) {
        sql.append((i > 0) ? "," : "");
        sql.append(entry.getKey());
        bindArgs[i++]=entry.getValue();
      }
      sql.append(')');
      sql.append(" VALUES (");
      for (i=0; i < size; i++) {
        sql.append((i > 0) ? ",?" : "?");
      }
    }
 else {
      sql.append(nullColumnHack + ") VALUES (NULL");
    }
    sql.append(')');
    SQLiteStatement statement=new SQLiteStatement(this,sql.toString(),bindArgs);
    try {
      return statement.executeInsert();
    }
  finally {
      statement.close();
    }
  }
  finally {
    releaseReference();
  }
}

@ SuppressWarnings ( "StringConcatenationInsideStringBufferAppend" ) public long insertWithOnConflict ( String table , String nullColumnHack , ContentValues initialValues , @ ConflictAlgorithm int conflictAlgorithm ) { acquireReference ( ) ; try { StringBuilder sql = new StringBuilder ( ) ; sql . append ( "INSERT" ) ; sql . append ( CONFLICT_VALUES [ conflictAlgorithm ] ) ; sql . append ( " INTO " ) ; sql . append ( table ) ; sql . append ( '(' ) ; Object [ ] bindArgs = null ; int size = ( initialValues != null && initialValues . size ( ) > 0 ) ? initialValues . size ( ) : 0 ; if ( size > 0 ) { bindArgs = new Object [ size ] ; int i = 0 ; for ( Map . Entry < String , Object > entry : initialValues . valueSet ( ) ) { sql . append ( ( i > 0 ) ? "," : "" ) ; sql . append ( entry . getKey ( ) ) ; bindArgs [ i ++ ] = entry . getValue ( ) ; } sql . append ( ')' ) ; sql . append ( " VALUES (" ) ; for ( i = 0 ; i < size ; i ++ ) { sql . append ( ( i > 0 ) ? ",?" : "?" ) ; } } else { sql . append ( nullColumnHack + ") VALUES (NULL" ) ; } sql . append ( ')' ) ; SQLiteStatement statement = new SQLiteStatement ( this , sql . toString ( ) , bindArgs ) ; try { return statement . executeInsert ( ) ; } finally { statement . close ( ) ; } } finally { releaseReference ( ) ; } }
general method for inserting a row into the database .
