android.database.SQLException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中android.database.SQLException.getMessage()方法的一些代码示例,展示了SQLException.getMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException.getMessage()方法的具体详情如下:
包路径:android.database.SQLException
类名称:SQLException
方法名:getMessage

SQLException.getMessage介绍

暂无

代码示例

代码示例来源:origin: filippella/Dagger-Rx-Database-MVP

@Override
public void onCreate(SQLiteDatabase db) {
  try {
    db.execSQL(CREATE_TABLE);
  } catch(SQLException e) {
    Log.d(TAG, e.getMessage());
  }
}

代码示例来源:origin: pires/android-obd-reader

/**
 * DESCRIPTION:
 * Deletes a specified trip record from the log.
 *
 * @param id - the TripRecord to delete.
 * @return boolean flag indicating success/failure (true=success)
 */
public boolean deleteTrip(long id) {
  final String tag = TAG + ".deleteRecord()";
  boolean success = false;
  try {
    String whereClause = RECORD_ID + "=" + id;
    String[] whereArgs = null;
    int count = db.delete(RECORDS_TABLE, whereClause, whereArgs);
    success = (count == 1);
  } catch (SQLException e) {
    Log.e(tag, "SQLException: " + e.getMessage());
  }
  return success;
}

代码示例来源:origin: fookwood/Launcher3

private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
  db.beginTransaction();
  try {
    db.execSQL("ALTER TABLE favorites ADD COLUMN "
        + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
    db.setTransactionSuccessful();
  } catch (SQLException ex) {
    Log.e(TAG, ex.getMessage(), ex);
    return false;
  } finally {
    db.endTransaction();
  }
  return true;
}

代码示例来源:origin: klinker24/launcher3

private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
  db.beginTransaction();
  try {
    db.execSQL("ALTER TABLE favorites ADD COLUMN "
        + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
    db.setTransactionSuccessful();
  } catch (SQLException ex) {
    Log.e(TAG, ex.getMessage(), ex);
    return false;
  } finally {
    db.endTransaction();
  }
  return true;
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
  db.beginTransaction();
  try {
    db.execSQL("ALTER TABLE favorites ADD COLUMN "
        + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
    db.setTransactionSuccessful();
  } catch (SQLException ex) {
    Log.e(TAG, ex.getMessage(), ex);
    return false;
  } finally {
    db.endTransaction();
  }
  return true;
}

代码示例来源:origin: fookwood/Launcher3

@Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
  db.beginTransaction();
  try {
    if (addRankColumn) {
      // Insert new column for holding rank
      db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;");
    }
    // Get a map for folder ID to folder width
    Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites"
        + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)"
        + " GROUP BY container;",
        new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)});
    while (c.moveToNext()) {
      db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE "
          + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;",
          new Object[] {c.getLong(1) + 1, c.getLong(0)});
    }
    c.close();
    db.setTransactionSuccessful();
  } catch (SQLException ex) {
    // Old version remains, which means we wipe old data
    Log.e(TAG, ex.getMessage(), ex);
    return false;
  } finally {
    db.endTransaction();
  }
  return true;
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

@Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
  db.beginTransaction();
  try {
    if (addRankColumn) {
      // Insert new column for holding rank
      db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;");
    }
    // Get a map for folder ID to folder width
    Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites"
        + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)"
        + " GROUP BY container;",
        new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)});
    while (c.moveToNext()) {
      db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE "
          + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;",
          new Object[] {c.getLong(1) + 1, c.getLong(0)});
    }
    c.close();
    db.setTransactionSuccessful();
  } catch (SQLException ex) {
    // Old version remains, which means we wipe old data
    Log.e(TAG, ex.getMessage(), ex);
    return false;
  } finally {
    db.endTransaction();
  }
  return true;
}

代码示例来源:origin: filippella/Dagger-Rx-Database-MVP

public void addCake(Cake cake) {
  SQLiteDatabase db = this.getWritableDatabase();
  ContentValues values = new ContentValues();
  values.put(TITLE, cake.getTitle());
  values.put(PREVIEW_DESCRIPTION, cake.getPreviewDescription());
  values.put(DETAIL_DESCRIPTION, cake.getDetailDescription());
  values.put(IMAGE_URL, cake.getImageUrl());
  try {
    db.insert(TABLE_NAME, null, values);
  } catch(SQLException e) {
    Log.d(TAG, e.getMessage());
  }
  db.close();
}

代码示例来源:origin: openbmap/radiocells-scanner-android

@Override
protected final Boolean doInBackground(final Void... params) {
  Log.i(TAG, "Cleaning database");
  try {
    final SQLiteDatabase db = new DatabaseHelper(mContext.getApplicationContext()).getWritableDatabase();
    db.execSQL("VACUUM");
    Log.i(TAG, "Finished cleaning");
    db.close();
  } catch (final SQLiteDatabaseLockedException e){
    // possibly a database upgrade is currently taking place
    Log.e(TAG, "Error locking database");
    return false;
  } catch (final SQLiteException e) {
    Log.e(TAG, "Database error: " + e.getMessage());
    return false;
  } catch (final SQLException e) {
    Log.e(TAG, "Generic database expection: " + e.getMessage());
    return false;
  }
  return true;
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

private boolean addProfileColumn(SQLiteDatabase db) {
  db.beginTransaction();
  try {
    UserManagerCompat userManager = UserManagerCompat.getInstance(mContext);
    // Default to the serial number of this user, for older
    // shortcuts.
    long userSerialNumber = userManager.getSerialNumberForUser(
        UserHandleCompat.myUserHandle());
    // Insert new column for holding user serial number
    db.execSQL("ALTER TABLE favorites " +
        "ADD COLUMN profileId INTEGER DEFAULT "
                + userSerialNumber + ";");
    db.setTransactionSuccessful();
  } catch (SQLException ex) {
    // Old version remains, which means we wipe old data
    Log.e(TAG, ex.getMessage(), ex);
    return false;
  } finally {
    db.endTransaction();
  }
  return true;
}

代码示例来源:origin: apptentive/apptentive-android

void deleteAllPayloads() {
  // TODO: Delete files too.
  SQLiteDatabase db;
  try {
    db = getWritableDatabase();
    db.delete(PayloadEntry.TABLE_NAME, "", null);
  } catch (SQLException sqe) {
    ApptentiveLog.e(DATABASE, "deleteAllPayloads EXCEPTION: " + sqe.getMessage());
    logException(sqe);
  }
}

代码示例来源:origin: filippella/Dagger-Rx-Database-MVP

public List<Cake> getSavedCakes() {
  List<Cake> cakeList = new ArrayList<>();
  SQLiteDatabase db = this.getWritableDatabase();
  try {
    Cursor cursor = db.rawQuery(SELECT_QUERY, null);
    if (cursor != null) {
      if (cursor.getCount() > 0) {
        if (cursor.moveToFirst()) {
          do {
            Cake cake = new Cake();
            cake.setTitle(cursor.getString(cursor.getColumnIndex(TITLE)));
            cake.setPreviewDescription(cursor.getString(cursor.getColumnIndex(PREVIEW_DESCRIPTION)));
            cake.setDetailDescription(cursor.getString(cursor.getColumnIndex(DETAIL_DESCRIPTION)));
            cake.setImageUrl(cursor.getString(cursor.getColumnIndex(IMAGE_URL)));
            cakeList.add(cake);
          } while (cursor.moveToNext());
        }
      }
    }
  } catch (SQLException e) {
    Log.d(TAG, e.getMessage());
  }
  return cakeList;
}

代码示例来源:origin: denzilferreira/aware-client

/**
 * Logs the current timezone
 */
private void retrieveTimezone() {
  if (lastTimezone.equalsIgnoreCase(TimeZone.getDefault().getID())) return;
  lastTimezone = TimeZone.getDefault().getID();
  ContentValues rowData = new ContentValues();
  rowData.put(TimeZone_Data.TIMESTAMP, System.currentTimeMillis());
  rowData.put(TimeZone_Data.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
  rowData.put(TimeZone_Data.TIMEZONE, lastTimezone);
  try {
    getContentResolver().insert(TimeZone_Data.CONTENT_URI, rowData);
    if (Aware.DEBUG) Log.d(Aware.TAG, rowData.toString());
    if (awareSensor != null) awareSensor.onTimezoneChanged(rowData);
    Intent newTimeZone = new Intent(ACTION_AWARE_TIMEZONE);
    newTimeZone.putExtra(EXTRA_DATA, rowData);
    sendBroadcast(newTimeZone);
  } catch (SQLiteException e) {
    if (Aware.DEBUG) Log.d(TAG, e.getMessage());
  } catch (SQLException e) {
    if (Aware.DEBUG) Log.d(TAG, e.getMessage());
  } catch (IllegalStateException e) {
    if (Aware.DEBUG) Log.d(TAG, e.getMessage());
  }
}

代码示例来源:origin: turbomanage/storm-gen

/**
 * Backs up the current table to a CSV file.
 *
 * @param db
 * @param ctx
 * @param suffix 
 * 
 * @return true on success
 */
public boolean backup(SQLiteDatabase db, Context ctx, String suffix) {
  try {
    new CsvTableWriter(this).dumpToCsv(ctx, db, suffix);
  } catch (SQLException e) {
    if (e.getMessage().contains("no such table")) {
      Log.w(TAG, "Table " + this.getTableName() + " doesn't exist. This is expected if the table is new in this db version.");
    }
  } catch (FileNotFoundException e) {
    e.printStackTrace();
    return false;
  }
  return true;
}

代码示例来源:origin: denzilferreira/aware-client

@Override
  public String call() throws Exception {
    ContentValues rowData = new ContentValues();
    rowData.put(WiFi_Sensor.DEVICE_ID, Aware.getSetting(mContext, Aware_Preferences.DEVICE_ID));
    rowData.put(WiFi_Sensor.TIMESTAMP, System.currentTimeMillis());
    rowData.put(WiFi_Sensor.MAC_ADDRESS, Encrypter.hashMac(mContext, mWifi.getMacAddress()));
    rowData.put(WiFi_Sensor.BSSID, Encrypter.hashMac(mContext, mWifi.getBSSID()));
    rowData.put(WiFi_Sensor.SSID, Encrypter.hashSsid(mContext, mWifi.getSSID()));
    try {
      mContext.getContentResolver().insert(WiFi_Sensor.CONTENT_URI, rowData);
      Intent currentAp = new Intent(ACTION_AWARE_WIFI_CURRENT_AP);
      currentAp.putExtra(EXTRA_DATA, rowData);
      mContext.sendBroadcast(currentAp);
      if (Aware.DEBUG) Log.d(TAG, "WiFi local sensor information: " + rowData.toString());
    } catch (SQLiteException e) {
      if (Aware.DEBUG) Log.d(TAG, e.getMessage());
    } catch (SQLException e) {
      if (Aware.DEBUG) Log.d(TAG, e.getMessage());
    }
    return Thread.currentThread().getName();
  }
}

代码示例来源:origin: apptentive/apptentive-android

void deleteAssociatedFiles(String messageNonce) {
  SQLiteDatabase db = null;
  try {
    db = getWritableDatabase();
    int deleted = db.delete(TABLE_COMPOUND_MESSAGE_FILESTORE, COMPOUND_FILESTORE_KEY_MESSAGE_NONCE + " = ?", new String[]{messageNonce});
    ApptentiveLog.d(DATABASE, "Deleted %d stored files.", deleted);
  } catch (SQLException sqe) {
    ApptentiveLog.e(DATABASE, "deleteAssociatedFiles EXCEPTION: " + sqe.getMessage());
    logException(sqe);
  }
}

代码示例来源:origin: pires/android-obd-reader

public TripRecord startTrip() {
  final String tag = TAG + ".createRecord()";
  try {
    TripRecord record = new TripRecord();
    long rowID = db.insertOrThrow(RECORDS_TABLE, null, getContentValues(record));
    record.setID((int) rowID);
    return record;
  } catch (SQLiteConstraintException e) {
    Log.e(tag, "SQLiteConstraintException: " + e.getMessage());
  } catch (SQLException e) {
    Log.e(tag, "SQLException: " + e.getMessage());
  }
  return null;
}

代码示例来源:origin: tgwizard/sls

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.status_activity);
  settings = new AppSettings(this);
  mDb = new ScrobblesDatabase(this);
  try {
    mDb.open();
  } catch (SQLException e) {
    Log.e(TAG, "Cannot open database!");
    Log.e(TAG, e.getMessage());
    mDb = null;
  }
  //getSupportActionBar().setElevation(0);
  //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  //setSupportActionBar(toolbar);
  //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  // manifest android:theme="@style/Theme.AppCompat.NoActionBar"
  ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
  if (viewPager != null) {
    setupViewPager(viewPager);
  }
  TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
  tabLayout.setupWithViewPager(viewPager);
}

代码示例来源:origin: pires/android-obd-reader

/**
 * DESCRIPTION:
 * Updates a trip record in the log.
 *
 * @param record - the TripRecord to update.
 * @return boolean flag indicating success/failure (true=success)
 */
public boolean updateRecord(TripRecord record) {
  final String tag = TAG + ".updateRecord()";
  ASSERT((record.getID() != null), tag, "record id cannot be null");
  boolean success = false;
  try {
    ContentValues values = getContentValues(record);
    values.remove(RECORD_ID);
    String whereClause = RECORD_ID + "=" + record.getID();
    int count = db.update(RECORDS_TABLE, values, whereClause, null);
    success = (count > 0);
  } catch (SQLiteConstraintException e) {
    Log.e(tag, "SQLiteConstraintException: " + e.getMessage());
  } catch (SQLException e) {
    Log.e(tag, "SQLException: " + e.getMessage());
  }
  return success;
}

代码示例来源:origin: apptentive/apptentive-android

void deletePayload(String payloadIdentifier) {
  if (payloadIdentifier == null) {
    throw new IllegalArgumentException("Payload identifier is null");
  }
  // First delete the row
  SQLiteDatabase db;
  try {
    db = getWritableDatabase();
    db.delete(
      PayloadEntry.TABLE_NAME,
      PayloadEntry.COLUMN_IDENTIFIER + " = ?",
      new String[]{payloadIdentifier}
    );
  } catch (SQLException sqe) {
    ApptentiveLog.e(DATABASE, "deletePayload EXCEPTION: " + sqe.getMessage());
    logException(sqe);
  }
  // Then delete the data file
  File dest = getPayloadBodyFile(payloadIdentifier);
  ApptentiveLog.v(DATABASE, "Deleted payload \"%s\" data file successfully? %b", payloadIdentifier, dest.delete());
  if (ApptentiveLog.canLog(ApptentiveLog.Level.VERBOSE)) {
    printPayloadTable("Deleted payload");
  }
}

相关文章