+++ /dev/null
-package ro.ieval.unical;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.database.SQLException;
-import android.database.sqlite.SQLiteDatabase;
-
-public class DatabaseInteract {
- private SQLiteDatabase database;
- private MySQLiteHelper dbHelper;
- private String[] allColumns = {
- MySQLiteHelper.ID, MySQLiteHelper.title,
- MySQLiteHelper.description, MySQLiteHelper.date,
- MySQLiteHelper.duration, MySQLiteHelper.repeat,
- MySQLiteHelper.repeatIn, MySQLiteHelper.location
- };
-
- public DatabaseInteract(Context context) {
- dbHelper = new MySQLiteHelper(context);
- database=dbHelper.getWritableDatabase();
- }
-
- public void open() throws SQLException {
- database=dbHelper.getWritableDatabase();
- }
-
- public void close() {
- dbHelper.close();
- }
-
- //Insert event
- public void insertEvent(Event e) {
- ContentValues values = new ContentValues();
- values.put(allColumns[0], e._id);
- values.put(allColumns[1], e.title);
- values.put(allColumns[2], e.description);
- values.put(allColumns[3], e.date);
- values.put(allColumns[4], e.duration);
- values.put(allColumns[5], e.repeat);
- values.put(allColumns[6], e.repeatInterval);
- values.put(allColumns[7], e.location);
- database.insert(MySQLiteHelper.Name, null, values);
- }
- //Delete event
- public void deleteEvent(String id) {
- database.delete(MySQLiteHelper.Name, MySQLiteHelper.ID + "=" + id, null);
- }
- //Search event
- //Get all events
- public List<Event> getAllEvents() {
- List<Event> events=new ArrayList<Event>();
- Cursor cursor=database.query(MySQLiteHelper.Name,allColumns,null,null,null,null,null);
-
- for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()) {
- Event ev=cursorToEvent(cursor);
- events.add(ev);
- }
- return events;
- }
-
- private Event cursorToEvent(Cursor cursor) {
- // TODO Auto-generated method stub
- Event e = new Event();
- e._id=cursor.getString(0);
- e.title=cursor.getString(1);
- e.description=cursor.getString(2);
- e.date=cursor.getInt(3);
- e.duration=cursor.getInt(4);
- if(cursor.getInt(5)==1) e.repeat=true;
- else e.repeat=false;
- e.repeatInterval=cursor.getInt(6);
- e.location=cursor.getString(7);
- return e;
- }
-}
+++ /dev/null
-package ro.ieval.unical;
-
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.util.Log;
-
-public class MySQLiteHelper extends SQLiteOpenHelper {
- public static final String Name="Events";
-
- public static final String ID = "_id";
- public static final String title = "Title";
- public static final String description = "Description";
- public static final String date = "Date";
- public static final String duration = "Duration";
- public static final String repeat = "repeat";
- public static final String repeatIn = "repeatInterval";
- public static final String location = "Location";
-
- private static final int dbversion=1;
-
- private static final String Database_create = "create table " + Name + "(" +
- //ID + " integer primary key autoincrement, " +
- ID + " text primary key, " +
- title + " text not null, " +
- description + " text, " +
- date + " integer, " +
- duration + " integer, " +
- repeat + " integer, "+
- repeatIn + " integer, " +
- location + " text);"
- ;
-
- public MySQLiteHelper(Context context) {
- super(context,Name, null, dbversion);
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- db.execSQL(Database_create);
-
- }
-
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // TODO Auto-generated method stub
- Log.w(MySQLiteHelper.class.getName(),
- "Upgrading database from version " + oldVersion + " to "
- + newVersion + ", which will destroy all old data");
- db.execSQL("DROP TABLE IF EXISTS " + Name);
- onCreate(db);
- }
-
-}
\ No newline at end of file