~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/cursor.cc

  • Committer: Stewart Smith
  • Date: 2010-07-27 00:49:32 UTC
  • mto: (1720.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1721.
  • Revision ID: stewart@flamingspork.com-20100727004932-basq3vx9szmmbswm
fix storing and manipulating foreign keys in the proto around ALTER TABLE, CREATE TABLE and ALTER TABLE ADD/DROP FOREIGN KEY. We also (mostly) emulate the naming of innodb foreign keys in the upper layer.

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;
48
51
  tool= static_cast<Function *>(engine)->getFunction(tab_name); 
49
52
//  assert(tool);
50
53
 
 
54
  record_id= 0;
 
55
 
51
56
  if (not tool)
52
57
    return HA_ERR_NO_SUCH_TABLE;
53
58
 
57
62
int FunctionCursor::close(void)
58
63
{
59
64
  tool= NULL;
 
65
  wipeCache();
 
66
 
60
67
  return 0;
61
68
}
62
69
 
63
 
int FunctionCursor::rnd_init(bool)
 
70
int FunctionCursor::doStartTableScan(bool)
64
71
{
65
 
  record_id= 0;
66
72
  rows_returned= 0;
67
 
  generator= tool->generator(table->field);
 
73
  generator= tool->generator(table->getFields());
68
74
 
69
75
  return 0;
70
76
}
76
82
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
77
83
 
78
84
  /* Fix bug in the debug logic for field */
79
 
  for (Field **field=table->field ; *field ; field++)
 
85
  for (Field **field= table->getFields() ; *field ; field++)
80
86
  {
81
87
    (*field)->setWriteSet();
82
88
  }
83
89
 
84
 
  more_rows= generator->sub_populate(table->s->fields);
 
90
  more_rows= generator->sub_populate(table->getShare()->sizeFields());
85
91
 
86
92
  if (more_rows)
87
93
  {
99
105
 
100
106
void FunctionCursor::position(const unsigned char *record)
101
107
{
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);
 
108
  if (row_cache.size() <= record_id * table->getShare()->getRecordLength())
 
109
  {
 
110
    row_cache.resize(row_cache.size() + table->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage
 
111
  }
 
112
  memcpy(&row_cache[record_id * table->getShare()->getRecordLength()], record, table->getShare()->getRecordLength());
108
113
  internal::my_store_ptr(ref, ref_length, record_id);
109
114
  record_id++;
110
115
}
111
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
 
 
118
void FunctionCursor::wipeCache()
 
119
{
121
120
  if (rows_returned > estimate_of_rows)
122
121
    estimate_of_rows= rows_returned;
123
122
 
124
123
  row_cache.clear();
125
124
  record_id= 0;
 
125
}
 
126
 
 
127
int FunctionCursor::extra(enum ha_extra_function operation)
 
128
{
 
129
  switch (operation)
 
130
  {
 
131
  case drizzled::HA_EXTRA_CACHE:
 
132
    break;
 
133
  case drizzled::HA_EXTRA_NO_CACHE:
 
134
    break;
 
135
  case drizzled::HA_EXTRA_RESET_STATE:
 
136
    wipeCache();
 
137
    break;
 
138
  default:
 
139
    break;
 
140
  }
 
141
 
 
142
  return 0;
 
143
}
 
144
 
 
145
int FunctionCursor::doEndTableScan()
 
146
126
147
  delete generator; // Do this in case of an early exit from rnd_next()
127
148
 
128
149
  return 0;
133
154
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
134
155
  size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length);
135
156
 
136
 
  memcpy(buf, row_cache[position_id], table->s->reclength);
 
157
  assert(position_id * table->getShare()->getRecordLength() < row_cache.size());
 
158
  memcpy(buf, &row_cache[position_id * table->getShare()->getRecordLength()], table->getShare()->getRecordLength());
137
159
 
138
160
  return 0;
139
161
}