Creating Apps for use on Android mobile phones

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Dragondos2020
Posts: 29
Joined: Mon Apr 20, 2020 1:00 pm

Re: Creating Apps for use on Android mobile phones

Post by Dragondos2020 » Fri May 01, 2020 11:52 am

I have made the inclusions and ensured that the following are checked:
Navigation Bar : DataGrid : Sqlite : Database : Answer Dialog : Ask Dialog

I am still obviously missing something here. As I found that the app works great in the LiveCode Environment but the buttons will not work when in the emulator or on my mobile phone.

sphere
Posts: 1114
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Creating Apps for use on Android mobile phones

Post by sphere » Fri May 01, 2020 5:57 pm

Can you put some scripts of the buttons here, so we can take a look what is happening?
Or a test stack ?

Dragondos2020
Posts: 29
Joined: Mon Apr 20, 2020 1:00 pm

Re: Creating Apps for use on Android mobile phones

Post by Dragondos2020 » Fri May 01, 2020 7:28 pm

Please find below (1) Code of the Stack; (2) Code of the Card; (3) Code of the Buttons Used;

Code of the Main Stack

global gConnID, gHomeFolder

on preOpenStack
set the enabled of button "Login" to true

put the effective filename of this stack into gHomeFolder
set the itemDelimiter to slash
put item 1 to -2 of gHomeFolder into gHomeFolder
set the defaultFolder to gHomeFolder
disable widget "navbar"
connectToDB
end preOpenStack

on openStack
set the fullscreenmode of stack "dbMembershipSuite" to "exactFit"
end openStack

on closeStack
databaseDisconnect
end closeStack

on connectToDB
local tDatabasePath, tDatabaseID
put "membershipdatabase.db" into tDatabasePath

put revOpenDatabase("sqlite", tDatabasePath,,,,) into tDatabaseID
if tDatabaseID is "" then
answer warning "There was a problem accessing the Membership Database!"
end if
setDatabaseID tDatabaseID
end connectToDB

command setDatabaseID pDatabaseID
put pDatabaseID into gConnID
end setDatabaseID

function getDatabaseID
return gConnID
end getDatabaseID


command databaseDisconnect
local tResult
revCloseDatabase gConnID
put the result into tResult
handleRevDBerror tResult
if the result is not empty then
answer warning the result
exit to top
end if
answer information "Connection Terminated"
end databaseDisconnect

on handleRevDBerror p
switch
case item 1 of p is "revdberr"
return "revDB Error:" & p
break
case "syntax error" is in p
return "Database Error:" & p
break
end switch
end handleRevDBerror

on showAllRecords
local tQuery, tRecords
connectToDB
show group "dgMembersList"
put "SELECT * FROM members" into tQuery
put revDataFromQuery(,,gConnID, tQuery) into tRecords
if tRecords begins with "revdberr" then
answer error "There was a problem accessing the Database: " & tRecords
databaseDisconnect gConnID
exit to top
end if
set the dgText of group "dgMembersList" to tRecords
end showAllRecords


Code of the Card

global gConnID

on openCard
set the enabled of button "MembersPaid" to true
set the enabled of button "MembersDue" to true
set the enabled of button "MembersList" to true
enable widget "navbar"
showAllRecords
end openCard

on resizeStack x,y
local tRowSize
put 60 into tRowSize
-- Header - fixed height, full bleed:
set the rect of btn "header" to 0,0,x, tRowSize
-- Content Region
set the rect of grp "ContentRegion" to 0, tRowSize, x, y-tRowSize
-- Footer - fixed height, full bleed:
set the rect of widget "NavBar" to 0,y-tRowSize,x,y
end resizeStack

Code of the 'Members Paid" Button

global gConnID

on mouseUp
local tQuery, tRecords, tDatabaseID
connectToDB
put gConnID into tDatabaseID

