Page 1 of 1

Problem of connecting Android phone and existing DB

Posted: Thu Jun 11, 2015 4:15 pm
by AstghikM
Hi,
I am having a problem with connecting to Android phone to test an app.
It fails to find the path file and I am attaching the screenshot in the zip below.
As I failed to do this, I also had a problem to connect the existing DB in the Android phone, I was using this:

Code: Select all

global gConnectionID

on preopenStack
dbconnect
 end preopenStack

//connect with DataBase
on dbconnect     
    answer specialfolderpath("documents")
    put revOpenDatabase("sqlite", specialfolderpath("documents")&"/test.sqlite",,,,,,) into gConnectionID
    answer gConnectionID
    answer the files
end dbconnect
Please, if someone did this before, send me some version of it.
Thanks,

Astghik

Re: Problem of connecting Android phone and existing DB

Posted: Thu Jun 11, 2015 4:33 pm
by LCNeil
Hi Astghik,

revOpenDatabase will create a blank database if one is not present. As you are not copying the database in the copy files section of your standalone application settings, this is why no tables will be found.

Files included in copy files will also initially resided in specialFolderPath("engine") which i not a writable directory As this is the case, you will need to copy the database from here too specialFolderPath("documents").

In regards to the APK failed installation message, this is because you are using illegal characters in your apps identifier. Remove the underscore (_) and change it to something like test.app.livecode.

I hope this gives you some leads
Kind Regards,

Neil Roger
--
LiveCode Support Team ~ http://www.livecode.com
-

Re: Problem of connecting Android phone and existing DB

Posted: Thu Jun 11, 2015 8:46 pm
by AstghikM
LCNeil wrote:Hi Astghik,

revOpenDatabase will create a blank database if one is not present. As you are not copying the database in the copy files section of your standalone application settings, this is why no tables will be found.

Files included in copy files will also initially resided in specialFolderPath("engine") which i not a writable directory As this is the case, you will need to copy the database from here too specialFolderPath("documents").

In regards to the APK failed installation message, this is because you are using illegal characters in your apps identifier. Remove the underscore (_) and change it to something like test.app.livecode.

I hope this gives you some leads
Kind Regards,

Neil Roger
--
LiveCode Support Team ~ http://www.livecode.com
-
Thank you,
I just wrote the code as you told, but now i am getting another error, which is : revdberr, the database disk image is malformed, query: select * from tableTest
Please can you tell me what i am doing wrong?
the code is

Code: Select all

on mouseUp
   local filePath
   if the environment is "mobile" then

      put specialFolderPath("engine") into tpath

      put tpath & "/test.sqlite" into filePath
   else
      set the itemDelimiter to "/"
      put item 1 to -2 of the effective filename of this stack into filePath
      put filePath & "/test.sqlite" into filePath
   end if
   put filePath into field FileLocation

   put URL("file:" & specialFolderPath("engine")& "/test.sqlite") into URL("file:" & specialFolderPath("documents") & "/test.sqlite")
   
   put revOpenDatabase("sqlite",specialFolderPath("documents") & "/test.sqlite",,,,,,) into gConnectionID

   answer gConnectionID
   
   put "select * from tableTest" into t_query
   put revDataFromQuery("","",gConnectionID,t_query) into tText
   
   answer tText
end mouseUp

Re: Problem of connecting Android phone and existing DB

Posted: Thu Jun 11, 2015 8:58 pm
by Simon
Hi Astghik,
Try with binfile;

Code: Select all

put URL("file:" & specialFolderPath("engine")& "/test.sqlite") into URL("file:" & specialFolderPath("documents") & "/test.sqlite")

Code: Select all

 put URL("binfile:" & specialFolderPath("engine")& "/test.sqlite") into URL("binfile:" & specialFolderPath("documents") & "/test.sqlite")
Simon

Re: Problem of connecting Android phone and existing DB

Posted: Thu Jun 11, 2015 9:20 pm
by AstghikM
Simon wrote:Hi Astghik,
Try with binfile;

Code: Select all

put URL("file:" & specialFolderPath("engine")& "/test.sqlite") into URL("file:" & specialFolderPath("documents") & "/test.sqlite")

Code: Select all

 put URL("binfile:" & specialFolderPath("engine")& "/test.sqlite") into URL("binfile:" & specialFolderPath("documents") & "/test.sqlite")
Simon
wow, it works :) Thank you a lot

Re: Problem of connecting Android phone and existing DB

Posted: Fri Jun 12, 2015 11:59 am
by Klaus
Don't forget to check for the existence of the database file or you may overwrite it every time! :D