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:Main.java

private static void createContactTable(SQLiteDatabase db) {
    String TABLE_CREATE = "create table if not exists CONTACT ("
            // + "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
            + "USER_ID TEXT PRIMARY KEY," + "NAME TEXT," + "COUPLE TEXT," + "JOB TEXT," + "AVATARPATH TEXT,"
            + "PHONE TEXT," + "ADDRESS TEXT," + "MAIL TEXT," + "DATE TEXT," + "WEBSITE TEXT," + "OTHER TEXT"
            + ");";

    db.execSQL(TABLE_CREATE);
}

From source file:com.silentcorp.autotracker.db.VehicleDB.java

/**
 * Creates the vehicles table//www  .j av  a  2  s.com
 * 
 * @param db the DB
 */
public static void onCreate(SQLiteDatabase db) {
    Log.i(VehicleDB.class.getName(), "Creating table: " + CREATE_TABLE);
    db.execSQL(CREATE_TABLE);
}

From source file:Main.java

public static void createTable(final SQLiteDatabase db, final String tableName,
        final String[] columnsDefinition) {
    String queryStr = "CREATE TABLE " + tableName + "(" + BaseColumns._ID + " INTEGER  PRIMARY KEY ,";
    // Add the columns now, Increase by 2
    for (int i = 0; i < (columnsDefinition.length - 1); i += 2) {
        if (i != 0) {
            queryStr += ",";
        }/*from   www .  j a  va  2  s  .  c o  m*/
        queryStr += columnsDefinition[i] + " " + columnsDefinition[i + 1];
    }

    queryStr += ");";

    db.execSQL(queryStr);
}

From source file:Main.java

private static void checkTableColumns(final SQLiteDatabase database, final String tableName,
        final String[] columns, final String[] columnTypes) {
    final List<String> cols = getTableColumns(database, tableName);
    for (int i = 0; i < columns.length; i++) {
        boolean found = false;
        for (final String col : cols) {
            if (col.equals(columns[i])) {
                found = true;//from   ww w . ja  v a2 s  .  c om
                break;
            }
        }
        if (!found) {
            database.execSQL("ALTER TABLE " + tableName + " ADD COLUMN " + columns[i] + " " + columnTypes[i]);
        }
    }
}

From source file:org.droidparts.util.PersistUtils.java

public static boolean executeStatements(final SQLiteDatabase db, final ArrayList<String> statements) {
    Callable<Boolean> task = new Callable<Boolean>() {

        @Override/*from   w w w. j a v a 2  s  .  c o  m*/
        public Boolean call() throws Exception {
            for (String statement : statements) {
                L.d(statement);
                db.execSQL(statement);
            }
            return Boolean.TRUE;
        }
    };
    Boolean result = executeInTransaction(db, task);
    return (result != null);
}

From source file:Main.java

public static void update(SQLiteDatabase db, String table, String[] items, String[] Values, String[] key,
        String[] id) {//  w  w  w  .j  a  v a  2  s  .  co m
    String str1 = "";
    String str2 = "";
    str1 = items[0] + " = '" + Values[0] + "' ";
    str2 = key[0] + " ='" + id[0] + "' ";
    for (int i = 1; i < items.length - 1; i++) {
        str1 += ", " + items[i] + " = " + "'" + Values[i] + "' ";
    }
    for (int i = 1; i < key.length - 1; i++) {
        str2 += "and " + key[i] + " = '" + id[i] + "' ";
    }
    String sql = "update " + table + " set " + str1 + "where " + str2;
    db.execSQL(sql);
}

From source file:curso.android.DAO.RespostaDAO.java

private static void createTable(SQLiteDatabase database, String tableName) {
    try {//  w ww.  j  a va  2 s .c  o  m
        database.beginTransaction();

        String tableSql = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
                + "asw_id INTEGER PRIMARY KEY AUTOINCREMENT," + "ask_id INTEGER," + "user_id INTEGER,"
                + "asw_resposta TEXT," + "user_name TEXT);";
        database.execSQL(tableSql);

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

From source file:org.droidparts.inner.PersistUtils.java

public static boolean executeStatements(final SQLiteDatabase db, final ArrayList<String> statements) {
    Callable<Boolean> task = new Callable<Boolean>() {

        @Override//from   w w w .j  a va 2 s.  c  o m
        public Boolean call() throws Exception {
            for (String statement : statements) {
                L.i(statement);
                db.execSQL(statement);
            }
            return Boolean.TRUE;
        }
    };
    Boolean result = executeInTransaction(db, task);
    return (result != null);
}

From source file:curso.android.DAO.PerguntaDAO.java

private static void createTable(SQLiteDatabase database, String tableName) {
    try {/*from w  w w .  java  2s . c  o  m*/
        // begin the transaction
        database.beginTransaction();

        // Create a table
        String tableSql = "CREATE TABLE IF NOT EXISTS " + tableName + " (" + "ask_id INTEGER PRIMARY KEY,"
                + "user_id INTEGER," + "ask_pergunta TEXT," + "user_name TEXT," + "status INTEGER);";
        database.execSQL(tableSql);

        // this makes sure transaction is committed
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}

From source file:com.silentcorp.autotracker.db.VehicleDB.java

/**
 * Drops and recreates the vehicles table TODO not on production environment
 * /*from w  w w .j  a  v a2s  . c o m*/
 * @param db the DB
 * @param oldVersion old DB version
 * @param newVersion new DB version
 */
public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.i(VehicleDB.class.getName(), "Upgrading DB from V:" + oldVersion + " to V:" + newVersion);

    // Drop older table if existed
    Log.i(VehicleDB.class.getName(), "Dropping old table: " + DROP_TABLE);
    db.execSQL(DROP_TABLE);

    // Create tables again
    onCreate(db);
}