public class SampleDatabaseClass extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "Database.db";
private static final int SCHEMA_VERSION = 1;
public SampleDatabaseClass (Context context) {
super(context, DATABASE_NAME, null, SCHEMA_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE Table Name( _id INTEGER PRIMARY KEY AUTOINCREMENT,title text,message text,Created text);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
// db.execSQL("ALTER TABLE Table Name ADD COLUMN Created DATE NULL");
}
public void insert(String title, String message,String Creation_date) {
ContentValues cv = new ContentValues();
cv.put("title", title);
cv.put("message", message);
cv.put("Created", Creation_date);
getWritableDatabase().insert("Table Name","title", cv);
}
public void update( String id,String title, String message,String Creation_date) {
ContentValues cv = new ContentValues();
String[] args ={id};
cv.put("title", title);
cv.put("message", message);
cv.put("Created", Creation_date);
getWritableDatabase().update("Table Name", cv, "_id=?", args);
}
public Cursor getAll(String orderby) {
return (getReadableDatabase().rawQuery(
"SELECT _id,title,message,Created from Table Name ORDER BY "+orderby, null));
}
public String getTitle(Cursor c) {
return (c.getString(1));
}
public String getMessage(Cursor c) {
return (c.getString(2));
}
public String getDate(Cursor c){
return(c.getString(3));
}
public Cursor getById(String id){
String [] args={id};
return (getReadableDatabase().rawQuery("SELECT _id,title,message,Created from Table Name here _id =?", args));
}
}
0 comments: