~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-28 14:09:50 UTC
  • mfrom: (2207 bootstrap)
  • mto: (2209.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2210.
  • Revision ID: olafvdspek@gmail.com-20110228140950-2nu0hyzhuww3wssx
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
23
23
#include <plugin/function_engine/cursor.h>
24
24
#include <drizzled/session.h>
25
 
#include "drizzled/internal/my_sys.h"
 
25
#include <drizzled/internal/my_sys.h>
 
26
#include <drizzled/field/blob.h>
26
27
 
27
28
#include <unistd.h>
28
29
#include <fcntl.h>
48
49
  tool= static_cast<Function *>(getEngine())->getFunction(name); 
49
50
//  assert(tool);
50
51
 
51
 
  record_id= 0;
 
52
  row_cache_position= 0;
52
53
 
53
54
  if (not tool)
54
55
    return HA_ERR_NO_SUCH_TABLE;
100
101
  return more_rows ? 0 : HA_ERR_END_OF_FILE;
101
102
}
102
103
 
 
104
uint32_t FunctionCursor::max_row_length()
 
105
{
 
106
  uint32_t length= (uint32_t)(getTable()->getRecordLength() + getTable()->sizeFields()*2);
 
107
 
 
108
  uint32_t *ptr, *end;
 
109
  for (ptr= getTable()->getBlobField(), end=ptr + getTable()->sizeBlobFields();
 
110
       ptr != end ;
 
111
       ptr++)
 
112
  {
 
113
      length += 2 + ((Field_blob*)getTable()->getField(*ptr))->get_length();
 
114
  }
 
115
 
 
116
  return length;
 
117
}
 
118
 
 
119
unsigned int FunctionCursor::pack_row(const unsigned char *record)
 
120
{
 
121
  unsigned char *ptr;
 
122
 
 
123
  record_buffer.resize(max_row_length());
 
124
 
 
125
  /* Copy null bits */
 
126
  memcpy(&record_buffer[0], record, getTable()->getShare()->null_bytes);
 
127
  ptr= &record_buffer[0] + getTable()->getShare()->null_bytes;
 
128
 
 
129
  for (Field **field=getTable()->getFields() ; *field ; field++)
 
130
  {
 
131
    if (!((*field)->is_null()))
 
132
      ptr= (*field)->pack(ptr, record + (*field)->offset(record));
 
133
  }
 
134
 
 
135
  return((unsigned int) (ptr - &record_buffer[0]));
 
136
}
 
137
 
103
138
void FunctionCursor::position(const unsigned char *record)
104
139
{
105
 
  if (row_cache.size() <= record_id * getTable()->getShare()->getRecordLength())
 
140
  uint32_t max_length= max_row_length();
 
141
 
 
142
  if (row_cache.size() <= row_cache_position + max_length)
106
143
  {
107
 
    row_cache.resize(row_cache.size() + getTable()->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage
 
144
    row_cache.resize(row_cache.size() +  max_length);
108
145
  }
109
 
  memcpy(&row_cache[record_id * getTable()->getShare()->getRecordLength()], record, getTable()->getShare()->getRecordLength());
110
 
  internal::my_store_ptr(ref, ref_length, record_id);
111
 
  record_id++;
 
146
 
 
147
  unsigned int r_pack_length;
 
148
  r_pack_length= pack_row(record);
 
149
  internal::my_store_ptr(ref, ref_length, row_cache_position);
 
150
 
 
151
  memcpy(&row_cache[row_cache_position], &record_buffer[0], r_pack_length);
 
152
  row_cache_position+= r_pack_length;
112
153
}
113
154
 
114
155
 
118
159
    estimate_of_rows= rows_returned;
119
160
 
120
161
  row_cache.clear();
121
 
  record_id= 0;
 
162
  row_cache_position= 0;
122
163
}
123
164
 
124
165
int FunctionCursor::extra(enum ha_extra_function operation)
151
192
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
152
193
  size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
153
194
 
154
 
  assert(position_id * getTable()->getShare()->getRecordLength() < row_cache.size());
155
 
  memcpy(buf, &row_cache[position_id * getTable()->getShare()->getRecordLength()], getTable()->getShare()->getRecordLength());
 
195
  const unsigned char *ptr;
 
196
  ptr= &row_cache[position_id];
 
197
 
 
198
  /* Copy null bits */
 
199
  memcpy(buf, ptr, getTable()->getNullBytes());
 
200
  ptr+= getTable()->getNullBytes();
 
201
  // and copy fields
 
202
  for (Field **field= getTable()->getFields() ; *field ; field++)
 
203
  {
 
204
    if (!((*field)->is_null()))
 
205
    {
 
206
      ptr= (*field)->unpack(buf + (*field)->offset(getTable()->getInsertRecord()), ptr);
 
207
    }
 
208
  }
156
209
 
157
210
  return 0;
158
211
}