Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBHandler extends SQLiteOpenHelper {
protected static final String COLUMN_ID = "User_ID";
private static final String DATABASE_NAME = "Database.db";
private static final int DATABASE_VERSION = 1;
protected static final String TABLE_NAME = "User";
//question table connected to username of previous table
protected static final String TABLE_NAME2 = "Question";
protected static final String COLUMN_USER = "Username";
protected static final String COLUMN_PASS = "Password";
protected static final String COLUMN_USER_ID = "User_ID";
protected static final String COLUMN_QUESTIONS = "QuestionTitle";
protected static final String COLUMN_ANSWER = "Answer";
protected static final String TABLE_NAME3 = "Note";
protected static final String COLUMN_NOTE_ID = "ID";
protected static final String COLUMN_NOTES = "Notes";
//information fot Table 1 - login details
private static final String TAG = "DataB";
//initialize the database
DBHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE " + TABLE_NAME + " ("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COLUMN_USER + " TEXT NOT NULL, "
+ COLUMN_PASS + " TEXT NOT NULL "
+ ");";
String createTable2 = "CREATE TABLE " + TABLE_NAME2 + " ("
+ COLUMN_USER_ID + " INTEGER, "
+ COLUMN_QUESTIONS + " TEXT, "
+ COLUMN_ANSWER + " TEXT NOT NULL"
+ ")";
String createTable3 = "CREATE TABLE " + TABLE_NAME3 + " ("
+ COLUMN_NOTE_ID + " INTEGER, "
+ COLUMN_NOTES + " TEXT PRIMARY KEY"
+ ");";
db.execSQL(createTable);
db.execSQL(createTable2);
db.execSQL(createTable3);
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME2);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME3);
onCreate(db);
}
public long addData(String user, String pass) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_USER, user);
values.put(COLUMN_PASS, pass);
Log.d(TAG, "addData: Adding " + user + " to " + TABLE_NAME);
Log.d(TAG, "addData: Adding " + pass + " to " + TABLE_NAME);
long result = db.insert(TABLE_NAME, null, values);
//if data is invalid it will return -1
return result;
}
}