<commit_before>package com.example.student.fitabs;

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;
import java.util.List;

/**
 * Created by <NAME> on 17.11.7.
 */

public class DBHandler extends SQLiteOpenHelper {

    // Database Version
    public static final int DATABASE_VERSION = 1;
    // Database Name
    public static final String DATABASE_NAME = "userInfo";
    // Contacts table name
    public static final String TABLE_USER = "User";
    public static final String TABLE_CONTACTS = "Contacts";
    public static final String TABLE_CHAT_MESSAGE = "ChatMessage";
    public static final String TABLE_EXERCISES = "Exercises";
    public static final String TABLE_IP = "IP";
    public static final String TABLE_EVENTS = "Events";

    // USer Table Columns names
    public static final String KEY_ID = "ID";
    public static final String KEY_USERNAME = "Username";
    public static final String KEY_TEL_NUMBER = "TelephoneNumber";
    public static final String KEY_IS_TRENER = "IsTrener";

    // IP Table Columns names
    public static final String KEY_IP_ID = "ID";
    public static final String KEY_IP = "IP";

    // Contacts Table Columns names
    public static final String KEY_C_ID = "ID";
    public static final String KEY_C_USERNAME = "Username";
    public static final String KEY_C_TEL_NUMBER = "TelephoneNumber";
    public static final String KEY_C_IS_TRENER = "IsTrener";

    // ChatMessage Table Columns names
    public static final String KEY_CM_ID = "ID";
    public static final String KEY_CM_CONTACT_NUMBER = "ConcactTelephoneNumber";
    public static final String KEY_CM_MSG = "Message";

    // Exercises Table Columns names
    public static final String KEY_EX_ID = "ID";
    public static final String KEY_EX_TYPE = "ExerciseType";
    public static final String KEY_EX_NAME = "ExerciseName";
    public static final String KEY_EX_DESCRIPTION = "ExerciseDescription";
    public static final String KEY_EX_IMAGE= "Image";

    //Events Table names
    public static final String KEY_E_ID = "ID";
    public static final String KEY_E_DATE = "Date";
    public static final String KEY_E_EVENT = "Event";

    public DBHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_USERS_TABLE = "CREATE TABLE " + TABLE_USER + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_USERNAME + " TEXT, "
                + KEY_TEL_NUMBER + " TEXT, " + KEY_IS_TRENER + " TEXT" + ")";
        db.execSQL(CREATE_USERS_TABLE);

        String CREATE_IP_TABLE = "CREATE TABLE " + TABLE_IP + "("
                + KEY_IP_ID + " INTEGER PRIMARY KEY," + KEY_IP + " TEXT)";
        db.execSQL(CREATE_IP_TABLE);

        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
                + KEY_C_ID + " INTEGER PRIMARY KEY," + KEY_C_USERNAME + " TEXT, "
                + KEY_C_TEL_NUMBER + " TEXT, " + KEY_C_IS_TRENER + " TEXT" + ")";
        db.execSQL(CREATE_CONTACTS_TABLE);

        String CREATE_CHAT_MESSAGE_TABLE = "CREATE TABLE " + TABLE_CHAT_MESSAGE + "("
                + KEY_CM_ID + " INTEGER PRIMARY KEY," + KEY_CM_CONTACT_NUMBER + " TEXT, "
                + KEY_CM_MSG + " TEXT" + ")";
        db.execSQL(CREATE_CHAT_MESSAGE_TABLE);

        String CREATE_EXERCISE_TABLE = "CREATE TABLE " + TABLE_EXERCISES + "("
                + KEY_EX_ID + " INTEGER PRIMARY KEY," + KEY_EX_TYPE + " TEXT, "
                + KEY_EX_NAME + " TEXT, " + KEY_EX_DESCRIPTION + " TEXT, " + KEY_EX_IMAGE + " TEXT" + ")";
        db.execSQL(CREATE_EXERCISE_TABLE);

