CREATE SERVICE "alice/files" AUTHORIZATION OFF USER DBA TYPE ‘RAW’ URL OFF AS CALL get_file();
http://www.host.com/alice/files/business/overview, how does our service use the remainder of the URL (the
'business/overview'part in this case)?
The answer lies in the
URL parameter of the service definition. The
URL parameter can take three values, and the default value is
URL OFF. With
URL OFF, the service will not be used unless the URL identically matches the service name. So this case, not only can we not use the remaining part of the URL, but the service simply won’t work.
To allow access to the remaining part of the URL, we have two options. The first is to set
URL ON. When
ON, a variable called
:url is automatically created that contains the remaining part of the URL. Let’s say we altered the service to be:
ALTER SERVICE "alice/files" AUTHORIZATION OFF USER DBA TYPE ‘RAW’ URL ON AS CALL get_file(:url);
:urlvariable that contains
'business/overview‘, and we can pass that to the stored procedure that handles this service. The drawback to
URL ONis that even if the remaining URL contains many elements, it will still only be captured as a single string. This is where the
URL ELEMENTSis useful.
URL ELEMENTS works differently. Instead of creating a single variable called :url that contains the whole string, it creates many variables each representing a part of the URL. These variables are called
:url1, :url2, ... , :url10. It will create as many variables as there are parts to the URL up to a maximum of 10.
URL ON, the
:urlvariable would contain the entire string
'Mens/Polo_Shirt/Large‘. By using
URL ELEMENTS, you instead end up with three strings:
:url1 = 'Mens':url2 = 'Polo_Shirt':url3 = 'Large'
CREATE SERVICE "Catalog" AUTHORIZATION OFF USER DBA TYPE ‘RAW’ URL ELEMENTS AS CALL get_price(:url1, :url2, :url3)