18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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>
27
#include <drizzled/table.h>
28
#include <drizzled/statistics_variables.h>
27
30
#include <unistd.h>
100
103
return more_rows ? 0 : HA_ERR_END_OF_FILE;
106
uint32_t FunctionCursor::max_row_length()
108
uint32_t length= (uint32_t)(getTable()->getRecordLength() + getTable()->sizeFields()*2);
111
for (ptr= getTable()->getBlobField(), end=ptr + getTable()->sizeBlobFields();
115
length += 2 + ((Field_blob*)getTable()->getField(*ptr))->get_length();
121
unsigned int FunctionCursor::pack_row(const unsigned char *record)
125
record_buffer.resize(max_row_length());
128
memcpy(&record_buffer[0], record, getTable()->getShare()->null_bytes);
129
ptr= &record_buffer[0] + getTable()->getShare()->null_bytes;
131
for (Field **field=getTable()->getFields() ; *field ; field++)
133
if (!((*field)->is_null()))
134
ptr= (*field)->pack(ptr, record + (*field)->offset(record));
137
return((unsigned int) (ptr - &record_buffer[0]));
103
140
void FunctionCursor::position(const unsigned char *record)
105
if (row_cache.size() <= record_id * getTable()->getShare()->getRecordLength())
142
uint32_t max_length= max_row_length();
144
if (row_cache.size() <= row_cache_position + max_length)
107
row_cache.resize(row_cache.size() + getTable()->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage
146
row_cache.resize(row_cache.size() + max_length);
109
memcpy(&row_cache[record_id * getTable()->getShare()->getRecordLength()], record, getTable()->getShare()->getRecordLength());
110
internal::my_store_ptr(ref, ref_length, record_id);
149
unsigned int r_pack_length;
150
r_pack_length= pack_row(record);
151
internal::my_store_ptr(ref, ref_length, row_cache_position);
153
memcpy(&row_cache[row_cache_position], &record_buffer[0], r_pack_length);
154
row_cache_position+= r_pack_length;
151
194
ha_statistic_increment(&system_status_var::ha_read_rnd_count);
152
195
size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
154
assert(position_id * getTable()->getShare()->getRecordLength() < row_cache.size());
155
memcpy(buf, &row_cache[position_id * getTable()->getShare()->getRecordLength()], getTable()->getShare()->getRecordLength());
197
const unsigned char *ptr;
198
ptr= &row_cache[position_id];
201
memcpy(buf, ptr, getTable()->getNullBytes());
202
ptr+= getTable()->getNullBytes();
204
for (Field **field= getTable()->getFields() ; *field ; field++)
206
if (!((*field)->is_null()))
208
ptr= (*field)->unpack(buf + (*field)->offset(getTable()->getInsertRecord()), ptr);