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:com.mobile.system.db.abatis.AbatisService.java

/**
 * DB connector//from  w w w .  j  a v a2  s  .  c  o  m
 * 
 * @param db
 *            SQLiteDatabase object
 * 
 */
@Override
public void onCreate(SQLiteDatabase db) {
    int pointer = context.getResources().getIdentifier(INIT_CREATE_SQL, "string", context.getPackageName());
    if (pointer == 0) {
        Log.e(TAG, "undefined sql id - initialize");
    } else {
        String createTabelSql = context.getResources().getString(pointer);
        db.execSQL(createTabelSql);
        Log.d(TAG, "Run sql : " + createTabelSql);
    }
}

From source file:mobisocial.bento.anyshare.util.DBHelper.java

@Override
public void onCreate(SQLiteDatabase db) {
    db.beginTransaction();/*  w  w w  . j a v a2 s.  co m*/

    createTable(db, ItemObject.TABLE, null, ItemObject._ID, "INTEGER PRIMARY KEY", ItemObject.FEEDNAME, "TEXT",
            ItemObject.TITLE, "TEXT", ItemObject.DESC, "TEXT", ItemObject.TIMESTAMP, "INTEGER", ItemObject.RAW,
            "BLOB", ItemObject.OBJHASH, "INTEGER", ItemObject.PARENT_ID, "INTEGER");
    createIndex(db, "INDEX", "objects_by_hash", ItemObject.TABLE, ItemObject.OBJHASH);
    createIndex(db, "INDEX", "objects_timestamp", ItemObject.TABLE, ItemObject.TIMESTAMP);
    db.execSQL("CREATE INDEX objects_by_parent_id ON " + ItemObject.TABLE + "(" + ItemObject.PARENT_ID + ", "
            + ItemObject.TIMESTAMP + ")");

    db.setVersion(VERSION);
    db.setTransactionSuccessful();
    db.endTransaction();
    this.onOpen(db);
    //}
}

From source file:yong.dealer.shopping.data.ShoppingDbHelper.java

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
    // Create a table to hold locations.  A location consists of the string supplied in the
    // location setting, the city name, and the latitude and longitude
    final String SQL_CREATE_INVENTORY_TABLE = "CREATE TABLE " + InventoryEntry.TABLE_NAME + " ("
            + InventoryEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + InventoryEntry.COLUMN_CATEGORY_ID
            + " INTEGER, " + InventoryEntry.COLUMN_NAME + " TEXT  NOT NULL, " + InventoryEntry.COLUMN_SHORT_DESC
            + " TEXT, " + InventoryEntry.COLUMN_CALORIE + " TEXT, " + InventoryEntry.COLUMN_CARBOH + " TEXT, "
            + InventoryEntry.COLUMN_FAT + " TEXT " + InventoryEntry.COLUMN_PROTEIN + " TEXT " +

            " );";
    final String SQL_CREATE_CATEGORY_TABLE = "CREATE TABLE " + CategoryEntry.TABLE_NAME + " ("
            + CategoryEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + CategoryEntry.COLUMN_NAME
            + " TEXT NOT NULL " + ")";

    sqLiteDatabase.execSQL(SQL_CREATE_INVENTORY_TABLE);
    sqLiteDatabase.execSQL(SQL_CREATE_CATEGORY_TABLE);
}

From source file:mobisocial.bento.anyshare.util.DBHelper.java

private void createTable(SQLiteDatabase db, String tableName, String[] uniqueCols, String... cols) {
    assert cols.length % 2 == 0;
    String s = "CREATE TABLE " + tableName + " (";
    for (int i = 0; i < cols.length; i += 2) {
        s += cols[i] + " " + cols[i + 1];
        if (i < (cols.length - 2)) {
            s += ", ";
        } else {//from  w  ww .  j ava 2 s . c o m
            s += " ";
        }
    }
    if (uniqueCols != null && uniqueCols.length > 0) {
        s += ", UNIQUE (" + join(uniqueCols, ",") + ")";
    }
    s += ")";
    Log.i(TAG, s);
    db.execSQL(s);
}

