Page 1 of 1

ERR: Attempt to write on read-only database

Posted: Tue Jul 03, 2012 7:37 am
by genie
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? :?:

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

Posted: Tue Jul 03, 2012 8:41 am
by Mark
Hi,

Have you included the database file in your standalone?

Kind regards,

Mark

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

Posted: Tue Jul 03, 2012 9:41 am
by genie
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

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

Posted: Tue Jul 03, 2012 11:11 am
by Klaus
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

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

Posted: Tue Jul 03, 2012 11:29 am
by bn
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 :)

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

Posted: Tue Jul 03, 2012 12:07 pm
by Klaus
:D :D :D

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

Posted: Wed Jul 04, 2012 4:14 am
by genie
Whoah! I see... I did not know "engine" is read-only. haha :lol:

Thanks much for your help, Klaus! :D


Regards,
genie

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

Posted: Wed Jul 04, 2012 11:35 am
by Klaus
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