![]() | ![]() |
Home |
|
|
Reference Manual |
|
| Chapter 9: System Extended Stored Procedures |
This chapter describes the system extended stored procedures (ESPs), which are extended stored procedures supplied by Sybase.
Table 9-1 lists the system extended stored procedures discussed in this chapter.
Procedure | Description | Platform |
|---|---|---|
Executes a native operating system command on the host system running Adaptive Server. | All Supporting DLLs | |
Deletes a message from the Adaptive Server message inbox. | NT Only | |
Displays groups for a specific Windows NT domain. | NT Only | |
Retrieves the message identifier of the next message in the Adaptive Server message inbox. | NT Only | |
Provides for logging a user-defined event in the Windows NT Event Log. | NT Only | |
Reads a message from the Adaptive Server message inbox. | NT Only | |
Sends a message to the specified recipients using the MAPI interface. | NT Only | |
Starts an Adaptive Server mail session. | NT Only | |
Stops an Adaptive Server mail session. | NT Only |
The system extended stored procedures, created by installmaster at installation, are located in the sybsystemprocs database and are owned by the System Administrator. They can be run from any database.
Since system extended stored procedures are located in the sybsystemprocs database, their permissions are also set there.
Users with the sa_role have default execution permissions on the system ESPs. These System Administrators can grant execution permissions to other users.
You can get the names of the DLLs associated with the system ESPs by running sp_helpextendedproc in the sybsystemprocs database.
The system ESPs follow the same calling conventions as the regular system procedures.
The only additional requirement for system ESPs is that the Open Server application, XP Server, must be running. Adaptive Server starts XP Server the first time an ESP is invoked. XP Server continues to run until you shut down Adaptive Server.
Executes a native operating system command on the host system running Adaptive Server.
xp_cmdshell command [, no_output]
command - is the operating system command string; maximum length is 255 bytes.
no_output - if specified, suppresses any output from the command.
Silently copies the file named log on the C drive to a file named log.0102 on the A drive.
Executes the operating system's date command and returns the current date as a row of data.
For more information about t xp_cmdshell context, see the System Administration Guide
grant execute on xp_cmdshell to joe
By default, only a System Administrator can execute xp_cmdshell. A System Administrator can grant execute permission to other users.
System procedures |
Deletes a message from the Adaptive Server message inbox.
xp_deletemail [msg_id]
msg_id - is the message identifier of the mail message to be deleted.
Deletes from the Adaptive Server message inbox the message with the message identifier specified in the cur_msg_id variable.
Deletes the first message from the Adaptive Server message inbox.
By default, only a System Administrator can execute xp_deletemail. A System Administrator can grant this permission to other users.
System ESPs | |
System procedures |
Displays groups for a specified Windows NT domain.
xp_enumgroups [domain_name]
domain_name - is the Windows NT domain for which you are listing user groups.
Lists all user groups on the Windows NT computer running XP Server.
Lists all user groups in the PCS domain.
By default, only a System Administrator can execute xp_enumgroups. A System Administrator can grant this permission to other users.
Retrieves the next message identifier from the Adaptive Server message inbox.
xp_findnextmsg @msg_id = @msg_id output [, type]
[, unread_only = {true | false}]
msg_id - on input, specifies the message identifier that immediately precedes the one you are trying to retrieve. Places the retrieved message identifier in the msg_id output parameter, which must be of type binary.
type - is the input message type based on the MAPI mail definition. The only supported message type is CMC:IPM. A NULL value or no value defaults to CMC:IPM.
unread_only - if this parameter is set to true, xp_findnextmsg considers only unread messages. If this parameter is set to false, xp_findnextmsg considers all messages, both read and unread, when retrieving the next message identifier. The default is true.
Returns, in the @out_msg_id output variable, the message identifier of the next unread message after the message specified by the @out_msg_id.
Returns, in the @out_msg_id output variable, the message identifier of the next message after the message specified by the @out_msg_id. The message may be read or unread.
By default, only a System Administrator can execute xp_findnextmsg. A System Administrator can grant this permission to other users.
System ESPs | |
System procedures |
Provides for logging a user-defined event in the Windows NT Event Log from within Adaptive Server.
xp_logevent error_number, message [, type]
error_number - is the user-assigned error number. It must be equal to or greater than 50000.
message - is the text of the message that is displayed in the description field of the event viewer. The maximum length of the message is 255 bytes. Enclose the message in quotes.
type - describes the urgency of the event. Values are informational, warning, and error. The default is informational. Enclose the value in quotes.
An informational event, number 55555, will be logged in the Windows NT Event Log. The text of the description in the event detail window is "Email message deleted".
An error event, number 66666, will be logged in the Windows NT Event Log. The text of the description in the event detail window is "DLL not found".
Detail | Value |
|---|---|
User | N/A |
Computer | Name of machine running XP Server |
Event ID | 12 |
Source | Name of Adaptive Server |
Category | User |
Only a System Administrator can execute xp_logevent.
Reads a message from the Adaptive Server message inbox.
xp_readmail [msg_id]
[, recipients output]
[, sender output]
[, date_received output]
[, subject output]
[, cc output]
[, message output]
[, attachments output]
[, suppress_attach = {true | false}]
[, peek = {true | false}]
[, unread = {true | false}]
[, msg_length output]
[, bytes_to_skip [output]]
[, type [output]]
msg _id - specifies the message identifier of the message to be read by xp_readmail. If the msg_id parameter is not used, the message defaults to the first unread message in the message box, if unread is true, or to the first message in the message box, if unread is false.
recipients - is a semicolon-separated list of the recipients of the message.
sender - is the originator of the message.
date_received - is the date the message was received.
subject - is the subject header of the message.
cc - is a list of the message's copied (cc'd) recipients (separated by semicolons).
message - is the text of the message body. If the length of the message body, obtained from the msg_length output parameter, is greater than 255, use the byte_to_skip and msg_length parameters to read the message in 255-byte increments.
attachments - is a list of the temporary paths of the attachments (separated by semicolons). attachments is ignored if suppress_attach is true.
suppress_attach - if set to true, prevents the creation of temporary files for attachments. The default is true.
peek- if set to false, flags the message as unread after it has been read. If set to true, flags the message as an unread message, even after it has been read. The default is false.
unread_only - if set to true, xp_readmail considers only unread messages. If set to false, xp_readmail considers all messages, whether they are flagged as read or unread. The default is true.
msg_length - is the total length of the message, in bytes. Used with the bytes_to_skip parameter, allows xp_readmail to read messages in 255-byte increments.
bytes_to_skip - on input, if not 0, specifies the number of bytes to skip before reading the next 255 bytes of the message into the message output parameter. On output, contains the offset in the message (the previous value of bytes_to_skip plus the msg_length that is output with the call) from which to start reading the next 255-byte increment.
type - is the message type based on the MAPI mail definition. The only supported message type is CMC:IPM. A NULL value or no value defaults to CMC:IPM.
xp_readmail reads the first unread message in the message inbox. It gets the message identifier for this message from the @msgid variable, where it has been stored by the xp_findnextmsg ESP. xp_readmail stores the sender's name in the @originator variable and the message body in the @mess variable.
Reads the first 255 bytes of the message for which the message identifier is output by xp_findnextmsg. If the total length of the message exceeds 255 bytes, reads the next 255 bytes and continues until there are no more bytes to read.
By default, only a System Administrator can execute xp_readmail. A System Administrator can grant this permission to other users.
System ESPs | |
System procedures |
Sends a message to the specified recipients. The message is either text or the results of a Transact-SQL query.
xp_sendmail recipient [; recipient] . . .
[, subject]
[, cc_recipient] . . .
[, bcc_recipient] . . .
[, {query | message}]
[, attachname]
[, attach_result = {true | false}]
[, echo_error = {true | false}]
[, include_file [, include_file] . . .]
[, no_column_header = {true | false}]
[, width]
[, separator]
[, dbuser]
[, dbname]
[, type]
[, include_query = {true | false}]
recipient - is the email address of the user who will receive the message. At least one recipient is required. Separate multiple recipients with semicolons.
subject - is the optional message subject header. If not used, defaults to "Sybase SQL Server Message".
cc_recipient - is a list of the message's copied (cc'd) recipients (separated by semicolons).
bcc_recipient - is the list of the message's blind- copied (bcc'd) recipients (separated by semicolons).
query - is one or more Transact-SQL statements. The results are sent to the recipients of the message. If query is used, message cannot be used.
message - is the text of the message being sent. If message is used, query cannot be used.
attachname - is the name of the file containing the results of a query, which is included as an attachment to the message, when the query parameter is used. If attachname is used, attach_result must be set to true. If attach_result is true and attachname is not specified, the prefix of the attached file's generated file name is "syb" followed by 5 random digits followed by the ".txt" extension; for example, syb84840.txt. This parameter is ignored if the message parameter is used.
attach_result - if set to true, sends the results of a query as an attachment to the message. If set to false, sends the results directly in the message body. The default is false. This parameter is ignored if the message parameter is used.
echo_error - if set to true, sends Adaptive Server messages, including the count of rows affected message, along with the query results. If set to false, does not send Adaptive Server messages. The default is true. This parameter is ignored if the message parameter is used.
include_file - is a list of files to be included as attachments to the message, separated by semicolons. The files can be specified as file names, path names, or relative path names and can be either text or binary files.
no_column_header - if set to true, column headers are sent with query results. If set to false, column headers are not sent. The default is false. This parameter is ignored if the message parameter is used.
no_output - if set to true, no output is sent to the session that sent the mail. If set to false, the session sending the mail receives output. The default is false. This parameter is ignored if the message parameter is used.
width - specifies, in characters, the width of the results sets when query results are sent in a message. width is the same as the /w option in isql. Result rows are broken by the newline character when the specified width is reached. The default is 80 characters. This parameter is ignored if the message parameter is used.
separator - specifies the character to be used as a column separator when query results are sent in a message. separator is the same as the /s option in isql. The default is the tab character. This parameter is ignored if the message parameter is used.
dbuser - specifies the database user name to be assumed for the user context for executing queries when the query parameter is used. The default is "guest." This parameter is ignored if the message parameter is used.
dname - specifies the database name to be assumed for the database context for executing queries when the query parameter is used. The default is "master." This parameter is ignored if the message parameter is used.
type - is the input message type based on the MAPI mail definition. The only supported message type is CMC:IPM. A NULL value or no value defaults to CMC:IPM.
include_query - if set to true, the query or queries used in the query parameter are appended to the results set. If set to false, the query is not appended. The default is false. include_query is ignored if the message parameter is used.
xp_sendmail sends a text message on the backup status of an Adaptive Server to "sally" and "ramon" with a copy to the "admin" group.
Sends "peter" the results of a query on the authors table. The results are in an attachment to the message, which consists of a file named au_lis.res, which is in the directory from which the server is being executed.
By default, only a System Administrator can execute xp_sendmail. A System Administrator can grant this permission to other users.
System ESPs | |
System procedures | |
Utility | isql |
Starts an Adaptive Server mail session.
xp_startmail [mail_user] [, mail_password]
mail_user - is a mail profile name used by Adaptive Server to log into the Windows NT mail system. If mail_user is not used, xp_startmail uses the mail user name that was used to set up Sybmail's Adaptive Server account.
mail_password - is the mail password used by Adaptive Server to log into the Windows NT mail system. If mail_password is not used, xp_startmail uses the mail password that was used to set up Sybmail's Adaptive Server account.
Starts an Adaptive Server mail session using the mail user name and password for Sybmail's user account.
Starts an Adaptive Server mail session with "mailuser" as the profile name and the password associated with that profile name.
sp_displaylogin sybmail
By default, only a System Administrator can execute xp_startmail. A System Administrator can grant this permission to other users.
System ESPs | |
System procedures |
Stops an Adaptive Server mail session.
xp_stopmail
None.
Stops an Adaptive Server mail session.
By default, only a System Administrator can execute xp_stopmail. A System Administrator can grant this permission to other users.
System ESPs | |
System procedures |
|
|