• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why doesn't this work on my device?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why doesn't this work on my device?


  • Subject: Re: Why doesn't this work on my device?
  • From: James Cicenia <email@hidden>
  • Date: Fri, 27 Feb 2009 10:44:37 -0600

Thanks for your patience. I did in fact use portions of sqlite books and have the following code:

// Creates a writable copy of the bundled default database in the application Documents directory.
- (void)createEditableCopyOfDatabaseIfNeeded {
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"whatsfresh.sql"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"whatsfresh.sql"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}


when I debug it, it achieves success so it does exist.
Someone wrote:

if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)

Don't use UTF8String to get a C string for a file system path, you should use -fileSystemRepresentation.


I don't even know what that is?

Thanks
James



On Feb 27, 2009, at 10:35 AM, Bill Bumgarner wr, ote:

On Feb 27, 2009, at 7:56 AM, James Cicenia wrote:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"whatsfresh.sql"];

int cntv = 0;
int cntf = 0;

ProduceItem *item=nil;
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = "SELECT type, subtype, name, id FROM ProduceItem ORDER BY name";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {


It does get to the second If statement so it did find the database. But then evidently it is not SQLITE_OK on my device in regards to that last if.

Have you checked to see if the file at path actually exists?

The documentation for sqlite3_open() indicates that it will quite happily create a band new empty database if one doesn't exist at the path.

Have a look at the SQLite Book List example (http://developer.apple.com/iphone/library/samplecode/SQLiteBooks/listing4.html ) as it demonstrates testing for the database file and then copying it into the writable location, as necessary.

b.bum



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Why doesn't this work on my device?
      • From: Bill Bumgarner <email@hidden>
References: 
 >Why doesn't this work on my device? (From: James Cicenia <email@hidden>)
 >Re: Why doesn't this work on my device? (From: Jason Foreman <email@hidden>)
 >Re: Why doesn't this work on my device? (From: James Cicenia <email@hidden>)
 >Re: Why doesn't this work on my device? (From: Bill Bumgarner <email@hidden>)
 >Re: Why doesn't this work on my device? (From: James Cicenia <email@hidden>)
 >Re: Why doesn't this work on my device? (From: Bill Bumgarner <email@hidden>)
 >Re: Why doesn't this work on my device? (From: James Cicenia <email@hidden>)
 >Re: Why doesn't this work on my device? (From: Bill Bumgarner <email@hidden>)
 >Re: Why doesn't this work on my device? (From: James Cicenia <email@hidden>)
 >Re: Why doesn't this work on my device? (From: Michael Ash <email@hidden>)
 >Re: Why doesn't this work on my device? (From: James Cicenia <email@hidden>)
 >Re: Why doesn't this work on my device? (From: Bill Bumgarner <email@hidden>)
 >Re: Why doesn't this work on my device? (From: James Cicenia <email@hidden>)
 >Re: Why doesn't this work on my device? (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: Why doesn't this work on my device?
  • Next by Date: Negative zero and NSNumberFormatter
  • Previous by thread: Re: Why doesn't this work on my device?
  • Next by thread: Re: Why doesn't this work on my device?
  • Index(es):
    • Date
    • Thread