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)
46
string temp_name= name;
47
tool= static_cast<Function *>(engine)->getFunction(temp_name);
52
int FunctionCursor::close(void)
58
int FunctionCursor::rnd_init(bool)
62
generator= tool->generator(table->field);
68
int FunctionCursor::rnd_next(unsigned char *)
71
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
73
/* Fix bug in the debug logic for field */
74
for (Field **field=table->field ; *field ; field++)
76
(*field)->setWriteSet();
79
more_rows= generator->sub_populate(table->s->fields);
92
return more_rows ? 0 : HA_ERR_END_OF_FILE;
95
void FunctionCursor::position(const unsigned char *record)
99
copy= (unsigned char *)calloc(table->s->reclength, sizeof(unsigned char));
101
memcpy(copy, record, table->s->reclength);
102
row_cache.push_back(copy);
103
internal::my_store_ptr(ref, ref_length, record_id);
107
int FunctionCursor::rnd_end()
109
size_t length_of_vector= row_cache.size();
111
for (size_t x= 0; x < length_of_vector; x++)
116
if (rows_returned > estimate_of_rows)
117
estimate_of_rows= rows_returned;
121
delete generator; // Do this in case of an early exit from rnd_next()
126
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
128
ha_statistic_increment(&system_status_var::ha_read_rnd_count);
129
size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
131
memcpy(buf, row_cache[position_id], table->s->reclength);
137
int FunctionCursor::info(uint32_t flag)
139
memset(&stats, 0, sizeof(stats));
141
if (flag & HA_STATUS_AUTO)
142
stats.auto_increment_value= 1;
144
stats.records= estimate_of_rows;