0

I write one application A written in objective-c which use my another framework B which is also written in objective-c. The framework B has some database related operations. To perform those operations I try to use DBAccess ORM (http://www.db-access.org/).

  1. In B I have created a model class which base class is DBObject.

    @interface SettingsModel : DBObject

  2. AppDelegate of application A delegates the DBDelegate protocol, in "-(BOOL) application: didFinishLaunchingWithOptions:" sets the delegate "[DBAccess setDelegate:self];"
  3. There is a class EnvironmentManager in B, which sets the database name in its init method. [DBAccess openDatabaseNamed:@"dbname"];
  4. An object of EnvironmentManager is created from A's ViewController's viewDidLoad method.
  5. Now I try to save and retrieve data from A's viewController methods.

When I run the application A with both save and retrieve methods opened, retrieve method give me the saved data. But if I comment the save data section and run A then no previous data can be retrieved.

  1. Is it possible to use DBAccess framework from another framework?
  2. If possible then Please help me to figure-out the problem from my above description.

EDIT:

I have tried some others options, which is discussed @Adrian_H answers comment section. I have got the same path in both A and B using

NSURL *applicationCachesDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];
NSLog(@"%@",[applicationCachesDirectory path]);
iOS-Developer84
  • 654
  • 8
  • 19

2 Answers2

0

It sounds like the path to the database is unknown, do you know if the Database file is getting created at all?

If it is not getting created, then you will need to implement the DBSettings method to explicitly state the path to where the DB file will be kept. (see DBAccess creating custom DBAccessSettings).

This is classic behaviour when the :memory: database is being used, due to an invalid path.

It could also be that in some way, something is initialising the DBObject classes before your -(BOOL) application: didFinishLaunchingWithOptions: method is being run, so your could always try closing the database first and then re-opening it. If this turns out to be the problem, I can produce a fix and release a new version of the framework as that is not expected behaviour.

Community
  • 1
  • 1
Adrian_H
  • 1,548
  • 1
  • 14
  • 27
  • Thanks a lot for your help. – iOS-Developer84 Jan 25 '16 at 12:26
  • But the **B** framework's model (DBObject) is not initialized. I have set the custom setting in **A**'s delegate by implementing `- (DBAccessSettings*)getCustomSettings` method. I also implement the `-(void) databaseOpened` method, though database name or any other settings is only used by framework **B**. I have created a new model class for test in **A** and call the same save and retrieve method for this new model. It works only for the new model. -(void) databaseOpened method only called when the new model's (**A**'s) query/fetch method is called. – iOS-Developer84 Jan 25 '16 at 12:53
  • Doe sthe database file get created? What objects does it have within it? – Adrian_H Jan 25 '16 at 13:40
  • The database file get created only when I add the new model in **A** and call the save method. There are three files with extensions db, wal and shm. If I open the shm file there is only information about the model of **A**. But no information of framework **B** model. – iOS-Developer84 Jan 25 '16 at 15:56
  • Okay, it sounds like a Framework within a framework does not have any access to the application path. It's not something that has been tested. You might be able to get around it by: 1) Set delegate first, then closeDatabase:nil, then openDatabase: again. This, should then ask for the DBSettings object, if you have put a database folder/location in the settings class, then it should create it there. Check by setting it somewhere different. – Adrian_H Jan 25 '16 at 16:00
0

The problem is that, DBAccess framework is initiated twice. One is initiated in your own framework, and the other is initiated in your application. To solve this problem:

  1. Select project > Build Settings > Open Linker flags
  2. Remove DBAccess framework from it. Also remove $(inherited).
  3. Save, clean and run
farhad rubel
  • 2,334
  • 2
  • 22
  • 29