Examples
The examples, 1 through 8, describe Embedded SQL character-mode programs that are written using plain C, standard C libraries, and Embedded SQL statements. Each program connects to the specified SQL Server and executes a series of Embedded SQL statements.
Each program that is described in the following examples uses the appropriate EXAMPLEn.SQC, GCUTIL.C, GCUTIL.H, and QUICKWIN.DEF files. Some of these programs use the author2 table, which you can create by using the AUTHOR2.SQL file.
You can build an example program for the following environments by using the associated commands.
|
Environment | Command |
|
Windows NT and Windows 95 | makec examplen nt, where n is the number of the example program |
MS-DOS | makec examplen dos, where n is the number of the example program |
QuickWin | makec examplen qwin, where n is the number of the example program |
Example 1
- Declares and opens a standard cursor by using a prepared SQL statement.
- Fetches rows from the sysobjects table in the specified database.
Example 2
- Declares and opens a browse cursor.
- Fetches rows from the sales table in the pubs database into a C structure.
Example 3
- Declares and opens a standard cursor.
- Fetches rows from the author2 table in the pubs database.
After each row is fetched, it:
1. Begins a transaction.
2. Performs a dummy update to lock that row.
3. Allows you to change the author's last name in that row.
4. Commits the transaction.
Example 4
- Connects to two SQL Servers, and declares and opens two standard cursors by using a prepared SQL statement.
- Fetches rows from the author2 table in the pubs database of each SQL Server.
- Allows you to issue positioned updates of each author's last name as the rows are fetched.
Example 5
- Issues a singleton select statement to retrieve a row from the titles table in the pubs database into a C structure or into the individual fields of a C structure.
- Uses browse cursors with a SELECT statement and the sp_who stored procedure.
- Issues static and dynamic INSERT statements.
- Issues a SELECT statement of various date and time values.
Example 6
- Issues multiple static SQL statements within a transaction in a Transact-SQL batch.
- Executes the sp_addtype and sp_droptype stored procedures.
- Uses a browse cursor with the sp_who stored procedure.
- Issues a SELECT statement into a temporary table and retrieves a row from that temporary table by using the EXECUTE IMMEDIATE statement.
- Executes a static Transact-SQL batch that uses control-of-flow language.
Example 7
- Opens a standard cursor by using HOLDLOCK within a transaction; inserts the cursor.
- Updates and deletes rows from the authors table in the pubs database.
- Inserts rows into the authors table within a transaction and then rolls back that transaction.
- Demonstrates that triggers are enforced by attempting to delete a row from the titles table that fires the deltitle trigger.
- Uses a browse cursor with the sp_who stored procedure.
- Executes the sp_addtype and sp_droptype stored procedures.
Example 8
- Demonstrates behavior that is similar to that of isql.