<commit_before><commit_msg>Database handler<commit_after>package edu.yalestc.yalepublic.Cache;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;

/**
 * Created by <NAME> on 1/3/15.
 */

public class CalendarDatabaseTableHandler extends SQLiteOpenHelper {

    private static final int TABLE_VERSION = 0;
    private static final String TABLE_NAME = "events";
    String TABLE_CREATE =
            "CREATE TABLE " + TABLE_NAME+ " (" +
                    "Date" + " TEXT, " +
                    "Title" + " TEXT, "+
                    "StartTime" + " TEXT, " +
                    "EndTime" + " TEXT, " +
                    "Location" + " TEXT, " +
                    "Description" + " TEXT, " +
                    "Category" + " TEXT, " +
                    "NumericalDate" + "INTEGER);";

    CalendarDatabaseTableHandler(Context context){
        super(context, TABLE_NAME, null, TABLE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
    }

    public void addEvent(String[] eventInfo){
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put("Date", eventInfo[4]);
        values.put("Title", eventInfo[0]);
        values.put("StartTime", eventInfo[1]);
        values.put("EndTime", eventInfo[2]);
        values.put("Location", eventInfo[3]);
        values.put("Description",eventInfo[5]);
        values.put("Category", eventInfo[6]);
            //for easier implementation of deleteEvents
        values.put("NumericalDate", Integer.parseInt(eventInfo[4]));

        db.insert(TABLE_NAME, null, values);
        db.close();
    }

    public ArrayList<String[]> getEvents(String date){
       SQLiteDatabase db = this.getReadableDatabase();

        String query = "select * from " + TABLE_NAME
                + "where Date in ('Date'," + date +");";

        Cursor cursor = db.rawQuery(query,null);
        ArrayList<String[]> result = new ArrayList<String[]>();
        if(cursor.moveToFirst()){
            do {
                String[] event = new String[7];
                for (int i = 0; i < 7; i++)
                    event[i] = cursor.getString(i);
                result.add(event);
            } while (cursor.moveToNext());
        }
        return result;
    }

    public void deleteEvents(int lowerBoundDate, int upperBoundDate){
        SQLiteDatabase db = this.getWritableDatabase();

        String query = "delete from " + TABLE_NAME
                + "where NumericalDate > " + Integer.toString(upperBoundDate) +
                " OR NumericalDate < " + Integer.toString(lowerBoundDate) + ";";

        db.rawQuery(query, null);
        db.close();
    }
}
{'fraction_non_alphanumeric': 0.12579034941763728, 'fraction_numerical': 0.005657237936772047, 'mean_word_length': 2.2603036876355747, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '532940', 'n_tokens_mistral': 851, 'n_tokens_neox': 813, 'n_words': 181}