当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteDatabase.execSQL方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:22,代码来源:AppSelectionDbHelper.java

示例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();
        }
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:18,代码来源:DatabaseAdapter.java

示例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");
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:8,代码来源:MigrationTo39.java

示例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);
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:10,代码来源:DBHelper.java

示例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");
		}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:PubkeyDatabase.java

示例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 )");
}
 
开发者ID:appteam-nith,项目名称:Hillffair17,代码行数:12,代码来源:DbHelper.java

示例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;");
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:16,代码来源:RestoreDbTask.java

示例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)"
        );
    }
}
 
开发者ID:lingochamp,项目名称:okdownload,代码行数:10,代码来源:BreakpointSQLiteHelper.java

示例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)");
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:12,代码来源:TimetableDatabaseHelper.java

示例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);
}
 
开发者ID:ProjektMedInf,项目名称:WiFiSDCryptoLocker,代码行数:10,代码来源:DatabaseHelper.java

示例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);");
}
 
开发者ID:yusufkocak1,项目名称:TMP-Music_player,代码行数:4,代码来源:Database.java

示例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");
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:7,代码来源:DBHelper.java

示例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");
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:58,代码来源:MigrationTo51.java

示例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);
}
 
开发者ID:talCrafts,项目名称:Udhari,代码行数:6,代码来源:TxDBHelper.java

示例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);
    }
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:47,代码来源:WeatherDbHelper.java


注:本文中的android.database.sqlite.SQLiteDatabase.execSQL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。