]> begriffs open source - ai-pg/blob - full-docs/txt/ecpg-sql-prepare.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / ecpg-sql-prepare.txt
1
2 PREPARE
3
4    PREPARE — prepare a statement for execution
5
6 Synopsis
7
8 PREPARE prepared_name FROM string
9
10 Description
11
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.
16
17 Parameters
18
19    prepared_name #
20           An identifier for the prepared query.
21
22    string #
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
26           execution.
27
28 Notes
29
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.
34
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.
42
43 Examples
44
45 char *stmt = "SELECT * FROM test1 WHERE a = ? AND b = ?";
46
47 EXEC SQL ALLOCATE DESCRIPTOR outdesc;
48 EXEC SQL PREPARE foo FROM :stmt;
49
50 EXEC SQL EXECUTE foo USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR outdesc;
51
52 Compatibility
53
54    PREPARE is specified in the SQL standard.
55
56 See Also
57
58    EXECUTE