23 #include <plugin/function_engine/cursor.h>
24 #include <drizzled/session.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>
42 FunctionCursor::FunctionCursor(plugin::StorageEngine &engine_arg,
44 Cursor(engine_arg, table_arg),
45 estimate_of_rows(100),
49 int FunctionCursor::open(
const char *name,
int, uint32_t)
51 tool=
static_cast<Function *
>(getEngine())->getFunction(name);
54 row_cache_position= 0;
57 return HA_ERR_NO_SUCH_TABLE;
62 int FunctionCursor::close(
void)
73 generator= tool->generator(getTable()->getFields());
79 int FunctionCursor::rnd_next(
unsigned char *)
82 ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
85 for (
Field **field= getTable()->getFields() ; *field ; field++)
87 (*field)->setWriteSet();
90 more_rows= generator->sub_populate(getTable()->getShare()->sizeFields());
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]));
140 void FunctionCursor::position(
const unsigned char *record)
142 uint32_t max_length= max_row_length();
144 if (row_cache.size() <= row_cache_position + max_length)
146 row_cache.resize(row_cache.size() + max_length);
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;
158 void FunctionCursor::wipeCache()
160 if (rows_returned > estimate_of_rows)
161 estimate_of_rows= rows_returned;
164 row_cache_position= 0;
167 int FunctionCursor::extra(
enum ha_extra_function operation)
171 case drizzled::HA_EXTRA_CACHE:
173 case drizzled::HA_EXTRA_NO_CACHE:
175 case drizzled::HA_EXTRA_RESET_STATE:
185 int FunctionCursor::doEndTableScan()
192 int FunctionCursor::rnd_pos(
unsigned char *buf,
unsigned char *pos)
194 ha_statistic_increment(&system_status_var::ha_read_rnd_count);
195 size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
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);
216 int FunctionCursor::info(uint32_t flag)
218 memset(&stats, 0,
sizeof(stats));
220 if (flag & HA_STATUS_AUTO)
221 stats.auto_increment_value= 1;
223 stats.records= estimate_of_rows;
TODO: Rename this file - func.h is stupid.
int doStartTableScan(bool scan)