put "SELECT * FROM members WHERE paid = 'Yes'" into tQuery
put revDataFromQuery(,,tDatabaseID, tQuery) into tRecords
if tRecords begins with "revdberr" then
answer error "There was a problem accessing the Database: " & tRecords
exit to top
end if
set the dgText of group "dgMembersList" to tRecords
end mouseUp

Code for the 'Members Due' Button

global gConnID

on mouseUp
local tRecords, tQuery, tDatabaseID
connectToDB
put gConnID into tDatabaseID

put "SELECT * FROM members WHERE paid = 'No'" into tQuery
put revDataFromQuery(,,tDatabaseID, tQuery) into tRecords
if tRecords begins with "revdberr" then
answer error "There was a problem accessing the Database: " & tRecords
exit to top
end if
set the dgText of group "dgMembersList" to tRecords
end mouseUp


Code for the 'Members List' Button

on mouseUp
showAllRecords
end mouseUp

Code for the 'mouseUp' when clicking on a members name shown on the Datagrid

global gConnID,gRecordID, gFname,gLname,gAddr1,gAddr2,gAddr3,gAddr4,gPostcode,gTelephone,gMobile,gEmail,gDate,gFee,gPaid,gType

on mouseUp
local tLineSelected

put the dgHilitedLine of group "dgMembersList" into tLineSelected
if tLineSelected is a number and tLineSelected>0 then
set the itemDelimiter to tab
put item 1 of line tLineSelected of the dgText of group "dgMembersList" into gRecordID
put item 2 of line tLineSelected of the dgText of group "dgMembersList" into gFname
put item 3 of line tLineSelected of the dgText of group "dgMembersList" into gLname
put item 4 of line tLineSelected of the dgText of group "dgMembersList" into gAddr1
put item 5 of line tLineSelected of the dgText of group "dgMembersList" into gAddr2
put item 6 of line tLineSelected of the dgText of group "dgMembersList" into gAddr3
put item 7 of line tLineSelected of the dgText of group "dgMembersList" into gAddr4
put item 8 of line tLineSelected of the dgText of group "dgMembersList" into gPostcode

put item 9 of line tLineSelected of the dgText of group "dgMembersList" into gDate
put item 10 of line tLineSelected of the dgText of group "dgMembersList" into gFee
put item 11 of line tLineSelected of the dgText of group "dgMembersList" into gPaid
put item 12 of line tLineSelected of the dgText of group "dgMembersList" into gType
put item 13 of line tLineSelected of the dgText of group "dgMembersList" into gTelephone
put item 14 of line tLineSelected of the dgText of group "dgMembersList" into gMobile
put item 15 of line tLineSelected of the dgText of group "dgMembersList" into gEmail
visual effect "push" left fast
go to card "selected member"
end if
end mouseUp

Code for the Widget 'NavBar'

on hiliteChanged
global gMenuName
get the hilitedItemName of widget "navbar"
go to card it
// set the hilitedItemName of widget "navbar" to gMenuName
set the hilitedItemName of widget "navbar" to it
end hiliteChanged

Thanks :D

sphere
Posts: 1114
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Creating Apps for use on Android mobile phones

Post by sphere » Fri May 01, 2020 8:15 pm

For the sake of better readable here on the forum ,please put your code like this

Code: Select all

 your button code here 
.
That's where the this </> button here on the forum is for.

What happens if you just say: answer tRecords

and probably you need to use: revExecuteSQL
else nothing is happening.

i Use something like this with sqlite

Code: Select all

put "SELECT * FROM cust WHERE id=1" into tSQL
   put revDataFromQuery(tab,return,gLocalDbID,tSQL) into tCustGeg

Dragondos2020
Posts: 29
Joined: Mon Apr 20, 2020 1:00 pm

Re: Creating Apps for use on Android mobile phones

Post by Dragondos2020 » Fri May 01, 2020 9:17 pm

Code: Select all

Code of the Main Stack

global gConnID, gHomeFolder

on preOpenStack
set the enabled of button "Login" to true