        String CREATE_EVENTS_TABLE = "CREATE TABLE " + TABLE_EVENTS + "("
                + KEY_E_ID + " INTEGER PRIMARY KEY," + KEY_E_DATE + " DATETIME, "
                + KEY_E_EVENT + " TEXT " + ")";
        db.execSQL(CREATE_EVENTS_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHAT_MESSAGE);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_EXERCISES);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_IP);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENTS);
        // Creating tables again
        onCreate(db);
    }

    //  INSERT : Adding new user
    public void addUser(User user) {
        SQLiteDatabase db = this.getWritableDatabase();
        //map user values with table’s column using ContentValues object
        ContentValues values = new ContentValues();
        values.put(KEY_USERNAME, user.getName());
        values.put(KEY_TEL_NUMBER, user.getTelnumber());
        values.put(KEY_IS_TRENER, user.getStatus());
        // Inserting Row
        db.insert(TABLE_USER, null, values);
        db.close(); // Closing database connection
    }
    public void addEvent(String event) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(KEY_E_EVENT, event);
        db.insert(TABLE_EVENTS, null, values);
        db.close();
    }

    public String getEvent() {
        String event = "";
        String selectQuery = "SELECT KEY_E_EVENT FROM " + TABLE_EVENTS;
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        if (cursor.moveToFirst()) event = cursor.getString(0);
        cursor.close();
        db.close();
        return event;
    }



    public void addIP(String ip) {
        SQLiteDatabase db = this.getWritableDatabase();
        //map user values with table’s column using ContentValues object
        ContentValues values = new ContentValues();
        values.put(KEY_IP, ip);
        db.insert(TABLE_IP, null, values);
        db.close();
    }

    public String getIP() {
        String ip = "";
        String selectQuery = "SELECT * FROM " + TABLE_IP;
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        if (cursor.moveToFirst()) ip = cursor.getString(1);
        cursor.close();
        db.close();
        return ip;
    }

    public void deleteIP() {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_IP, null, null);<commit_msg>DBHandle changed addEvent and getEvent methods...<commit_after>package com.example.student.fitabs;

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;
import java.util.List;

/**
 * Created by <NAME> on 17.11.7.
 */

public class DBHandler extends SQLiteOpenHelper {

    // Database Version
    public static final int DATABASE_VERSION = 1;
    // Database Name
    public static final String DATABASE_NAME = "userInfo";
    // Contacts table name
    public static final String TABLE_USER = "User";
    public static final String TABLE_CONTACTS = "Contacts";
    public static final String TABLE_CHAT_MESSAGE = "ChatMessage";
    public static final String TABLE_EXERCISES = "Exercises";
    public static final String TABLE_IP = "IP";
    public static final String TABLE_EVENTS = "Events";

    // USer Table Columns names
    public static final String KEY_ID = "ID";
    public static final String KEY_USERNAME = "Username";
    public static final String KEY_TEL_NUMBER = "TelephoneNumber";
    public static final String KEY_IS_TRENER = "IsTrener";

    // IP Table Columns names
    public static final String KEY_IP_ID = "ID";
    public static final String KEY_IP = "IP";

    // Contacts Table Columns names
    public static final String KEY_C_ID = "ID";
    public static final String KEY_C_USERNAME = "Username";
    public static final String KEY_C_TEL_NUMBER = "TelephoneNumber";
    public static final String KEY_C_IS_TRENER = "IsTrener";

    // ChatMessage Table Columns names
    public static final String KEY_CM_ID = "ID";
    public static final String KEY_CM_CONTACT_NUMBER = "ConcactTelephoneNumber";
    public static final String KEY_CM_MSG = "Message";

    // Exercises Table Columns names
    public static final String KEY_EX_ID = "ID";
    public static final String KEY_EX_TYPE = "ExerciseType";
    public static final String KEY_EX_NAME = "ExerciseName";
    public static final String KEY_EX_DESCRIPTION = "ExerciseDescription";
    public static final String KEY_EX_IMAGE= "Image";

    //Events Table names
    public static final String KEY_E_ID = "ID";
    public static final String KEY_E_DATE = "Date";
    public static final String KEY_E_EVENT = "Event";

    public DBHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_USERS_TABLE = "CREATE TABLE " + TABLE_USER + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_USERNAME + " TEXT, "
                + KEY_TEL_NUMBER + " TEXT, " + KEY_IS_TRENER + " TEXT" + ")";
        db.execSQL(CREATE_USERS_TABLE);

