Skip to content

Commit

Permalink
Added subject code
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh Joshi committed Jul 28, 2014
1 parent 79f8ae3 commit 3b7ad04
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class sqDatabase extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
private static final int DATABASE_VERSION = 2;

// Database Name
private static final String DATABASE_NAME = "subjectsManager";
Expand All @@ -31,7 +31,7 @@ public class sqDatabase extends SQLiteOpenHelper {
private static final String KEY_TITLE = "title";
private static final String KEY_SLOT = "slot";

private static final String[] COLUMNS = {KEY_CLASNBR,KEY_TITLE,KEY_SLOT,"type","attended", "conducted", "regdate", "details"};
private static final String[] COLUMNS = {KEY_CLASNBR,KEY_TITLE,KEY_SLOT,"type","attended", "conducted", "regdate", "details", "code"};

public sqDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Expand All @@ -42,15 +42,20 @@ public void onCreate(SQLiteDatabase sqLiteDatabase) {
String CREATE_SUBJECTS_TABLE = "CREATE TABLE " + TABLE_SUBJECTS + "("
+ KEY_CLASNBR + " INTEGER PRIMARY KEY," + KEY_TITLE + " TEXT,"
+ KEY_SLOT + " TEXT,"
+ "type TEXT, attended INTEGER, conducted INTEGER, regdate TEXT, details TEXT)";

+ "type TEXT, attended INTEGER, conducted INTEGER, regdate TEXT, details TEXT, code TEXT)";
sqLiteDatabase.execSQL(CREATE_SUBJECTS_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_SUBJECTS);
onCreate(sqLiteDatabase);
if(i == 1 && i2 == 2){
String upgradeQuery = "ALTER TABLE " + TABLE_SUBJECTS + " ADD COLUMN code TEXT";
sqLiteDatabase.execSQL(upgradeQuery);
}
else{
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_SUBJECTS);
onCreate(sqLiteDatabase);
}
}

public void addSubjects(String SubjectJSON){
Expand All @@ -73,6 +78,7 @@ public void addSubjects(String SubjectJSON){
values.put("attended", Integer.parseInt(sub.getString("attended")));
values.put("regdate", sub.getString("regdate"));
values.put("details", sub.getJSONArray("details").toString());
values.put("code", sub.getString("code"));
db.insertWithOnConflict(TABLE_SUBJECTS, null, values, SQLiteDatabase.CONFLICT_REPLACE);
}
db.close();
Expand All @@ -98,7 +104,7 @@ public Subject getSubject(String clsnbr) {
sub.conducted = cursor.getInt(5);
sub.regdate = cursor.getString(6);
sub.detailsString = cursor.getString(7);

sub.code = cursor.getString(8);
sub.percentage = (int) DataHandler.getPer(sub.attended, sub.conducted);

if (DataHandler.getPer(sub.attended, sub.conducted) > sub.percentage)
Expand Down Expand Up @@ -144,7 +150,7 @@ public ArrayList<Subject> getAllSubjects(){
sub.conducted = cursor.getInt(5);
sub.regdate = cursor.getString(6);
sub.detailsString = cursor.getString(7);

sub.code = cursor.getString(8);
sub.percentage = (int) DataHandler.getPer(sub.attended, sub.conducted);

if (DataHandler.getPer(sub.attended, sub.conducted) > sub.percentage)
Expand Down

0 comments on commit 3b7ad04

Please sign in to comment.