Chapter 3 DynaScript Predefined Objects
The connection
object
has these properties:
connection.autoCommit
If true, each SQL statement executed using the connection is automatically committed immediately after it is executed.
chained mode
Open Client connections are automatically
set to CHAINED = ON which is equal to autoCommit=false. Use
autoCommit property to set chained mode to off (autoCommit=true).
This example adds $1000 to account 999999999. The insert is executed and committed immediately:
<!--SCRIPT
connection.autoCommit = true;
query = connection.CreateQuery( "insert into savings values ( '999999999', '1000' )" );
-->
connection.connected
This property is read-only.
Uses a Boolean value to indicate whether a connection has been made to the database.
This example displays the return. True indicates a successful connection, false indicates no connection has been made.
<!--SCRIPT
document.writeln( connection.connected );
connection.Connect();
document.writeln( connection.connected );
connection.Disconnect();
document.writeln( connection.connected );
-->
This example has an output of:
false
true
false
The "Connect method"
connection.connectionType
This property is read-only.
The type of connection (string). One of:
This example displays the connection type for a script's default connection object:
<!--SCRIPT
// This script displays the type of connection
// being used.
document.Write( "This is an " );
document.Write( connection.connectionType );
document.WriteLn( " connection." );
-->
connection.connectParameters
Connection parameters for an ODBC data source (string).
This example lists the connection parameters for the ODBC data source:
<!--SCRIPT
document.WriteLn( connection.connectParameters );
-->
This example could have the following output:
autostop = no
connection.database
The name of the database to which an Open Client connection (string) is made.
This example changes the database to which "myConnection" will connect.
<!--SCRIPT
myConn = site.GetConnection ( "myConnection" );
myConn.database = "newDatabaseName";
-->
connection.databaseType
This property is read-only.
The type of database to which you are connecting; for example, Adaptive Server Enterprise.
This example displays the type of database that is currently connected to:
<!--SCRIPT
document.WriteLn( connection.databaseType );
-->
connection.dataSource
Name of an ODBC data source (string).
This example changes the data sourcethat "MyConnection" uses to connect to "PowerDynamo Demo":
<!--SCRIPT
myConn = site.GetConnection ( "MyConnection" );
myConn.datasource = "PowerDynamo Demo";
-->
connection.dataSourceList
This property is read-only.
Names of all available ODBC data sources (array of strings).
This example lists all the available ODBC data sources:
<!--SCRIPT
list = connection.dataSourceList;
i = 0;
while( exists( list[i] ) ) {
document.writeln( list[i] );
i++;
}
-->
This example might have the following output:
SQL Anywhere Sample
PowerDynamo Demo
connection.description
Description associated with the connection (string).
This example displays the description associated with the connection:
<!--SCRIPT
document.WriteLn( connection.description );
-->
If the connection includes a description, this example might have output similar to:
Connection to the sample site.
connection.isolationLevel
The isolation level for the database that you are connected to. You must be connected to set the isolation level. You can set this value with an integer or a string but it is always retrieved as a string. The possible values are:
If you set the isolation level to a value that the database does not recognize, the old isolation value will remain.
This example displays the current isolation level and then resets the isolation level to 3:
<!--SCRIPT
myConn=site.GetConnection("MyConnection")
myConn.Connect();
document.WriteLn( "The isolation level = " + myConn.isolationLevel )
myConn.isolationLevel = 3;
document.WriteLn( "The isolation level = " + myConn.isolationLevel )
-->
connection.name
Name of the connection object (string). The
name of the default connection is <default>
.
This example displays the name of the connection object. The Connections folder in Sybase Central lists all connection object names.
<!--SCRIPT
/* display the name of a connection object */
document.WriteLn( connection.name );
-->
This example has an output of:
<default>
connection.password
User password for the data source (string).
This example changes the password for "MyConnection" to "secret":
<!--SCRIPT
myConn = site.GetConnection ( "MyConnection" );
myconn.password = "secret";
-->
connection.server
Server name for the Open Client connection (string). This property can be used only when you are using an Open Client connection.
This example displays the server name to which the connection object is connected:
<!--SCRIPT
/* display the server name */
document.WriteLn( connection.server );
-->
This example has an output of:
myserver
connection.simulateCursors
Allows support for movement through a query result set for individual connections. This property is useful when working with Adaptive Server Enterprise connections.
[Adaptive Server Enterprise]
The cursor support of Adaptive Server
Enterprise is not as extensive as that of Adaptive Server Anywhere,
and some of the Move
functions
are unavailable.
Move
, MoveFirst
, MoveLast
, MovePrevious
or MoveRelative
with
an Adaptive Server Enterprise connection you simulate the cursor
abilities of Adaptive Server Anywhere using connection.simulateCursors.
To simulate cursors for all connections indefinitely,
modify your Registry as follows:
From your system's Registry Editor,
open the following file: HKEY_LOCAL_MACHINE\SOFTWARE\SYBASE\SYBASE
TOOLS
Add the new string value name Simulate
Cursors
with the string value of "yes."
Using simulated cursors may cause a decline
in performance. When possible, use MoveNext
instead.
This example allows MovePrevious
to
be used with an Adaptive Server Enterprise connection:
<!--SQL
select lname from customer
-->
<!--script
connection.simulateCursors = true;
SQL.MoveLast()
while( SQL.MovePrevious() ) {
document.writeln( SQL.GetValue(1) );
}
-->
The "Move method"
connection.userId
User name for the ODBC data source (string).
This example gets the connection "Temp" and changes the password and user ID.
<!--SCRIPT
// change the password and userId of the "Temp"
// connection object
myConn=site.GetConnection ( "Temp" );
myConn.password = "Top";
myConn.userId = "Secret";
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |