Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RI Messages
Message
From
13/08/2003 18:06:30
 
 
To
13/08/2003 16:05:58
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00819926
Message ID:
00819958
Views:
10
>If I setup RI for a field so that deletion is restricted, when a user tries to delete a parent record for which multiple child records exists, he gets an error.
>
>"Unable to commit changes- delete trigger failed"
>
>This is exactly what I want to happen, except i would like to display a friendlier message that would make sense to the ordinary user.
>
>How can I display my own message instead?

Steve,

You'll need a general error routine and activate it with
ON ERROR YourErrorRoutine(Error(), Program(), LineNo() )
in there
#define	ERROR_TABLE_FIELD_DOES_NOT_ACCEPT_NULL_VALUES	1581
#define	ERROR_TABLE_FIELD_RULE_VIOLATED	1582
#define	ERROR_TABLE_TRIGGER_FAILED		1539
#define	ERROR_TABLE_RULE_VIOLATED		1583
#define	ERROR_TABLE_KEY_NOT_UNIQUE		1884

#define	nKEY_CR				13
#define CR		chr(nKEY_CR)

#define	MESSAGE_TABLE_TRIGGER_FAILED_INSERT ;
			'Cannot insert '

#define	MESSAGE_TABLE_TRIGGER_FAILED_UPDATE ;
			'Cannot modify '
	#define	MESSAGE_TABLE_TRIGGER_FAILED_Delete ;
			'Cannot delete '

#define	MESSAGE_CHANGE_OR_UNDO 'Correct or UNDO the changes'

procedure YourErrorRoutine(nError, _program, _lineno  )

local	_Error[1], _Table, _msg
=aerror(_Error)

do case
case _Error[1] == ERROR_TABLE_TRIGGER_FAILED
        _Table = GetTableName(_error[4])
	_msg = _Table + ': '
	do case
	case _Error[5] == 1		&& Insert
		_msg = _msg + MESSAGE_TABLE_TRIGGER_FAILED_INSERT + CR + MESSAGE_CHANGE_OR_UNDO
	case _Error[5] == 2		&& Update
		_msg = _msg + MESSAGE_TABLE_TRIGGER_FAILED_UPDATE + CR + MESSAGE_CHANGE_OR_UNDO
	case _Error[5] == 3		&& Delete
		_msg = _msg + MESSAGE_TABLE_TRIGGER_FAILED_DELETE
	endcase

        = MessageBox( _msg, MB_ICONEXCLAMATION, 'Hell' )

case ....

otherwise
 ....
endcase
*--------------------------------------------------------------------------
function	GetTableName(wa)
	local _alias
	
	_alias = iif(empty(wa), alias(), alias(wa) )
	if( !empty(cursorgetprop('DataBase', _alias)) )
		return proper(cursorgetprop('SourceName', _alias))
	else
		return Proper(_alias)
	endif
endfunc
*--------------------------------------------------------------------------
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform