Обсуждение: preprocessor question: prepare statement
Could anyone tell me whether the EXEC SQL PREPARE statement is to be interpreted by the preprocessor or during run-time? That is can it be placed outside a function? Does it have to stand above the DECLARE or EXECUTE statement that references it or does it have to be executed prior to this statement? The DECLARE statement AFAIK is to be processed by the preprocessor. Hopefully that one is correct too. :-) Michael -- Michael Meskes | Go SF 49ers! Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire! Tel.: (+49) 2431/72651 | Use Debian GNU/Linux! Email: Michael.Meskes@gmx.net | Use PostgreSQL!
> Could anyone tell me whether the EXEC SQL PREPARE statement is to be > interpreted by the preprocessor or during run-time? That is can it be > placed outside a function? Does it have to stand above the DECLARE or > EXECUTE statement that references it or does it have to be executed > prior to this statement? > The DECLARE statement AFAIK is to be processed by the preprocessor. > Hopefully that one is correct too. :-) Pretty sure that PREPARE is a run-time thing, since you can dynamically build the sql statement fed to PREPARE. In fact, looking at my Ingres docs: "Dynamic SQL has four statements that are exclusively used in a dynamic program: 'execute immediate', 'prepare', 'execute', and 'describe'." In another section, it says: "The 'prepare' statement tells the DBMS to encode the dynamically built statement and assign it the specified name. After a statement is prepared, the program can execute the statement one or more times within a transaction by issuing the 'execute' statement and specifying the statement name. This method improves performance if your program must execute the same statement many times in a transaction. When you commit a transaction, all statements that were prepared during the transaction are discarded." Hope this helps... - Tom
On Thu, Feb 04, 1999 at 02:47:20AM +0000, Thomas G. Lockhart wrote: > Pretty sure that PREPARE is a run-time thing, since you can dynamically > build the sql statement fed to PREPARE. That is also possible with a compile time statement as you give it a variable name not the variable data as argument. But all in all I agree, and I will try to implement it that way. Michael -- Michael Meskes | Go SF 49ers! Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire! Tel.: (+49) 2431/72651 | Use Debian GNU/Linux! Email: Michael.Meskes@gmx.net | Use PostgreSQL!
Okay, I got it going as long as no variables are involved, a statement is prepared only once and not deallocated. Hopefully I get it complete before freezing 6.5, but I'm not sure I make that deadline. Am I correct that the wildcard used to represent a variable is implementation defined? I know Oracle uses something like :var1, :var2 etc. This requires parsing of the statement (right now I just store it for later use). I'd prefer to use ";;" since this is was ecpg uses internally. What is used on other systems? Michael -- Michael Meskes | Go SF 49ers! Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire! Tel.: (+49) 2431/72651 | Use Debian GNU/Linux! Email: Michael.Meskes@gmx.net | Use PostgreSQL!