From source file:com.cuddlesoft.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);//  w  ww  .ja v a 2  s .  c o  m
    // 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, "Safebooru",
            SearchClient.Settings.APIType.GELBOORU.ordinal(), "http://safebooru.org");

    // Execute SQL queries.
    db.execSQL(createSQL);
    db.execSQL(populateSQL);
}

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public void updateStatistics(final Set<RequestFilterUtil.FilterType> exfiltrated) {
    new Thread(new Runnable() {
        @Override//from w  w w  .  java2  s.co m
        public void run() {
            for (RequestFilterUtil.FilterType filter : exfiltrated) {
                String column = "";
                switch (RequestFilterUtil.getDescriptionForFilterType(filter)) {
                case "Contacts Data":
                    column = KEY_CONTACTSINFO;
                    break;
                case "IMEI":
                    column = KEY_IMEI;
                    break;
                case "Phone Number":
                    column = KEY_PHONENUMBER;
                    break;
                case "Device Id":
                    column = KEY_IMSI;
                    break;
                case "Carrier Name":
                    column = KEY_CARRIERNAME;
                    break;
                case "Location Information":
                    column = KEY_LOCATION;
                    break;
                case "Android Id":
                    column = KEY_ANDROIDID;
                    break;
                case "Mac Addresses":
                    column = KEY_MACADDRESSES;
                    break;
                }
                if (!column.equals("")) {
                    SQLiteDatabase db = DatabaseHelper.this.getWritableDatabase();
                    try {
                        db.execSQL("UPDATE " + TABLE_STATISTICS + " SET " + column + " = " + column
                                + "+1 WHERE " + KEY_ID + "=1");
                    } catch (SQLException sqle) {
                        sqle.getMessage();
                    }
                }
            }
        }
    }).start();
}

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

@Override
public void onCreate(SQLiteDatabase db) {
    String createIoTable = "CREATE TABLE " + TABLE_IO + "(" + KEY_HASH + " TEXT PRIMARY KEY,"
            + KEY_HASH_ALGORITHM + " TEXT NOT NULL, " + KEY_CONTENT_TYPE + " TEXT NOT NULL, " + KEY_FILEPATH
            + " TEXT NOT NULL, " + KEY_FILE_SIZE + " REAL NOT NULL CHECK(" + KEY_FILE_SIZE + " > 0.0))";

    String createUrlTable = "CREATE TABLE " + TABLE_URL + "(" + KEY_HASH + " TEXT NOT NULL, " + KEY_URL
            + " TEXT NOT NULL, " + "CONSTRAINT primarykey PRIMARY KEY " + "( " + KEY_HASH + ", " + KEY_URL
            + "), " + "FOREIGN KEY (" + KEY_HASH + ") " + "REFERENCES " + TABLE_IO + " ( " + KEY_HASH + ") "
            + "ON DELETE CASCADE )";

    db.execSQL(createIoTable);
    db.execSQL(createUrlTable);/*from   w w w. j a  v a2  s . c o  m*/
}

From source file:com.spoiledmilk.ibikecph.util.DB.java

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_SEARCH_HOSTORY_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_SEARCH_HISTORY + "(" + KEY_ID
            + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_ADDRESS + " TEXT," + KEY_START_DATE + " TEXT,"
            + KEY_END_DATE + " TEXT," + KEY_SOURCE + " TEXT," + KEY_SUBSOURCE + " TEXT," + KEY_LAT + " REAL,"
            + KEY_LONG + " REAL)";
    db.execSQL(CREATE_SEARCH_HOSTORY_TABLE);
    String CREATE_FAVORITES_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_FAVORITES + "(" + KEY_ID
            + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_ADDRESS + " TEXT," + KEY_SOURCE + " TEXT,"
            + KEY_SUBSOURCE + " TEXT," + KEY_LAT + " REAL," + KEY_LONG + " REAL, " + KEY_API_ID
            + " INTEGER DEFAULT -1)";
    db.execSQL(CREATE_FAVORITES_TABLE);/*from   w ww. j a  v  a  2s. co  m*/
}

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

