~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Jay Pipes
  • Date: 2009-09-15 21:01:42 UTC
  • mto: (1126.2.5 merge)
  • mto: This revision was merged to the branch mainline in revision 1128.
  • Revision ID: jpipes@serialcoder-20090915210142-x8mwiqn1q0vzjspp
Moves Alter_info out into its own header and source file, cleans up some related include mess in sql_lex.h, and renames Alter_info to AlterInfo.

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, Inc.
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 <unistd.h>
28
 
#include <fcntl.h>
29
 
 
30
 
#include <string>
31
 
 
32
 
using namespace std;
33
 
using namespace drizzled;
34
 
 
35
 
/*****************************************************************************
36
 
** Data Function tables
37
 
*****************************************************************************/
38
 
 
39
 
FunctionCursor::FunctionCursor(plugin::StorageEngine &engine_arg,
40
 
                               Table &table_arg) :
41
 
  Cursor(engine_arg, table_arg),
42
 
  estimate_of_rows(100), // Completely fabricated, I used to use the value 2.
43
 
  rows_returned(0)
44
 
{}
45
 
 
46
 
int FunctionCursor::open(const char *name, int, uint32_t)
47
 
{
48
 
  tool= static_cast<Function *>(getEngine())->getFunction(name); 
49
 
//  assert(tool);
50
 
 
51
 
  record_id= 0;
52
 
 
53
 
  if (not tool)
54
 
    return HA_ERR_NO_SUCH_TABLE;
55
 
 
56
 
  return 0;
57
 
}
58
 
 
59
 
int FunctionCursor::close(void)
60
 
{
61
 
  tool= NULL;
62
 
  wipeCache();
63
 
 
64
 
  return 0;
65
 
}
66
 
 
67
 
int FunctionCursor::doStartTableScan(bool)
68
 
{
69
 
  rows_returned= 0;
70
 
  generator= tool->generator(getTable()->getFields());
71
 
 
72
 
  return 0;
73
 
}
74
 
 
75
 
 
76
 
int FunctionCursor::rnd_next(unsigned char *)
77
 
{
78
 
  bool more_rows;
79
 
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
80
 
 
81
 
  /* Fix bug in the debug logic for field */
82
 
  for (Field **field= getTable()->getFields() ; *field ; field++)
83
 
  {
84
 
    (*field)->setWriteSet();
85
 
  }
86
 
 
87
 
  more_rows= generator->sub_populate(getTable()->getShare()->sizeFields());
88
 
 
89
 
  if (more_rows)
90
 
  {
91
 
    return 0;
92
 
  }
93
 
  else 
94
 
  {
95
 
    delete generator;
96
 
    generator= NULL;
97
 
  }
98
 
  rows_returned++;
99
 
 
100
 
  return more_rows ? 0 : HA_ERR_END_OF_FILE;
101
 
}
102
 
 
103
 
void FunctionCursor::position(const unsigned char *record)
104
 
{
105
 
  if (row_cache.size() <= record_id * getTable()->getShare()->getRecordLength())
106
 
  {
107
 
    row_cache.resize(row_cache.size() + getTable()->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage
108
 
  }
109
 
  memcpy(&row_cache[record_id * getTable()->getShare()->getRecordLength()], record, getTable()->getShare()->getRecordLength());
110
 
  internal::my_store_ptr(ref, ref_length, record_id);
111
 
  record_id++;
112
 
}
113
 
 
114
 
 
115
 
void FunctionCursor::wipeCache()
116
 
{
117
 
  if (rows_returned > estimate_of_rows)
118
 
    estimate_of_rows= rows_returned;
119
 
 
120
 
  row_cache.clear();
121
 
  record_id= 0;
122
 
}
123
 
 
124
 
int FunctionCursor::extra(enum ha_extra_function operation)
125
 
{
126
 
  switch (operation)
127
 
  {
128
 
  case drizzled::HA_EXTRA_CACHE:
129
 
    break;
130
 
  case drizzled::HA_EXTRA_NO_CACHE:
131
 
    break;
132
 
  case drizzled::HA_EXTRA_RESET_STATE:
133
 
    wipeCache();
134
 
    break;
135
 
  default:
136
 
    break;
137
 
  }
138
 
 
139
 
  return 0;
140
 
}
141
 
 
142
 
int FunctionCursor::doEndTableScan()
143
 
144
 
  delete generator; // Do this in case of an early exit from rnd_next()
145
 
 
146
 
  return 0;
147
 
}
148
 
 
149
 
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
150
 
{
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);
153
 
 
154
 
  assert(position_id * getTable()->getShare()->getRecordLength() < row_cache.size());
155
 
  memcpy(buf, &row_cache[position_id * getTable()->getShare()->getRecordLength()], getTable()->getShare()->getRecordLength());
156
 
 
157
 
  return 0;
158
 
}
159
 
 
160
 
 
161
 
int FunctionCursor::info(uint32_t flag)
162
 
{
163
 
  memset(&stats, 0, sizeof(stats));
164
 
 
165
 
  if (flag & HA_STATUS_AUTO)
166
 
    stats.auto_increment_value= 1;
167
 
 
168
 
  stats.records= estimate_of_rows;
169
 
 
170
 
  return 0;
171
 
}