Page 1 of 2

standalone for Mac from Windows with Database

Posted: Thu Jun 26, 2014 7:12 pm
by fko
Hi,

I am developping in Windows and i am trying to create the standalone for MacOs...
And i have one problem with the database...There is one error to connect to the database from the application in MacOs...:-(

this is the path of my application (myApplication.Livecode) where i am developping: "C:/users/fko/Lc/TestApp"
And i have one database (myDatabase.sqlite) into the folder BBDD...So the complete path is the next one: "C:/users/fko/Lc/TestApp/BBDD/myDatabase.sqlite"

When i am making the standalone i am choosing the folder "TestApp" ( the complete path is: "C:/users/fko/Lc/TestApp") to create the versión for MacOs

The result is that i have one new folder ("myApplication") in "C:/users/fko/Lc/TestApp/"...So i have "C:/users/fko/Lc/TestApp/myApplication"
and inside this folder i have another one ("myApplication.app") ..."C:/users/fko/Lc/TestApp/myApplication/myApplication.app"

After one day trying things, i decide to write the path of the application in the script where i am conncecting to the database to control where is trying to open the database.

In the script of the database connection i have this:

put myPath & "/BBDD/myDatabase.sqlite" into tDatabasePath
answer tDatabasePath
put revOpenDatabase ("sqlite",tDatabasePath,,,,) into tDatabaseID

This is the result of the answer: "/mac/applications/myApplication/myApplication.app/Content/DDBB/myDatabase.sqlite"

And in the OpenCard Script i have this:

global myPath
"put the effective filename of this stack into myPath"
answer myPath....This is the result of the answer: "/mac/applications/myApplication/myApplication.app"

What is the problem? What am i doing wrong? For Windows is working well the path for the database...
Do i have to change my script of database connection?
As i am not putting in any place the folder "Content"...
It should be like this : "put myPath & "/Content/BBDD/myDatabase.sqlite" into tDatabasePath" in place of "put myPath & "/BBDD/myDatabase.sqlite" into tDatabasePath"?

Or there is another thing that i am not seeing or not taking in consideration to can pass from Windows to MacOs?

Regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Thu Jun 26, 2014 8:00 pm
by Simon
Hi fko,
If you put the db in the Copy Files tab in the standalone builder then the file will end up right next to the app.

Code: Select all

put revOpenDatabase("sqlite", myDatabase.sqlit, , , , ) into tDatabaseID
But maybe that is not what you are after?

Simon

Re: standalone for Mac from Windows with Database

Posted: Thu Jun 26, 2014 8:24 pm
by fko
Hi Simon,

I don't understand...:-(
what do you mean with this sentence? "But maybe that is not what you are after?"

And if i put directly "myDatabase.sqlite" in place of "/BBDD/myDatabase.sqlite" in the revOpenDatabase it will open it without knowing that this database is in another folder?

In the "standalone application setting" i marked the Database in the "Script libraries" and the Sqlite in the "Database Support" of the "Select Inclusions for the standalone application" option.
I don't know if this has one influence or not in 'my problem'...

regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Thu Jun 26, 2014 8:32 pm
by Simon
Hi fko,
what do you mean with this sentence? "But maybe that is not what you are after?"
Well if your user has to access the db not using your stack but some other method.
If not then you can use the below to copy the db and then it will be in the same folder as your app.
2014-06-26_1227.png
No need to look for it.
put revOpenDatabase("sqlite", myDatabase.sqlit, , , , ) into tDatabaseID
See no path.

Simon
Edit : oops forgot the quotes
put revOpenDatabase("sqlite", "myDatabase.sqlit", , , , ) into tDatabaseID

Re: standalone for Mac from Windows with Database

Posted: Thu Jun 26, 2014 8:45 pm
by fko
Hi Simon,

Thanks to clarify me the doubt...:-)

I will try like you said...

regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 10:24 am
by fko
Hi,

it is me again...:-(

I don't manage with this problem...
In fact what i could see that is happening to me too when i create the standalone for Windows too...


I added the file "myDatabase.sqlite" from the 'COPY FILES' and it didn't work...
And i also added the folder "BBDD"...Even if it is adding it empty and not with the file "myDatabase.sqlite" that was inside...So then i put it inside

So i tried with the file "myDatabase.sqlite" in the same folder as the stack and inside the folder "BBDD"

And putting this in the different ways:

1)
put myPath & "/BBDD/myDatabase.sqlite" into tDatabasePath
put revOpenDatabase ("sqlite",tDatabasePath,,,,) into tDatabaseID

2)
put myPath & "/myDatabase.sqlite" into tDatabasePath
put revOpenDatabase ("sqlite",tDatabasePath,,,,) into tDatabaseID

3)
put revOpenDatabase ("sqlite","myDatabase.sqlite",,,,) into tDatabaseID



Why it is working well from the developping path, but not when i create one standalone for Windows at least? The next step it will be for MacOS...
I thought for Windows at least it will work well directly...:-(

regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 11:40 am
by Klaus
Hi fko,

one important thing to consider:
Only users with ADMIN privileges are allowed to WRITE into the (default system) application folder!
And saving data into the database IS writing, so this may silently fail.

You need to copy the database file to a folder where EVERYONE has write permissions when the app starts the first time!


Best

Klaus

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 12:17 pm
by fko
Hi Klaus,

When i am developping is in one folder of my user (so the admin), but then i am trying the ".EXE" in the "E" partition of my disk...And here it is not inside any folder of my user...
So normally it should work, i think...

I am trying many things as i am not managing...But putting only "myDatabase.sqlite" in the revOpenDatabase it seems that it is not working...
Should i add one "/" before "myDatabase.sqlite"?

Now i added the file directly in the root folder (so with the "EXE" file, and not inside "BBDD" folder)

regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 12:34 pm
by Klaus
In a Mac standalone, this:
...
global myPath
put the effective filename of this stack into myPath
answer myPath
...
Should give:
/mac/applications/myApplication/myApplication.app/Contents/MacOS/myApplication"

Which is the original stack with the runtime engine wrapped around it.
So you should do this (if you have your subfolder "BBDD" etc. entered in the standalone builder settings for "Copy files"):
...
put the effective filename of this stack into myPath
## -> .../myApplication.app/Contents/MacOS/myApplication"

set itemdel to "/"
## remove filename of runtime/stack:
delete item -1 of myPath
## -> .../myApplication/myApplication.app/Contents/MacOS"

put "/BBDD/myDatabase.sqlite" AFTER myPath
## Now myPath will contain the correct path to your database file, this works on Mac and Windows!
## -> .../myApplication/myApplication.app/Contents/MacOS/BBDD/myDatabase.sqlite"
...


Best

Klaus

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 2:39 pm
by fko
Hi Klaus,

Hi put what you told me, but i don't manage...:-(

To be sure that was not one thing of permissions / profiles users i put the 'EXE' in the same folder i am developping (so where it is working well) and even like this is not working...

And in the same time i put the same code you put in your last post, and it didn't work...:-(

When i enter in the standalone settings and i try to add the folder BBDD, it is only adding the folder, but not what it contains...
It is written "BBDD/*", but then when i open the folder BBDD when the standalone is ready, there is nothing inside...This should be like this???

Anyway, as i see the folder is empty when the standalone is done, i am adding the database...But even like this, it is not working...


i make one answer of tDatabasePath and it is correct the path where it is the database...

put revOpenDatabase ("sqlite",tDatabasePath,,,,) into tDatabaseID

then i make another answer for tDatabaseID, and i have one number...So, it is not null or an error message...

I added my databaseConnect and the first script it is entering when the application starts...And around the "tCounter" is not advancing anymore in this script...
But as i said, only with the standalone ( in the same folder or not as the one for developping)...As when i am developping it is working as i want...


command databaseConnect

local tDatabasePath, tDatabaseID
global myPath

put myPath into tDatabasePath
put revOpenDatabase ("sqlite",tDatabasePath,,,,) into tDatabaseID

answer tDatabaseID

setDatabaseID tDatabaseID

end databaseConnect


on PutNameColumns
global theDataGridArray

databaseConnect

put getDatabaseID() into tDatabaseID
put revQueryDatabase( tDatabaseID, " PRAGMA table_info( Rep )") into theCursor
put "DGPragmaRep" into nameTablePragma

if theCursor is an integer then
ConvertSQLCursorToArray theCursor, theDataGridArray
put the result into theError

if theError is empty then

set the dgData of group nameTablePragma to theDataGridArray

end if

## Close the database cursor
revCloseCursor theCursor
end if

put the dgData of group nameTablePragma into theDataPragma
put the dgNumberOfRecords of group nombreTablaPragma into tCounter
answer "Counter" & tCounter --*****************************************************HERE tCounter is empty, and it should not********************
put theDataPragma[1]["name"] into tColumns
put 2 into i
repeat while i <=tCounter
put cr & theDataPragma["name"] after tColumns
add 1 to i
end repeat


set the dgProp["columns"] of grp "DGPenC" to tColumns
set the dgProp["column labels"] of grp "DGPenC" to tColumns


set the dgProp["columns"] of grp "DGImp" to tColumns
set the dgProp["column labels"] of grp "DGImp" to tColumns

answer "end script" --**************************************HERE IT NEVER ARRIVES*****************************************************
end PutNameColumns


regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 3:10 pm
by fko
Hi,

This is the script...In the other it was one mistake (only putting it in the post, as from the developping code is working)...

This is the corrected one: :-)

