Page 1 of 1

SQLITE File is not opened by compiled app

Posted: Thu May 31, 2012 7:11 pm
by fsw
Some strange things are going on on OSX:
I have an app that is used for quite awhile now on Win7 and it utilizes a sqlite database file.

Trying to make the app run on OSX and when I run it from the IDE it works but when the app is compiled the sqlite file is not found (resides in the same directory).

Went to the example directory and compiled the database example. It writes an sqlite file and opens it... it works.

One difference I saw is that Finder tells me that the newly generated sqlite file (from the example) is a "document" while the sqlite file that came from a Win7 machine (from my app) is a "unix executable file".

Changing the file attributes with chmod doesn't help; also when I list the files with ls -l the file has a @ right after the file attributes. (which tells me that the file has extended file attributes)


On the net I found some info were they talk about moving files from Windows to OSX can cause the wrong file type thingy, but in reality I don't know if this is actually causing the compiled app not to find the sqlite file.

As I said running the app from the IDE the sqlite file is found...

I also tried to add a "./" like it might be needed on Linux or to use the GetCurrentDirectory() function but the resulting directory seems to link inside the app bundle...

Maybe the error is that the compiled file automatically gets the ".app" extension but I don't know if it actually is an app bundle or not.
(IncludeBinary is used to insert an image file into the executable)

Maybe deleting the extension will solve the problem; I don't know - still learning while going....

I'm thankful for any help.

Thanks for reading
fsw

Re: SQLITE File is not opened by compiled app

Posted: Thu May 31, 2012 7:38 pm
by fsw
Found more information on the net about app bundles.

Maybe because there is an image inside the executable it automatically becomes an app bundle.
So if the GetCurrentDirectory() function returns:

Applications/myprog.app/Contents/MacOS/

most probably the executable looks inside the bundle for the file.

If this is true, the file I'm looking for should be loaded with:

Applications/myprog.app/Contents/MacOS/../../../mydata.sqlite


Hmm, will try this as soon as I can... and report back.

bye

Re: SQLITE File is not opened by compiled app

Posted: Thu May 31, 2012 7:49 pm
by gekkonier
An App Bundle is basically a Directory. So, if you put that sql file beside the app Directory which is always a bad idea, you have to alter the path (make it relative to the binary in your app bundle).
Normally you put such files into /Users/yourusername/Library/Application Support/Yourbeautifulapp (read about correct usage of this in mountain lion aswell, it will change little), or if they database is unmutable into the Contents/Resources Folder.
Basically, if you press "compile" an binary will be created (not an app bundle!). But if you build the executable an app bundle (directory structure with the binary in it) will be created.

So, there is nothing wrong ;)

Re: SQLITE File is not opened by compiled app

Posted: Thu May 31, 2012 8:04 pm
by fsw
Thank you for the valuable information, it's truly appreciated.
It's my second week with a Mac and I'm glad I have this forum as a backup when I'm stuck.
When I get home I will try this:

Applications/myprog.app/Contents/MacOS/../../../mydata.sqlite

In the end, there is nothing wrong with OSX - it's just me not knowing what needs to be done.

Thanks again.

Note: Need to read more about OSX file structure...

Re: SQLITE File is not opened by compiled app

Posted: Fri Jun 01, 2012 6:51 am
by gekkonier
Think about what would happen if the user starts the app from another directory than /Applications ;)

Re: SQLITE File is not opened by compiled app

Posted: Fri Jun 01, 2012 7:20 pm
by fsw
gekkonier wrote:Think about what would happen if the user starts the app from another directory than /Applications ;)
Understood.

For now this works: GetCurrentDirectory + "../../mydata.sqlite"
But you are right, if someone starts the app from a different directory it does not work anymore.
(because the current directory changed)
ProgramFilename() is a better choice: ProgramFilename() + "/../mydata.sqlite"
Will try this out next...

Thanks

Re: SQLITE File is not opened by compiled app

Posted: Sat Jun 02, 2012 3:53 am
by fsw
The only way to make it work is:
GetPathPart(ProgramFilename()) + "../../../" + #DatabaseFile$
If:
ProgramFilename() + "/../../../../" + #DatabaseFile$
is used (without GetPathPart) it doesn't work...