Page 1 of 1

adding android scroller to datagrid with database

Posted: Fri Jun 13, 2014 1:10 pm
by keram
Hello,

I'm trying to add a native android scroller to the sample Data Grid with SQL database from this lesson:
http://lessons.runrev.com/m/datagrid/l/ ... ts-of-data
I'm using the scroller from Klaus that is working very well with regular DG and I just added it to the sample stack from the above lesson.

To get it working in the android besides the scroller I added this to the card's script:

Code: Select all

local sThePath
...
...
         switch platform()
         case "android"
            ## Android
            put specialFolderPath("documents") into sThePath
            break
         case "Win32"
            ## Everything >= Win2000
            if the systemversion contains "NT" then put specialFolderPath(26) into sThePath
            break
         case "MacOS"
            ## MacOS X
            put specialFolderPath("preferences") into sThePath
            break
      end switch
	  
      put sThePath &"/MQdata2" into sThePath
      if there is not a folder sThePath then new folder sThePath  --new folder
      if result() <> empty then answer "Sorry, but there was a problem writing to a .sqlite3 file." with "OK"

...
...

command OpenDatabase
   set the wholematches to true
   
   if sConnID is not an integer OR sConnID is not among the items of revOpenDatabases() then
      set the itemdelimiter to slash

      put "movies.sqlite3" into the last item of sThePath
      put revOpenDatabase("sqlite",sThePath,,,,) into sConnID

      if sConnID is not an integer then
         answer "Error connecting to the database:" && sConnID & "."
         put empty into sConnID
         exit to top
      end if
   end if
end OpenDatabase
When clicking on the button "Populate List Group from Data Base" in the sample stack I'm getting error:
"Error opening cursor: Database error: no such table: movies"

and in the android this error:
"Error connecting to the database: Database error: Unable to open the database file."

What am I doing wrong?

I'm attaching the stack with my changes only, the database and the original stack can be downloaded from the above page with the lesson.

keram

Re: adding android scroller to datagrid with database

Posted: Fri Jun 13, 2014 1:26 pm
by Klaus
Hi keram,

this is your first pathname:
...
put sThePath &"/MQdata2" into sThePath
...
where "MQdata2" is a folder that you create if not yet present.

Then later you do:
...
set the itemdelimiter to slash
put "movies.sqlite3" into the last item of sThePath
...
and this REPLACE the folder name "MQdata2" in the variable and will create this path to the database file:
...
sThePath &"/movies.sqlite3"
...
Which is obiously wrong.

So I GUESS it shoud be:
...
sThePath &"/MQdata2/movies.sqlite3"
...
right?

In that case you need to:
...
put "/movies.sqlite3" AFTER sThePath
...

Hope I understood this right 8)

Hint:
Since Android and iOS are CASE SENSITIVE filesystems, you should stick with lowercase EVERYWHERE for filenames!
Will save a lot of headache :D


Best

Klaus

Re: adding android scroller to datagrid with database

Posted: Fri Jun 13, 2014 5:12 pm
by keram
Thanks, Klaus.
Klaus wrote:Since Android and iOS are CASE SENSITIVE filesystems, you should stick with lowercase EVERYWHERE for filenames!
With filenames you mean the names of the folders in the path as well? So in my case I should write mqdata2 instead of MQdata2, right?
Klaus wrote:put "/movies.sqlite3" AFTER sThePath
Yes, this correction fixed it but only on Windows. On android I'm still getting an error, this time:
"Error opening cursor: Database error: no such table: movies."

the code is now:

Code: Select all

command OpenDatabase
   set the wholematches to true
   
   if sConnID is not an integer OR sConnID is not among the items of revOpenDatabases() then
      set the itemdelimiter to slash
      put "/movies.sqlite3" after sThePath
      put revOpenDatabase("sqlite",sThePath,,,,) into sConnID
      
      if sConnID is not an integer then
         answer "Error connecting to the database:" && sConnID & "."
         put empty into sConnID
         exit to top
      end if
   end if
end OpenDatabase
Any idea what's wrong?

keram

Re: adding android scroller to datagrid with database

Posted: Fri Jun 13, 2014 5:47 pm
by Klaus
Hi Keram,
keram wrote:Any idea what's wrong?
If there is not a file "movies.sqlite3" at that specific place, then "revopendatabase"
will create an EMPTY database file with NO tables in it!

Maybe that is the case here?


Best

Klaus

Re: adding android scroller to datagrid with database

Posted: Sat Jun 14, 2014 5:37 am
by keram
Hi Klaus,

Thanks for your response!
Klaus wrote:If there is not a file "movies.sqlite3" at that specific place,...
Yes, you were right, as usual :)

I simply did not think that I have to copy the database to android's specialFolderPath("documents") - I thought that it may end up in the right folder automatically 8) ;
I also did not know where the database file is stored after making the standalone until I found this info on the forum - it's in specialFolderPath("engine")
So I added these lines to the card script:

Code: Select all

      
...
case "android"
         ## Android
         put specialFolderPath("documents") into sThePath
         put specialFolderPath("engine") into sEnginePath
         break
...
...
		 
      if there is not a file(sThePath & "/movies.sqlite3") then
      put url("binfile:" & sEnginePath & "/movies.sqlite3") into url("binfile:" & sThePath& "/movies.sqlite3")
   end if
Now the DG is populating correctly from the database BUT it's not scrolling :(
I'm using your code from this post: http://forums.livecode.com/viewtopic.ph ... ing#p93753
which is:

Code: Select all

on openCard
   local sScrollerID,isScrolling
   ## Create scroller now:
   create_scroller
   
   ...

end openCard


command create_scroller   
   put "Data Grid" into tScrollerGroup
   
   if the environment <> "mobile" then
      exit create_scroller
   end if
   
   ## Create native scroller object and save its ID in a local variable
   MobileControlCreate "scroller"
   put the result into sScrollerId
   
   ## RECT is the area on the card where the SCOLLER should do its work
   MobileControlSet sScrollerId, "rect", (the rect of grp tScrollerGroup)
   
   put the width of grp tScrollerGroup into tWidth
   put the dgFormattedheight of grp tScrollerGroup into tHeight
   set the dgvScroll of grp tScrollerGroup to 0
   
   ## WHAT part fo the datagrid shall be scrolled-> the complete datagrid
   MobileControlSet sScrollerId, "contentRect", (0,0,tWidth,tHeight)
   
   ## Display SCROLLER
   MobileControlSet sScrollerId, "visible", "true"
   
   ## the typical BUMP effect when you ge to the edge of the object
   MobileControlSet sScrollerId, "canBounce", "true"
   MobileControlSet sScrollerId, "pagingEnabled", "false"
   
   MobileControlSet sScrollerId, "vIndicator", "false"
   MobileControlSet sScrollerId,  "borderStyle", "none"
   
   MobileControlSet sScrollerId, "canScrollToTop", "false"
end create_scroller

## Will be sent when the user actually SCROLLs with his finger
on scrollerDidScroll OffsetX, OffsetY
   lock screen
   set the dgvScroll of grp "Data Grid" to OffsetY
   unlock screen
end scrollerDidScroll

## REMOVE natove object when card closes!!!!!
command delete_scroller
   if the environment <> "mobile" then
      exit delete_scroller
   end if
   MobileControlDelete sScrollerId   
end delete_scroller

on closeCard
   delete_scroller
   ...
end closeCard
So again, what am I doing wrong??? :(

keram