~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Brian Aker
  • Date: 2010-11-08 18:24:58 UTC
  • mto: (1921.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1916.
  • Revision ID: brian@tangent.org-20101108182458-twv4hyix43ojno80
Merge in changes such that lock is now broken out into its own directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <drizzled/session.h>
25
25
#include "drizzled/internal/my_sys.h"
26
26
 
 
27
#include <unistd.h>
 
28
#include <fcntl.h>
 
29
 
27
30
#include <string>
28
31
 
29
32
using namespace std;
34
37
*****************************************************************************/
35
38
 
36
39
FunctionCursor::FunctionCursor(plugin::StorageEngine &engine_arg,
37
 
                               TableShare &table_arg) :
 
40
                               Table &table_arg) :
38
41
  Cursor(engine_arg, table_arg),
39
42
  estimate_of_rows(100), // Completely fabricated, I used to use the value 2.
40
43
  rows_returned(0)
42
45
 
43
46
int FunctionCursor::open(const char *name, int, uint32_t)
44
47
{
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); 
 
48
  tool= static_cast<Function *>(getEngine())->getFunction(name); 
49
49
//  assert(tool);
50
50
 
 
51
  record_id= 0;
 
52
 
51
53
  if (not tool)
52
54
    return HA_ERR_NO_SUCH_TABLE;
53
55
 
57
59
int FunctionCursor::close(void)
58
60
{
59
61
  tool= NULL;
 
62
  wipeCache();
 
63
 
60
64
  return 0;
61
65
}
62
66
 
63
 
int FunctionCursor::rnd_init(bool)
 
67
int FunctionCursor::doStartTableScan(bool)
64
68
{
65
 
  record_id= 0;
66
69
  rows_returned= 0;
67
 
  generator= tool->generator(table->field);
 
70
  generator= tool->generator(getTable()->getFields());
68
71
 
69
72
  return 0;
70
73
}
76
79
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
77
80
 
78
81
  /* Fix bug in the debug logic for field */
79
 
  for (Field **field=table->field ; *field ; field++)
 
82
  for (Field **field= getTable()->getFields() ; *field ; field++)
80
83
  {
81
84
    (*field)->setWriteSet();
82
85
  }
83
86
 
84
 
  more_rows= generator->sub_populate(table->s->fields);
 
87
  more_rows= generator->sub_populate(getTable()->getShare()->sizeFields());
85
88
 
86
89
  if (more_rows)
87
90
  {
99
102
 
100
103
void FunctionCursor::position(const unsigned char *record)
101
104
{
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);
 
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());
108
110
  internal::my_store_ptr(ref, ref_length, record_id);
109
111
  record_id++;
110
112
}
111
113
 
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
 
 
 
114
 
 
115
void FunctionCursor::wipeCache()
 
116
{
121
117
  if (rows_returned > estimate_of_rows)
122
118
    estimate_of_rows= rows_returned;
123
119
 
124
120
  row_cache.clear();
125
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
126
144
  delete generator; // Do this in case of an early exit from rnd_next()
127
145
 
128
146
  return 0;
133
151
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
134
152
  size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
135
153
 
136
 
  memcpy(buf, row_cache[position_id], table->s->reclength);
 
154
  assert(position_id * getTable()->getShare()->getRecordLength() < row_cache.size());
 
155
  memcpy(buf, &row_cache[position_id * getTable()->getShare()->getRecordLength()], getTable()->getShare()->getRecordLength());
137
156
 
138
157
  return 0;
139
158
}