List of usage examples for android.database.sqlite SQLiteDatabase execSQL
public void execSQL(String sql) throws SQLException
From source file:org.mitre.svmp.common.DatabaseHandler.java
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); if (!db.isReadOnly()) { // Enable foreign key constraints db.execSQL("PRAGMA foreign_keys=ON;"); }// w ww. ja v a 2 s . c om }
From source file:com.snt.bt.recon.database.DBHandler.java
@Override public void onCreate(SQLiteDatabase db) { String CREATE_TRIPS_TABLE = "CREATE TABLE " + TABLE_TRIPS + "(" + KEY_SESSION_ID + " VARCHAR(36) PRIMARY KEY," + KEY_IMEI + " TEXT," + KEY_TRANSPORT + " TEXT," + KEY_TIMESTAMP_START + " DATETIME," + KEY_TIMESTAMP_END + " DATETIME, " + KEY_APP_VERSION + " TEXT, " + KEY_UPLOAD_STATUS + " TEXT" + ")"; db.execSQL(CREATE_TRIPS_TABLE); String CREATE_LOCATIONS_TABLE = "CREATE TABLE " + TABLE_LOCATIONS + "(" + KEY_LOCATION_ID + " VARCHAR(36) PRIMARY KEY, " + KEY_SESSION_ID + " VARCHAR(36)," + KEY_TIMESTAMP + " DATETIME," + KEY_LATITUDE + " FLOAT, " + KEY_LONGITUDE + " FLOAT, " + KEY_SPEED + " FLOAT, " + KEY_BEARING + " FLOAT, " + KEY_ALTITUDE + " FLOAT, " + KEY_ACCURACY + " FLOAT, " + KEY_UPLOAD_STATUS + " TEXT" + ")"; db.execSQL(CREATE_LOCATIONS_TABLE);//from w w w . j a v a 2 s . com String CREATE_BC_TABLE = "CREATE TABLE " + TABLE_BC + "(" + " id INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_SESSION_ID + " VARCHAR(36)," + KEY_LOCATION_ID + " VARCHAR(36)," + KEY_TIMESTAMP + " DATETIME," + KEY_MAC + " VARCHAR(17), " + KEY_TYPE + " INT(11), " + KEY_RSSI + " INT(11), " + KEY_DEVICE_NAME + " TEXT, " + KEY_BC_CLASS + " TEXT, " + KEY_UPLOAD_STATUS + " TEXT" + ")"; db.execSQL(CREATE_BC_TABLE); String CREATE_BLE_TABLE = "CREATE TABLE " + TABLE_BLE + "(" + " id INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_SESSION_ID + " VARCHAR(36)," + KEY_LOCATION_ID + " VARCHAR(36)," + KEY_TIMESTAMP + " DATETIME," + KEY_MAC + " VARCHAR(17), " + KEY_RSSI + " INT(11), " + KEY_DEVICE_NAME + " TEXT, " + KEY_BLE_ADV_DATA + " TEXT, " + KEY_UPLOAD_STATUS + " TEXT" + ")"; db.execSQL(CREATE_BLE_TABLE); }
From source file:com.barcamppenang2014.tabfragment.ProfileFragment.java
License:asdf
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.update_profile_page, container, false); profilefrg = this; bt_save = (Button) v.findViewById(R.id.btnSave); bt_connect = (ImageButton) v.findViewById(R.id.btnfbconnect); bt_namecard = (ImageButton) v.findViewById(R.id.bt_namecard); et_name = (EditText) v.findViewById(R.id.editTextName); et_email = (EditText) v.findViewById(R.id.editTextEmail); et_phone = (EditText) v.findViewById(R.id.editTextPhone); et_profession = (EditText) v.findViewById(R.id.editTextProfession); et_fbId = (EditText) v.findViewById(R.id.editTextFbId); tv_imgtext = (TextView) v.findViewById(R.id.tx_namecard); tv_remove = (TextView) v.findViewById(R.id.tx_remove); final Bitmap defaultNamecard = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.default_namecard); //set default image for namecard bt_namecard.setImageBitmap(defaultNamecard); // Retrive the data from sqlite if profile is created. isProfileCreated = check();/*w w w . j av a2 s . com*/ if (isProfileCreated.equalsIgnoreCase("true")) { String[] myInfo = fillTextField(); et_name.setText(myInfo[0]); et_email.setText(myInfo[1]); et_phone.setText(myInfo[2]); et_profession.setText(myInfo[3]); if (!myInfo[4].equals("none")) { et_fbId.setText(myInfo[4]); } String picUri = getSharePreferenceKey("picuri"); // myInfo[5] retrieved from sharedpreference if (!picUri.equals("none")) { Uri imageUri = Uri.parse(picUri); try { URIToBitmap(imageUri); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } } bt_connect.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { fbLogin(); } }); tv_remove.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { SharedPreferences sharedpreferences = getActivity().getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE); Editor editor = sharedpreferences.edit(); editor.putString("picuri", "none"); editor.commit(); //set default image for namecard bt_namecard.setImageBitmap(defaultNamecard); } }); bt_namecard.setOnClickListener(galleryOnClickListener); tv_imgtext.setOnClickListener(galleryOnClickListener); Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { Activity temp = getActivity(); session = new Session(temp); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } bt_save.setOnClickListener(new OnClickListener() { public void onClick(View v) { String name = et_name.getText().toString(); String email = et_email.getText().toString(); String phone = et_phone.getText().toString(); String profession = et_profession.getText().toString(); // fbId and picUri can be null String fbId = et_fbId.getText().toString().equals("") ? "none" : et_fbId.getText().toString(); // String picUri = getSharePreferenceKey("picuri"); if (name.equals("") || email.equals("") || phone.equals("") || profession.equals("")) { Toast.makeText(getActivity(), "Please fill in all the details.", Toast.LENGTH_LONG).show(); } else { // URLNamecard = // "http://chimou.com/barcamppg/namecard.php?get&email=yinsee@wsatp.com"; // If bitmap is not null, POST to php String picUri = getSharePreferenceKey("picuri"); if (!picUri.equals("none")) { // new POSTNamecard().execute(email); //new POSTNamecard().execute("baa@gmail.com"); } MyDatabase database = new MyDatabase(getActivity()); SQLiteDatabase sqliteDatabase = database.getWritableDatabase(); String sql = "INSERT OR REPLACE INTO USERPROFILE (ISPFOFILECREATED,MYKEYID, MYNAME, MYEMAIL, MYPHONE,MYPROFESSION, MYFBID )" + " VALUES ('true','" + "1','" + name + "', '" + email + "', '" + phone + "', '" + profession + "', '" + fbId + "'); "; sqliteDatabase.execSQL(sql); database.close(); sqliteDatabase.close(); MainActivity main = (MainActivity) getActivity(); // main.switchContentWithinTab(new ProfileQrFragment(), // TITLE); main.switchContent(new ProfileQrFragment()); } } }); return v; }
From source file:ru.gkpromtech.exhibition.db.DbHelper.java
public void applyUpdates(SQLiteDatabase db, JsonNode updates, boolean isStatic) throws Exception { JsonNode nodeRev = updates.get("revision"); if (nodeRev == null) return;/*from w w w . ja v a2 s . com*/ final String synchronous = getPragma(db, "synchronous"); final String journalMode = getPragma(db, "journal_mode"); db.rawQuery("PRAGMA synchronous = OFF", null); db.rawQuery("PRAGMA journal_mode = MEMORY", null); // FK, ? ??? add-update db.execSQL("PRAGMA foreign_keys = OFF"); SharedPreferences prefs = getPrefs(); int langId = Profile.getInstance(mContext).getLangId(); int currentRevision = prefs.getInt("revision", 0); ObjectMapper mapper = new ObjectMapper(); int revision = nodeRev.asInt(); ArrayNode nodeChanges = (ArrayNode) updates.get("changes"); TypeReference<List<Change>> typeRef = new TypeReference<List<Change>>() { }; List<Change> changes = mapper.readValue(nodeChanges.traverse(), typeRef); Map<Table, List<Integer>> deletedTableRowIds = new HashMap<>(); try { db.beginTransaction(); for (Change change : changes) { if (currentRevision > change.id) { Log.w("PPDB", "Skipping old change #" + change.id); continue; } boolean tr = change.entity.endsWith("_tr"); String entityName = !tr ? change.entity : change.entity.substring(0, change.entity.length() - 3); Class<? extends Entity> entity = getEntityForTableName(entityName); if (entity == null) { Log.e("PPDB", "Cannot find entity for " + entityName); continue; } Table<? extends Entity> table = getTableFor(entity); if (table == null) { Log.e("PPDB", "Cannot find table for entity " + entityName); continue; } if (!tr) { if (change.data != null) { switch (change.changetype) { case Change.ADDED: table.insert(db, change.data, SQLiteDatabase.CONFLICT_FAIL); break; case Change.UPDATED: change.data.remove("id"); table.partialUpdate(db, change.rowid, change.data, SQLiteDatabase.CONFLICT_FAIL); break; } } else { if (change.changetype == Change.DELETED) { List<Integer> ids = deletedTableRowIds.get(table); if (ids == null) { ids = new ArrayList<>(); deletedTableRowIds.put(table, ids); } ids.add(change.rowid); } } } else if (change.data != null) { int changeLangId = change.data.get("languageid").asInt(); if (changeLangId != langId) continue; change.data.remove("languageid"); switch (change.changetype) { case Change.ADDED: case Change.UPDATED: TableRef annotation = entity.getAnnotation(TableRef.class); if (annotation == null) { Log.e("PPDB", "Cannot get trid field for entity " + entityName); continue; } String trIdName = annotation.trid(); JsonNode nodeTrId = change.data.get(trIdName); if (nodeTrId == null) { Log.e("PPDB", "Change data don't have a field [" + trIdName + "]: " + entityName); continue; } int id = nodeTrId.asInt(); change.data.remove("id"); change.data.remove(trIdName); table.partialUpdate(db, id, change.data, SQLiteDatabase.CONFLICT_FAIL); break; } } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } // ??? ?, ? FK db.execSQL("PRAGMA foreign_keys = ON"); try { db.beginTransaction(); for (Map.Entry<Table, List<Integer>> entry : deletedTableRowIds.entrySet()) { Table table = entry.getKey(); List<Integer> ids = entry.getValue(); for (Integer id : ids) table.delete(db, id); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } if (synchronous != null) db.rawQuery("PRAGMA synchronous = " + synchronous, null); if (journalMode != null) db.rawQuery("PRAGMA journal_mode = " + journalMode, null); if (revision > currentRevision) prefs.edit().putInt("revision", revision).apply(); if (isStatic) prefs.edit().putInt("jsonRevision", revision).apply(); }
From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java
public void onUpgradeDatabase(SQLiteDatabase db, int oldVersion, int newVersion) { Cursor c = db.rawQuery("select 'drop table ' || name || ';' from sqlite_master where type = 'table'", null); if (c.moveToFirst()) { do {//ww w . j ava2 s . c o m db.execSQL(c.getString(0)); } while (c.moveToNext()); } onCreateDataBase(db); }
From source file:org.totschnig.myexpenses.provider.TransactionDatabase.java
private void refreshViews(SQLiteDatabase db) { db.execSQL("DROP VIEW IF EXISTS transactions_extended"); db.execSQL("DROP VIEW IF EXISTS templates_extended"); db.execSQL("DROP VIEW IF EXISTS transactions_committed"); db.execSQL("DROP VIEW IF EXISTS transactions_uncommitted"); db.execSQL("DROP VIEW IF EXISTS transactions_all"); db.execSQL("DROP VIEW IF EXISTS templates_all"); db.execSQL("CREATE VIEW transactions_extended" + buildViewDefinitionExtended(TABLE_TRANSACTIONS) + " WHERE " + KEY_STATUS + " != " + STATUS_UNCOMMITTED + ";"); db.execSQL("CREATE VIEW templates_extended" + buildViewDefinitionExtended(TABLE_TEMPLATES)); String viewTransactions = buildViewDefinition(TABLE_TRANSACTIONS); db.execSQL("CREATE VIEW transactions_committed " + viewTransactions + " WHERE " + KEY_STATUS + " != " + STATUS_UNCOMMITTED + ";"); db.execSQL("CREATE VIEW transactions_uncommitted" + viewTransactions + " WHERE " + KEY_STATUS + " = " + STATUS_UNCOMMITTED + ";"); db.execSQL("CREATE VIEW transactions_all" + viewTransactions); db.execSQL("CREATE VIEW templates_all" + buildViewDefinition(TABLE_TEMPLATES)); }
From source file:net.smart_json_database.JSONDatabase.java
/** * Deletes all content without the meta data * /*from w w w.ja v a 2s.c o m*/ * @return true if all delte operations are succesfull */ public boolean clearAllTables() { boolean returnValue = true; SQLiteDatabase db = dbHelper.getWritableDatabase(); try { db.beginTransaction(); //db.execSQL("DELETE FROM " + TABLE_Meta); db.execSQL("DELETE FROM " + TABLE_TAG); db.execSQL("DELETE FROM " + TABLE_JSON_DATA); db.execSQL("DELETE FROM " + TABLE_REL_TAG_JSON_DATA); db.setTransactionSuccessful(); } catch (Exception e) { returnValue = false; } finally { db.endTransaction(); db.close(); } return returnValue; }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
@Override public void onCreate(SQLiteDatabase db) { try {//from www . j a v a 2 s. c o m // creating required tables db.execSQL(CREATE_TABLE_RESPONSE_FILTERS); db.execSQL(CREATE_TABLE_DOMAIN_FILTERS); db.execSQL(CREATE_TABLE_ALLOWED_DOMAINS); db.execSQL(CREATE_TABLE_BLOCKED_DOMAINS); db.execSQL(CREATE_TABLE_PENDING_NOTIFICATIONS); db.execSQL(CREATE_TABLE_TRUSTED_ACCESS_POINTS); db.execSQL(CREATE_TABLE_STATISTICS); db.execSQL("INSERT INTO " + TABLE_STATISTICS + " VALUES (null, 0, 0, 0, 0, 0, 0, 0, 0)"); } catch (Exception e) { Log.d("ERROR", e.getMessage()); } }
From source file:org.totschnig.myexpenses.provider.TransactionDatabase.java
@Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); db.execSQL(PAYEE_CREATE);/*from w w w . jav a 2s. c o m*/ db.execSQL(PAYMENT_METHODS_CREATE); db.execSQL(TEMPLATE_CREATE); db.execSQL(PLAN_INSTANCE_STATUS_CREATE); String viewTransactions = buildViewDefinition(TABLE_TRANSACTIONS); db.execSQL("CREATE VIEW " + VIEW_COMMITTED + viewTransactions + " WHERE " + KEY_STATUS + " != " + STATUS_UNCOMMITTED + ";"); db.execSQL("CREATE VIEW " + VIEW_UNCOMMITTED + viewTransactions + " WHERE " + KEY_STATUS + " = " + STATUS_UNCOMMITTED + ";"); db.execSQL("CREATE VIEW " + VIEW_ALL + viewTransactions); db.execSQL("CREATE VIEW " + VIEW_TEMPLATES + buildViewDefinition(TABLE_TEMPLATES)); db.execSQL(CATEGORIES_CREATE); db.execSQL(ACCOUNTS_CREATE); db.execSQL("CREATE VIEW " + VIEW_EXTENDED + buildViewDefinitionExtended(TABLE_TRANSACTIONS) + " WHERE " + KEY_STATUS + " != " + STATUS_UNCOMMITTED + ";"); db.execSQL("CREATE VIEW " + VIEW_TEMPLATES_EXTENDED + buildViewDefinitionExtended(TABLE_TEMPLATES)); db.execSQL(ACCOUNTS_TRIGGER_CREATE); insertDefaultAccount(db); db.execSQL(ACCOUNTTYE_METHOD_CREATE); insertDefaultPaymentMethods(db); db.execSQL(CURRENCY_CREATE); //category for splits needed to honour foreign constraint ContentValues initialValues = new ContentValues(); initialValues.put(KEY_ROWID, SPLIT_CATID); initialValues.put(KEY_PARENTID, SPLIT_CATID); initialValues.put(KEY_LABEL, "__SPLIT_TRANSACTION__"); db.insertOrThrow(TABLE_CATEGORIES, null, initialValues); insertCurrencies(db); db.execSQL(EVENT_CACHE_CREATE); db.execSQL(STALE_URIS_CREATE); db.execSQL(STALE_URI_TRIGGER_CREATE); db.execSQL("CREATE INDEX transactions_cat_id_index on " + TABLE_TRANSACTIONS + "(" + KEY_CATID + ")"); db.execSQL("CREATE INDEX templates_cat_id_index on " + TABLE_TEMPLATES + "(" + KEY_CATID + ")"); }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // on upgrade drop older tables db.execSQL("DROP TABLE IF EXISTS " + TABLE_RESPONSE_FILTERS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_DOMAIN_FILTERS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_ALLOWED_DOMAINS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_BLOCKED_DOMAINS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_PENDING_NOTIFICATIONS); db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE_TRUSTED_ACCESS_POINTS); db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE_STATISTICS); // create new tables onCreate(db);/*from w w w . j a v a 2 s .co m*/ }