put the effective filename of this stack into gHomeFolder
set the itemDelimiter to slash
put item 1 to -2 of gHomeFolder into gHomeFolder
set the defaultFolder to gHomeFolder
disable widget "navbar"
connectToDB
end preOpenStack

on openStack 
set the fullscreenmode of stack "dbMembershipSuite" to "exactFit"
end openStack

on closeStack
databaseDisconnect
end closeStack

on connectToDB
local tDatabasePath, tDatabaseID
put "membershipdatabase.db" into tDatabasePath

put revOpenDatabase("sqlite", tDatabasePath,,,,) into tDatabaseID
if tDatabaseID is "" then
answer warning "There was a problem accessing the Membership Database!"
end if
setDatabaseID tDatabaseID
end connectToDB

command setDatabaseID pDatabaseID
put pDatabaseID into gConnID
end setDatabaseID

function getDatabaseID
return gConnID
end getDatabaseID


command databaseDisconnect
local tResult
revCloseDatabase gConnID
put the result into tResult
handleRevDBerror tResult
if the result is not empty then 
answer warning the result
exit to top
end if
answer information "Connection Terminated"
end databaseDisconnect

on handleRevDBerror p
switch 
case item 1 of p is "revdberr"
return "revDB Error:" & p
break
case "syntax error" is in p
return "Database Error:" & p
break
end switch
end handleRevDBerror

on showAllRecords
local tQuery, tRecords
connectToDB
show group "dgMembersList"
put "SELECT * FROM members" into tQuery
put revDataFromQuery(,,gConnID, tQuery) into tRecords
if tRecords begins with "revdberr" then
answer error "There was a problem accessing the Database: " & tRecords
databaseDisconnect gConnID
exit to top
end if
set the dgText of group "dgMembersList" to tRecords
end showAllRecords


Code of the Card

global gConnID

on openCard
set the enabled of button "MembersPaid" to true
set the enabled of button "MembersDue" to true
set the enabled of button "MembersList" to true
enable widget "navbar"
showAllRecords
end openCard

on resizeStack x,y
local tRowSize
put 60 into tRowSize
-- Header - fixed height, full bleed:
set the rect of btn "header" to 0,0,x, tRowSize
-- Content Region
set the rect of grp "ContentRegion" to 0, tRowSize, x, y-tRowSize
-- Footer - fixed height, full bleed:
set the rect of widget "NavBar" to 0,y-tRowSize,x,y
end resizeStack

Code of the 'Members Paid" Button

global gConnID

on mouseUp
local tQuery, tRecords, tDatabaseID
connectToDB
put gConnID into tDatabaseID

put "SELECT * FROM members WHERE paid = 'Yes'" into tQuery
put revDataFromQuery(,,tDatabaseID, tQuery) into tRecords
if tRecords begins with "revdberr" then
answer error "There was a problem accessing the Database: " & tRecords
exit to top
end if
set the dgText of group "dgMembersList" to tRecords
end mouseUp

Code for the 'Members Due' Button

global gConnID

on mouseUp
local tRecords, tQuery, tDatabaseID
connectToDB
put gConnID into tDatabaseID

put "SELECT * FROM members WHERE paid = 'No'" into tQuery
put revDataFromQuery(,,tDatabaseID, tQuery) into tRecords
if tRecords begins with "revdberr" then
answer error "There was a problem accessing the Database: " & tRecords
exit to top
end if
set the dgText of group "dgMembersList" to tRecords
end mouseUp


Code for the 'Members List' Button

on mouseUp
showAllRecords
end mouseUp

Code for the 'mouseUp' when clicking on a members name shown on the Datagrid

global gConnID,gRecordID, gFname,gLname,gAddr1,gAddr2,gAddr3,gAddr4,gPostcode,gTelephone,gMobile,gEmail,gDate,gFee,gPaid,gType

on mouseUp
local tLineSelected

