Chapter 3 DynaScript Predefined Objects


query properties

The query object has this property:

connection property

Syntax

query.connection 

Attributes

This property is read-only.

Description

The connection object used to execute the query.

Example

This example displays the name of the connection used to execute the query:

<!--SQL
select name from product
-->
<!--SCRIPT
document.WriteLn( SQL.connection.name );
-->

See also

"connection object".

"CreateQuery method".

cursorType property

Syntax

query.cursorType

Description

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.

Example

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) );
}
-->

See also

"CreateQuery method".

stripTrailingBlanks property

Syntax

query.stripTrailingBlanks

Description

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.

Example

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() );
-->

See also

"CreateQuery method".

 


Copyright © 1999 Sybase, Inc. All rights reserved.