本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.execSQL方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.execSQL方法的具体用法?Java SQLiteDatabase.execSQL怎么用?Java SQLiteDatabase.execSQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.execSQL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUpgrade
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d("DB_UPGRADE", "Updating " + AppChoiceTable.NAME + " table to version " +
newVersion + " from version " + oldVersion);
Cursor cursor = db.query(AppChoiceTable.NAME, null, null, null, null, null, null);
ArrayList<String> existentColumns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
cursor.close();
ArrayList<String> missingColumns = AppChoiceTable.Cols.NAME_LIST;
missingColumns.removeAll(existentColumns);
try {
for (String columnName : missingColumns) {
Log.d("DB_UPGRADE", "Adding column " + columnName + " to table using: " +
mDbAlterCommands.get(columnName));
db.execSQL(mDbAlterCommands.get(columnName));
}
} catch (Exception e) {
Log.e("DB_UPGRADE", "Failed to upgrade DB: " + e.getMessage());
Toast.makeText(mContext, "App update has an issue! Please send logs to developer!", Toast.LENGTH_LONG).show();
}
}
示例2: purgeAccountAtDate
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void purgeAccountAtDate(Account account, long date) {
long nearestTransactionId = findNearestOlderTransactionId(account, date);
if (nearestTransactionId > 0) {
SQLiteDatabase db = db();
db.beginTransaction();
try {
Transaction newTransaction = createTransactionFromNearest(account, nearestTransactionId);
breakSplitTransactions(account, date);
deleteOldTransactions(account, date);
insertWithoutUpdatingBalance(newTransaction);
db.execSQL(INSERT_RUNNING_BALANCE, new Object[]{account.id, newTransaction.id, newTransaction.dateTime, newTransaction.fromAmount});
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
}
示例3: headersPruneOrphans
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static void headersPruneOrphans(SQLiteDatabase db) {
try {
db.execSQL("DELETE FROM headers WHERE id in (SELECT headers.id FROM headers LEFT JOIN messages ON headers.message_id = messages.id WHERE messages.id IS NULL)");
} catch (SQLiteException e) {
Timber.e("Unable to remove extra header data from the database");
}
}
示例4: createFeedListsTable
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void createFeedListsTable(SQLiteDatabase db) {
String sql = "CREATE TABLE [" + FeedListsColumns.TABLENAME + "] (\n" +
" [" + FeedListsColumns._ID + "] INTEGER NOT NULL UNIQUE, " +
" [" + FeedListsColumns.TITLE + "] TEXT, " +
" [" + FeedListsColumns.NO_REPOSTS + "] BOOLEAN, " +
" [" + FeedListsColumns.SOURCE_IDS + "] TEXT, " +
" CONSTRAINT [] PRIMARY KEY([" + UserColumns._ID + "]) ON CONFLICT REPLACE);";
db.execSQL(sql);
}
示例5: onRobustUpgrade
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onRobustUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) throws SQLiteException {
switch (oldVersion) {
case 1:
db.execSQL("ALTER TABLE " + TABLE_PUBKEYS
+ " ADD COLUMN " + FIELD_PUBKEY_CONFIRMUSE + " INTEGER DEFAULT 0");
db.execSQL("ALTER TABLE " + TABLE_PUBKEYS
+ " ADD COLUMN " + FIELD_PUBKEY_LIFETIME + " INTEGER DEFAULT 0");
}
}
示例6: onCreate
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " +TABLE_HOMEPOST+ "( "
+NOTIFICATION_ID+ " text , "
+NOTIFICATION_small_icon+ " text , "
+NOTIFICATION_TITLE+ " text , "
+NOTIFICATION_BODY+" text , "
+NOTIFICATION_LARGE_ICON+" text , "
+NOTIFICATION_BIG_PICTURE+" text , "
+NOTIFICATION_LAUNCH_URL+" text )");
}
示例7: migrateProfileId
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Updates profile id of all entries and changes the default value for the column.
*/
private void migrateProfileId(SQLiteDatabase db, long newProfileId) {
// Update existing entries.
ContentValues values = new ContentValues();
values.put(Favorites.PROFILE_ID, newProfileId);
db.update(Favorites.TABLE_NAME, values, null, null);
// Change default value of the column.
db.execSQL("ALTER TABLE favorites RENAME TO favorites_old;");
Favorites.addTableToDb(db, newProfileId, false);
db.execSQL("INSERT INTO favorites SELECT * FROM favorites_old;");
db.execSQL("DROP TABLE favorites_old;");
}
示例8: onUpgrade
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 1 && newVersion == 2) {
db.execSQL("CREATE TABLE IF NOT EXISTS "
+ RESPONSE_FILENAME_TABLE_NAME + "( "
+ URL + " VARCHAR NOT NULL PRIMARY KEY, "
+ FILENAME + " VARCHAR NOT NULL)"
);
}
}
示例9: onCreate
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_META + "(" + COL_TIMETABLE_ID + " TEXT PRIMARY KEY," + COL_MODIFIED_MILLIS + " INTEGER)");
db.execSQL("CREATE TABLE " + TABLE_DAYS + "(" + COL_DAY_ID + " INTEGER," + COL_NAME + " TEXT," + COL_SHORT_NAME + " TEXT," + COL_TIMETABLE_ID + " INTEGER, PRIMARY KEY (" + COL_DAY_ID + ", " + COL_TIMETABLE_ID + "))");
db.execSQL("CREATE TABLE " + TABLE_PERIODS + "(" + COL_PERIOD_ID + " INTEGER," + COL_START_TIME + " TEXT," + COL_END_TIME + " TEXT," + COL_TIMETABLE_ID + " INTEGER, PRIMARY KEY (" + COL_PERIOD_ID + ", " + COL_TIMETABLE_ID + "))");
db.execSQL("CREATE TABLE " + TABLE_FORMS + "(" + COL_FORM_ID + " INTEGER," + COL_NAME + " TEXT," + COL_SHORT_NAME + " TEXT," + COL_TEACHER_ID + " INTEGER," + COL_TIMETABLE_ID + " INTEGER, PRIMARY KEY (" + COL_FORM_ID + ", " + COL_TIMETABLE_ID + "))");
db.execSQL("CREATE TABLE " + TABLE_SUBJECTS + "(" + COL_SUBJECT_ID + " INTEGER," + COL_NAME + " TEXT," + COL_SHORT_NAME + " TEXT," + COL_TIMETABLE_ID + " INTEGER, PRIMARY KEY (" + COL_SUBJECT_ID + ", " + COL_TIMETABLE_ID + "))");
db.execSQL("CREATE TABLE " + TABLE_CLASSROOMS + "(" + COL_CLASSROOM_ID + " INTEGER," + COL_NAME + " TEXT," + COL_SHORT_NAME + " TEXT," + COL_TIMETABLE_ID + " INTEGER, PRIMARY KEY (" + COL_CLASSROOM_ID + ", " + COL_TIMETABLE_ID + "))");
db.execSQL("CREATE TABLE " + TABLE_TEACHERS + "(" + COL_TEACHER_ID + " INTEGER," + COL_NAME + " TEXT," + COL_SHORT_NAME + " TEXT," + COL_COLOUR + " INTEGER," + COL_TIMETABLE_ID + " INTEGER, PRIMARY KEY (" + COL_TEACHER_ID + ", " + COL_TIMETABLE_ID + "))");
db.execSQL("CREATE TABLE " + TABLE_SCHEDULES + "(" + COL_DAY_ID + " INTEGER," + COL_PERIOD_ID + " INTEGER," + COL_CLASSROOM_ID + " INTEGER," + COL_TEACHER_ID + " INTEGER," + COL_SUBJECT_ID + " INTEGER," + COL_FORM_ID + " TEXT," + COL_TIMETABLE_ID + " INTEGER)");
}
示例10: onUpgrade
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_USER);
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_IMAGE);
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_SESSION);
onCreate(sqLiteDatabase);
}
示例11: onCreate
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE "+TABLENAME+" ( "+ID+" INTEGER PRIMARY KEY AUTOINCREMENT,"+NAME+" TEXT NOT NULL,"+PATH+" TEXT NOT NULL,"+CATEGORY+" TEXT NOT NULL);");
}
示例12: addMaxAgeToRepo
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void addMaxAgeToRepo(SQLiteDatabase db, int oldVersion) {
if (oldVersion >= 30 || columnExists(db, RepoTable.NAME, RepoTable.Cols.MAX_AGE)) {
return;
}
db.execSQL("alter table " + RepoTable.NAME + " add column " + RepoTable.Cols.MAX_AGE + " integer not null default 0");
}
示例13: renameOldMessagesTableAndCreateNew
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private static void renameOldMessagesTableAndCreateNew(SQLiteDatabase db) {
db.execSQL("ALTER TABLE messages RENAME TO messages_old");
db.execSQL("CREATE TABLE messages (" +
"id INTEGER PRIMARY KEY, " +
"deleted INTEGER default 0, " +
"folder_id INTEGER, " +
"uid TEXT, " +
"subject TEXT, " +
"date INTEGER, " +
"flags TEXT, " +
"sender_list TEXT, " +
"to_list TEXT, " +
"cc_list TEXT, " +
"bcc_list TEXT, " +
"reply_to_list TEXT, " +
"attachment_count INTEGER, " +
"internal_date INTEGER, " +
"message_id TEXT, " +
"preview TEXT, " +
"mime_type TEXT, "+
"normalized_subject_hash INTEGER, " +
"empty INTEGER default 0, " +
"read INTEGER default 0, " +
"flagged INTEGER default 0, " +
"answered INTEGER default 0, " +
"forwarded INTEGER default 0, " +
"message_part_id INTEGER" +
")");
db.execSQL("CREATE TABLE message_parts (" +
"id INTEGER PRIMARY KEY, " +
"type INTEGER NOT NULL, " +
"root INTEGER, " +
"parent INTEGER NOT NULL, " +
"seq INTEGER NOT NULL, " +
"mime_type TEXT, " +
"decoded_body_size INTEGER, " +
"display_name TEXT, " +
"header TEXT, " +
"encoding TEXT, " +
"charset TEXT, " +
"data_location INTEGER NOT NULL, " +
"data BLOB, " +
"preamble TEXT, " +
"epilogue TEXT, " +
"boundary TEXT, " +
"content_id TEXT, " +
"server_extra TEXT" +
")");
db.execSQL("CREATE TRIGGER set_message_part_root " +
"AFTER INSERT ON message_parts " +
"BEGIN " +
"UPDATE message_parts SET root=id WHERE root IS NULL AND ROWID = NEW.ROWID; " +
"END");
}
示例14: onUpgrade
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DatabaseContract.TABLE_TRANSACTIONS);
onCreate(db);
}
示例15: onCreate
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Called when the database is created for the first time. This is where the creation of
* tables and the initial population of the tables should happen.
*
* @param sqLiteDatabase The database.
*/
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
/*
* This String will contain a simple SQL statement that will create a table that will
* cache our weather data.
*/
final String SQL_CREATE_WEATHER_TABLE =
"CREATE TABLE " + WeatherEntry.TABLE_NAME + " (" +
/*
* WeatherEntry did not explicitly declare a column called "_ID". However,
* WeatherEntry implements the interface, "BaseColumns", which does have a field
* named "_ID". We use that here to designate our table's primary key.
*/
WeatherEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
WeatherEntry.COLUMN_DATE + " INTEGER NOT NULL, " +
WeatherEntry.COLUMN_WEATHER_ID + " INTEGER NOT NULL, " +
WeatherEntry.COLUMN_MIN_TEMP + " REAL NOT NULL, " +
WeatherEntry.COLUMN_MAX_TEMP + " REAL NOT NULL, " +
WeatherEntry.COLUMN_HUMIDITY + " REAL NOT NULL, " +
WeatherEntry.COLUMN_PRESSURE + " REAL NOT NULL, " +
WeatherEntry.COLUMN_WIND_SPEED + " REAL NOT NULL, " +
WeatherEntry.COLUMN_DEGREES + " REAL NOT NULL, " +
// COMPLETED (1) Add a UNIQUE constraint on the date column to replace on conflict
" UNIQUE (" + WeatherEntry.COLUMN_DATE + ") ON CONFLICT REPLACE);";
/*
* After we've spelled out our SQLite table creation statement above, we actually execute
* that SQL with the execSQL method of our SQLite database object.
*/
sqLiteDatabase.execSQL(SQL_CREATE_WEATHER_TABLE);
}