Hello,
First of all, to compile adordd.prg with Harbour, you need to add before ANNOUNCE ADORDD:
- Code: Select all Expand view
#ifndef __XHARBOUR__
#include "fivewin.ch" // as Harbour does not have TRY / CATCH
#define UR_FI_FLAGS 6
#define UR_FI_STEP 7
#define UR_FI_SIZE 7 //eram 5 ahf
#endif
Next, I have to adapt ADO_OPEN to allow Access files, as you are using DBFS with ADS:
- Code: Select all Expand view
STATIC FUNCTION ADO_OPEN( nWA, aOpenInfo )
LOCAL aWAData := USRRDD_AREADATA( nWA )
LOCAL cName, aField, oError, nResult
LOCAL oRecordSet, nTotalFields, n
LOCAL nCountIndexes // see below
/* When there is no ALIAS we will create new one using file name */
IF Empty( aOpenInfo[ UR_OI_ALIAS ] )
hb_FNameSplit( aOpenInfo[ UR_OI_NAME ],, @cName )
aOpenInfo[ UR_OI_ALIAS ] := cName
ENDIF
/*
//aOpenInfo[ UR_OI_NAME ] += ".dbf"
hb_adoSetTable( aOpenInfo[ UR_OI_NAME ] )
hb_adoSetEngine( "")
hb_adoSetServer( "")
hb_adoSetQuery( )
hb_adoSetUser( "")
hb_adoSetPassword( "" )
*/
IF Empty( aOpenInfo[ UR_OI_CONNECT ] )
IF EMPTY(oConnection)
aWAData[ WA_CONNECTION ] := TOleAuto():New( "ADODB.Connection" )
oConnection := aWAData[ WA_CONNECTION ]
aWAData[ WA_TABLENAME ] := t_cTableName
aWAData[ WA_QUERY ] := t_cQuery
aWAData[ WA_USERNAME ] := t_cUserName
aWAData[ WA_PASSWORD ] := t_cPassword
aWAData[ WA_SERVER ] := t_cServer
aWAData[ WA_ENGINE ] := t_cEngine
aWAData[ WA_CONNOPEN ] := .T.
aWAData[ WA_OPENSHARED ] := aOpenInfo[ UR_OI_SHARED ]
DO CASE
CASE Lower( Right( aOpenInfo[ UR_OI_NAME ], 4 ) ) == ".mdb"
IF Empty( aWAData[ WA_PASSWORD ] )
aWAData[ WA_CONNECTION ]:Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + aOpenInfo[ UR_OI_NAME ] )
ELSE
aWAData[ WA_CONNECTION ]:Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + aOpenInfo[ UR_OI_NAME ] + ";Jet OLEDB:Database Password=" + AllTrim( aWAData[ WA_PASSWORD ] ) )
ENDIF
CASE Lower( Right( aOpenInfo[ UR_OI_NAME ], 4 ) ) == ".xls"
aWAData[ WA_CONNECTION ]:Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + aOpenInfo[ UR_OI_NAME ] + ";Extended Properties='Excel 8.0;HDR=YES';Persist Security Info=False" )
CASE Lower( Right( aOpenInfo[ UR_OI_NAME ], 4 ) ) == ".dbf"
cStr := CFILEPATH(aOpenInfo[ UR_OI_NAME ])
cStr := SUBSTR(cStr,1,LEN(Cstr)-1)
cStr := "d:\followup-testes\tESTES FOLLOWUP.add"
//aWAData[ WA_CONNECTION ]:Open(adoconnect()) //trials
aWAData[ WA_CONNECTION ]:Open("Provider=Advantage OLE DB Provider;User ID=adssys;Data Source="+cStr+";TableType=ADS_CDX;"+;
"Advantage Server Type=ADS_LOCAL_SERVER;")
//OTHE PROVIDERS FOR DBF FOR TRIALS
// aWAData[ WA_CONNECTION ]:Open("Provider=vfpoledb.1;Data Source="+cStr+";Collating Sequence=machine;")
// aWAData[ WA_CONNECTION ]:Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + cstr + ";Extended Properties=dBASE IV;User ID=Admin;Password=;" )
CASE Lower( Right( aOpenInfo[ UR_OI_NAME ], 3 ) ) == ".db"
aWAData[ WA_CONNECTION ]:Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + aOpenInfo[ UR_OI_NAME ] + ";Extended Properties='Paradox 3.x';" )
CASE aWAData[ WA_ENGINE ] == "MYSQL"
aWAData[ WA_CONNECTION ]:Open( "DRIVER={MySQL ODBC 3.51 Driver};" + ;
"server=" + aWAData[ WA_SERVER ] + ;
";database=" + aOpenInfo[ UR_OI_NAME ] + ;
";uid=" + aWAData[ WA_USERNAME ] + ;
";pwd=" + aWAData[ WA_PASSWORD ] )
CASE aWAData[ WA_ENGINE ] == "SQL"
aWAData[ WA_CONNECTION ]:Open( "Provider=SQLOLEDB;" + ;
"server=" + aWAData[ WA_SERVER ] + ;
";database=" + aOpenInfo[ UR_OI_NAME ] + ;
";uid=" + aWAData[ WA_USERNAME ] + ;
";pwd=" + aWAData[ WA_PASSWORD ] )
CASE aWAData[ WA_ENGINE ] == "ORACLE"
aWAData[ WA_CONNECTION ]:Open( "Provider=MSDAORA.1;" + ;
"Persist Security Info=False" + ;
iif( Empty( aWAData[ WA_SERVER ] ), ;
"", ";Data source=" + aWAData[ WA_SERVER ] ) + ;
";User ID=" + aWAData[ WA_USERNAME ] + ;
";Password=" + aWAData[ WA_PASSWORD ] )
CASE aWAData[ WA_ENGINE ] == "FIREBIRD"
aWAData[ WA_CONNECTION ]:Open( "Driver=Firebird/InterBase(r) driver;" + ;
"Persist Security Info=False" + ;
";Uid=" + aWAData[ WA_USERNAME ] + ;
";Pwd=" + aWAData[ WA_PASSWORD ] + ;
";DbName=" + aOpenInfo[ UR_OI_NAME ] )
ENDCASE
ELSE
// ITS ALREDY OPE THE ADODB CONN USE THE SAME WE WANT TRANSACTIONS WITHIN THE CONNECTION
aWAData[ WA_CONNECTION ] := oConnection
aWAData[ WA_TABLENAME ] := t_cTableName
aWAData[ WA_QUERY ] := t_cQuery
aWAData[ WA_USERNAME ] := t_cUserName
aWAData[ WA_PASSWORD ] := t_cPassword
aWAData[ WA_SERVER ] := t_cServer
aWAData[ WA_ENGINE ] := t_cEngine
aWAData[ WA_CONNOPEN ] := .T.
aWAData[ WA_OPENSHARED ] := aOpenInfo[ UR_OI_SHARED ]
ENDIF
ELSE
// here we dont save oconnection for the next one because
// we assume that is not application defult conn but a temporary conn
//to other db system.
aWAData[ WA_CONNECTION ] := TOleAuto():New("ADODB.Connection")
aWAData[ WA_CONNECTION ]:Open( aOpenInfo[ UR_OI_CONNECT ] )
aWAData[ WA_TABLENAME ] := t_cTableName
aWAData[ WA_QUERY ] := t_cQuery
aWAData[ WA_USERNAME ] := t_cUserName
aWAData[ WA_PASSWORD ] := t_cPassword
aWAData[ WA_SERVER ] := t_cServer
aWAData[ WA_ENGINE ] := t_cEngine
aWAData[ WA_CONNOPEN ] := .F.
ENDIF
/* will be initilized */
t_cQuery := ""
IF Empty( aWAData[ WA_QUERY ] )
aWAData[ WA_QUERY ] := "SELECT * FROM "
ENDIF
oRecordSet := TOleAuto():New( "ADODB.Recordset" )
IF oRecordSet == NIL
oError := ErrorNew()
oError:GenCode := EG_OPEN
oError:SubCode := 1001
oError:Description := hb_langErrMsg( EG_OPEN )
oError:FileName := aOpenInfo[ UR_OI_NAME ]
oError:OsCode := 0 /* TODO */
oError:CanDefault := .T.
UR_SUPER_ERROR( nWA, oError )
RETURN HB_FAILURE
ENDIF
oRecordSet:CursorType := adOpenDynamic
oRecordSet:CursorLocation := adUseServer // adUseClient its slower but has avntages such always bookmaks
oRecordSet:LockType := adLockPessimistic
// LUCAS
//aWAData[ WA_TABLENAME ] := SUBSTR(CFILENOPATH(aWAData[ WA_TABLENAME ] ),1,LEN(CFILENOPATH(aWAData[ WA_TABLENAME ] ))-4)
IF aWAData[ WA_QUERY ] == "SELECT * FROM "
ALERT(aWAData[ WA_TABLENAME ])
oRecordSet:Open( aWAData[ WA_QUERY ] + aWAData[ WA_TABLENAME ], aWAData[ WA_CONNECTION ])
//this should allow prop index and seek adCmdTableDirect
ELSE
oRecordSet:Open( aWAData[ WA_QUERY ], aWAData[ WA_CONNECTION ],,,adCmdTableDirect )
ENDIF
aWAData[ WA_RECORDSET ] := oRecordSet
aWAData[ WA_BOF ] := aWAData[ WA_EOF ] := .F.
UR_SUPER_SETFIELDEXTENT( nWA, nTotalFields := oRecordSet:Fields:Count )
FOR n := 1 TO nTotalFields
aField := Array( UR_FI_SIZE )
aField[ UR_FI_NAME ] := oRecordSet:Fields( n - 1 ):Name
aField[ UR_FI_TYPE ] := ADO_FIELDSTRUCT( oRecordSet, n-1 )[7]
aField[ UR_FI_TYPEEXT ] := 0
aField[ UR_FI_LEN ] := ADO_FIELDSTRUCT( oRecordSet, n-1 )[3]
aField[ UR_FI_DEC ] := ADO_FIELDSTRUCT( oRecordSet, n-1 )[4]
aField[ UR_FI_FLAGS ] := 0 // xHarbour expecs this field
aField[ UR_FI_STEP ] := 0 // xHarbour expecs this field
alert(nwa)
xbrowser @afield FASTEDIT
// here error happens:
UR_SUPER_ADDFIELD( nWA, aField )
NEXT
nResult := UR_SUPER_OPEN( nWA, aOpenInfo )
IF nResult == HB_SUCCESS
ADO_GOTOP( nWA )
ENDIF
RETURN nResult
But, in UR_SUPER_ADDFIELD( nWA, aField ) i get:
Error description: Error ADORDD/1003 Argument error
Stack Calls
===========
Called from: => UR_SUPER_ADDFIELD(0)
But xbrowse shows values, so the Access database is opened.
Something wrong with aField structure?.
Thank you.