2
Licensed Materials - Property of IBM
3
DB2 Storage Engine Enablement
4
Copyright IBM Corporation 2007,2008
7
Redistribution and use in source and binary forms, with or without modification,
8
are permitted provided that the following conditions are met:
9
(a) Redistributions of source code must retain this list of conditions, the
10
copyright notice in section {d} below, and the disclaimer following this
12
(b) Redistributions in binary form must reproduce this list of conditions, the
13
copyright notice in section (d) below, and the disclaimer following this
14
list of conditions, in the documentation and/or other materials provided
15
with the distribution.
16
(c) The name of IBM may not be used to endorse or promote products derived from
17
this software without specific prior written permission.
18
(d) The text of the required copyright notice is:
19
Licensed Materials - Property of IBM
20
DB2 Storage Engine Enablement
21
Copyright IBM Corporation 2007,2008
24
THIS SOFTWARE IS PROVIDED BY IBM CORPORATION "AS IS" AND ANY EXPRESS OR IMPLIED
25
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27
SHALL IBM CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
37
#ifndef DB2I_SQLSTATEMENTSTREAM_H
38
#define DB2I_SQLSTATEMENTSTREAM_H
40
#include "db2i_charsetSupport.h"
44
@class SqlStatementStream
46
This class handles building the stream of SQL statements expected by the
47
QMY_EXECUTE_IMMEDIATE and QMY_PREPARE_OPEN_CURSOR APIs.
48
Memory allocation is handled internally.
50
class SqlStatementStream
54
ctor to be used when multiple strings may be appended.
56
SqlStatementStream(uint32 firstStringSize) : statements(0)
58
curSize = firstStringSize + sizeof(StmtHdr_t);
59
curSize = (curSize + 3) & ~3;
60
ptr = (char*) getNewSpace(curSize);
66
ctor to be used when only a single statement will be executed.
68
SqlStatementStream(const String& statement) : statements(0), block(NULL), curSize(0), ptr(0)
70
addStatement(statement);
74
ctor to be used when only a single statement will be executed.
76
SqlStatementStream(const char* statement) : statements(0), block(NULL), curSize(0), ptr(0)
78
addStatement(statement);
82
Append an SQL statement, specifiying the DB2 sort sequence under which
83
the statement should be executed. This is important for CREATE TABLE
84
and CREATE INDEX statements.
86
SqlStatementStream& addStatement(const String& append, const char* fileSortSequence, const char* fileSortSequenceLibrary)
88
char sortSeqEbcdic[10];
89
char sortSeqLibEbcdic[10];
91
DBUG_ASSERT(strlen(fileSortSequence) <= 10 &&
92
strlen(fileSortSequenceLibrary) <= 10);
93
memset(sortSeqEbcdic, 0x40, 10);
94
memset(sortSeqLibEbcdic, 0x40, 10);
95
convToEbcdic(fileSortSequence, sortSeqEbcdic, strlen(fileSortSequence));
96
convToEbcdic(fileSortSequenceLibrary, sortSeqLibEbcdic, strlen(fileSortSequenceLibrary));
98
return addStatementInternal(append.ptr(), append.length(), sortSeqEbcdic, sortSeqLibEbcdic);
102
Append an SQL statement using default (*HEX) sort sequence.
104
SqlStatementStream& addStatement(const String& append)
106
const char splatHEX[] = {0x5C, 0xC8, 0xC5, 0xE7, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40}; // *HEX
107
const char blanks[] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40}; //
109
return addStatementInternal(append.ptr(), append.length(), splatHEX, blanks);
113
Append an SQL statement using default (*HEX) sort sequence.
115
SqlStatementStream& addStatement(const char* stmt)
117
const char splatHEX[] = {0x5C, 0xC8, 0xC5, 0xE7, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40}; // *HEX
118
const char blanks[] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40}; //
120
return addStatementInternal(stmt, strlen(stmt), splatHEX, blanks);
123
char* getPtrToData() const { return block; }
124
uint32 getStatementCount() const { return statements; }
126
SqlStatementStream& addStatementInternal(const char* stmt,
128
const char* fileSortSequence,
129
const char* fileSortSequenceLibrary);
131
uint32 storageRemaining() const
133
return (block == NULL ? 0 : curSize - (ptr - block));
136
char* getNewSpace(size_t size)
138
allocBase = (char*)sql_alloc(size + 15);
139
block = (char*)roundToQuadWordBdy(allocBase);
143
uint32 curSize; // The size of the usable memory.
144
char* allocBase; // The allocated memory (with padding for aligment)
145
char* block; // The usable memory chunck (aligned for ILE)
146
char* ptr; // The current position within block.
147
uint32 statements; // The number of statements that have been appended.