work with a ADO recordset with SQLMIX

209 views
Skip to first unread message

José Quintas

unread,
Mar 16, 2020, 6:39:19 AM3/16/20
to harbou...@googlegroups.com
In general, SQLMIX works with a ADO recordset using a connection.

Is possible to work with the standard ADO recordset? with no database
defined?

cn := win_OleCreateObject( "ADODB.Connection")

...

rs := cn:Execute( "SELECT * FROM" ) // output is a ADO recordset

Rs:Save( "test.ado" ) // can save the recordset to disk

Rs:Open( test.ado" ) // can open the recordset from disk

**Only as an example, where no conection is needed on recordset


José M. C. Quintas



Alex Strickland

unread,
Mar 17, 2020, 2:56:30 AM3/17/20
to harbou...@googlegroups.com
Hi José

Yes, I do it quite a lot with sql server connections.
--
Regards
Alex
--

Alex Strickland

unread,
Mar 17, 2020, 3:09:58 AM3/17/20
to harbou...@googlegroups.com
Hi

Oops, I did not read your question carefully, I don't know but why wouldn't it work?
--
Regards
Alex
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/f6833cc9-0e15-c94a-1439-433cb7f204fa%40mweb.co.za.


--

David Field

unread,
Mar 17, 2020, 2:23:40 PM3/17/20
to Harbour Users
José,

Yes, you can work with an empty or not empty recordset that is not conected.

rs := cn:Execute( "SELECT * FROM" ) will return an SQL error since no table is defined in the statement

If you want an empty recordset all you need to do is:
oRs := win_oleCreateObject( "ADODB.Recordset" )

You can then define what fields you need with:

        oRs:Fields:Append( Name, Type, DefinedSize, Attributes )
        If Precision > 0   // Decimals
            oRs:Fields(Name):Precision = Precision
        EndIf
        If fld:NumericScale > 0
            oRs:Fields(Name):NumericScale = NumericScale
        EndIf

    //Use a client cursor
   oRs:CursorLocation = adUseClient
   oRs:CursorType = adOpenKeyset    //1
    oRs:LockType := adLockOptimistic

    //Open the recordset
   oRs:Open()

If what you want is an empty recordset with fields defined from a table you can do:
rs := cn:Execute( "SELECT * FROM clients WHERE 1=2" ) // output is a ADO recordset

This will return and empty recordset with all table clients fields defined but with no records, but it will be connected.
You can disconnect from the connection using oRs:ActiveConnection = NULL, but I have not been able to do this using Harbour since I have been told NULL is C type and different from NIL.

I have tried but does not work:
HB_FUNC( NOTHING )
{
    LONG ActiveConnection = hb_parnl( 1 );
     ActiveConnection = NULL;
}

I never thought about using SAVE() and OPEN() this way, I am trying some things and will let you know.

Regards,
David Field
Reply all
Reply to author
Forward
0 new messages