PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Sean Roe on November 21, 2004, 02:49:47 PM

Title: ADO Disconnected Recordsets
Post by: Sean Roe on November 21, 2004, 02:49:47 PM
I like using ADO Disconnected Recordsets, so I want to make sure by checking with you and Jose that I am doing it correctly.

I declare a variant variable like vNothing and then use the following call to set it pointing to nothing with a dispatch interface:

FF_AdoMakeDispatchVariant 0, vNothing

Then after opening up a recordset with a Cursor Location of adUseClient, I make the following call:

FF_AdoRecordset_SetActiveConnection(lpRecordset, vNothing)

This should make the recordset disconnected and from what I can tell, it does. Just wanted to make sure I am not missing something.

Or would it be better to do something like this:

vNothing = 0
FF_AdoRecordset_SetActiveConnection(lpRecordset, vNothing)

I have also had success with

FF_AdoRecordset_SetActiveConnection(lpRecordset, 0)

The funny thing is right after this call I check FF_AdoResult. With my first example I get a 0 with the others I get a negative number. My next line uses IF NOT FF_AdoResult THEN  and the if statement gets executed with all three examples.

A read through the FF_ADO.inc file is informative. I really want to give you and Jose a big thank you for all your work with the ADO stuff.
Title: ADO Disconnected Recordsets
Post by: Jose Roca on November 21, 2004, 03:45:27 PM
The first way is the correct, because ADO expects a dispatch variant containing a valid connection handle (or null to disconnect) or a variant containing a connection string. If you get something <> 0 in FF_AdoResult this means that the call has failed and the recordset has been not disconnected.

FF_AdoMakeDispatchVariant 0, vNothing
FF_AdoRecordset_SetActiveConnection(lpRecordset, vNothing)

To allow to use FF_AdoRecordset_SetActiveConnection(lpRecordset, 0) I will have to modify the following code in the function

   if variant#(pVar) > 0 then
      lpvObj = varptr(vCon)
      @lpvObj.vt = %VT_DISPATCH
      @lpvObj.vd.pdispVal = variant#(pVar)
   else
      vCon = pvar
   end if

To

   if VARIANTVT(pVar) <> %VT_BSTR then
      lpvObj = varptr(vCon)
      @lpvObj.vt = %VT_DISPATCH
      @lpvObj.vd.pdispVal = variant#(pVar)
   else
      vCon = pvar
   end if

I didn't remembered disconnected recordsets when I wrote the function  :oops: . Well, versions 1.0 are never perfect :)
Title: ADO Disconnected Recordsets
Post by: Sean Roe on November 21, 2004, 03:51:51 PM
Actually Jose I like the first way anyway. You included the FF_AdoMakeDispatchVariant function anyway and I thought that is what one of it's uses was for. I was just playing around with other ways to do this. Thanks for the explaination.

We have had this conversation before over on PB's forum prior to FireFly. So I was adding a function that was like FF_AdoMakeDispatchVariant. I thought you might have added something like this to FireFly so I started to read FF_ADO.inc. That is when I spotted this function and then I went down to read the FF_AdoRecordset_SetActiveConnection and thought maybe I could just pass a Variant with a 0 or just a 0 but as usual you are right, this does not disconnect the recordset. Only the first way disconnects the recordset.

Thanks again.
Title: ADO Disconnected Recordsets
Post by: Jose Roca on November 21, 2004, 03:55:57 PM
Yes, I have remembered the discussion:
http://www.powerbasic.com/support/forums/Forum6/HTML/003585.html

The code that I posted in my reply does the same that FF_AdoMakeDispatchVariant.

  LOCAL vVar AS VARIANT
  LOCAL lpv AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
  lpv = VARPTR(vVar)                          ' Get the VARIANT address
  @lpv.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
  @lpv.vd.pdispVal = 0                        ' Set the dispatch pointer address


Quote
Actually Jose I like the first way anyway. You included the FF_AdoMakeDispatchVariant function anyway and I thought that is what one of it's uses was for.
Right. It can be used in all the cases were we only have a pointer variable and the function expects a dispatch variant. But as many users don't have this knowledge, I have tried to make life easier for them doing the conversion inside the function. Now passing 0 fails because I only make the conversion is the value is > 0.
Title: ADO Disconnected Recordsets
Post by: Sean Roe on November 21, 2004, 04:16:05 PM
Would changing the code


   if variant#(pVar) > 0 then
      lpvObj = varptr(vCon)
      @lpvObj.vt = %VT_DISPATCH
      @lpvObj.vd.pdispVal = variant#(pVar)
   else
      vCon = pvar
   end if


To


   if variant#(pVar) >= 0 then
      lpvObj = varptr(vCon)
      @lpvObj.vt = %VT_DISPATCH
      @lpvObj.vd.pdispVal = variant#(pVar)
   else
      vCon = pvar
   end if



In FF_AdoRecordset_SetConnection enable the user to pass a valid pointer in or 0 to determine to disconnect from the connection or reconnect the recordset to the connection.

I modified FF_ADO.inc to this second way and ran this call:

FF_AdoRecordset_SetActiveConnection(lpRecordset,0)

And it disconnected the recordset.
Title: ADO Disconnected Recordsets
Post by: Jose Roca on November 21, 2004, 04:42:24 PM
Yes, but the correct instruction is if VARIANTVT(pVar) <> %VT_BSTR then, because otherwise you couldn't pass an string to set a connection, since VARIANT#(pVar) will evaluate as 0 if it contains an string.
Title: ADO Disconnected Recordsets
Post by: Sean Roe on November 21, 2004, 04:47:48 PM
Sorry, my mistake for not reading your other posting more closely. I see now what it is really trying to do.

Thanks.