        String CREATE_IP_TABLE = "CREATE TABLE " + TABLE_IP + "("
                + KEY_IP_ID + " INTEGER PRIMARY KEY," + KEY_IP + " TEXT)";
        db.execSQL(CREATE_IP_TABLE);

        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
                + KEY_C_ID + " INTEGER PRIMARY KEY," + KEY_C_USERNAME + " TEXT, "
                + KEY_C_TEL_NUMBER + " TEXT, " + KEY_C_IS_TRENER + " TEXT" + ")";
        db.execSQL(CREATE_CONTACTS_TABLE);

        String CREATE_CHAT_MESSAGE_TABLE = "CREATE TABLE " + TABLE_CHAT_MESSAGE + "("
                + KEY_CM_ID + " INTEGER PRIMARY KEY," + KEY_CM_CONTACT_NUMBER + " TEXT, "
                + KEY_CM_MSG + " TEXT" + ")";
        db.execSQL(CREATE_CHAT_MESSAGE_TABLE);

        String CREATE_EXERCISE_TABLE = "CREATE TABLE " + TABLE_EXERCISES + "("
                + KEY_EX_ID + " INTEGER PRIMARY KEY," + KEY_EX_TYPE + " TEXT, "
                + KEY_EX_NAME + " TEXT, " + KEY_EX_DESCRIPTION + " TEXT, " + KEY_EX_IMAGE + " TEXT" + ")";
        db.execSQL(CREATE_EXERCISE_TABLE);

        String CREATE_EVENTS_TABLE = "CREATE TABLE " + TABLE_EVENTS + "("
                + KEY_E_ID + " INTEGER PRIMARY KEY," + KEY_E_DATE + " TEXT, "
                + KEY_E_EVENT + " TEXT " + ")";
        db.execSQL(CREATE_EVENTS_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHAT_MESSAGE);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_EXERCISES);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_IP);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENTS);
        // Creating tables again
        onCreate(db);
    }

    //  INSERT : Adding new user
    public void addUser(User user) {
        SQLiteDatabase db = this.getWritableDatabase();
        //map user values with table’s column using ContentValues object
        ContentValues values = new ContentValues();
        values.put(KEY_USERNAME, user.getName());
        values.put(KEY_TEL_NUMBER, user.getTelnumber());
        values.put(KEY_IS_TRENER, user.getStatus());
        // Inserting Row
        db.insert(TABLE_USER, null, values);
        db.close(); // Closing database connection
    }
    public void addEvent(String event, Day day) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(KEY_E_EVENT, event);
        values.put(KEY_E_DATE, day.getDay() + "/" + day.getMonth() + "/" + day.getYear());
        db.insert(TABLE_EVENTS, null, values);
        db.close();
    }

    public String getEvent(Day day) {
        String event = "";
        String date = day.getDay() + "/" + day.getMonth() + "/" + day.getYear();
        String selectQuery = "SELECT " + KEY_E_EVENT +  " FROM " + TABLE_EVENTS + " WHERE " + KEY_E_EVENT + "= '" + date + "'";
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        if (cursor.moveToFirst()) event = cursor.getString(0);
        cursor.close();
        db.close();
        return event;
    }

    public void addIP(String ip) {
        SQLiteDatabase db = this.getWritableDatabase();
        //map user values with table’s column using ContentValues object
        ContentValues values = new ContentValues();
        values.put(KEY_IP, ip);
        db.insert(TABLE_IP, null, values);
        db.close();
    }

    public String getIP() {
        String ip = "";
        String selectQuery = "SELECT * FROM " + TABLE_IP;
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        if (cursor.moveToFirst()) ip = cursor.getString(1);
        cursor.close();
        db.close();
        return ip;
    }

    public void deleteIP() {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_IP, null, null);
{'fraction_non_alphanumeric': 0.10275596384649578, 'fraction_numerical': 0.001185360794191732, 'mean_word_length': 2.775944055944056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7389475', 'n_tokens_mistral': 4153, 'n_tokens_neox': 3965, 'n_words': 1063}