mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-01 04:17:21 +01:00
database fix
This commit is contained in:
parent
34adfca115
commit
5f5445e757
@ -47,9 +47,7 @@ public class LoginAction extends AsyncExecutor<LoginAction.Param, LoginAction.Re
|
||||
case Param.MODE_REQUEST:
|
||||
if (settings.isLoggedIn()) {
|
||||
Account login = settings.getLogin();
|
||||
if (!database.containsLogin(login.getId())) {
|
||||
database.saveLogin(login);
|
||||
}
|
||||
database.saveLogin(login);
|
||||
}
|
||||
ConnectionResult result = connection.getAuthorisationLink(param.connection);
|
||||
return new Result(Result.MODE_REQUEST, null, result, null);
|
||||
|
@ -262,7 +262,7 @@ public class AppDatabase {
|
||||
/**
|
||||
* selection for account entry
|
||||
*/
|
||||
private static final String ACCOUNT_SELECTION = AccountTable.ID + "=?";
|
||||
private static final String ACCOUNT_SELECTION = AccountTable.ID + "=? AND " + AccountTable.HOSTNAME + "=?";
|
||||
|
||||
/**
|
||||
* selection for poll entry
|
||||
@ -512,6 +512,11 @@ public class AppDatabase {
|
||||
*/
|
||||
public void saveLogin(Account account) {
|
||||
synchronized (LOCK) {
|
||||
SQLiteDatabase db = adapter.getDbWrite();
|
||||
// delete login entry if exists
|
||||
String[] accountArgs = {Long.toString(account.getId()), account.getHostname()};
|
||||
db.delete(AccountTable.NAME, ACCOUNT_SELECTION, accountArgs);
|
||||
// insert/update login
|
||||
ContentValues column = new ContentValues(9);
|
||||
column.put(AccountTable.ID, account.getId());
|
||||
column.put(AccountTable.DATE, account.getTimestamp());
|
||||
@ -522,7 +527,6 @@ public class AppDatabase {
|
||||
column.put(AccountTable.ACCESS_TOKEN, account.getOauthToken());
|
||||
column.put(AccountTable.TOKEN_SECRET, account.getOauthSecret());
|
||||
column.put(AccountTable.BEARER, account.getBearerToken());
|
||||
SQLiteDatabase db = adapter.getDbWrite();
|
||||
db.insertWithOnConflict(AccountTable.NAME, "", column, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
if (account.getUser() != null) {
|
||||
saveUser(account.getUser(), db, SQLiteDatabase.CONFLICT_IGNORE);
|
||||
@ -976,7 +980,7 @@ public class AppDatabase {
|
||||
*/
|
||||
public void removeLogin(Account account) {
|
||||
synchronized (LOCK) {
|
||||
String[] accountArgs = {Long.toString(account.getId())};
|
||||
String[] accountArgs = {Long.toString(account.getId()), account.getHostname()};
|
||||
String[] pushArgs = {account.getId() + '@' + account.getHostname()};
|
||||
|
||||
SQLiteDatabase db = adapter.getDbWrite();
|
||||
@ -1003,23 +1007,6 @@ public class AppDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if status exists in database
|
||||
*
|
||||
* @param id status ID
|
||||
* @return true if found
|
||||
*/
|
||||
public boolean containsLogin(long id) {
|
||||
synchronized (LOCK) {
|
||||
String[] args = {Long.toString(id)};
|
||||
SQLiteDatabase db = adapter.getDbRead();
|
||||
Cursor c = db.query(AccountTable.NAME, null, ACCOUNT_SELECTION, args, null, null, SINGLE_ITEM);
|
||||
boolean result = c.moveToFirst();
|
||||
c.close();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove user from notification results
|
||||
*
|
||||
|
@ -90,7 +90,7 @@ public class DatabaseAdapter {
|
||||
*/
|
||||
private static final String TABLE_ACCOUNTS = "CREATE TABLE IF NOT EXISTS "
|
||||
+ AccountTable.NAME + "("
|
||||
+ AccountTable.ID + " INTEGER PRIMARY KEY,"
|
||||
+ AccountTable.ID + " INTEGER,"
|
||||
+ AccountTable.DATE + " INTEGER,"
|
||||
+ AccountTable.ACCESS_TOKEN + " TEXT,"
|
||||
+ AccountTable.TOKEN_SECRET + " TEXT,"
|
||||
|
Loading…
Reference in New Issue
Block a user