~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

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;
42
45
 
43
46
int FunctionCursor::open(const char *name, int, uint32_t)
44
47
{
45
 
  (void)name;
46
 
  string temp_name= name;
47
 
  tool= static_cast<Function *>(engine)->getFunction(temp_name); 
 
48
  tool= static_cast<Function *>(engine)->getFunction(name); 
 
49
//  assert(tool);
 
50
 
 
51
  record_id= 0;
 
52
 
 
53
  if (not tool)
 
54
    return HA_ERR_NO_SUCH_TABLE;
48
55
 
49
56
  return 0;
50
57
}
52
59
int FunctionCursor::close(void)
53
60
{
54
61
  tool= NULL;
 
62
  wipeCache();
 
63
 
55
64
  return 0;
56
65
}
57
66
 
58
 
int FunctionCursor::rnd_init(bool)
 
67
int FunctionCursor::doStartTableScan(bool)
59
68
{
60
 
  record_id= 0;
61
69
  rows_returned= 0;
62
 
  generator= tool->generator(table->field);
 
70
  generator= tool->generator(table->getFields());
63
71
 
64
72
  return 0;
65
73
}
71
79
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
72
80
 
73
81
  /* Fix bug in the debug logic for field */
74
 
  for (Field **field=table->field ; *field ; field++)
 
82
  for (Field **field= table->getFields() ; *field ; field++)
75
83
  {
76
84
    (*field)->setWriteSet();
77
85
  }
78
86
 
79
 
  more_rows= generator->sub_populate(table->s->fields);
 
87
  more_rows= generator->sub_populate(table->getShare()->sizeFields());
80
88
 
81
89
  if (more_rows)
82
90
  {
94
102
 
95
103
void FunctionCursor::position(const unsigned char *record)
96
104
{
97
 
  unsigned char *copy;
98
 
 
99
 
  copy= (unsigned char *)calloc(table->s->reclength, sizeof(unsigned char));
100
 
  assert(copy);
101
 
  memcpy(copy, record, table->s->reclength);
102
 
  row_cache.push_back(copy);
 
105
  if (row_cache.size() <= record_id * table->getShare()->getRecordLength())
 
106
  {
 
107
    row_cache.resize(row_cache.size() + table->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage
 
108
  }
 
109
  memcpy(&row_cache[record_id * table->getShare()->getRecordLength()], record, table->getShare()->getRecordLength());
103
110
  internal::my_store_ptr(ref, ref_length, record_id);
104
111
  record_id++;
105
112
}
106
113
 
107
 
int FunctionCursor::rnd_end()
108
 
109
 
  size_t length_of_vector= row_cache.size();
110
 
 
111
 
  for (size_t x= 0; x < length_of_vector; x++)
112
 
  {
113
 
    free(row_cache[x]);
114
 
  }
115
 
 
 
114
 
 
115
void FunctionCursor::wipeCache()
 
116
{
116
117
  if (rows_returned > estimate_of_rows)
117
118
    estimate_of_rows= rows_returned;
118
119
 
119
120
  row_cache.clear();
120
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
121
144
  delete generator; // Do this in case of an early exit from rnd_next()
122
145
 
123
146
  return 0;
128
151
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
129
152
  size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
130
153
 
131
 
  memcpy(buf, row_cache[position_id], table->s->reclength);
 
154
  assert(position_id * table->getShare()->getRecordLength() < row_cache.size());
 
155
  memcpy(buf, &row_cache[position_id * table->getShare()->getRecordLength()], table->getShare()->getRecordLength());
132
156
 
133
157
  return 0;
134
158
}