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

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

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

SQLException.<init>介绍

暂无

代码示例

代码示例来源:origin: google/agera

@Override
public void onCreate(final SQLiteDatabase sqLiteDatabase) {
 throw new SQLException();
}

代码示例来源:origin: ankidroid/Anki-Android

public String queryString(String query) throws SQLException {
  Cursor cursor = null;
  try {
    cursor = mDatabase.query(query, null);
    if (!cursor.moveToNext()) {
      throw new SQLException("No result for query: " + query);
    }
    return cursor.getString(0);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public Uri insert(Uri url, ContentValues initialValues) {
 long rowID=
   db.getWritableDatabase().insert(TABLE, Constants.TITLE,
                   initialValues);
 if (rowID > 0) {
  Uri uri=
    ContentUris.withAppendedId(Provider.Constants.CONTENT_URI,
                  rowID);
  getContext().getContentResolver().notifyChange(uri, null);
  return(uri);
 }
 throw new SQLException("Failed to insert row into " + url);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public Uri insert(Uri url, ContentValues initialValues) {
 long rowID=
   db.getWritableDatabase().insert(TABLE, Constants.TITLE,
                   initialValues);
 if (rowID > 0) {
  Uri uri=
    ContentUris.withAppendedId(Provider.Constants.CONTENT_URI,
                  rowID);
  getContext().getContentResolver().notifyChange(uri, null);
  return(uri);
 }
 throw new SQLException("Failed to insert row into " + url);
}

代码示例来源:origin: udacity/ud851-Exercises

@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
  // Get access to the task database (to write new data to)
  final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase();
  // Write URI matching code to identify the match for the tasks directory
  int match = sUriMatcher.match(uri);
  Uri returnUri; // URI to be returned
  switch (match) {
    case TASKS:
      // Insert new values into the database
      // Inserting values into tasks table
      long id = db.insert(TABLE_NAME, null, values);
      if ( id > 0 ) {
        returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id);
      } else {
        throw new android.database.SQLException("Failed to insert row into " + uri);
      }
      break;
    // Set the value for the returnedUri and write the default case for unknown URI's
    // Default case throws an UnsupportedOperationException
    default:
      throw new UnsupportedOperationException("Unknown uri: " + uri);
  }
  // Notify the resolver if the uri has been changed, and return the newly inserted URI
  getContext().getContentResolver().notifyChange(uri, null);
  // Return constructed uri (this points to the newly inserted row of data)
  return returnUri;
}

代码示例来源:origin: udacity/ud851-Exercises

@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
  // Get access to the task database (to write new data to)
  final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase();
  // Write URI matching code to identify the match for the tasks directory
  int match = sUriMatcher.match(uri);
  Uri returnUri; // URI to be returned
  switch (match) {
    case TASKS:
      // Insert new values into the database
      // Inserting values into tasks table
      long id = db.insert(TABLE_NAME, null, values);
      if ( id > 0 ) {
        returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id);
      } else {
        throw new android.database.SQLException("Failed to insert row into " + uri);
      }
      break;
    // Set the value for the returnedUri and write the default case for unknown URI's
    // Default case throws an UnsupportedOperationException
    default:
      throw new UnsupportedOperationException("Unknown uri: " + uri);
  }
  // Notify the resolver if the uri has been changed, and return the newly inserted URI
  getContext().getContentResolver().notifyChange(uri, null);
  // Return constructed uri (this points to the newly inserted row of data)
  return returnUri;
}

代码示例来源:origin: udacity/ud851-Exercises

@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
  // COMPLETED (1) Get access to the task database (to write new data to)
  final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase();
  // COMPLETED (2) Write URI matching code to identify the match for the tasks directory
  int match = sUriMatcher.match(uri);
  Uri returnUri; // URI to be returned
  switch (match) {
    case TASKS:
      // COMPLETED (3) Insert new values into the database
      // Inserting values into tasks table
      long id = db.insert(TABLE_NAME, null, values);
      if ( id > 0 ) {
        returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id);
      } else {
        throw new android.database.SQLException("Failed to insert row into " + uri);
      }
      break;
    // COMPLETED (4) Set the value for the returnedUri and write the default case for unknown URI's
    // Default case throws an UnsupportedOperationException
    default:
      throw new UnsupportedOperationException("Unknown uri: " + uri);
  }
  // COMPLETED (5) Notify the resolver if the uri has been changed, and return the newly inserted URI
  getContext().getContentResolver().notifyChange(uri, null);
  // Return constructed uri (this points to the newly inserted row of data)
  return returnUri;
}

