1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "libdrizzle_priv.h"
24
#include <libdrizzle/drizzle_data.h>
25
#include <libdrizzle/drizzle_rows.h>
26
#include <libdrizzle/drizzle_field.h>
34
/***************************************************************************
35
Change field rows to field structs
36
***************************************************************************/
39
unpack_fields(DRIZZLE_DATA *data, unsigned int fields,
43
DRIZZLE_FIELD *field,*result;
44
uint32_t lengths[9]; /* Max of fields */
46
field= result= (DRIZZLE_FIELD*) malloc((unsigned int) sizeof(*field)*fields);
49
free_rows(data); /* Free old data */
52
memset((char*) field, 0, (unsigned int) sizeof(DRIZZLE_FIELD)*fields);
54
for (row= data->data; row ; row = row->next,field++)
57
/* fields count may be wrong */
58
assert((unsigned int) (field - result) < fields);
59
cli_fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7);
60
field->catalog= strdup((char*) row->data[0]);
61
field->db= strdup((char*) row->data[1]);
62
field->table= strdup((char*) row->data[2]);
63
field->org_table= strdup((char*) row->data[3]);
64
field->name= strdup((char*) row->data[4]);
65
field->org_name= strdup((char*) row->data[5]);
67
field->catalog_length= lengths[0];
68
field->db_length= lengths[1];
69
field->table_length= lengths[2];
70
field->org_table_length= lengths[3];
71
field->name_length= lengths[4];
72
field->org_name_length= lengths[5];
74
/* Unpack fixed length parts */
75
pos= (unsigned char*) row->data[6];
76
field->charsetnr= uint2korr(pos);
77
field->length= (unsigned int) uint4korr(pos+2);
78
field->type= (enum enum_field_types) pos[6];
79
field->flags= uint2korr(pos+7);
80
field->decimals= (unsigned int) pos[9];
82
/* Test if field is Internal Number Format */
83
if (((field->type <= DRIZZLE_TYPE_LONGLONG) &&
84
(field->type != DRIZZLE_TYPE_TIMESTAMP)) ||
85
(field->length == 14) ||
87
field->flags|= NUM_FLAG;
88
if (default_value && row->data[7])
90
field->def= (char *)malloc(lengths[7]);
91
memcpy(field->def, row->data[7], lengths[7]);
92
field->def_length= lengths[7];
99
free_rows(data); /* Free old data */
103
void free_rows(DRIZZLE_DATA *cur)
107
if (cur->data != NULL)
109
struct st_drizzle_rows * row= cur->data;
111
for (x= 0; x< cur->rows; x++)
113
struct st_drizzle_rows * next_row= row->next;
118
free((unsigned char*) cur);