DbPool objects, see the Server-Side JavaScript Guide.
DbPool constructor.
DbPool object (its scope) varies. Assuming it has been assigned to a variable, a DbPool object can go out of scope at different times:
project object (such as project.engconn), then it remains in scope until the application terminates or until you reassign the property to another value or to null.server object (such as server.engconn), it remains in scope until the server goes down or until you reassign the property to another value or to null. request object. In this situation, the variable goes out of scope when control leaves the HTML page or you reassign the property to another value or to null.DbPool object before that object goes out of scope. Release connections and close the other objects as soon as you are done with them.
If you do not release a connection, it remains bound and is unavailable to the next user until the associated DbPool object goes out of scope. When you do call release to give up a connection, the runtime engine waits until all associated cursors, stored procedures, and result sets are closed before actually releasing the connection. Therefore, you must close those objects when you are done with them.
You can use the prototype property of the DbPool object to add a property to all DbPool instances. If you do so, that addition applies to all DbPool 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.
| Property |
Description
| |
|---|
watch and unwatch methods from Object.
Connects the pool to a particular configuration of database and user.
1. connect (dbtype, serverName, username, password,
databaseName)
2. connect (dbtype, serverName, username, password,
databaseName[, maxConnections])
3. connect (dbtype, serverName, username, password,
databaseName[, maxConnections[, commitflag]])
majorErrorCode and majorErrorMessage methods to interpret the cause of the error.
maxConnections parameter. If successful, it stores those connections for later use. If the runtime engine does not obtain the requested connections, it returns an error. When this connection goes out of scope, pending transactions are rolled back.
The third version of this method does everything the second version does. In addition, the commitflag parameter indicates what to do with pending transactions when this connection goes out of scope. If this parameter is false (the default), a pending transaction is rolled back. If this parameter is true, a pending transaction if committed.
pool.connect("INFORMIX", "myserver", "SYSTEM", "MANAGER", "mydb", 4)
connected()
connected method indicates whether this object is currently connected to a database.
If this method returns false for a Connection object, you cannot use any other methods of that object. You must reconnect to the database, using the DbPool object, and then get a new Connection object. Similarly, if this method returns false for the database object, you must reconnect before using other methods of that object.
myconn variable.
if (!myconn.connected()) {
mypool.connect ("INFORMIX", "myserver", "SYSTEM", "MANAGER", "mydb", 4);
myconn = mypool.connection;
}
Example 2: The following example uses an if condition to determine if an application is connected to a database server. If the application is connected, the isConnectedRoutine function runs; if the application is not connected, the isNotConnected routine runs.
if(database.connected()) {
isConnectedRoutine() }
else {
isNotConnectedRoutine() }
connection (name, timeout)
name | An arbitrary name for the connection. Primarily used for debugging. |
timeout |
Connection object.
disconnect()
majorErrorCode and majorErrorMessage methods to interpret the cause of the error.
DbPool object, before calling the disconnect method, you must first call the release method for all connections in this database pool. Otherwise, the connection is still considered in use by the system, so the disconnect waits until all connections are released.
After disconnecting from a database, the only methods of this object you can use are connect and connected.
if condition to determine if an application is connected to a database server. If the application is connected, the application calls the disconnect method; if the application is not connected, the isNotConnected routine runs.
if(database.connected()) {
database.disconnect() }
else {
isNotConnectedRoutine() }
1. new DbPool();
2. new DbPool (dbtype, serverName, username, password,
databaseName);
3. new DbPool (dbtype, serverName, username, password,
databaseName[, maxConnections]);
4. new DbPool (dbtype, serverName, username, password,
databaseName[, maxConnections[, commitflag]]);
DbPool object. This version of the constructor creates and caches one connection. When this connection goes out of scope, pending transactions are rolled back.
The second version of this constructor instantiates a DbPool object and then calls the connect method to establish a database connection. This version of the constructor also creates and caches one connection. When this connection goes out of scope, pending transactions are rolled back.
The third version of this constructor instantiates a DbPool object and then calls the connect method to establish a database connection. In addition, it attempts to create as many connections as specified by the maxConnections parameter. If successful, it stores those connections for later use. If the runtime engine does not obtain the requested connections, it returns an error. When this connection goes out of scope, pending transactions are rolled back.
The fourth version of this constructor does everything the third version does. In addition, the commitflag parameter indicates what to do with pending transactions when the connection goes out of scope. If this parameter is false (the default), a pending transaction is rolled back. If this parameter is true, a pending transaction if committed.
To detect errors, you can use the majorErrorCode method.
If possible, your application should call this constructor and make the database connection on its initial page. Doing so prevents conflicts from multiple client requests trying to manipulate the status of the connections at once.
majorErrorCode()
Table 1.3 Database status codes.
| Status code | Explanation | Status code |
Explanation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|---|
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 0, 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()
}
majorErrorMessage()
connection and DbPool methods or from special connection or DbPool properties containing error messages and codes.
DbPool.majorErrorCode.
minorErrorCode()
minorErrorMessage()
Function.prototype.storedProcArgs (procName [, type1 [, ... typeN]])
procName | |
type1, ..., typeN |
IN"), only for output ("OUT"), or for both input and output ("INOUT").
You must create one prototype for each Sybase stored procedure you use in your application. Additional prototypes for the same stored procedure are ignored.
You can specify an INOUT parameter either as an INOUT or as an OUT parameter. If you use an INOUT parameter of a stored procedure as an OUT parameter, the LiveWire Database Service implicitly passes a NULL value for that parameter.
inoutdemo stored procedure takes one input parameter and one input/output parameter, as follows:
create procedure inoutdemo ( @inparam int, @inoutparam int output)Assume execute the following code and then call
as
if ( @inoutparam == null)
@inoutparam = @inparam + 1
else
@inoutparam = @inoutparam + 1
outParameters(0), the result will be 101:
database.storedProcArgs("inoutdemo", "IN", "INOUT")
spobj= database.storedProc("inoutdemo", 6, 100);
answer = spobj.outParameters(0);
The value of answer is 101. On the other hand, assume you execute this code:
database.storedProcArgs("inoutdemo", "IN", "OUT")
spobj = database.storedProc("inoutdemo", 6, 100);
answer = spobj.outParameters(0);
In this case, the value of answer is 7.
toString()
toString method that is automatically called when it is to be represented as a text value or when an object is referred to in a string concatenation.
You can use toString within your own code to convert an object into a string, and you can create your own function to be called in place of the default toString method.
This method returns a string of the following format:
db "name" "userName" "dbtype" "serverName"where
name | |
userName | |
dbType | |
serverName |
toString method, see the Object.toString method.
Last Updated: 11/13/98 10:23:04
Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use