當前位置: 首頁>>代碼示例>>Java>>正文


Java SQLiteStatement.executeInsert方法代碼示例

本文整理匯總了Java中android.database.sqlite.SQLiteStatement.executeInsert方法的典型用法代碼示例。如果您正苦於以下問題:Java SQLiteStatement.executeInsert方法的具體用法?Java SQLiteStatement.executeInsert怎麽用?Java SQLiteStatement.executeInsert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.database.sqlite.SQLiteStatement的用法示例。


在下文中一共展示了SQLiteStatement.executeInsert方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createItem

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
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;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:21,代碼來源:DataManager.java

示例2: runCase

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
@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;
}
 
開發者ID:jasonwyatt,項目名稱:SQLite-Performance,代碼行數:20,代碼來源:IntegerSQLiteStatementTransactionCase.java

示例3: insertInsideTx

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
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();
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:AbstractDao.java

示例4: createList

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
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();
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:12,代碼來源:DataManager.java

示例5: doInsertions

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
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();
}
 
開發者ID:jasonwyatt,項目名稱:SQLite-Performance,代碼行數:28,代碼來源:IntegerSQLiteStatementBatchTransactionCase.java

示例6: executeInsert

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
private <T> T executeInsert(
        SQLiteDatabase database,
        String query,
        ExecuteResultHandler<T> handler) {
    SQLiteStatement statement = database.compileStatement(query);
    long count = statement.executeInsert();
    return handler.handleInsert(count);
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:9,代碼來源:RongDatabaseDriver.java

示例7: insertUser

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
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();
}
 
開發者ID:shevart,項目名稱:Android-SQLite-Master-Project,代碼行數:10,代碼來源:UserDao.java

示例8: insertUserMessage

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
private static void insertUserMessage(@NonNull SQLiteStatement statement,
                                      long userId, long messageId) {
    statement.bindLong(1, userId);
    statement.bindLong(2, messageId);
    statement.executeInsert();
    statement.clearBindings();
}
 
開發者ID:shevart,項目名稱:Android-SQLite-Master-Project,代碼行數:8,代碼來源:UserMessagesRelationDao.java

示例9: InsertToSqlite

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
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();
}
 
開發者ID:sarikaya,項目名稱:Bee-Analyzer,代碼行數:11,代碼來源:MapsActivity.java

示例10: runCase

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
@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;
}
 
開發者ID:jasonwyatt,項目名稱:SQLite-Performance,代碼行數:42,代碼來源:SQLiteStatementTestCase.java

示例11: doInsertions

import android.database.sqlite.SQLiteStatement; //導入方法依賴的package包/類
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();
}
 
開發者ID:jasonwyatt,項目名稱:SQLite-Performance,代碼行數:43,代碼來源:BatchedSQLiteStatementTestCase.java


注:本文中的android.database.sqlite.SQLiteStatement.executeInsert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。