Note that there are some explanatory texts on larger screens.

plurals
  1. PODB Wrapper Not Responding to Message?
    primarykey
    data
    text
    <p>I'm developing for iphone-sdk 2.2.1 (so no CoreData <em>cry</em>). </p> <p>So I'm using the <a href="http://code.google.com/p/flycode/source/browse/trunk/fmdb/src/FMDatabase.h" rel="nofollow noreferrer">FMDatabase project</a>, which is just a SQLite Wrapper in Obj C. I have my DB working well when interacting with it from my AppDelegate. I've tested connecting, INSERTING, etc from the AppDelegate. </p> <p>Now, I have a data object that I want to store into the Database. I would like this event to occur from a ViewController class. Lets see some code:</p> <p>App Delegate Creates the DB in the applicationDidFinishLaunching method. The DB is declared as a property of this class so I can easily access it.</p> <pre><code>db = [FMDatabase databaseWithPath:[self getDBPath]]; </code></pre> <p>This works fine, I have tested it. The only thing I'm a little concerned about is 'db' being a property of the class. That shouldn't cause problems, should it?</p> <p>From the same applicationDidFinishLaunching method, I've tested that a simple insert works using. This Works:</p> <pre><code>[db beginTransaction]; [db executeUpdate:@"INSERT INTO tblDataSamples (...) VALUES (...);"]; [db commit]; </code></pre> <p>Now, if I simply take this exact code and move it to an instance method of the AppDelegate, the code no longer works. I get a <code>"EXC_BAD_ACCESS"</code> error when we hit the [db beginTransaction] line.</p> <p>The flow of this code to this call: - AltViewController Receives a button tap Event - AltViewController tells ApplicationDelegate to execute the "addSample" method. - ApplicationDelegate's addSample method fails on [db beginTransaction].</p> <p>Now that I've written this out, I am thinking the problem is that my DB gets lost after the ApplicationDelegate loads the RootView. Maybe I'm wrong though. Anyone have any ideas?</p> <p>!!!!!!!!!</p> <p><strong>UPDATE!</strong> <em>I just altered my addSample method to include</em> </p> <pre><code>db = [FMDatabase databaseWithPath:[self getDBPath]]; if (![db open]) { NSLog(@"Could not open db."); } </code></pre> <p>and</p> <pre><code>[db close]; </code></pre> <p>The entire transaction works now. So, the new question is: how do I make the database open ONCE and stay open across different views and viewControllers?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload