mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-15 05:25:05 -05:00
Add/Edit server: server title should be unique
This commit is contained in:
parent
0a4a6be5fd
commit
e28c09e704
@ -97,11 +97,14 @@ public class Database extends SQLiteOpenHelper
|
||||
{
|
||||
// XXX: We delete the database currently, in future versions we want to
|
||||
// migrate the database to the new version (add or remove rows..)
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ServerConstants.TABLE_NAME + ";");
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ChannelConstants.TABLE_NAME + ";");
|
||||
db.execSQL("DROP TABLE IF EXISTS " + IdentityConstants.TABLE_NAME + ";");
|
||||
|
||||
onCreate(db);
|
||||
// XXX: Do not delete databases (release version)
|
||||
|
||||
// db.execSQL("DROP TABLE IF EXISTS " + ServerConstants.TABLE_NAME + ";");
|
||||
// db.execSQL("DROP TABLE IF EXISTS " + ChannelConstants.TABLE_NAME + ";");
|
||||
// db.execSQL("DROP TABLE IF EXISTS " + IdentityConstants.TABLE_NAME + ";");
|
||||
|
||||
// onCreate(db);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,6 +233,35 @@ public class Database extends SQLiteOpenHelper
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given server title is currently used
|
||||
*
|
||||
* @param title The server title
|
||||
* @return true if there's a server with this title, false otherwise
|
||||
*/
|
||||
public boolean isTitleUsed(String title)
|
||||
{
|
||||
boolean isTitleUsed = false;
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
ServerConstants.TITLE + " = '" + title + "'",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
if (cursor.moveToNext()) {
|
||||
isTitleUsed = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
||||
return isTitleUsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate a server object from the given database cursor
|
||||
* @param cursor
|
||||
|
@ -263,6 +263,13 @@ public class AddServerActivity extends Activity implements OnClickListener
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ValidationException("Enter a numeric port");
|
||||
}
|
||||
|
||||
Database db = new Database(this);
|
||||
if (db.isTitleUsed(title) && (server == null || !server.getTitle().equals(title))) {
|
||||
db.close();
|
||||
throw new ValidationException("There is already a server with this title");
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user