public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.mContext = context;
Log.e("Path 1", DB_PATH);
}
public void openDataBase() throws SQLException {
String myPath = DB_PATH + DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
@Override
public void onCreate(SQLiteDatabase database) {
String createQuery1 = "CREATE TABLE " + COURSES_TABLE + "(" +
COURSES_KEY_FIELD_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
FIELD_ALPHA + " TEXT, " +
FIELD_NUMBER + " TEXT, " +
FIELD_TITLE + " TEXT," +
FIELD_TITLE1 + " TEXT," +
FIELD_TITLE2 + " TEXT " + ")";
database.execSQL(createQuery1);
String createQuery2 = "CREATE TABLE " + OFFERINGS_TABLE + "(" +
OFFERINGS_KEY_FIELD_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
FIELD_SEMESTER_CODE + " INTEGER, " +
FIELD_COURSE_ID + " INTEGER, "
+
"FOREIGN KEY(" + FIELD_COURSE_ID + ") REFERENCES "
+
COURSES_TABLE + "(" + COURSES_KEY_FIELD_ID + ")" +
")";
database.execSQL(createQuery2);
String createQuery3 = "CREATE TABLE " + DATAALL_TABLE + "(" +
COURSES_KEY_FIELD_ID1 + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
FIELD_BARCODE + " TEXT, " +
FIELD_MATERIALNUM + " TEXT, " +
FIELD_MATERIALDESC + " TEXT, " +
FIELD_CURRENTDATE + " TEXT, " +
FIELD_PRODUCTIONDATE + " TEXT, " +
FIELD_EXPIRYRATIO + " TEXT, " +
FIELD_PRODUCTIONEXPIRY + " TEXT, " +
FIELD_QTY + " TEXT " + ")";
database.execSQL(createQuery3);
}
@Override
public void onUpgrade(SQLiteDatabase database,
int oldVersion,
int newVersion) {
database.execSQL("DROP TABLE IF EXISTS " + COURSES_TABLE);
database.execSQL("DROP TABLE IF EXISTS " + OFFERINGS_TABLE);
database.execSQL("DROP TABLE IF EXISTS " + DATAALL_TABLE);
onCreate(database);
}
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
String myPath = DB_PATH + DATABASE_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
} catch (SQLiteException e) {}
if (checkDB != null) {
checkDB.close();
}
return checkDB != null ? true : false;
}
private void copyDataBase() throws IOException {
InputStream myInput = mContext.getAssets().open(DATABASE_NAME);
String outFileName = DB_PATH + DATABASE_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[10];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
//******* ADDING THE DATA IN TO DATABASE
public void insertlabel(String Material_Barcode, String Material_Number, String Material_Description, String Scanning_Date, String Production_Date, String Expiry_Ratio, String Product_Durability, String Qty) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(FIELD_BARCODE, Material_Barcode);
cv.put(FIELD_MATERIALNUM, Material_Number);
cv.put(FIELD_MATERIALDESC, Material_Description);
cv.put(FIELD_CURRENTDATE, Scanning_Date);
cv.put(FIELD_PRODUCTIONDATE, Production_Date);
cv.put(FIELD_EXPIRYRATIO, Expiry_Ratio);
cv.put(FIELD_PRODUCTIONEXPIRY, Product_Durability);
cv.put(FIELD_QTY, Qty);
db.insert(DATAALL_TABLE, null, cv);
db.close();
}
//********** COURSE TABLE OPERATIONS: ADD, GETALL, EDIT, DELETE
当包含值15的节点是叶节点(没有childern)时,此函数有效,但是,如果此节点是父节点,则它不起作用。有人可以帮我调整指针,这样即使节点是父节点,它也会创建一个没有15的新树吗?