~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to storage/ibmdb2i/db2i_sqlStatementStream.h

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Licensed Materials - Property of IBM
3
 
DB2 Storage Engine Enablement
4
 
Copyright IBM Corporation 2007,2008
5
 
All rights reserved
6
 
 
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
11
 
     list of conditions. 
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 
22
 
       All rights reserved
23
 
 
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
33
 
OF SUCH DAMAGE.
34
 
*/
35
 
 
36
 
 
37
 
#ifndef DB2I_SQLSTATEMENTSTREAM_H
38
 
#define DB2I_SQLSTATEMENTSTREAM_H
39
 
 
40
 
#include "db2i_charsetSupport.h"
41
 
#include "qmyse.h"
42
 
 
43
 
/**
44
 
  @class SqlStatementStream
45
 
  
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.
49
 
*/
50
 
class SqlStatementStream
51
 
{
52
 
  public:
53
 
    /**
54
 
      ctor to be used when multiple strings may be appended.
55
 
    */
56
 
    SqlStatementStream(uint32 firstStringSize) : statements(0)
57
 
    {
58
 
      curSize = firstStringSize + sizeof(StmtHdr_t);
59
 
      curSize = (curSize + 3) & ~3;
60
 
      ptr = (char*) getNewSpace(curSize);
61
 
      if (ptr == NULL)
62
 
        curSize = 0;
63
 
    }
64
 
    
65
 
    /**
66
 
      ctor to be used when only a single statement will be executed.
67
 
    */
68
 
    SqlStatementStream(const String& statement) : statements(0), block(NULL), curSize(0), ptr(0)
69
 
    {
70
 
      addStatement(statement);
71
 
    }
72
 
 
73
 
    /**
74
 
      ctor to be used when only a single statement will be executed.
75
 
    */
76
 
    SqlStatementStream(const char* statement) : statements(0), block(NULL), curSize(0), ptr(0)
77
 
    {
78
 
      addStatement(statement);
79
 
    }
80
 
 
81
 
    /**
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.
85
 
    */
86
 
    SqlStatementStream& addStatement(const String& append, const char* fileSortSequence, const char* fileSortSequenceLibrary)
87
 
    {
88
 
      char sortSeqEbcdic[10];
89
 
      char sortSeqLibEbcdic[10];
90
 
      
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));
97
 
      
98
 
      return addStatementInternal(append.ptr(), append.length(), sortSeqEbcdic, sortSeqLibEbcdic);
99
 
    }
100
 
    
101
 
    /**
102
 
      Append an SQL statement using default (*HEX) sort sequence.
103
 
    */
104
 
    SqlStatementStream& addStatement(const String& append)
105
 
    {
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};   //
108
 
 
109
 
      return addStatementInternal(append.ptr(), append.length(), splatHEX, blanks);
110
 
    }
111
 
    
112
 
    /**
113
 
      Append an SQL statement using default (*HEX) sort sequence.
114
 
    */
115
 
    SqlStatementStream& addStatement(const char* stmt)
116
 
    {
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};   //
119
 
 
120
 
      return addStatementInternal(stmt, strlen(stmt), splatHEX, blanks);
121
 
    }
122
 
    
123
 
    char* getPtrToData() const { return block; }
124
 
    uint32 getStatementCount() const { return statements; }
125
 
  private:
126
 
    SqlStatementStream& addStatementInternal(const char* stmt, 
127
 
                                             uint32 length, 
128
 
                                             const char* fileSortSequence, 
129
 
                                             const char* fileSortSequenceLibrary);
130
 
    
131
 
    uint32 storageRemaining() const
132
 
    {
133
 
      return (block == NULL ? 0 : curSize - (ptr - block));
134
 
    }
135
 
    
136
 
    char* getNewSpace(size_t size)
137
 
    {
138
 
      allocBase = (char*)sql_alloc(size + 15);
139
 
      block = (char*)roundToQuadWordBdy(allocBase);
140
 
      return block;
141
 
    }
142
 
 
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.
148
 
};
149
 
 
150
 
#endif
151