Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.marci.parserv1;
- /**
- * Created by marci on 24.02.2016.
- */
- import android.content.Context;
- import android.database.Cursor;
- import android.database.SQLException;
- import android.database.sqlite.SQLiteDatabase;
- import android.util.Log;
- import java.io.IOException;
- public class TestAdapter
- {
- protected static final String TAG = "DataAdapter";
- private final Context mContext;
- private SQLiteDatabase mDb;
- private DataBaseHelper mDbHelper;
- public TestAdapter(Context context)
- {
- this.mContext = context;
- mDbHelper = new DataBaseHelper(mContext);
- }
- public TestAdapter createDatabase() throws SQLException
- {
- try
- {
- mDbHelper.createDataBase();
- }
- catch (IOException mIOException)
- {
- Log.e(TAG, mIOException.toString() + " UnableToCreateDatabase");
- throw new Error("UnableToCreateDatabase");
- }
- return this;
- }
- public TestAdapter open() throws SQLException
- {
- try
- {
- mDbHelper.openDataBase();
- mDbHelper.close();
- mDb = mDbHelper.getWritableDatabase();
- }
- catch (SQLException mSQLException)
- {
- Log.e(TAG, "open >>"+ mSQLException.toString());
- throw mSQLException;
- }
- return this;
- }
- public void close()
- {
- mDbHelper.close();
- }
- public Cursor getAll() {
- try{
- String[] columns = {"_id", "NAME", "DEPARTMENTS", "ADDRES"};
- return mDb.query("university", columns, null, null, null, null, null);
- }
- catch (SQLException mSQLException)
- {
- Log.e(TAG, "getTestData >>"+ mSQLException.toString());
- throw mSQLException;
- }
- }
- public Cursor getResult(String nazwa) {
- Cursor cursor;
- cursor=mDb.rawQuery("SELECT * FROM university" + " WHERE "
- + "NAME" +
- " LIKE '"+nazwa+"%'",null);
- return cursor;
- }
- public BuildingItem getBuilding(String namme) {
- String[] columns = {"_id", "NAME", "DEPARTMENTS", "ADDRES"};
- String where = "NAME" + "=" + namme;
- Cursor cursor = mDb.query("university", columns, where, null, null, null, null);
- BuildingItem task = null;
- if(cursor != null && cursor.moveToFirst()) {
- String departments = cursor.getString(1);
- String name = cursor.getString(2);
- String addres = cursor.getString(3);
- //boolean completed = cursor.getInt(COMPLETED_COLUMN) > 0 ? true : false;
- task = new BuildingItem(name, departments, addres);
- }
- return task;
- }
- public Cursor getTestData()
- {
- try
- {
- String sql ="SELECT * FROM university";
- Cursor mCur = mDb.rawQuery(sql, null);
- if (mCur!=null)
- {
- mCur.moveToNext();
- }
- return mCur;
- }
- catch (SQLException mSQLException)
- {
- Log.e(TAG, "getTestData >>"+ mSQLException.toString());
- throw mSQLException;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement