Resultset

JavaScript

JavaScript手册
【目录】 【上一页】 【下一页】 【索引】

Resultset

Represents a virtual 表 created by executing a stored procedure.

服务器端对象
实现版本Netscape Server 3.0

创建源

The resultSet method of a Stproc object. The Resultset object does not have a constructor.

描述

For Sybase, Oracle, ODBC, and DB2 stored procedures, the stored-procedure object has one result set object for each SELECT statement executed by the stored procedure. For Informix stored procedures, the stored-procedure object always has one result set object.

A result set has a property for each column in the SELECT statement used to generate the result set. For Sybase, Oracle, and ODBC stored procedures, you can refer to these properties by the name of the column in the virtual 表. For Informix and DB2 stored procedures, the columns are not named. For these databases, you must use a numeric index to refer to the column.

Result set objects are not valid indefinitely. In general, once a stored procedure starts, no interactions are allowed between the database client and the database server until the stored procedure has completed. In particular, there are three circumstances that cause a result set to be invalid:

  1. If you create a result set as part of a transaction, you must finish using the result set during that transaction. Once you either commit or rollback the transaction, you can't get any more data from a result set, and you can't get any additional result sets. For example, the following code is illegal: database.beginTransaction();
    spobj = database.storedProc("getcusts");
    resobj = spobj.resultSet();
    database.commitTransaction();
    /* Illegal! Result set no longer valid! */
    col1 = resobj[0];

  2. You must retrieve result set objects before you call a stored-procedure object's returnValue or outParameters methods. Once you call either of these methods, you can't get any more data from a result set, and you can't get any additional result sets. spobj = database.storedProc("getcusts");
    resobj = spobj.resultSet();
    retval = spobj.returnValue();
    /* Illegal! Result set no longer valid! */
    col1 = resobj[0];

  3. Similarly, you must retrieve result set objects before you call the associated Connection object's cursor or SQLTable method. For example, the following code is illegal: spobj = database.storedProc("getcusts");
    cursobj = database.cursor("SELECT * FROM ORDERS;");
    /* Illegal! The result set is no longer available! */
    resobj = spobj.resultSet();
    col1 = resobj[0];
When finished with a Resultset object, use the close method to close it and release the memory it uses. If you release a connection that has an open result set, the runtime engine waits until the result set is closed before actually releasing the connection.

If you do not explicitly close a result set with the close method, the JavaScript runtime engine on the server automatically tries to close all open result sets when the associated database or DbPool object goes out of scope. This can tie up system resources unnecessarily. It can also lead to unpredic表 results.

You can use the prototype property of the Resultset class to add a property to all Resultset instances. If you do so, that addition applies to all Resultset objects running in all applications on your server, not just in the single application that made the change. This allows you to expand the capabilities of this object for your entire server.

属性概览

prototypeAllows the addition of properties to a Resultset object.

方法概览

closeCloses a result set object.
columnNameReturns the name of a column in the result set.
columnsReturns the number of columns in the result set.
nextMoves the current row to the next row in the result set.

示例

Assume you have the following Oracle stored procedure:

create or replace package timpack
as type timcurtype is ref cursor return customer%rowtype;
type timrentype is ref cursor return rentals%rowtype;
end timpack;
create or replace procedure timset4(timrows1 in out timpack.timcurtype, timrows in out timpack.timrentype)
as begin
open timrows for select * from rentals;
open timrows1 for select * from customer;
end timset4;
Running this stored procedure creates two result sets you can access. In the following code fragment the resobj1 result set has rows returned by the timrows ref cursor and the resobj2 result set has the rows returned by the timrows1 ref cursor.

spobj = database.storedProc("timset4");
resobj1 = spobj.resultSet();
resobj2 = spobj.resultSet();

属性

prototype

Represents the prototype for this class. You can use the prototype to add properties or methods to all instances of a class. For information on prototypes, see Function.prototype.

属性源Resultset
实现版本LiveWire 1.0

方法

close

Closes the result set and frees the allocated memory.

方法源Resultset
实现版本Netscape Server 3.0

语法

close()

参数

无。

返回

0 if the call was successful; otherwise, a nonzero status code based on any error message passed by the database. If the method returns a nonzero status code, use the associated majorErrorCode and majorErrorMessage methods to interpret the cause of the error.

描述

The close method closes a cursor or result set and releases the memory it uses. If you do not explicitly close a cursor or result set with the close method, the JavaScript runtime engine on the server automatically closes all open cursors and result sets when the corresponding client object goes out of scope.

示例

The following example creates the rentalSet cursor, performs certain operations on it, and then closes it with the close method.

// Create a Cursor object
rentalSet = database.cursor("SELECT * FROM rentals")
// Perform operations on the cursor
cursorOperations()
//Close the cursor
err = rentalSet.close()

参看

Cursor

columnName

Returns the name of the column in the result set corresponding to the specified number.

方法源Resultset
实现版本Netscape Server 3.0

语法

columnName (n)

参数

nZero-based integer corresponding to the column in the query. The first column in the result set is 0, the second is 1, and so on.

返回

The name of the column. For Informix stored procedures, this method for the Resultset object always returns the string "Expression".

If your SELEC