vendredi 27 mars 2015

Getting results from sqlite table

I implemented SQLite into my xocode project with this tutorial. I have 3 tables. 2 tables are linked to the 1st table with a 1 to many relationship.


When I try accessing values from the main table, it works as its supposed to. The problem is when I try accessing values from the tables that are linked to the main table. When I try accessing there results, I don't get anything.



NSString *query = [NSString stringWithFormat:@"select * from personalInfo where id=%d", 1];
NSString *ingredients = [NSString stringWithFormat:@"select * from homePhone where personalInfoID=%d", 1];

NSArray *results = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
NSArray *infoResults = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:ingredients]];

NSLog(@"%@ and %@", results, infoResults); // results gives me the correct info.
// But infoResults doesn't give me anything.


When I change



select * from homePhone where personalInfoID=%d", 1


to:



select * from homePhone where id=%d", 1


it gives me the correct results. Not sure what is going on.


Here is the SQLite table.



CREATE TABLE personalInfo (
id integer PRIMARY KEY,
name text,
image text,
info1 text,
info2 text,
info3 text,
);

CREATE TABLE homePhone (
id integer PRIMARY KEY,
phone1 text,
personalInfoID integer references personalInfo(id)
);

CREATE TABLE address (
id integer PRIMARY KEY,
address1 text,
address2 text,
address3 text,
personalInfoID integer references personalInfo(id)
);


If you need more info, please let me know in comments below. Thanks!


Aucun commentaire:

Enregistrer un commentaire