~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Monty Taylor
  • Date: 2010-04-22 02:46:23 UTC
  • mto: (1497.3.4 enable-dtrace)
  • mto: This revision was merged to the branch mainline in revision 1527.
  • Revision ID: mordred@inaugust.com-20100422024623-4urw8fi8eraci08p
Don't overwrite the pandora_vc_revinfo file if we don't have new
authoratative information.

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