Fix provider for API_ACCOUNTS

This commit is contained in:
Dominik Schürmann 2014-03-26 17:55:48 +01:00
parent ba37fc254d
commit 2e063a42ed
3 changed files with 10 additions and 10 deletions

View File

@ -65,7 +65,7 @@ public class KeychainContract {
String ENCRYPTION_ALGORITHM = "encryption_algorithm"; String ENCRYPTION_ALGORITHM = "encryption_algorithm";
String HASH_ALORITHM = "hash_algorithm"; String HASH_ALORITHM = "hash_algorithm";
String COMPRESSION = "compression"; String COMPRESSION = "compression";
String PACKAGE_NAME_FK = "package_name"; // foreign key to api_apps.package_name String PACKAGE_NAME = "package_name"; // foreign key to api_apps.package_name
} }
public static final class KeyTypes { public static final class KeyTypes {

View File

@ -88,10 +88,10 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ ApiAppsAccountsColumns.ENCRYPTION_ALGORITHM + " INTEGER, " + ApiAppsAccountsColumns.ENCRYPTION_ALGORITHM + " INTEGER, "
+ ApiAppsAccountsColumns.HASH_ALORITHM + " INTEGER, " + ApiAppsAccountsColumns.HASH_ALORITHM + " INTEGER, "
+ ApiAppsAccountsColumns.COMPRESSION + " INTEGER, " + ApiAppsAccountsColumns.COMPRESSION + " INTEGER, "
+ ApiAppsAccountsColumns.PACKAGE_NAME_FK + " TEXT NOT NULL, " + ApiAppsAccountsColumns.PACKAGE_NAME + " TEXT NOT NULL, "
+ "UNIQUE(" + ApiAppsAccountsColumns.ACCOUNT_NAME + ", " + "UNIQUE(" + ApiAppsAccountsColumns.ACCOUNT_NAME + ", "
+ ApiAppsAccountsColumns.PACKAGE_NAME_FK + "), " + ApiAppsAccountsColumns.PACKAGE_NAME + "), "
+ "FOREIGN KEY(" + ApiAppsAccountsColumns.PACKAGE_NAME_FK + ") REFERENCES " + "FOREIGN KEY(" + ApiAppsAccountsColumns.PACKAGE_NAME + ") REFERENCES "
+ Tables.API_APPS + "(" + ApiAppsColumns.PACKAGE_NAME + ") ON DELETE CASCADE)"; + Tables.API_APPS + "(" + ApiAppsColumns.PACKAGE_NAME + ") ON DELETE CASCADE)";
KeychainDatabase(Context context) { KeychainDatabase(Context context) {

View File

@ -687,13 +687,13 @@ public class KeychainProvider extends ContentProvider {
break; break;
case API_ACCOUNTS: case API_ACCOUNTS:
qb.setTables(Tables.API_ACCOUNTS); qb.setTables(Tables.API_ACCOUNTS);
qb.appendWhere(Tables.API_ACCOUNTS + "." + ApiAccounts.PACKAGE_NAME + " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(1));
break; break;
case API_ACCOUNTS_BY_ACCOUNT_NAME: case API_ACCOUNTS_BY_ACCOUNT_NAME:
qb.setTables(Tables.API_ACCOUNTS + " INNER JOIN " + Tables.API_APPS + " ON " + "(" qb.setTables(Tables.API_ACCOUNTS);
+ Tables.API_APPS + "." + ApiApps.PACKAGE_NAME + " = " + Tables.API_ACCOUNTS + "." qb.appendWhere(Tables.API_ACCOUNTS + "." + ApiAccounts.PACKAGE_NAME + " = ");
+ ApiAccounts.PACKAGE_NAME_FK + " )");
qb.appendWhere(Tables.API_APPS + "." + ApiApps.PACKAGE_NAME + " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(1)); qb.appendWhereEscapeString(uri.getPathSegments().get(1));
qb.appendWhere(" AND " + Tables.API_ACCOUNTS + "." + ApiAccounts.ACCOUNT_NAME + " = "); qb.appendWhere(" AND " + Tables.API_ACCOUNTS + "." + ApiAccounts.ACCOUNT_NAME + " = ");
@ -800,7 +800,7 @@ public class KeychainProvider extends ContentProvider {
// set foreign key automatically based on given uri // set foreign key automatically based on given uri
// e.g., api_apps/com.example.app/accounts/ // e.g., api_apps/com.example.app/accounts/
String packageName = uri.getPathSegments().get(1); String packageName = uri.getPathSegments().get(1);
values.put(ApiAccounts.PACKAGE_NAME_FK, packageName); values.put(ApiAccounts.PACKAGE_NAME, packageName);
Log.d(Constants.TAG, "provider packageName: " + packageName); Log.d(Constants.TAG, "provider packageName: " + packageName);
@ -1061,7 +1061,7 @@ public class KeychainProvider extends ContentProvider {
andSelection = " AND (" + selection + ")"; andSelection = " AND (" + selection + ")";
} }
return ApiAccounts.PACKAGE_NAME_FK + "=" + packageName + " AND " return ApiAccounts.PACKAGE_NAME + "=" + packageName + " AND "
+ ApiAccounts.ACCOUNT_NAME + "=" + accountName + ApiAccounts.ACCOUNT_NAME + "=" + accountName
+ andSelection; + andSelection;
} }