Hiding the contents of procedures, functions, and views

In some cases, you may want to distribute an application and a database without disclosing the logic contained within procedures, functions, triggers and views. As an added security measure, you can obscure the contents of these objects using the SET HIDDEN clause of the ALTER PROCEDURE, ALTER FUNCTION, and ALTER VIEW statements.

The SET HIDDEN clause scrambles the contents of the associated objects and makes them unreadable, while still allowing the objects to be used. You can also unload and reload the objects into another database.

The modification is irreversible, and for databases created using Sybase IQ 12.6 or higher, deletes the original text of the object. Preserving the original source for the object outside the database is required.

Debugging using the stored procedure debugger will not show the procedure definition, nor will procedure profiling display the source.

Running one of the above statements on an object that is already hidden has no effect.

To hide the text for all objects of a particular type, you can use a loop similar to the following:

begin 
	for hide_lp as hide_cr cursor for 
		select proc_name,user_name
		from SYS.SYSPROCEDURE p, SYS.SYSUSERPERM u
		where p.creator = u.user_id 
		and p.creator not in (0,1,3)
	do
		message 'altering ' || proc_name;
		execute immediate 'alter procedure "' 
			|| user_name || '"."' || proc_name 
			|| '" set hidden'
	end for 
end

For more information, see “ALTER FUNCTION statement,” in the Adaptive Server Anywhere SQL Reference Manual, “ALTER PROCEDURE statement,” and “ALTER VIEW statement” in the Sybase IQ Reference Manual.