~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Stewart Smith
  • Date: 2009-08-20 17:15:54 UTC
  • mto: (1119.2.2 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090820171554-72eo1tqlc4n64rak
Valgrind 3.5 requires --alignment to be a power of 2 between 16 and 4096. The specifying --alignment is not important for us, so remove it.

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
 
  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); 
49
 
//  assert(tool);
50
 
 
51
 
  if (not tool)
52
 
    return HA_ERR_NO_SUCH_TABLE;
53
 
 
54
 
  return 0;
55
 
}
56
 
 
57
 
int FunctionCursor::close(void)
58
 
{
59
 
  tool= NULL;
60
 
  return 0;
61
 
}
62
 
 
63
 
int FunctionCursor::rnd_init(bool)
64
 
{
65
 
  record_id= 0;
66
 
  rows_returned= 0;
67
 
  generator= tool->generator(table->field);
68
 
 
69
 
  return 0;
70
 
}
71
 
 
72
 
 
73
 
int FunctionCursor::rnd_next(unsigned char *)
74
 
{
75
 
  bool more_rows;
76
 
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
77
 
 
78
 
  /* Fix bug in the debug logic for field */
79
 
  for (Field **field=table->field ; *field ; field++)
80
 
  {
81
 
    (*field)->setWriteSet();
82
 
  }
83
 
 
84
 
  more_rows= generator->sub_populate(table->s->fields);
85
 
 
86
 
  if (more_rows)
87
 
  {
88
 
    return 0;
89
 
  }
90
 
  else 
91
 
  {
92
 
    delete generator;
93
 
    generator= NULL;
94
 
  }
95
 
  rows_returned++;
96
 
 
97
 
  return more_rows ? 0 : HA_ERR_END_OF_FILE;
98
 
}
99
 
 
100
 
void FunctionCursor::position(const unsigned char *record)
101
 
{
102
 
  unsigned char *copy;
103
 
 
104
 
  copy= (unsigned char *)calloc(table->s->reclength, sizeof(unsigned char));
105
 
  assert(copy);
106
 
  memcpy(copy, record, table->s->reclength);
107
 
  row_cache.push_back(copy);
108
 
  internal::my_store_ptr(ref, ref_length, record_id);
109
 
  record_id++;
110
 
}
111
 
 
112
 
int FunctionCursor::rnd_end()
113
 
114
 
  size_t length_of_vector= row_cache.size();
115
 
 
116
 
  for (size_t x= 0; x < length_of_vector; x++)
117
 
  {
118
 
    free(row_cache[x]);
119
 
  }
120
 
 
121
 
  if (rows_returned > estimate_of_rows)
122
 
    estimate_of_rows= rows_returned;
123
 
 
124
 
  row_cache.clear();
125
 
  record_id= 0;
126
 
  delete generator; // Do this in case of an early exit from rnd_next()
127
 
 
128
 
  return 0;
129
 
}
130
 
 
131
 
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
132
 
{
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);
135
 
 
136
 
  memcpy(buf, row_cache[position_id], table->s->reclength);
137
 
 
138
 
  return 0;
139
 
}
140
 
 
141
 
 
142
 
int FunctionCursor::info(uint32_t flag)
143
 
{
144
 
  memset(&stats, 0, sizeof(stats));
145
 
 
146
 
  if (flag & HA_STATUS_AUTO)
147
 
    stats.auto_increment_value= 1;
148
 
 
149
 
  stats.records= estimate_of_rows;
150
 
 
151
 
  return 0;
152
 
}