#include "FiveWin.ch"
#include "Ado.ch"
#include "inkey.ch"
#include "xBrowse.ch"
Static oWnd
//-------------------------------------------------------------------------------------
Function Main()
Public lMysql:=.F.
Request DBFFPT, DBFCDX
RDDSETDEFAULT("DBFCDX")
SET OPTIMIZE ON
SET EPOCH TO 1920
SET DATE FORMAT "dd/mm/yyyy"
SET WRAP ON
SET DELETED ON
DEFINE WINDOW oWnd FROM 1, 1 TO 25, 79 MDI ;
TITLE "Test Traffic" Menu BuildMenu()
ACTIVATE WINDOW oWnd MAXIMIZED
Return Nil
//--------------------------------------------------------------------
//--------------------------------------------------------------------
Function BuildMenu()
local oMenu
MENU oMenu 2007
MENUITEM "ADO"
MENU
MENUITEM "Ado Test" ACTION AdoTest()
ENDMENU
MENUITEM "DBF"
MENU
MENUITEM "DBF Test" ACTION DBFTest()
ENDMENU
MENUITEM "Exit"
MENU
MENUITEM "End" ACTION oWnd:End()
ENDMENU
ENDMENU
Return oMenu
//--------------------------------------------------------------------
//--------------------------------------------------------------------
Function Conectar()
Local Retorno:=.F.
Local rs, oErr,oCs
Local odbcli
Local cSelect
Public oCn
TRY
oCn:= CreateObject( "ADODB.Connection" )
oCs:= "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=192.168.0.1; DATABASE=test; UID=adolfo; PWD=300966"
oCn:Open(oCs)
Retorno:=.T.
CATCH oErr
MSGAlert("Error : No se tiene acceso al servidor de MYSQL " + CRLF + "por favor verifique conexion a red o que el servidor este funcionando", "Error: " + oErr:Operation + " -> " + oErr:Description )
Retorno:=.F.
END
Return Retorno
//-------------------------------------------------------------------------------------------------------------------------------------
//---------- Mysql Browse ------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
Function AdoTest()
Local oWndMain:=WndMain()
Local lExit:=.F.
Local oRcs
Local cSelect:="select RUT,RAZON,DIRECCION from CLIENTES order by RAZON"
Local oErrorAdo
Local TBO:=0
Local TAO:=0
Local TDO:=0
Local TBX:=0
Local TAX:=0
Local TDX:=0
If !Conectar()
Return Nil
Endif
TBO:=Seconds()
oRcs:=TOleAuto():New("ADODB.recordset")
oRcs:CursorLocation:= adUseClient
oRcs:LockType := adLockOptimistic
oRcs:CursorType := adOpenDynamic
oRcs:CacheSize := 30
oRcs:PageSize := 30
TRY
oRcs:Open(cSelect,oCn)
CATCH
FOR EACH oErrorAdo IN oCn:Errors
ShowError(oErrorAdo)
NEXT
END
oRcs:MoveFirst()
lMysql:=.T.
TAO:=Seconds()
TDO:=TAO - TBO
TBX:=Seconds()
Define Font oFontBold NAME "Arial" SIZE 9, 15 BOLD
DEFINE WINDOW oWnd02 FROM 1, 1 TO 25, 79 TITLE "MYSQL XBrowse Incremental Search" STYLE nOr( WS_CAPTION, WS_VISIBLE, WS_SYSMENU )
oBrw:=TxBrowse():New(oWnd02)
oBrw:nTop:=0
oBrw:nLeft:=0
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
oBrw:nColDividerStyle := LINESTYLE_BLACK
oBrw:nRowDividerStyle := LINESTYLE_BLACK
oBrw:lColDividerComplete := .T.
oBrw:l2007 :=.T.
oBrw:lAutoSort :=.T.
oBrw:bClrSelFocus := { | | { 16777215, 9539840 } }
aClrRow := { { CLR_BLACK, 14737602 }, { CLR_BLACK, 16777215 } }
oBrw:bClrStd := {|| aClrRow[ oBrw:KeyNo % 2 + 1 ] }
oBrw:nHeaderLines := 1
oBrw:nDataLines := 1
oBrw:lHScroll := .F.
oBrw:lVScroll := .T.
oBrw:lFooter := .T.
oBrw:bClrFooter := { || {CLR_HBLUE,CLR_WHITE} }
oBrw:bKeyDown :={| nKey, nFlags | MyKeyDown(nKey, nFlags, oBrw) }
oBrw:bKeyChar :={| nKey, nFlags | MyKeyChar(nKey, nFlags, oBrw) }
oBrw:SetAdo(oRcs)
oBrw:bSeek := { | c | SeekIncremental(UPPER(c),oRcs,"RAZON") }
oBrw:CreateFromCode()
oWnd02:oClient := oBrw
oBrw:SetFoCus()
SET MESSAGE OF oWnd02 TO " " 2007
DEFINE MSGITEM oBrw:oSeek OF oWnd02:oMsgBar ;
PROMPT "BUSQUEDA DE DATOS" ;
SIZE 350 COLOR CLR_RED FONT oFontBold
ACTIVATE WINDOW oWnd02 MAXIMIZED VALID ( oWnd02 := nil, lExit := .T. , .T.) ;
ON INIT (TAX:=Seconds() , TDX:=TAX-TBX , .T. )
StopUntil( {|| lExit} )
If oWndMain != nil
oWndMain:Show()
SysRefresh()
Endif
oRcs:Close()
SysRefresh()
MsgAlert( Str(TDO,10,5) + CRLF + STR(TDX,10,5) )
Return Nil
//-----------------------------------------------------------------------------------------------------------
Function MyKeyDown( nKey, nFlags, oBrw)
Return 0
//-----------------------------------------------------------------------------------------------------------
Function MyKeyChar( nKey, nFlags, oBrw )
Do Case
Case nKey == K_ENTER
ShowRecord(lMysql)
Endcase
Return 0
//-----------------------------------------------------------------------------------------------------------
Function ShowError(oError)
MsgInfo( "Descripción : " + oError:Description + CRLF + ;
"Error Nativo : " + Str(oError:NativeError) + CRLF + ;
"Número Error : " + Str(oError:Number) + CRLF + ;
"Origen : " + oError:Source + CRLF + ;
"Estado SQL : " + oError:SQLState )
Return nil
//-------------------------------------------------------------------------------------------------------------------------------------
//---------- DBF Browse ------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
Function DbfTest()
Local oWndMain:=WndMain()
Local lExit:=.F.
Local TBO:=0
Local TAO:=0
Local TDO:=0
Local TBX:=0
Local TAX:=0
Local TDX:=0
TBO=Seconds()
Use P:\TEST\clientes Alias Cli
Set Order To 1
DbGoTop()
lMysql:=.F.
TAO:=Seconds()
TDO:=TAO - TBO
TBX:=Seconds()
Define Font oFontBold NAME "Arial" SIZE 9, 15 BOLD
DEFINE WINDOW oWnd02 FROM 1, 1 TO 25, 79 TITLE "DBF XBrowse Incremental Search" STYLE nOr( WS_CAPTION, WS_VISIBLE, WS_SYSMENU )
oBrw:=TxBrowse():New(oWnd02)
oBrw:nTop:=0
oBrw:nLeft:=0
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
oBrw:nColDividerStyle := LINESTYLE_BLACK
oBrw:nRowDividerStyle := LINESTYLE_BLACK
oBrw:lColDividerComplete := .T.
oBrw:l2007 :=.T.
oBrw:lAutoSort :=.T.
oBrw:bClrSelFocus := { | | { 16777215, 9539840 } }
aClrRow := { { CLR_BLACK, 14737602 }, { CLR_BLACK, 16777215 } }
oBrw:bClrStd := {|| aClrRow[ oBrw:KeyNo % 2 + 1 ] }
oBrw:nHeaderLines := 1
oBrw:nDataLines := 1
oBrw:lHScroll := .F.
oBrw:lVScroll := .T.
oBrw:lFooter := .T.
oBrw:bClrFooter := { || {CLR_HBLUE,CLR_WHITE} }
oBrw:bKeyDown :={| nKey, nFlags | MyKeyDown(nKey, nFlags, oBrw) }
oBrw:bKeyChar :={| nKey, nFlags | MyKeyChar(nKey, nFlags, oBrw) }
// oBrw:SetRdd()
Add Column To oBrw DATA Cli->Rut
Add Column To oBrw DATA Cli->Razon
Add Column To oBrw DATA Cli->Direccion
oBrw:bSeek := {|c| DbSeek( Upper( c ) ,.T.) }
oBrw:CreateFromCode()
oWnd02:oClient := oBrw
oBrw:SetFoCus()
SET MESSAGE OF oWnd02 TO " " 2007
DEFINE MSGITEM oBrw:oSeek OF oWnd02:oMsgBar ;
PROMPT "BUSQUEDA DE DATOS" ;
SIZE 350 COLOR CLR_RED FONT oFontBold
ACTIVATE WINDOW oWnd02 MAXIMIZED VALID ( oWnd02 := nil, lExit := .T. , .T.) ;
ON INIT (TAX:=Seconds(),TDX:=TAX-TBX , .T. )
StopUntil( {|| lExit} )
If oWndMain != nil
oWndMain:Show()
SysRefresh()
Endif
MsgAlert( Str(TDO,10,5) + CRLF + STR(TDX,10,5) )
Close All
SysRefresh()
Return Nil
Adolfo wrote:ADO's is slower when getting data, and also consumes more bandwith when you first call the xbrowse,but... thats all, after the job is done, no more net traffic is present.
FUNCTION SeekIncremental(cBuscar,oRcs,cOrden)
LOCAL nLen:=Len(cBuscar)
STATIC nLenAnt
DEFAULT nLenAnt:=0
IF Len(cBuscar)>1
IF(nLenAnt>nLen,oRcs:MoveFirst(),)
oRcs:Find( cOrden + " like '"+cBuscar+"*'",,1)
ELSE
oRcs:MoveFirst()
IF !Empty(cBuscar)
oRcs:Find( cOrden + " like '"+cBuscar+"*'",,1)
ENDIF
ENDIF
nLenAnt:=nLen
RETURN !(oRcs:Eof .OR. oRcs:Bof)
reinaldocrespo wrote:I'm not sure if you already did, but would you please point again to that thread where you publish your tado class?
Thank you,
Reinaldo.
Adolfo wrote:Paging does a good trick when retrieving data is involved...
Enrico Maria Giordano wrote:Adolfo wrote:Paging does a good trick when retrieving data is involved...
Sorry, but paging can't be achieved using standard SQL, that was my earlier objection.
EMG
mmmEnrico Maria Giordano wrote:You are using LIMIT clause that is NOT standard SQL.
EMG
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 8 guests