10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

How You Can Access a Database with DataStream ObjectsHow You Can Use Parameterized QueriesTo allow greater flexibility, the text of the SQLSelect's Query attribute cancontain parameter substitutions. There are two types of query parameters:Parameters evaluated before the query is sent to the DBMS serverThese parameters involve straight textual substitution and can appearanywhere in the text, even inside quoted strings and substituting for SQLkeywords and operators. They cannot, however, be used with repeatqueries. These parameters begin with a leading ampersand (&).The following example contains parameterized column names and aparameterized table name:ss.Query.Value = 'select &(col1), &(col2),&(col3) ' +'from &tablename';The variables representing the column names and table name must bevisible in the scope specified in the SetCols or Open method. When theampersand is followed by an expression, the expression must be enclosedwithin parentheses as shown in the following example:ss.Query.Value = 'select &(col1 + col2/2) ' +'from &tablename';Parameters interpreted by the Ingres serverThese parameters can appear only where the Ingres DBMS acceptsparameters (that is, in the same places as constants). They begin with aleading colon (:).The following example evaluates an expression and uses the result as thevalue for the where clause:select number from infotblwhere number = :(var1 + var2);The following example shows how you can set the Value attribute of anSQLSelect with a parameterized where clause:initialize () =declaress = SQLSelect;wclause = varchar(60) not null;...enddeclarebeginss.Query.Value = 'select * from customer&(wclause)' +' order by cname';You can set the where clause later. The value of the where clause is assignedafter the SQLSelect is opened and evaluated and before the query is sent tothe DBMS server.For a discussion of setting the Query's Value attribute, see How You CanSpecify the Query (see page 167).Working with a Database 175

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!