put the dgHilitedLine of group "dgMembersList" into tLineSelected
if tLineSelected is a number and tLineSelected>0 then
set the itemDelimiter to tab
put item 1 of line tLineSelected of the dgText of group "dgMembersList" into gRecordID
put item 2 of line tLineSelected of the dgText of group "dgMembersList" into gFname
put item 3 of line tLineSelected of the dgText of group "dgMembersList" into gLname
put item 4 of line tLineSelected of the dgText of group "dgMembersList" into gAddr1
put item 5 of line tLineSelected of the dgText of group "dgMembersList" into gAddr2
put item 6 of line tLineSelected of the dgText of group "dgMembersList" into gAddr3
put item 7 of line tLineSelected of the dgText of group "dgMembersList" into gAddr4
put item 8 of line tLineSelected of the dgText of group "dgMembersList" into gPostcode

put item 9 of line tLineSelected of the dgText of group "dgMembersList" into gDate
put item 10 of line tLineSelected of the dgText of group "dgMembersList" into gFee
put item 11 of line tLineSelected of the dgText of group "dgMembersList" into gPaid
put item 12 of line tLineSelected of the dgText of group "dgMembersList" into gType
put item 13 of line tLineSelected of the dgText of group "dgMembersList" into gTelephone
put item 14 of line tLineSelected of the dgText of group "dgMembersList" into gMobile
put item 15 of line tLineSelected of the dgText of group "dgMembersList" into gEmail
visual effect "push" left fast
go to card "selected member"
end if
end mouseUp

Code for the Widget 'NavBar'

on hiliteChanged
global gMenuName
get the hilitedItemName of widget "navbar"
go to card it
// set the hilitedItemName of widget "navbar" to gMenuName
set the hilitedItemName of widget "navbar" to it
end hiliteChanged
Thanks for advice to show the code within the special format.

answer tRecords displays the data as expected and neatly placed tabbed out

I also replaced the lines with your suggestion which gave the same results as mine did.

I have ensured that the General Tab, the Stacks tab, inclusion tabs and Android tabs are containing the relevant information as previously suggested.

I feel that I am taking up everyones time who offered help and yet I can still not resolve the problem of the buttons working within the LiveCode Environment but not working within the emulator or Android phone.
Thanks

sphere
Posts: 1114
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Creating Apps for use on Android mobile phones

Post by sphere » Fri May 01, 2020 9:28 pm

did you try this also on a phone or the emulator? Does it answer then?

i'm going to put it in a stack and see what happens on my test phone

edit

where is the part that you actually create the DB file and insert data?

Dragondos2020
Posts: 29
Joined: Mon Apr 20, 2020 1:00 pm

Re: Creating Apps for use on Android mobile phones

Post by Dragondos2020 » Fri May 01, 2020 11:17 pm

The 'connectToDB' routine can be found in the stack code and is called via 'onPreOpenStack' routine. The whole project only has one stack and five additional cards.

Code: Select all

on connectToDB
   local tDatabasePath, tDatabaseID
   put "membershipdatabase.db" into tDatabasePath
   
   put revOpenDatabase("sqlite", tDatabasePath,,,,) into tDatabaseID
   if tDatabaseID is "" then
      answer warning "There was a problem accessing the Membership Database!"
   end if
   setDatabaseID tDatabaseID
end connectToDB

command setDatabaseID pDatabaseID
   put pDatabaseID into gConnID
end setDatabaseID
The routine for saving the data to the database can be found on the 'newmembers' card where the end user would fill in the details required and then selecting the 'Save' button. The script for that button is:

Code: Select all

global gConnID

on mouseUp
   local tRowData, tSQL, tResult, tDatabaseID
   connectToDB
   put gConnID into tDatabaseID
   
   
   put field "txtFname" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtLname" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtAddr1" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtAddr2" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtAddr3" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtAddr4" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtPostcode" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtDate" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtFee" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtPaid" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put the label of button "optMembership" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtTelephone" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtMobile" into it
   put "'" & cleanSQL(it) & "'" & "," after tRowData
   put field "txtEmail" into it
   put "'" & cleanSQL(it) & "'" after tRowData
   
   put "INSERT INTO members (member_id,fname,lname,addr1,addr2,addr3,addr4,postcode,joindate,fee,paid,membership,phone,mobile,email) " & "VALUES(null," & tRowData & ")" into tSQL
   revExecuteSQL tDatabaseID, tSQL
   put the result into tResult
   handleRevDBerror tResult
   if the result is not empty then
      answer warning the result
      exit to top
   end if
   answer information "Membership Details Saved!" titled "Stephen R Lucas"
   send "mouseUp" to button "Cancel Entry"
end mouseUp

function cleanSQL pSQL
   replace "'" with "''" in pSQL
   replace quote with quote & quote in pSQL
   replace return with "*RETURN*" in pSQL
   replace tab with "*TAB*" in pSQL
   return pSQL
end cleanSQL
I have tested the project within the LiveCode Environment. All works well with opening the database and successfully saving the data and then displaying the saved data. I can even delete the record from the database, amend the record on the database even search the database for a specific record. As I said the whole project works well and performs as expected when testing within the LiveCode Environment.

The problem is that when I test the project, either on the emulator or by downloading the .apk file to my Android Phone. The navigation bar works well and allows me to move from card to card. But ALL the other buttons on the different cards, when selected DO NOTHING. So I cannot 'Save' a new record to the database.

When I created the standalone I did ensure that I added the image files, the database file, and the text file which holds the membership fees. I also ensured that I selected the 'Inclusions' such as Database, SQLite, Datagrid, Navigation Bar.

I hope this extra information which assist.
Regards

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Creating Apps for use on Android mobile phones

Post by Klaus » Fri May 01, 2020 11:33 pm

Hi Dragondos2020,

a couple of things...

1. Location of your database file

Code: Select all

on preOpenStack
   set the enabled of button "Login" to true
   
   ## put the effective filename of this stack into gHomeFolder
   ## set the itemDelimiter to slash
   ## put item 1 to -2 of gHomeFolder into gHomeFolder
   ## set the defaultFolder to gHomeFolder
   
   ## NO need to se the defaultfolder!
   
   disable widget "navbar"
   connectToDB
end preOpenStack
Are you sure that the folder the app is in is the folder with your database?
I have no idea, but LC did take care of this! :-)

You surely have added the db file via the "Copy files" tab in the "Standalone Application Settings" for your stack, right?
In that case you will find everything added there in -> specialfolderpath("resources") in your final app On ANY platform,
whereever that folder may be on the target platform.

So you will find your db file here:

Code: Select all

