Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fritzables

macrumors regular
Original poster
May 6, 2011
149
1
Brisbane AUSTRALIA
Hi All,

I was hoping I could create/open a SQLite database using the file path in a NSString, but it appears this is illegal.

Code:
rc = sqlite3_open(fullPath,&db);

Does this mean I have to convert the NSString to a char?
If so, how is this best achieved?

Pete
 
The sqlite API is in pure C, so yes you will need to use char* instead of NSString. There are a bunch of methods in NSString that will give you a C string. Look at the documentation.
 
Thanks Guys,

Got it worked out.... thanks for the assistance.

Something weird happening though.... I am not a full bottle on Unix as yet but progressing slowly.

What I have asked the app do after it loads is to create a database in the current directory, for example: /users/Fritzables/Development/Projects/

When I run the app within XCode by using the Build and Run the database is created where I have asked it to, but, if I was to run the app directly from the Debug directory the database ends up in the root "/".

Why does it do this?

Pete
 
When I run the app within XCode by using the Build and Run the database is created where I have asked it to, but, if I was to run the app directly from the Debug directory the database ends up in the root "/".

Why does it do this?

Finder (or more specifically Launch Services) does not set the current working directory. The concept of the current working directory is not a useful one under Mac OS X, unless you change the working directory in your code.
 
G'Day Jim,

I have created a variable that I place the applications current directory - well I thought so - but it ain't working.

So, if I wanted to keep the database with the app regardless of where the app is placed - what are the options??

Pete
 
G'Day Jim,

I have created a variable that I place the applications current directory - well I thought so - but it ain't working.

So, if I wanted to keep the database with the app regardless of where the app is placed - what are the options??

Pete

Look at NSBundle. Your app (the .app directory containing your executable, etc.) is the main bundle.

You want to use - pathForResource:ofType:inDirectory:. Note is this is the object method and not the class method. You don't want to use the class method.
 
So, if I wanted to keep the database with the app regardless of where the app is placed - what are the options??

You can't necessarily create a database with the app. Open, yes. Create, not necessarily.

That's because the permissions of an installed app may forbid writing by the current user.

If you're now thinking about allowing writing for all, don't. Public-write presents a security risk. It means any user can modify an app, altering it in ways that other users may find hostile.

Read the reference docs for NSBundle, and its Companion guide docs, and learn about the directories where Mac OS X wants you to put app-specific things, user-specific things, etc.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.