Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-09-2009, 04:55 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Germany
Age: 27
Posts: 246
hosam is on a distinguished road
Default could not prepare statemnt: no such table: test "SQLITE"

Hello,

I have a very very weird problem with SQLITE today. I have a database with the name "hosam.sqlite" and it have one table called test.

- From the command line I insert a new row in the test table

- In Resources I added the file and checked copy to project if needed


Now when I issue a select command on the database, I get an error that the table doesn't exist in my database!.

I made clean all targets and rebuilt but still the same problem that for some reason the path to the database is wrong so the phone makes its own database

Any ideas or hints?

thanks,

Hosam
hosam is offline   Reply With Quote
Old 01-09-2009, 07:44 PM   #2 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 18
jmac1074 is on a distinguished road
Default

how do you get the path to the database?

This is the easiest way:

Code:
[[NSBundle mainBundle]pathForResource:@"hosam"extension:@"sqlite"];
Jmac
jmac1074 is offline   Reply With Quote
Old 01-09-2009, 07:57 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Germany
Age: 27
Posts: 246
hosam is on a distinguished road
Default

Thanks a lot for your reply but now I get an exception


*** -[NSBundle pathForResource:extension:]: unrecognized selector sent to instance 0x50b1d0
2009-01-10 02:53:12.557 [37340:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSBundle pathForResource:extension:]: unrecognized selector sent to instance 0x50b1d0'


The way I was doing it before was like that


Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
 /NSString *path = [documentsDirectory stringByAppendingPathComponent:@"hosam.sqlite"];
and the call to open the database is
Code:
   if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {

hosam.sqlite is inside the resources folder as well as in the project folder
hosam is offline   Reply With Quote
Old 01-09-2009, 10:33 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 18
jmac1074 is on a distinguished road
Default

sorry, i totally spaced. I spelled the method wrong.

Its actually:

Code:
[[NSBundle mainBundle]pathForResource:@"hosam"ofType:@"sqlite"];
that will work. the problem is that right now you are looking for it in the documents directory which is not the same thing as the project directory/bundle.

Jmac
jmac1074 is offline   Reply With Quote
Old 01-10-2009, 08:45 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Germany
Age: 27
Posts: 246
hosam is on a distinguished road
Default

Many thanks it works now
hosam is offline   Reply With Quote
Old 04-25-2009, 01:50 AM   #6 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 8
NewToMacAndIphone is on a distinguished road
Default How do you package/add existing document to the "Documents" directory on the device?

Thank. This is helpful and resolved my problem.

I was running into the same issue and was suspecting that my sqlitedb file is not getting copied to the "Documents" directory on the device. For the same reason I didn't add it to the resource bundle.

Q1: How do you copy existing document to the "<HOME>/Documents" folder on the device? Or is it only for the documents that get created by the app on the device?

Q2: Is it recommended to have sqldb as part of the resource bundle assuming it will grow over a period of time?
NewToMacAndIphone is offline   Reply With Quote
Old 04-21-2010, 05:27 AM   #7 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 7
int3rc3pt0r is on a distinguished road
Default

Quote:
Originally Posted by jmac1074 View Post
sorry, i totally spaced. I spelled the method wrong.

Its actually:

Code:
[[NSBundle mainBundle]pathForResource:@"hosam"ofType:@"sqlite"];
that will work. the problem is that right now you are looking for it in the documents directory which is not the same thing as the project directory/bundle.

Jmac
Hey this code worked for me thanks ...
I am using a Wrapper from : Objective-C: SQLite Wrapper : Th30z – Coding on the Fly

will this cause any issue ahead ???
int3rc3pt0r is offline   Reply With Quote
Old 01-09-2012, 09:03 AM   #8 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 1
Aspgod is on a distinguished road
Default

Quote:
Originally Posted by jmac1074 View Post
sorry, i totally spaced. I spelled the method wrong.

Its actually:

Code:
[[NSBundle mainBundle]pathForResource:@"hosam"ofType:@"sqlite"];
that will work. the problem is that right now you are looking for it in the documents directory which is not the same thing as the project directory/bundle.

Jmac
It works !!. Thank you very much.
Aspgod is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 411
9 members and 402 guests
apatsufas, Eclectic, JackReidy, jeroenkeij, Sami Gh, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:59 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0