ERR: Attempt to write on read-only database

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

ERR: Attempt to write on read-only database

Post by genie » Tue Jul 03, 2012 7:37 am

My database works perfectly on development mode and on the simulator... but when I deploy the app to the device, I cannot do UPDATEs and INSERTs. :(

Code: Select all

   dbConnect
   put getDbID() into tDatabaseID

   put "UPDATE subjects SET email='" & vemail & "', birthdate='" & vdate & "', height='" & vheight & "', weight='" & vweight & "',  firstname='" & vfname & "', lastname='" & vlname & "', distributor='" & vdistnum & "', gender='" & vgender & "', smoker='" & vsmoker & "', fruitserving='" & vfruits & "', vegeserving='" & vvege & "' WHERE email='" & gEmail & "'" into tSQL

   revExecuteSQL tDatabaseID, tSQL
   answer the result  -- {attempt to write on read-only database}
What can I do so that users can have write permissions to the DB? :?:

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: ERR: Attempt to write on read-only database

Post by Mark » Tue Jul 03, 2012 8:41 am

Hi,

Have you included the database file in your standalone?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: ERR: Attempt to write on read-only database

Post by genie » Tue Jul 03, 2012 9:41 am

Hi Mark!

Thanks for your response...

Yes! I have included my .sqlite file in the standalone, under 'copy files'. In fact, I can retrieve data out of my table...I just can't modify anything in it. :(

This piece of code can retrieve data...

Code: Select all

   dbConnect
   put getDbID() into tDatabaseID
   put revDataFromQuery(tab,return,tDatabaseID,"SELECT * FROM subjects") into tRecords
   answer tRecords
but this one returns error... :(

Code: Select all

   dbConnect
   put getDbID() into tDatabaseID
   put "UPDATE subjects SET email='" & vemail & "', birthdate='" & vdate & "', height='" & vheight & "', weight='" & vweight & "',  firstname='" & vfname & "', lastname='" & vlname & "', distributor='" & vdistnum & "', gender='" & vgender & "', smoker='" & vsmoker & "', fruitserving='" & vfruits & "', vegeserving='" & vvege & "' WHERE email='" & gEmail & "'" into tSQL  
   revExecuteSQL tDatabaseID, tSQL

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

Re: ERR: Attempt to write on read-only database

Post by Klaus » Tue Jul 03, 2012 11:11 am

Hi genie,

sounds like you only added your DB file with the "Copy files" tab of the standalone maker, right?
In that case your db will be in:
...
specialfolderpath("engine") &"/your_db_file.db"
...
But you do not have WRITE permission in that folder, you can only read!
That's why a "select" will work, but an "update" (write recoreds/changes) will not.

EDITED because Bernd is SO mean :cry:

Copy your DB file to the DOCUMENTS folder and you are done:

Code: Select all

on preopenstack
  put specialfolderpath("documents") & "/your_db_file.db" into tDB
  put specialfolderpath("engine") &"/your_db_file.db" into tDBINLINE
  if there is NOT a FILE tDB then
      put url("binfile:" & tDBINLINE) into url("binfile:" & tDB)
  end if
## Now you can refer to that file and and also WRITE to the db
...
end preopenstack
This must have been discussed for at least 500 times in the iOS forum (sic!) 8)

Best

Klaus (das alte Fickel)

P.S.
Bernd is dohf!
:D :D :D

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: ERR: Attempt to write on read-only database

Post by bn » Tue Jul 03, 2012 11:29 am

Hi Klaus,
This must have been discussed for at least 500 times in the iOS forum
sure but this is the first time we test for

Code: Select all

if there is NOT a fikel tDB then
or

Code: Select all

put ul("binfile:" & tDBINLINE) into url("bifile:" & tDB)
the amazing richness of the language :)

kind regards
Bernd (the fikel)

please delete this post once the fikel is gone, just could not resist and did not even try to, either :)

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

Re: ERR: Attempt to write on read-only database

Post by Klaus » Tue Jul 03, 2012 12:07 pm

:D :D :D

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: ERR: Attempt to write on read-only database

Post by genie » Wed Jul 04, 2012 4:14 am

Whoah! I see... I did not know "engine" is read-only. haha :lol:

Thanks much for your help, Klaus! :D


Regards,
genie

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

Re: ERR: Attempt to write on read-only database

Post by Klaus » Wed Jul 04, 2012 11:35 am

Hi genie,
genie wrote:I did not know "engine" is read-only.
well, checking the "iOS Release Notes" from time to time isn't a bad idea actually... 8)


Best

Klaus

Post Reply