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.android.strictmodetest.StrictModeActivity.java

/** Called when the activity is first created. */
@Override//ww w.  j  av  a  2 s . c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    cr = getContentResolver();
    final SQLiteDatabase db = openOrCreateDatabase("foo.db", MODE_PRIVATE, null);

    final Button readButton = (Button) findViewById(R.id.read_button);
    readButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Cursor c = null;
            try {
                c = db.rawQuery("SELECT * FROM foo", null);
            } finally {
                if (c != null)
                    c.close();
            }
        }
    });

    final Button writeButton = (Button) findViewById(R.id.write_button);
    writeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            db.execSQL("CREATE TABLE IF NOT EXISTS FOO (a INT)");
        }
    });

    final Button writeLoopButton = (Button) findViewById(R.id.write_loop_button);
    writeLoopButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            long startTime = SystemClock.uptimeMillis();
            int iters = 1000;
            BlockGuard.Policy policy = BlockGuard.getThreadPolicy();
            for (int i = 0; i < iters; ++i) {
                policy.onWriteToDisk();
            }
            long endTime = SystemClock.uptimeMillis();
            Log.d(TAG, "Time for " + iters + ": " + (endTime - startTime) + ", avg="
                    + (endTime - startTime) / (double) iters);
        }
    });

    final Button dnsButton = (Button) findViewById(R.id.dns_button);
    dnsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.d(TAG, "Doing DNS lookup for www.l.google.com... " + "(may be cached by InetAddress)");
            try {
                InetAddress[] addrs = InetAddress.getAllByName("www.l.google.com");
                for (int i = 0; i < addrs.length; ++i) {
                    Log.d(TAG, "got: " + addrs[i]);
                }
            } catch (java.net.UnknownHostException e) {
                Log.d(TAG, "DNS error: " + e);
            }
        }
    });

    final Button httpButton = (Button) findViewById(R.id.http_button);
    httpButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                // Note: not using AndroidHttpClient, as that comes with its
                // own pre-StrictMode network-on-Looper thread check.  The
                // intent of this test is that we test the network stack's
                // instrumentation for StrictMode instead.
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpResponse res = httpClient.execute(new HttpGet("http://www.android.com/favicon.ico"));
                Log.d(TAG, "Fetched http response: " + res);
            } catch (IOException e) {
                Log.d(TAG, "HTTP fetch error: " + e);
            }
        }
    });

    final Button http2Button = (Button) findViewById(R.id.http2_button);
    http2Button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                // Usually this ends up tripping in DNS resolution,
                // so see http3Button below, which connects directly to an IP
                InputStream is = new URL("http://www.android.com/").openConnection().getInputStream();
                Log.d(TAG, "Got input stream: " + is);
            } catch (IOException e) {
                Log.d(TAG, "HTTP fetch error: " + e);
            }
        }
    });

    final Button http3Button = (Button) findViewById(R.id.http3_button);
    http3Button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                // One of Google's web IPs, as of 2010-06-16....
                InputStream is = new URL("http://74.125.19.14/").openConnection().getInputStream();
                Log.d(TAG, "Got input stream: " + is);
            } catch (IOException e) {
                Log.d(TAG, "HTTP fetch error: " + e);
            }
        }
    });

    final Button binderLocalButton = (Button) findViewById(R.id.binder_local_button);
    binderLocalButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                boolean value = mLocalServiceConn.stub.doDiskWrite(123 /* dummy */);
                Log.d(TAG, "local writeToDisk returned: " + value);
            } catch (RemoteException e) {
                Log.d(TAG, "local binderButton error: " + e);
            }
        }
    });

    final Button binderRemoteButton = (Button) findViewById(R.id.binder_remote_button);
    binderRemoteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                boolean value = mRemoteServiceConn.stub.doDiskWrite(1);
                Log.d(TAG, "remote writeToDisk #1 returned: " + value);
                value = mRemoteServiceConn.stub.doDiskWrite(2);
                Log.d(TAG, "remote writeToDisk #2 returned: " + value);
            } catch (RemoteException e) {
                Log.d(TAG, "remote binderButton error: " + e);
            }
        }
    });

    final Button binderOneWayButton = (Button) findViewById(R.id.binder_oneway_button);
    binderOneWayButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                Log.d(TAG, "doing oneway disk write over Binder.");
                mRemoteServiceConn.stub.doDiskOneWay();
            } catch (RemoteException e) {
                Log.d(TAG, "remote binderButton error: " + e);
            }
        }
    });

    final Button binderCheckButton = (Button) findViewById(R.id.binder_check_button);
    binderCheckButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            int policy;
            try {
                policy = mLocalServiceConn.stub.getThreadPolicy();
                Log.d(TAG, "local service policy: " + policy);
                policy = mRemoteServiceConn.stub.getThreadPolicy();
                Log.d(TAG, "remote service policy: " + policy);
            } catch (RemoteException e) {
                Log.d(TAG, "binderCheckButton error: " + e);
            }
        }
    });

    final Button serviceDumpButton = (Button) findViewById(R.id.service_dump);
    serviceDumpButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.d(TAG, "About to do a service dump...");
            File file = new File("/sdcard/strictmode-service-dump.txt");
            FileOutputStream output = null;
            final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
            try {
                StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX);
                output = new FileOutputStream(file);
                StrictMode.setThreadPolicy(oldPolicy);
                boolean dumped = Debug.dumpService("cpuinfo", output.getFD(), new String[0]);
                Log.d(TAG, "Dumped = " + dumped);
            } catch (IOException e) {
                Log.e(TAG, "Can't dump service", e);
            } finally {
                StrictMode.setThreadPolicy(oldPolicy);
            }
            Log.d(TAG, "Did service dump.");
        }
    });

    final Button lingerCloseButton = (Button) findViewById(R.id.linger_close_button);
    lingerCloseButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            closeWithLinger(true);
        }
    });

    final Button nonlingerCloseButton = (Button) findViewById(R.id.nonlinger_close_button);
    nonlingerCloseButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            closeWithLinger(false);
        }
    });

    final Button leakCursorButton = (Button) findViewById(R.id.leak_cursor_button);
    leakCursorButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            final StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
            try {
                StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                        .penaltyLog().penaltyDropBox().build());
                db.execSQL("CREATE TABLE IF NOT EXISTS FOO (a INT)");
                Cursor c = db.rawQuery("SELECT * FROM foo", null);
                c = null; // never close it
                Runtime.getRuntime().gc();
            } finally {
                StrictMode.setVmPolicy(oldPolicy);
            }

        }
    });

    final CheckBox checkNoWrite = (CheckBox) findViewById(R.id.policy_no_write);
    final CheckBox checkNoRead = (CheckBox) findViewById(R.id.policy_no_reads);
    final CheckBox checkNoNetwork = (CheckBox) findViewById(R.id.policy_no_network);
    final CheckBox checkPenaltyLog = (CheckBox) findViewById(R.id.policy_penalty_log);
    final CheckBox checkPenaltyDialog = (CheckBox) findViewById(R.id.policy_penalty_dialog);
    final CheckBox checkPenaltyDeath = (CheckBox) findViewById(R.id.policy_penalty_death);
    final CheckBox checkPenaltyDropBox = (CheckBox) findViewById(R.id.policy_penalty_dropbox);

    View.OnClickListener changePolicy = new View.OnClickListener() {
        public void onClick(View v) {
            StrictMode.ThreadPolicy.Builder newPolicy = new StrictMode.ThreadPolicy.Builder();
            if (checkNoWrite.isChecked())
                newPolicy.detectDiskWrites();
            if (checkNoRead.isChecked())
                newPolicy.detectDiskReads();
            if (checkNoNetwork.isChecked())
                newPolicy.detectNetwork();
            if (checkPenaltyLog.isChecked())
                newPolicy.penaltyLog();
            if (checkPenaltyDialog.isChecked())
                newPolicy.penaltyDialog();
            if (checkPenaltyDeath.isChecked())
                newPolicy.penaltyDeath();
            if (checkPenaltyDropBox.isChecked())
                newPolicy.penaltyDropBox();
            StrictMode.ThreadPolicy policy = newPolicy.build();
            Log.v(TAG, "Changing policy to: " + policy);
            StrictMode.setThreadPolicy(policy);
        }
    };
    checkNoWrite.setOnClickListener(changePolicy);
    checkNoRead.setOnClickListener(changePolicy);
    checkNoNetwork.setOnClickListener(changePolicy);
    checkPenaltyLog.setOnClickListener(changePolicy);
    checkPenaltyDialog.setOnClickListener(changePolicy);
    checkPenaltyDeath.setOnClickListener(changePolicy);
    checkPenaltyDropBox.setOnClickListener(changePolicy);
}

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

public static void expireReadMessages(Context context, boolean expireAll, long expireTime) {

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

    // Get all the expired messages so we can delete bodies and attachments
    long currentTime = System.currentTimeMillis();
    String q = null;/*from  w w  w . j a  va  2 s  .  co m*/

    if (expireAll) {
        q = "SELECT _id, subscribed_group_id, has_attachments, attachments_fnames " + "FROM headers "
                + "WHERE read=1 AND catched=1";
    } else {
        q = "SELECT _id, subscribed_group_id, has_attachments, attachments_fnames " + "FROM headers "
                + "WHERE read=1 AND catched=1 AND read_unixdate < " + currentTime + " - " + expireTime;
    }

    Cursor c = dbwrite.rawQuery(q, null);

    int count = c.getCount();
    c.moveToFirst();
    String groupname;

    for (int i = 0; i < count; i++) {

        groupname = getGroupNameFromId(c.getInt(1) /*subscribed_group_id*/, context);
        FSUtils.deleteCacheMessage(c.getInt(0)/* _id */, groupname);

        if (c.getInt(2)/*has_attach*/ == 1) {
            FSUtils.deleteAttachments(c.getString(3) /*attachments_fnames*/, groupname);
        }

        c.moveToNext();
    }

    if (expireAll)
        q = "DELETE FROM headers WHERE read=1";
    else
        q = "DELETE FROM headers WHERE read=1 AND read_unixdate < " + currentTime + " - " + expireTime;
    dbwrite.execSQL(q);
    c.close();
    dbwrite.close();
    db.close();
}

