Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring objects in an Array
    primarykey
    data
    text
    <p>I'm working with a database, and trying to store the rows of a table as dictionary in an Array.</p> <pre><code>#import "RootViewController.h" #import "ProgettoAppDelegate.h" #import "AddItemViewController.h" #import "DetailViewController.h" #include &lt;sqlite3.h&gt; @implementation RootViewController @synthesize nibLoadedCell; @synthesize addItem; NSNumberFormatter *priceFormatter; NSDateFormatter *dateFormatter; NSMutableArray *shoppingListItems; &lt;--i created here... NSDictionary *editItem; -(void) loadDataFromDb { //apriamo il database sqlite3 *db; int dbrc; //Codice di ritorno del database (database return code) ProgettoAppDelegate *appDelegate = (ProgettoAppDelegate *) [UIApplication sharedApplication].delegate; const char *dbFilePathUTF8 = [appDelegate.dbFilePath UTF8String]; dbrc = sqlite3_open(dbFilePathUTF8, &amp;db); if (dbrc) { NSLog(@"Impossibile aprire il Database!"); return; } //database aperto! Prendiamo i valori dal database. sqlite3_stmt *dbps; //Istruzione di preparazione del database NSString *queryStatementNS = @"select key, item, price, groupid, dateadded from shoppinglist order by item"; const char *queryStatement = [queryStatementNS UTF8String]; dbrc = sqlite3_prepare_v2(db, queryStatement, -1, &amp;dbps, NULL); //Richiamo la funzione sqlite3_step() finché ho righe nel database while ((dbrc = sqlite3_step(dbps)) == SQLITE_ROW) { int primaryKeyValueI = sqlite3_column_int(dbps, 0); NSNumber *primaryKeyValue = [[NSNumber alloc] initWithInt:primaryKeyValueI]; NSString *itemValue = [[NSString alloc] initWithUTF8String:(char*) sqlite3_column_text(dbps, 1)]; double priceValueD = sqlite3_column_double(dbps, 2); NSNumber *priceValue = [[NSNumber alloc] initWithDouble:priceValueD]; int groupValueI = sqlite3_column_int(dbps, 3); NSNumber *groupValue = [[NSNumber alloc] initWithInt:groupValueI]; NSString *dateValueS = [[NSString alloc] initWithUTF8String:(char*) sqlite3_column_text(dbps, 4)]; NSDate *dateValue = [dateFormatter dateFromString: dateValueS]; NSMutableDictionary *rowDict = [[NSMutableDictionary alloc] initWithCapacity:5]; [rowDict setObject:primaryKeyValue forKey: ID_KEY]; [rowDict setObject:itemValue forKey: ITEM_KEY]; [rowDict setObject:priceValue forKey: PRICE_KEY]; [rowDict setObject:groupValue forKey: GROUP_ID_KEY]; [rowDict setObject:dateValue forKey: DATE_ADDED_KEY]; [shoppingListItems addObject: rowDict]; NSLog(@"%d", [shoppingListItems count]); //I have a Breakpoint here! //rilascio tutti gli elementi [dateValue release]; [primaryKeyValue release]; [itemValue release]; [priceValue release]; [groupValue release]; [rowDict release]; } } </code></pre> <p>using Breakpoint at the end of the procedure, i can see that in the variables there are the contents of the database, but array "shoppingListItems" is empty. (count = 0)</p> <p>If you are brave enough to take a look, here there is the entire project: <a href="http://cl.ly/9uvb" rel="nofollow">http://cl.ly/9uvb</a></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.
 

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