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