...
DATA oMysql // TMySQL recordset if Method Setmysql() is used
...
METHOD SetMySql( oMysql, lAddCols, lAutoOrder, aFldNames ) // TMySql object
METHOD SetColFromMySQL( cnCol, cHeader ) // used internally from mysql
...
...
METHOD Initiate( hDlg ) CLASS TXBrowse
...
...
if Empty( ::nDataType ) .or. Empty( ::aCols )
if ! Empty( ::aArrayData )
if lAnd( ::nDataType, DATATYPE_RDD )
::SetRDD( .t., nil, nil, ::aArrayData )
elseif lAnd( ::nDataType, DATATYPE_ODBF ) .and. !Empty( ::oDbf )
::SetODbf( ::oDbf, nil, nil, .t., ::aArrayData )
else
::SetArray( ::aArrayData )
endif
elseif ! Empty( ::oRs )
::SetADO( ::oRs )
elseif ! Empty( ::oMysql )
::SetMysql( ::oMysql )
...
...
METHOD SetMySql( oMysql, lAddCols, lAutoOrder, aFldNames )
LOCAL xField := NIL
LOCAL cHeader := ""
LOCAL cCol := ""
DEFAULT oMysql := ::oMysql
DEFAULT aFldNames := {}
DEFAULT lAddCols := Empty( ::aCols ) .or. ! Empty( aFldNames )
DEFAULT lAutoOrder := ::lAutoSort
::oMysql := oMysql
DEFAULT ::bGoTop := {|| If( ::oMysql:RecCount() > 0, ::oMysql:GoTop(), NIL ) },;
::bGoBottom := {|| If( ::oMysql:RecCount() > 0, ::oMysql:GoBottom(), nil ) },;
::bSkip := {| n | ::oMysql:Skip( n ) },;
::bBof := {|| ::oMysql:Bof() },;
::bEof := {|| ::oMysql:Eof() },;
::bBookMark := {| n | If( n == nil,;
If( ::oMysql:RecCount() > 0, ::oMysql:RecNo(), 0 ), ;
If( ::oMysql:RecCount() > 0, ::oMysql:goto( n ), 0 ) ) }, ;
::bKeyNo := {| n | If( n == nil, ;
If( ::oMysql:RecCount() > 0, ::oMysql:RecNo(), 0 ), ;
If( ::oMysql:RecCount() > 0, ::oMysql:Goto( n ), 0 ) ) },;
::bKeyCount := {|| ::oMysql:RecCount() }
::nDataType := DATATYPE_MYSQL
IF lAddCols
IF Len(aFldNames) == 0
aFldNames := ::oMysql:aFieldStruct
ENDIF
FOR EACH xField IN aFldNames
IF Valtype( xField ) == "A" .AND. Len(xField) == 2
cCol := xField[1]
cHeader := xField[2]
ELSEIF Valtype( xField ) == "A" .AND. Len(xField) # 2
cCol := xField[1]
cHeader := xField[1]
ELSE
cCol := xField
cHeader := xField
ENDIF
::SetColFromMySQL( cCol, cHeader )
NEXT
::bSeek := { |c| MysqlSeek( ::oMysql, c, , ::lSeekWild ) }
ENDIF
if ::lCreated
::Adjust()
::Refresh()
endif
RETURN Self
//----------------------------------------------------------------------------//
METHOD SetColFromMySQL( cnCol, cHeader )
LOCAL nType, cType, nLen, nDec, cName
LOCAL oCol, nCol
IF ValType( cnCol ) == "C"
nCol := ::oMysql:FieldPos( cnCol )
ENDIF
nCol := cnCol
oCol := ::AddCol()
oCol:cHeader := cHeader
cType := ::oMysql:FieldType( nCol )
nLen := 0
nDec := 0
DO CASE
CASE cType == 'N'
nLen := ::oMysql:FieldLen( nCol )
nDec := ::oMysql:FieldDec( nCol )
oCol:cEditPicture := NumPict( nLen, nDec, .F., .f. )
CASE cType == 'C'
nLen := MIN( 100, ::oMysql:FieldLen( nCol ) )
CASE cType == 'M'
nLen := MIN( 100, Len(AllTrim(::oMysql:FieldGet( nCol ))) )
nLen := IF(nLen < 30, 30, nLen )
CASE cType == 'D'
oCol:nHeadStrAlign := 2
oCol:nDataStrAlign := 0
CASE cType == NIL
// some types like adChapter( child recset), etc. can not be shown
// programmer who uses such types should make his own coding for
// such columns
oCol:bEditValue := { || "..." }
OTHERWISE
// just in case. this will not be executed
oCol:bEditValue := { || MSGINFO( "Abriendo fronteras, wmormar...", FWDESCRIPTION ) }
ENDCASE
oCol:bEditValue := { || ::oMysql:FieldGet( nCol ) }
oCol:cDataType := If( cType == nil, 'C', cType )
oCol:bOnPostEdit := { |o,x,n| If( n == VK_RETURN, ::onedit( o, x, n, cType, nCol ), NIL ) }
RETURN oCol
//----------------------------------------------------------------------------//
static function MysqlSeek( oMysql, uSeek, lSoft, lWildSeek )
local lFound := .f.
local cCol := oMysql:cSort
local cExpr := ''
local cType, d, uVal
if ! Empty( cCol ) .and. ! oMysql:Eof() .and. ! oMysql:Bof()
DEFAULT lSoft := Set(_SET_SOFTSEEK), lWildSeek := .f.
uVal := oMysql:FieldGet( cCol )
cType := oMysql:FieldType( cCol )
do case
case cType == 'C'
if lWildSeek
lSoft := .f.
cExpr := cCol + " LIKE '%" + uSeek + "%'"
else
cExpr := If( Set( _SET_EXACT ), cCol + " = '" + uSeek + "'", ;
cCol + " LIKE '" + uSeek + "%'" )
endif
case cType == 'N'
cExpr := cCol + " >= " + ;
LTrim( Str( Val( uSeek ) ) )
case cType == 'D'
if Empty( d := CToD( uSeek ) )
d := CToD( uSeek + SubStr( DToC( uVal ), Len( uSeek ) + 1 ) )
endif
if ! Empty( d )
cExpr := cCol + " >= #" + ;
StrZero( Year( d ), 4 ) + "-" + ;
StrZero( Month( d ), 2 ) + "-" + ;
StrZero( Day( d ), 2 ) + "#"
endif
endcase
if ! Empty( cExpr )
oMysql:WSeekplus( cExpr, oMysql:cSort, oMysql:recno() )
if oMysql:Eof() .and. lSoft .and. cType == 'C'
oMysql:GoTop()
cExpr := cCol + " > '" + uSeek + "'"
oMysql:WSeekplus( cExpr, oMysql:cSort, oMysql:recno() )
endif
if oMysql:Eof()
oMysql:GoBottom()
else
lFound := .t.
endif
endif
endif
return lFound
//----------------------------------------------------------------------------//
METHOD Adjust() CLASS TXBrwColumn
....
....
....
DEFAULT ::bOnPostEdit := { |o,x,n| If( n != VK_ESCAPE, ::Value := x,) }
if ::cSortOrder != nil
if ValType( ::cSortOrder ) != 'B'
if ( ::oBrw:nDataType == DATATYPE_RDD )
if EQ( (::oBrw:cAlias)->( OrdSetFocus() ), ::cSortOrder )
::cOrder := 'A'
endif
elseif ( ::oBrw:nDataType == DATATYPE_ADO )
if EQ( ::oBrw:oRs:Sort, ::cSortOrder )
::cOrder := 'A'
endif
elseif ( ::oBrw:nDataType == DATATYPE_MYSQL )
if EQ( ::oBrw:oMysql:cSort, ::cSortOrder )
::cOrder := 'A'
endif
....................
............................
METHOD SetOrder() CLASS TXBrwColumn
............................
............................
elseif nAnd( ::oBrw:nDataType, DATATYPE_ADO ) == DATATYPE_ADO .and. ;
::oBrw:oRs != nil
cSort := Upper( ::oBrw:oRs:Sort )
cSort := TRIM( StrTran( StrTran( cSort, 'DESC', '' ), 'ASC', '' ) )
if EQ( cSort, ::cSortOrder )
// Asc -> Desc or Desc -> Asc
if ::cOrder == 'D'
::oBrw:oRs:Sort := ::cSortOrder
::cOrder := 'A'
else
::oBrw:oRs:Sort := ::cSortOrder + " DESC"
::cOrder := 'D'
endif
lSorted := .T.
else
// Asc Sort
::oBrw:oRs:Sort := ::cSortOrder
For n := 1 TO Len(::oBrw:aCols)
oCol := ::oBrW:aCols[ n ]
oCol:cOrder := " "
Next n
::cOrder := 'A'
lSorted := .T.
endif
elseif nAnd( ::oBrw:nDataType, DATATYPE_MYSQL ) == DATATYPE_MYSQL .and. ;
::oBrw:oMysql != nil
cSort := Upper( ::oBrw:oMysql:cSort )
cSort := TRIM( StrTran( StrTran( cSort, 'DESC', '' ), 'ASC', '' ) )
if EQ( cSort, ::cSortOrder )
// Asc -> Desc or Desc -> Asc
if ::cOrder == 'D'
::oBrw:oMysql:cSort := ::cSortOrder
::cOrder := 'A'
else
::oBrw:oMysql:cSort := ::cSortOrder + " DESC"
::cOrder := 'D'
endif
lSorted := .T.
else
// Asc Sort
::oBrw:oMysql:Sort := ::cSortOrder
For n := 1 TO Len(::oBrw:aCols)
oCol := ::oBrW:aCols[ n ]
oCol:cOrder := " "
Next n
::cOrder := 'A'
lSorted := .T.
endif
elseif nAnd( ::oBrw:nDataType, DATATYPE_ODBF ) == DATATYPE_ODBF .and. ;
............................
............................
static function XbrwSetDataSource( oBrw, uDataSrc, lAddCols, lAutoSort, aCols, aRows )
............................
............................
elseif cType == 'O'
if Upper( uDataSrc:ClassName() ) == "TMYSQL"
oBrw:nDataType := DATATYPE_MYSQL
oBrw:oMysql := uDataSrc
if lAddCols .or. ! Empty( aCols )
oBrw:SetMysql( uDataSrc, lAddCols, lAutoSort, aCols )
endif
elseif Upper( uDataSrc:ClassName ) == "TOLEAUTO"
............................
............................