~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: mordred
  • Date: 2009-07-15 05:28:57 UTC
  • mto: (1093.1.16 captain)
  • mto: This revision was merged to the branch mainline in revision 1097.
  • Revision ID: mordred@orisndriz02-20090715052857-fyizopg1m23l8vfo
pandora-build v0.18
Added support for ICC

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
5
 
 *
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.
10
 
 *
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.
15
 
 *
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
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
 
23
 
#include <plugin/function_engine/cursor.h>
24
 
#include <drizzled/session.h>
25
 
#include "drizzled/internal/my_sys.h"
26
 
 
27
 
#include <string>
28
 
 
29
 
using namespace std;
30
 
using namespace drizzled;
31
 
 
32
 
/*****************************************************************************
33
 
** Data Function tables
34
 
*****************************************************************************/
35
 
 
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.
40
 
  rows_returned(0)
41
 
{}
42
 
 
43
 
int FunctionCursor::open(const char *name, int, uint32_t)
44
 
{
45
 
  (void)name;
46
 
  string temp_name= name;
47
 
  tool= static_cast<Function *>(engine)->getFunction(temp_name); 
48
 
 
49
 
  return 0;
50
 
}
51
 
 
52
 
int FunctionCursor::close(void)
53
 
{
54
 
  tool= NULL;
55
 
  return 0;
56
 
}
57
 
 
58
 
int FunctionCursor::rnd_init(bool)
59
 
{
60
 
  record_id= 0;
61
 
  rows_returned= 0;
62
 
  generator= tool->generator(table->field);
63
 
 
64
 
  return 0;
65
 
}
66
 
 
67
 
 
68
 
int FunctionCursor::rnd_next(unsigned char *)
69
 
{
70
 
  bool more_rows;
71
 
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
72
 
 
73
 
  /* Fix bug in the debug logic for field */
74
 
  for (Field **field=table->field ; *field ; field++)
75
 
  {
76
 
    (*field)->setWriteSet();
77
 
  }
78
 
 
79
 
  more_rows= generator->sub_populate(table->s->fields);
80
 
 
81
 
  if (more_rows)
82
 
  {
83
 
    return 0;
84
 
  }
85
 
  else 
86
 
  {
87
 
    delete generator;
88
 
    generator= NULL;
89
 
  }
90
 
  rows_returned++;
91
 
 
92
 
  return more_rows ? 0 : HA_ERR_END_OF_FILE;
93
 
}
94
 
 
95
 
void FunctionCursor::position(const unsigned char *record)
96
 
{
97
 
  unsigned char *copy;
98
 
 
99
 
  copy= (unsigned char *)calloc(table->s->reclength, sizeof(unsigned char));
100
 
  assert(copy);
101
 
  memcpy(copy, record, table->s->reclength);
102
 
  row_cache.push_back(copy);
103
 
  internal::my_store_ptr(ref, ref_length, record_id);
104
 
  record_id++;
105
 
}
106
 
 
107
 
int FunctionCursor::rnd_end()
108
 
109
 
  size_t length_of_vector= row_cache.size();
110
 
 
111
 
  for (size_t x= 0; x < length_of_vector; x++)
112
 
  {
113
 
    free(row_cache[x]);
114
 
  }
115
 
 
116
 
  if (rows_returned > estimate_of_rows)
117
 
    estimate_of_rows= rows_returned;
118
 
 
119
 
  row_cache.clear();
120
 
  record_id= 0;
121
 
  delete generator; // Do this in case of an early exit from rnd_next()
122
 
 
123
 
  return 0;
124
 
}
125
 
 
126
 
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
127
 
{
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);
130
 
 
131
 
  memcpy(buf, row_cache[position_id], table->s->reclength);
132
 
 
133
 
  return 0;
134
 
}
135
 
 
136
 
 
137
 
int FunctionCursor::info(uint32_t flag)
138
 
{
139
 
  memset(&stats, 0, sizeof(stats));
140
 
 
141
 
  if (flag & HA_STATUS_AUTO)
142
 
    stats.auto_increment_value= 1;
143
 
 
144
 
  stats.records= estimate_of_rows;
145
 
 
146
 
  return 0;
147
 
}