on PutNameColumns
global theDataGridArray

databaseConnect

put getDatabaseID() into tDatabaseID
put revQueryDatabase( tDatabaseID, " PRAGMA table_info( Rep )") into theCursor
put "DGPragmaRep" into nameTablePragma

if theCursor is an integer then
ConvertSQLCursorToArray theCursor, theDataGridArray
put the result into theError

if theError is empty then

set the dgData of group nameTablePragma to theDataGridArray

end if

## Close the database cursor
revCloseCursor theCursor
end if

put the dgData of group nameTablePragma into theDataPragma
put the dgNumberOfRecords of group nameTablePragma into tCounter
answer "Counter " & tCounter --*****************************************************HERE tCounter is empty, and it should not********************
put theDataPragma[1]["name"] into tColumns
put 2 into i
repeat while i <=tCounter
put cr & theDataPragma["name"] after tColumns
add 1 to i
end repeat


set the dgProp["columns"] of grp "DGPenC" to tColumns
set the dgProp["column labels"] of grp "DGPenC" to tColumns


set the dgProp["columns"] of grp "DGImp" to tColumns
set the dgProp["column labels"] of grp "DGImp" to tColumns

answer "end script" --**************************************HERE IT NEVER ARRIVES*****************************************************
end PutNameColumns

regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 4:06 pm
by Klaus
Hi fko,

I'm not a SQL expert, but is this correct syntax: " PRAGMA table_info( Rep )"?
e.g. the SPACE at the beginning?

And you should also check if "theError" is NOT empty:

Code: Select all

...
if theError is empty then
  set the dgData of group nameTablePragma to theDataGridArray
else
  answer "ERROR"

  # Do NOT continue in that case!
  EXIT TO TOP
end if
...
You should also try to debug the script to see what the variable actually contain (and what not)
to get a hint on what does happen here.


Best

Klaus

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 4:43 pm
by fko
Hi Klaus,

The SQL sentence normally it is working...And it seems this because i added some 'answer' in my other code and i am receiving values from the 'Pragma' sentence:

This is the part of the code where i added the answers:

if theError is empty then

set the dgData of group nameTablePragma to theDataGridArray
answer theDataGridArray[1]["name"] --AND THIS IS RETURNING WHAT I EXPECTED
end if

## Close the database cursor
revCloseCursor theCursor
end if

put the dgData of group nameTablePragma into theDataPragma
answer theDataPragma[2]["name"] --AND THIS ONE TOO IS RETURNING WHAT I EXPECTED
put the dgNumberOfRecords of group nameTablePragma into tCounter
answer "Counter " & tCounter --*****************************************************HERE tCounter is empty, and it should not********************

And as in both answer i have values, then i wonder why i have no value in the tCounter...This is turning me crazy...:-(
Specially when it is working in the developping code and only is empty the tCounter when it is from the standalone...


regards,
fko

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 5:13 pm
by Klaus
Hi fko,

ah, I see!

1. Do yourself a favour and get used to put QUOTES around object names (and STRINGS in general):
...
grp "nameTablePragma" ...
...

2. I completely overlooked this one:
"dgNumberOfrecords" is NOT what you need here, that is something completely different :D
Check "the dgNumberOfLines" of that group!


Best

Klaus

Re: standalone for Mac from Windows with Database

Posted: Fri Jun 27, 2014 5:42 pm
by fko
Hi Klaus,

In the beginning of the script i have this line

put "DGPragmaRep" into nameTablePragma...

So i am putting the name of the DataGrid "DGPragmaRep" in one variable...
Do i have to use quotes for the variable? I thought was for the object name...

And coming to the 'paranormal zone again'...:-)

I used:

put the dgNumberOfRecords of group nameTablePragma into tCounter
put the dgNumberOfLines of group nameTablePragma into tCounter

and in boths i have '11' when it is from my developping code and 'empty' from the standalone...:-(
Is it posible that the counter is empty if i had values in theDataGridArray[1]["name"] and in theDataPragma[2]["name"]???

regards,
fko