1/*
2 * The contents of this file are subject to the Interbase Public
3 * License Version 1.0 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy
5 * of the License at http://www.Inprise.com/IPL.html
6 *
7 * Software distributed under the License is distributed on an
8 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code was created by Inprise Corporation
13 * and its predecessors. Portions created by Inprise Corporation are
14 * Copyright (C) Inprise Corporation.
15 *
16 * All Rights Reserved.
17 * Contributor(s): ______________________________________.
18 * Adriano dos Santos Fernandes
19 */
20
21#ifndef JRD_STATEMENT_H
22#define JRD_STATEMENT_H
23
24#include "../include/fb_blk.h"
25#include "../jrd/exe.h"
26#include "../jrd/EngineInterface.h"
27
28namespace Jrd {
29
30// Compiled statement.
31class JrdStatement : public pool_alloc<type_req>
32{
33public:
34 static const unsigned FLAG_SYS_TRIGGER = 0x01;
35 static const unsigned FLAG_INTERNAL = 0x02;
36 static const unsigned FLAG_IGNORE_PERM = 0x04;
37 //static const unsigned FLAG_VERSION4 = 0x08;
38
39 //static const unsigned MAP_LENGTH; // CVC: Moved to dsql/Nodes.h as STREAM_MAP_LENGTH
40 static const unsigned MAX_CLONES = 1000;
41 static const unsigned MAX_REQUEST_SIZE = 10485760; // 10 MB - just to be safe
42
43private:
44 JrdStatement(thread_db* tdbb, MemoryPool* p, CompilerScratch* csb);
45
46public:
47 static JrdStatement* makeStatement(thread_db* tdbb, CompilerScratch* csb, bool internalFlag);
48 static jrd_req* makeRequest(thread_db* tdbb, CompilerScratch* csb, bool internalFlag);
49
50 const Routine* getRoutine() const;
51 bool isActive() const;
52
53 jrd_req* findRequest(thread_db* tdbb);
54 jrd_req* getRequest(thread_db* tdbb, USHORT level);
55 void verifyAccess(thread_db* tdbb);
56 void release(thread_db* tdbb);
57
58private:
59 static void verifyTriggerAccess(thread_db* tdbb, jrd_rel* ownerRelation, trig_vec* triggers,
60 jrd_rel* view);
61 static void triggersExternalAccess(thread_db* tdbb, ExternalAccessList& list, trig_vec* tvec);
62
63 void buildExternalAccess(thread_db* tdbb, ExternalAccessList& list);
64
65public:
66 MemoryPool* pool;
67 unsigned flags; // statement flags
68 unsigned blrVersion;
69 ULONG impureSize; // Size of impure area
70 Firebird::Array<record_param> rpbsSetup;
71 Firebird::Array<jrd_req*> requests; // vector of requests
72 ExternalAccessList externalList; // Access to procedures/triggers to be checked
73 AccessItemList accessList; // Access items to be checked
74 ResourceList resources; // Resources (relations and indices)
75 const jrd_prc* procedure; // procedure, if any
76 const Function* function; // function, if any
77 Firebird::MetaName triggerName; // name of request (trigger), if any
78 JrdStatement* parentStatement; // Sub routine's parent statement
79 Firebird::Array<JrdStatement*> subStatements; // Array of subroutines' statements
80 const StmtNode* topNode; // top of execution tree
81 Firebird::Array<const RecordSource*> fors; // record sources
82 Firebird::Array<ULONG*> invariants; // pointer to nodes invariant offsets
83 Firebird::RefStrPtr sqlText; // SQL text (encoded in the metadata charset)
84 Firebird::Array<UCHAR> blr; // BLR for non-SQL query
85 MapFieldInfo mapFieldInfo; // Map field name to field info
86 MapItemInfo mapItemInfo; // Map item to item info
87 JRequest* interface; // External interface to this JrdStatement
88};
89
90
91} // namespace Jrd
92
93#endif // JRD_STATEMENT_H
94