Chapter 3 DynaScript Predefined Objects
The query
object
has this property:
query.connection
This property is read-only.
The connection object used to execute the query.
This example displays the name of the connection used to execute the query:
<!--SQL
select name from product
-->
<!--SCRIPT
document.WriteLn( SQL.connection.name );
-->
query.cursorType
Use this property when you are executing stored
procedures in a Microsoft SQL Server database that return multiple
result sets. The cursorType
must
be set to ForwardOnly
to
avoid problems during execution.
This example executes a stored procedure that returns multiple results sets from a Microsoft SQL Server database:
<!--SCRIPT MSSQL_MultiStatement.ssc
/*
CREATE PROCEDURE test3 AS
select * into #footable from employee
select * from #footable
*/
conn = site.GetConnection( "MSSQLServer" );
// create an empty query
q = conn.CreateQuery();
q.cursorType = "ForwardOnly";
q.SetSQL( "exec test3" );
q.Execute();
if( q.GetErrorCode() != 0 ) {
document.writeln(q.GetErrorInfo());
}
while( q.MoveNext() ){
document.writeln( q.GetValue(1)+' '+q.GetValue(2)+' '+q.GetValue(3)+' '+q.GetValue(4) );
}
-->
query.stripTrailingBlanks
Use this property to strip trailing blanks
from query data. This property is quite useful when executing queries
against databases that have trailing blank characters such as Adaptive
Server Enterprise. The stripTrailingBlanks
property
may be set to true or false. False is the default.
This example executes a query against an Adaptive Server Enterprise database and strips that trailing blanks from the output:
<!--SCRIPT
SQL=connection.CreateQuery("select distinct name from product order by name" );
SQL.stripTrailingBlanks = true;
while SQL.MoveNext() {
document.WriteLn("[" +SQL.GetValue(1) + "]");
}
-->
The output from this example is:
[Baseball Cap]
[Shorts]
[Sweatshirt]
[Tee Shirt]
[Visor]
Without stripping the trailing blanks, the output might look like this:
[Baseball Cap ]
[Shorts ]
[Sweatshirt ]
[Tee Shirt ]
[Visor ]
You can also use the stripTrailingBlanks
property
in conjunction with the ResultsToXMLString
:
<!--SCRIPT
SQL=connection.CreateQuery("select distinct name from product order by name" );
SQL.stripTrailingBlanks = true;
document.WriteLn( SQL.ResultsToXMLString() );
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |
![]() |