Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mysite.datasources;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.SQLException;
- import android.database.sqlite.SQLiteDatabase;
- import android.util.Log;
- import com.mysite.models.Section;
- import com.mysite.utilities.DateHelper;
- import com.mysite.utilities.DbHelper;
- public class SectionsDataSource
- {
- //private Context mContext;
- // Database fields
- private SQLiteDatabase database;
- private DbHelper dbHelper;
- public SectionsDataSource(Context context)
- {
- //this.mContext = context;
- dbHelper = new DbHelper(context);
- }
- public void open() throws SQLException
- {
- Log.d("mysite", "SectionsDataSource.open();");
- database = dbHelper.getWritableDatabase();
- }
- public void close()
- {
- Log.d("mysite", "SectionsDataSource.close();");
- dbHelper.close();
- }
- public void updated(String slug) {
- this.open();
- try {
- Section s1 = new Section();
- s1.last_updated = DateHelper.now();
- ContentValues values = new ContentValues();
- values.put(Section.COLUMN_LASTUPDATED, s1.last_updated);
- database.update(Section.TABLE, values, Section.COLUMN_SLUG + " = ?", new String[] { slug });
- } catch (Exception e) {
- System.out.println(e);
- }
- finally
- {
- this.close();
- }
- }
- public String last_updated(String slug) {
- this.open();
- Section s1 = new Section();
- try {
- Cursor cursor = database.query(Section.TABLE,
- new String[] { Section.COLUMN_LASTUPDATED },
- Section.COLUMN_SLUG + "=?",
- new String[] {slug},
- null, null, null, null);
- cursor.moveToFirst(); // ERRORING HERE - didn't return anything?
- s1 = cursorToSection(cursor);
- cursor.close();
- } catch (Exception e) {
- e.printStackTrace();
- s1.last_updated = "";
- }
- finally
- {
- this.close();
- }
- return s1.last_updated;
- }
- private Section cursorToSection(Cursor cursor)
- {
- Section section = new Section();
- //section.id = cursor.getLong(cursor.getColumnIndex(Section.COLUMN_ID));
- //section.title = cursor.getString(cursor.getColumnIndex(Section.COLUMN_TITLE));
- section.last_updated = cursor.getString(cursor.getColumnIndex(Section.COLUMN_LASTUPDATED));
- return section;
- }
- /*private ContentValues buildContentValues(Section section)
- {
- ContentValues values = new ContentValues();
- values.put(Section.COLUMN_TITLE, section.title);
- values.put(Section.COLUMN_LASTUPDATED, section.last_updated);
- return values;
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement