4 PREPARE — prepare a statement for execution
8 PREPARE prepared_name FROM string
12 PREPARE prepares a statement dynamically specified as a string for
13 execution. This is different from the direct SQL statement PREPARE,
14 which can also be used in embedded programs. The EXECUTE command is
15 used to execute either kind of prepared statement.
20 An identifier for the prepared query.
23 A literal string or a host variable containing a preparable SQL
24 statement, one of SELECT, INSERT, UPDATE, or DELETE. Use
25 question marks (?) for parameter values to be supplied at
30 In typical usage, the string is a host variable reference to a string
31 containing a dynamically-constructed SQL statement. The case of a
32 literal string is not very useful; you might as well just write a
33 direct SQL PREPARE statement.
35 If you do use a literal string, keep in mind that any double quotes you
36 might wish to include in the SQL statement must be written as octal
37 escapes (\042) not the usual C idiom \". This is because the string is
38 inside an EXEC SQL section, so the ECPG lexer parses it according to
39 SQL rules not C rules. Any embedded backslashes will later be handled
40 according to C rules; but \" causes an immediate syntax error because
41 it is seen as ending the literal.
45 char *stmt = "SELECT * FROM test1 WHERE a = ? AND b = ?";
47 EXEC SQL ALLOCATE DESCRIPTOR outdesc;
48 EXEC SQL PREPARE foo FROM :stmt;
50 EXEC SQL EXECUTE foo USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR outdesc;
54 PREPARE is specified in the SQL standard.