...
put specialfolderpath("resources") & "/membershipdatabase.db" into The_DB_File
...
2. We cannot open that database at that location! :-(

Since we do not have write permission in that folder and even opening a database is considered writing on almost all operating systems.
Maybe that is the problem and the script just halts(s) at that point and nothing else works!?

So you need to copy the db file to the users documents folder where we have write permissions and actually use the db!
We add a little check if the db file is already there and copy it if not:

Code: Select all

## Global and local variables only need be declared ONCE at the top of the complete script!
global gConnID, gHomeFolder
local tDatabasePath, tDatabaseID

on preopenstack
  ##...
end preopenstack
## etc...
 
 on connectToDB   
   ## This folder is where we have write permission and we should store everything we need here 
   ## like user settings, database, PDFs, screenshots etc... whatever your app outputs :-)
   put specialfolderpath("documents") & "/membershipdatabase.db" into tDatabasePath
   
   ## Now check if the app has started the very first time = db file NOT (yet) present
   ## If not we copy the db 
   if there is NOT a file tDatabasePath then
     ## See above
      put specialfolderpath("resources") & "/membershipdatabase.db" into tSourceFile
      
      ## Copy the file:
      put url("binfile:" & tSourceFile) into url("binfile:" & tDatabasePath)
   end if
   
   ## Green light, file present, ready to connect!
   put revOpenDatabase("sqlite", tDatabasePath,,,,) into tDatabaseID
   if tDatabaseID is "" then
      answer warning "There was a problem accessing the Membership Database!"
   end if
   setDatabaseID tDatabaseID
end connectToDB
Please try and report back.


Best

Klaus

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Creating Apps for use on Android mobile phones

Post by Klaus » Fri May 01, 2020 11:45 pm

Hint:
specialfolderpath("resources") even works in the IDE, where it points to the folder with the current stack.

So you could script something like this to cover all cases (IDE and RUNTIME) in one script,
just put the db file into the folder with your stack, add it via "Copy files" to your final app and there you go:

Code: Select all

on connectToDB  
   ## This folder is where we can work with the db
   ## Check if we are in the IDE:
   if the environment = "development" then
      put specialfolderpath("resources") & "/membershipdatabase.db" into tDatabasePath
      ## Folder where the stack is in, we may write here in the IDE!
   else
     ## Runtime:
      put specialfolderpath("documents") & "/membershipdatabase.db" into tDatabasePath
   end if
   
   ## Now check if the app has started the very first time but only as the final runtime because of our check above!
   ## If not we copy the db 
   if there is NOT a file tDatabasePath then
      put specialfolderpath("resources") & "/membershipdatabase.db" into tSourceFile
      put url("binfile:" & tSourceFile) into url("binfile:" & tDatabasePath)
   end if
   
   ## Green light, file present, ready to connect!
   put revOpenDatabase("sqlite", tDatabasePath,,,,) into tDatabaseID
   if tDatabaseID is "" then
      answer warning "There was a problem accessing the Membership Database!"
   end if
   ## setDatabaseID tDatabaseID
end connectToDB
## setDatabaseID tDatabaseID
That handler setDatabaseID is completely redundant, since tDatabaseID IS ALREADY A LOCAL and setting it
again, and even in a separate handler, is really ****CENSORED****! So just delete it.

Who on earth invented that?
A member of the "confuse-a-newbie" department? :D

Dragondos2020
Posts: 29
Joined: Mon Apr 20, 2020 1:00 pm

Re: Creating Apps for use on Android mobile phones

Post by Dragondos2020 » Sat May 02, 2020 1:08 pm

Thank you for your assistance. I changed the stack code as suggested to :

Code: Select all

global gConnID, gHomeFolder

on preOpenStack
   set the enabled of button "Login" to true
   
   // put the effective filename of this stack into gHomeFolder
   // set the itemDelimiter to slash
   // put item 1 to -2 of gHomeFolder into gHomeFolder
   // set the defaultFolder to gHomeFolder
   disable widget "navbar"
   connectToDB
end preOpenStack
Also changed the ConnectToDB Code as suggested:

Code: Select all

on connectToDB
   local tDatabasePath, tDatabaseID, tSourceFile
   
   -- Check if we are in the IDE:
   if the environment = "development" then
      put specialFolderPath("resources") & "/membershipdatabase.db" into tDatabasePath
      -- Folder where the stack is in, we may write here in the IDE!
   else
      -- Runtime:
      put specialFolderPath("documents") & "/membershipdatabase.db" into tDatabaseID
   end if
   
   -- Now check if the app has started the very first time but only as the final
   -- runtime because of our check above!
   if there is NOT a file tDatabasePath then
      put specialFolderPath("resources") & "/membershipdatabase.db" into tSourceFile
      put URL("binfile:" & tSourceFile) into URL("binfile:" & tDatabasePath)
   end if
   
   -- Green Light, File Present, Ready to Connect
   put revOpenDatabase("sqlite", tDatabasePath,,,,) into tDatabaseID
   if tDatabaseID is "" then
      answer warning "There was a problem accessing the Membership Database!"
   end if
   // put "membershipdatabase.db" into tDatabasePath
   // setDatabaseID tDatabaseID
end connectToDB
I then run the project in the LiveCode Environment and watched its process. It chose the 'Development' option, as expected. Checked it was Not a file and found its way to the ## Green Light comments, where it successfully connected to the database and put 27 into the tDatabaseID. No warnings were given, so all was ok. When I moved on from the main screen the program did throw up a small problem as I had used gConnID. So once I rectified that the whole program worked perfectly

After saving as a standalone I then tested the program in the Android Emulator. When I accessed the Main Screen, whereas before when I selected any of the buttons (Members Paid, Members Due and Members List). Literally nothing would happen. However, this time when selecting any of the three buttons (Coding for which can be found previously within the Post and Replies). I receive the follow message: This is also the same message I get when my project moves from the first card to the second card. The second card being the main where the first card is the Login screen. The Login has not been coded yet.

There was a problem accessing the Database: rebdberr,Database Error: No such table: members

This to me appears to be at least an improvement from getting no action from the buttons before. Knowing that the database does hold the table members. I guess, what it is really telling me is that it cannot find the Database to access.

Thanks for helping me to understand LiveCode better and in trying to understand the difference need to run on Android Phones.

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Creating Apps for use on Android mobile phones

Post by Klaus » Sat May 02, 2020 1:50 pm

Wrong resp. NO PATHNAME in runtime, so LC will TRY to open the db in -> resources, which is not allowed and gives an error!

Code: Select all

...
else
      -- Runtime:
      ## put specialFolderPath("documents") & "/membershipdatabase.db" into -> tDatabaseID
      put specialFolderPath("documents") & "/membershipdatabase.db" into tDatabasePath
   end if
8)

Dragondos2020
Posts: 29
Joined: Mon Apr 20, 2020 1:00 pm

Re: Creating Apps for use on Android mobile phones

Post by Dragondos2020 » Sat May 02, 2020 3:35 pm

I really do not know what is happening here ….. or why it is not working.

I have included / amended the line of code as recommended:

Code: Select all

else
      -- Runtime:
      ## put specialFolderPath("documents") & "/membershipdatabase.db" into -> tDatabaseID
      put specialFolderPath("documents") & "/membershipdatabase.db" into tDatabasePath
   end if
But I still get the same message as before, stating that there was no such table: members.

I am at a complete loss. I have taken on all the points raised and given …. so frustrating. I am sure it is something that is so simple.

Best Regards

AxWald
Posts: 486
Joined: Thu Mar 06, 2014 2:57 pm

Re: Creating Apps for use on Android mobile phones

Post by AxWald » Sat May 02, 2020 4:45 pm

Hi,

when you add your "myDB.sqlite" in the "copy File" sttings, it ends in specialFolderPath("resources").
This isn't good 'cause you cannot use it there. You have to copy it to specialFolderPath("documents") before!

Code: Select all

on openstack
if not (there is a file (specialFolderPath("documents") & "myDB.sqlite")) then
   put URL ("binfile:" & specialFolderPath("resources") & "myDB.sqlite") \
      into URL (specialFolderPath("documents") & "myDB.sqlite")
end if
...
Attention - as soon as you try to connect to a non-existent specialFolderPath("documents") & "myDB.sqlite" there will be an empty one created, and above will not run! So uninstall the old version from your Android before to get rid of it.

