Problem of connecting Android phone and existing DB

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
AstghikM
Posts: 45
Joined: Mon Sep 08, 2014 8:35 pm

Problem of connecting Android phone and existing DB

Post by AstghikM » Thu Jun 11, 2015 4:15 pm

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
Attachments
test.zip
(175.6 KiB) Downloaded 205 times

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Problem of connecting Android phone and existing DB

Post by LCNeil » Thu Jun 11, 2015 4:33 pm

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
-

AstghikM
Posts: 45
Joined: Mon Sep 08, 2014 8:35 pm

Re: Problem of connecting Android phone and existing DB

Post by AstghikM » Thu Jun 11, 2015 8:46 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Problem of connecting Android phone and existing DB

Post by Simon » Thu Jun 11, 2015 8:58 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

AstghikM
Posts: 45
Joined: Mon Sep 08, 2014 8:35 pm

Re: Problem of connecting Android phone and existing DB

Post by AstghikM » Thu Jun 11, 2015 9:20 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problem of connecting Android phone and existing DB

Post by Klaus » Fri Jun 12, 2015 11:59 am

Don't forget to check for the existence of the database file or you may overwrite it every time! :D

Post Reply