~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Olaf van der Spek
  • Date: 2011-08-05 13:28:48 UTC
  • mto: This revision was merged to the branch mainline in revision 2395.
  • Revision ID: olafvdspek@gmail.com-20110805132848-vvwjg6pgwf56xnsd
Use const char* instead of str_ref

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
23
23
#include <plugin/function_engine/cursor.h>
24
24
#include <drizzled/session.h>
25
 
#include "drizzled/internal/my_sys.h"
 
25
#include <drizzled/internal/my_sys.h>
 
26
#include <drizzled/field/blob.h>
 
27
#include <drizzled/table.h>
 
28
#include <drizzled/statistics_variables.h>
26
29
 
27
30
#include <unistd.h>
28
31
#include <fcntl.h>
48
51
  tool= static_cast<Function *>(getEngine())->getFunction(name); 
49
52
//  assert(tool);
50
53
 
51
 
  record_id= 0;
 
54
  row_cache_position= 0;
52
55
 
53
56
  if (not tool)
54
57
    return HA_ERR_NO_SUCH_TABLE;
100
103
  return more_rows ? 0 : HA_ERR_END_OF_FILE;
101
104
}
102
105
 
 
106
uint32_t FunctionCursor::max_row_length()
 
107
{
 
108
  uint32_t length= (uint32_t)(getTable()->getRecordLength() + getTable()->sizeFields()*2);
 
109
 
 
110
  uint32_t *ptr, *end;
 
111
  for (ptr= getTable()->getBlobField(), end=ptr + getTable()->sizeBlobFields();
 
112
       ptr != end ;
 
113
       ptr++)
 
114
  {
 
115
      length += 2 + ((Field_blob*)getTable()->getField(*ptr))->get_length();
 
116
  }
 
117
 
 
118
  return length;
 
119
}
 
120
 
 
121
unsigned int FunctionCursor::pack_row(const unsigned char *record)
 
122
{
 
123
  unsigned char *ptr;
 
124
 
 
125
  record_buffer.resize(max_row_length());
 
126
 
 
127
  /* Copy null bits */
 
128
  memcpy(&record_buffer[0], record, getTable()->getShare()->null_bytes);
 
129
  ptr= &record_buffer[0] + getTable()->getShare()->null_bytes;
 
130
 
 
131
  for (Field **field=getTable()->getFields() ; *field ; field++)
 
132
  {
 
133
    if (!((*field)->is_null()))
 
134
      ptr= (*field)->pack(ptr, record + (*field)->offset(record));
 
135
  }
 
136
 
 
137
  return((unsigned int) (ptr - &record_buffer[0]));
 
138
}
 
139
 
103
140
void FunctionCursor::position(const unsigned char *record)
104
141
{
105
 
  if (row_cache.size() <= record_id * getTable()->getShare()->getRecordLength())
 
142
  uint32_t max_length= max_row_length();
 
143
 
 
144
  if (row_cache.size() <= row_cache_position + max_length)
106
145
  {
107
 
    row_cache.resize(row_cache.size() + getTable()->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage
 
146
    row_cache.resize(row_cache.size() +  max_length);
108
147
  }
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++;
 
148
 
 
149
  unsigned int r_pack_length;
 
150
  r_pack_length= pack_row(record);
 
151
  internal::my_store_ptr(ref, ref_length, row_cache_position);
 
152
 
 
153
  memcpy(&row_cache[row_cache_position], &record_buffer[0], r_pack_length);
 
154
  row_cache_position+= r_pack_length;
112
155
}
113
156
 
114
157
 
118
161
    estimate_of_rows= rows_returned;
119
162
 
120
163
  row_cache.clear();
121
 
  record_id= 0;
 
164
  row_cache_position= 0;
122
165
}
123
166
 
124
167
int FunctionCursor::extra(enum ha_extra_function operation)
151
194
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
152
195
  size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
153
196
 
154
 
  assert(position_id * getTable()->getShare()->getRecordLength() < row_cache.size());
155
 
  memcpy(buf, &row_cache[position_id * getTable()->getShare()->getRecordLength()], getTable()->getShare()->getRecordLength());
 
197
  const unsigned char *ptr;
 
198
  ptr= &row_cache[position_id];
 
199
 
 
200
  /* Copy null bits */
 
201
  memcpy(buf, ptr, getTable()->getNullBytes());
 
202
  ptr+= getTable()->getNullBytes();
 
203
  // and copy fields
 
204
  for (Field **field= getTable()->getFields() ; *field ; field++)
 
205
  {
 
206
    if (!((*field)->is_null()))
 
207
    {
 
208
      ptr= (*field)->unpack(buf + (*field)->offset(getTable()->getInsertRecord()), ptr);
 
209
    }
 
210
  }
156
211
 
157
212
  return 0;
158
213
}