database.majorErrorCode()
Description
When the database methods execute, insertRow, updateRow, deleteRow, beginTransaction, commitTransaction, and rollbackTransaction fail they return a database status code to indicate the reason for failure. When that status code is five (server error) or seven (vendor library error), the majorErrorCode method returns additional information about the failure.
The majorErrorCode method returns the major error code returned by the database server or ODBC. For server errors, this value typically corresponds to the server's SQLCODE. See "Error handling." for a description of database status codes and error methods.
Examples
This example updates the rentals table within a transaction. The updateRow method assigns a database status code to the statusCode variable to indicate whether the method is successful.
If updateRow succeeds, the value of statusCode is zero, and the transaction is committed. If updateRow returns a statusCode value of either five or seven, the values of majorErrorCode, majorErrorMessage, minorErrorCode, and minorErrorMessage are displayed. If statusCode is set to any other value, the errorRoutine function is called.
database.beginTransaction()
statusCode = cursor.updateRow("rentals")
if (statusCode == 0) {
database.commitTransaction()
if (statusCode == 5 || statusCode == 7) {
write("The operation failed to complete.<BR>"
write("Contact your system administrator with the following:<P>"
write("The value of statusCode is " + statusCode + "<BR>")
write("The value of majorErrorCode is " +
database.majorErrorCode() + "<BR>")
write("The value of majorErrorMessage is " +
database.majorErrorMessage() + "<BR>")
write("The value of minorErrorCode is " +
database.minorErrorCode() + "<BR>")
write("The value of minorErrorMessage is " +
database.minorErrorMessage() + "<BR>") }
database.rollbackTransaction()
else {
errorRoutine() }
See also
majorErrorMessage, minorErrorCode, minorErrorMessage methods
majorErrorMessage
Method. Returns the major error message returned by the database server.
Syntax
database.majorErrorMessage()
Method of
database
Description
When the database methods execute, insertRow, updateRow, deleteRow, beginTransaction, commitTransaction, and rollbackTransaction fail they return a database status code to indicate the reason for failure. When that status code is five (server error) or seven (vendor library error), the majorErrorMessage method returns additional information about the failure.
The majorErrorMessage method returns the major error message returned by the database server or ODBC. See "Error handling." for a description of the database status codes and error methods.
Examples
See the example for the majorErrorCode method.
See also
majorErrorCode, minorErrorCode, minorErrorMessage methods
Math
Object. A built-in object that has properties and methods for mathematical constants and functions. For example, the Math object's PI property has the value of pi.
Syntax
To use a Math object:
1. Math.propertyName
2. Math.methodName(parameters)
Parameters
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
Property of
None. The Math object is a top-level, built-in JavaScript object.
Description
You reference the constant PI as Math.PI
. Constants are defined with the full precision of real numbers in JavaScript. Similarly, you reference Math functions as methods. For example, the sine function is Math.sin(argument)
, where argument is the argument.
It is often convenient to use the with statement when a section of code uses several Math constants and methods, so you don't have to type "Math" repeatedly. For example,
with (Math) {
a = PI * r*r
y = r*sin(theta)
x = r*cos(theta)
}
Properties
The Math object has the following properties:
Methods
The Math object has the following methods:
Event handlers
None. Built-in objects do not have event handlers.
Examples
See the examples for the individual properties and methods.
max
Method. Returns the greater of two numbers.
Syntax
Math.max(number1, number2)
Parameters
number1 and number2 are any numeric arguments or the properties of existing objects.
Method of
Math
Examples
The following function evaluates the variables x and y:
function getMax(x,y) {
return Math.max(x,y)
}
If you pass getMax the values ten and twenty, it returns twenty; if you pass it the values -10 and -20, it returns -10.
See also
min method
method
Property. Provides the HTTP method associated with the request.
Syntax
request.method
Property of
request
Description
The value of the method property is the same as the value of the method property of the client-side form object; that is, method reflects the METHOD attribute of the FORM tag. For HTTP 1.0, the method property evaluates to either "get" or "post." Use the method property to determine the proper response to a request.
method is a read-only property.
Examples
The following example executes the postResponse function if the method property evaluates to "post." If method evaluates to anything else, the getResponse function executes.
<SERVER>
if (request.method=="post")
postResponse()
else
getResponse()
</SERVER>
See also
agent, ip, protocol (request object) properties
min
Method. Returns the lesser of two numbers.
Syntax
Math.min(number1, number2)
Parameters
number1 and number2 are any numeric arguments or the properties of existing objects.
Method of
Math
Examples
The following function evaluates the variables x and y:
function getMin(x,y) {
return Math.min(x,y)
}
If you pass getMin the values ten and twenty, it returns ten; if you pass it the values -10 and -20, it returns -20.
See also
max method
minorErrorCode
Method. Returns the secondary error code returned by the database vendor library.
Syntax
database.minorErrorCode()
Method of
database
Description
When the database methods execute, insertRow, updateRow, deleteRow, beginTransaction, commitTransaction, and rollbackTransaction fail they return a database status code to indicate the reason for failure. When that status code is five (server error) or seven (vendor library error), the minorErrorCode method returns additional information about the failure. See "Error handling." for a description of database status codes and error methods.
Examples
See the example for the majorErrorCode method.
See also
majorErrorCode, majorErrorMessage, and minorErrorMessage methods
minorErrorMessage
Method. Returns the secondary message returned by the database vendor library.
Syntax
database.minorErrorMessage()
Method of
database
Description
When the database methods execute, insertRow, updateRow, deleteRow, beginTransaction, commitTransaction, and rollbackTransaction fail they return a database status code to indicate the reason for failure. When that status code is five (server error) or seven (vendor library error), the minorErrorMessage method returns the secondary message returned by the database vendor library. See "Error handling." for a description of the database status codes and error methods.
Examples
See the example for the majorErrorCode method.
See also
majorErrorCode, majorErrorMessage, minorErrorCode methods
next
Method. Navigates to the next row in a cursor object.
Syntax
cursorName.next()
Parameters
cursorName is the name of a cursor object.
Method of
cursor object
Description
The next method moves the pointer to the next row in a cursor object. The next method returns false if the current row is the last row in the cursor; otherwise, it returns true. See the cursor object for more information about the pointer.
Use the next method to iterate through the records in a cursor. When the last row in the answer set is the current row, the next method returns false.
Examples
Example 1. This example uses the next method to navigate to the last row in a cursor. The variable x is initialized to true. When the pointer is in the last row of the cursor, the next method returns false and terminates the while
loop.
customerSet = database.cursor("select * from customer", true)
x=true
while (x) {
x = customerSet.next() }
Example 2. In the following example, the rentalSet cursor contains columns named videoId, rentalDate, and dueDate. The next method is called in a while loop that iterates over every row in the cursor. When the pointer is on the last row in the cursor, the next method returns false and terminates the while loop.
This example displays the three columns in the cursor in an HTML table:
<SERVER>
// Create a cursor object
rentalSet = database.cursor("SELECT videoId, rentalDate, returnDate
FROM rentals")
</SERVER>
// Create an HTML table
<TABLE BORDER>
<TR>
<TH>Video ID</TH>
<TD>Rental Date</TD>
<TD>Due Date</TD>
</TR>
<SERVER>
// Iterate through each row in the cursor
while (rentalSet.next()) {
</SERVER>
// Display the cursor values in the HTML table
<TR>
<TH><SERVER>write(rentalSet.videoId)</SERVER></TH>
<TD><SERVER>write(rentalSet.rentalDate)</SERVER></TD>
<TD><SERVER>write(rentalSet.returnDate)</SERVER></TD>
</TR>
// Terminate the while loop
<SERVER>
}
</SERVER>
// End the table
</TABLE>
See also
cursor method, cursor object
open
Method. Opens a file on the server.
Syntax
fileObjectName.open("mode")
Parameters
fileObjectName is a string specifying the name of a File object.
mode is a string specifying whether to open the file to read, write, or append, according to the list below.
Method of
File
Description
Use the open method to open a file on the server before you read from it or write to it. If the file is already open, the method fails and has no effect. The open method returns true if it is successful; otherwise, it returns false.
The mode parameter is a string that specifies whether to open the file to read, write, or append data:
info.txt
so an application can write information to it. If info.txt
does not already exist, the open method creates it; otherwise, the open method overwrites it. The close method closes the file after the writeData function is completed.
userInfo = new File("c:/data/info.txt") userInfo.open("w") writeData() userInfo.close()Example 2. The following example opens a binary file so an application can read data from it. The application uses an if statement to take different actions depending on whether the open statement finds the specified file.
entryGraphic = new File("c:/data/splash.gif") if (entryGraphic.open("rb") == true) { displayProcedure() } else { errorProcedure() } entryGraphic.close()
parse
Method. Returns the number of milliseconds in a date string since January 1, 1970, 00:00:00, local time.
Syntax
Date.parse(dateString)
Parameters
dateString is a string representing a date or a property of an existing object.
Method of
Date
Description
The parse method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 (local time). This function is useful for setting date values based on string values, for example in conjunction with the setTime method and the Date object.
Given a string representing a time, parse returns the time value. It accepts the IETF standard date syntax: "Mon, 25 Dec 1995 13:30:00 GMT." It understands the continental US time-zone abbreviations, but for general use, use a time-zone offset, for example, "Mon, 25 Dec 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.
Because the parse function is a static method of Date, you always use it as Date.parse()
, rather than as a method of a Date object you created.
Examples
If IPOdate is an existing Date object, then
IPOdate.setTime(Date.parse("Aug 9, 1995"))
See also
UTC method
parseFloat
Function. Parses a string argument and returns a floating point number.
Syntax
parseFloat(string)
Parameters
string is a string that represents the value you want to parse.
Description
The parseFloat function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself.
parseFloat parses its argument, a string, and returns a floating point number. If it encounters a character other than a sign ( + or -), numeral (0-9), a decimal point, or an exponent, then it returns the value up to that point and ignores that character and all succeeding characters.
If the first character cannot be converted to a number, parseFloat returns:
parseFloat("3.14") parseFloat("314e-2") parseFloat("0.0314E+2") var x = "3.14" parseFloat(x)The following example returns "NaN" or zero:
parseFloat("FF2")
parseInt
Function. Parses a string argument and returns an integer of the specified radix or base.
Syntax
parseInt(string [,radix])
Parameters
string is a string that represents the value you want to parse.
radix is an integer that represents the radix of the return value.
Description
The parseInt function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself.
The parseInt function parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of ten indicates to convert to a decimal number, eight octal, sixteen hexadecimal, and so on. For radixes above ten, the letters of the alphabet indicate numerals greater than ninr. For example, for hexadecimal numbers (base sixteen), A through F are used.
If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values.
If the radix is not specified or is specified as zero, JavaScript assumes the following:
parseInt("F", 16) parseInt("17", 8) parseInt("15", 10) parseInt(15.99, 10) parseInt("FXX123", 16) parseInt("1111", 2) parseInt("15*3", 10)The following examples all return "NaN" or zero:
parseInt("Hello", 8) parseInt("0x7", 10) parseInt("FFF", 10)Even though the radix is specified differently, the following examples all return seventeen because the input string begins with "0x."
parseInt("0x11", 16) parseInt("0x11", 0) parseInt("0x11")
PI
Property. The ratio of the circumference of a circle to its diameter, approximately 3.14159.
Syntax
Math.PI
Property of
Math
Description
Because PI is a constant, it is a read-only property of Math.
Examples
The following function returns the value of pi:
function getPi() {
return Math.PI
}
See also
E, LN2, LN10, LOG2E, LOG10E, SQRT1_2, SQRT2 properties
port
Property. A string indicating the port number used for the server.
Syntax
server.port
Property of
server
Description
The port property specifies a portion of the URL. The port property is a substring of the hostname property. The hostname property is the concatenation of the host and port properties, separated by a colon.
The default value of the port property is 80. When the port property is set to the default, the values of the host and hostname properties are the same.
port is a read-only property.
See Section 3.1 of RFC 1738 (http://www.cis.ohio-state.edu/htbin/rfc/rfc1738.html
) for complete information about the port.
Examples
See the examples for the server object.
See also
host, hostname, protocol (server object) properties.
pow
Method. Returns base to the exponent power, that is, baseexponent.
Syntax
Math.pow(base, exponent)
Parameters
base is any numeric expression or a property of an existing object.
exponent is any numeric expression or a property of an existing object.
Method of
Math
Examples
function raisePower(x,y) {
return Math.pow(x,y)
}
If x equals seven and y equals two, raisePower returns forty-nine (seven to the power of two).
See also
exp, log methods
project
Object. Contains data for an entire application.
Syntax
To use a project object:
1. project.propertyName
2. project.methodName
Parameters
propertyName is a property that you create.
methodName is one of the methods listed below or a method that you create.
Property of
None
Description
LiveWire creates a project object when an application starts and destroys the project object when the application or server stops. The typical project object lifetime is days or weeks.
Each client accessing the same application shares the same project object. Use the project object to maintain global data for an entire application. Many clients can access an application simultaneously, and the project object lets these clients share information.
LiveWire creates a set of project objects for each distinct Netscape HTTPD process running on the server. Because several server HTTPD processes may be running on different port numbers, LiveWire creates a set of project objects for each process.
You can lock the project object to ensure that different clients do not change its properties simultaneously. When one client locks the project object, other clients must wait before they can modify it. See the lock and unlock methods for complete information.
Properties
The project object has no predefined properties. You create custom properties to contain project-specific data that is required by an application.
You can create a property for the project object by assigning it a name and a value. For example, you can create a project object property to keep track of the next available Customer ID. Any client that accesses the application without a Customer ID is sequentially assigned one, and the value of the ID is incremented for each initial access.
Methods
Examples
Example 1. This example creates the lastID property and assigns a value to it by incrementing an existing value.
project.lastID = 1 + parseInt(project.lastID, 10)
Example 2. This example increments the value of the lastID property and uses it to assign a value to the customerID property.
project.lock()
project.lastID = 1 + parseInt(project.lastID, 10)
client.customerID = project.lastID
project.unlock()
In the previous example, notice that the project object is locked while the customerID property is assigned, so no other client can attempt to change the lastID property at the same time.
See also
client, request, server objects
protocol (request object)
Property. Provides the HTTP protocol level supported by the client's software.
Syntax
request.protocol
Property of
request
Description
For HTTP 1.0, the protocol value is "HTTP/1.0." Use the protocol property to determine the proper response to a request. protocol is a read-only property.
Examples
In the following example, the currentProtocol function executes if request.protocol
evaluates to "HTTP/1.0."
<SERVER>
if (request.protocol=="HTTP/1.0"
currentProtocol()
else
unknownProtocol()
</SERVER>
See also
agent, ip, method properties
protocol (server object)
Property. A string indicating the communication protocol used by the server.
Syntax
server.protocol
Property of
server
Description
The protocol property specifies the beginning of the URL, up to and including the first colon. The protocol indicates the access method of the URL. For example, a protocol of "http:" specifies HyperText Transfer Protocol.
protocol is a read-only property.
The protocol property represents the scheme name of the URL. See Section 2.1 of RFC 1738 (http://www.cis.ohio-state.edu/htbin/rfc/rfc1738.html
) for complete information about the protocol.
Examples
See the examples for the server object.