Why I get this error?

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: 914
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Why I get this error?

Post by trevordevore » Fri Oct 11, 2013 2:19 pm

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

HI,

I try to update a record.

Code: Select all

put "NUMBER is :1 and ID_CUSTOMER is :2" into theParamsA["conditions"] 
 
   put gNumDoc into theParamsA["condition bindings"][1]
   put gCustomerID into theParamsA["condition bindings"][2]
 
   sqlrecord_find "DOCUMENT", theParamsA, theRecordA 
 
   sqlrecord_set theRecordA,"DO_INVOICE",1
 
   sqlrecord_update theRecordA

But I get the error "you must assign a valid table to a record". Why?

Salut,
Josep
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: 914
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Why I get this error?

Post by trevordevore » Fri Oct 11, 2013 2:19 pm

What does the theRecordA array look like after calling sqlrecord_find?
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: 914
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Why I get this error?

Post by trevordevore » Fri Oct 11, 2013 2:19 pm

The array have the record values but with a index like:

Code: Select all

theRecordA[1]["DO_INVOICE"]
Using "sqlquery_update" all is fine. What is the difference between them? Cursor versus query? So with sqlquery_update only I must modify the updated values but with sqlrecord_update I must fill all the values before, isn't?


Salut,

Josep
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: 914
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Why I get this error?

Post by trevordevore » Fri Oct 11, 2013 2:20 pm

Although the docs don't explain this very well (I've updated them for the next release), sqlrecord_find behaves differently based on whether or not you pass an array in for the second param.

When you pass in an array for the search conditions an array of SQL Record objects is returned. This is why you see the [1]. When you pass in a string then a single SQL Record object is returned.

In your case you could just do this:

Code: Select all

put theRecordA[1]["DO_INVOICE"] into theRecordA
Now you can call sqlrecord_set and it should work. You can just pass theRecordA[1] to sqlrecord_set because LiveCode does not yet support passing array subkeys by reference.

Note: I don't know if the version of SQL Yoga that you are using supports this but the next release will have a "find" property that you can pass in. If you set it to "first" then a single SQL Record object will be returned rather than an array of SQL Record objects.

Code: Select all

put "first" into theParamsA["find"]
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”