project-imas / encrypted-core-data Goto Github PK
View Code? Open in Web Editor NEWv2.0 - iOS Core Data encrypted SQLite store using SQLCipher
License: Other
v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
License: Other
I have an abstract Account class with multiple child classes. I have a fetch request that pulls in all of the various accounts by setting the Account entity as the fetch request entity. If I use encrypted-core-data this works fine immediately after the data is imported. After the accounts have been saved and reloaded, however, for every child account object that was saved both an Account object and an object of the child class is returned
Using the following NSPredicate code to access to one-to-many relations I have an error as in attached image.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fld_Code CONTAINS[cd] %@) OR (rel_Localizations.fld_Name CONTAINS[cd] %@)", query, query];
All other things using encrypted-core-data goes very very very well.
I try to NSPredicate in not related columns and I have no errors. All things goes well.
I confirm that the NSPredicate line is fully functional in unencrypted version of sqlite db.
Thanks a lot for your great work!
Davide
Looks like there may be a potential path issue with iOS 7, will update to follow Gordiii's assessment (#37) and then check that everything still works as intended on iOS 6.
The collection operators used on relationships within NSPredicate are not currently working. I am trying to use a sum operation but am getting an error. This works in my existing Magical Record / Core Data application, but fails when I switch to EncryptedStore.
I'll describe my problem in terms of the FailedBankCD data model. Perform the following changes:
// Find only the failed banks where the total balance across all customers > 100
NSPredicate *totalBalancePredicate = [NSPredicate predicateWithFormat:@"[email protected] > 100"];
[FailedBankInfo MR_fetchAllSortedBy:@"name" ascending:YES withPredicate:totalBalancePredicate groupBy:nil delegate:self];
The follow is the error I'm running into:
+[MagicalRecord(ErrorHandling) defaultErrorHandler:](0x2ec308) Error: no such column: [email protected]
The following is the generated query that triggers the above error:
SELECT FailedBankInfo.ID FROM FailedBankInfo JOIN FailedBankCustomer AS [customers] ON FailedBankInfo.customers_id = [customers].ID WHERE ([customers.@sum].balance > ?) ORDER BY FailedBankInfo.name ASC;
Great Toolkit and I like to use it!
Unfortunately I have now to fetch the db for filling a table with sections. For that I use the NSFetchedResultsController and I need distinct results. With core data that's no problem but I have to set the result type to NSDictionaryResultType. The framework seems to support only NSManagedObjectResultType or NSManagedObjectIDResultType yet. Do you plan to integrate NSDictionaryResultType?
Pull-Request solves this issue. Please check and integrate.
Somewhere along the way test_createSeveralUsersWithPostsAndComplexSearch. Looks like it is one of my recent predicate handling commits, but need to track it down.
to fix it:
replace:
NSString *limit = ([fetchRequest fetchLimit] > 0 ? [NSString stringWithFormat:@" LIMIT %ld", (unsigned long)[fetchRequest fetchLimit]]: @"");
with:
NSString *limit = ([fetchRequest fetchLimit] > 0 ? [NSString stringWithFormat:@" LIMIT %ld, %ld", (unsigned long)[fetchRequest fetchOffset] , (unsigned long)[fetchRequest fetchLimit]]: @"");
In FBCDMasterViewController.m, line 27 (![[self fetchedResultsController] performFetch:&error]) fails with 2013-08-20 09:30:28.322 FailedBankCD[59917:c07] *** -[NSError retain]: message sent to deallocated instance 0xda13be0
This seems to have been introduced with the latest set of pull requests that update fetchRequests.
I was wondering if there is proposed support for using string predicates such as:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name.length > 0"];
Or what I can do to make this work
Thanks
I've successfully encrypt and decrypted a sqlciphered db through using encrypted-core-data. All seemed fine until I deployed to an iPhone device. The issue appears to be in the method:
makeStoreWithDatabaseURL:(NSURL )databaseURL managedObjectModel:(NSManagedObjectModel *)objModel :(NSString)passcode
of EncryptedStore.m when the NSPersistentStore is created. The NSAssert reports the corresponding error. Here's a summary of my trial and errors by modifying the NSURL variable databaseURL in the method:
makeStore:(NSManagedObjectModel *)objModel :(NSString *)passcode
Test A:
databaseURL = [applicationSupportURL URLByAppendingPathComponent:[@"Preload" stringByAppendingString:@".sqlite"]];Test A Result:
Error Domain=NSSQLiteErrorDomain Code=14 "The operation couldn’t be completed. (NSSQLiteErrorDomain error 14.)" UserInfo=0xc46e5e0 {EncryptedStoreErrorMessage=unable to open database file}Test B:
databaseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Preload" ofType:@"sqlite"]];Test B Result:
Success --> Loads the data as intended in the simulator
Repeat Test A:
Error Domain=NSSQLiteErrorDomain Code=14 "The operation couldn’t be completed. (NSSQLiteErrorDomain error 14.)" UserInfo=0x15d5fd40 {EncryptedStoreErrorMessage=unable to open database file}'Repeat Test B:
Error Domain=NSSQLiteErrorDomain Code=8 "The operation couldn’t be completed. (NSSQLiteErrorDomain error 8.)" UserInfo=0x14e4e180 {EncryptedStoreErrorMessage=attempt to write a readonly database}'
The main difference is the path in which the sqlite resides:
For Test A:
file:///Users/hkbc02/Library/Application%20Support/iPhone%20Simulator/7.0.3-64/Applications/D0864B56-840A-455F-9B52-EB75FE258FD1/Library/Application%20Support/Preload.sqlite
For Test B:
file:///Users/hkbc02/Library/Application%20Support/iPhone%20Simulator/7.0.3-64/Applications/D0864B56-840A-455F-9B52-EB75FE258FD1/MyAppName.app/Preload.sqlite
Any ideas what I might have done wrong?
Hi! I don't know if it's related to this project, or maybe only to SQLCipher, but I had a chance to find the problem using "blind" debug method, because all I've got from EncryptedStore is:
'Unable to add persistent store
(null)'
where (null) is NSError.
SQL debug shows a little bit more: db wasn't created (SQL DEBUG: ROLLBACK;
).
After a few hours of desperate debugging I found out that the reason was an attribute, called when
. It's crashing everything and it's easy to reproduce.
Inheritance Table: inheritance is not really supported or tested at this time.
I'd like to add support for inheritance. What is broken / needs to be added to support this feature?
Before tackling the intermediate table issues from #20 need to come up with a good set of cases that fail and are quick to check against.
I am evaluating ECD, and the managed object model that we want to use with it exposed a problem. We have an entity with the name Transaction
, and that is a keyword in SQLite. The convention within Core Data's built-in support for using the SQLite store type is to prefix just about every name (tables, columns, possibly other aspects) with "Z". For my case, I can make a quick change to -tableNameForEntity:
so that every table name starts with Z. Other people might run into similar problems but not have such an easy time addressing the naming conflicts.
This is a great library, and I hope to put it into production use soon. Thank you!
We are using a subquery in one of our predicates, and it looks like that is not yet supported. Should we figure out an alternative way?
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(SUBQUERY(%K, $message, $message.isEncrypted == NO).@count != 0)",OTRManagedBuddyRelationships.messages];
It looks like there is some code to support it but there is a missing "else" which causes it to fail. I added the potentially missing else, but it still fails, so for now we will figure out a way to use less complex NSPredicates.
Is there any way to change this when setting up a store? Perhaps where ...options... is below?
NSDictionary *optionsENC = @{....options.....};
store = [self addPersistentStoreWithType:EncryptedStoreType
configuration:nil
URL:url
options:optionsENC
error:&error];
In general no relations propagate back to their source. For example if you have:
You will end up with the Posts table having reference to the IDs in the Users table, but not vice-versa. This seems to be the case for all relationship types.
Many-to-Many relationships would actually require an intermediate table, and there is no code in the master that would actually deal with this.
Despite exceptions, established relations between entities will never be persisted to the store and will not survive an application restart (alltough they might be cached by CoreData mechanisms while the application is running).
i use your EncryptedStore init NSManagedObjectContext in AppDelegate like this:
(NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"XXXX.sqlite"];
_persistentStoreCoordinator =
[EncryptedStore makeStoreWithDatabaseURL:storeURL
managedObjectModel:self.managedObjectModel
:@"XXXX"];
return _persistentStoreCoordinator;
}
(NSManagedObjectContext *)managedObjectContext {
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = self.persistentStoreCoordinator;
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContext alloc] init];
_managedObjectContext.persistentStoreCoordinator = coordinator;
}
return _managedObjectContext;
}
(NSManagedObjectModel *)managedObjectModel {
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"XXXX" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
then i can use this NSManagedObjectContext to save data, but can't fetch data out. fetch code like this:
(NSArray *)getPlantByIds:(NSArray *)plantIds
{
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"plant_id IN %@", plantIds];
[fetchRequest setResultType:NSDictionaryResultType];
fetchRequest.propertiesToFetch = [[NSArray alloc] initWithObjects:@"plant_id", @"name", nil];
NSError *error = nil;
NSArray *plants = [context executeFetchRequest:fetchRequest error:&error];
if (error) {
DebugLog(@"fecth by is failed reason is: %@", error);
} else if ( [plants count] != 0) {
DebugLog(@"plants %@", plants);
return plants;
}
return nil;
}
my project build for iOS7, please help me.
NSFetchedResultsController has the ability to use sectionNameKeyPath (https://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html#//apple_ref/occ/instp/NSFetchedResultsController/sectionNameKeyPath). ECD does not currently support this feature.
Hi,
I am using your store, along with Magical Records.
I am raising a fetch request with the predicate
[NSPredicate predicateWithFormat:@"attribute != NULL"]
However, the resulting query contained 'attribute IS ?'
Following through the logic of the query construction I found that the operator becomes a dictionary containing the format ("%@"), and operator ("!="). However, the operator key never seemed to be used in the query construction, effectively turning != into =.
I made the following change (around line 1567), and it seems to have fixed the issue. Apologies for not just forking the code, but there's a lot of other changes that will confuse the issue.
Does this look right, or am I following your logic incorrectly with possible side effects?
if (rightOperand && !rightBindings) {
if([[operator objectForKey:@"operator"] isEqualToString:@"!="]) {
query = [@[leftOperand, @"IS NOT", rightOperand] componentsJoinedByString:@" "];
}
else {
query = [@[leftOperand, @"IS", rightOperand] componentsJoinedByString:@" "];
}
} else {
query = [@[leftOperand, [operator objectForKey:@"operator"], rightOperand] componentsJoinedByString:@" "];
}
Thanks for the great project.
Due to a new behaviour in iOS7 which caused me to believe there was an issue with my configurations sqlite3/sqlcipher/encrypted-core-data I added and removed various packages on my system. The behaviour was the fact sqlite built through compiling iOS generated two extra files, awl and shm (journal files). What was strange to me was that if I copied only the sqlite file to a different location no data would be retrieved/queried. This has now been resolved, however, I'm now encountering compilation issues with encrypted-core-data as shown below:
Undefined symbols for architecture x86_64:
"_sqlite3_bind_blob", referenced from:
-[EncryptedStore saveMetadata] in EncryptedStore.o
-[EncryptedStore bindProperty:withValue:forKey:toStatement:atIndex:] in EncryptedStore.o
"_sqlite3_bind_double", referenced from:
-[EncryptedStore bindProperty:withValue:forKey:toStatement:atIndex:] in EncryptedStore.o
___46-[EncryptedStore bindWhereClause:toStatement:]_block_invoke in EncryptedStore.o
"_sqlite3_bind_int", referenced from:
-[EncryptedStore bindProperty:withValue:forKey:toStatement:atIndex:] in EncryptedStore.o
"_sqlite3_bind_int64", referenced from:
-[EncryptedStore newValuesForObjectWithID:withContext:error:] in EncryptedStore.o
-[EncryptedStore newValueForRelationship:forObjectWithID:withContext:error:] in EncryptedStore.o
___59-[EncryptedStore handleInsertedObjectsInSaveRequest:error:]_block_invoke in EncryptedStore.o
___64-[EncryptedStore handleUpdatedObjectsInSaveRequest:cache:error:]_block_invoke in EncryptedStore.o
___58-[EncryptedStore handleDeletedObjectsInSaveRequest:error:]_block_invoke in EncryptedStore.o
-[EncryptedStore bindProperty:withValue:forKey:toStatement:atIndex:] in EncryptedStore.o
___46-[EncryptedStore bindWhereClause:toStatement:]_block_invoke in EncryptedStore.o
...
"_sqlite3_bind_text", referenced from:
.....
...
"_sqlite3_value_text", referenced from:
_dbsqliteRegExp in EncryptedStore.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Just throwing out the question, has anything changed recently that may have caused this?
I'm using SQLite version 3.7.17.
Add method to change the key(passcode) on an existing encrypted database.
If I have already created a database with password, is there a way to change that password?
When there is a relationship that requires a foreign key, the name of the field is created by taking the name of the table and affixing _id to it. This works great until you have more than one relationship to the same table, and then it fails. I was wondering if using the name of the relationship (if that is guaranteed to be unique for that table) is a better way to go and not affixing the _id because that could also create a problem with duplicate field names.
I have two entities that have a one-to-one relationship to each other. The entities are fine in memory when created, until saving and quitting the app. Upon reload of the entities, the relationship is gone.
The problem seems to stem from an assumption that a statement such as if (![obj isToMany] && [inverse isToMany])
is the way all relationships work. I made some changes locally to these assumptions, but I'm not confident I handled this correctly. This makes me nervous to use this otherwise fantastic library.
You can reproduce this by setting up a model to have two entities with inverse relationships pointing at each other, but not checking the To-Many Relationship box on either end. Saved entities will not retain their relationship after restarting the app.
I have a case where I need to create a query that uses a NSExpressionDescription as one of the properties when setting NSFetchRequest.propertiesToFetch. In my case I am specifying a NSExpressionDescription to obtain the ObjectID of a set of records. An example is shown below
NSExpressionDescription* objectIDExpression = [NSExpressionDescription new];
objectIDExpression.name = @"objectID";
objectIDExpression.expression = [NSExpression expressionForEvaluatedObject];
objectIDExpression.expressionResultType = NSObjectIDAttributeType;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = self.entity;
fetchRequest.resultType = NSDictionaryResultType;
fetchRequest.propertiesToFetch = [self.attributes arrayByAddingObject:objectIDExpression];
The current implementation of EncryptedStore does not currently support NSExpressionDescription for fetched properties so I have tried to implement it myself to solve my own specialized needs.
However advice would be appreciated in regard so what is the best and correct way to implement this within the project.
The hacked changes I have made to EncryptedStore are as follows.
in valueForProperty I have added the following else if logic
else if ([property isKindOfClass:[NSExpressionDescription class]]) {
NSExpressionDescription * expressionDescription = (NSExpressionDescription *)property;
if(expressionDescription.expressionResultType == NSObjectIDAttributeType){
NSNumber *number = @(sqlite3_column_int64(statement, index));
return [self newObjectIDForEntity:entity referenceObject:number];
}
}
in columnsClauseWithProperties i have added the following else if logic
else if ([prop isKindOfClass:[NSExpressionDescription class]]) {
NSExpressionDescription * expressionDescription = (NSExpressionDescription *)prop;
if(expressionDescription.expressionResultType == NSObjectIDAttributeType){
[columns addObject:@"__objectID"];
}
}
Obviously my hacked changes are specific to my ObjectID requests and will only work in my case so how can we make this work for everyone an have a framework for supporting other uses of NSExpressionDescription.
Will this work with icloud?
Hi,
App is crashing, when i am trying to delete the entity from the core data
The EncryptedCoreDataTests still have several errors that need addressed:
Right now I see:
EncryptedCoreDataTests.m: error: testCustomTransformer (EncryptedCoreDataTests) failed: 'Test object <float=72379128682929452842713677299712.000000, uint64=7162247752875012965' should be equal to 'Test object <float=3.141593, uint64=18446744073709551614' The two ECDTestObject instances should be equal
EncryptedCoreDataTests.m: error: testDefaultTransformer (EncryptedCoreDataTests) failed: '<62706c69 73743030 d4010203 0405080b 0c542474 6f705824 6f626a65 63747358 24766572 73696f6e 59246172 63686976 6572d106 0754726f 6f748001 a2090a55 246e756c 6c4b6563 64737562 54797065 73120001 86a05f10 0f4e534b 65796564 41726368 69766572 0811161f 2832353a 3c3f4551 56000000 00000001 01000000 00000000 0d000000 00000000 00000000 00000000 68>' should be equal to '(
EncryptedCoreDataTests.m: error: testMigration (EncryptedCoreDataTests) failed: "migrated" should be true. Failed to migrate to the new managed object model: Error Domain=NSCocoaErrorDomain Code=1570 "The operation couldn’t be completed. (Cocoa error 1570.)" UserInfo=0x1115c8b0 {NSValidationErrorObject=<NSManagedObject: 0x23782a0> (entity: Transaction; id: 0xc65bdb0 <x-coredata://106FCF63-3745-4B59-BD26-7CAC94A7DBBE/Transaction/p1> ; data: <fault>), NSValidationErrorKey=account, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1570.)}
error: testFetchObjectWithTemporaryID (EncryptedCoreDataTests) failed: Cannot retrieve referenceObject from an objectID that was not created by this store
This last error seems to be tied to the newly added unique column names. Not sure why it only appears on the migration testing, could pop up other places as well.
We are trying to use Encrypted Core Data in an existing app that uses [NSCompoundPredicate andPredicateWithSubpredicates:] to build a query with some date constrains. But every time one of this queries is executed, the app crashes with an EXC_BAD_ACCESS in objc_retain (inside objc_storeStrong).
Example:
// Create request
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entityDescription =
[NSEntityDescription entityForName:@"MyEntity"
inManagedObjectContext:context];
[request setEntity:entityDescription];
// Set array of predicates to the request
NSMutableArray *arrayOfPredicates = [[NSMutableArray alloc] init];
[arrayOfPredicates addObject:[NSPredicate predicateWithFormat:@"(attr1 = %@)", value1]];
[arrayOfPredicates addObject:[NSPredicate predicateWithFormat:@"(date >= %@)", startDate]];
NSPredicate * queryPredicate =
[NSCompoundPredicate andPredicateWithSubpredicates:
[[NSArray alloc] initWithArray:arrayOfPredicates]];
[request setPredicate:queryPredicate];
// Execute the request
NSError *error = nil;
NSArray *array = [context executeFetchRequest:request error:&error];
This code throws an EXC_BAD_ACCESS (code=1, address: 0xd0000010). When debugging, the generated SQL query looks like this:
SQL DEBUG:
SELECT MyEntity.ID FROM MyEntity JOIN (null) AS [399922965]
ON MyEntity.(null)_id = [399922965].ID
WHERE (attr1 = ? AND date <= ?);
Any ideas on how to fix/avoid this?
PS: Thanks for all this great work.
I'm using xcode 5, and I'm getting a whole bunch of linker errors. I added the libsqlite3.dylib, and that got rid of most of them. Is there another one I need to add? This is the error I'm getting now:
Undefined symbols for architecture armv7:
"_sqlite3_key", referenced from:
-[EncryptedStore configureDatabasePassphrase] in EncryptedStore.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have found a problem where if you use {fieldname}.length predicate and the query joins another table with a field with the same name sqllite will report ambiguous field errors.
A possible fix to this problem could be the following:
// Test if the last component is actually a predicate
// TODO: Conflict if the model has an attribute named length?
if ([lastComponent isEqualToString:@"length"]){
// We terminate when there is one item left since that is the field of interest
for (int i = 0 ; i < pathComponents.count - 1; i++) {
NSRelationshipDescription *rel = [[entity relationshipsByName]
objectForKey:[pathComponents objectAtIndex:i]];
if(rel != nil) {
// TODO: This should probably be objectAtIndex:i, need to retest now that changed
NSString* asComponent = [NSString stringWithFormat:@"[%@]", [pathComponents objectAtIndex:i]];
[pathComponents replaceObjectAtIndex:0 withObject:asComponent];
}
}
// Add the entity name to the path so that we do not
// get ambiguous field name issues
[pathComponents insertObject:[self tableNameForEntity:entity] atIndex:0];
value = [NSString stringWithFormat:@"LENGTH(%@)", [[pathComponents subarrayWithRange:NSMakeRange(0, pathComponents.count - 1)] componentsJoinedByString:@"."]];
foundPredicate = YES;
}
Hello all,
I using MagicalRecord for my project.
The first, it work very good: insert, delete, fetch. But when i update attribute of entity, it was saved in "saveWithBlockAndWait", and fetch this entity is all attribute is nil.
Ex: Entity E has attribute: A=a, B=b. IF update A=aa and saved, then fetch E return: A=aa, B=nil
Then restart app, all attribute have value.
where is error? Thanks for hepl.
Hello,
After performing the following project setup step:
"Navigate to encrypted-core-data, highlight Incremental Store, and click Add"
I get the following Build Failed error:
ld: warning: ignoring file /Users/myUserID/Library/Developer/Xcode/DerivedData/Test-hhxbihbzilfrzqfblxjtppdxqwvl/Build/Products/Debug-iphonesimulator/libsqlcipher.a, file was built for archive which is not the architecture being linked (i386): /Users/hkbc02/Library/Developer/Xcode/DerivedData/Test-hhxbihbzilfrzqfblxjtppdxqwvl/Build/Products/Debug-iphonesimulator/libsqlcipher.a
Undefined symbols for architecture i386:
"_sqlite3_key", referenced from:
-[EncryptedStore configureDatabasePassphrase] in EncryptedStore.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any ideas what's causing this?
I'm using:
Xcode 5.0.1
OSX 10.9
Building for iOS7
If there is enough interest may try to add the ability to automatically convert core-data into encrypted-core-data. Right now this is a manual process for applications that are already using core-data. This effects any preset data they want to load, and ability to migrate customers to versions of their app that use iMAS security controls.
I'm trying to incorporate encrypted-core-data in my project for an encrypted sqlite DB. I've followed the setup steps and can see it can successfully login with the key. The difference between using "core data and a non-encrypted sqlite db" and "encrypted-core-data and an encrypted sqlite db", is that I'm getting 0 rows returned for the later (1066 rows for the former). I turned on the sqlite debugging
-com.apple.CoreData.SQLDebug 1
and notice the following difference in SQL statements:
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZENADDRESS FROM ZPROFILE t0
CoreData: annotation: sql connection fetch time: 0.0255s
CoreData: annotation: total fetch execution time: 0.0279s for 1066 rows.
fetch count: 1066
SQL DEBUG: SELECT Profile.ID FROM Profile ;
fetch count: 0
Any ideas what I'm doing wrong?
I'm probably not understanding how the select queries work for this lib, but it seems like creating a NSFetchRequest on a child entity that has a where clause for a property in an abstract parent object returns all child entities of the parent object that match the where clause without limiting to the specific child entity I created the fetch request for.
Here is the data model:
BaseObj
property id: int
ChildOne: BaseObj
property name: string
ChildTwo: BaseObj
property phone: string
A fetch request created with [NSFetchRequest fetchRequestWithEntityName:ChildOne]; and a predicate of "id == 5" appears to return all objects of ChildOne and ChildTwo that have id == 5, not just ChildOne objects.
From my limited understanding of the code it looks like both ChildOne and ChildTwo are all in the same table, so it kind of makes sense that the query would return both ChildOne and ChildTwo objects, however using built in CoreData, the fetch request used to be limited to just the entity I wanted to fetch.
I did a few queries and I don't see any indexes. I've written my own basic method to perform queries and ran the following
NSLog(@"Table Columns: %@",[enc performQuery:@"PRAGMA table_info(TableName);"]);
I got the following output (col 42 is one that I know has a index and STRING type) .....
id title type null? default index?
( 0, id, integer, 0, "<null>", 1 ),
( 1, "_entityType", integer, 0, "<null>", 0 ),
....
( 42, uuid, "", 0, "<null>", 0 ),
It looks like neither indexes nor data types are correctly set.
The following query returns an empty result (although I don't know if this is a failure of my method as I'd expect row 0 from above to be returned
PRAGMA index_list(TableName);
Currently only a limited subset of migrations are available
I put together a test case that demonstrates trying to fetch using a predicate that references another managed object. If the store type is EncryptedStoreType
, the fetch fails with this error:
Error Domain=NSSQLiteErrorDomain Code=1 "The operation couldn’t be completed. (NSSQLiteErrorDomain error 1.)" UserInfo=0x2c2d8a0 {EncryptedStoreErrorMessage=near "<": syntax error}
The test code uses a managed object has a temporary ID, but it fails in the same way if the object has a permanent ID.
The test behaves correctly if the store type is NSSQLiteStoreType
.
I can't be sure if this is a SQLCipher or encrypted store issue, but I don't see it when encryption is turned off so I can rule out SQLite, Core Data and Magical Records.
For various reasons I need to save images to the encrypted database ranging in size (I do my best to keep them as small as possible).
At a certain point the database becomes entirely unusable. Import/fetch requests begin to take many seconds and my entire app begins to pause for multiple seconds when moving between screens.
I have the following observations:
i) I can use my app for weeks at a time and see no slow down but after importing a certain number of pictures it'll begin to freeze again
ii) I can delete the database, reimport the non-BLOB data and the app works fine again
iii)The slow down occurs after less BLOBs saved if there are initially more non-BLOB records in the database
I can't tell if the slow down occurs once the database reaches a certain size or if it occurs when saving a random BLOB (i.e. the save corrupts the file in some way). Based on (iii) above I'd predict the former.
I realise this is a bit of a vague point, but I was interested if anyone else has experienced a similar issue or alternatively is able to import massive BLOBs without issue (and has any tips)
When using predicate with @"date = %@", the query built is "date = 2014-02-18 11:08:36 +0000" which leads to incorrect result.
Using the following NSPredicate code is failing when encrypted core data is used , but works fine when normal core data is used
@"sessionJobStatus == '%@' OR sessionJobStatus == '%@' OR sessionJobStatus == '%@'"
for example " sessionJobStatus == "2004" OR sessionJobStatus == "2002" OR sessionJobStatus == "2001"
Looks like predicate parsing function "- (NSDictionary *)whereClauseWithFetchRequest:(NSFetchRequest *)request" is not proper
The result of whereClauseWithFetchRequest is as follows
(sessionJobStatus = ? OR sessionJobStatus = ? OR sessionJobStatus = ?)
Regards,
Vijayan
in bindProperty:withValue:forKey:toStatement:atIndex:(int)index when the value is an NSFaultingMutableSet and the property is a NSRelationshipDescription the code crashes because NSFaultingMutableSet has no method objectId
This is on a Many to Many relationship.
(copied from here as is the best description of the same error I'm having):
I'm guessing that you want a 1-1 relationship over there not 1 - N.
How can I fix this?
Hi guys,
I'm trying to create an index on a column of my encrypted, encrypted-core-data, sqlite database from the command line after logging in through sqlcipher:
$ sqlcipher
SQLCipher version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
sqlite> CREATE INDEX aColumn_index ON MYTABLE (aColumn);
Error: no such table: main.MYTABLE
sqlite> CREATE INDEX aColumn_index ON meta.MYTABLE (aColumn);
Error: near ".": syntax error
I can retrieve data from the database without a problem
sqlite> SELECT COUNT(*) FROM MYTABLE;
2000
Any newbie mistakes you can see?
In many cases deleting requests only deletes the parent and not the related children. For example if you have a User with many Posts, and delete the user the corresponding posts are not necessarily deleted.
Problems when using SortDescriptors for more then ascending and descending sorting:
NSFetchRequest * request = [[NSFetchRequest alloc] init];
NSEntityDescription* descr = [NSEntityDescription entityForName:@"Products" inManagedObjectContext:[[ModelObjectsManager sharedInstance] managedObjectsContext]];
NSSortDescriptor* sort_manu = [NSSortDescriptor sortDescriptorWithKey:@"sort_manu_name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
NSSortDescriptor* sort_products = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
[request setEntity:descr];
[request setSortDescriptors:[NSArray arrayWithObjects:sort_manu,sort_products,nil]];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.