~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/src/NDBT_ResultRow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <ndb_global.h>
 
17
#include "NDBT_ResultRow.hpp"
 
18
#include <NdbOut.hpp>
 
19
#include <NdbSchemaCon.hpp>
 
20
 
 
21
NDBT_ResultRow::NDBT_ResultRow(const NdbDictionary::Table& tab,
 
22
                               char attrib_delimiter)
 
23
  : m_table(tab)
 
24
{
 
25
  assert(tab.getObjectStatus() == NdbDictionary::Object::Retrieved);
 
26
 
 
27
  cols = tab.getNoOfColumns();
 
28
  names = new char *       [cols];
 
29
  data  = new NdbRecAttr * [cols];
 
30
  
 
31
  for(int i = 0; i<cols; i++){
 
32
    names[i] = new char[255];
 
33
    strcpy(names[i], tab.getColumn(i)->getName());
 
34
  }  
 
35
 
 
36
  ad[0] = attrib_delimiter;
 
37
  ad[1] = 0;
 
38
  m_ownData = false;
 
39
}
 
40
 
 
41
NDBT_ResultRow::~NDBT_ResultRow(){
 
42
  for(int i = 0; i<cols; i++){
 
43
    delete [] names[i];
 
44
  }  
 
45
  delete [] names;
 
46
 
 
47
  if(m_ownData){
 
48
    for(int i = 0; i<cols; i++)
 
49
      delete data[i];
 
50
  }
 
51
  delete [] data;
 
52
}
 
53
 
 
54
NdbRecAttr* & 
 
55
NDBT_ResultRow::attributeStore(int i){
 
56
 
 
57
  return data[i];
 
58
}
 
59
 
 
60
const NdbRecAttr*
 
61
NDBT_ResultRow::attributeStore(int i) const {
 
62
  return data[i];
 
63
}
 
64
 
 
65
const 
 
66
NdbRecAttr * 
 
67
NDBT_ResultRow::attributeStore(const char* name) const {
 
68
  for(int i = 0; i<cols; i++){
 
69
    if (strcmp(names[i], name) == 0)
 
70
      return data[i];
 
71
  }  
 
72
  assert(false);
 
73
  return 0;
 
74
}
 
75
 
 
76
NdbOut & 
 
77
NDBT_ResultRow::header (NdbOut & out) const {
 
78
  for(int i = 0; i<cols; i++){
 
79
    out << names[i];
 
80
    if (i < cols-1)
 
81
      out << ad;
 
82
  }
 
83
  return out;
 
84
}
 
85
 
 
86
BaseString NDBT_ResultRow::c_str() const {
 
87
  
 
88
  BaseString str;
 
89
  
 
90
  char buf[10];
 
91
  for(int i = 0; i<cols; i++){
 
92
    if(data[i]->isNULL()){
 
93
      sprintf(buf, "NULL");
 
94
      str.append(buf);    
 
95
    }else{
 
96
      Uint32* p = (Uint32*)data[i]->aRef();
 
97
      Uint32 sizeInBytes = data[i]->get_size_in_bytes();
 
98
      for (Uint32 j = 0; j < sizeInBytes; j+=(sizeof(Uint32))){
 
99
        str.append("H'");
 
100
        if (j + 4 < sizeInBytes)
 
101
        {
 
102
          sprintf(buf, "%.8x", *p);
 
103
        }
 
104
        else
 
105
        {
 
106
          Uint32 tmp = 0;
 
107
          memcpy(&tmp, p, sizeInBytes - j);
 
108
          sprintf(buf, "%.8x", tmp);
 
109
        }
 
110
        p++;
 
111
        str.append(buf);
 
112
        if ((j + sizeof(Uint32)) < sizeInBytes)
 
113
          str.append(", ");
 
114
      }
 
115
    }
 
116
    str.append("\n");
 
117
  }
 
118
  str.append("*");
 
119
  
 
120
  //ndbout << "NDBT_ResultRow::c_str() = " << str.c_str() << endl;
 
121
  
 
122
  return str;
 
123
}
 
124
 
 
125
NdbOut & 
 
126
operator << (NdbOut& ndbout, const NDBT_ResultRow & res)
 
127
{
 
128
  if (res.cols != 0)
 
129
  {
 
130
    ndbout << *(res.data[0]);
 
131
    for(int i = 1; i<res.cols; i++)
 
132
      ndbout << res.ad << *(res.data[i]);
 
133
  }
 
134
  return ndbout;
 
135
}
 
136
 
 
137
NDBT_ResultRow *
 
138
NDBT_ResultRow::clone () const {
 
139
 
 
140
  NDBT_ResultRow * row = new NDBT_ResultRow(m_table, ad[0]);
 
141
  row->m_ownData = true;
 
142
  Uint32 noOfColumns = m_table.getNoOfColumns();
 
143
  for(Uint32 i = 0; i < noOfColumns; i++){
 
144
    row->data[i] = data[i]->clone();
 
145
  }
 
146
  
 
147
  return row;
 
148
}
 
149
 
 
150
bool
 
151
NDBT_ResultRow::operator==(const NDBT_ResultRow& other) const 
 
152
{
 
153
  // quick and dirty
 
154
  return c_str() == other.c_str();
 
155
}