[V4RB] API Equivalent of UPDATE WHERE

Frank Schima frank-list3 at mindstarprods.com
Mon Jan 3 13:35:17 CST 2005


On Jan 3, 2005, at 1:15 PM, Ruslan Zasukhin wrote:

> On 1/3/05 9:53 PM, "Frank Schima" <frank-list3 at mindstarprods.com> 
> wrote:
>
> Hi Frank,
>
>> With all this talk about the API way being faster than SQL, I was
>> wondering what is the equivalent code for UPDATE... WHERE... with the
>> new V4RB API?
>>
>> UpdateRecord will update a single record, and UpdateAllRecords will
>> update all the records of a table/cursor. So how can I update a subset
>> of records without looping through them all and using UpdateRecord?
>>
>> Basically I'm looking for an API workaround for that UPDATE SQL
>> statement that is crashing for me. Namely:
>>
>>     UPDATE MyTable Set MyVarcharField = 'some text' WHERE 
>> MyVarcharField
>> is Null
>>
>> Pseudo-code please? :^)
>
> * But what is bad in looping ?
>     if this is local db then no problems in fact,
>     RB is fast on this.

I thought it would be slower than SQL.

> * API way will require more coding. This is a RULE.
>
>     so the pure API way can be:
>
>     set = fldVarChar.FindNulls()
>
>     Iter = set.MakeNewIterator
>     recid = Iter.first
>
>     do
>         tbl.RecID = recid
>         fldVarChar.value = "some text"
>         tbl.UpdateRecord()
>
>     while recid = iter.next

I will try this.

> * Also your task CAN be made with UpdateAllRecords() as I see.
>
>     curs = db.SqlSelect(
>                 "SELECT MyVarcharField WHERE MyVarcharField IS NULL" )
>
>     curs.VarCharField(x).valule = "someText"
>
>     curs.UpdateAllRecords()

Well i have some records with text that i want to preserve because it's 
different than 'some text'. I only want the NULL ones changed.

> * keep in mind that API way cannot do JOINS, GROUP BY and so on.
>     this is RELATIONAL Model features, mirrored in the SQL.

So SQL will still be needed then for some tasks then right?


Best regards,
Frank Schima



More information about the Valentina-beta mailing list