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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 10-01-2008, 03:12 PM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default SQLite Problems: Simulator copy + first value of every query is mumbo-jumbo

Hi,

I saved constant values into a table of a SQLite3 database. I've done this via Terminal. Then I filled the table with some values. The database is set up all right: Queries in Terminal and in DB inspectors like 'SELECT * FROM myTable' return all values and they are all right.
I added the database file into my XCode project.
Now I've got two problems:


The first one: When I click on 'Build & Go' the database file isn't copied correctly into the iPhone simulator directory. sqlite3_prepare_v2() returns ERROR 1 and opening the database file manually gets me an error too.
If I copy the original database file from the project directory into the simulator's application directory then sqlite3_prepare_v2() works.
Unlike Apple's SQLBook example, my code doesn't make a copy of the DB explicitly as I don't need an editable copy of it. I just want to read values out of it.

Is this a bug or a...



My second problem: When I drop off queries like 'SELECT name FROM Constants' in Terminal, I get all the values and all are correct (like mentioned above).
But when I do this in my code:
Code:
CONNECTION EXISTS...

const char *sql = "SELECT name FROM Constants";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
  // We "step" through the results - once for each row.
  while (sqlite3_step(statement) == SQLITE_ROW) {
    // The second parameter indicates the column index into the result set.
    char *name = (char*)sqlite3_column_text(statement, 0);
  }
}
The first result is ALWAYS:
Code:
[\x8bU\x10\x8d\x83`
The following names are all correct but the first one is a mess. I've already created a brand new database file with a new table and other values. Same errornous value.


Has someone experienced a similar problem one day and found the solution to this?
Norbert is offline   Reply With Quote
Old 10-01-2008, 03:25 PM   #2 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Does your database file that's being copied by Xcode have a file extension? You should look at the build transcript and see how Xcode is copying it. In the build window there are several little icons on the left side in the middle. Click on the one that looks like a page of text. It's possible that Xcode thinks it's some other kind of file than it really is and is processing it somehow when it copies it.
PhoneyDeveloper is offline   Reply With Quote
Old 10-01-2008, 03:42 PM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
Does your database file that's being copied by Xcode have a file extension? You should look at the build transcript and see how Xcode is copying it. In the build window there are several little icons on the left side in the middle. Click on the one that looks like a page of text. It's possible that Xcode thinks it's some other kind of file than it really is and is processing it somehow when it copies it.
Hm, don't know what icons you mean. In my build window are "Building target..." and "Checking dependencies" and "Build succeeded", nothing else.
I tried both .db and .sql as file extensions and there was no difference.
Norbert is offline   Reply With Quote
Old 10-01-2008, 11:11 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

These icons. Click on the third one from the left.

Last edited by PhoneyDeveloper; 11-18-2008 at 07:32 PM.
PhoneyDeveloper is offline   Reply With Quote
Old 10-02-2008, 06:49 AM   #5 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

Thank you for posting this image

I found out that I was a little lazy when reading Apple's example: I didn't open the bundled DB but the one in the application folder. Because I haven't copied it in there first it gave me an error when trying to open it. I didn't realize my fault because it created the file in the Documents directory because it was not there. And I thought that creating a temporary copy is standard behaviour.
So this solves my first problem.

But the second one is still occuring. Any thoughts?

Last edited by Norbert; 10-02-2008 at 09:26 AM.
Norbert is offline   Reply With Quote
Reply

Bookmarks

Tags
copy, first value, sqlite, sqlite3

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: 278
24 members and 254 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, fkmtc, HDshot, HemiMG, iDifferent, jakerocheleau, JasonR, jimbo, macquitzon216, mer10, NSeven, prchn4christ, Rudy, sacha1996, silverwiz, sneaky, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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