The class CommentsDataSource
is this application’s DAO (data access object), which provides an abstract interface to a database.
The method createComment
, which adds a new comment to the database and returns the comment, is implemented as follows:
public Comment createComment( String comment ) {
ContentValues values = new ContentValues( );
values.put( MySQLiteHelper.COLUMN_COMMENT, comment );
long insertId = database.insert(
MySQLiteHelper.TABLE_COMMENTS, null, values );
Cursor cursor = database.query( MySQLiteHelper.TABLE_COMMENTS,
allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId,
null, null, null, null );
cursor.moveToFirst( );
return cursorToComment( cursor );
}