Example usage for android.database.sqlite SQLiteStatement bindAllArgsAsStrings

List of usage examples for android.database.sqlite SQLiteStatement bindAllArgsAsStrings

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteStatement bindAllArgsAsStrings.

Prototype

public void bindAllArgsAsStrings(String[] bindArgs) 

Source Link

Document

Given an array of String bindArgs, this method binds all of them in one single call.

Usage

From source file:com.xfinity.ceylon_steel.controller.CustomerController.java

public static void downloadCustomers(final Context context) {
    new AsyncTask<User, Void, JSONArray>() {

        @Override//  w  ww .  ja  v  a 2  s .c  o m
        protected void onPreExecute() {
            if (UserController.progressDialog == null) {
                UserController.progressDialog = new ProgressDialog(context);
                UserController.progressDialog.setMessage("Downloading Data");
                UserController.progressDialog.setCanceledOnTouchOutside(false);
            }
            if (!UserController.progressDialog.isShowing()) {
                UserController.progressDialog.show();
            }
        }

        @Override
        protected JSONArray doInBackground(User... users) {
            try {
                User user = users[0];
                HashMap<String, Object> parameters = new HashMap<String, Object>();
                parameters.put("userId", user.getUserId());
                return getJsonArray(getCustomersOfUser, parameters, context);
            } catch (IOException ex) {
                Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JSONException ex) {
                Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
            }
            return null;
        }

        @Override
        protected void onPostExecute(JSONArray result) {
            if (UserController.atomicInteger.decrementAndGet() == 0 && UserController.progressDialog != null
                    && UserController.progressDialog.isShowing()) {
                UserController.progressDialog.dismiss();
                UserController.progressDialog = null;
            }
            if (result != null) {
                SQLiteDatabaseHelper databaseInstance = SQLiteDatabaseHelper.getDatabaseInstance(context);
                SQLiteDatabase database = databaseInstance.getWritableDatabase();
                SQLiteStatement compiledStatement = database
                        .compileStatement("replace into tbl_customer(customerId,customerName) values(?,?)");
                try {
                    database.beginTransaction();
                    for (int i = 0; i < result.length(); i++) {
                        JSONObject customer = result.getJSONObject(i);
                        compiledStatement.bindAllArgsAsStrings(
                                new String[] { Integer.toString(customer.getInt("customerId")),
                                        customer.getString("customerName") });
                        long response = compiledStatement.executeInsert();
                        if (response == -1) {
                            return;
                        }
                    }
                    database.setTransactionSuccessful();
                    Toast.makeText(context, "Customers downloaded successfully", Toast.LENGTH_SHORT).show();
                } catch (JSONException ex) {
                    Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
                    Toast.makeText(context, "Unable parse customers", Toast.LENGTH_SHORT).show();
                } finally {
                    database.endTransaction();
                    databaseInstance.close();
                }
            } else {
                Toast.makeText(context, "Unable to download customers", Toast.LENGTH_SHORT).show();
            }
        }

    }.execute(UserController.getAuthorizedUser(context));
}

From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java

private SQLitePLuginResult doUpdateInBackgroundAndPossiblyThrow(String sql, String[] bindArgs,
        SQLiteDatabase db) {/*from   ww  w .  j a v  a  2 s .c  o m*/
    debug("\"run\" query: %s", sql);
    SQLiteStatement statement = null;
    try {
        statement = db.compileStatement(sql);
        debug("compiled statement");
        if (bindArgs != null) {
            statement.bindAllArgsAsStrings(bindArgs);
        }
        debug("bound args");
        if (isInsert(sql)) {
            debug("type: insert");
            long insertId = statement.executeInsert();
            int rowsAffected = insertId >= 0 ? 1 : 0;
            return new SQLitePLuginResult(EMPTY_ROWS, EMPTY_COLUMNS, rowsAffected, insertId, null);
        } else if (isDelete(sql) || isUpdate(sql)) {
            debug("type: update/delete");
            int rowsAffected = statement.executeUpdateDelete();
            return new SQLitePLuginResult(EMPTY_ROWS, EMPTY_COLUMNS, rowsAffected, 0, null);
        } else {
            // in this case, we don't need rowsAffected or insertId, so we can have a slight
            // perf boost by just executing the query
            debug("type: drop/create/etc.");
            statement.execute();
            return EMPTY_RESULT;
        }
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
}

From source file:io.requery.android.database.sqlite.SQLiteDatabase.java

/**
 * Utility method to run the pre-compiled query and return the value in the
 * first column of the first row./*from   w ww. ja v a2  s  .c  o m*/
 */
private static long longForQuery(SQLiteStatement prog, String[] selectionArgs) {
    prog.bindAllArgsAsStrings(selectionArgs);
    return prog.simpleQueryForLong();
}

From source file:io.requery.android.database.sqlite.SQLiteDatabase.java

/**
 * Utility method to run the pre-compiled query and return the value in the
 * first column of the first row.//from  ww  w.ja  v  a2 s  .c  om
 */
public static String stringForQuery(SQLiteStatement prog, String[] selectionArgs) {
    prog.bindAllArgsAsStrings(selectionArgs);
    return prog.simpleQueryForString();
}

From source file:io.requery.android.database.sqlite.SQLiteDatabase.java

/**
 * Utility method to run the pre-compiled query and return the blob value in the
 * first column of the first row./*from  ww w.j  a  va2 s  . c o  m*/
 *
 * @return A read-only file descriptor for a copy of the blob value.
 */
public static ParcelFileDescriptor blobFileDescriptorForQuery(SQLiteStatement prog, String[] selectionArgs) {
    prog.bindAllArgsAsStrings(selectionArgs);
    return prog.simpleQueryForBlobFileDescriptor();
}