public static void DoUpdateDatabaseSQL() { SanitaLog.d(TAG, "DoUpdateDatabaseSQL--START"); try { IBaseDao baseDAO = MediboxDatabaseUtility.GetDatabaseDAO(); //Get connection using (IDbConnection connection = baseDAO.GetConnection()) { //Open connection connection.Open(); //Begin transtation using (IDbTransaction trans = connection.BeginTransaction()) { //Check sql SoftUpdate mSoftUpdate = SoftUpdateDB.mInstance.GetSoftUpdate_Simple(connection, trans); SanitaLog.d(TAG, "Database sql = " + mSoftUpdate.SoftUpdateSQL); SanitaLog.d(TAG, "Software sql = " + MediboxDatabaseUtility.GetDatabaseVersion()); if (MediboxDatabaseUtility.GetDatabaseVersion().GetDouble() > mSoftUpdate.SoftUpdateSQL.GetDouble()) { SanitaLog.d(TAG, "BEGIN UPDATE SQL"); int hosobenhan_partion = 0; if (mLocalDatabase.SynchDatabase(connection, trans, null, hosobenhan_partion, false)) { SanitaLog.d(TAG, "UPDATE SUCCESS !"); mSoftUpdate.SoftUpdateSQL = MediboxDatabaseUtility.GetDatabaseVersion(); if (mSoftUpdate.SoftUpdateID > 0) { if (SoftUpdateDB.mInstance.UpdateSoftUpdate_SQL(connection, trans, mSoftUpdate) < 0) { SanitaLog.d(TAG, "UPDATE SQL VERSION TO DATABASE NG !"); //Rollback trans.Rollback(); connection.Close(); return; } } else { if (SoftUpdateDB.mInstance.InsertSoftUpdate(connection, trans, mSoftUpdate) < 0) { SanitaLog.d(TAG, "INSERT SQL VERSION TO DATABASE NG !"); //Rollback trans.Rollback(); connection.Close(); return; } } } SanitaLog.d(TAG, "END UPDATE SQL"); } //----------------------------------------------------------------------------- //Commit transtation trans.Commit(); //Close connection connection.Close(); } } SanitaLog.d(TAG, "DoUpdateDatabaseSQL--END"); } catch (Exception ex) { SanitaLog.e(TAG, ex); } }
public static void InitDatabase() { MediboxDatabaseUtility.InitDatabase(); }