(Hope this isn't redundant ...)

Have fun!
Livecode programming until the cat hits the fan ...

Dragondos2020
Posts: 29
Joined: Mon Apr 20, 2020 1:00 pm

Re: Creating Apps for use on Android mobile phones

Post by Dragondos2020 » Sat May 02, 2020 9:00 pm

Sorry. After adding the coded suggested to the stack openStack . I then run within the LiveCode. No Problem. Running in the emulator produced the same problem indicating no table: members. When running on my Android Phone, then none of the buttons worked.

If anyone who feels they can help further, (and of course willing). Then I would be well happy to send the complete project to your email address. I just want to get to the bottom of this and start progressing further with programming education.

Thanks. :oops:

AxWald
Posts: 486
Joined: Thu Mar 06, 2014 2:57 pm

Re: Creating Apps for use on Android mobile phones

Post by AxWald » Sun May 03, 2020 11:10 am

Hi,
this looks nasty. And I need to apologize, my last example was meant as pseudo-code, and contained errors.
I tried to re-create the problem, and ran into a nasty ugliness in my trusty old LC 6.7.10 - there you need to add the database libs in the Android section of the StandAlone properties, additionally ...
Anyways, for the following I used 9.5.1, as slow, bloated & ugly it may be :/

So, time to debug. I suggest you use the "test target/ test", this should be the quickest way.
  • For the .sqlite that you add, make sure there's a table "members" in it & that it contains some records. To manage your SQLite databases, use "HeidiSQL" (SQLite here is experimental but works ...), "SQLite Manager" if you have a browser that supports it, "DB Browser for SQLite", or whatever runs on your system.
    Make sure you add the db via "copy Files" in the standAlone settings.
    .
  • Replace the openStack part:

    Code: Select all

    global gPath
    
    on openstack
       put the defaultFolder into gPath                    --  preserve it
       set the defaultfolder to specialfolderPath("resources") & slash
       answer "SFP Resources, Files:" & CR & the files          --  files in resources
       answer "There is a DB in Resorces?" & CR & ("myDB.sqlite" is in the files)
       
       set the defaultfolder to specialfolderPath("documents") & slash
       answer "There is a DB in Documents?" & CR & ("myDB.sqlite" is in the files)
       if not ("myDB.sqlite" is in the files) then
          put URL ("binfile:" & specialFolderPath("resources") & slash & "myDB.sqlite") \
                into URL "binfile:./myDB.sqlite"
          answer "Tried to copy, result:" & CR & the result
       end if
       
       answer "SFP Documents, Files:" & CR & the files         --  files in documents
       set the defaultFolder to gPath                      --  reset it
       ...
    end openstack
    Here we take care that the "myDB.sqlite" actually ends in a place where we have write access. Once this runs flawlessly you can remove the "answer" lines.
    .
  • Now make a button in your stack, and add this code:

    Code: Select all

    global gPath
    
    on mouseUp
       set the defaultfolder to specialfolderPath("documents") & slash
       answer "There is a DB in Documents?" & CR & ("myDB.sqlite" is in the files)
       
       get revdb_connect("sqlite","myDB.sqlite")             --  connect
       if it is not a number then
          answer "Connection failed:" & CR & it              --  ouch!
          exit mouseUp
       else
          put it into myDBID                                 --  gotcha!
       end if
       set the defaultfolder to gPath
       
       put "SELECT * FROM `members` LIMIT 1;" into StrSQL
       get revdb_queryList(tab,CR,myDBID,StrSQL)             --  get some data
       if it begins with "revdberr" then
          answer "Query failed:" & CR & it & CR & StrSQL
       else
          answer "Success!" & CR & it
       end if
       get revdb_disconnect(myDBID)                          -- and clean up
    end mouseUp
    If this doesn't work, something is really, really wrong.
I tested this with LC 9.5.1-64, Win10-64, compiled for ArmV7/ Android 5.0, on my Lenovo Yoga Tab3 (Android 6.0.1).

If revdb_connect fails, compile an .APK, open it (with 7zip, for instance) & check in "/lib/[architecture]/" - you need "libdbsqlite.so" there, as well as "librevdb.so". If they don't exist, the database extensions have not been added. Play with your settings, maybe try with fresh LC preferences ...

If revdb_connect succeeds, but revdb_queryList fails, then you have an error in your SQL. Try again with a simple query, test this query in your desktop sqlite with your sqlite manager - it's often simple typos.
Use single quotes for not-numeric data, and be sure you don't use reserved words as table or field names - in that case make yourself comfortable to use grave accents as in my example, they work well in nearly every database engine!

if this all doesn't help, write again, and try to provide as much information as possible. Best luck!
Livecode programming until the cat hits the fan ...

Post Reply

Return to “Android Deployment”