Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.dariabut.myapplication_3.database;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.content.Context;
- import android.content.ContentValues;
- import android.database.Cursor;
- import android.util.Log;
- import com.example.dariabut.myapplication_3.model.Attendance;
- import com.example.dariabut.myapplication_3.model.Course;
- import com.example.dariabut.myapplication_3.model.Group;
- import com.example.dariabut.myapplication_3.model.Hometask;
- import com.example.dariabut.myapplication_3.model.Lesson;
- import com.example.dariabut.myapplication_3.model.Mark;
- import com.example.dariabut.myapplication_3.model.Student;
- import com.example.dariabut.myapplication_3.model.Teacher;
- import com.example.dariabut.myapplication_3.model.User;
- import java.util.ArrayList;
- import java.util.List;
- public class DatabaseHandler extends SQLiteOpenHelper {
- //information of database
- private static final int DATABASE_VERSION = 4;
- private static final String DATABASE_NAME = "studdeediary";
- private static DatabaseHandler sInstance;//возмодно добавить .db
- // Table names
- private static final String
- TABLE_USER = "User",
- TABLE_TEACHER = "Teacher",
- TABLE_TEACHER_COURSE = "TeacherCourse",
- TABLE_STUDENT = "Student",
- TABLE_COURSE = "Course",
- TABLE_STUDY_PLAN = "StudyPlan",
- TABLE_LESSON = "Lesson",
- TABLE_GROUP = "Groupp",
- TABLE_MARK = "Mark",
- TABLE_ATTENDANCE = "Attendance",
- TABLE_HOMETASK = "Hometask";
- // Common column names
- private static final String
- KEY_USER_ID = "userID",
- KEY_TEACHER_ID = "teacherID",
- KEY_STUDENT_ID = "studentID",
- KEY_GROUP_ID = "groupID",
- KEY_COURSE_NAME_ID = "courseNameID",
- KEY_ATTENDANCE_ID = "attendanceID",
- KEY_HOMETASK_ID = "hometaskID",
- KEY_MARK_ID = "markID",
- KEY_LESSON_ID = "lessonID";
- // TABLE_USER - column names
- private static final String
- KEY_FULL_NAME = "fullName",
- KEY_EMAIL = "email",
- KEY_PASSWORD = "password",
- KEY_TYPE = "type";
- // TABLE_TEACHER - column names
- private static final String
- KEY_ROLE = "role";
- // TABLE_COURSE - column names
- private static final String
- KEY_AMOUNT = "amount",
- KEY_CLASS_NUMBER = "classNumber";
- // TABLE_STUDENT - column names
- private static final String
- KEY_ADRESS = "adress";
- //TABLE_GROUP - column names
- private static final String
- KEY_GROUP_NUMBER_ID = "groupNumberID",
- KEY_GROUP_LABEL = "groupLabel";
- //TABLE_LESSON
- private static final String
- KEY_TOPIC = "lessonTopic",
- KEY_ROOM = "room",
- KEY_LESSON_DATE = "lessonDate",
- KEY_LESSON_TIME = "lessonTime",
- KEY_LESSON_TYPE = "lessonType";
- //TABLE_HOMETASK
- private static final String
- KEY_DEADLINE = "deadline",
- KEY_HOMETASK_STATUS = "hometaskStatus";
- //TABLE_ATTENDANCE
- private static final String
- KEY_ATTENDANCE_STATUS = "attendanceStatus",
- KEY_REASON = "reason";
- //TABLE_MARK
- private static final String
- KEY_MARK_VALUE = "markValue",
- KEY_COMMENT = "comment";
- public static synchronized DatabaseHandler getInstance(Context context) {
- if (sInstance == null) {
- sInstance = new DatabaseHandler(context.getApplicationContext());
- }
- return sInstance;
- }
- public DatabaseHandler(Context context) {
- super(context, DATABASE_NAME, null, DATABASE_VERSION);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- final String createTableUser = "CREATE TABLE " + TABLE_USER + "(" +
- KEY_USER_ID + " INTEGER PRIMARY KEY, " +
- KEY_EMAIL + " TEXT, " +
- KEY_PASSWORD + " TEXT, " +
- KEY_FULL_NAME + " TEXT, " +
- KEY_TYPE + " TEXT " + ")";
- final String createTableTeacher = "CREATE TABLE " + TABLE_TEACHER + "(" +
- KEY_TEACHER_ID + " INTEGER PRIMARY KEY, " +
- // KEY_EMAIL + " TEXT, " +
- KEY_USER_ID + " INTEGER, " +
- KEY_ROLE + " TEXT, " +
- " FOREIGN KEY (" + KEY_USER_ID + ") REFERENCES " +
- TABLE_USER + "(" + KEY_USER_ID + ") ON DELETE CASCADE )";
- final String createTableCourse = "CREATE TABLE " + TABLE_COURSE + "(" +
- KEY_COURSE_NAME_ID + " TEXT PRIMARY KEY, " +
- // KEY_EMAIL + " TEXT, " +
- KEY_AMOUNT + " INTEGER, " +
- KEY_CLASS_NUMBER + " TEXT " + ")";
- final String createTableTeacherCourse = "CREATE TABLE " + TABLE_TEACHER_COURSE + "(" +
- KEY_TEACHER_ID + " INTEGER, " +
- KEY_COURSE_NAME_ID + " TEXT, " +
- KEY_CLASS_NUMBER + " INTEGER, " +
- " FOREIGN KEY (" + KEY_TEACHER_ID + ") REFERENCES " +
- TABLE_TEACHER + "(" + KEY_TEACHER_ID + ")," +
- " FOREIGN KEY (" + KEY_COURSE_NAME_ID + ") REFERENCES " +
- TABLE_COURSE + "(" + KEY_COURSE_NAME_ID + "))";
- final String createTableStudent = "CREATE TABLE " + TABLE_STUDENT + "(" +
- KEY_STUDENT_ID + " INTEGER PRIMARY KEY, " +
- KEY_USER_ID + " INTEGER, " +
- KEY_ADRESS + " TEXT, " +
- KEY_GROUP_ID + " INTEGER, " +
- " FOREIGN KEY (" + KEY_USER_ID + ") REFERENCES " +
- TABLE_USER + "(" + KEY_USER_ID + ") ON DELETE CASCADE," +
- " FOREIGN KEY (" + KEY_GROUP_ID + ") REFERENCES " +
- TABLE_GROUP + "(" + KEY_GROUP_ID +"))";
- final String createTableGroup = "CREATE TABLE " + TABLE_GROUP + "(" +
- KEY_GROUP_ID + " INTEGER PRIMARY KEY, " +
- KEY_GROUP_NUMBER_ID + " INTEGER, " +
- KEY_GROUP_LABEL + " TEXT" + ")";
- final String createTableStudyPlan ="CREATE TABLE " + TABLE_STUDY_PLAN + "(" +
- KEY_GROUP_ID + " INTEGER, " +
- KEY_COURSE_NAME_ID + " TEXT, " +
- " FOREIGN KEY (" + KEY_GROUP_ID + ") REFERENCES " +
- TABLE_GROUP + "(" + KEY_GROUP_ID + ")," +
- " FOREIGN KEY (" + KEY_COURSE_NAME_ID + ") REFERENCES " +
- TABLE_COURSE + "(" + KEY_COURSE_NAME_ID + "))";
- final String createTableLesson = "CREATE TABLE " + TABLE_LESSON +"(" +
- KEY_LESSON_ID + " INTEGER PRIMARY KEY, " +
- KEY_TOPIC + " TEXT, " +
- KEY_LESSON_DATE + " TEXT, " +
- KEY_LESSON_TIME + " TEXT, " +
- KEY_LESSON_TYPE + " TEXT, " +
- KEY_ROOM + " TEXT, " +
- KEY_COURSE_NAME_ID + " TEXT, " +
- KEY_GROUP_ID + " INTEGER, " +
- " FOREIGN KEY (" + KEY_GROUP_ID + ") REFERENCES " +
- TABLE_GROUP + "(" + KEY_GROUP_ID + "), " +
- " FOREIGN KEY (" + KEY_COURSE_NAME_ID + ") REFERENCES " +
- TABLE_COURSE + "(" + KEY_COURSE_NAME_ID + ") ON DELETE CASCADE)";
- final String createTableMark = "CREATE TABLE " + TABLE_MARK + "(" +
- KEY_MARK_ID + " INTEGER PRIMARY KEY, " +
- KEY_STUDENT_ID + " INTEGER, " +
- KEY_LESSON_ID + " INTEGER, " +
- KEY_MARK_VALUE + " TEXT, " +
- KEY_COMMENT + " TEXT, " +
- " FOREIGN KEY (" + KEY_STUDENT_ID + ") REFERENCES " +
- TABLE_STUDENT + "(" + KEY_STUDENT_ID + ") ON DELETE CASCADE," +
- " FOREIGN KEY (" + KEY_LESSON_ID + ") REFERENCES " +
- TABLE_LESSON + "(" + KEY_LESSON_ID + ") ON DELETE CASCADE" + ")";
- final String createTableHometask = "CREATE TABLE " + TABLE_HOMETASK + "(" +
- KEY_HOMETASK_ID + " INTEGER PRIMARY KEY, " +
- KEY_DEADLINE + " TEXT, " +
- KEY_HOMETASK_STATUS + " TEXT, " +
- KEY_STUDENT_ID + " INTEGER, " +
- KEY_LESSON_ID + " INTEGER, " +
- " FOREIGN KEY (" + KEY_STUDENT_ID + ") REFERENCES " +
- TABLE_STUDENT + "(" + KEY_STUDENT_ID + ") ON DELETE CASCADE," +
- " FOREIGN KEY (" + KEY_LESSON_ID + ") REFERENCES " +
- TABLE_LESSON + "(" + KEY_LESSON_ID + ") ON DELETE CASCADE" + ")";
- final String createTableAttendance = "CREATE TABLE " + TABLE_ATTENDANCE + "(" +
- KEY_ATTENDANCE_ID + " INTEGER PRIMARY KEY, " +
- KEY_ATTENDANCE_STATUS + " TEXT, " +
- KEY_REASON + " TEXT, " +
- KEY_STUDENT_ID + " INTEGER, " +
- KEY_LESSON_ID + " INTEGER, " +
- " FOREIGN KEY (" + KEY_STUDENT_ID + ") REFERENCES " +
- TABLE_STUDENT + "(" + KEY_STUDENT_ID + ") ON DELETE CASCADE," +
- " FOREIGN KEY (" + KEY_LESSON_ID + ") REFERENCES " +
- TABLE_LESSON + "(" + KEY_LESSON_ID + ") ON DELETE CASCADE" + ")";
- db.execSQL(createTableUser);
- db.execSQL(createTableStudent);
- db.execSQL(createTableTeacher);
- db.execSQL(createTableTeacherCourse);
- db.execSQL(createTableCourse);
- db.execSQL(createTableStudyPlan);
- db.execSQL(createTableGroup);
- db.execSQL(createTableLesson);
- db.execSQL(createTableMark);
- db.execSQL(createTableHometask);
- db.execSQL(createTableAttendance);
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_STUDENT);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_TEACHER);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_TEACHER_COURSE);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_COURSE);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_STUDY_PLAN);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_GROUP);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_LESSON);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_ATTENDANCE);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_HOMETASK);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_MARK);
- onCreate(db);
- }
- // User
- //======================================================================================================================================
- public User getUser(int id) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_USER, new String[]{
- KEY_USER_ID, KEY_EMAIL, KEY_PASSWORD, KEY_FULL_NAME, KEY_TYPE}, KEY_USER_ID + "=?",
- new String[]{String.valueOf(id)}, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- //Integer userID, String email, String password, String fullName, String type
- User user = new User(
- cursor.getInt(0), //KEY_USER_ID
- cursor.getString(1), // KEY_EMAIL
- cursor.getString(2), // KET_PASSWORD
- cursor.getString(3), // KEY_FUL_NAME
- cursor.getString(4)); // KEY_TYPE
- cursor.close();
- db.close();
- return user;
- }
- db.close();
- return null;
- }
- public List<User> getAllUsers(){
- List<User> users = new ArrayList<>();
- String selectQuery = "SELECT " +
- KEY_USER_ID + ", " +
- KEY_FULL_NAME +
- " FROM " + TABLE_USER;
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- do {
- User user = new User();
- user.setUserID(cursor.getInt(0));
- user.setFullName(cursor.getString(1));
- // user.setEmail(cursor.getString(2));
- users.add(user);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return users;
- }
- public Integer addUser(User user, SQLiteDatabase db) {
- ContentValues userValues = new ContentValues();
- userValues.put(KEY_FULL_NAME, user.getFullName());
- userValues.put(KEY_PASSWORD, user.getPassword());
- userValues.put(KEY_EMAIL, user.getEmail());
- userValues.put(KEY_TYPE, user.getType());
- Integer userID = (int) db.insert(TABLE_USER, null, userValues);
- Log.d("DB Add new user", user.toString());
- Log.d("UserID=", String.valueOf(userID));
- return userID;
- }
- //======================================================================================================================================
- // Teacher
- //======================================================================================================================================
- public Integer addTeacher(User user, Teacher teacher) {
- SQLiteDatabase db = this.getWritableDatabase();
- Integer userID = addUser(user, db);
- ContentValues teacherValues = new ContentValues();
- teacherValues.put(KEY_USER_ID, userID);
- teacherValues.put(KEY_ROLE, teacher.getRole());
- Integer teacherId = (int) db.insert(TABLE_TEACHER, null, teacherValues);
- db.close();
- Log.d("Add new teacher", teacher.toString());
- Log.d("teacherID", String.valueOf(teacherId));
- return teacherId;
- }
- public Teacher getTeacher(int id) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_TEACHER, new String[]{
- KEY_TEACHER_ID, KEY_USER_ID, KEY_ROLE}, KEY_TEACHER_ID + "=?",
- new String[]{String.valueOf(id)}, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- //(Integer teacherID, Integer userID, String role)
- Teacher teacher = new Teacher(
- cursor.getInt(0), // KEY_TEACHER_ID
- cursor.getInt(1), // KEY_USER_ID
- cursor.getString(2)); // KET_ROLE
- cursor.close();
- db.close();
- return teacher;
- }
- db.close();
- return null;
- }
- //======================================================================================================================================
- // Teacher_Course
- //======================================================================================================================================
- public void addCourseForTeacher(Integer teacherID, String courseName) {
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put(KEY_TEACHER_ID, teacherID);
- values.put(KEY_COURSE_NAME_ID, courseName);
- db.insertWithOnConflict(TABLE_TEACHER_COURSE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
- db.close();
- Log.d("Add course for teacher", courseName + " " + teacherID);
- }
- public List<Course> getCoursesForTeacher(Teacher teacher) {
- List<Course> coursesList = new ArrayList<>();
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_TEACHER_COURSE, new String[]{
- KEY_TEACHER_ID, KEY_COURSE_NAME_ID}, KEY_TEACHER_ID + "=?",
- new String[]{String.valueOf(teacher.getTeacherID())}, null, null, null, null);
- if (cursor.moveToFirst()) {
- do {
- Course course = getCourse(cursor.getString(1));
- coursesList.add(course);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return coursesList;
- }
- //======================================================================================================================================
- // Course
- //======================================================================================================================================
- public Course getCourse(String nameID) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_COURSE, new String[]{
- KEY_COURSE_NAME_ID, KEY_AMOUNT, KEY_CLASS_NUMBER}, KEY_COURSE_NAME_ID + "=?",
- new String[]{nameID}, null, null, null, null);
- Course course = null;
- if (cursor != null && cursor.moveToFirst()) {
- course = new Course(
- cursor.getString(0),
- cursor.getInt(1),
- cursor.getInt(2));
- cursor.close();
- }
- db.close();
- return course;
- }
- public void addCourse(Course course){
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put(KEY_COURSE_NAME_ID, course.getCourseNameID());
- values.put(KEY_AMOUNT, course.getAmountOfLessons());
- values.put(KEY_CLASS_NUMBER, course.getGroupNumber());
- db.insertWithOnConflict(TABLE_COURSE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
- db.close();
- Log.d("Add new course", course.toString());
- }
- //======================================================================================================================================
- // StudyPlan - Course_Group
- //======================================================================================================================================
- public void addCourseForGroup(Integer groupID, String courseName) {
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put(KEY_GROUP_ID, groupID);
- values.put(KEY_COURSE_NAME_ID, courseName);
- db.insertWithOnConflict(TABLE_STUDY_PLAN, null, values, SQLiteDatabase.CONFLICT_IGNORE);
- db.close();
- Log.d("Add course for teacher", courseName + " " + groupID);
- }
- //======================================================================================================================================
- // Group
- //======================================================================================================================================
- public List<Group> getGroupsForTeacher(Integer teacherID){
- List<Group> groups = new ArrayList<>();
- String selectQuery = "SELECT " +
- TABLE_GROUP + "." + KEY_GROUP_NUMBER_ID +
- TABLE_GROUP + "." + KEY_GROUP_LABEL +
- " FROM " + TABLE_GROUP +
- " INNER JOIN " + TABLE_STUDY_PLAN +
- " ON " + TABLE_GROUP + "." + KEY_GROUP_ID + "=" +
- TABLE_STUDY_PLAN + "." + KEY_GROUP_ID +
- " INNER JOIN " + TABLE_COURSE +
- " ON " + TABLE_COURSE + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_STUDY_PLAN + "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER_COURSE +
- " ON " + TABLE_TEACHER_COURSE + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_STUDY_PLAN + "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER +
- " ON " + TABLE_TEACHER_COURSE + "." + KEY_TEACHER_ID + "=" +
- TABLE_TEACHER + "." + KEY_TEACHER_ID +
- " WHERE (" + TABLE_TEACHER + "." + KEY_TEACHER_ID + " LIKE \'" + teacherID + "%\'" + ")";
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- do {
- Group group = new Group();
- // group.setGroupID(cursor.getInt(0));
- group.setGroupNumberID(cursor.getInt(0));
- group.setGroupLabel(cursor.getString(1));
- groups.add(group);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return groups;
- }
- public Integer getGroupID (Integer groupNum, String groupLab){
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT " + TABLE_GROUP +"." + KEY_GROUP_ID +
- " FROM " + TABLE_GROUP +
- " WHERE (" +
- TABLE_GROUP + "." + KEY_GROUP_NUMBER_ID + "=?" + " AND " +
- TABLE_GROUP + "." + KEY_GROUP_LABEL + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{Integer.toString(groupNum), groupLab});
- Integer groupID = cursor.getInt(0);
- cursor.close();
- db.close();
- return groupID;
- }
- public Group getGroup(Integer groupID){
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT * FROM " + TABLE_GROUP +
- " WHERE( " + KEY_GROUP_ID + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{String.valueOf(groupID)});
- if (cursor != null) {
- cursor.moveToFirst();
- Group group = new Group(
- cursor.getInt(0), // KEY_GROUP_ID
- cursor.getInt(1), // KEY_GROUP_NAME_ID
- cursor.getString(2)); // KEY_GROUP_LABEL
- cursor.close();
- db.close();
- return group;
- }
- db.close();
- return null;
- }
- public Integer addGroup(Group group, SQLiteDatabase db) {
- ContentValues groupValues = new ContentValues();
- // groupValues.put(KEY_GROUP_ID, group.getGroupID());
- groupValues.put(KEY_GROUP_LABEL, group.getGroupLabel());
- groupValues.put(KEY_GROUP_NUMBER_ID, group.getGroupNumberID());
- Integer groupId = (int) db.insert(TABLE_GROUP, null, groupValues);
- db.close();
- Log.d("Add new group", group.toString());
- return groupId;
- }
- public Integer addGroup(Group group){
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues groupValues = new ContentValues();
- // groupValues.put(KEY_GROUP_ID, group.getGroupID());
- groupValues.put(KEY_GROUP_LABEL, group.getGroupLabel());
- groupValues.put(KEY_GROUP_NUMBER_ID, group.getGroupNumberID());
- Integer groupId = (int) db.insert(TABLE_GROUP, null, groupValues);
- db.close();
- Log.d("Add new group", group.toString());
- return groupId;
- }
- //======================================================================================================================================
- // Lesson
- //======================================================================================================================================
- public Integer addLessonForCourse(Lesson lesson){
- SQLiteDatabase db = this.getReadableDatabase();
- String courseName = lesson.getCourseID();
- Integer groupID = lesson.getGroupID();
- ContentValues values = new ContentValues();
- values.put(KEY_LESSON_DATE, lesson.getLessonDate());
- values.put(KEY_LESSON_TIME, lesson.getLessonTime());
- values.put(KEY_LESSON_TYPE, lesson.getLessonType());
- values.put(KEY_ROOM, lesson.getRoom());
- values.put(KEY_TOPIC, lesson.getTopic());
- values.put(KEY_COURSE_NAME_ID, courseName);
- values.put(KEY_GROUP_ID, groupID);
- Integer lessonID = (int) db.insert(TABLE_LESSON, null, values);
- db.close();
- Log.d("Add new lesson", lesson.toString());
- return lessonID;
- }
- public Lesson getLesson(int id) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_LESSON, new String[] {
- KEY_LESSON_ID, KEY_COURSE_NAME_ID, KEY_LESSON_DATE, KEY_LESSON_TIME, KEY_TOPIC, KEY_ROOM, KEY_LESSON_TYPE}, KEY_ATTENDANCE_ID + "=?",
- new String[] { String.valueOf(id) }, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- //Integer lessonID, String courseID, String lessonDate, String lessonTime, String topic, String room, String lessonType
- Lesson lesson = new Lesson(
- cursor.getInt(0),
- cursor.getString(1),
- cursor.getInt(2),
- cursor.getString(3),
- cursor.getString(4),
- cursor.getString(5),
- cursor.getString(6),
- cursor.getString(7));
- cursor.close();
- db.close();
- return lesson;
- }
- db.close();
- return null;
- }
- public void deleteLessonById(Integer lessonID){
- SQLiteDatabase db = this.getWritableDatabase();
- String courseID = getLesson(lessonID).getCourseID();
- Integer groupID = getLesson(lessonID).getGroupID();
- this.getWritableDatabase()
- .delete(TABLE_COURSE, KEY_COURSE_NAME_ID + " =?", new String[] {courseID});
- this.getWritableDatabase()
- .delete(TABLE_LESSON, KEY_LESSON_ID + " =?", new String[]{Integer.toString(lessonID)});
- this.getWritableDatabase()
- .delete(TABLE_GROUP, KEY_LESSON_ID + " =?", new String[]{Integer.toString(groupID)});
- db.close();
- }
- public void addLessonForCourseGroup(String courseName, Lesson lesson, Integer groupID) {
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- //values.put(KEY_TEACHER_ID, teacherID);
- values.put(KEY_COURSE_NAME_ID, courseName);
- values.put(KEY_LESSON_TYPE, lesson.getLessonType());
- values.put(KEY_LESSON_TIME, lesson.getLessonTime());
- values.put(KEY_LESSON_DATE, lesson.getLessonDate());
- values.put(KEY_ROOM, lesson.getRoom());
- values.put(KEY_TOPIC, lesson.getTopic());
- values.put(KEY_GROUP_ID, groupID);
- Integer lessonID = (int) db.insertWithOnConflict(TABLE_LESSON, null, values, SQLiteDatabase.CONFLICT_IGNORE);
- db.close();
- Log.d("Add lesson for course", courseName + " " + lessonID);
- }
- public Lesson getLessonForTeacherOnCourse(Integer teacherID, Integer lessonID, String courseNameID) {
- // List<Lesson> lessons = new ArrayList<>();
- SQLiteDatabase db = this.getWritableDatabase();
- String selectQuery = "SELECT " +
- TABLE_LESSON + "." + KEY_TOPIC +
- " FROM " + TABLE_LESSON +
- " INNER JOIN " + TABLE_COURSE +
- " ON " + TABLE_LESSON + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_COURSE+ "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER_COURSE +
- " ON " + TABLE_TEACHER_COURSE + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_COURSE + "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER +
- " ON " + TABLE_TEACHER + "." + KEY_TEACHER_ID + "=" +
- TABLE_TEACHER + "." + KEY_TEACHER_ID +
- " WHERE (" +
- KEY_COURSE_NAME_ID + " LIKE \'" + courseNameID + "%\'" +
- KEY_LESSON_ID + " LIKE \'" + lessonID + "%\'" +
- KEY_TEACHER_ID + " LIKE \'" + teacherID + "%\')";
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor != null) {
- cursor.moveToFirst();
- Lesson lesson = new Lesson();
- lesson.setTopic(cursor.getString(0));
- cursor.close();
- db.close();
- return lesson;
- }
- db.close();
- return null;
- }
- public List<Lesson> getLessonsForTeacher(Integer teacherID) {
- List<Lesson> lessons = new ArrayList<>();
- SQLiteDatabase db = this.getWritableDatabase();
- String selectQuery = "SELECT " +
- TABLE_LESSON + "." + KEY_TOPIC +
- " FROM " + TABLE_LESSON +
- " INNER JOIN " + TABLE_COURSE +
- " ON " + TABLE_LESSON + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_COURSE + "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER_COURSE +
- " ON " + TABLE_TEACHER_COURSE + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_COURSE + "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER +
- " ON " + TABLE_TEACHER + "." + KEY_TEACHER_ID + "=" +
- TABLE_TEACHER + "." + KEY_TEACHER_ID +
- " WHERE (" +
- TABLE_TEACHER + "." + KEY_TEACHER_ID + " LIKE \'" + teacherID + "%\')";
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor != null) {
- do {
- Lesson lesson = new Lesson(
- cursor.getInt(0),
- cursor.getString(1),
- cursor.getInt(2),
- cursor.getString(3),
- cursor.getString(4),
- cursor.getString(5),
- cursor.getString(6),
- cursor.getString(7));
- lessons.add(lesson);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return lessons;
- }
- public Integer getLessonID (String lessonTopic){
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT " + TABLE_LESSON +"." + KEY_LESSON_ID +
- " FROM " + TABLE_LESSON +
- " WHERE (" +
- TABLE_LESSON +"." + KEY_LESSON_ID+ "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{lessonTopic});
- Integer currentUserID = cursor.getInt(1);
- cursor.close();
- db.close();
- return currentUserID;
- }
- //======================================================================================================================================
- // Mark
- //======================================================================================================================================
- public List<Mark> getMarksForStudentOnSubject(Integer studentID, String courseName){
- List<Mark> marks = new ArrayList<>();
- String selectQuery = "SELECT " +
- TABLE_LESSON + "." + KEY_TOPIC + ", " +
- TABLE_MARK + "." + KEY_MARK_VALUE +
- " FROM "+ TABLE_MARK +
- " INNER JOIN " + TABLE_LESSON + " ON " +
- TABLE_LESSON + "." + KEY_LESSON_ID + "=" +
- TABLE_MARK + "." + KEY_LESSON_ID +
- " WHERE (" + KEY_STUDENT_ID + " LIKE \'" + studentID + "%\'"+ " AND " +
- TABLE_LESSON + "." + KEY_COURSE_NAME_ID + " LIKE \'" + courseName + "%\'" + ")";
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- do {
- Mark mark = new Mark();
- mark.setMarkID(cursor.getInt(0));
- mark.setMarkValue(cursor.getString(1));
- mark.setLessonID(cursor.getInt(2));
- // user.setEmail(cursor.getString(2));
- marks.add(mark);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return marks;
- }
- public List<Mark> getAllMarks(Integer studentID){
- List<Mark> marks = new ArrayList<>();
- String selectQuery = "SELECT " +
- TABLE_LESSON + "." + KEY_TOPIC + ", " +
- TABLE_MARK + "." + KEY_MARK_VALUE +
- " FROM "+ TABLE_MARK +
- " INNER JOIN " + TABLE_LESSON + " ON " +
- TABLE_LESSON + "." + KEY_LESSON_ID + "=" +
- TABLE_MARK + "." + KEY_LESSON_ID +
- " WHERE (" + KEY_STUDENT_ID + " LIKE \'" + studentID + "%\')";
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- do {
- Mark mark = new Mark();
- mark.setMarkID(cursor.getInt(0));
- mark.setMarkValue(cursor.getString(1));
- mark.setLessonID(cursor.getInt(2));
- // user.setEmail(cursor.getString(2));
- marks.add(mark);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return marks;
- }
- public void addMark(Mark mark) {
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put(KEY_MARK_VALUE, mark.getMarkValue());
- values.put(KEY_MARK_ID, mark.getMarkID());
- values.put(KEY_STUDENT_ID, mark.getStudentID());
- values.put(KEY_LESSON_ID, mark.getLessonID());
- values.put(KEY_COMMENT, mark.getComment());
- db.insertWithOnConflict(TABLE_MARK, null, values, SQLiteDatabase.CONFLICT_IGNORE);
- db.close();
- Log.d("Add side mark", mark.toString());
- }
- public Mark getMark(int id) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_MARK, new String[] {
- KEY_MARK_ID, KEY_LESSON_ID, KEY_STUDENT_ID, KEY_MARK_VALUE, KEY_COMMENT}, KEY_MARK_ID + "=?",
- new String[] { String.valueOf(id) }, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- }
- //(Integer markID, Integer lessonID, Integer studentID, String markValue, String comment)
- Mark mark = new Mark(
- cursor.getInt(0), // KEY_MARK_ID
- cursor.getInt(1), // KEY_LESSON_ID
- cursor.getInt(2), // KEY_STUDENT_ID
- cursor.getString(3), // KEY_MARK_VALUE
- cursor.getString(4)); // KEY_COMMENT
- cursor.close();
- db.close();
- return mark;
- }
- public void deleteMarkById(Integer markID){
- SQLiteDatabase db = this.getWritableDatabase();
- // int studentID = getMark(markID).getStudentID();
- //int lessonID = getMark(markID).getLessonID();
- this.getWritableDatabase()
- .delete(TABLE_MARK, KEY_MARK_ID + " =?", new String[]{Integer.toString(markID)});
- /*this.getWritableDatabase()
- .delete(TABLE_STUDENT, KEY_STUDENT_ID + " =?", new String[] {Integer.toString(studentID)});
- this.getWritableDatabase()
- .delete(TABLE_LESSON, KEY_LESSON_ID + " =?", new String[]{Integer.toString(lessonID)});*/
- db.close();
- }
- //======================================================================================================================================
- // Hometask
- //======================================================================================================================================
- public Hometask getHometask(int id) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_HOMETASK, new String[] {
- KEY_HOMETASK_ID, KEY_LESSON_ID, KEY_STUDENT_ID, KEY_HOMETASK_STATUS, KEY_DEADLINE}, KEY_HOMETASK_ID + "=?",
- new String[] { String.valueOf(id) }, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- //((Integer hometaskID, Integer lessonID, Integer studentID, String status, String deadline)
- Hometask hometask = new Hometask(
- cursor.getInt(0), // KEY_HOMETASK_ID
- cursor.getInt(1), // KEY_LESSON_ID
- cursor.getInt(2), // KEY_STUDENT_ID
- cursor.getString(3), // KEY_HOMETASK_STATUS
- cursor.getString(4)); // KEY_DEADLINE
- cursor.close();
- db.close();
- return hometask;
- }
- db.close();
- return null;
- }
- //отсортированное ДЗ
- public List<Hometask> getAllHometasks(Integer studentID){
- List<Hometask> hometasks = new ArrayList<>();
- String selectQuery = "SELECT " +
- TABLE_LESSON + "." + KEY_TOPIC + ", " +
- TABLE_HOMETASK + "." + KEY_HOMETASK_STATUS +
- TABLE_HOMETASK + "." + KEY_DEADLINE +
- " FROM "+ TABLE_HOMETASK +
- " INNER JOIN " + TABLE_LESSON + " ON " +
- TABLE_LESSON + "." + KEY_LESSON_ID + "=" +
- TABLE_MARK + "." + KEY_LESSON_ID +
- " WHERE " + KEY_STUDENT_ID + " LIKE \'" + studentID + "%\'" +
- " ORDER BY " + KEY_HOMETASK_STATUS + " DESC, " + KEY_DEADLINE + " DESC" ;
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- do {
- Hometask hometask = new Hometask();
- hometask.setStatus(cursor.getString(0));
- hometask.setDeadline(cursor.getString(1));
- // user.setEmail(cursor.getString(2));
- hometasks.add(hometask);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return hometasks;
- }
- public void deleteHometaskById(Integer hometaskID){
- SQLiteDatabase db = this.getWritableDatabase();
- // int studentID = getHometask(hometaskID).getStudentID();
- // int lessonID = getHometask(hometaskID).getLessonID();
- this.getWritableDatabase().delete(TABLE_HOMETASK, KEY_HOMETASK_ID +
- " =?", new String[]{Integer.toString(hometaskID)});
- /* this.getWritableDatabase()
- .delete(TABLE_STUDENT, KEY_STUDENT_ID + " =?", new String[] {Integer.toString(studentID)});
- this.getWritableDatabase()
- .delete(TABLE_LESSON, KEY_LESSON_ID + " =?", new String[]{Integer.toString(lessonID)});*/
- db.close();
- }
- //======================================================================================================================================
- // Attendance
- //======================================================================================================================================
- public Attendance getAttendance(int id) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_ATTENDANCE, new String[] {
- KEY_ATTENDANCE_ID, KEY_STUDENT_ID, KEY_LESSON_ID, KEY_ATTENDANCE_STATUS, KEY_ATTENDANCE_STATUS, KEY_REASON}, KEY_ATTENDANCE_ID + "=?",
- new String[] { String.valueOf(id) }, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- //(Integer attendanceID, Integer lessonID, Integer studentID, Integer status, String reason)
- Attendance attendance = new Attendance(
- cursor.getInt(0), // KEY_ATTENDANCE_ID
- cursor.getInt(1), // KEY_LESSON_ID
- cursor.getInt(2), // KEY_STUDENT_ID
- cursor.getInt(3), // KEY_ATTENDANCE_STATUS
- cursor.getString(4)); // KEY_REASON
- cursor.close();
- db.close();
- return attendance;
- }
- db.close();
- return null;
- }
- public List<Attendance> getAllAttendance(Integer studentID){
- List<Attendance> attendances = new ArrayList<>();
- String selectQuery = "SELECT " +
- TABLE_LESSON + "." + KEY_TOPIC + ", " +
- TABLE_ATTENDANCE + "." + KEY_ATTENDANCE_STATUS +
- " FROM "+ TABLE_ATTENDANCE +
- " INNER JOIN " + TABLE_LESSON + " ON " +
- TABLE_LESSON + "." + KEY_LESSON_ID + "=" +
- TABLE_ATTENDANCE + "." + KEY_ATTENDANCE_STATUS +
- " WHERE (" + KEY_STUDENT_ID + " LIKE \'" + studentID + "%\')";
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- do {
- Attendance attendance = new Attendance();
- attendance.setAttendanceID(cursor.getInt(0));
- attendance.setStatus(cursor.getInt(1));
- attendance.setLessonID(cursor.getInt(2));
- // user.setEmail(cursor.getString(2));
- attendances.add(attendance);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return attendances;
- }
- public void deleteAttendenceById(Integer attendenceID){
- SQLiteDatabase db = this.getWritableDatabase();
- // int studentID = getAttendance(attendenceID).getStudentID();
- // int lessonID = getAttendance(attendenceID).getLessonID();
- this.getWritableDatabase().delete(TABLE_ATTENDANCE, KEY_ATTENDANCE_ID +
- " =?", new String[]{Integer.toString(attendenceID)});
- /* this.getWritableDatabase()
- .delete(TABLE_STUDENT, KEY_STUDENT_ID + " =?", new String[] {Integer.toString(studentID)});
- this.getWritableDatabase()
- .delete(TABLE_LESSON, KEY_LESSON_ID + " =?", new String[]{Integer.toString(lessonID)});*/
- db.close();
- }
- //======================================================================================================================================
- // Student
- //======================================================================================================================================
- public Student getStudent(int id) {
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_STUDENT, new String[]{
- KEY_STUDENT_ID, KEY_USER_ID, KEY_GROUP_NUMBER_ID, KEY_GROUP_LABEL, KEY_ADRESS}, KEY_STUDENT_ID + "=?",
- new String[]{String.valueOf(id)}, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- Student student = new Student(
- cursor.getInt(0), // KEY_STUDENT_ID
- cursor.getInt(1), // KEY_USER_ID
- cursor.getString(2), // KEY_ADRESS
- cursor.getInt(3)); // KEY_GROUP_ID
- cursor.close();
- db.close();
- return student;
- }
- db.close();
- return null;
- }
- public List<Student> getStudentsForTeacher(Integer teacherID){
- List<Student> students = new ArrayList<>();
- String selectQuery = "SELECT " +
- TABLE_USER + "." + KEY_FULL_NAME + ", " +
- TABLE_GROUP + "." + KEY_GROUP_NUMBER_ID +
- TABLE_GROUP + "." + KEY_GROUP_LABEL +
- " FROM "+ TABLE_USER +
- " INNER JOIN " + TABLE_STUDENT +
- " ON " + TABLE_USER + "." + KEY_USER_ID + "=" +
- TABLE_STUDENT + "." + KEY_USER_ID +
- " INNER JOIN " + TABLE_GROUP +
- " ON " + TABLE_GROUP + "." + KEY_GROUP_ID + "=" +
- TABLE_STUDENT + "." + KEY_GROUP_ID +
- " INNER JOIN " + TABLE_STUDY_PLAN +
- " ON " + TABLE_GROUP + "." + KEY_GROUP_ID + "=" +
- TABLE_STUDY_PLAN + "." + KEY_GROUP_ID +
- " INNER JOIN " + TABLE_COURSE +
- " ON " + TABLE_COURSE + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_STUDY_PLAN + "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER_COURSE +
- " ON " + TABLE_TEACHER_COURSE + "." + KEY_COURSE_NAME_ID + "=" +
- TABLE_STUDY_PLAN + "." + KEY_COURSE_NAME_ID +
- " INNER JOIN " + TABLE_TEACHER +
- " ON " + TABLE_TEACHER_COURSE + "." + KEY_TEACHER_ID + "=" +
- TABLE_TEACHER + "." + KEY_TEACHER_ID +
- " WHERE (" + TABLE_TEACHER + "." + KEY_TEACHER_ID + " LIKE \'" + teacherID + "%\'" + ")";
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- do {
- Student student = new Student();
- student.setStudentID(cursor.getInt(0));
- student.setGroupID(cursor.getInt(1));
- student.setUserID(cursor.getInt(2));
- student.setAdress(cursor.getString(3));
- // user.setEmail(cursor.getString(2));
- students.add(student);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- return students;
- }
- public Integer addStudent(User user, Student student) {
- SQLiteDatabase db = this.getWritableDatabase();
- Integer userID = addUser(user, db);
- ContentValues studentValues = new ContentValues();
- studentValues.put(KEY_USER_ID, userID);
- studentValues.put(KEY_ADRESS, student.getAdress());
- Integer studentID = (int) db.insert(TABLE_STUDENT, null, studentValues);
- db.close();
- Log.d("Add new student", student.toString());
- Log.d("studentID", String.valueOf(studentID));
- return studentID;
- }
- public Integer addStudentForGroup(User user, Integer groupID, Student student) {
- SQLiteDatabase db = this.getWritableDatabase();
- Integer userID = addUser(user, db);
- ContentValues studentValues = new ContentValues();
- studentValues.put(KEY_USER_ID, userID);
- studentValues.put(KEY_GROUP_ID, groupID);
- studentValues.put(KEY_ADRESS, student.getAdress());
- Integer studentID = (int) db.insert(TABLE_STUDENT, null, studentValues);
- db.close();
- Log.d("Add new student", student.toString());
- Log.d("studentID", String.valueOf(studentID));
- return studentID;
- }
- public Integer getStudentID (String fullName){
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT " + TABLE_STUDENT +"." + KEY_STUDENT_ID +
- " FROM " + TABLE_STUDENT +
- " INNER JOIN " + TABLE_USER +
- " ON " + TABLE_STUDENT + "." + KEY_USER_ID +
- " = " + TABLE_USER + "." + KEY_USER_ID +
- " WHERE (" +
- TABLE_USER + "." + KEY_FULL_NAME + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{fullName});
- Integer currentUserID = cursor.getInt(1);
- cursor.close();
- db.close();
- return currentUserID;
- }
- //======================================================================================================================================
- //======================================================================================================================================
- public Boolean checkEmailAndPasswordTeacher(String email, String password) {
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT * FROM " + TABLE_TEACHER +
- " INNER JOIN " + TABLE_USER +
- " ON " + TABLE_TEACHER + "." + KEY_USER_ID +
- " = " + TABLE_USER + "." + KEY_USER_ID +
- " WHERE (" +
- TABLE_USER + "." + KEY_EMAIL + "=?" + " and " +
- TABLE_USER + "." + KEY_PASSWORD + "=?" + ")";
- String selectQuery1 = "SELECT * FROM " + TABLE_USER +
- " WHERE (" +
- TABLE_USER + "." + KEY_EMAIL + "=?" + " and " +
- TABLE_USER + "." + KEY_PASSWORD + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{email, password});
- //Log.d("User-teacher", "1");
- int count = cursor.getCount();
- cursor.close();
- return count > 0;
- }
- public Boolean checkEmailAndPasswordStudent(String email, String password) {
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT * FROM " + TABLE_STUDENT +
- " INNER JOIN " + TABLE_USER +
- " ON " + TABLE_STUDENT + "." + KEY_USER_ID +
- " = " + TABLE_USER + "." + KEY_USER_ID +
- " WHERE (" +
- TABLE_USER + "." + KEY_EMAIL + "=?" + " and " +
- TABLE_USER + "." + KEY_PASSWORD + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{email, password});
- int count = cursor.getCount();
- cursor.close();
- db.close();
- return count > 0;
- }
- public Integer CurrentUserID(String email, String password){
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT " + TABLE_USER + "." + KEY_USER_ID +
- " FROM " + TABLE_USER +
- " WHERE (" +
- TABLE_USER + "." + KEY_EMAIL + "=?" + " and " +
- TABLE_USER + "." + KEY_PASSWORD + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{email, password});
- Integer currentUserID = cursor.getInt(0);
- cursor.close();
- db.close();
- return currentUserID;
- }
- public Integer CurrentTeacherID(String email, String password){
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT " + TABLE_TEACHER + "." + KEY_TEACHER_ID +
- " FROM " + TABLE_TEACHER +
- " INNER JOIN " + TABLE_USER +
- " ON " + TABLE_TEACHER + "." + KEY_USER_ID +
- " = " + TABLE_USER + "." + KEY_USER_ID +
- " WHERE (" +
- TABLE_USER + "." + KEY_EMAIL + "=?" + " and " +
- TABLE_USER + "." + KEY_PASSWORD + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{email, password});
- Integer currentUserID = cursor.getInt(0);
- cursor.close();
- db.close();
- return currentUserID;
- }
- public Integer CurrentStudentID(String email, String password){
- SQLiteDatabase db = this.getReadableDatabase();
- String selectQuery = "SELECT " + TABLE_STUDENT +"." + KEY_STUDENT_ID +
- " FROM " + TABLE_STUDENT +
- " INNER JOIN " + TABLE_USER +
- " ON " + TABLE_STUDENT + "." + KEY_USER_ID +
- " = " + TABLE_USER + "." + KEY_USER_ID +
- " WHERE (" +
- TABLE_USER + "." + KEY_EMAIL + "=?" + " and " +
- TABLE_USER + "." + KEY_PASSWORD + "=?" + ")";
- Cursor cursor = db.rawQuery(selectQuery, new String[]{email, password});
- Integer currentUserID = cursor.getInt(0);
- cursor.close();
- db.close();
- return currentUserID;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement