]>
iEval git - unical.git/blob - unical/DatabaseInteract.java
1 package ro
.ieval
.unical
;
3 import java
.util
.ArrayList
;
6 import android
.content
.ContentValues
;
7 import android
.content
.Context
;
8 import android
.database
.Cursor
;
9 import android
.database
.SQLException
;
10 import android
.database
.sqlite
.SQLiteDatabase
;
12 public class DatabaseInteract
{
13 private SQLiteDatabase database
;
14 private MySQLiteHelper dbHelper
;
15 private String
[] allColumns
= {
16 MySQLiteHelper
.ID
, MySQLiteHelper
.title
,
17 MySQLiteHelper
.description
, MySQLiteHelper
.date
,
18 MySQLiteHelper
.duration
, MySQLiteHelper
.repeat
,
19 MySQLiteHelper
.repeatIn
, MySQLiteHelper
.location
22 public DatabaseInteract(Context context
) {
23 dbHelper
= new MySQLiteHelper(context
);
24 database
=dbHelper
.getWritableDatabase();
27 public void open() throws SQLException
{
28 database
=dbHelper
.getWritableDatabase();
36 public void insertEvent(Event e
) {
37 ContentValues values
= new ContentValues();
38 values
.put(allColumns
[0], e
._id
);
39 values
.put(allColumns
[1], e
.title
);
40 values
.put(allColumns
[2], e
.description
);
41 values
.put(allColumns
[3], e
.date
);
42 values
.put(allColumns
[4], e
.duration
);
43 values
.put(allColumns
[5], e
.repeat
);
44 values
.put(allColumns
[6], e
.repeatInterval
);
45 values
.put(allColumns
[7], e
.location
);
46 database
.insert(MySQLiteHelper
.Name
, null, values
);
49 public void deleteEvent(String id
) {
50 database
.delete(MySQLiteHelper
.Name
, MySQLiteHelper
.ID
+ "=" + id
, null);
54 public List
<Event
> getAllEvents() {
55 List
<Event
> events
=new ArrayList
<Event
>();
56 Cursor cursor
=database
.query(MySQLiteHelper
.Name
,allColumns
,null,null,null,null,null);
58 for(cursor
.moveToFirst();!cursor
.isAfterLast();cursor
.moveToNext()) {
59 Event ev
=cursorToEvent(cursor
);
65 private Event
cursorToEvent(Cursor cursor
) {
66 // TODO Auto-generated method stub
67 Event e
= new Event();
68 e
._id
=cursor
.getString(0);
69 e
.title
=cursor
.getString(1);
70 e
.description
=cursor
.getString(2);
71 e
.date
=cursor
.getInt(3);
72 e
.duration
=cursor
.getInt(4);
73 if(cursor
.getInt(5)==1) e
.repeat
=true;
75 e
.repeatInterval
=cursor
.getInt(6);
76 e
.location
=cursor
.getString(7);
This page took 0.043782 seconds and 4 git commands to generate.