1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 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; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <plugin/function_engine/cursor.h>
24
#include <drizzled/session.h>
25
#include "drizzled/internal/my_sys.h"
33
using namespace drizzled;
35
/*****************************************************************************
36
** Data Function tables
37
*****************************************************************************/
39
FunctionCursor::FunctionCursor(plugin::StorageEngine &engine_arg,
41
Cursor(engine_arg, table_arg),
42
estimate_of_rows(100), // Completely fabricated, I used to use the value 2.
46
int FunctionCursor::open(const char *name, int, uint32_t)
48
tool= static_cast<Function *>(getEngine())->getFunction(name);
54
return HA_ERR_NO_SUCH_TABLE;
59
int FunctionCursor::close(void)
67
int FunctionCursor::doStartTableScan(bool)
70
generator= tool->generator(getTable()->getFields());
76
int FunctionCursor::rnd_next(unsigned char *)
79
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
81
/* Fix bug in the debug logic for field */
82
for (Field **field= getTable()->getFields() ; *field ; field++)
84
(*field)->setWriteSet();
87
more_rows= generator->sub_populate(getTable()->getShare()->sizeFields());
100
return more_rows ? 0 : HA_ERR_END_OF_FILE;
103
void FunctionCursor::position(const unsigned char *record)
105
if (row_cache.size() <= record_id * getTable()->getShare()->getRecordLength())
107
row_cache.resize(row_cache.size() + getTable()->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage
109
memcpy(&row_cache[record_id * getTable()->getShare()->getRecordLength()], record, getTable()->getShare()->getRecordLength());
110
internal::my_store_ptr(ref, ref_length, record_id);
115
void FunctionCursor::wipeCache()
117
if (rows_returned > estimate_of_rows)
118
estimate_of_rows= rows_returned;
124
int FunctionCursor::extra(enum ha_extra_function operation)
128
case drizzled::HA_EXTRA_CACHE:
130
case drizzled::HA_EXTRA_NO_CACHE:
132
case drizzled::HA_EXTRA_RESET_STATE:
142
int FunctionCursor::doEndTableScan()
144
delete generator; // Do this in case of an early exit from rnd_next()
149
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
151
ha_statistic_increment(&system_status_var::ha_read_rnd_count);
152
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());
161
int FunctionCursor::info(uint32_t flag)
163
memset(&stats, 0, sizeof(stats));
165
if (flag & HA_STATUS_AUTO)
166
stats.auto_increment_value= 1;
168
stats.records= estimate_of_rows;