ORACLE Y ADO
Posted: Tue Dec 25, 2007 9:29 am
Llevo varios dias intentando sacar un browse desde una DB-Oracle, pero la cosa se resiste. Consigo sin problemas, abrir la DB, descargar el RecordSet, pero despues el browse sale vacio. Acompaño el código por si alguien me puede dar una ayudita.
#include "Fivewin.ch"
FUNCTION Main()
local cHost := '127.0.0.1'
local cUser := 'hr'
local cPass := 'hr'
local oRs, oBrw, oDlg
local oCon := TOLEAuto():New('ADODB.Connection')
// conexion a Oracle
TRY
oCon:Open("Provider='MSDAORA.1';" + ;
"Data Source= " + cHost + ";" + ;
"User ID=" + cUser + ";" + ;
"Password=" + cPass + ";" )
CATCH
msgstop("Error conexión ADODB")
quit
END
// recordset
oRs := TOleAuto():New("adodb.recordset")
oRs:CursorLocation := 2 // adUseServer adUseClient
oRs:LockType := 3 // adLockOptimistic
oRs:CursorType := 1 // adOpenKeyset
oRs:Source := "Select * from regions"
oRs:ActiveConnection(oCon)
TRY
oRs:Open( )
CATCH
msgstop("Error conexión RecordSet")
quit
END
oRs:MoveFirst()
IF oRs:EOF .or. oRs:BOF
msgstop ("Fichero vacio")
quit
ENDI
DEFINE DIALOG oDlg ;
TITLE "Indice de Datos" ;
FROM 0, 0 TO 25, 99
@ 1, 2 LISTBOX oBrw FIELDS ;
oRs:Fields("REGION_ID"):value, ;
oRs:Fields("REGION_NAME"):value ;
HEADERS "Número","Región" ;
FIELDSIZES 80,150 ;
SIZE 356,135 OF oDlg
oBrw:bLogicLen = { || oRs:RecordCount }
oBrw:bGoTop = { || oRs:MoveFirst() }
oBrw:bGoBottom = { || oRs:MoveLast() }
oBrw:bSkip = { | nSkip | Skipper( oRs, nSkip ) }
oBrw:cAlias = "ARRAY"
ACTIVATE DIALOG oDlg CENTER
oRs:CLOSE()
oCon:CLOSE()
RETURN nil
STATIC FUNCTION SKIPPER( oRs, nSkip )
LOCAL nRec := oRs:AbsolutePosition
oRs:Move( nSkip )
IF oRs:EOF; oRs:MoveLast(); ENDIF
IF oRs:BOF; oRs:MoveFirst(); ENDIF
RETURN oRs:AbsolutePosition - nRec
#include "Fivewin.ch"
FUNCTION Main()
local cHost := '127.0.0.1'
local cUser := 'hr'
local cPass := 'hr'
local oRs, oBrw, oDlg
local oCon := TOLEAuto():New('ADODB.Connection')
// conexion a Oracle
TRY
oCon:Open("Provider='MSDAORA.1';" + ;
"Data Source= " + cHost + ";" + ;
"User ID=" + cUser + ";" + ;
"Password=" + cPass + ";" )
CATCH
msgstop("Error conexión ADODB")
quit
END
// recordset
oRs := TOleAuto():New("adodb.recordset")
oRs:CursorLocation := 2 // adUseServer adUseClient
oRs:LockType := 3 // adLockOptimistic
oRs:CursorType := 1 // adOpenKeyset
oRs:Source := "Select * from regions"
oRs:ActiveConnection(oCon)
TRY
oRs:Open( )
CATCH
msgstop("Error conexión RecordSet")
quit
END
oRs:MoveFirst()
IF oRs:EOF .or. oRs:BOF
msgstop ("Fichero vacio")
quit
ENDI
DEFINE DIALOG oDlg ;
TITLE "Indice de Datos" ;
FROM 0, 0 TO 25, 99
@ 1, 2 LISTBOX oBrw FIELDS ;
oRs:Fields("REGION_ID"):value, ;
oRs:Fields("REGION_NAME"):value ;
HEADERS "Número","Región" ;
FIELDSIZES 80,150 ;
SIZE 356,135 OF oDlg
oBrw:bLogicLen = { || oRs:RecordCount }
oBrw:bGoTop = { || oRs:MoveFirst() }
oBrw:bGoBottom = { || oRs:MoveLast() }
oBrw:bSkip = { | nSkip | Skipper( oRs, nSkip ) }
oBrw:cAlias = "ARRAY"
ACTIVATE DIALOG oDlg CENTER
oRs:CLOSE()
oCon:CLOSE()
RETURN nil
STATIC FUNCTION SKIPPER( oRs, nSkip )
LOCAL nRec := oRs:AbsolutePosition
oRs:Move( nSkip )
IF oRs:EOF; oRs:MoveLast(); ENDIF
IF oRs:BOF; oRs:MoveFirst(); ENDIF
RETURN oRs:AbsolutePosition - nRec