// f_check_for_block()
// Displays warning if there are any blocked connections.
// Returns 0 if there are no blocked connections
// nnn if there are nnn blocked connections
// -1 if some other error was detected
long ll_this_connection
long ll_blocked_by_connection
string ls_this_userid
string ls_blocked_by_userid
long ll_previous_connection
string ls_warning
long ll_blocked_count
ls_warning = ""
ll_blocked_count = 0
SQLCA.DBMS = "ODB"
SQLCA.DBParm = "ConnectString='DSN=TinyDB;UID=DBA;PWD=gzornenplatz'"
CONNECT USING SQLCA;
IF SQLCA.SQLCode <> 0 THEN
MessageBox ( "Error", "CONNECT failed" )
RETURN -1
END IF
// Get the first connection number.
ll_this_connection = 0
SELECT Next_Connection ( NULL )
INTO :ll_this_connection
FROM sys.dummy
USING SQLCA;
IF SQLCA.SQLCode <> 0 THEN
MessageBox ( "Error", "SELECT first connection failed" )
RETURN -1
END IF
IF IsNull ( ll_this_connection ) THEN
ll_this_connection = 0
END IF
DO WHILE ll_this_connection <> 0
// Check for the number of the connection that's blocking this one.
ll_blocked_by_connection = 0
SELECT Connection_Property ( 'BlockedOn', :ll_this_connection )
INTO :ll_blocked_by_connection
FROM sys.dummy
USING SQLCA;
IF SQLCA.SQLCode <> 0 THEN
MessageBox ( "Error", "SELECT BlockedOn failed" )
RETURN -1
END IF
// Record information about the blocked connection.
IF ll_blocked_by_connection <> 0 THEN
ll_blocked_count++
// Get the userids for the two connections.
ls_this_userid = ""
ls_blocked_by_userid = ""
SELECT Connection_Property ( 'UserID', :ll_this_connection ),
Connection_Property ( 'UserID', :ll_blocked_by_connection )
INTO :ls_this_userid,
:ls_blocked_by_userid
FROM sys.dummy
USING SQLCA;
IF SQLCA.SQLCode <> 0 THEN
MessageBox ( "Error", "SELECT UserIDs failed" )
RETURN -1
END IF
// Record information about the blocked connection.
IF ls_warning <> "" THEN
ls_warning = ls_warning + "~r~n"
END IF
ls_warning = ls_warning + "User " &
+ Upper ( ls_this_userid ) + " (" &
+ String ( ll_this_connection ) &
+ ") is blocked by " &
+ Upper ( ls_blocked_by_userid ) + " (" + &
+ String ( ll_blocked_by_connection ) + ")"
END IF
// Get the next connection number.
ll_previous_connection = ll_this_connection
ll_this_connection = 0
SELECT Next_Connection ( :ll_previous_connection )
INTO :ll_this_connection
FROM sys.dummy
USING SQLCA;
IF SQLCA.SQLCode <> 0 THEN
MessageBox ( "Error", "SELECT later connection failed" )
RETURN -1
END IF
IF IsNull ( ll_this_connection ) THEN
ll_this_connection = 0
END IF
LOOP
DISCONNECT USING SQLCA;
IF SQLCA.SQLCode <> 0 THEN
MessageBox ( "Error", "DISCONNECT failed" )
RETURN -1
END IF
IF ls_warning <> "" THEN
MessageBox ( "Warning", ls_warning )
END IF
RETURN ll_blocked_count