Example usage for android.database.sqlite SQLiteDatabase execSQL

List of usage examples for android.database.sqlite SQLiteDatabase execSQL

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase execSQL.

Prototype

public void execSQL(String sql) throws SQLException 

Source Link

Document

Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.

Usage

From source file:ru.orangesoftware.financisto2.db.MyEntityManager.java

public long saveOrUpdate(Currency currency) {
    SQLiteDatabase db = db();
    db.beginTransaction();/*w w  w.j ava  2s  .c  o  m*/
    try {
        if (currency.isDefault) {
            db.execSQL(UPDATE_DEFAULT_FLAG);
        }
        long id = super.saveOrUpdate(currency);
        db.setTransactionSuccessful();
        return id;
    } finally {
        db.endTransaction();
    }
}

From source file:io.github.tjg1.nori.database.APISettingsDatabase.java

@Override
public void onCreate(SQLiteDatabase db) {
    // SQL query used to create the database schema.
    String createSQL = String.format(Locale.US,
            "CREATE TABLE %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT NOT NULL, %s INTEGER NOT NULL, %s TEXT NOT NULL, %s TEXT, %s TEXT);",
            TABLE_NAME, COLUMN_ID, COLUMN_NAME, COLUMN_TYPE, COLUMN_ENDPOINT_URL, COLUMN_USERNAME,
            COLUMN_PASSPHRASE);//from   ww  w .j a  va  2s  .co m
    db.execSQL(createSQL);

    // SQL query used to populate the database with initial data (when the app is first launched).
    String populateSQL = String.format(Locale.US, "INSERT INTO %s (%s, %s, %s) VALUES ('%s', %d, '%s');",
            TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, COLUMN_ENDPOINT_URL, "Flickr",
            SearchClient.Settings.APIType.FLICKR.ordinal(), Flickr.FLICKR_API_ENDPOINT);
    db.execSQL(populateSQL);
}

From source file:org.fitchfamily.android.wifi_backend.database.Database.java

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
    // Always create version 0 of database, then update the schema
    // in the same order it might occur "in the wild". Avoids having
    // to check to see if the table exists (may be old version)
    // or not (can be new version).
    sqLiteDatabase
            .execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_SAMPLES + "(" + COL_BSSID + " STRING PRIMARY KEY, "
                    + COL_LATITUDE + " REAL, " + COL_LONGITUDE + " REAL, " + COL_LAT1 + " REAL, " + COL_LON1
                    + " REAL, " + COL_LAT2 + " REAL, " + COL_LON2 + " REAL, " + COL_LAT3 + " REAL, " + COL_LON3
                    + " REAL, " + COL_D12 + " REAL, " + COL_D23 + " REAL, " + COL_D31 + " REAL);");

    onUpgrade(sqLiteDatabase, 1, VERSION);
}

From source file:com.cyanogenmod.eleven.provider.LocalizedStore.java

private void rebuildLocaleData(LocaleSet locales) {
    if (DEBUG) {/*from  w  w w. j a va  2  s  . c o m*/
        Log.d(TAG, "Locale has changed, rebuilding sorting data");
    }

    final long start = SystemClock.elapsedRealtime();
    final SQLiteDatabase db = mMusicDatabase.getWritableDatabase();
    db.beginTransaction();
    try {
        db.execSQL("DELETE FROM " + SongSortColumns.TABLE_NAME);
        db.execSQL("DELETE FROM " + AlbumSortColumns.TABLE_NAME);
        db.execSQL("DELETE FROM " + ArtistSortColumns.TABLE_NAME);

        // prep the localization classes
        mLocaleSetManager.updateLocaleSet(locales);

        updateLocalizedStore(db, null);

        // Update the ICU version used to generate the locale derived data
        // so we can tell when we need to rebuild with new ICU versions.
        PropertiesStore.getInstance(mContext).storeProperty(PropertiesStore.DbProperties.ICU_VERSION,
                ICU.getIcuVersion());
        PropertiesStore.getInstance(mContext).storeProperty(PropertiesStore.DbProperties.LOCALE,
                locales.toString());

        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }

    if (DEBUG) {
        Log.i(TAG, "Locale change completed in " + (SystemClock.elapsedRealtime() - start) + "ms");
    }
}

From source file:net.willwebberley.gowertides.utils.WeatherDatabase.java

@Override
public void onCreate(SQLiteDatabase db) {
    String create = "CREATE TABLE IF NOT EXISTS weather (timestamp INTEGER, " + "year INTEGER,"
            + "month INTEGER," + "day INTEGER," + "max_temp_c INTEGER," + "max_temp_f INTEGER,"
            + "min_temp_c INTEGER," + "min_temp_f INTEGER," + "wind_speed_miles INTEGER,"
            + "wind_speed_km INTEGER," + "wind_direction TEXT," + "wind_degree INTEGER," + "icon_url TEXT,"
            + "description TEXT," + "precipitation FLOAT)";
    db.execSQL(create);
    String create2 = "CREATE TABLE IF NOT EXISTS surf (" + "location INTEGER," + "timestamp INTEGER,"
            + "local_time INTEGER," + "year INTEGER," + "month INTEGER," + "day INTEGER," + "hour INTEGER,"
            + "minute INTEGER," + "faded_rating INTEGER," + "solid_rating INTEGER," + "min_surf REAL,"
            + "abs_min_surf REAL," + "max_surf REAL," + "abs_max_surf REAL," + "swell_height REAL,"
            + "swell_period REAL," + "swell_angle REAL," + "swell_direction TEXT," + "swell_chart_url TEXT,"
            + "period_chart_url TEXT," + "wind_chart_url TEXT," + "pressure_chart_url TEXT,"
            + "sst_chart_url TEXT)";
    db.execSQL(create2);//from w  w  w.  j  a  v a2 s .c  om
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void onCreate(SQLiteDatabase db) throws InvalidPropertiesFormatException {
    db.execSQL(getCreateQuery());
}

From source file:com.citrus.sdk.database.DBHandler.java

@Override
public void onCreate(SQLiteDatabase db) {
    String payTable = "CREATE TABLE IF NOT EXISTS " + PAYOPTION_TABLE + " (" + MMID + " TEXT, " + SCHEME
            + " TEXT, " + EXPDATE + " TEXT, " + NAME + " TEXT PRIMARY KEY, " + OWNER + " TEXT, " + BANK
            + " TEXT, " + NUMBER + " TEXT, " + TYPE + " TEXT, " + TOKEN_ID + " TEXT, " + IMPS_REGISTERED
            + " TEXT, " + DEFAULT_OPTION + " INTEGER)";
    String bankTable = "CREATE TABLE IF NOT EXISTS " + BANK_TABLE + " (" + BANK_CID + " TEXT PRIMARY KEY, "
            + BANK + " TEXT)";
    db.execSQL(payTable);
    db.execSQL(bankTable);/*from   www.  j a  v a2 s.com*/
}

From source file:com.money.manager.ex.database.MmxOpenHelper.java

/**
 * @param db    SQLite database to execute raw SQL
 * @param rawId id raw resource//from  ww w .ja v  a 2s  . co m
 */
private void executeRawSql(SQLiteDatabase db, int rawId) {
    String sqlRaw = MmxFileUtils.getRawAsString(getContext(), rawId);
    String sqlStatement[] = sqlRaw.split(";");

    // process all statements
    for (String aSqlStatment : sqlStatement) {
        Timber.d(aSqlStatment);

        try {
            db.execSQL(aSqlStatment);
        } catch (Exception e) {
            String errorMessage = e.getMessage();
            if (e instanceof SQLiteException && errorMessage != null
                    && errorMessage.contains("not an error (code 0)")) {
                Timber.w(errorMessage);
            } else {
                Timber.e(e, "executing raw sql: %s", aSqlStatment);
            }
        }
    }
}

From source file:it.bradipao.berengar.DbTool.java

public static int json2table(SQLiteDatabase mDB, JSONObject jsonTable) {

    // vars/*  ww w.  j ava  2  s .c om*/
    JSONArray jsonRows = new JSONArray();
    JSONArray jsonColsName = new JSONArray();
    JSONArray jsonCols = null;
    ContentValues cv = null;

    int iRes = 0;
    try {
        // init database transaction
        mDB.beginTransaction();
        // fetch table name and drop if exists
        String sTableName = jsonTable.getString("table_name");
        mDB.execSQL("DROP TABLE IF EXISTS " + sTableName);
        if (GOLOG)
            Log.d(LOGTAG, "TABLE NAME : " + sTableName);
        // fetch and execute create sql
        String sTableSql = jsonTable.getString("table_sql");
        mDB.execSQL(sTableSql);
        // fetch columns name
        jsonColsName = jsonTable.getJSONArray("cols_name");
        // fetch rows array
        jsonRows = jsonTable.getJSONArray("rows");
        // iterate through rows
        for (int i = 0; i < jsonRows.length(); i++) {
            // fetch columns
            jsonCols = jsonRows.getJSONArray(i);
            // perform insert
            cv = new ContentValues();
            for (int j = 0; j < jsonCols.length(); j++)
                cv.put(jsonColsName.getString(j), jsonCols.getString(j));
            mDB.insert(sTableName, null, cv);
            if (GOLOG)
                Log.d(LOGTAG, "INSERT IN " + sTableName + " ID=" + jsonCols.getString(0));
        }
        iRes++;
        // set transaction successful
        mDB.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(LOGTAG, "error in json2table", e);
    } finally {
        // end transaction, commit if successful else rollback
        mDB.endTransaction();
    }

    return iRes;
}

From source file:project.cs.netinfservice.database.IODatabase.java

/**
 * Called when the database needs to be upgraded. The implementation should use this method
 * to drop tables, add tables, or do anything else it needs to upgrade to the new schema
 * version./*from   w  w w.  ja v  a  2  s . c o m*/
 * 
 * @param db
 *     The SQLite database.
 * @param oldVersion
 *     Old database version number.
 * @param newVersion
 *     New database version number.
 */
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.d(TAG, "Upgrading database to version " + newVersion);

    // Drop tables to re-build them later
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_IO);
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_URL);

    // Re-run the creation of the database
    onCreate(db);
}