1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Copyright (C) 2009 Sun Microsystems
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <plugin/information_engine/information_cursor.h>
#include <drizzled/session.h>
#include <string>
using namespace std;
using namespace drizzled;
/*****************************************************************************
** INFORMATION_ENGINE tables
*****************************************************************************/
InformationCursor::InformationCursor(plugin::StorageEngine &engine_arg,
TableShare &table_arg) :
Cursor(engine_arg, table_arg)
{}
int InformationCursor::open(const char *name, int, uint32_t)
{
string tab_name(name);
string i_s_prefix("./information_schema/");
tab_name.erase(0, i_s_prefix.length());
share= ((InformationEngine *)engine)->getShare(tab_name);
assert(share);
thr_lock_data_init(&share->lock, &lock, NULL);
return 0;
}
int InformationCursor::close(void)
{
((InformationEngine *)engine)->freeShare(share);
return 0;
}
int InformationCursor::rnd_init(bool)
{
plugin::InfoSchemaTable *sch_table= share->getInfoSchemaTable();
if (sch_table)
{
if (! sch_table->getRows().empty())
{
sch_table->clearRows();
}
sch_table->fillTable(ha_session(),
table);
iter= sch_table->getRows().begin();
}
return 0;
}
int InformationCursor::rnd_next(unsigned char *buf)
{
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
plugin::InfoSchemaTable *sch_table= share->getInfoSchemaTable();
if (iter != sch_table->getRows().end() &&
! sch_table->getRows().empty())
{
(*iter)->copyRecordInto(buf);
++iter;
return 0;
}
return HA_ERR_END_OF_FILE;
}
class FindRowByChecksum
{
uint32_t checksum;
public:
FindRowByChecksum(uint32_t in_crc)
:
checksum(in_crc)
{}
inline bool operator()(const plugin::InfoSchemaRecord *rec) const
{
return rec->checksumMatches(checksum);
}
};
void InformationCursor::position(const unsigned char *record)
{
/* compute a hash of the row */
uint32_t cs= drizzled::hash::crc32((const char *) record, table->s->reclength);
/* copy the hash into ref */
memcpy(ref, &cs, sizeof(uint32_t));
}
int InformationCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
{
ha_statistic_increment(&SSV::ha_read_rnd_count);
/* get the checksum */
uint32_t cs;
memcpy(&cs, pos, sizeof(uint32_t));
/* search for that data */
plugin::InfoSchemaTable *sch_table= share->getInfoSchemaTable();
plugin::InfoSchemaTable::Rows::iterator it= find_if(sch_table->getRows().begin(),
sch_table->getRows().end(),
FindRowByChecksum(cs));
if (it != sch_table->getRows().end())
{
(*it)->copyRecordInto(buf);
}
return 0;
}
int InformationCursor::info(uint32_t flag)
{
memset(&stats, 0, sizeof(stats));
if (flag & HA_STATUS_AUTO)
stats.auto_increment_value= 1;
return 0;
}
|