~jaypipes/drizzle/split-xa-resource-manager

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Jay Pipes
  • Date: 2010-02-14 20:26:43 UTC
  • mfrom: (1273.1.27 staging)
  • Revision ID: jpipes@serialcoder-20100214202643-ahuqvc8rhn8u7y33
Merge trunk and resolve conflicts

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(&SSV::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 *)malloc(table->s->reclength);
 
100
  memcpy(copy, record, table->s->reclength);
 
101
  row_cache.push_back(copy);
 
102
  internal::my_store_ptr(ref, ref_length, record_id);
 
103
  record_id++;
 
104
}
 
105
 
 
106
int FunctionCursor::rnd_end()
 
107
 
108
  size_t length_of_vector= row_cache.size();
 
109
 
 
110
  for (size_t x= 0; x < length_of_vector; x++)
 
111
  {
 
112
    free(row_cache[x]);
 
113
  }
 
114
 
 
115
  if (rows_returned > estimate_of_rows)
 
116
    estimate_of_rows= rows_returned;
 
117
 
 
118
  row_cache.clear();
 
119
  record_id= 0;
 
120
  delete generator; // Do this in case of an early exit from rnd_next()
 
121
 
 
122
  return 0;
 
123
}
 
124
 
 
125
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
 
126
{
 
127
  ha_statistic_increment(&SSV::ha_read_rnd_count);
 
128
  size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
 
129
 
 
130
  memcpy(buf, row_cache[position_id], table->s->reclength);
 
131
 
 
132
  return 0;
 
133
}
 
134
 
 
135
 
 
136
int FunctionCursor::info(uint32_t flag)
 
137
{
 
138
  memset(&stats, 0, sizeof(stats));
 
139
 
 
140
  if (flag & HA_STATUS_AUTO)
 
141
    stats.auto_increment_value= 1;
 
142
 
 
143
  stats.records= estimate_of_rows;
 
144
 
 
145
  return 0;
 
146
}