Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.bodprod.rettinfo;
- import java.util.ArrayList;
- import java.util.HashMap;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.util.Log;
- public class DatabaseHandler extends SQLiteOpenHelper {
- // All Static variables
- // Database Version
- private static final int DATABASE_VERSION = 7;
- // Database Name
- private static final String DATABASE_NAME = "rettinfo";
- // Antidot table name
- private static final String TABLE_ANTIDOT = "antidotlist";
- // Antidot Table Columns names
- private static final String KEY_ID = "id";
- private static final String KEY_TOX = "tox";
- private static final String KEY_ANTIDOT = "antidot";
- private static final String KEY_DOS = "dos";
- private static final String KEY_KAT = "kat";
- public DatabaseHandler(Context context) {
- super(context, DATABASE_NAME, null, DATABASE_VERSION);
- }
- // Creating Tables
- @Override
- public void onCreate(SQLiteDatabase db) {
- Log.d("Create: ", "Creating ..");
- String CREATE_ANTIDOT_TABLE = "CREATE TABLE " + TABLE_ANTIDOT + "("
- + KEY_ID + " INTEGER PRIMARY KEY," + KEY_TOX + " TEXT,"
- + KEY_ANTIDOT + " TEXT," + KEY_DOS + " TEXT," + KEY_KAT + " INTEGER" + ")";
- Log.d("Create: ", CREATE_ANTIDOT_TABLE);
- db.execSQL(CREATE_ANTIDOT_TABLE);
- ContentValues values = new ContentValues();
- values.put(KEY_TOX, "Alkylphosphat");
- values.put(KEY_ANTIDOT, "Atropinsulfat");
- values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min 
 Kinder - Initial: 0,5 - 2 mg i.V. 
 bis zum Rückgang der Bronchialsekretion");
- values.put(KEY_KAT, "1");
- db.insert(TABLE_ANTIDOT, null, values);
- values.put(KEY_TOX, "E605 (Alkylphosphat)");
- values.put(KEY_ANTIDOT, "Atropinsulfat");
- values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min 
 Kinder - Initial: 0,5 - 2 mg i.V. 
 bis zum Rückgang der Bronchialsekretion");
- values.put(KEY_KAT, "1");
- db.insert(TABLE_ANTIDOT, null, values);
- values.put(KEY_TOX, "DDVP (Alkylphosphat)");
- values.put(KEY_ANTIDOT, "Atropinsulfat");
- values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min 
 Kinder - Initial: 0,5 - 2 mg i.V. 
 bis zum Rückgang der Bronchialsekretion");
- values.put(KEY_KAT, "1");
- db.insert(TABLE_ANTIDOT, null, values);
- values.put(KEY_TOX, "Sarin (Alkylphosphat)");
- values.put(KEY_ANTIDOT, "Atropinsulfat");
- values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min 
 Kinder - Initial: 0,5 - 2 mg i.V. 
 bis zum Rückgang der Bronchialsekretion");
- values.put(KEY_KAT, "1");
- db.insert(TABLE_ANTIDOT, null, values);
- values.put(KEY_TOX, "Nervengas (Alkylphosphat)");
- values.put(KEY_ANTIDOT, "Atropinsulfat");
- values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min 
 Kinder - Initial: 0,5 - 2 mg i.V. 
 bis zum Rückgang der Bronchialsekretion");
- values.put(KEY_KAT, "1");
- db.insert(TABLE_ANTIDOT, null, values);
- }
- // Upgrading database
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // Drop older table if existed
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_ANTIDOT);
- // Create tables again
- onCreate(db);
- }
- public ArrayList<HashMap<String,Object>> getAllAntidots() {
- ArrayList<HashMap<String,Object>> antidotList = new ArrayList<HashMap<String,Object>>();
- String selectQuery = "SELECT * FROM " + TABLE_ANTIDOT + " ORDER BY " + KEY_TOX;
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- HashMap<String , Object> antidot;
- if (cursor.moveToFirst()) {
- do {
- antidot = new HashMap<String, Object>();
- antidot.put("sql_id", Integer.parseInt(cursor.getString(0)));
- antidot.put("toxin", cursor.getString(1));
- antidot.put("antidot", cursor.getString(2));
- antidotList.add(antidot);
- } while (cursor.moveToNext());
- }
- return antidotList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment