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:uk.ac.horizon.ubihelper.service.PeersOpenHelper.java

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(PEER_TABLE_CREATE);
    //      db.execSQL(GROUP_TABLE_CREATE);
    //      db.execSQL(PEERGROUP_TABLE_CREATE);
}

From source file:org.jsharkey.oilcan.ScriptDatabase.java

public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE " + TABLE_SCRIPTS + " (_id INTEGER PRIMARY KEY, " + FIELD_SCRIPT_NAME + " TEXT, "
            + FIELD_SCRIPT_AUTHOR + " TEXT, " + FIELD_SCRIPT_DESCRIP + " TEXT, " + FIELD_SCRIPT_DOMAINREGEX
            + " TEXT, " + FIELD_SCRIPT_CONTENT + " TEXT, " + FIELD_SCRIPT_ENABLED + " INTEGER)");

    // populate database with a few example scripts 
    try {/*from   w  w  w .  j  av  a2s .  c o m*/
        this.insertScript(db, Util.getRawString(res, R.raw.email));
        this.insertScript(db, Util.getRawString(res, R.raw.halfscan));
        this.insertScript(db, Util.getRawString(res, R.raw.sharedigg));
        this.insertScript(db, Util.getRawString(res, R.raw.wikipedia));
        this.insertScript(db, Util.getRawString(res, R.raw.slashdot));
        this.insertScript(db, Util.getRawString(res, R.raw.userscripts));
    } catch (Exception e) {
        Log.e(TAG, "Problem while inserting default scripts", e);
    }

}

From source file:org.thomnichols.android.gmarks.WebViewCookiesDB.java

List<Cookie> getCookies() {
    List<Cookie> cookies = new ArrayList<Cookie>();
    SQLiteDatabase db = openDatabase(SQLiteDatabase.OPEN_READONLY);
    if (db == null)
        return cookies;

    try {/*from www.  j a  va 2 s.c  o m*/
        db.execSQL("PRAGMA read_uncommitted = true;");
        Cursor cursor = db.query(TABLE_NAME, COLUMNS, null, null, null, null, null);

        while (cursor.moveToNext()) {
            BasicClientCookie c = new BasicClientCookie(cursor.getString(COL_NAME),
                    cursor.getString(COL_VALUE));
            c.setDomain(cursor.getString(COL_DOMAIN));
            c.setPath(cursor.getString(COL_PATH));
            Long expiry = cursor.getLong(COL_EXPIRES);
            if (expiry != null)
                c.setExpiryDate(new Date(expiry));
            c.setSecure(cursor.getShort(COL_SECURE) == 1);
            Log.d(TAG, "Got cookie: " + c.getName());
            cookies.add(c);
        }
        cursor.close();

        //         cursor = db.query(TABLE_NAME, new String[] {"count(name)"}, null, null, null, null, null);
        //         cursor.moveToFirst();
        //         Log.d("WEBVIEW DB QUERY", "COunt: " + cursor.getLong(0) );
        //          cursor.close();
        return cookies;
    } finally {
        db.close();
    }
}

From source file:com.github.longkai.zhihu.util.Utils.java

public static void createTables(SQLiteDatabase db) {
    StringBuilder sql = new StringBuilder();
    // ?/*from  w w  w.java  2 s .  c  o  m*/
    // _id ??id
    sql.append("CREATE TABLE ").append(ITEMS).append("(").append(BaseColumns._ID).append(" int,")
            .append(QUESTION_ID).append(" int NOT NULL,").append(TITLE).append(" text NOT NULL,")
            .append(DESCRIPTION).append(" text,").append(STARRED).append(" int,").append(ANSWERED)
            .append(" int,").append(VIEWED).append(" int,").append(TOPICS).append(" text,")

            .append(ANSWER_ID).append(" int NOT NULL,").append(ANSWER).append(" text,").append(VOTE)
            .append(" int PRIMARY KEY,").append(LAST_ALTER_DATE).append(" int,").append(VOTERS).append(" text,")

            .append(UID).append(" text,").append(NICK).append(" text,").append(STATUS).append(" text,")
            .append(AVATAR).append(" text").append(")");

    db.execSQL(sql.toString());

    // ?string builder
    sql.setLength(0);

    // ??
    sql.append("CREATE TABLE ").append(TOPICS).append("(").append(TOPIC_ID).append(" int PRIMARY KEY,")
            .append(TOPIC_NAME).append(" text,").append(TOPIC_DESCRIPTION).append(" text,").append(TOPIC_AVATAR)
            .append(" text").append(")");

    db.execSQL(sql.toString());
}

From source file:com.liferay.alerts.database.DatabaseHelper.java

public void onCreate(SQLiteDatabase database) {
    UserDAO userDAO = new UserDAO();
    AlertDAO alertDAO = new AlertDAO();

    database.execSQL(userDAO.getCreateTableSQL());
    database.execSQL(alertDAO.getCreateTableSQL());
}

From source file:io.vit.vitio.Managers.ConnectDatabase.java

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {

    sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_COURSES);
    onCreate(sqLiteDatabase);/*from  w ww .ja  va 2 s  .co  m*/
}

From source file:heartware.com.heartware_master.DBAdapter.java

@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(profileSchema);
    database.execSQL(meetupsSchema);
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(SQL_CREATE_ENTRIES);
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void updateStarredThread(boolean starred, String clean_subject, int groupid, Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbWrite = db.getWritableDatabase();

    clean_subject = clean_subject.replace("'", "''");

    String query;/*from   w w w  .  j av a2s. c o  m*/

    if (starred == false) {
        query = "DELETE FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        dbWrite.execSQL(query);
    } else {
        // Check that it's not already on the table
        query = "SELECT _ID FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        Cursor c = dbWrite.rawQuery(query, null);

        if (c.getCount() == 0) {
            ContentValues cv = new ContentValues();
            cv.put("subscribed_group_id", groupid);
            cv.put("clean_subject", clean_subject);
            dbWrite.insert("starred_threads", null, cv);
        }
        c.close();
    }
    dbWrite.close();
    db.close();
}

From source file:org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataExtender.java

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // For now we'll just drop and recreate the tables.
    db.execSQL("DROP TABLE IF EXISTS " + TBL_HISTORY_EXT);
    onCreate(db);/*from  w w  w . j  av a  2 s . c o  m*/
}