From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java

private void addVitalsIntoInvstigation() {

    String addedVitalsSugarFlag = getInsertedInvestigationVitalsFlag();
    if (addedVitalsSugarFlag == null) {
        SQLiteDatabase db = null;
        try {//from   ww  w.  j  a  v a  2s .c  om
            db = sInstance.getWritableDatabase();
            db.execSQL(
                    "insert into table_investigation(patient_id,key_visit_id,sugar,sugar_fasting) select patient_id, key_visit_id , sugar, sugar_fasting from patient_history;");

            /*Updating flag to true so wont run 2nd time */ //20-05-2017

            setInsertedInvestigationVitalsFlag();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
}

From source file:com.maxwen.wallpaper.board.databases.Database.java

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_TABLE_CATEGORY = "CREATE TABLE " + TABLE_CATEGORIES + "(" + KEY_ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + KEY_NAME + " TEXT NOT NULL UNIQUE,"
            + KEY_THUMB_URL + " TEXT, " + KEY_SELECTED + " INTEGER DEFAULT 1" + ")";
    String CREATE_TABLE_WALLPAPER = "CREATE TABLE IF NOT EXISTS " + TABLE_WALLPAPERS + "(" + KEY_ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " + KEY_NAME + " TEXT NOT NULL, " + KEY_AUTHOR
            + " TEXT NOT NULL, " + KEY_THUMB_URL + " TEXT NOT NULL, " + KEY_URL + " TEXT NOT NULL UNIQUE, "
            + KEY_CATEGORY + " TEXT NOT NULL," + KEY_FAVORITE + " INTEGER DEFAULT 0," + KEY_ADDED_ON
            + " INTEGER DEFAULT 0" + ")";
    db.execSQL(CREATE_TABLE_CATEGORY);
    db.execSQL(CREATE_TABLE_WALLPAPER);/*from   w w w .j  a va 2  s . c  o  m*/
}

From source file:org.kontalk.provider.UsersProvider.java

/** Triggers a complete resync of the users database. */
private int resync() {
    Context context = getContext();
    ContentResolver cr = context.getContentResolver();
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    // begin transaction
    beginTransaction(db);//ww w  .j  a  v  a  2 s.  c  o m
    boolean success = false;

    int count = 0;

    // delete old users content
    try {
        db.execSQL("DELETE FROM " + TABLE_USERS_OFFLINE);
    } catch (SQLException e) {
        // table might not exist - create it! (shouldn't happen since version 4)
        db.execSQL(DatabaseHelper.SCHEMA_USERS_OFFLINE);
    }

    // we are trying to be fast here
    SQLiteStatement stm = db.compileStatement("INSERT INTO " + TABLE_USERS_OFFLINE
            + " (number, jid, display_name, lookup_key, contact_id, registered)" + " VALUES(?, ?, ?, ?, ?, ?)");

    // these two statements are used to immediately update data in the online table
    // even if the data is dummy, it will be soon replaced by sync or by manual request
    SQLiteStatement onlineUpd = db.compileStatement("UPDATE " + TABLE_USERS
            + " SET number = ?, display_name = ?, lookup_key = ?, contact_id = ? WHERE jid = ?");
    SQLiteStatement onlineIns = db.compileStatement("INSERT INTO " + TABLE_USERS
            + " (number, jid, display_name, lookup_key, contact_id, registered)" + " VALUES(?, ?, ?, ?, ?, ?)");

    Cursor phones = null;
    String dialPrefix = Preferences.getDialPrefix();
    int dialPrefixLen = dialPrefix != null ? dialPrefix.length() : 0;

    try {
        String where = !Preferences.getSyncInvisibleContacts(context)
                ? ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1 AND "
                : "";

        // query for phone numbers
        phones = cr.query(Phone.CONTENT_URI, new String[] { Phone.NUMBER, Phone.DISPLAY_NAME, Phone.LOOKUP_KEY,
                Phone.CONTACT_ID, RawContacts.ACCOUNT_TYPE }, where + " (" +
        // this will filter out RawContacts from Kontalk
                        RawContacts.ACCOUNT_TYPE + " IS NULL OR " + RawContacts.ACCOUNT_TYPE
                        + " NOT IN (?, ?))",
                new String[] { Authenticator.ACCOUNT_TYPE, Authenticator.ACCOUNT_TYPE_LEGACY }, null);

        if (phones != null) {
            while (phones.moveToNext()) {
                String number = phones.getString(0);
                String name = phones.getString(1);

                // buggy provider - skip entry
                if (name == null || number == null)
                    continue;

                // remove dial prefix first
                if (dialPrefix != null && number.startsWith(dialPrefix))
                    number = number.substring(dialPrefixLen);

                // a phone number with less than 4 digits???
                if (number.length() < 4)
                    continue;

                // fix number
                try {
                    number = NumberValidator.fixNumber(context, number,
                            Authenticator.getDefaultAccountName(context), 0);
                } catch (Exception e) {
                    Log.e(SyncAdapter.TAG, "unable to normalize number: " + number + " - skipping", e);
                    // skip number
                    continue;
                }

                try {
                    String hash = MessageUtils.sha1(number);
                    String lookupKey = phones.getString(2);
                    long contactId = phones.getLong(3);
                    String jid = XMPPUtils.createLocalJID(getContext(), hash);

                    addResyncContact(db, stm, onlineUpd, onlineIns, number, jid, name, lookupKey, contactId,
                            false);
                    count++;
                } catch (IllegalArgumentException iae) {
                    Log.w(SyncAdapter.TAG, "doing sync with no server?");
                } catch (SQLiteConstraintException sqe) {
                    // skip duplicate number
                }
            }

            phones.close();
        } else {
            Log.e(SyncAdapter.TAG, "query to contacts failed!");
        }

        if (Preferences.getSyncSIMContacts(getContext())) {
            // query for SIM contacts
            // column selection doesn't work because of a bug in Android
            // TODO this is a bit unclear...
            try {
                phones = cr.query(Uri.parse("content://icc/adn/"), null, null, null, null);
            } catch (Exception e) {
                /*
                On some phones:
                java.lang.NullPointerException
                at android.os.Parcel.readException(Parcel.java:1431)
                at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
                at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
                at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
                at android.content.ContentResolver.query(ContentResolver.java:372)
                at android.content.ContentResolver.query(ContentResolver.java:315)
                 */
                Log.w(SyncAdapter.TAG, "unable to retrieve SIM contacts", e);
                phones = null;
            }

            if (phones != null) {
                while (phones.moveToNext()) {
                    String name = phones.getString(phones.getColumnIndex("name"));
                    String number = phones.getString(phones.getColumnIndex("number"));
                    // buggy firmware - skip entry
                    if (name == null || number == null)
                        continue;

                    // remove dial prefix first
                    if (dialPrefix != null && number.startsWith(dialPrefix))
                        number = number.substring(dialPrefixLen);

                    // a phone number with less than 4 digits???
                    if (number.length() < 4)
                        continue;

                    // fix number
                    try {
                        number = NumberValidator.fixNumber(context, number,
                                Authenticator.getDefaultAccountName(context), 0);
                    } catch (Exception e) {
                        Log.e(SyncAdapter.TAG, "unable to normalize number: " + number + " - skipping", e);
                        // skip number
                        continue;
                    }

                    try {
                        String hash = MessageUtils.sha1(number);
                        String jid = XMPPUtils.createLocalJID(getContext(), hash);
                        long contactId = phones.getLong(phones.getColumnIndex(BaseColumns._ID));

                        addResyncContact(db, stm, onlineUpd, onlineIns, number, jid, name, null, contactId,
                                false);
                        count++;
                    } catch (IllegalArgumentException iae) {
                        Log.w(SyncAdapter.TAG, "doing sync with no server?");
                    } catch (SQLiteConstraintException sqe) {
                        // skip duplicate number
                    }
                }
            }
        }

        // try to add account number with display name
        String ownNumber = Authenticator.getDefaultAccountName(getContext());
        if (ownNumber != null) {
            String ownName = Authenticator.getDefaultDisplayName(getContext());
            String fingerprint = null;
            byte[] publicKeyData = null;
            try {
                PersonalKey myKey = Kontalk.get(getContext()).getPersonalKey();
                if (myKey != null) {
                    fingerprint = myKey.getFingerprint();
                    publicKeyData = myKey.getEncodedPublicKeyRing();
                }
            } catch (Exception e) {
                Log.w(SyncAdapter.TAG, "unable to load personal key", e);
            }
            try {
                String hash = MessageUtils.sha1(ownNumber);
                String jid = XMPPUtils.createLocalJID(getContext(), hash);

                addResyncContact(db, stm, onlineUpd, onlineIns, ownNumber, jid, ownName, null, null, true);
                insertOrUpdateKey(jid, fingerprint, publicKeyData, false);
                count++;
            } catch (IllegalArgumentException iae) {
                Log.w(SyncAdapter.TAG, "doing sync with no server?");
            } catch (SQLiteConstraintException sqe) {
                // skip duplicate number
            }
        }

        success = setTransactionSuccessful(db);
    } finally {
        endTransaction(db, success);
        if (phones != null)
            phones.close();
        stm.close();

        // time to invalidate contacts cache (because of updates to online)
        Contact.invalidate();
    }
    return count;
}

From source file:org.totschnig.myexpenses.provider.TransactionDatabase.java

@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    //since API 16 we could use onConfigure to enable foreign keys
    //which is run before onUpgrade
    //but this makes upgrades more difficult, since then you have to maintain the constraint in
    //each step of a multi statement upgrade with table rename
    //we stick to doing upgrades with foreign keys disabled which forces us
    //to take care of ensuring consistency during upgrades
    if (!db.isReadOnly()) {
        db.execSQL("PRAGMA foreign_keys=ON;");
    }/*w  w w. ja  v a2s.  com*/
    try {
        db.delete(TABLE_TRANSACTIONS, KEY_STATUS + " = " + STATUS_UNCOMMITTED, null);
    } catch (SQLiteException e) {
        AcraHelper.report(e, DbUtils.getTableDetails(db.query("sqlite_master", new String[] { "name", "sql" },
                "type = 'table'", null, null, null, null)));
    }
}

