Database Reference
In-Depth Information
#include<stdio.h>
#include<sys/types.h>
#include<stdio.h>
EXEC SQL BEGIN DECLARE SECTION;
char target[] = "unix:postgresql://localhost:5432/postgres";
int id;
char name[255];
EXEC SQL END DECLARE SECTION;
int main(int argc, char **argv)
{
EXEC SQL CONNECT TO: target AS connection_unix USER postgres;
/* Drop table */
EXEC SQL DROP TABLE IF EXISTS foo;
/* Create table foo */
EXEC SQL CREATE TABLE foo (id INTEGER, name TEXT);
/*
* Try to insert wrong number of columns
* into table to produce error and capture
* the error using SQLERROR "condition and
* perform SQLPRINT action.
*/
EXEC SQL WHENEVER SQLERROR SQLPRINT;
EXEC SQL INSERT INTO foo VALUES (1, 2, 'foo1');
EXEC SQL COMMIT;
/*
* Try to insert wrong number of columns
* into table to produce error and capture
* the error using SQLERROR "condition and
* perform GOTO action.
*/
EXEC SQL WHENEVER SQLERROR GOTO error_label;
EXEC SQL INSERT INTO foo VALUES (1, 2, 'foo1');
EXEC SQL COMMIT;
EXEC SQL DISCONNECT ALL;
return 0;
error_label:
fprintf(stderr, "\nSQL Error occur and captured using SQLERROR
condition\n");
EXEC SQL DISCONNECT ALL;
return 1;
 
Search WWH ::




Custom Search