开发者

Iphone Sqlite problem

开发者 https://www.devze.com 2023-03-10 00:24 出处:网络
I have to make a project using sqlite, i would rather use simple plists, xml or even core data as i don\'t have any experience with sql. However it has to be able to read from sqlite database. I downl

I have to make a project using sqlite, i would rather use simple plists, xml or even core data as i don't have any experience with sql. However it has to be able to read from sqlite database. I downloaded the FMDB wrapper and set it up quickly however when i try and read from my database it does not display in the tableview, Here is my code:

TermsArray = [[NSMutableArray alloc] init];

NSString *path  = [[NSBundle mainBundle] pathForResource:@"Database" ofType:@"sql"];
FMDatabase *db  = 开发者_如何学Python[[FMDatabase alloc] initWithPath:path];
[db open];

FMResultSet *fResult= [db executeQuery:@"SELECT * FROM country WHERE id=1"];

while([fResult next])
{

    CountryString = [fResult stringForColumn:@"name"];

    [CountryArray addObject:CountryString];

    NSLog(@"The data is %@=",CountryString);
}
[db close];
  }

and i display it in my tableview using this:

NSString *Text = [CountryArray objectAtIndex:indexPath.row];
cell.textLabel.text = Text;

Now i don't get any errors, however the array is always empty, in the console i don't get any warnings etc either but i noticed that the NSLOG never shows up, so i don't think that part is working. Heres my sql file in a text editor:

 CREATE TABLE country ( id INTEGER PRIMARY KEY, name VARCHAR(250),location TEXT,number INTERGER);
  INSERT INTO country (name,location,number) VALUES('UK','country location here',1);

Also how are sqlite files supposed to be like? I created one using a sqlite editor and it produced a sql file, when i open it in a text editor i just see sql statements?

It would be really great it someone could help me with this,

Thanks!


just copy the sql statements and run it in the sql console after that u have to backup the database using .backup


I have fixed it, It was a problem with my sql file, it now works great! Thanks for all your comments!

0

精彩评论

暂无评论...
验证码 换一张
取 消