本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.compileStatement方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.compileStatement方法的具体用法?Java SQLiteDatabase.compileStatement怎么用?Java SQLiteDatabase.compileStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.compileStatement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInsertStatement
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
SQLiteStatement createInsertStatement(SQLiteDatabase database) {
return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " +
PERSON + ", " +
DATE_SENT + ", " +
DATE_RECEIVED + ", " +
PROTOCOL + ", " +
READ + ", " +
STATUS + ", " +
TYPE + ", " +
REPLY_PATH_PRESENT + ", " +
SUBJECT + ", " +
BODY + ", " +
SERVICE_CENTER +
", " + THREAD_ID + ") " +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
}
示例2: createItem
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的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;
}
示例3: insert
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();
List<String> segments = uri.getPathSegments();
String recordId = segments.get(1);
String name = segments.get(3);
String insertView = "Insert or replace into views (record_id, name, query, date_synced) values(?,?,?,?)";
SQLiteStatement insertViewStmt = sqlDb.compileStatement(insertView);
insertViewStmt.bindString(1, recordId);
insertViewStmt.bindString(2, name);
insertViewStmt.bindString(3, values.getAsString("query"));
insertViewStmt.bindString(4, values.getAsString("date_synced"));
insertViewStmt.execute();
getContext()
.getContentResolver()
.notifyChange(uri, null);
return uri;
}
示例4: addAll
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
static void addAll(SQLiteDatabase database, List<OpenLocateLocation> locations) {
if (database == null || locations == null || locations.isEmpty()) {
return;
}
SQLiteStatement statement = database.compileStatement(BULK_INSERT_LOCATION);
database.beginTransaction();
for (OpenLocateLocation location : locations) {
statement.clearBindings();
statement.bindString(COLUMN_LOCATION_INDEX, location.getJson().toString());
statement.bindLong(2, location.getCreated().getTime());
statement.execute();
}
database.setTransactionSuccessful();
database.endTransaction();
}
示例5: saveUserMessagesRelations
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static void saveUserMessagesRelations(@NonNull SQLiteDatabase database,
@NonNull User user) {
if (Utils.isNullOrEmpty(user.getMessages())) {
return;
}
final SQLiteStatement statement = database.compileStatement(UserMessagesRelationContract.Script.Insert.INSERT);
try {
database.beginTransaction();
for (Message message : user.getMessages())
insertUserMessage(statement, user.getId(), message.getId());
database.setTransactionSuccessful();
} finally {
database.setTransactionSuccessful();
}
}
示例6: countItemsInList
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private int countItemsInList(SQLiteDatabase db, int listId)
{
SQLiteStatement stmt = db.compileStatement("select count(*) from items where list_id=?");
stmt.bindLong(1, listId);
int rv = (int)stmt.simpleQueryForLong();
stmt.close();
return rv;
}
示例7: blobFileDescriptorForQuery
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Utility method to run the query on the db and return the blob value in the
* first column of the first row.
*
* @return A read-only file descriptor for a copy of the blob value.
*/
public static ParcelFileDescriptor blobFileDescriptorForQuery(SQLiteDatabase db,
String query, String[] selectionArgs) {
SQLiteStatement prog = db.compileStatement(query);
try {
return blobFileDescriptorForQuery(prog, selectionArgs);
} finally {
prog.close();
}
}
示例8: createFiles
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void createFiles(SQLiteDatabase db) {
mFileNames = new String[mFiles];
byte[] rawData = new byte[mFileSize+mFiles];
Random random = new Random();
random.nextBytes(rawData);
ByteArrayOutputStream[] streams = new ByteArrayOutputStream[mFiles];
for (int i = 0; i < mFiles; i++) {
streams[i] = new ByteArrayOutputStream(mFileSize);
streams[i].write(rawData, i, mFileSize);
mFileNames[i] = String.valueOf(i);
}
SQLiteStatement insert = db.compileStatement("INSERT INTO files (filename, data) VALUES (?, ?)");
for (int i = 0; i < mFiles; i++) {
insert.bindString(1, mFileNames[i]);
insert.bindBlob(2, streams[i].toByteArray());
insert.execute();
}
}
示例9: updateLocation
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void updateLocation(LocationModel locationModel) {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteStatement stmt = db.compileStatement(Constants.UPDATE_TABLE_LOCATION);
stmt.bindString(1, locationModel.getName());
stmt.bindDouble(2, locationModel.getLongitude());
stmt.bindDouble(3, locationModel.getLatitude());
stmt.bindString(4, locationModel.getAddress());
stmt.bindString(5, locationModel.getDescription());
stmt.bindLong(6, locationModel.getId());
stmt.execute();
}
示例10: executeInsert
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的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);
}
示例11: save
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static User save(@NonNull SQLiteDatabase database, @NonNull User user) {
final SQLiteStatement statement = database.compileStatement(UserContract.Script.Insert.INSERT);
try {
database.beginTransaction();
insertUser(statement, user);
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
return user;
}
示例12: countInactiveItemsInList
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private int countInactiveItemsInList(SQLiteDatabase db, int listId)
{
SQLiteStatement stmt = db.compileStatement("select count(*) from items where list_id=? and active=1");
stmt.bindLong(1, listId);
int rv = (int)stmt.simpleQueryForLong();
stmt.close();
return rv;
}
示例13: deleteItem
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void deleteItem(int itemId)
{
Log.d(L.TAG, "Deleting item " + itemId);
SQLiteDatabase db = helper.getWritableDatabase();
SQLiteStatement stmt = db.compileStatement("delete from items where id=?");
stmt.bindLong(1, itemId);
stmt.execute();
stmt.close();
db.close();
}
示例14: performSetItem
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
SQLiteDatabase database = mDatabaseSupplier.getDatabase();
if (database == null) {
return false;
}
WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")");
String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);";
SQLiteStatement statement = null;
String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date());
try {
statement = database.compileStatement(sql);
statement.clearBindings();
statement.bindString(1, key);
statement.bindString(2, value);
statement.bindString(3, timeStamp);
statement.bindLong(4, isPersistent ? 1 : 0);
statement.execute();
return true;
} catch (Exception e) {
WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
if (e instanceof SQLiteFullException) {
if (allowRetryWhenFull && trimToSize()) {
//try again
//setItem/setItemPersistent method only allow try once when occurred a sqliteFullException.
WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")");
return performSetItem(key, value, isPersistent, false);
}
}
return false;
} finally {
if(statement != null) {
statement.close();
}
}
}
示例15: stringForQuery
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Utility method to run the query on the db and return the value in the
* first column of the first row.
*/
public static String stringForQuery(SQLiteDatabase db, String query, String[] selectionArgs) {
SQLiteStatement prog = db.compileStatement(query);
try {
return stringForQuery(prog, selectionArgs);
} finally {
prog.close();
}
}