Page 1 of 1

Why I get this error?

Posted: Fri Oct 11, 2013 2:19 pm
by trevordevore
[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

Re: Why I get this error?

Posted: Fri Oct 11, 2013 2:19 pm
by trevordevore
What does the theRecordA array look like after calling sqlrecord_find?

Re: Why I get this error?

Posted: Fri Oct 11, 2013 2:19 pm
by trevordevore
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

Re: Why I get this error?

Posted: Fri Oct 11, 2013 2:20 pm
by trevordevore
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"]