completely lost on updating a record

This is the place to post technical queries about SQL Yoga

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, trevordevore

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 919
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

completely lost on updating a record

Post by trevordevore » Fri Oct 11, 2013 1:58 pm

[This post is an archive from old SQL Yoga forums]

I have the following code to find a specific record in my "book" table and then change the "display_page" field...

Code: Select all

 sqlyoga_setDefaultDatabase "Library"

   put sqlquery_createObject("book") into theQueryA

   put sqlrecord_createObject("book") into theRecordA

   sqlquery_set theQueryA, "conditions", "filename is ':1'", gTheBookFileName

   sqlquery_retrieveAsRecords theQueryA, theRecordA

   sqlrecord_set theRecordA, "display_page", gdisplay_page

   sqlrecord_set theRecordA, "filename", gTheBookFileName

   sqlrecord_update theRecordA 
Everything goes well up to the actual sqlrecord_update command.

I successfully find the record, modify the record object with the new "display_page" value.

(I had to add the "filename" value as this is the primary key and it complained when it was not being updated.)

but when it tries to execute the sqlrecord_update I get the following error:

sqlyoga_executesql_err,0,0,book.name may not be NULL (UPDATE book SET current_book = NULL,id = NULL,name = NULL,display_page = :1 WHERE filename = 'ACourseinMiracl1340788553.sqlite')

Now I can both see where this comes from but also don't.

In the record object there are indeed "NULL"s against the mentioned fields.

But they are also mentioned in the "passthru" entry and have valid values in the returned record entry.

The record object looks like this:

Code: Select all

theRecordA

   1

         @table   <->  book

         current_book   <->  yes

         display_page   <->  Text/combined_volume_002.html

         filename  <->  ACourseinMiracl1340788553.sqlite

         id   <->    a9f10048-1812-4141-bed7-c69ec69c27ea

         name   <->   Course in Miracles 

   @connection  <->   the_Library

   @database  <->   Library

   @passthru  <->   name,id,current_book

   @table  <->   book

    current_book   <->  NULL

    display_page   <->  Text/combined_volume_030.html

    filename  <->  ACourseinMiracl1340788553.sqlite

    id   <->    NULL

    name   <->   NULL
How should I be doing this?
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 919
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: completely lost on updating a record

Post by trevordevore » Fri Oct 11, 2013 1:58 pm

I found a solution.

Code: Select all

  put sqlrecord_createObject("book") into theRecordA

   sqlrecord_find "book", gTheBookFileName, theRecordA

   sqlrecord_set theRecordA, "display_page", gdisplay_page

   sqlrecord_update theRecordA 
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

Post Reply

Return to “SQL Yoga”