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
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"
30
using namespace drizzled;
32
/*****************************************************************************
33
** Data Function tables
34
*****************************************************************************/
36
FunctionCursor::FunctionCursor(plugin::StorageEngine &engine_arg,
37
TableShare &table_arg) :
38
Cursor(engine_arg, table_arg),
39
estimate_of_rows(100), // Completely fabricated, I used to use the value 2.
43
int FunctionCursor::open(const char *name, int, uint32_t)
45
string tab_name(name);
46
transform(tab_name.begin(), tab_name.end(),
47
tab_name.begin(), ::tolower);
48
tool= static_cast<Function *>(engine)->getFunction(tab_name);
52
return HA_ERR_NO_SUCH_TABLE;
57
int FunctionCursor::close(void)
63
int FunctionCursor::rnd_init(bool)
67
generator= tool->generator(table->field);
73
int FunctionCursor::rnd_next(unsigned char *)
76
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
78
/* Fix bug in the debug logic for field */
79
for (Field **field=table->field ; *field ; field++)
81
(*field)->setWriteSet();
84
more_rows= generator->sub_populate(table->s->fields);
97
return more_rows ? 0 : HA_ERR_END_OF_FILE;
100
void FunctionCursor::position(const unsigned char *record)
104
copy= (unsigned char *)calloc(table->s->reclength, sizeof(unsigned char));
106
memcpy(copy, record, table->s->reclength);
107
row_cache.push_back(copy);
108
internal::my_store_ptr(ref, ref_length, record_id);
112
int FunctionCursor::rnd_end()
114
size_t length_of_vector= row_cache.size();
116
for (size_t x= 0; x < length_of_vector; x++)
121
if (rows_returned > estimate_of_rows)
122
estimate_of_rows= rows_returned;
126
delete generator; // Do this in case of an early exit from rnd_next()
131
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
133
ha_statistic_increment(&system_status_var::ha_read_rnd_count);
134
size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
136
memcpy(buf, row_cache[position_id], table->s->reclength);
142
int FunctionCursor::info(uint32_t flag)
144
memset(&stats, 0, sizeof(stats));
146
if (flag & HA_STATUS_AUTO)
147
stats.auto_increment_value= 1;
149
stats.records= estimate_of_rows;