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

« back to all changes in this revision

Viewing changes to storage/ibmdb2i/db2i_sqlStatementStream.cc

  • 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
 
#include "db2i_sqlStatementStream.h"
38
 
#include "as400_types.h"
39
 
 
40
 
/**
41
 
  Add a statement to the statement stream, allocating additional memory as needed.
42
 
  
43
 
  @parm stmt  The statement text
44
 
  @parm length  The length of the statement text
45
 
  @parm fileSortSequence  The DB2 sort sequence identifier, in EBCDIC
46
 
  @parm fileSortSequenceLibrary  The DB2 sort sequence library, in EBCDIC
47
 
  
48
 
  @return Reference to this object
49
 
*/
50
 
SqlStatementStream& SqlStatementStream::addStatementInternal(const char* stmt, 
51
 
                                                             uint32 length, 
52
 
                                                             const char* fileSortSequence, 
53
 
                                                             const char* fileSortSequenceLibrary)
54
 
{
55
 
  uint32 storageNeeded = length + sizeof(StmtHdr_t);
56
 
  storageNeeded = (storageNeeded + 3) & ~3; // We have to be 4-byte aligned.
57
 
  if (storageNeeded > storageRemaining())
58
 
  {
59
 
    // We overallocate new storage to reduce number of times reallocation is
60
 
    // needed.
61
 
    int newSize = curSize + 2 * storageNeeded;
62
 
    DBUG_PRINT("SqlStatementStream::addStatementInternal", 
63
 
               ("PERF: Had to realloc! Old size=%d. New size=%d", curSize, newSize));
64
 
    char* old_space = block;
65
 
    char* new_space = (char*)getNewSpace(newSize);
66
 
    memcpy(new_space, old_space, curSize);
67
 
    ptr = new_space + (ptr - old_space);
68
 
    curSize = newSize;
69
 
  }
70
 
 
71
 
  DBUG_ASSERT((address64_t)ptr % 4 == 0);      
72
 
 
73
 
  memcpy(((StmtHdr_t*)ptr)->SrtSeqNam, 
74
 
         fileSortSequence, 
75
 
         sizeof(((StmtHdr_t*)ptr)->SrtSeqNam));
76
 
  memcpy(((StmtHdr_t*)ptr)->SrtSeqSch, 
77
 
         fileSortSequenceLibrary, 
78
 
         sizeof(((StmtHdr_t*)ptr)->SrtSeqSch));
79
 
  ((StmtHdr_t*)ptr)->Length = length;
80
 
  memcpy(ptr + sizeof(StmtHdr_t), stmt, length);
81
 
 
82
 
  ptr += storageNeeded;
83
 
  ++statements;
84
 
 
85
 
  return *this;
86
 
}