LOCAL cSql := "EXECUTE PROCEDURE sp_mgGetConnectedUsers()"
reinaldocrespo wrote:Dutch;
Execute stored procedure sp_mgGetConnectedUsers() to get a cursor with the list of connected users. Like this:
- Code: Select all Expand view
LOCAL cSql := "EXECUTE PROCEDURE sp_mgGetConnectedUsers()"
Using AdsCreateSqlStatement() and AdsExeucteSqlDirect() you can execute this sql.
Reinaldo.
cAlias := "cursor"
cSql := "EXECUTE PROCEDURE sp_mgGetConnectedUsers()"
ADSCreateSQLStatement( cAlias )
AdsExecuteSQLDirect( cSql )
While !(cAlias)->( eof() )
? (cAlias)->Username, (cAlias)->Address, (cAlias)->DictionaryUser
(cAlias)->( dbSkip() )
EndWhile
AdsCreateSqlStatemtn( cArea )
CheckForErrors()
AdsExecuteSqlDirect( cSql )
CheckForErrors()
//------------------------------------
Function CheckForErrors()
local nErr, cErr
If (nErr := AdsGetLastError( @cError ) ) != 0
msgError( cError, nErr )
Endif
return nil
*------------------------------------------------------------------------------------------------------
METHOD ShowConnectedUsers() CLASS MpAdmin
LOCAL cSql := "EXECUTE PROCEDURE sp_mgGetConnectedUsers()"
LOCAL cSeek , cUser, cTable
LOCAL aData := {}
LOCAL aCursor, bChange, bGetConnUsers
LOCAL aChildData := {}
LOCAL bDelete
LOCAL oSelf := Self
LOCAL oDlg, oGet1, oBrw, oChildBrw, oSay, oChkBx
LOCAL isLoginsEnabled := !ADSDDGetDatabaseProperty( ADS_DD_LOGINS_DISABLED )
IF ifOpenOption( 'CONNECTEDUSERS' )
RETURN NIL
ENDIF
aCursor := ExecuteSqlScript( cSql, .f. )
aEval( aCursor, { |e,n| aadd( aData, { e[ 3 ], e[ 4 ], e[ 1 ] } ) } )
bGetConnUsers := { || aCursor := ExecuteSqlScript( cSql, .f. ), ;
aData := {}, ;
aEval( aCursor, { |e,n| aadd( aData, { e[ 3 ], e[ 4 ], e[ 1 ] } ) } ),;
oBrw:aArrayData := aData,;
oBrw:Refresh() ,; //needed here in case nArrayAt was past eof. to avoid run time error
Eval( bChange ),;
oDlg:Update(),;
oBrw:Refresh() }
bChange := { || oChildBrw:aArrayData := ;
IF( Len( oBrw:aArrayData ) > 0 .and. Len( oBrw:aArrayData[ oBrw:nArrayAt ] ) > 2, ;
ExecuteSqlScript( "EXECUTE PROCEDURE SP_mgGetUserTables('" + ;
alltrim( oBrw:Computer:Value() ) + "' );", .f. ),;
{} ),;
aEval( oChildBrw:aArrayData, { |e,n| hb_FNameSplit( e[ 1 ],,@cTable ),;
oChildBrw:aArrayData[ n,1 ] := Lower( cTable ) } ),;
oChildBrw:Refresh() }
bDelete := { || IF( len( oBrw:aArrayData ) > 0 .and. ;
( cUser := alltrim( oBrw:aArrayData[ oBrw:nArrayAt, 3 ] ),;
MsgYesNo( "Disconnect User " + cUser ) ), ;
( ExecuteSqlScript( "EXECUTE PROCEDURE sp_mgKillUser( '"+cUser+"' );", .f. ),;
Eval( bGetConnUsers ) ), NIL ) }
DEFINE DIALOG oDlg RESOURCE "CONNECTED_USERS" OF ::oPanelBrowse ;
TRANSPARENT COLOR CLR_BLACK, RGB(240,240,240)
REDEFINE XBROWSE oBrw ID 1 OF oDlg ;
ARRAY aData AUTOCOLS AUTOSORT;
HEADER "User", "ip", "Computer" ;
SIZES 120,100, 100 ;
ON CHANGE Eval( bChange )
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLWIN7
oBrw:bClrStd := { || If( oBrw:KeyNo % 2 == 1, { CLR_BLUE, CLR_WHITE }, { CLR_BLUE, RGB(242,242,255)} ) }
oBrw:bKeyDown := {|nkey| IF( nkey = K_DEL, ( Eval( bDelete ), ;
Eval( bGetConnUsers ) ), NIL ) }
REDEFINE GET oGet1 Var cSeek ID 101 OF oDlg WHEN .f.
oBrw:oSeek := oGet1
REDEFINE SAY oSay PROMPT "Total Connections: " + cValToChar( Len( aData ) ) ;
ID 102 OF oDlg COLOR CLR_BLACK UPDATE
REDEFINE CHECKBOX oChkBx VAR isLoginsEnabled ID 4 OF oDlg
oChkBx:bChange := { || AdsDDSetDatabaseProperty( ADS_DD_LOGINS_DISABLED, !isLoginsEnabled ) }
setGridProperties( oBrw, .f. )
REDEFINE XBROWSE oChildBrw ID 2 OF oDlg ;
ARRAY aChildData AUTOCOLS AUTOSORT;
HEADER "Table Alias" ;
SIZES 150
setGridProperties( oChildBrw, .f. )
oChildBrw:bClrStd := { || If( oChildBrw:KeyNo % 2 == 1, { CLR_BLUE, CLR_WHITE }, { CLR_BLUE, RGB(242,242,255)} ) }
REDEFINE BUTTONBMP ID 201 OF oDlg BITMAP "Cancel16" TEXTRIGHT ACTION Eval( bDelete )
REDEFINE BUTTONBMP ID 202 OF oDlg BITMAP "run16" TEXTRIGHT ;
ACTION Eval( bGetConnUsers )
REDEFINE BUTTONBMP ID 203 OF oDlg BITMAP "exit16" TEXTRIGHT ACTION oDlg:END()
oDlg:lHelpIcon := .F.
FONDOBOTONES 1003, oDlg
ACTIVATE DIALOG oDlg NOWAIT ;
ON INIT ( oDlg:Center( oSelf:oPanelBrowse ), Eval( bChange ), oBrw:setFocus() ) ;
VALID closeOption( 'CONNECTEDUSERS' )
AADD( aOpenOptions, { 'CONNECTEDUSERS', oDlg } )
RETURN NIL
*-------------------------------------------------------------------------------------------------------------------------------
FUNCTION ExecuteSQLScript( cScript, lShowProgress, nTblType, lCursor, bProgress, cMsg )
Local cArea := ValidAlias( "SqlFunc" )
local aStruc, i
local nCount := 1
local a := {}
local xTmp, oMeter
local isGood := .f.
DEFAULT lShowProgress := .t.
DEFAULT nTblType := ADS_ADT
DEFAULT lCursor := .f.
nErr := 0 ;cErr := ""
if !empty( cScript )
AdsCacheOpenCursors( 0 )
DBSELECTAREA(0)
if Select( cArea ) > 0 ; ( cArea )-> ( DBCLOSEAREA() ) ;endif
IF !ADSCreateSQLStatement(cArea, nTblType ) //.or. !ADSVerifySQL( cScript )
nErr := ADSGetLastError( @cErr )
logfile( "SQLError.log", { nErr, cErr, cScript } )
if Select( cArea ) > 0 ; ( cArea )-> ( DBCLOSEAREA() ) ;endif
Else
if lShowProgress
if bProgress == Nil
DEFAULT cMsg := "Working..."
/*oMeter:= msgMeter():New( 100 )
bProgress := { |n| oMeter:Set( n ) } /**/
oMeter := PROGRESSBAR():New( 100, cMsg )
ACTIVATE DIALOG oMeter:oDlg NOWAIT ON INIT oMeter:oDlg:center( WndMain() )
bProgress := { |n| oMeter:Update( n, .t. ) }
endif
Register_CallBack( { | nPercent | nCount++, ;
iif( nCount * nPercent > 100, nCount := 1, ), ;
Eval( bProgress, nPercent ) } )
isgood := ADSExecuteSQLDirect( cScript )
Unregister_callback()
if oMeter != Nil
oMeter:end()
endif
else
isgood := ADSExecuteSQLDirect( cScript )
endif
if isgood
if ( nErr := ADSGetLastError( @cErr ) ) != 0
logfile( "SQLError.log", { "ADS error:", nErr, cErr, cScript } )
endif
if lCursor ;return( cArea ) ;endif
a := GetCursorContents( cArea, cScript, lShowProgress, bProgress )
Else
logfile( "SQLError.log", { nErr := ADSGetLastError( @cErr ), cErr, cScript } )
ENDIF
AdsCacheOpenCursors( 0 )
if Select( cArea ) > 0 ; (cArea)->( DBCLOSEAREA() ) ;endif
#ifndef PATHOLOGY
//pathlabs and billing still built with xharb 0.99.6 uncompatible with newer
//rddads using hb_adsGetWorkAreaPointer();
#ifndef BILLING
AdsCloseSQLStatement()
#ENDIF
#ENDIF
Endif
endif
Return a
//------------------------------------------------------------------------------
FUNCTION GetCursorContents( cArea, cScript, lShowProgress, bProgress )
LOCAL aStruc, e
LOCAL a := {}
LOCAL nCount := 1
LOCAL i, xTmp, oMeter
LOCAL nLastRec := (cArea)->( lastrec() )
IF lShowProgress .and. bProgress == NIL
oMeter := PROGRESSBAR():New( 100, "Downloading Result Set", 1 )
ACTIVATE DIALOG oMeter:oDlg NOWAIT ON INIT oMeter:oDlg:center( WndMain() )
bProgress := { |nPercent| oMeter:Update( nPercent ) }
ENDIF
IF Select( cArea ) > 0 .AND. (cArea)->( lastrec() ) > 0
TRY
aStruc := (cArea)->( dbStruct() )
a := array( nLastRec )
WHILE !(cArea)->( eof() )
a[ nCount ] := array( len( aStruc ) ) //{}
afill( a[nCount], " " )
IF lShowProgress
EVAL( bProgress, ( nCount / nLastRec ) * 100 ) //oMeter:Update( nCount )
IF oMeter != NIL .and. oMeter:isCancel ;BREAK ;ENDIF
ENDIF
FOR i := 1 to len( aStruc )
xTmp := NIL
TRY
xTmp := ( cArea )->( FieldGet( i ) )
IF xTmp == Nil ;xTmp := blank( aStruc[ i, DBS_TYPE ] ) ;Endif
CATCH e
LogError( e, i, cScript )
END
a[ nCount, i ]:= xTmp
NEXT i
nCount++
(cArea)->( dbSkip() )
END
CATCH e
LogError( e, i, cScript )
a := {}
END
ENDIF
IF lShowProgress .and. bProgress == NIL ; oMeter:end() ;ENDIF
aSize( a, nCount-1 )
RETURN a
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 74 guests