Listing 1

String lsSQL

lsSQL = "drop table inventory;"
Execute Immediate :lsSQL Using SQLCA;

lsSQL = "create table inventory(partnumber integer not null primary key," + &
"partdesc char(20)," + &
"datecount date);"
Execute Immediate :lsSQL Using SQLCA;

lsSQL = "insert into inventory values (100,'Scanner',null);"
Execute Immediate :lsSQL Using SQLCA;

lsSQL = "grant select on inventory to public;"
Execute Immediate :lsSQL Using SQLCA;




Listing 2

string ls_result
string ls_state = "MA"
string sqlstatement
DECLARE my_cursor DYNAMIC CURSOR FOR SQLSA ;
sqlstatement = "SELECT emp_lname FROM employee WHERE state = ?"
PREPARE SQLSA FROM :sqlstatement ;
OPEN DYNAMIC my_cursor using :ls_state;
FETCH my_cursor INTO :ls_result;
lb_1.AddItem(ls_result)
Do While SQLCA.SQLCode = 0 
FETCH my_cursor INTO :ls_result;
lb_1.AddItem(ls_result)
Loop




Listing 3

string ls_var
string ls_sql
int li_var

ls_sql = "SELECT emp_lname FROM employee"

PREPARE sqlsa FROM :ls_sql ;
DESCRIBE sqlsa INTO sqlda ;
DECLARE my_cursor DYNAMIC CURSOR FOR sqlsa ;
OPEN DYNAMIC my_cursor USING DESCRIPTOR sqlda ;
FETCH my_cursor USING DESCRIPTOR sqlda ;

CHOOSE CASE sqlda.OutParmType[1]

CASE TypeString!
ls_var = GetDynamicString(sqlda, 1)
CASE TypeInteger!
li_var = GetDynamicNumber(sqlda, 1)
END CHOOSE

CLOSE my_cursor ;




Listing 4

//gs_user is a global variable
string ls_current_sql
string ls_where

If sqltype = PreviewSelect! Then
ls_current_sql = sqlsyntax
If gs_user = "EMPLOYEE" Then
ls_where = " WHERE salary < 75000"
ls_current_sql = ls_current_sql + ls_where
This.SetSQLPreview(ls_current_sql)
End If 
End If




Listing 5

string ls_orig_sql
string ls_new_sql
string ls_rc
string ls_mod_string

ls_orig_sql = dw_1.Describe("datawindow.table.select")
ls_new_sql = "select * from employee where state = 'CA'"
ls_mod_string = "datawindow.table.select = '" + ls_new_sql + "'"
ls_rc = dw_1.Modify(ls_mod_string)
dw_1.SetTRansObject(SQLCA)
dw_1.Retrieve()




Listing 6

string ls_errors
string ls_sql
string ls_presentation_str
string ls_dwsyntax_str

ls_sql = mle_1.Text
ls_presentation_str= "style(type=grid)"

ls_dwsyntax_str = SQLCA.SyntaxFromSQL(ls_sql,ls_presentation_str,ls_errors)
IF Len(ls_errors) > 0 THEN
MessageBox("Warning","Could not create DW syntax " + ls_errors)
HALT CLOSE
END IF

dw_1.Create(ls_dwsyntax_str,ls_errors)

IF Len(ls_errors) > 0 THEN
MessageBox("Warning","Could not create DW" + ls_errors)
HALT CLOSE
END IF