Contents IndexCatalog stored procedures Chapter 50.  SQL Anywhere System Tables

User's Guide
   Part VI. SQL Anywhere Reference
     Chapter 49. SQL Anywhere System Procedures and Functions
      System extended stored procedures

A set of system extended procedures are included into SQL Anywhere databases. These procedures are owned by the DBO user ID that owns the Transact-SQL-compatibility system views.

The following sections describe each of the stored procedures.

Top of page


MAPI system extended stored procedures

SQL Anywhere includes a set of three system procedures for sending electronic mail using Microsoft's Messaging API standard (MAPI). These system procedures are implemented as Extended Stored Procedures: each of the procedures calls a function in an external DLL.

In order to use the MAPI stored procedures, a MAPI e-mail system must be accessible from the database server machine.

The MAPI stored procedures are:

The following procedure notifies a set of people that a backup has been completed.

     CREATE PROCEDURE notify_backup()
     BEGIN
         CALL xp_startmail( mail_user='ServerAccount',
                             mail_password='ServerPassword'
                                 );
         CALL xp_sendmail( recipient='IS Group',
                                 subject='Backup',
                                 "message"='Backup completed'
                                 );
         CALL xp_stopmail( )
     END

The MAPI system procedures are discussed in the following sections.

Top of page


xp_startmail system procedure

Purpose

To start an e-mail session.

Syntax

     [ [ variable = ] CALL ] xp_startmail (
          ...      [ mail_user = mail-login-name ]
          ...      [, mail_password = mail-password ]
          ...      )

Usage

Anywhere.

Authorization

None.

Description

xp_startmail is a system stored procedure that starts an e-mail session. It is implemented as a user-defined function.

xp_startmail returns an integer. The return value is zero if the login is successful, and non-zero otherwise.

The mail-login-name and mail-password values are strings containing the MAPI login name and password to be used in the mail session.

If you are using Microsoft Exchange, the mail_user argument is an Exchange profile name, and you should not include a password in the procedure call.

Return codes

The xp_startmail system procedure uses the following return codes:

Return code Meaning
0 Success
2 Failure

Top of page


xp_sendmail system procedure

Purpose

To send an e-mail message.

Syntax

     [ [ variable = ] CALL ] xp_sendmail (
          ... [ recipient = mail-address ]
          ... [, cc_recipient = mail-address ]
          ... [, bcc_recipient = mail-address ]
          ... [, "message" = message-body ]
          ... [, include_file = file-name ]
          ... )

Usage

Anywhere.

Authorization

Must have executed xp_startmail to start an e-mail session.

Description

xp_sendmail is a system stored procedure that sends an e-mail message once a session has been started using :name_startmail:ename.. It is implemented as a user-defined function.

xp_sendmail returns an integer. The return value is zero if the message is successfully sent, and non-zero otherwise.

The argument values are strings. The message parameter name requires double quotes around it as MESSAGE is a keyword.

Return codes

The xp_sendmail system procedure uses the following return codes:

Return code Meaning
0 Success
5 Failure (general)
11 Ambiguous recipient
12 Attachment not found
13 Disk full
14 Insufficient memory
15 Invalid session
16 Text too large
17 Too many files
18 Too many recipients
19 Unknown recipient

Example

The following call sends a message to the user ID Sales Group containing the file PRICES.DOC as a mail attachment:

     CALL xp_sendmail(recipient='Sales Group',
             subject='New Pricing',
             include_file = 'C:\\DOCS\\PRICES.DOC'
             )

Top of page


xp_stopmail system procedure

Purpose

To close an e-mail session.

Syntax

     [ variable = ] [ CALL ] xp_stopmail ()

Usage

Anywhere.

Authorization

None.

Description

xp_stopmail is a system stored procedure that starts an e-mail session. It is implemented as a user-defined function.

xp_stopmail returns an integer. The return value is zero if the mail session is successfully closed, and non-zero otherwise.

Return codes

The xp_stopmail system procedure uses the following return codes:

Return code Meaning
0 Success
3 Failure

Top of page


Other system extended stored procedures

The other system extended stored procedures included are:

The following sections provide more detail on each of these procedures.

Top of page


xp_cmdshell system procedure

Purpose

To carry out an operating system command from a procedure.

Syntax

     [ variable = CALL ] xp_cmdshell ( string )

Usage

Anywhere.

Authorization

None.

Description

xp_cmdshell is a system stored procedure that executes a system command and then returns control to the calling environment.

Example

The following statement lists the files in the current directory in the file C:\TEMP.TXT

     xp_cmdshell('dir > c:\\temp.txt')

Top of page


xp_msver system function

Purpose

To retrieve version and name information about the database engine or server.

Syntax

     xp_msver ( string )

The string must be one of the following, enclosed in string delimiters.

Argument Description
ProductName The name of the product (Sybase SQL Anywhere)
ProductVersion The version number, followed by the build number. The format is as follows:
     5.5.02 (1200)
CompanyName Returns the following string:
     Sybase Inc.
FileDescription Returns the name of the product followed by the name of the operating system.
LegalCopyright Returns a copyright string for the software
LegalTrademarks Returns trademark information for the software

Returns

String containing information appropriate to the argument.

Usage

Anywhere.

Authorization

None.

Description

xp_msver returns product, company, version, and other information.

Example

Top of page


xp_sprintf system procedure

Purpose

To build up a string from a format string and a set of input strings.

Syntax

     [ variable = CALL ] xp_sprintf ( out-string,
          ...      format-string
          ...      [ input-string, ... ] )

Usage

Anywhere.

Authorization

None.

Description

xp_sprintf is a system stored procedure that builds up a string from a format string and a set of input strings. The format-string can contain up to fifty string placeholders (%s). These placeholders are filled in by the input-string arguments.

All arguments must be strings of less than 254 characters.

Example

The following statements put the string Hello World ! into the variable mystring.

     CREATE VARIABLE mystring CHAR(254) ;
     xp_sprintf( mystring, 'Hello %s', 'World!' )

Top of page


xp_scanf system procedure

Purpose

To extract substrings from an input string and a format string.

Syntax

     [ variable = CALL ] xp_scanf ( in-string,
          ...      format-string
          ...      [ output-string, ... ] )

Usage

Anywhere.

Authorization

None.

Description

xp_scanf is a system stored procedure that extracts substrings from an input string and a format string. The format-string can contain up to fifty string placeholders (%s). The value of these placeholders in the are filled in by the output-string arguments.

All arguments must be strings of less than 254 characters.

Example

The following statements put the string World! into the variable mystring.

     CREATE VARIABLE mystring CHAR(254) ;
     xp_scanf( 'Hello World!', 'Hello %s', mystring )

Top of page


Contents IndexCatalog stored procedures Chapter 50.  SQL Anywhere System Tables