Component: Execute

 Show all Hide all

Executes an sql query.

SQL

SQL Call: Sql query (mandatory)

Supports custom errors: Yes
May modify database: Yes

Parameters:

@force optional bit
Set to '1' by Softadmin® when the user clicks OK in an ADMIN_FORCE message box.

Resultset: Forwarding definitions

Repeat mode:
Row count:

Columns:

<querystring_variable> optional string
Any column with no other specific meaning will pe passed along on the querystring to the menuitem you are forwarding to.
admin_AllowParameterForm optional bit
If 1 a parameter input form will be shown for the parameters not supplied as passing fields.

If 0 the parameters not supplied will have the value null.
Defaults to 1.
admin_cancelcidstepsback optional int
Number of steps in the page history to jump back if the user clicks OK in an ADMIN_MESSAGE dialog or Cancel in an ADMIN_FORCE dialog (the default being none). This value overrides cancelcidstepsback specified in the query string.
admin_cancelmenuitemid optional int
Id of the menuitem to execute if the user clicks OK in an ADMIN_MESSAGE dialog or Cancel in an ADMIN_FORCE dialog (the default being none). This value overrides cancelmenuitemid specified in the query string.
admin_cidstepsback optional int
Number of steps in the page history to jump back after execution (the default being one step back). This value overrides any destination specified by the query string.
admin_force optional string
Prompts the user with the specified text and the user may answer OK or cancel. If the user chooses OK the sql call will be rerun with the parameter @force set to 1.
admin_forward optional string
Displays a user friendly message and then forwards to the next menu item.
admin_forwardmenugroupid optional int
Id of the menu group to show after execution (instead of former menu item). This value overrides any destination specified by the query string.
admin_forwardmenuitemid optional int
Id of the menuitem to execute after execution (instead of former menu item). This value overrides any destination specified by the query string.
admin_message optional string
Displays a user friendly message to the user.
admin_pastehtmlfrompopup optional string
Pastes HTML. See admin_setfieldvaluefrompopup
admin_setfieldvaluefrompopup optional string
Sets the value of field specified in the menuitempopup call. Only select this column if menuitem is opened in popup.
admin_closepopup optional bit
If this column is anything but NULL the popup will be closed. Only select this column if the menuitem is opened in popup.
The default behavior is to step back inside the popup window and close it if there is nothing to step back to.
admin_unselect optional bit
Alias for ADMIN_UnselectAll.
admin_unselectall optional bit
If this column is anything but NULL all items are removed from the list of selected items.
By default selected items are maintained when you return to the grid/calendar. This applies even if the selected item is no longer visible in the component unless this column is specified.
Cache optional string
Cache key to be cleared. Supports wildcards.
CacheUserId optional string
Either a user id or '%'.

Clears all caches (e.g. access permissions) related to the specified user id.

Use '%' to clear caches for all users.
cancelbuttontext optional string
Changes the text of the Cancel button when used with ADMIN_Force.
okbuttontext optional string
Changes the text of the OK button when used with ADMIN_Message, ADMIN_Force, or ADMIN_Forward.

SQL Call: Validate parameters

Allows you to validate the parameters supplied by the user before any other SQL is run in the component. This call is only made if the component has visible parameters, the SQL is a stored procedure, and 'Validate parameters' is checked.
Supports custom errors: No
May modify database: No

Parameters:

@force optional bit
@validateparams mandatory bit
This parameter is set to 1 by Softadmin® when this call is made.

Custom access control and logging

SQL Call: Custom access control and logging

Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.

Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.

The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.

If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.
Supports custom errors: No
May modify database: Yes

Resultset: Access permissions

Return whether the user is allowed to visit the menu item with the current parameters.
Repeat mode: repeated exactly once
Row count: exactly one row

Columns:

GrantAccess mandatory bit
1 if the user is allowed to view the menu item, 0 if the user should not be allowed to view the menu item.

If 0 then an error will be logged as the user should not have been able to reach the menu item with the given parameters in the first place.

Examples

How to handle transactions

Avoid using nested transactions (since only the outermost matters regarding ROLLBACK or COMMIT). The following code only starts transactions when necessary, ie if one has not already been started. Make sure to look at the @IsUsingLocalTransaction parameter before any COMMITs or ROLLBACKs.

-----------------------
-- Begin transaction --
-----------------------

DECLARE
	@IsUsingLocalTransaction	bit

IF @@TRANCOUNT = 0
BEGIN
	SET XACT_ABORT ON
	BEGIN TRANSACTION

	SELECT
		@IsUsingLocalTransaction = 1
END

--------------------------
-- INSERT/UPDATE/DELETE --
--------------------------

<DML statements>

------------------------
-- Commit transaction --
------------------------

IF @IsUsingLocalTransaction = 1
BEGIN
	COMMIT TRANSACTION
END

Using progress output

This code demonstrates how to use the process functions to maintain a progress bar during processing.

CREATE TABLE #ToPostProcess
(
	ThingyId int not null
);

 /* Choose things to post-process here */
INSERT #ToPostProcess (ThingyId)
SELECT n
FROM SoftadminUtil.Number_Range(1,5);

EXEC SoftadminApi.Progress_SetTitle
	@TitleText = 'Post processing thingies';

DECLARE
	@CompletedSteps int = 0,
	@TotalSteps int = (SELECT COUNT(*) FROM #ToPostProcess);

DECLARE ThingyCursor CURSOR LOCAL FOR
SELECT
	ThingyId
FROM
	#ToPostProcess;

OPEN ThingyCursor;
WHILE 1=1
BEGIN
	EXEC SoftadminApi.Progress_SetStep
		@CompletedSteps = @CompletedSteps,
		@TotalSteps     = @TotalSteps;

	DECLARE @ThingyId int;
	FETCH ThingyCursor INTO @ThingyId;

	IF @@FETCH_STATUS <> 0
		BREAK;

	/* Post-process Thingy with id @ThingyId here */
	-- EXEC Example.Thingy_PostProcess @ThingyId = @ThingyId;

	SET @CompletedSteps += 1;
END
CLOSE ThingyCursor;
DEALLOCATE ThingyCursor;

DROP TABLE #ToPostProcess;