From source file:me.jreilly.JamesTweet.Adapters.TweetDataHelper.java

public Callback<List<Tweet>> callBackMaker(final int mMaxItems, final RecyclerView mRecyclerView,
        final Cursor mCursor, final SQLiteDatabase mTimelineDB, final TweetDataHelper mHelper,
        final SwipeRefreshLayout mSwipeRefreshLayout) {
    final int position = mCursor.getPosition();
    return new Callback<List<Tweet>>() {
        @Override/* w ww.j  a  va 2 s. c  o  m*/
        public void success(Result<List<Tweet>> listResult) {

            long numEntries = DatabaseUtils.queryNumEntries(mTimelineDB, "home");
            List<Tweet> list = listResult.data.subList(0, listResult.data.size());

            for (Tweet t : list) {
                try {
                    ContentValues tweetValues = mHelper.getValues(t);
                    mTimelineDB.insertOrThrow("home", null, tweetValues);
                    Log.v("NEW CONTEXT", "Added Tweet Tweets!");

                } catch (Exception te) {
                    Log.e("NEW CONTEXT", "Exception: " + te);
                }

            }

            int rowLimit = 50;

            if (DatabaseUtils.queryNumEntries(mTimelineDB, "home") > rowLimit) {
                String deleteQuery = "DELETE FROM home WHERE " + BaseColumns._ID + " NOT IN " + "(SELECT "
                        + BaseColumns._ID + " FROM home ORDER BY " + "update_time DESC " + "limit " + rowLimit
                        + ")";
                mTimelineDB.execSQL(deleteQuery);
                Log.v("NEW CONTEXT", "Deleteing Tweets!");
            }
            mRecyclerView.getAdapter().notifyDataSetChanged();
            if (mSwipeRefreshLayout != null) {
                mSwipeRefreshLayout.setRefreshing(false);
            } else {
                mRecyclerView.smoothScrollToPosition(position);
            }

            Log.v("NEW CONTEXT", "All done!");

        }

        @Override
        public void failure(TwitterException e) {
            Log.e("NEW CONTEXT", "Exception " + e);

        }
    };
}

From source file:com.openerp.orm.ORM.java

/**
 * Clean user records.//from w  ww  .j a  v a  2  s .  co  m
 * 
 * @param user_name
 *            the user_name
 * @return true, if successful
 */
public boolean cleanUserRecords(String user_name) {
    SQLiteDatabase db = getWritableDatabase();
    for (String table : databaseTables()) {
        String sql = "DELETE FROM " + table + " where oea_name = '" + user_name + "'";
        db.execSQL(sql);
    }
    db.close();
    return true;

}

From source file:org.nuxeo.android.cache.sql.DeferedUpdateTableWrapper.java

public OperationRequest storeRequest(String key, OperationRequest request, OperationType opType) {

    SQLiteDatabase db = getWritableDatabase();

    String sql = "INSERT INTO " + getTableName() + " (" + KEY_COLUMN + "," + OPID_COLUMN + "," + OPTYPE_COLUMN
            + "," + PARAMS_COLUMN + "," + HEADERS_COLUMN + "," + CTX_COLUMN + "," + DEPS_COLUMN;

    String operationId = request.getDocumentation().getId();
    String jsonParams = new JSONObject(request.getParameters()).toString();
    String jsonHeaders = new JSONObject(request.getHeaders()).toString();
    String jsonCtx = new JSONObject(request.getContextParameters()).toString();
    String deps = request.getDependencies().asJSON();

    String sqlValues = " VALUES (" + "'" + key + "'," + "'" + operationId + "'," + "'" + opType.toString()
            + "'," + "'" + jsonParams + "'," + "'" + jsonHeaders + "'," + "'" + jsonCtx + "'," + "'" + deps
            + "'";

    if (request.getInput() != null) {
        String inputType = request.getInput().getInputType();
        String inputRef = request.getInput().getInputRef();
        String inputBin = new Boolean(request.getInput().isBinary()).toString();

        sql = sql + "," + INPUT_TYPE_COLUMN + "," + INPUT_REF_COLUMN + "," + INPUT_BINARY_COLUMN;
        sqlValues = sqlValues + ",'" + inputType + "','" + inputRef + "','" + inputBin + "'";
    }//from  w  w w  .ja  v a  2 s .  c  om
    String insertQuery = sql + " ) " + sqlValues + ");";
    db.beginTransaction();
    db.execSQL(insertQuery);
    db.setTransactionSuccessful();
    db.endTransaction();

    return request;
}

From source file:com.xengar.android.englishverbs.data.VerbDBHelper.java

/**
 * Creates the schema for version 1.//  ww  w  .j a  v a2 s  .co  m
 * NOTE: If the version changes, add code for the upgrade also.
 * @param db SQLiteDatabase
 */
private void createSchemaVersion1(SQLiteDatabase db) {
    // Create a String that contains the SQL statement to create the verbs table
    String query = "CREATE TABLE " + VerbEntry.VERBS_TBL + " (" + VerbEntry._ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT, " + VerbEntry.COLUMN_ID + " INTEGER NOT NULL, "
            + VerbEntry.COLUMN_INFINITIVE + " TEXT NOT NULL, " + VerbEntry.COLUMN_SIMPLE_PAST
            + " TEXT NOT NULL, " + VerbEntry.COLUMN_PAST_PARTICIPLE + " TEXT NOT NULL, "
            + VerbEntry.COLUMN_PHONETIC_INFINITIVE + " TEXT, " + VerbEntry.COLUMN_PHONETIC_SIMPLE_PAST
            + " TEXT, " + VerbEntry.COLUMN_PHONETIC_PAST_PARTICIPLE + " TEXT, " + VerbEntry.COLUMN_SAMPLE_1
            + " TEXT, " + VerbEntry.COLUMN_SAMPLE_2 + " TEXT, " + VerbEntry.COLUMN_SAMPLE_3 + " TEXT, "
            + VerbEntry.COLUMN_COMMON + " INTEGER NOT NULL DEFAULT 0, " + VerbEntry.COLUMN_REGULAR
            + " INTEGER NOT NULL DEFAULT 0, " + VerbEntry.COLUMN_COLOR + " INTEGER NOT NULL DEFAULT 0, "
            + VerbEntry.COLUMN_SCORE + " INTEGER NOT NULL DEFAULT 0, " + VerbEntry.COLUMN_SOURCE
            + " INTEGER NOT NULL DEFAULT 0, " + VerbEntry.COLUMN_DEFINITION + " TEXT NOT NULL, "
            + VerbEntry.COLUMN_TRANSLATION_ES + " TEXT, " + VerbEntry.COLUMN_TRANSLATION_FR + " TEXT, "
            + VerbEntry.COLUMN_NOTES + " TEXT);";

    // Execute the SQL statement
    db.execSQL(query);

    query = "CREATE TABLE " + VerbEntry.FAVORITES_TBL + " (" + VerbEntry._ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT, " + VerbEntry.COLUMN_ID + " INTEGER NOT NULL); ";
    db.execSQL(query);
}