public static void logSentMessage(String msgId, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    /* Check first that the number of logged messages for this group is not greater than the 
    * limit impossed per group, because if it's greater we must delete number-limit older logs
    * until the table only has the limit. This is done this way because on the MessageList a set
    * is built with the post messages from that group, and then every loaded message's msgId is checked 
    * to see if it's in the set (to check for replies to our messages), so allowing it to grow too much
    * could make the MessageView slow//from   ww w.  ja v  a 2s .co m
    */

    Cursor c = dbwrite.rawQuery(
            "SELECT _id FROM sent_posts_log WHERE subscribed_group_id=" + groupid + " ORDER BY _id", null);
    int count = c.getCount();
    int toKill = count - UsenetConstants.SENT_POSTS_LOG_LIMIT_PER_GROUP;
    int kennyId;

    if (toKill > 0) {
        // Delete some more than needed so we don't have to do this on every post sent
        toKill += UsenetConstants.SENT_POST_KILL_ADITIONAL;
        c.moveToFirst();

        for (int i = 0; i < toKill; i++) {
            kennyId = c.getInt(0);
            dbwrite.execSQL("DELETE FROM sent_posts_log WHERE _id=" + kennyId);
            c.moveToNext();
        }
    }
    c.close();

    // Now we have room for sure, insert the log
    ContentValues cv = new ContentValues(2);
    cv.put("server_article_id", msgId);
    cv.put("subscribed_group_id", groupid);
    dbwrite.insert("sent_posts_log", null, cv);

    dbwrite.close();
    db.close();
}

From source file:com.mk4droid.IMC_Services.DatabaseHandler.java

/** Create tables */
@Override// w  w  w.  jav a2 s  . co m
public void onCreate(SQLiteDatabase db) {

    String CREATE_Categ_TABLE = "CREATE TABLE " + TABLE_Categories + "(" + KEY_CatID + " INTEGER PRIMARY KEY,"
            + KEY_CatName + " TEXT," + KEY_CatIcon + " BLOB," + KEY_CatLevel + " INTEGER," + KEY_CatParentID
            + " INTEGER," + KEY_CatVisible + " INTEGER)";

    db.execSQL(CREATE_Categ_TABLE);

    String CREATE_Issues_TABLE = "CREATE TABLE " + TABLE_Issues + "(" + KEY_IssueID + " INTEGER PRIMARY KEY,"
            + KEY_Title + " TEXT," + KEY_CatID + " INTEGER," + KEY_Lat + " TEXT," + KEY_Long + " TEXT,"
            + KEY_Description + " TEXT," + KEY_Photo + " TEXT," + KEY_Address + " TEXT," + KEY_Votes
            + " INTEGER," + KEY_CurrStat + " INTEGER," + KEY_Reported + " TEXT," + KEY_Ack + " TEXT,"
            + KEY_Closed + " TEXT," + KEY_UserID + " INTEGER," + KEY_Ordering + " INTEGER," + KEY_Params
            + " TEXT," + KEY_State + " INTEGER," + KEY_Lang + " TEXT," + KEY_Hits + " INTEGER," + KEY_Username
            + " TEXT)";

    db.execSQL(CREATE_Issues_TABLE);

    String CREATE_IssuesPics_TABLE = "CREATE TABLE " + TABLE_IssuesPics + "(" + KEY_IssueID
            + " INTEGER PRIMARY KEY," + KEY_IssuePicData + " BLOB )";

    db.execSQL(CREATE_IssuesPics_TABLE);

    String CREATE_IssuesThumbs_TABLE = "CREATE TABLE " + TABLE_IssuesThumbs + "(" + KEY_IssueID
            + " INTEGER PRIMARY KEY," + KEY_IssueThumbData + " BLOB )";

    db.execSQL(CREATE_IssuesThumbs_TABLE);

    String CREATE_Version_TABLE = "CREATE TABLE " + TABLE_Version + "(" + KEY_VersionID
            + " INTEGER PRIMARY KEY," + KEY_VersionTimestamp + " TEXT );";

    db.execSQL(CREATE_Version_TABLE);

    String CREATE_CategVersion_TABLE = "CREATE TABLE " + TABLE_CategVersion + "(" + KEY_VersionID
            + " INTEGER PRIMARY KEY," + KEY_VersionTimestamp + " TEXT );";

    db.execSQL(CREATE_CategVersion_TABLE);

    String CREATE_Votes_TABLE = "CREATE TABLE " + TABLE_Votes + "(" + KEY_VoteID + " INTEGER PRIMARY KEY,"
            + KEY_IssueIDVotes + " INTEGER);";

    db.execSQL(CREATE_Votes_TABLE);
}