FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ayuda Mysql
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Ayuda Mysql
Posted: Tue Nov 18, 2008 02:44 PM

Aprendiendo MySql decidí hacer un programita que leyera la BBDD de ayuda nativa de este motor ( la ayuda que dá MySql es en modo consola )
si a alguien le interesa aquí les dejo el código.

include 'fivewin.ch'

include 'splitter.ch'

Static lError
Static oWnd
Static oLink
Static oSay
Static cDescripcion

                    Function main()

Set Date To British
Set Century On
Define Window oWnd Mdi

oWnd : SetText( "Ayuda nativa MySql" )
oWnd : SetMenu( MainMenu() )

Activate Window oWnd Maximized On Init HallaTabla()
Return 0

                    Function MainMenu()

Local oMenu

Menu oMenu
MenuItem "Opciones"
Menu
Menuitem "&Salir" Action oWnd : End()
EndMenu
EndMenu
Return oMenu
Function HallaTabla()

Local aTitle := {}
Local aRegistro := {}
Local aDatos := {}
Local cCadena := Alltrim( GetPvProfString( "Cadena Conexion","Cadena","", CurDrive() + ":\" + CurDir() + "\help_mysql.ini" ) )
Local oCn
Local e
Local oRe
Local nPos
Local oTablas
Local n
Local aInfo

lError := .f.
REQUEST HB_LANG_ES
HB_LANGSELECT("ES")
Try
oCn :=CreateObject("ADODB.Connection")
oCn : Open( "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=mysql;User=root;Password=root;Option=3;" )
oRe := CreateObject("ADODB.RecordSet")
oRe : CursorType := 3 // opendkeyset
oRe : CursorLocation := 3 // local cache
oRe : LockType := 3
oRe : ActiveConnection( oCn )
oRe : Source( "Select help_topic_id, name, description, example from help_topic Order by name" )
oRe : Open()
While( !oRe : Eof )
aRegistro := {}
For nPos := 0 to oRe : Fields : Count - 1
AAdd( aRegistro, Value( oRe, nPos ) )
Next nPos
Aadd( aDatos, aRegistro )
oRe : MoveNext()
Enddo
oRe : Close()
Catch e
MsgStop( "ERROR!!!! " + e:Description + '--' + e : Operation + '--' + Alltrim( Str( e:genCode ) ), "Atención !!!" )
lError := .t.
End
If( !lError )
MuestraSql( aDatos, aTitle, oRe )
End
Return 0

                    Function MuestraSql( aDatos, aTitles, oRe )

Local oWinH
Local cTitle := ''
Local nSegundos := SECONDS()
Local oSplitter
Local i
Local oTree
Local oFont
Local oFont1
Local oBrw
Local oImgList
Local oReBar
Local oToolBar

cTitle += "Total Registros: " + Alltrim(Str(Len(aDatos) ) )

nSegundos := SECONDS() - nSegundos

Define Font oFont Name 'Arial' Size 0, -10
Define Font oFont1 Name 'Arial' Size 0, -12

Define Window oWinH MDICHILD Of oWnd From 0,0 to 0, 0 Title cTitle Pixel NoSysMenu

oWinH : Hide()
oImgList := TImageList() : New( 32, 32 )
oImgList : AddMasked( TBitmap() : Define( "#8052" ,, oWinh ), nRGB( 255,255,255 ) )
oImgList : AddMasked( TBitmap() : Define( "#8054" ,, oWinh ), nRGB( 255,255,255 ))

oReBar := TReBar() : New( oWinh )

oToolBar := TToolbar() : New( oReBar, 50, 50, oImgList )
oToolBar : AddButton( { || oWinh:End() } , "Salir", " Salir ")
oToolBar : AddSeparator()
oToolBar : AddButton( { || .t. } , "Excel", "Excel")

AEval( oToolBar : aButtons, { | aBtn, nBtn| CAMBIA_EL_SIZE_DEL_BOTON( oToolBar : hWnd,;
nBtn, nOr( 0x0010 ) ) } )

oReBar : InsertBand( oToolBar )
oWinH : Hide()
Define Statusbar Prompt Alltrim( Str( nSegundos ) ) + " Segundos..." OF oWinh PROMPTS cTitle

@ 47, 285 Get oSay Var cDescripcion Memo Size 535, oWnd : nHeight - 124 Of oWinh Pixel Font oFont1

@ 47, 01 TREEVIEW oTree SIZE 279, oWnd : nHeight Of oWinh PIXEL
oTree : bChanged := { || BuscaExplicacion( oTree, aDatos ) }
_ArmarTree( oTree, aDatos )

@ 47, 280 Splitter oSplitter Vertical Previous Controls oTree Hinds Controls oSay Size 5, oWnd : nHeight - 124 Of oWinh Pixel _3D

Activate Window oWinh On Init( oTree : Expand(), oWinH : Show() ) Valid ( oFont : End(), oFont1 : End(), aDatos := Nil, oBrw := Nil, .t.) ;
On Resize oSplitter : Adjust( .t., .t., .t., .t. )
oWinh : Maximize()
Return 0

                    Function _ArmarTree( oTree, aDatos )

Local oDatabase
Local nStep, i, aCursos
Memvar oVarGlobales

oDatabase := oTree : Add( "TÓPICOS" )
For i := 1 To Len( aDatos )
oLink := oDatabase : Add( Alltrim( aDatos[ i ][ 2 ] ), 3, 2 )
oLink : Cargo := aDatos[ i ][ 1 ]
Next i
oTree : SetFocus()
Return oTree

                       Function BuscaExplicacion( oTree, aDatos )

Local I
Local nId
Local cDescrip
Local cCodigo_id

oLink := oTree : GetSelected()
cCodigo_id := oLink : Cargo

nId := Ascan( aDatos, { | x, y | x[ 1 ] == cCodigo_id } )
cDescripcion := ''
If( nId != 0 )
cDescrip := aDatos[ nId ][ 3 ]
For i := 1 To Len( cDescrip )
If( Asc( SubStr( cDescrip, i, 1 ) ) == 10 )
cDescripcion += CRLF
Else
cDescripcion += SubStr( cDescrip, i, 1 )
End
Next i
If( Len( aDatos[ nId ][ 4 ] ) > 0 )
cDescrip := aDatos[ nId ][ 4 ]
cDescripcion += CRLF + 'Examples' + CRLF + CRLF
For i := 1 To Len( cDescrip )
If( Asc( SubStr( cDescrip, i, 1 ) ) == 10 )
cDescripcion += CRLF
Else
cDescripcion += SubStr( cDescrip, i, 1 )
End
Next i
End
Else
cDescripcion := ''
End
oSay : Refresh()
Return 0

                    Function Value(oRs,nPos)

Local xVar := oRs:Fields(nPos):Value

    // ------------------------------------------ //
    // vemos de que tipos es y lo pasamos a string
    // ------------------------------------------ //
DO CASE
    CASE Valtype(xVar)=="C"
     If( Len( xVar ) == 1 .and. xVar == 'T' )
        xVar := .t.
     ElseIf( Len( xVar ) == 1 .and. xVar == 'F' )
        xVar := .f.
     Else
        xVar := OemToAnsi( xVar )
     End
    CASE Valtype(xVar)=="N" ; xVar := Str(xVar)
    CASE Valtype(xVar)=="D" ; xVar := DTOC(xVar)
    CASE Valtype(xVar)=="L" ; xVar := iif(xVar,"TRUE", "FALSE")
    OTHERWISE               ; xVar := ""
ENDCASE

Return xVar

pragma BEGINDUMP

#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"

/-----------------------------------------------------------------------------------------------/
HB_FUNC( CAMBIA_EL_SIZE_DEL_BOTON ){
TBBUTTONINFO tbutton;
tbutton.cbSize = sizeof( tbutton );
tbutton.dwMask = TBIF_STYLE;
SendMessage( ( HWND ) hb_parnl( 1 ), TB_GETBUTTONINFO, ( WPARAM ) hb_parni( 2 ), (LPARAM) &tbutton );
tbutton.fsStyle = hb_parni( 3 );
SendMessage( ( HWND ) hb_parnl( 1 ), TB_SETBUTTONINFO, ( WPARAM ) hb_parni( 2 ), (LPARAM) &tbutton );
}

pragma ENDDUMP

Continue the discussion