代码示例来源:origin: udacity/ud851-Exercises

@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
  // Get access to the task database (to write new data to)
  final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase();
  // Write URI matching code to identify the match for the tasks directory
  int match = sUriMatcher.match(uri);
  Uri returnUri; // URI to be returned
  switch (match) {
    case TASKS:
      // Insert new values into the database
      // Inserting values into tasks table
      long id = db.insert(TABLE_NAME, null, values);
      if ( id > 0 ) {
        returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id);
      } else {
        throw new android.database.SQLException("Failed to insert row into " + uri);
      }
      break;
    // Set the value for the returnedUri and write the default case for unknown URI's
    // Default case throws an UnsupportedOperationException
    default:
      throw new UnsupportedOperationException("Unknown uri: " + uri);
  }
  // Notify the resolver if the uri has been changed, and return the newly inserted URI
  getContext().getContentResolver().notifyChange(uri, null);
  // Return constructed uri (this points to the newly inserted row of data)
  return returnUri;
}

代码示例来源:origin: udacity/ud851-Exercises

@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
  // Get access to the task database (to write new data to)
  final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase();
  // Write URI matching code to identify the match for the tasks directory
  int match = sUriMatcher.match(uri);
  Uri returnUri; // URI to be returned
  switch (match) {
    case TASKS:
      // Insert new values into the database
      // Inserting values into tasks table
      long id = db.insert(TABLE_NAME, null, values);
      if ( id > 0 ) {
        returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id);
      } else {
        throw new android.database.SQLException("Failed to insert row into " + uri);
      }
      break;
    // Set the value for the returnedUri and write the default case for unknown URI's
    // Default case throws an UnsupportedOperationException
    default:
      throw new UnsupportedOperationException("Unknown uri: " + uri);
  }
  // Notify the resolver if the uri has been changed, and return the newly inserted URI
  getContext().getContentResolver().notifyChange(uri, null);
  // Return constructed uri (this points to the newly inserted row of data)
  return returnUri;
}

代码示例来源:origin: evernote/android-job

private void store(JobRequest request) {
  ContentValues contentValues = request.toContentValues();
  SQLiteDatabase database = null;
  try {
    database = getDatabase();
    /*
     * It could happen that a conflict with the job ID occurs, when a job was cancelled (cancelAndEdit())
     * the builder object scheduled twice. In this case the last call wins and the value in the database
     * will be overwritten.
     */
    if (database.insertWithOnConflict(JOB_TABLE_NAME, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE) < 0) {
      throw new SQLException("Couldn't insert job request into database");
    }
  } finally {
    closeDatabase(database);
  }
}

代码示例来源:origin: julesbond007/android-jigsaw-puzzle

@Override
public Uri insert(Uri uri, ContentValues values) {
  long row = db.insert(JIGSAW_TABLE, "", values);
  if (row > 0) {
    Uri newUri = ContentUris.withAppendedId(CONTENT_URI, row);
    getContext().getContentResolver().notifyChange(newUri, null);
    return newUri;
  }
  throw new SQLException("Fail to add a new record into " + uri);
}

代码示例来源:origin: payatu/diva-android

@Override
public Uri insert(Uri uri, ContentValues values) {
  long row = mDB.insert(TABLE, "", values);
  if(row > 0) {
    // Record added
    Uri newUri = ContentUris.withAppendedId(CONTENT_URI, row);
    getContext().getContentResolver().notifyChange(newUri, null);
    return newUri;
  }
  throw new SQLException("Divanotes: Fail to add a new record into " + uri);
}

代码示例来源:origin: gpfduoduo/AirPlay-Receiver-on-Android

@Override
public Uri insert(Uri uri, ContentValues values) {
  boolean isPrefrences = URI_MATCHER.match(uri) == PREFERENCES;
  if (!isPrefrences)
    throw new IllegalArgumentException("Unknown URI " + uri);
  SQLiteDatabase db = mDbHelper.getWritableDatabase();
  long rowId = db.insert(TB_NAME, null, values);
  if (rowId > 0) {
    Uri noteUri = ContentUris.withAppendedId(CONTENT_URI, rowId);
    getContext().getContentResolver().notifyChange(noteUri, null);
    return noteUri;
  }
  throw new SQLException("Failed to insert row into " + uri);
}

代码示例来源:origin: gpfduoduo/AirPlay-Receiver-on-Android

@Override
public Uri insert(Uri uri, ContentValues values) {
  boolean isPrefrences = URI_MATCHER.match(uri) == SESSIONS;
  if (!isPrefrences)
    throw new IllegalArgumentException("Unknown URI " + uri);
  SQLiteDatabase db = mDbHelper.getWritableDatabase();
  long rowId = db.insert(TB_NAME, COL_VALUE, values);
  if (rowId > 0) {
    Uri noteUri = ContentUris.withAppendedId(CONTENT_URI, rowId);
    getContext().getContentResolver().notifyChange(noteUri, null);
    return noteUri;
  }
  throw new SQLException("Failed to insert row into " + uri);
}

代码示例来源:origin: openintents/openintents

@Override
public Uri insert(Uri uri, ContentValues contentValues) {
  // Validate the requested uri
  if (sUriMatcher.match(uri) != VOICENOTES) {
    throw new IllegalArgumentException("Unknown URI " + uri);
  }
  SQLiteDatabase db = mOpenHelper.getWritableDatabase();
  long rowId = db.insert(VOICE_NOTES_TABLE_NAME, VoiceNote.DATA_URI, contentValues);
  if (rowId > 0) {
    Uri noteUri = ContentUris.withAppendedId(VoiceNote.CONTENT_URI, rowId);
    getContext().getContentResolver().notifyChange(noteUri, null);
    return noteUri;
  }
  throw new SQLException("Failed to insert row into " + uri);
}

代码示例来源:origin: andstatus/andstatus

public static long insert(MyContext myContext, String tableName, ContentValues values) {
  SQLiteDatabase db = myContext.getDatabase();
  if (db == null || values.size() == 0) return -1;
  long rowId = db.insert(tableName, null, values);
  if (rowId == -1) {
    throw new SQLException("Failed to insert " + values);
  }
  return rowId;
}

代码示例来源:origin: com.github.japgolly.android.test/robolectric

@Implementation
public long insertOrThrow(String table, String nullColumnHack, ContentValues values) throws android.database.SQLException {
  if (throwOnInsert)
    throw new android.database.SQLException();
  return insertWithOnConflict(table, nullColumnHack, values, SQLiteDatabase.CONFLICT_NONE);
}

代码示例来源:origin: matburt/mobileorg-android

@Override
public Uri insert(Uri uri, ContentValues contentValues) {
  final String tableName = getTableNameFromUri(uri);
  if (contentValues == null)
    contentValues = new ContentValues();
  SQLiteDatabase db = OrgDatabase.getInstance().getWritableDatabase();
  long rowId = 0;
  try {
    rowId = db.insert(tableName, null, contentValues);
  } catch (Exception e) {
    e.printStackTrace();
  }
  if (rowId > 0) {
    Uri noteUri = ContentUris.withAppendedId(uri, rowId);
    getContext().getContentResolver().notifyChange(noteUri, null);
    return noteUri;
  } else
    throw new SQLException("Failed to insert row into " + uri);
}

代码示例来源:origin: com.github.japgolly.android.test/robolectric

@Implementation
public void execSQL(String sql) throws android.database.SQLException {
  if (!isOpen()) {
    throw new IllegalStateException("database not open");
  }
  try {
    String scrubbedSql= DatabaseConfig.getScrubSQL(sql);
    connection.createStatement().execute(scrubbedSql);
  } catch (java.sql.SQLException e) {
    android.database.SQLException ase = new android.database.SQLException();
    ase.initCause(e);
    throw ase;
  }
}

代码示例来源:origin: henrichg/PhoneProfilesPlus

private void store(JobRequest request) {
  ContentValues contentValues = request.toContentValues();
  SQLiteDatabase database = null;
  try {
    database = getDatabase();
    /*
     * It could happen that a conflict with the job ID occurs, when a job was cancelled (cancelAndEdit())
     * the builder object scheduled twice. In this case the last call wins and the value in the database
     * will be overwritten.
     */
    if (database.insertWithOnConflict(JOB_TABLE_NAME, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE) < 0) {
      throw new SQLException("Couldn't insert job request into database");
    }
  } finally {
    closeDatabase(database);
  }
}

相关文章