Advanced PowerBuilder

HomePrevious Lesson: Embedded & Dynamic SQL
Next Lesson: Embedded SQL - PowerBuilder Implementation

Introduction

The Structured Query Language is the most popular and commonly known database query language, so, it makes sense to use SQL to query a database.

Providing support for Embedded SQL ensures that, a language has the means to query most database engines for information. When you use this particular type of SQL, the statements are directly embedded into the code, introduced by keywords specific to the language being used.

These statements are put through pre-compilation which translate them into the equivalent functions or statements in the host language. For example, you can use embedded SQL in a C program as follows:

EXEC SQL INCLUDE SQLCA ;

EXEC SQL BEGIN DECLARE SECTION ;
DBCHAR mDescription[32] ;
DBINT mItemNumber ;
EXEC SQL END DECLARE SECTION ;
...
EXEC SQL SELECT product_description
INTO :mDescription
FROM product_master
WHERE product_no = :mItemNumber ;
...
printf( "Product No: %d, Product_description: %s",
mItemNumber, mDescription) ;

EXEC SQL is the keyword used by C to identify SQL statements. Otherwise, the SQL statements are similar to the ones found in a database administrator's handbook.

Writing Embedded SQL is very easy in PowerBuilder as it automatically detects SQL keywords, making special keywords redundant. The only thing you need to do is terminate the SQL statements with a semicolon (;).
  SQL statements can span multiple lines, without the need for a line continuation character.
HomePrevious Lesson: Embedded & Dynamic SQL
Next Lesson: Embedded SQL - PowerBuilder Implementation