ASA Programming Guide
Using SQL in Applications
The way you include SQL statements in your application depends on the application development tool and programming interface you use.
ODBC If you are writing directly to the ODBC programming interface, your SQL statements appear in function calls. For example, the following C function call executes a DELETE statement:
SQLExecDirect( stmt, "DELETE FROM employee WHERE emp_id = 105", SQL_NTS );
ADO.NET You can execute SQL statements using a variety of ADO.NET objects. The AsaCommand object is one example:
AsaCommand cmd = new AsaCommand( "select emp_lname from employee", conn ); AsaDataReader reader = cmd.ExecuteReader();
JDBC If you are using the JDBC programming interface, you can execute SQL statements by invoking methods of the statement object. For example,
stmt.executeUpdate( "DELETE FROM employee WHERE emp_id = 105" );
Embedded SQL If you are using embedded SQL, you prefix your C language SQL statements with the keyword EXEC SQL. The code is then run through a preprocessor before compiling. For example,
EXEC SQL EXECUTE IMMEDIATE 'DELETE FROM employee WHERE emp_id = 105';
Sybase Open Client If you use the Sybase Open Client interface, your SQL statements appear in function calls. For example, the following pair of calls executes a DELETE statement:
ret = ct_command( cmd, CS_LANG_CMD, "DELETE FROM employee WHERE emp_id=105" CS_NULLTERM, CS_UNUSED); ret = ct_send(cmd);
Application Development Tools Application development tools such as the members of the Sybase Enterprise Application Studio family provide their own SQL objects, which use either ODBC (PowerBuilder) or JDBC (Power J) under the covers.
For more detailed information on how to include SQL in your application, see your development tool documentation. If you are using ODBC or JDBC, consult the software development kit for those interfaces.
For a detailed description of embedded SQL programming, see Embedded SQL Programming.
In many ways, stored procedures and triggers act as applications or parts of applications running inside the server. You can use many of the techniques here in stored procedures also. Stored procedures use statements very similar to embedded SQL statements.
For more information about stored procedures and triggers, see Using Procedures, Triggers, and Batches.
Java classes in the database can use the JDBC interface in the same way as Java applications outside the server. This chapter discusses some aspects of JDBC. For other information on using JDBC, see JDBC Programming.