Client 3—Processing SQL Commands

Now let's turn our attention to the task of executing SQL commands and interpreting the results. To start with, I'll show you how to execute simple SQL statements in an ecpg application:

 1 2 /* client3a.pgc */ 3 4 EXEC SQL INCLUDE sqlca; 5 6 #include <stdio.h> 7 8 int main( ) 9 { 10 11 EXEC SQL WHENEVER SQLERROR SQLPRINT; 12 EXEC SQL WHENEVER SQLWARNING SQLPRINT; 13 EXEC SQL WHENEVER NOT FOUND SQLPRINT; 14 15 EXEC SQL CONNECT TO movies; 16 17 EXEC SQL 18 INSERT INTO tapes 19 VALUES 20 ( 21 'GG-44278', 22 'Strangers On A Train', 23 '1 hour 3 minutes' 24 ); 25 26 EXEC SQL 27 DELETE FROM tapes WHERE tape_id = 'GG-44278'; 28 29 EXEC SQL 30 DELETE FROM tapes WHERE tape_id IS NULL; 31 32 EXEC SQL DISCONNECT; 33 34 ...

Get PostgreSQL, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.