Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

sqlite file path problem
Started by haro0on.77 Nov 12 2017 06:36 AM

8 replies to this topic
sqlite filelocation readfile problem

Best Answer Rob Miracle , 13 November 2017 - 08:00 AM

Put it in the same folder as main.lua and open it from system.ResourceDirectory.

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

haro0on.77

[GLOBAL: userInfoPane.html]
haro0on.77
  • Observer

  • 27 posts
  • Corona SDK

hi bro
i have create Database by my seilf and i post it in system.DecmountDirectory and it work prefctly on corona smilutor 
but after i build it, On android device it give me error !
how can i solve it ?
--------------------------------------------------------
some part of my code 
 

 local path =system.pathForFile("data.db",system.DocumentsDirectory)
 db=sqlite3.open(path)
for row in db:nrows ("SELECT*FROM morning") do

the result on device Attached File  2017-11-12-PHOTO-0000334981.jpg   74.86KB   0 downloads



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,544 posts
  • Enterprise

How do you create the database in system.DocumentsDirectory?  You have to initialize the database somehow. If you have the sqlite database in the folder with your main.lua, that's system.ResourcesDirectory and it's read-only.

 

It's your responsibility to copy/initialize your database in a writable area like system.DocumentsDirectory.  Installing your apk file to your android device does not include your Corona simulator's sandbox folders.

 

Rob



[TOPIC: post.html]
#3

haro0on.77

[GLOBAL: userInfoPane.html]
haro0on.77
  • Observer

  • 27 posts
  • Corona SDK

I created by SQLite browser app
Then I posted in Decument By file-sandbox by simulator

[TOPIC: post.html]
#4

haro0on.77

[GLOBAL: userInfoPane.html]
haro0on.77
  • Observer

  • 27 posts
  • Corona SDK

So what I need to do after posted in same file of main.lua
And I changed file path to resource
It also give me error with different reason
See the attached fileAttached File  A5D0DFE8-65DA-4B84-9B35-35D83BE306A6.jpeg   86.5KB   0 downloads

[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,544 posts
  • Enterprise

You have to install your initial SQLite database in your project alongside your main.lua. Then you need to detect if this is the first time the app is starting (perhaps by checking to see if the SQLite database is in system.DocumentsDirectory. If you don't find it there, then you need to use the file IO functions to open the SQLite file in system.ResourceDirectory for read in binary mode, read it in, then open a file for writing in system.DocumentsDirectory in binary mode and write the data out, close both files, and then use the sqlite.* function to open the database in system.DocumentsDirectory.

 

Now for the second error, are you doing anything with widget.newButton()?

 

Rob



[TOPIC: post.html]
#6

haro0on.77

[GLOBAL: userInfoPane.html]
haro0on.77
  • Observer

  • 27 posts
  • Corona SDK

Yes I have 3 buttons

[TOPIC: post.html]
#7

haro0on.77

[GLOBAL: userInfoPane.html]
haro0on.77
  • Observer

  • 27 posts
  • Corona SDK

About the SQLite file , I want to make it read just.what I need to do ? Just posted at main.lua file !!?

[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,544 posts
  • Enterprise

  Best Answer

Put it in the same folder as main.lua and open it from system.ResourceDirectory.



[TOPIC: post.html]
#9

haro0on.77

[GLOBAL: userInfoPane.html]
haro0on.77
  • Observer

  • 27 posts
  • Corona SDK

Ok thank you.
I have solved the other problem. The other problem cursed name of image was with underscore not allowing with android
‘morning_activeButton ‘
I have changed to duch
‘morning-activeButton’ and it work fine


[topic_controls]
[/topic_controls]