Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. package com.examples.android.calendar;
  2.  
  3.  
  4. import android.content.ContentValues;
  5. import android.content.Context;
  6. import android.database.Cursor;
  7. import android.database.SQLException;
  8. import android.database.sqlite.SQLiteDatabase;
  9.  
  10.  
  11. public class DatabaseConnector {
  12.  
  13. private static final String DB_NAME = "watchaday";
  14. private SQLiteDatabase database;
  15. private DatabaseOpenHelper dbOpenHelper;
  16.  
  17. public DatabaseConnector(Context context) {
  18. dbOpenHelper = new DatabaseOpenHelper(context, DB_NAME, null, 1);
  19. }
  20.  
  21. public void open() throws SQLException
  22. {
  23. //open database in reading/writing mode
  24. database = dbOpenHelper.getWritableDatabase();
  25. }
  26.  
  27. public void close()
  28. {
  29. if (database != null)
  30. database.close();
  31. }
  32.  
  33. public void insertContact(String date, String hour_from, String hour_to, String event, String colour)
  34. {
  35. ContentValues newCon = new ContentValues();
  36. newCon.put("date", date);
  37. newCon.put("hour_from", hour_from);
  38. newCon.put("hour_to", hour_to);
  39. newCon.put("event", event);
  40. newCon.put("colour", colour);
  41.  
  42.  
  43.  
  44. open();
  45. database.insert("calendar_events", null, newCon);
  46. close();
  47. }
  48.  
  49.  
  50. public void updateContact(long id, String date, String hour_from, String hour_to, String event, String colour)
  51. {
  52. ContentValues editCon = new ContentValues();
  53. ;
  54. editCon.put("date", date);
  55. editCon.put("hour_from", hour_from);
  56. editCon.put("hour_to", hour_to);
  57. editCon.put("event", event);
  58. editCon.put("colour", colour);
  59.  
  60.  
  61. open();
  62. database.update("calendar_events", editCon, "_id=" + id, null);
  63. close();
  64. }
  65.  
  66.  
  67. public Cursor getAllContacts()
  68. {
  69. return database.query("calendar_events", new String[] {"_id", "event"},
  70. null, null, null, null, "date");
  71. }
  72.  
  73. public Cursor getOneContact(long id)
  74. {
  75. return database.query("calendar_events", null, "_id=" + id, null, null, null, null);
  76. }
  77.  
  78. public void deleteContact(long id)
  79. {
  80. open();
  81. database.delete("calendar_events", "_id=" + id, null);
  82. close();
  83. }
  84.  
  85. public Cursor getdate(String data){
  86.  
  87. return database.rawQuery("SELECT event FROM calendar_events WHERE date = '" + data + "'", new String[] { "event"});
  88.  
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement