Method SqlStatement():fromChar() Foundation

Creates an SQL statement object from a character string.

Syntax
:fromChar( <cStatement> ) -> oSqlStatement
Parameters
<cStatement>
The parameter <cStatement> must be a valid SQL statement in the native syntax of the connected DBMS. Named parameters in the statement must be prefixed with ::. Use a backslash as an escape character (\::) if :: is used as a valid token in the SQL syntax of the DBMS.
Return

This method returns an SQL statement object which can be used for statement building and execution.

Description

The SqlStatement() class supports a named parameter syntax, which simplifies the handling of parameters passed to the SQL backend and allows statement reuse. To utilize this feature, simply use <::symbolName> instead of the parameter value in your SQL statement. The SqlStatement() class then automatically creates a member variable with the name "symbolName". Any value that is assigned to this member variable is inserted into the SQL statement when calling the :build() method. This procedure is outlined below. Additional examples can be found in the documentation of the :asString() method.

#include "pgdbe.ch" 

PROCEDURE main 
LOCAL oSess, oStmt 

oSess := DacSession():new("DBE=pgdbe;SERVER=localhost;DB=northwind;UID=postgres;PWD=postgres;") 

oStmt:= DacSqlStatement():fromChar( "SELECT * FROM customers WHERE country=::country" ) 

oStmt:country := "Germany" 
oStmt:build():query() 
Browse() 

oStmt:country := "USA" 
oStmt:build():query() 
Browse() 
RETURN 

PROCEDURE DbeSys 
DbeLoad("pgdbe") 
DbeSetDefault("pgdbe") 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.