A quick question

Ruslan Zasukhin sunshine at public.kherson.ua
Fri Feb 3 21:15:32 CST 2006


On 2/3/06 8:57 PM, "Norman Palardy" <npalardy at great-white-software.com>
wrote:

> In the RB database API I would normally do
> 
> 
> dim rs as Recordset
> 
> rs = db.sqlselect ( ... some query ... )
> 
> if not ( rs  is nil ) then
> 
> while rs.eof <> true
> 
> rs.movenext
> wend
> end if

This syntax do work for RBDB API.

[OFF a little]

So in RBDB recordset was on the first record from start

I believe ODBC style says that recodset on start has position BEFORE first
record. And ODBC style use the next syntax which is the most short.

    rs = db.sqlselect ( ... some query ... )
    while( rs.NextODBC() )
    
    wend
 
If I not mistake this syntax must work for Valentina also.
Aha, we have not exposure to V4RB function NextRecordODBC().
Bad. WE will do this for next build.

But this is not primary syntax for Valentina. Read more.
Mainly because I do not like idea that recordset can have position BEFORE
first record. IMHO this is not natural idea.

> In trying to use the same style with a VCursor I found that I could not
> 
> I initially tried
> 
>      r = vdb.SqlSelect("select field1 from test2")
> 
>      if not ( r is nil ) then
> 
>        while r.position <= r.RecordCount
> 
>          if r.NextRecord then
>          end if
>        wend
> 
>      end if
> 
> expecting that r.nextRecord would make r.position exceed r.RecordCount
> and therefore terminate my loop. I see that this does not happen.

And this is again because IMHO position must NOT be AFTER last record.
Position can be in range 1 .. N
 
> I ended up writing
> 
>      r = vdb.SqlSelect("select field1 from test2")
> 
>      if not ( r is nil ) then
> 
>        done = false
>        if r.FirstRecord = false then done = true
>        end if
>        while done = false
>          Listbox1.AddRow r.VarCharField(1).GetString
> 
>          if r.NextRecord = false then
>            done = true
>          end if
>        wend
> 
>      end if
> 
> but this seems inelegant somehow. Is there something better you can
> suggest ?

First of all please note:
    I do not see code to handle ERRORS.

Valentina on error throw exception. You can disable exceptions if you want.
So your SqlSelect() call can throw and you need care about catch.

On the other hand, this means that cursor will not be NIL if all is right.
The primary syntax for Valentina cursors is:

    r = vdb.SqlSelect("select field1 from test2")

    // we check if cursor have at least one record:
    if( r.FirstRecord() ) then
        do


        while( r.NextRecord() )
    endif


-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list