KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Binding query results to 4D Objects.
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: December 9, 2004

The built-in high level ODBC commands in 4D 2004 allows you to communicate to external data sources. You can easily query an ODBC-compliant data source and bind the result to 4D Objects (arrays, fields, or variables). The command ODBC EXECUTE allows you to do this. It takes a SQL statement and bound objects as parameters which follows this format ODBC EXECUTE (sqlStatement{;boundObj1;...;boundObjN}). A valid connection is required to execute this command. If 4D fields are passed as parameters, records are automatically created and saved. And if arrays are passed, they are automatically resized. The variable bound follow the column sequence in the SQL statement. For instance, the code below executes an SQL statement that gets the City, State, and Country of companies and binds it to their respective arrays following the column sequence in the statement.

C_TEXT($SqlStatement)
ARRAY TEXT($City;0)
ARRAY TEXT($State;0)
ARRAY TEXT($Country;0)
ODBC LOGIN
If (OK=1)
  $SqlStatement:="Select City, State, Country from Company_Location"
  ODBC EXECUTE($SqlStatement;$City;$State;$Country)
  ODBC LOAD RECORD(ODBC All Records )
  ODBC LOGOUT
End if