PREPARE
Description
Prepares the statement to be executed.
Syntax
PREPARE name FROM string
Parameters
- name
An identifier for the prepared query.
- string
A C string or host variable that contains a prepared statement, which can be SELECT, INSERT, UPDATE, or DELETE.
Examples
char *stmt = "SELECT * FROM test1 WHERE a = ? AND b = ?"; EXEC SQL ALLOCATE DESCRIPTOR outdesc; EXEC SQL PREPARE foo FROM :stmt; EXEC SQL EXECUTE foo USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR outdesc;
The PREPARE statement provided by ecpg is not equivalent to the PREPARE syntax provided by the kernel. Example:
PREPARE name [ ( data_type [, ...] ) ] AS statement
EXEC SQL PREPARE I (int, int) AS INSERT INTO T VALUES ( $1, $2 ); EXEC SQL EXECUTE I(1, 2);
When the preceding statement is executed, an error message "too few arguments on" is reported. ecpg provides a dynamic SQL statement to solve the problem in the PREPARE name [ ( data_type [, ...] ) ] AS statement syntax scenario.
EXEC SQL PREPARE I AS INSERT INTO T VALUES ( $1, $2 ); EXEC SQL EXECUTE I using 1, 2;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot