~mdcallag/+junk/5.1-map

« back to all changes in this revision

Viewing changes to storage/ndb/src/ndbapi/NdbRecAttr.cpp

  • Committer: msvensson at pilot
  • Date: 2007-04-24 09:11:45 UTC
  • mfrom: (2469.1.106)
  • Revision ID: sp1r-msvensson@pilot.blaudden-20070424091145-10463
Merge pilot.blaudden:/home/msvensson/mysql/my51-m-mysql_upgrade
into  pilot.blaudden:/home/msvensson/mysql/mysql-5.1-maint

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
    theRef = tRef;
82
82
    return 0;
83
83
  }
 
84
  errno = ENOMEM;
84
85
  return -1;
85
86
}
86
87
 
100
101
NdbRecAttr *
101
102
NdbRecAttr::clone() const {
102
103
  NdbRecAttr * ret = new NdbRecAttr(0);
103
 
 
 
104
  if (ret == NULL)
 
105
  {
 
106
    errno = ENOMEM;
 
107
    return NULL;
 
108
  }
104
109
  ret->theAttrId = theAttrId;
105
110
  ret->m_size_in_bytes = m_size_in_bytes;
106
111
  ret->m_column = m_column;
112
117
    ret->theValue = 0;
113
118
  } else {
114
119
    ret->theStorageX = new Uint64[((n + 7) >> 3)];
 
120
    if (ret->theStorageX == NULL)
 
121
    {
 
122
      delete ret;
 
123
      errno = ENOMEM;
 
124
      return NULL;
 
125
    }
115
126
    ret->theRef = (char*)ret->theStorageX;    
116
127
    ret->theValue = 0;
117
128
  }
138
149
  return false;
139
150
}
140
151
 
 
152
NdbRecordPrintFormat::NdbRecordPrintFormat()
 
153
{
 
154
  fields_terminated_by= ";";
 
155
  start_array_enclosure= "[";
 
156
  end_array_enclosure= "]";
 
157
  fields_enclosed_by= "";
 
158
  fields_optionally_enclosed_by= "\"";
 
159
  lines_terminated_by= "\n";
 
160
  hex_prefix= "H'";
 
161
  null_string= "[NULL]";
 
162
  hex_format= 0;
 
163
}
 
164
NdbRecordPrintFormat::~NdbRecordPrintFormat() {}
 
165
static const NdbRecordPrintFormat default_print_format;
 
166
 
141
167
static void
142
 
ndbrecattr_print_string(NdbOut& out, const char *type,
 
168
ndbrecattr_print_string(NdbOut& out, const NdbRecordPrintFormat &f,
 
169
                        const char *type, bool is_binary,
143
170
                        const char *aref, unsigned sz)
144
171
{
145
172
  const unsigned char* ref = (const unsigned char*)aref;
148
175
  for (i=sz-1; i >= 0; i--)
149
176
    if (ref[i] == 0) sz--;
150
177
    else break;
 
178
  if (!is_binary)
 
179
  {
 
180
    // trailing spaces are not printed
 
181
    for (i=sz-1; i >= 0; i--)
 
182
      if (ref[i] == 32) sz--;
 
183
      else break;
 
184
  }
 
185
  if (is_binary && f.hex_format)
 
186
  {
 
187
    if (sz == 0)
 
188
    {
 
189
      out.print("0x0");
 
190
      return;
 
191
    }
 
192
    out.print("0x");
 
193
    for (len = 0; len < (int)sz; len++)
 
194
      out.print("%02X", (int)ref[len]);
 
195
    return;
 
196
  }
151
197
  if (sz == 0) return; // empty
152
198
 
153
199
  for (len=0; len < (int)sz && ref[i] != 0; len++)
168
214
    for (i= len+1; ref[i] != 0; i++)
169
215
    out.print("%u]",len-i);
170
216
    assert((int)sz > i);
171
 
    ndbrecattr_print_string(out,type,aref+i,sz-i);
 
217
    ndbrecattr_print_string(out,f,type,is_binary,aref+i,sz-i);
172
218
  }
173
219
}
174
220
 
175
 
NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
 
221
NdbOut&
 
222
ndbrecattr_print_formatted(NdbOut& out, const NdbRecAttr &r,
 
223
                           const NdbRecordPrintFormat &f)
176
224
{
177
225
  if (r.isNULL())
178
226
  {
179
 
    out << "[NULL]";
 
227
    out << f.null_string;
180
228
    return out;
181
229
  }
182
230
  
183
231
  const NdbDictionary::Column* c = r.getColumn();
184
232
  uint length = c->getLength();
185
 
  if (length > 1)
186
 
    out << "[";
187
 
 
188
 
  for (Uint32 j = 0; j < length; j++) 
189
233
  {
190
 
    if (j > 0)
191
 
      out << " ";
192
 
 
 
234
    const char *fields_optionally_enclosed_by;
 
235
    if (f.fields_enclosed_by[0] == '\0')
 
236
      fields_optionally_enclosed_by=
 
237
        f.fields_optionally_enclosed_by;
 
238
    else
 
239
      fields_optionally_enclosed_by= "";
 
240
    out << f.fields_enclosed_by;
 
241
    Uint32 j;
193
242
    switch(r.getType()){
194
243
    case NdbDictionary::Column::Bigunsigned:
195
244
      out << r.u_64_value();
196
245
      break;
197
246
    case NdbDictionary::Column::Bit:
198
 
      out << hex << "H'" << r.u_32_value() << dec;
 
247
      out << f.hex_prefix << "0x";
 
248
      {
 
249
        const Uint32 *buf = (Uint32 *)r.aRef();
 
250
        int k = (length+31)/32;
 
251
        while (k > 0 && (buf[--k] == 0));
 
252
        out.print("%X", buf[k]);
 
253
        while (k > 0)
 
254
          out.print("%.8X", buf[--k]);
 
255
      }
199
256
      break;
200
257
    case NdbDictionary::Column::Unsigned:
201
 
      out << *((Uint32*)r.aRef() + j);
 
258
      if (length > 1)
 
259
        out << f.start_array_enclosure;
 
260
      out << *(Uint32*)r.aRef();
 
261
      for (j = 1; j < length; j++)
 
262
        out << " " << *((Uint32*)r.aRef() + j);
 
263
      if (length > 1)
 
264
        out << f.end_array_enclosure;
 
265
      break;
 
266
    case NdbDictionary::Column::Mediumunsigned:
 
267
      out << r.u_medium_value();
202
268
      break;
203
269
    case NdbDictionary::Column::Smallunsigned:
204
270
      out << r.u_short_value();
212
278
    case NdbDictionary::Column::Int:
213
279
      out << r.int32_value();
214
280
      break;
 
281
    case NdbDictionary::Column::Mediumint:
 
282
      out << r.medium_value();
 
283
      break;
215
284
    case NdbDictionary::Column::Smallint:
216
285
      out << r.short_value();
217
286
      break;
219
288
      out << (int) r.char_value();
220
289
      break;
221
290
    case NdbDictionary::Column::Binary:
 
291
      if (!f.hex_format)
 
292
        out << fields_optionally_enclosed_by;
222
293
      j = r.get_size_in_bytes();
223
 
      ndbrecattr_print_string(out,"Binary", r.aRef(), j);
 
294
      ndbrecattr_print_string(out,f,"Binary", true, r.aRef(), j);
 
295
      if (!f.hex_format)
 
296
        out << fields_optionally_enclosed_by;
224
297
      break;
225
298
    case NdbDictionary::Column::Char:
 
299
      out << fields_optionally_enclosed_by;
226
300
      j = r.get_size_in_bytes();
227
 
      ndbrecattr_print_string(out,"Char", r.aRef(), j);
 
301
      ndbrecattr_print_string(out,f,"Char", false, r.aRef(), j);
 
302
      out << fields_optionally_enclosed_by;
228
303
      break;
229
304
    case NdbDictionary::Column::Varchar:
230
305
    {
 
306
      out << fields_optionally_enclosed_by;
231
307
      unsigned len = *(const unsigned char*)r.aRef();
232
 
      ndbrecattr_print_string(out,"Varchar", r.aRef()+1,len);
 
308
      ndbrecattr_print_string(out,f,"Varchar", false, r.aRef()+1,len);
233
309
      j = length;
 
310
      out << fields_optionally_enclosed_by;
234
311
    }
235
312
    break;
236
313
    case NdbDictionary::Column::Varbinary:
237
314
    {
 
315
      if (!f.hex_format)
 
316
        out << fields_optionally_enclosed_by;
238
317
      unsigned len = *(const unsigned char*)r.aRef();
239
 
      ndbrecattr_print_string(out,"Varbinary", r.aRef()+1,len);
 
318
      ndbrecattr_print_string(out,f,"Varbinary", true, r.aRef()+1,len);
240
319
      j = length;
 
320
      if (!f.hex_format)
 
321
        out << fields_optionally_enclosed_by;
241
322
    }
242
323
    break;
243
324
    case NdbDictionary::Column::Float:
366
447
    break;
367
448
    case NdbDictionary::Column::Longvarchar:
368
449
    {
369
 
      unsigned len = uint2korr(r.aRef());
370
 
      ndbrecattr_print_string(out,"Longvarchar", r.aRef()+2,len);
371
 
      j = length;
 
450
      out << fields_optionally_enclosed_by;
 
451
      unsigned len = uint2korr(r.aRef());
 
452
      ndbrecattr_print_string(out,f,"Longvarchar", false, r.aRef()+2,len);
 
453
      j = length;
 
454
      out << fields_optionally_enclosed_by;
 
455
    }
 
456
    break;
 
457
    case NdbDictionary::Column::Longvarbinary:
 
458
    {
 
459
      if (!f.hex_format)
 
460
        out << fields_optionally_enclosed_by;
 
461
      unsigned len = uint2korr(r.aRef());
 
462
      ndbrecattr_print_string(out,f,"Longvarbinary", true, r.aRef()+2,len);
 
463
      j = length;
 
464
      if (!f.hex_format)
 
465
        out << fields_optionally_enclosed_by;
372
466
    }
373
467
    break;
374
468
 
375
469
    case NdbDictionary::Column::Undefined:
376
 
    case NdbDictionary::Column::Mediumint:
377
 
    case NdbDictionary::Column::Mediumunsigned:
378
 
    case NdbDictionary::Column::Longvarbinary:
379
470
    unknown:
380
471
    //default: /* no print functions for the rest, just print type */
381
472
    out << (int) r.getType();
384
475
      out << " " << j << " times";
385
476
    break;
386
477
    }
387
 
  }
388
 
 
389
 
  if (length > 1)
390
 
  {
391
 
    out << "]";
 
478
    out << f.fields_enclosed_by;
392
479
  }
393
480
 
394
481
  return out;
395
482
}
396
483
 
 
484
NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
 
485
{
 
486
  return ndbrecattr_print_formatted(out, r, default_print_format);
 
487
}
 
488
 
397
489
Int64
398
490
NdbRecAttr::int64_value() const 
399
491
{
425
517
  memcpy(&val,theRef,sizeof(val));
426
518
  return val;
427
519
}
 
520
 
 
521
Int32
 
522
NdbRecAttr::medium_value() const
 
523
{
 
524
  return sint3korr((unsigned char *)theRef);
 
525
}
 
526
 
 
527
Uint32
 
528
NdbRecAttr::u_medium_value() const
 
529
{
 
530
  return uint3korr((unsigned char*)theRef);
 
531
}