1063.4.5
by Padraig O'Sullivan
Fixed a stupid mistake I made in the innodb handler. Also reverted back to |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
20 |
||
21 |
/* Function with list databases, tables or fields */
|
|
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
22 |
#include "config.h" |
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
23 |
#include <drizzled/sql_select.h> |
575.4.7
by Monty Taylor
More header cleanup. |
24 |
#include <drizzled/show.h> |
538
by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib. |
25 |
#include <drizzled/gettext.h> |
492.1.8
by Monty Taylor
Replaced some int10_to_str with to_string. |
26 |
#include <drizzled/util/convert.h> |
550
by Monty Taylor
Moved error.h into just the files that need it. |
27 |
#include <drizzled/error.h> |
520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
28 |
#include <drizzled/tztime.h> |
520.6.7
by Monty Taylor
Moved a bunch of crap out of common_includes. |
29 |
#include <drizzled/data_home.h> |
642.1.63
by Lee
more header file cleanup |
30 |
#include <drizzled/item/blob.h> |
584.4.7
by Monty Taylor
Removed a big bank of includes from item.h. |
31 |
#include <drizzled/item/cmpfunc.h> |
642.1.17
by Lee
header file clean up |
32 |
#include <drizzled/item/return_int.h> |
642.1.23
by Lee
more header file cleanup |
33 |
#include <drizzled/item/empty_string.h> |
642.1.18
by Lee
header file clean up |
34 |
#include <drizzled/item/return_date_time.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
35 |
#include <drizzled/sql_base.h> |
36 |
#include <drizzled/db.h> |
|
584.5.1
by Monty Taylor
Removed field includes from field.h. |
37 |
#include <drizzled/field/timestamp.h> |
670.1.1
by Monty Taylor
Renamed fdecimal.* to decimal.*. Let's see how many things we can break! |
38 |
#include <drizzled/field/decimal.h> |
670.2.4
by Monty Taylor
Removed more stuff from the headers. |
39 |
#include <drizzled/lock.h> |
675
by Brian Aker
Cleanup around item includes. |
40 |
#include <drizzled/item/return_date_time.h> |
41 |
#include <drizzled/item/empty_string.h> |
|
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
42 |
#include "drizzled/plugin/registry.h" |
1241.9.17
by Monty Taylor
Removed more bits from server_includes. |
43 |
#include "drizzled/session_list.h" |
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
44 |
#include <drizzled/message/schema.pb.h> |
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
45 |
#include <drizzled/plugin/client.h> |
1241.9.44
by Monty Taylor
Made magic with cached_directory. |
46 |
#include <drizzled/cached_directory.h> |
1241.9.23
by Monty Taylor
Removed sql_table.h from server_includes.h. |
47 |
#include "drizzled/sql_table.h" |
1241.9.28
by Monty Taylor
Removed global_charset_info.h from server_includes.h |
48 |
#include "drizzled/global_charset_info.h" |
1241.9.31
by Monty Taylor
Moved global pthread variables into their own header. |
49 |
#include "drizzled/pthread_globals.h" |
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
50 |
#include "drizzled/internal/m_string.h" |
51 |
#include "drizzled/internal/my_sys.h" |
|
1241.9.28
by Monty Taylor
Removed global_charset_info.h from server_includes.h |
52 |
|
1108.4.2
by David Shrewsbury
Replace my_dir in find_files() with CachedDirectory. Renamed find_files() to find_dirs() to more accurately reflect what it is doing after removing dead code inside it. |
53 |
#include <sys/stat.h> |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
54 |
|
55 |
#include <string> |
|
629.4.1
by Monty Taylor
First step in support size_t sys_var stuff. |
56 |
#include <iostream> |
57 |
#include <sstream> |
|
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
58 |
#include <vector> |
59 |
#include <algorithm> |
|
629.4.1
by Monty Taylor
First step in support size_t sys_var stuff. |
60 |
|
61 |
using namespace std; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
62 |
|
63 |
namespace drizzled |
|
64 |
{
|
|
1
by brian
clean slate |
65 |
|
322.2.2
by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter. |
66 |
inline const char * |
67 |
str_or_nil(const char *str) |
|
68 |
{
|
|
69 |
return str ? str : "<nil>"; |
|
70 |
}
|
|
1
by brian
clean slate |
71 |
|
1014.3.4
by Brian Aker
Remove dead session calls. |
72 |
static void store_key_options(String *packet, Table *table, KEY *key_info); |
1
by brian
clean slate |
73 |
|
74 |
||
1273.13.38
by Brian Aker
Add in new show work. |
75 |
int wild_case_compare(const CHARSET_INFO * const cs, const char *str, const char *wildstr) |
1
by brian
clean slate |
76 |
{
|
77 |
register int flag; |
|
1273.13.61
by Brian Aker
Fixes a memory leak. sql_string() sucks. |
78 |
|
1
by brian
clean slate |
79 |
while (*wildstr) |
80 |
{
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
81 |
while (*wildstr && *wildstr != internal::wild_many && *wildstr != internal::wild_one) |
1
by brian
clean slate |
82 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
83 |
if (*wildstr == internal::wild_prefix && wildstr[1]) |
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
84 |
wildstr++; |
85 |
if (my_toupper(cs, *wildstr++) != my_toupper(cs, *str++)) |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
86 |
return (1); |
1
by brian
clean slate |
87 |
}
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
88 |
if (! *wildstr ) |
89 |
return (*str != 0); |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
90 |
if (*wildstr++ == internal::wild_one) |
1
by brian
clean slate |
91 |
{
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
92 |
if (! *str++) |
93 |
return (1); /* One char; skip */ |
|
1
by brian
clean slate |
94 |
}
|
95 |
else
|
|
96 |
{ /* Found '*' */ |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
97 |
if (! *wildstr) |
98 |
return (0); /* '*' as last char: OK */ |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
99 |
flag=(*wildstr != internal::wild_many && *wildstr != internal::wild_one); |
1
by brian
clean slate |
100 |
do
|
101 |
{
|
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
102 |
if (flag) |
103 |
{
|
|
104 |
char cmp; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
105 |
if ((cmp= *wildstr) == internal::wild_prefix && wildstr[1]) |
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
106 |
cmp= wildstr[1]; |
107 |
cmp= my_toupper(cs, cmp); |
|
108 |
while (*str && my_toupper(cs, *str) != cmp) |
|
109 |
str++; |
|
110 |
if (! *str) |
|
111 |
return (1); |
|
112 |
}
|
|
113 |
if (wild_case_compare(cs, str, wildstr) == 0) |
|
114 |
return (0); |
|
115 |
} while (*str++); |
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
116 |
return (1); |
1
by brian
clean slate |
117 |
}
|
118 |
}
|
|
1273.13.61
by Brian Aker
Fixes a memory leak. sql_string() sucks. |
119 |
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
120 |
return (*str != '\0'); |
1
by brian
clean slate |
121 |
}
|
122 |
||
123 |
||
1222.2.3
by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO. |
124 |
bool drizzled_show_create(Session *session, TableList *table_list, bool is_if_not_exists) |
1
by brian
clean slate |
125 |
{
|
126 |
char buff[2048]; |
|
127 |
String buffer(buff, sizeof(buff), system_charset_info); |
|
128 |
||
129 |
/* Only one table for now, but VIEW can involve several tables */
|
|
1109.1.3
by Brian Aker
Move names around a bit (to align similar methods) |
130 |
if (session->openTables(table_list)) |
1
by brian
clean slate |
131 |
{
|
737
by Brian Aker
Updates for dead code removal (and forced assert() in delete). |
132 |
if (session->is_error()) |
1014.3.4
by Brian Aker
Remove dead session calls. |
133 |
return true; |
1
by brian
clean slate |
134 |
|
135 |
/*
|
|
136 |
Clear all messages with 'error' level status and
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
137 |
issue a warning with 'warning' level status in
|
1
by brian
clean slate |
138 |
case of invalid view and last error is ER_VIEW_INVALID
|
139 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
140 |
drizzle_reset_errors(session, true); |
141 |
session->clear_error(); |
|
1
by brian
clean slate |
142 |
}
|
143 |
||
144 |
buffer.length(0); |
|
145 |
||
1222.1.3
by Brian Aker
Remove used flag for engine. |
146 |
if (store_create_info(table_list, &buffer, is_if_not_exists)) |
1014.3.4
by Brian Aker
Remove dead session calls. |
147 |
return true; |
1
by brian
clean slate |
148 |
|
149 |
List<Item> field_list; |
|
150 |
{
|
|
151 |
field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN)); |
|
152 |
// 1024 is for not to confuse old clients
|
|
153 |
field_list.push_back(new Item_empty_string("Create Table", |
|
1067.4.7
by Nathan Williams
The remaining files using cmax have been converted to std::max. |
154 |
max(buffer.length(),(uint32_t)1024))); |
1
by brian
clean slate |
155 |
}
|
156 |
||
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
157 |
if (session->client->sendFields(&field_list)) |
1014.3.4
by Brian Aker
Remove dead session calls. |
158 |
return true; |
1
by brian
clean slate |
159 |
{
|
1225.1.20
by Padraig O'Sullivan
Removed all remnants of schema_table from the TableList class. This cleans up a bunch of code. |
160 |
session->client->store(table_list->table->alias); |
1
by brian
clean slate |
161 |
}
|
162 |
||
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
163 |
session->client->store(buffer.ptr(), buffer.length()); |
1
by brian
clean slate |
164 |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
165 |
if (session->client->flush()) |
1014.3.4
by Brian Aker
Remove dead session calls. |
166 |
return true; |
1
by brian
clean slate |
167 |
|
836
by Brian Aker
Fixed session call from function to method. |
168 |
session->my_eof(); |
1014.3.4
by Brian Aker
Remove dead session calls. |
169 |
return false; |
1
by brian
clean slate |
170 |
}
|
171 |
||
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
172 |
/**
|
173 |
Get a CREATE statement for a given database.
|
|
174 |
||
175 |
The database is identified by its name, passed as @c dbname parameter.
|
|
176 |
The name should be encoded using the system character set (UTF8 currently).
|
|
177 |
||
178 |
Resulting statement is stored in the string pointed by @c buffer. The string
|
|
179 |
is emptied first and its character set is set to the system character set.
|
|
180 |
||
1222.2.3
by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO. |
181 |
If is_if_not_exists is set, then
|
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
182 |
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
|
183 |
in @c create_options are ignored.
|
|
184 |
||
185 |
@param session The current thread instance.
|
|
186 |
@param dbname The name of the database.
|
|
187 |
@param buffer A String instance where the statement is stored.
|
|
188 |
@param create_info If not NULL, the options member influences the resulting
|
|
189 |
CRATE statement.
|
|
190 |
||
191 |
@returns true if errors are detected, false otherwise.
|
|
192 |
*/
|
|
193 |
||
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
194 |
static bool store_db_create_info(const char *dbname, string &buffer, bool if_not_exists) |
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
195 |
{
|
1118.2.1
by Stewart Smith
fix drizzled::message::Table usage so that in kernel .cc files we are 'using namespace drizzled' |
196 |
message::Schema schema; |
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
197 |
|
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
198 |
bool found= plugin::StorageEngine::getSchemaDefinition(dbname, schema); |
199 |
if (not found) |
|
200 |
return false; |
|
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
201 |
|
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
202 |
buffer.append("CREATE DATABASE "); |
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
203 |
|
204 |
if (if_not_exists) |
|
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
205 |
buffer.append("IF NOT EXISTS "); |
206 |
||
207 |
buffer.append("`"); |
|
208 |
buffer.append(schema.name()); |
|
209 |
buffer.append("`"); |
|
210 |
||
211 |
if (schema.has_collation()) |
|
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
212 |
{
|
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
213 |
buffer.append(" COLLATE = "); |
214 |
buffer.append(schema.collation()); |
|
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
215 |
}
|
216 |
||
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
217 |
return true; |
1089.10.1
by Stewart Smith
fix SHOW CREATE DATABASE for default collation. Move database metadata reading code around to be a bit more sane. |
218 |
}
|
219 |
||
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
220 |
bool mysqld_show_create_db(Session *session, const char *dbname, bool if_not_exists) |
1
by brian
clean slate |
221 |
{
|
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
222 |
string buffer; |
1
by brian
clean slate |
223 |
|
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
224 |
if (not store_db_create_info(dbname, buffer, if_not_exists)) |
1
by brian
clean slate |
225 |
{
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
226 |
/*
|
1
by brian
clean slate |
227 |
This assumes that the only reason for which store_db_create_info()
|
228 |
can fail is incorrect database name (which is the case now).
|
|
229 |
*/
|
|
1273
by Brian Aker
Revert db patch. |
230 |
my_error(ER_BAD_DB_ERROR, MYF(0), dbname); |
1014.3.4
by Brian Aker
Remove dead session calls. |
231 |
return true; |
1
by brian
clean slate |
232 |
}
|
233 |
||
234 |
List<Item> field_list; |
|
235 |
field_list.push_back(new Item_empty_string("Database",NAME_CHAR_LEN)); |
|
236 |
field_list.push_back(new Item_empty_string("Create Database",1024)); |
|
237 |
||
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
238 |
if (session->client->sendFields(&field_list)) |
1014.3.4
by Brian Aker
Remove dead session calls. |
239 |
return true; |
1
by brian
clean slate |
240 |
|
1273
by Brian Aker
Revert db patch. |
241 |
session->client->store(dbname, strlen(dbname)); |
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
242 |
session->client->store(buffer); |
1
by brian
clean slate |
243 |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
244 |
if (session->client->flush()) |
1014.3.4
by Brian Aker
Remove dead session calls. |
245 |
return true; |
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
246 |
|
836
by Brian Aker
Fixed session call from function to method. |
247 |
session->my_eof(); |
1273.19.28
by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it... |
248 |
|
1014.3.4
by Brian Aker
Remove dead session calls. |
249 |
return false; |
1
by brian
clean slate |
250 |
}
|
251 |
||
252 |
/*
|
|
253 |
Get the quote character for displaying an identifier.
|
|
254 |
||
255 |
SYNOPSIS
|
|
256 |
get_quote_char_for_identifier()
|
|
257 |
||
258 |
IMPLEMENTATION
|
|
259 |
Force quoting in the following cases:
|
|
260 |
- name is empty (for one, it is possible when we use this function for
|
|
261 |
quoting user and host names for DEFINER clause);
|
|
262 |
- name is a keyword;
|
|
263 |
- name includes a special character;
|
|
264 |
Otherwise identifier is quoted only if the option OPTION_QUOTE_SHOW_CREATE
|
|
265 |
is set.
|
|
266 |
||
267 |
RETURN
|
|
268 |
EOF No quote character is needed
|
|
269 |
# Quote character
|
|
270 |
*/
|
|
271 |
||
1014.3.4
by Brian Aker
Remove dead session calls. |
272 |
int get_quote_char_for_identifier() |
1
by brian
clean slate |
273 |
{
|
352.2.1
by Harrison Fisk
Fix for bugs 259843 and 256482 |
274 |
return '`'; |
1
by brian
clean slate |
275 |
}
|
276 |
||
277 |
||
278 |
#define LIST_PROCESS_HOST_LEN 64
|
|
279 |
||
1014.3.4
by Brian Aker
Remove dead session calls. |
280 |
static bool get_field_default_value(Field *timestamp_field, |
1
by brian
clean slate |
281 |
Field *field, String *def_value, |
282 |
bool quoted) |
|
283 |
{
|
|
284 |
bool has_default; |
|
285 |
bool has_now_default; |
|
286 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
287 |
/*
|
1
by brian
clean slate |
288 |
We are using CURRENT_TIMESTAMP instead of NOW because it is
|
289 |
more standard
|
|
290 |
*/
|
|
291 |
has_now_default= (timestamp_field == field && |
|
292 |
field->unireg_check != Field::TIMESTAMP_UN_FIELD); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
293 |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
294 |
has_default= (field->type() != DRIZZLE_TYPE_BLOB && |
1
by brian
clean slate |
295 |
!(field->flags & NO_DEFAULT_VALUE_FLAG) && |
884.2.1
by Toru Maesaka
Fixed the bug of SHOW CREATE TABLE not outputting DEFAULT values. Killed some tabular indents on the way too |
296 |
field->unireg_check != Field::NEXT_NUMBER); |
1
by brian
clean slate |
297 |
|
298 |
def_value->length(0); |
|
299 |
if (has_default) |
|
300 |
{
|
|
301 |
if (has_now_default) |
|
302 |
def_value->append(STRING_WITH_LEN("CURRENT_TIMESTAMP")); |
|
303 |
else if (!field->is_null()) |
|
304 |
{ // Not null by default |
|
305 |
char tmp[MAX_FIELD_WIDTH]; |
|
306 |
String type(tmp, sizeof(tmp), field->charset()); |
|
307 |
field->val_str(&type); |
|
308 |
if (type.length()) |
|
309 |
{
|
|
310 |
String def_val; |
|
482
by Brian Aker
Remove uint. |
311 |
uint32_t dummy_errors; |
1
by brian
clean slate |
312 |
/* convert to system_charset_info == utf8 */
|
313 |
def_val.copy(type.ptr(), type.length(), field->charset(), |
|
314 |
system_charset_info, &dummy_errors); |
|
315 |
if (quoted) |
|
316 |
append_unescaped(def_value, def_val.ptr(), def_val.length()); |
|
317 |
else
|
|
318 |
def_value->append(def_val.ptr(), def_val.length()); |
|
319 |
}
|
|
320 |
else if (quoted) |
|
321 |
def_value->append(STRING_WITH_LEN("''")); |
|
322 |
}
|
|
323 |
else if (field->maybe_null() && quoted) |
|
324 |
def_value->append(STRING_WITH_LEN("NULL")); // Null as default |
|
325 |
else
|
|
1014.3.4
by Brian Aker
Remove dead session calls. |
326 |
return false; |
1
by brian
clean slate |
327 |
}
|
328 |
return has_default; |
|
329 |
}
|
|
330 |
||
331 |
/*
|
|
332 |
Build a CREATE TABLE statement for a table.
|
|
333 |
||
334 |
SYNOPSIS
|
|
335 |
store_create_info()
|
|
336 |
table_list A list containing one table to write statement
|
|
337 |
for.
|
|
338 |
packet Pointer to a string where statement will be
|
|
339 |
written.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
340 |
|
1
by brian
clean slate |
341 |
NOTE
|
342 |
Currently always return 0, but might return error code in the
|
|
343 |
future.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
344 |
|
1
by brian
clean slate |
345 |
RETURN
|
346 |
0 OK
|
|
347 |
*/
|
|
348 |
||
1222.1.3
by Brian Aker
Remove used flag for engine. |
349 |
int store_create_info(TableList *table_list, String *packet, bool is_if_not_exists) |
1
by brian
clean slate |
350 |
{
|
351 |
List<Item> field_list; |
|
492.1.8
by Monty Taylor
Replaced some int10_to_str with to_string. |
352 |
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH]; |
1
by brian
clean slate |
353 |
const char *alias; |
670.3.3
by Toru Maesaka
Added namespacing for std to .cc files that needed it |
354 |
string buff; |
1
by brian
clean slate |
355 |
String type(tmp, sizeof(tmp), system_charset_info); |
356 |
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info); |
|
357 |
Field **ptr,*field; |
|
482
by Brian Aker
Remove uint. |
358 |
uint32_t primary_key; |
1
by brian
clean slate |
359 |
KEY *key_info; |
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
360 |
Table *table= table_list->table; |
1208.3.2
by brian
Update for Cursor renaming. |
361 |
Cursor *cursor= table->cursor; |
1000.1.3
by Brian Aker
Renamed TABLE_SHARE to TableShare |
362 |
TableShare *share= table->s; |
1
by brian
clean slate |
363 |
HA_CREATE_INFO create_info; |
163
by Brian Aker
Merge Monty's code. |
364 |
bool show_table_options= false; |
1005.2.3
by Monty Taylor
Further reversion of P. |
365 |
my_bitmap_map *old_map; |
1
by brian
clean slate |
366 |
|
997.5.1
by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record |
367 |
table->restoreRecordAsDefault(); // Get empty record |
1
by brian
clean slate |
368 |
|
369 |
if (share->tmp_table) |
|
370 |
packet->append(STRING_WITH_LEN("CREATE TEMPORARY TABLE ")); |
|
371 |
else
|
|
372 |
packet->append(STRING_WITH_LEN("CREATE TABLE ")); |
|
1222.2.3
by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO. |
373 |
if (is_if_not_exists) |
1
by brian
clean slate |
374 |
packet->append(STRING_WITH_LEN("IF NOT EXISTS ")); |
1225.1.20
by Padraig O'Sullivan
Removed all remnants of schema_table from the TableList class. This cleans up a bunch of code. |
375 |
alias= share->table_name.str; |
1039.1.5
by Brian Aker
Remove lower case filename bits (aka we just lock into the most compatible |
376 |
|
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
377 |
packet->append_identifier(alias, strlen(alias)); |
1
by brian
clean slate |
378 |
packet->append(STRING_WITH_LEN(" (\n")); |
379 |
/*
|
|
380 |
We need this to get default values from the table
|
|
381 |
We have to restore the read_set if we are called from insert in case
|
|
382 |
of row based replication.
|
|
383 |
*/
|
|
1005.2.3
by Monty Taylor
Further reversion of P. |
384 |
old_map= table->use_all_columns(table->read_set); |
1
by brian
clean slate |
385 |
|
386 |
for (ptr=table->field ; (field= *ptr); ptr++) |
|
387 |
{
|
|
482
by Brian Aker
Remove uint. |
388 |
uint32_t flags = field->flags; |
1
by brian
clean slate |
389 |
|
390 |
if (ptr != table->field) |
|
391 |
packet->append(STRING_WITH_LEN(",\n")); |
|
392 |
||
393 |
packet->append(STRING_WITH_LEN(" ")); |
|
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
394 |
packet->append_identifier(field->field_name, strlen(field->field_name)); |
1
by brian
clean slate |
395 |
packet->append(' '); |
396 |
// check for surprises from the previous call to Field::sql_type()
|
|
397 |
if (type.ptr() != tmp) |
|
398 |
type.set(tmp, sizeof(tmp), system_charset_info); |
|
399 |
else
|
|
400 |
type.set_charset(system_charset_info); |
|
401 |
||
402 |
field->sql_type(type); |
|
403 |
packet->append(type.ptr(), type.length(), system_charset_info); |
|
404 |
||
405 |
if (field->has_charset()) |
|
406 |
{
|
|
407 |
if (field->charset() != share->table_charset) |
|
408 |
{
|
|
884.2.1
by Toru Maesaka
Fixed the bug of SHOW CREATE TABLE not outputting DEFAULT values. Killed some tabular indents on the way too |
409 |
packet->append(STRING_WITH_LEN(" CHARACTER SET ")); |
410 |
packet->append(field->charset()->csname); |
|
1
by brian
clean slate |
411 |
}
|
884.2.1
by Toru Maesaka
Fixed the bug of SHOW CREATE TABLE not outputting DEFAULT values. Killed some tabular indents on the way too |
412 |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
413 |
/*
|
884.2.1
by Toru Maesaka
Fixed the bug of SHOW CREATE TABLE not outputting DEFAULT values. Killed some tabular indents on the way too |
414 |
For string types dump collation name only if
|
415 |
collation is not primary for the given charset
|
|
1
by brian
clean slate |
416 |
*/
|
417 |
if (!(field->charset()->state & MY_CS_PRIMARY)) |
|
418 |
{
|
|
884.2.1
by Toru Maesaka
Fixed the bug of SHOW CREATE TABLE not outputting DEFAULT values. Killed some tabular indents on the way too |
419 |
packet->append(STRING_WITH_LEN(" COLLATE ")); |
420 |
packet->append(field->charset()->name); |
|
1
by brian
clean slate |
421 |
}
|
422 |
}
|
|
423 |
||
424 |
if (flags & NOT_NULL_FLAG) |
|
425 |
packet->append(STRING_WITH_LEN(" NOT NULL")); |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
426 |
else if (field->type() == DRIZZLE_TYPE_TIMESTAMP) |
1
by brian
clean slate |
427 |
{
|
428 |
/*
|
|
429 |
TIMESTAMP field require explicit NULL flag, because unlike
|
|
430 |
all other fields they are treated as NOT NULL by default.
|
|
431 |
*/
|
|
432 |
packet->append(STRING_WITH_LEN(" NULL")); |
|
433 |
}
|
|
434 |
{
|
|
435 |
/*
|
|
436 |
Add field flags about FIELD FORMAT (FIXED or DYNAMIC)
|
|
437 |
and about STORAGE (DISK or MEMORY).
|
|
438 |
*/
|
|
439 |
enum column_format_type column_format= (enum column_format_type) |
|
440 |
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK); |
|
441 |
if (column_format) |
|
442 |
{
|
|
443 |
packet->append(STRING_WITH_LEN(" /*!")); |
|
444 |
packet->append(STRING_WITH_LEN(" COLUMN_FORMAT")); |
|
445 |
if (column_format == COLUMN_FORMAT_TYPE_FIXED) |
|
446 |
packet->append(STRING_WITH_LEN(" FIXED */")); |
|
447 |
else
|
|
448 |
packet->append(STRING_WITH_LEN(" DYNAMIC */")); |
|
449 |
}
|
|
450 |
}
|
|
1014.3.4
by Brian Aker
Remove dead session calls. |
451 |
if (get_field_default_value(table->timestamp_field, field, &def_value, 1)) |
1
by brian
clean slate |
452 |
{
|
453 |
packet->append(STRING_WITH_LEN(" DEFAULT ")); |
|
454 |
packet->append(def_value.ptr(), def_value.length(), system_charset_info); |
|
455 |
}
|
|
456 |
||
457 |
if (table->timestamp_field == field && field->unireg_check != Field::TIMESTAMP_DN_FIELD) |
|
458 |
packet->append(STRING_WITH_LEN(" ON UPDATE CURRENT_TIMESTAMP")); |
|
459 |
||
460 |
if (field->unireg_check == Field::NEXT_NUMBER) |
|
461 |
packet->append(STRING_WITH_LEN(" AUTO_INCREMENT")); |
|
462 |
||
463 |
if (field->comment.length) |
|
464 |
{
|
|
465 |
packet->append(STRING_WITH_LEN(" COMMENT ")); |
|
466 |
append_unescaped(packet, field->comment.str, field->comment.length); |
|
467 |
}
|
|
468 |
}
|
|
469 |
||
470 |
key_info= table->key_info; |
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
471 |
memset(&create_info, 0, sizeof(create_info)); |
1
by brian
clean slate |
472 |
/* Allow update_create_info to update row type */
|
473 |
create_info.row_type= share->row_type; |
|
1208.3.2
by brian
Update for Cursor renaming. |
474 |
cursor->update_create_info(&create_info); |
1
by brian
clean slate |
475 |
primary_key= share->primary_key; |
476 |
||
482
by Brian Aker
Remove uint. |
477 |
for (uint32_t i=0 ; i < share->keys ; i++,key_info++) |
1
by brian
clean slate |
478 |
{
|
479 |
KEY_PART_INFO *key_part= key_info->key_part; |
|
480 |
bool found_primary=0; |
|
481 |
packet->append(STRING_WITH_LEN(",\n ")); |
|
482 |
||
590.1.1
by Stewart Smith
begin moving from global const char* primary_key_name to methods is_primary_key() and is_primary_key_name() |
483 |
if (i == primary_key && is_primary_key(key_info)) |
1
by brian
clean slate |
484 |
{
|
485 |
found_primary=1; |
|
486 |
/*
|
|
487 |
No space at end, because a space will be added after where the
|
|
488 |
identifier would go, but that is not added for primary key.
|
|
489 |
*/
|
|
490 |
packet->append(STRING_WITH_LEN("PRIMARY KEY")); |
|
491 |
}
|
|
492 |
else if (key_info->flags & HA_NOSAME) |
|
493 |
packet->append(STRING_WITH_LEN("UNIQUE KEY ")); |
|
494 |
else
|
|
495 |
packet->append(STRING_WITH_LEN("KEY ")); |
|
496 |
||
497 |
if (!found_primary) |
|
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
498 |
packet->append_identifier(key_info->name, strlen(key_info->name)); |
1
by brian
clean slate |
499 |
|
500 |
packet->append(STRING_WITH_LEN(" (")); |
|
501 |
||
482
by Brian Aker
Remove uint. |
502 |
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++) |
1
by brian
clean slate |
503 |
{
|
504 |
if (j) |
|
505 |
packet->append(','); |
|
506 |
||
507 |
if (key_part->field) |
|
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
508 |
packet->append_identifier(key_part->field->field_name, |
884.2.1
by Toru Maesaka
Fixed the bug of SHOW CREATE TABLE not outputting DEFAULT values. Killed some tabular indents on the way too |
509 |
strlen(key_part->field->field_name)); |
1
by brian
clean slate |
510 |
if (key_part->field && |
511 |
(key_part->length != |
|
512 |
table->field[key_part->fieldnr-1]->key_length())) |
|
513 |
{
|
|
1008.3.8
by Stewart Smith
remove more evil that is operator overloading. |
514 |
buff.assign("("); |
1008.3.7
by Stewart Smith
remove evil that is operator overloading. |
515 |
buff.append(to_string((int32_t) key_part->length / |
516 |
key_part->field->charset()->mbmaxlen)); |
|
517 |
buff.append(")"); |
|
492.1.8
by Monty Taylor
Replaced some int10_to_str with to_string. |
518 |
packet->append(buff.c_str(), buff.length()); |
1
by brian
clean slate |
519 |
}
|
520 |
}
|
|
521 |
packet->append(')'); |
|
1014.3.4
by Brian Aker
Remove dead session calls. |
522 |
store_key_options(packet, table, key_info); |
1
by brian
clean slate |
523 |
}
|
524 |
||
525 |
/*
|
|
526 |
Get possible foreign key definitions stored in InnoDB and append them
|
|
527 |
to the CREATE TABLE statement
|
|
528 |
*/
|
|
529 |
||
1208.3.2
by brian
Update for Cursor renaming. |
530 |
if ((for_str= cursor->get_foreign_key_create_info())) |
1
by brian
clean slate |
531 |
{
|
532 |
packet->append(for_str, strlen(for_str)); |
|
1208.3.2
by brian
Update for Cursor renaming. |
533 |
cursor->free_foreign_key_create_info(for_str); |
1
by brian
clean slate |
534 |
}
|
535 |
||
536 |
packet->append(STRING_WITH_LEN("\n)")); |
|
537 |
{
|
|
163
by Brian Aker
Merge Monty's code. |
538 |
show_table_options= true; |
1
by brian
clean slate |
539 |
/*
|
540 |
Get possible table space definitions and append them
|
|
541 |
to the CREATE TABLE statement
|
|
542 |
*/
|
|
543 |
||
1222.1.3
by Brian Aker
Remove used flag for engine. |
544 |
/*
|
545 |
We should always store engine since we will now be
|
|
546 |
making sure engines accept options (aka... no
|
|
547 |
dangling arguments for engines.
|
|
1
by brian
clean slate |
548 |
*/
|
1222.1.3
by Brian Aker
Remove used flag for engine. |
549 |
packet->append(STRING_WITH_LEN(" ENGINE=")); |
550 |
packet->append(cursor->engine->getName().c_str()); |
|
1
by brian
clean slate |
551 |
|
552 |
if (share->db_create_options & HA_OPTION_PACK_KEYS) |
|
553 |
packet->append(STRING_WITH_LEN(" PACK_KEYS=1")); |
|
554 |
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS) |
|
555 |
packet->append(STRING_WITH_LEN(" PACK_KEYS=0")); |
|
556 |
if (create_info.row_type != ROW_TYPE_DEFAULT) |
|
557 |
{
|
|
558 |
packet->append(STRING_WITH_LEN(" ROW_FORMAT=")); |
|
895
by Brian Aker
Completion (?) of uint conversion. |
559 |
packet->append(ha_row_type[(uint32_t) create_info.row_type]); |
1
by brian
clean slate |
560 |
}
|
1188.2.1
by Stewart Smith
move key_block_size out of table_share and into the table proto. init it in parser |
561 |
if (table->s->hasKeyBlockSize()) |
1
by brian
clean slate |
562 |
{
|
563 |
packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE=")); |
|
1188.2.1
by Stewart Smith
move key_block_size out of table_share and into the table proto. init it in parser |
564 |
buff= to_string(table->s->getKeyBlockSize()); |
492.1.8
by Monty Taylor
Replaced some int10_to_str with to_string. |
565 |
packet->append(buff.c_str(), buff.length()); |
1
by brian
clean slate |
566 |
}
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
567 |
if (share->block_size) |
568 |
{
|
|
569 |
packet->append(STRING_WITH_LEN(" BLOCK_SIZE=")); |
|
492.1.8
by Monty Taylor
Replaced some int10_to_str with to_string. |
570 |
buff= to_string(share->block_size); |
571 |
packet->append(buff.c_str(), buff.length()); |
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
572 |
}
|
1208.3.2
by brian
Update for Cursor renaming. |
573 |
table->cursor->append_create_info(packet); |
1116.1.1
by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem). |
574 |
if (share->hasComment() && share->getCommentLength()) |
1
by brian
clean slate |
575 |
{
|
576 |
packet->append(STRING_WITH_LEN(" COMMENT=")); |
|
1116.1.1
by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem). |
577 |
append_unescaped(packet, share->getComment(), |
578 |
share->getCommentLength()); |
|
1
by brian
clean slate |
579 |
}
|
580 |
}
|
|
1005.2.3
by Monty Taylor
Further reversion of P. |
581 |
table->restore_column_map(old_map); |
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
582 |
return(0); |
1
by brian
clean slate |
583 |
}
|
584 |
||
1014.3.4
by Brian Aker
Remove dead session calls. |
585 |
static void store_key_options(String *packet, Table *table, KEY *key_info) |
1
by brian
clean slate |
586 |
{
|
587 |
char *end, buff[32]; |
|
588 |
||
589 |
if (key_info->algorithm == HA_KEY_ALG_BTREE) |
|
590 |
packet->append(STRING_WITH_LEN(" USING BTREE")); |
|
591 |
||
592 |
if (key_info->algorithm == HA_KEY_ALG_HASH) |
|
593 |
packet->append(STRING_WITH_LEN(" USING HASH")); |
|
594 |
||
595 |
if ((key_info->flags & HA_USES_BLOCK_SIZE) && |
|
1188.2.1
by Stewart Smith
move key_block_size out of table_share and into the table proto. init it in parser |
596 |
table->s->getKeyBlockSize() != key_info->block_size) |
1
by brian
clean slate |
597 |
{
|
598 |
packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE=")); |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
599 |
end= internal::int64_t10_to_str(key_info->block_size, buff, 10); |
895
by Brian Aker
Completion (?) of uint conversion. |
600 |
packet->append(buff, (uint32_t) (end - buff)); |
1
by brian
clean slate |
601 |
}
|
602 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
603 |
assert(test(key_info->flags & HA_USES_COMMENT) == |
1
by brian
clean slate |
604 |
(key_info->comment.length > 0)); |
605 |
if (key_info->flags & HA_USES_COMMENT) |
|
606 |
{
|
|
607 |
packet->append(STRING_WITH_LEN(" COMMENT ")); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
608 |
append_unescaped(packet, key_info->comment.str, |
1
by brian
clean slate |
609 |
key_info->comment.length); |
610 |
}
|
|
611 |
}
|
|
612 |
||
613 |
||
614 |
/****************************************************************************
|
|
615 |
Return info about all processes
|
|
616 |
returns for each thread: thread id, user, host, db, command, info
|
|
617 |
****************************************************************************/
|
|
618 |
||
1245.2.1
by Monty Taylor
Removed final use if I_List<> in the server. |
619 |
class thread_info |
620 |
{
|
|
621 |
thread_info(); |
|
1
by brian
clean slate |
622 |
public: |
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
623 |
uint64_t thread_id; |
1
by brian
clean slate |
624 |
time_t start_time; |
482
by Brian Aker
Remove uint. |
625 |
uint32_t command; |
1292
by Brian Aker
Merge in security refactor. |
626 |
string user; |
627 |
string host; |
|
628 |
string db; |
|
629 |
string proc_info; |
|
630 |
string state_info; |
|
631 |
string query; |
|
1245.2.7
by Monty Taylor
Merged up with trunk. |
632 |
thread_info(uint64_t thread_id_arg, |
633 |
time_t start_time_arg, |
|
634 |
uint32_t command_arg, |
|
1245.2.1
by Monty Taylor
Removed final use if I_List<> in the server. |
635 |
const string &user_arg, |
636 |
const string &host_arg, |
|
637 |
const string &db_arg, |
|
638 |
const string &proc_info_arg, |
|
639 |
const string &state_info_arg, |
|
640 |
const string &query_arg) |
|
641 |
: thread_id(thread_id_arg), start_time(start_time_arg), command(command_arg), |
|
642 |
user(user_arg), host(host_arg), db(db_arg), proc_info(proc_info_arg), |
|
643 |
state_info(state_info_arg), query(query_arg) |
|
644 |
{}
|
|
1
by brian
clean slate |
645 |
};
|
646 |
||
647 |
/*****************************************************************************
|
|
648 |
Status functions
|
|
649 |
*****************************************************************************/
|
|
650 |
||
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
651 |
static vector<drizzle_show_var *> all_status_vars; |
1273.13.76
by Brian Aker
Remove dead SHOW_ARRAY type. |
652 |
static vector<drizzle_show_var *> com_status_vars; |
1
by brian
clean slate |
653 |
static bool status_vars_inited= 0; |
1165.1.122
by Stewart Smith
make show_var_cmp() static in drizzled/show.cc |
654 |
static int show_var_cmp(const void *var1, const void *var2) |
1
by brian
clean slate |
655 |
{
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
656 |
return strcmp(((drizzle_show_var*)var1)->name, ((drizzle_show_var*)var2)->name); |
1
by brian
clean slate |
657 |
}
|
658 |
||
901.1.13
by Padraig
Renaming the function object for the std::sort() algorithm. |
659 |
class show_var_cmp_functor |
901.1.9
by Padraig
Modified function object to be used as comparison parameter for sort() |
660 |
{
|
661 |
public: |
|
901.1.13
by Padraig
Renaming the function object for the std::sort() algorithm. |
662 |
show_var_cmp_functor() { } |
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
663 |
inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const |
901.1.9
by Padraig
Modified function object to be used as comparison parameter for sort() |
664 |
{
|
901.1.22
by Padraig
Small modifications based on Jay's merge review comments. Should be all good |
665 |
int val= strcmp(var1->name, var2->name); |
666 |
return (val < 0); |
|
901.1.9
by Padraig
Modified function object to be used as comparison parameter for sort() |
667 |
}
|
668 |
};
|
|
669 |
||
901.1.14
by Padraig
Changing name of functor show_var_if to show_var_remove_if. |
670 |
class show_var_remove_if |
901.1.4
by Padraig
Added function object to be used for removing elements from the vector. This |
671 |
{
|
672 |
public: |
|
901.1.14
by Padraig
Changing name of functor show_var_if to show_var_remove_if. |
673 |
show_var_remove_if() { } |
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
674 |
inline bool operator()(const drizzle_show_var *curr) const |
901.1.4
by Padraig
Added function object to be used for removing elements from the vector. This |
675 |
{
|
901.1.8
by Padraig
Removed function which has become unused and also added some more comments. |
676 |
return (curr->type == SHOW_UNDEF); |
901.1.4
by Padraig
Added function object to be used for removing elements from the vector. This |
677 |
}
|
678 |
};
|
|
679 |
||
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
680 |
drizzle_show_var *getFrontOfStatusVars() |
1088.1.1
by Padraig O'Sullivan
Extracted the 3 STATUS tables into the I_S plugin. |
681 |
{
|
682 |
return all_status_vars.front(); |
|
683 |
}
|
|
684 |
||
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
685 |
drizzle_show_var *getCommandStatusVars() |
1273.13.22
by Brian Aker
Added status bits. Variables next! |
686 |
{
|
1273.13.76
by Brian Aker
Remove dead SHOW_ARRAY type. |
687 |
return com_status_vars.front(); |
1273.13.22
by Brian Aker
Added status bits. Variables next! |
688 |
}
|
689 |
||
1
by brian
clean slate |
690 |
/*
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
691 |
Adds an array of drizzle_show_var entries to the output of SHOW STATUS
|
1
by brian
clean slate |
692 |
|
693 |
SYNOPSIS
|
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
694 |
add_status_vars(drizzle_show_var *list)
|
695 |
list - an array of drizzle_show_var entries to add to all_status_vars
|
|
1
by brian
clean slate |
696 |
the last entry must be {0,0,SHOW_UNDEF}
|
697 |
||
698 |
NOTE
|
|
699 |
The handling of all_status_vars[] is completely internal, it's allocated
|
|
700 |
automatically when something is added to it, and deleted completely when
|
|
701 |
the last entry is removed.
|
|
702 |
||
703 |
As a special optimization, if add_status_vars() is called before
|
|
704 |
init_status_vars(), it assumes "startup mode" - neither concurrent access
|
|
705 |
to the array nor SHOW STATUS are possible (thus it skips locks and qsort)
|
|
706 |
*/
|
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
707 |
int add_status_vars(drizzle_show_var *list) |
1
by brian
clean slate |
708 |
{
|
709 |
int res= 0; |
|
710 |
if (status_vars_inited) |
|
711 |
pthread_mutex_lock(&LOCK_status); |
|
712 |
while (list->name) |
|
901.1.22
by Padraig
Small modifications based on Jay's merge review comments. Should be all good |
713 |
all_status_vars.insert(all_status_vars.begin(), list++); |
1
by brian
clean slate |
714 |
if (status_vars_inited) |
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
715 |
sort(all_status_vars.begin(), all_status_vars.end(), |
901.1.17
by Padraig
cleaning up comments a little bit. |
716 |
show_var_cmp_functor()); |
1
by brian
clean slate |
717 |
if (status_vars_inited) |
718 |
pthread_mutex_unlock(&LOCK_status); |
|
719 |
return res; |
|
720 |
}
|
|
721 |
||
1273.13.76
by Brian Aker
Remove dead SHOW_ARRAY type. |
722 |
int add_com_status_vars(drizzle_show_var *list) |
723 |
{
|
|
724 |
int res= 0; |
|
725 |
||
726 |
while (list->name) |
|
727 |
com_status_vars.insert(com_status_vars.begin(), list++); |
|
728 |
if (status_vars_inited) |
|
729 |
sort(com_status_vars.begin(), com_status_vars.end(), |
|
730 |
show_var_cmp_functor()); |
|
731 |
||
732 |
return res; |
|
733 |
}
|
|
734 |
||
1
by brian
clean slate |
735 |
/*
|
736 |
Make all_status_vars[] usable for SHOW STATUS
|
|
737 |
||
738 |
NOTE
|
|
739 |
See add_status_vars(). Before init_status_vars() call, add_status_vars()
|
|
740 |
works in a special fast "startup" mode. Thus init_status_vars()
|
|
741 |
should be called as late as possible but before enabling multi-threading.
|
|
742 |
*/
|
|
743 |
void init_status_vars() |
|
744 |
{
|
|
901.1.3
by Padraig
More work on removing DYNAMIC_ARRAY from show.cc |
745 |
status_vars_inited= 1; |
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
746 |
sort(all_status_vars.begin(), all_status_vars.end(), |
901.1.17
by Padraig
cleaning up comments a little bit. |
747 |
show_var_cmp_functor()); |
1273.13.76
by Brian Aker
Remove dead SHOW_ARRAY type. |
748 |
sort(com_status_vars.begin(), com_status_vars.end(), |
749 |
show_var_cmp_functor()); |
|
1
by brian
clean slate |
750 |
}
|
751 |
||
752 |
void reset_status_vars() |
|
753 |
{
|
|
1273.13.76
by Brian Aker
Remove dead SHOW_ARRAY type. |
754 |
vector<drizzle_show_var *>::iterator p; |
755 |
||
756 |
p= all_status_vars.begin(); |
|
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
757 |
while (p != all_status_vars.end()) |
1
by brian
clean slate |
758 |
{
|
759 |
/* Note that SHOW_LONG_NOFLUSH variables are not reset */
|
|
901.1.3
by Padraig
More work on removing DYNAMIC_ARRAY from show.cc |
760 |
if ((*p)->type == SHOW_LONG) |
761 |
(*p)->value= 0; |
|
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
762 |
++p; |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
763 |
}
|
1273.13.76
by Brian Aker
Remove dead SHOW_ARRAY type. |
764 |
|
765 |
p= com_status_vars.begin(); |
|
766 |
while (p != com_status_vars.end()) |
|
767 |
{
|
|
768 |
/* Note that SHOW_LONG_NOFLUSH variables are not reset */
|
|
769 |
if ((*p)->type == SHOW_LONG) |
|
770 |
(*p)->value= 0; |
|
771 |
++p; |
|
772 |
}
|
|
1
by brian
clean slate |
773 |
}
|
774 |
||
775 |
/*
|
|
776 |
catch-all cleanup function, cleans up everything no matter what
|
|
777 |
||
778 |
DESCRIPTION
|
|
779 |
This function is not strictly required if all add_to_status/
|
|
780 |
remove_status_vars are properly paired, but it's a safety measure that
|
|
901.1.17
by Padraig
cleaning up comments a little bit. |
781 |
deletes everything from the all_status_vars vector even if some
|
1
by brian
clean slate |
782 |
remove_status_vars were forgotten
|
783 |
*/
|
|
901.1.3
by Padraig
More work on removing DYNAMIC_ARRAY from show.cc |
784 |
void free_status_vars() |
785 |
{
|
|
901.1.12
by Padraig
Modifying free_status_vars() for std::vector. |
786 |
all_status_vars.clear(); |
1273.13.76
by Brian Aker
Remove dead SHOW_ARRAY type. |
787 |
com_status_vars.clear(); |
901.1.3
by Padraig
More work on removing DYNAMIC_ARRAY from show.cc |
788 |
}
|
1
by brian
clean slate |
789 |
|
790 |
/*
|
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
791 |
Removes an array of drizzle_show_var entries from the output of SHOW STATUS
|
1
by brian
clean slate |
792 |
|
793 |
SYNOPSIS
|
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
794 |
remove_status_vars(drizzle_show_var *list)
|
795 |
list - an array of drizzle_show_var entries to remove to all_status_vars
|
|
1
by brian
clean slate |
796 |
the last entry must be {0,0,SHOW_UNDEF}
|
797 |
||
798 |
NOTE
|
|
799 |
there's lots of room for optimizing this, especially in non-sorted mode,
|
|
800 |
but nobody cares - it may be called only in case of failed plugin
|
|
801 |
initialization in the mysqld startup.
|
|
802 |
*/
|
|
803 |
||
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
804 |
void remove_status_vars(drizzle_show_var *list) |
1
by brian
clean slate |
805 |
{
|
806 |
if (status_vars_inited) |
|
807 |
{
|
|
808 |
pthread_mutex_lock(&LOCK_status); |
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
809 |
drizzle_show_var *all= all_status_vars.front(); |
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
810 |
int a= 0, b= all_status_vars.size(), c= (a+b)/2; |
1
by brian
clean slate |
811 |
|
812 |
for (; list->name; list++) |
|
813 |
{
|
|
814 |
int res= 0; |
|
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
815 |
for (a= 0, b= all_status_vars.size(); b-a > 1; c= (a+b)/2) |
1
by brian
clean slate |
816 |
{
|
817 |
res= show_var_cmp(list, all+c); |
|
818 |
if (res < 0) |
|
819 |
b= c; |
|
820 |
else if (res > 0) |
|
821 |
a= c; |
|
822 |
else
|
|
823 |
break; |
|
824 |
}
|
|
825 |
if (res == 0) |
|
826 |
all[c].type= SHOW_UNDEF; |
|
827 |
}
|
|
901.1.8
by Padraig
Removed function which has become unused and also added some more comments. |
828 |
/* removes all the SHOW_UNDEF elements from the vector */
|
901.1.18
by Padraig
Adding std:: prefix to remove_if since that caused compilation errors on |
829 |
all_status_vars.erase(std::remove_if(all_status_vars.begin(), |
901.1.14
by Padraig
Changing name of functor show_var_if to show_var_remove_if. |
830 |
all_status_vars.end(),show_var_remove_if()), |
901.1.4
by Padraig
Added function object to be used for removing elements from the vector. This |
831 |
all_status_vars.end()); |
1
by brian
clean slate |
832 |
pthread_mutex_unlock(&LOCK_status); |
833 |
}
|
|
834 |
else
|
|
835 |
{
|
|
1273.13.73
by Brian Aker
Remove typedef and drop some dead code. |
836 |
drizzle_show_var *all= all_status_vars.front(); |
482
by Brian Aker
Remove uint. |
837 |
uint32_t i; |
1
by brian
clean slate |
838 |
for (; list->name; list++) |
839 |
{
|
|
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
840 |
for (i= 0; i < all_status_vars.size(); i++) |
1
by brian
clean slate |
841 |
{
|
842 |
if (show_var_cmp(list, all+i)) |
|
843 |
continue; |
|
844 |
all[i].type= SHOW_UNDEF; |
|
845 |
break; |
|
846 |
}
|
|
847 |
}
|
|
901.1.8
by Padraig
Removed function which has become unused and also added some more comments. |
848 |
/* removes all the SHOW_UNDEF elements from the vector */
|
901.1.18
by Padraig
Adding std:: prefix to remove_if since that caused compilation errors on |
849 |
all_status_vars.erase(std::remove_if(all_status_vars.begin(), |
901.1.14
by Padraig
Changing name of functor show_var_if to show_var_remove_if. |
850 |
all_status_vars.end(),show_var_remove_if()), |
901.1.4
by Padraig
Added function object to be used for removing elements from the vector. This |
851 |
all_status_vars.end()); |
1
by brian
clean slate |
852 |
}
|
853 |
}
|
|
854 |
||
855 |
/* collect status for all running threads */
|
|
856 |
||
1273.13.74
by Brian Aker
Bits of dead code/STATUS_VAR rename. |
857 |
void calc_sum_of_all_status(system_status_var *to) |
1
by brian
clean slate |
858 |
{
|
859 |
/* Ensure that thread id not killed during loop */
|
|
398.1.6
by Monty Taylor
Removed __alpha__ references. |
860 |
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list |
1
by brian
clean slate |
861 |
|
862 |
/* Get global values as base */
|
|
863 |
*to= global_status_var; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
864 |
|
1
by brian
clean slate |
865 |
/* Add to this status from existing threads */
|
1320.1.14
by Brian Aker
Small style issue. |
866 |
for(SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it ) |
1014.7.1
by Nathan Williams
Replaced global I_List<Session> with std::vector<Session*> |
867 |
{
|
868 |
add_to_status(to, &((*it)->status_var)); |
|
869 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
870 |
|
398.1.6
by Monty Taylor
Removed __alpha__ references. |
871 |
pthread_mutex_unlock(&LOCK_thread_count); |
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
872 |
return; |
1
by brian
clean slate |
873 |
}
|
874 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
875 |
} /* namespace drizzled */ |