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