in reply to (ar0n) Re: sql connection
in thread sql connection

Thanks much, use is what I missed, now I went further and encountered another problem, I use Recordset to get table values, but program is terminated at $rs->RecordCount. my $rs = Win32::OLE->new('ADODB.Recordset'); $rs->Open("Select * from $SQLTABLE", $conn); if ($rs->RecordCount > 0) {...} Can you point out where might be wrong? -- PC

Replies are listed 'Best First'.
Re: Re: (ar0n) Re: sql connection
by dorko (Prior) on Nov 27, 2001 at 05:25 UTC
    You might want to try posting your code inside <code> </code> tags. It'll look like this:
    $rs->RecordCount. my $rs = Win32::OLE->new('ADODB.Recordset'); $rs->Open("Select * from $SQLTABLE", $conn); if ($rs->RecordCount > 0) {...}
    It's a little easier to read and thus a little bit more likely to get a good response to your question. Also, <code> tags allow others to easily download your code. You be amazed at how many fellow members of the Monastery will actually try out your code in order to better help you.

    You might also want to check out Writeup Formatting Tips.

    Cheers!

    Brent

Re: sql connection
by jehuni (Pilgrim) on Nov 28, 2001 at 16:43 UTC

    Not all cursor types can return a RecordCount, including the default ForwardOnly cursor type. Since you aren't explicitly specifying a cursor type, you're getting the default, in which case RecordCount will return -1.

    If you truly need the RecordCount, use either a Static or Keyset cursor. However, a Static cursor will load the entire recordset into memory, so you might want to avoid that. A Keyset on the other hand, only loads in the primary keys, and then uses that to cache subsets of the recordset. Of course, if someone adds a row in the meanwhile, it won't be available. Plus, there's extra overhead involved in the multiple roundtrips to update the cache as you navigate the recordset

    My guess is that what you really want to know is whether or not the recordset is empty. Try:

    unless ( $rs->{EOF} && $rs->{BOF} ) { ... }
    That will tell you whether or not it's empty, but can still take advantage of the efficiency of a ForwardOnly cursor.

    -jehuni