Java Code Examples for android.database.sqlite.SQLiteStatement.executeInsert()

The following are Jave code examples for showing how to use executeInsert() of the android.database.sqlite.SQLiteStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: buildAPKsApps   File: DataManager.java   Source Code and License Vote up 6 votes
public int createItem(int list_id, String label)
{
    Log.v(L.TAG, "DataManager.createItem(): Insert item " + label);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("insert into items (list_id,label,active) values (?,?,?)");        
    stmt.bindLong(1, list_id);
    stmt.bindString(2, label);
    stmt.bindLong(3, 1);
    long id = stmt.executeInsert();
    stmt.close();
    db.close();
    
    Log.d(L.TAG, "DataManager.createItem(): Inserted item and got id " + id);
    if(id == -1)
    {
        Log.e(L.TAG, "DataManager.createItem(): Attempt to insert item failed. Got " + id + " from executeInsert()");
    }
    return (int)id;
}
 
Example 2
Project: SQLite-Performance   File: IntegerSQLiteStatementTransactionCase.java   Source Code and License Vote up 6 votes
@Override
public Metrics runCase() {
    mDbHelper = new DbHelper(App.getInstance(), IntegerSQLiteStatementTransactionCase.class.getSimpleName());
    Metrics result = new Metrics(getClass().getSimpleName()+" ("+mInsertions+" insertions)", mTestSizeIndex);
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    result.started();
    SQLiteStatement stmt = db.compileStatement("INSERT INTO inserts_1 (val) VALUES (?)");
    db.beginTransaction();
    for (int i = 0; i < mInsertions; i++) {
        stmt.bindLong(1, mRandom.nextInt());
        stmt.executeInsert();
        stmt.clearBindings();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    result.finished();
    return result;
}
 
Example 3
Project: GitHub   File: AbstractDao.java   Source Code and License Vote up 5 votes
private long insertInsideTx(T entity, DatabaseStatement stmt) {
    synchronized (stmt) {
        if (isStandardSQLite) {
            SQLiteStatement rawStmt = (SQLiteStatement) stmt.getRawStatement();
            bindValues(rawStmt, entity);
            return rawStmt.executeInsert();
        } else {
            bindValues(stmt, entity);
            return stmt.executeInsert();
        }
    }
}
 
Example 4
Project: buildAPKsApps   File: DataManager.java   Source Code and License Vote up 5 votes
public void createList(String label)
{
    Log.d(L.TAG, "Insert list " + label);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("insert into lists (label) values (?)");        
    stmt.bindString(1, label);
    stmt.executeInsert();
    stmt.close();
    db.close();
}
 
Example 5
Project: SQLite-Performance   File: IntegerSQLiteStatementBatchTransactionCase.java   Source Code and License Vote up 5 votes
private void doInsertions(SQLiteDatabase db, int total, Map<Integer, SQLiteStatement> statementCache) {
    if (total > 999) {
        doInsertions(db, total - 999, statementCache);
        total = 999;
    }
    SQLiteStatement stmt;
    if (statementCache.containsKey(total)) {
        stmt = statementCache.get(total);
    } else {
        StringBuilder valuesBuilder = new StringBuilder();
        for (int i = 0; i < total; i++) {
            if (i > 0) {
                valuesBuilder.append(", ");
            }
            valuesBuilder.append("(?)");
        }
        stmt = db.compileStatement("INSERT INTO inserts_1 (val) VALUES "+valuesBuilder.toString());
        statementCache.put(total, stmt);
    }

    for (int i = 0; i < total; i++) {
        stmt.bindLong(i+1, mRandom.nextInt());
    }

    stmt.executeInsert();
    stmt.clearBindings();
}
 
Example 6
Project: sealtalk-android-master   File: RongDatabaseDriver.java   Source Code and License Vote up 5 votes
private <T> T executeInsert(
        SQLiteDatabase database,
        String query,
        ExecuteResultHandler<T> handler) {
    SQLiteStatement statement = database.compileStatement(query);
    long count = statement.executeInsert();
    return handler.handleInsert(count);
}
 
Example 7
Project: Android-SQLite-Master-Project   File: UserDao.java   Source Code and License Vote up 5 votes
private static void insertUser(@NonNull SQLiteStatement statement, @NonNull User user) {
    statement.bindLong(1, user.getId());
    bindString(statement, 2, user.getName());
    bindString(statement, 3, user.getSecondName());
    bindString(statement, 4, user.getEmail());
    bindDate(statement, 5, user.getBirthday());
    statement.executeInsert();
    statement.clearBindings();
}
 
Example 8
Project: Android-SQLite-Master-Project   File: UserMessagesRelationDao.java   Source Code and License Vote up 5 votes
private static void insertUserMessage(@NonNull SQLiteStatement statement,
                                      long userId, long messageId) {
    statement.bindLong(1, userId);
    statement.bindLong(2, messageId);
    statement.executeInsert();
    statement.clearBindings();
}
 
Example 9
Project: Bee-Analyzer   File: MapsActivity.java   Source Code and License Vote up 5 votes
public void InsertToSqlite(String imei, String latitude, String longitude, String out)
{
    SQLiteStatement statement = localdb.compileStatement("INSERT INTO position VALUES(?,?,?,datetime(),?)");
    statement.bindString(1, imei);
    statement.bindString(2, latitude);
    statement.bindString(3, longitude);
    statement.bindString(4, out);
    statement.executeInsert();
    statement.close();
}
 
Example 10
Project: SQLite-Performance   File: SQLiteStatementTestCase.java   Source Code and License Vote up 4 votes
@Override
public Metrics runCase() {
    mDbHelper = new DbHelper(App.getInstance(), getClass().getName());
    Metrics result = new Metrics(getClass().getSimpleName()+" ("+mInsertions+" insertions)", mTestSizeIndex);
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    Charset ascii = Charset.forName("US-ASCII");

    byte[] titleByteArry = new byte[50];
    byte[] urlByteArray = new byte[100];
    byte[] lyricsByteArray = new byte[2000];
    byte[] aboutByteArray = new byte[2000];

    result.started();
    db.beginTransaction();
    SQLiteStatement stmt = db.compileStatement("INSERT INTO tracks (id, title, band_id, duration, url, lyrics, about, release_date, mod_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
    for (int i = 0; i < mInsertions; i++) {
        mRandom.nextBytes(titleByteArry);
        mRandom.nextBytes(urlByteArray);
        mRandom.nextBytes(lyricsByteArray);
        mRandom.nextBytes(aboutByteArray);

        stmt.bindLong(1, i);
        stmt.bindString(2, new String(titleByteArry, ascii));
        stmt.bindLong(3, mRandom.nextInt());
        stmt.bindDouble(4, mRandom.nextDouble());
        stmt.bindString(5, new String(urlByteArray, ascii));
        stmt.bindString(6, new String(lyricsByteArray, ascii));
        stmt.bindString(7, new String(aboutByteArray, ascii));
        stmt.bindLong(8, mRandom.nextLong());
        stmt.bindLong(9, mRandom.nextLong());

        stmt.executeInsert();
        stmt.clearBindings();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    result.finished();

    return result;
}
 
Example 11
Project: SQLite-Performance   File: BatchedSQLiteStatementTestCase.java   Source Code and License Vote up 4 votes
private void doInsertions(SQLiteDatabase db, int total, Map<Integer, SQLiteStatement> statementCache, byte[] titleByteArray, byte[] urlByteArray, byte[] lyricsByteArray, byte[] aboutByteArray) {
    // divide 999 by 9 since that's the # of fields in our table
    if (total > 999/9) {
        doInsertions(db, total-999/9, statementCache, titleByteArray, urlByteArray, lyricsByteArray, aboutByteArray);
        total = 999/9;
    }
    SQLiteStatement stmt;
    if (statementCache.containsKey(total)) {
        stmt = statementCache.get(total);
    } else {
        StringBuilder valueBuilder = new StringBuilder();
        for (int i = 0; i < total; i++) {
            if (i > 0) {
                valueBuilder.append(", ");
            }
            valueBuilder.append("(?, ?, ?, ?, ?, ?, ?, ?, ?)");
        }
        stmt = db.compileStatement("INSERT INTO tracks (id, title, band_id, duration, url, lyrics, about, release_date, mod_date) VALUES "+valueBuilder.toString());
        statementCache.put(total, stmt);
    }

    Charset ascii = Charset.forName("US-ASCII");
    for (int i = 0; i < total; i++) {
        mRandom.nextBytes(titleByteArray);
        mRandom.nextBytes(urlByteArray);
        mRandom.nextBytes(lyricsByteArray);
        mRandom.nextBytes(aboutByteArray);

        stmt.bindLong(9*i+1, mInsertId++);
        stmt.bindString(9*i+2, new String(titleByteArray, ascii));
        stmt.bindLong(9*i+3, mRandom.nextInt());
        stmt.bindDouble(9*i+4, mRandom.nextDouble());
        stmt.bindString(9*i+5, new String(urlByteArray, ascii));
        stmt.bindString(9*i+6, new String(lyricsByteArray, ascii));
        stmt.bindString(9*i+7, new String(aboutByteArray, ascii));
        stmt.bindLong(9*i+8, mRandom.nextLong());
        stmt.bindLong(9*i+9, mRandom.nextLong());
    }

    stmt.executeInsert();
    stmt.clearBindings();
}