~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
17
/* create and drop of databases */
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
18
#include "config.h"
1259.3.7 by Monty Taylor
Fixed OSX build error.
19
20
#include <fcntl.h>
21
#include <sys/stat.h>
22
#include <sys/types.h>
23
24
#include <set>
318 by Brian Aker
Modified sql_db to now use Google Proto buffers instead of MySQL type.
25
#include <string>
26
#include <fstream>
1259.3.7 by Monty Taylor
Fixed OSX build error.
27
1271.5.3 by Tim Penhey
change the include files
28
#include "drizzled/error.h"
538 by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib.
29
#include <drizzled/gettext.h>
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
30
#include <drizzled/my_hash.h>
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
31
#include "drizzled/internal/m_string.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.
32
#include <drizzled/session.h>
33
#include <drizzled/db.h>
34
#include <drizzled/sql_base.h>
670.2.4 by Monty Taylor
Removed more stuff from the headers.
35
#include <drizzled/lock.h>
722.4.1 by Mark Atwood
integrate errmsg plugin into sql_print_* functions
36
#include <drizzled/errmsg_print.h>
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
37
#include <drizzled/transaction_services.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.
38
#include <drizzled/message/schema.pb.h>
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
39
#include "drizzled/sql_table.h"
1273.20.3 by Brian Aker
Fixing charset return.
40
#include "drizzled/plugin/storage_engine.h"
1317.2.1 by Monty Taylor
Removed an unused variable.
41
#include "drizzled/plugin/authorization.h"
1241.9.28 by Monty Taylor
Removed global_charset_info.h from server_includes.h
42
#include "drizzled/global_charset_info.h"
1241.9.31 by Monty Taylor
Moved global pthread variables into their own header.
43
#include "drizzled/pthread_globals.h"
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
44
#include "drizzled/charset.h"
1241.9.28 by Monty Taylor
Removed global_charset_info.h from server_includes.h
45
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
46
#include <boost/thread/mutex.hpp>
47
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
48
#include "drizzled/internal/my_sys.h"
988.1.6 by Jay Pipes
Removed old protobuf_replicator plugin, fixed up db.cc and other files to use new
49
1 by brian
clean slate
50
#define MAX_DROP_TABLE_Q_LEN      1024
51
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
52
using namespace std;
53
54
namespace drizzled
55
{
56
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
57
static void change_db_impl(Session *session);
2087.4.1 by Brian Aker
Merge in schema identifier.
58
static void change_db_impl(Session *session, identifier::Schema &schema_identifier);
820.1.11 by Stewart Smith
re-introduce db.opt, but with parsing it from disk instead of in process cache with mutex.
59
1 by brian
clean slate
60
/*
61
  Create a database
62
63
  SYNOPSIS
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
64
  create_db()
520.1.22 by Brian Aker
Second pass of thd cleanup
65
  session		Thread handler
1 by brian
clean slate
66
  db		Name of database to create
67
		Function assumes that this is already validated.
68
  create_info	Database create options (like character set)
69
70
  SIDE-EFFECTS
71
   1. Report back to client that command succeeded (my_ok)
72
   2. Report errors to client
73
   3. Log event to binary log
74
75
  RETURN VALUES
51.1.51 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
76
  false ok
77
  true  Error
1 by brian
clean slate
78
79
*/
80
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
81
bool create_db(Session *session, const message::Schema &schema_message, const bool is_if_not_exists)
1 by brian
clean slate
82
{
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
83
  TransactionServices &transaction_services= TransactionServices::singleton();
1039.1.3 by Brian Aker
Remove dead bits from db create/rm
84
  bool error= false;
1235.4.14 by Stewart Smith
use message::Schema in mysql_create_db instead of HA_CREATE_INFO
85
1 by brian
clean slate
86
  /*
87
    Do not create database if another thread is holding read lock.
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
88
    Wait for global read lock before acquiring session->catalog()->schemaLock().
1 by brian
clean slate
89
    After wait_if_global_read_lock() we have protection against another
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
90
    global read lock. If we would acquire session->catalog()->schemaLock() first,
1 by brian
clean slate
91
    another thread could step in and get the global read lock before we
92
    reach wait_if_global_read_lock(). If this thread tries the same as we
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
93
    (admin a db), it would then go and wait on session->catalog()->schemaLock()...
1 by brian
clean slate
94
    Furthermore wait_if_global_read_lock() checks if the current thread
95
    has the global read lock and refuses the operation with
96
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
97
  */
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
98
  if (session->wait_if_global_read_lock(false, true))
1 by brian
clean slate
99
  {
1273.19.25 by Brian Aker
createSchema() now works via SE interface.
100
    return false;
1 by brian
clean slate
101
  }
102
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
103
  assert(schema_message.has_name());
104
  assert(schema_message.has_collation());
105
1273.19.25 by Brian Aker
createSchema() now works via SE interface.
106
  // @todo push this lock down into the engine
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
107
  {
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
108
    boost::mutex::scoped_lock scopedLock(session->catalog().schemaLock());
1 by brian
clean slate
109
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
110
    // Check to see if it exists already.  
2087.4.1 by Brian Aker
Merge in schema identifier.
111
    identifier::Schema schema_identifier(schema_message.name());
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
112
    if (plugin::StorageEngine::doesSchemaExist(schema_identifier))
113
    {
114
      if (not is_if_not_exists)
115
      {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
116
        my_error(ER_DB_CREATE_EXISTS, schema_identifier);
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
117
        error= true;
118
      }
119
      else
120
      {
121
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
122
                            ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS),
123
                            schema_message.name().c_str());
124
        session->my_ok();
125
      }
126
    }
1856.2.8 by Joseph Daly
working alter, drop, create schema
127
    else if (not plugin::StorageEngine::createSchema(schema_message)) // Try to create it 
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
128
    {
129
      my_error(ER_CANT_CREATE_DB, MYF(0), schema_message.name().c_str(), errno);
1273.19.25 by Brian Aker
createSchema() now works via SE interface.
130
      error= true;
131
    }
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
132
    else // Created !
1273.19.25 by Brian Aker
createSchema() now works via SE interface.
133
    {
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
134
      transaction_services.createSchema(session, schema_message);
135
      session->my_ok(1);
1273.19.25 by Brian Aker
createSchema() now works via SE interface.
136
    }
137
  }
1910.2.2 by Brian Aker
First pass through the global lock refactor merge.
138
  session->startWaitingGlobalReadLock();
1273.19.25 by Brian Aker
createSchema() now works via SE interface.
139
1039.1.3 by Brian Aker
Remove dead bits from db create/rm
140
  return error;
1 by brian
clean slate
141
}
142
143
144
/* db-name is already validated when we come here */
145
2078.1.1 by David Shrewsbury
Push ALTER SCHEMA through replication stream as proper GPB message instead of RAW_SQL.
146
bool alter_db(Session *session,
147
              const message::Schema &schema_message,
148
              const message::schema::shared_ptr &original_schema)
1 by brian
clean slate
149
{
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
150
  TransactionServices &transaction_services= TransactionServices::singleton();
1 by brian
clean slate
151
152
  /*
153
    Do not alter database if another thread is holding read lock.
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
154
    Wait for global read lock before acquiring session->catalog()->schemaLock().
1 by brian
clean slate
155
    After wait_if_global_read_lock() we have protection against another
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
156
    global read lock. If we would acquire session->catalog()->schemaLock() first,
1 by brian
clean slate
157
    another thread could step in and get the global read lock before we
158
    reach wait_if_global_read_lock(). If this thread tries the same as we
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
159
    (admin a db), it would then go and wait on session->catalog()->schemaLock()...
1 by brian
clean slate
160
    Furthermore wait_if_global_read_lock() checks if the current thread
161
    has the global read lock and refuses the operation with
162
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
163
  */
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
164
  if ((session->wait_if_global_read_lock(false, true)))
1273.19.26 by Brian Aker
Move Alter schema to SE interface.
165
    return false;
1235.4.16 by Stewart Smith
use Schema proto for ALTER DATABASE/SCHEMA as well. Fix 'ALTER DATABASE COLLATE = foo'. Remove now obsolete fill_schema_message. HA_CREATE_INFO is no longer used in CREATE or ALTER SCHEMA.
166
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
167
  bool success;
168
  {
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
169
    boost::mutex::scoped_lock scopedLock(session->catalog().schemaLock());
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
170
2087.4.1 by Brian Aker
Merge in schema identifier.
171
    identifier::Schema schema_idenifier(schema_message.name());
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
172
    if (not plugin::StorageEngine::doesSchemaExist(schema_idenifier))
173
    {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
174
      my_error(ER_SCHEMA_DOES_NOT_EXIST, schema_idenifier);
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
175
      return false;
176
    }
177
178
    /* Change options if current database is being altered. */
179
    success= plugin::StorageEngine::alterSchema(schema_message);
180
181
    if (success)
182
    {
2078.1.1 by David Shrewsbury
Push ALTER SCHEMA through replication stream as proper GPB message instead of RAW_SQL.
183
      transaction_services.alterSchema(session, original_schema, schema_message);
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
184
      session->my_ok(1);
185
    }
186
    else
187
    {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
188
      my_error(ER_ALTER_SCHEMA, schema_idenifier);
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
189
    }
190
  }
1910.2.2 by Brian Aker
First pass through the global lock refactor merge.
191
  session->startWaitingGlobalReadLock();
1273.19.26 by Brian Aker
Move Alter schema to SE interface.
192
193
  return success;
1 by brian
clean slate
194
}
195
196
197
/*
198
  Drop all tables in a database and the database itself
199
200
  SYNOPSIS
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
201
    rm_db()
520.1.22 by Brian Aker
Second pass of thd cleanup
202
    session			Thread handle
1 by brian
clean slate
203
    db			Database name in the case given by user
204
		        It's already validated and set to lower case
205
                        (if needed) when we come here
206
    if_exists		Don't give error if database doesn't exists
207
    silent		Don't generate errors
208
209
  RETURN
51.1.51 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
210
    false ok (Database dropped)
1 by brian
clean slate
211
    ERROR Error
212
*/
213
2087.4.1 by Brian Aker
Merge in schema identifier.
214
bool rm_db(Session *session, identifier::Schema &schema_identifier, const bool if_exists)
1 by brian
clean slate
215
{
2041.3.6 by Brian Aker
Cleanup of drop table.
216
  bool error= false;
1 by brian
clean slate
217
218
  /*
219
    Do not drop database if another thread is holding read lock.
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
220
    Wait for global read lock before acquiring session->catalog()->schemaLock().
1 by brian
clean slate
221
    After wait_if_global_read_lock() we have protection against another
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
222
    global read lock. If we would acquire session->catalog()->schemaLock() first,
1 by brian
clean slate
223
    another thread could step in and get the global read lock before we
224
    reach wait_if_global_read_lock(). If this thread tries the same as we
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
225
    (admin a db), it would then go and wait on session->catalog()->schemaLock()...
1 by brian
clean slate
226
    Furthermore wait_if_global_read_lock() checks if the current thread
227
    has the global read lock and refuses the operation with
228
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
229
  */
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
230
  if (session->wait_if_global_read_lock(false, true))
1 by brian
clean slate
231
  {
2041.3.4 by Brian Aker
remove goto
232
    return true;
1 by brian
clean slate
233
  }
234
2041.3.4 by Brian Aker
remove goto
235
  do
1 by brian
clean slate
236
  {
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
237
    boost::mutex::scoped_lock scopedLock(session->catalog().schemaLock());
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
238
239
    /* See if the schema exists */
240
    if (not plugin::StorageEngine::doesSchemaExist(schema_identifier))
1309.1.8 by Brian Aker
Modest update to drop schema.
241
    {
1954.2.1 by Brian Aker
getSQLPath() modified to take a string so that we can const the table
242
      std::string path;
243
      schema_identifier.getSQLPath(path);
244
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
245
      if (if_exists)
246
      {
247
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
248
                            ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS),
1954.2.1 by Brian Aker
getSQLPath() modified to take a string so that we can const the table
249
                            path.c_str());
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
250
      }
251
      else
252
      {
2041.3.6 by Brian Aker
Cleanup of drop table.
253
        error= true;
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
254
        my_error(ER_DB_DROP_EXISTS, schema_identifier);
2041.3.4 by Brian Aker
remove goto
255
        break;
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
256
      }
1309.1.8 by Brian Aker
Modest update to drop schema.
257
    }
258
    else
1 by brian
clean slate
259
    {
2041.3.10 by Brian Aker
Put more of drop schema behind interface.
260
      error= plugin::StorageEngine::dropSchema(*session, schema_identifier);
1 by brian
clean slate
261
    }
262
2041.3.4 by Brian Aker
remove goto
263
  } while (0);
1685.2.14 by Brian Aker
Use boost for the main lock we use in schema creation/alteration.
264
2041.3.11 by Brian Aker
Only change schemas if we DROP the schema.
265
  /*
266
    If this database was the client's selected database, we silently
267
    change the client's selected database to nothing (to have an empty
268
    SELECT DATABASE() in the future). For this we free() session->db and set
269
    it to 0.
270
  */
271
  if (not error and schema_identifier.compare(*session->schema()))
272
    change_db_impl(session);
273
1910.2.2 by Brian Aker
First pass through the global lock refactor merge.
274
  session->startWaitingGlobalReadLock();
1309.1.8 by Brian Aker
Modest update to drop schema.
275
1259.3.3 by Monty Taylor
Removed last use of my_dir.
276
  return error;
1 by brian
clean slate
277
}
278
279
/**
280
  @brief Change the current database and its attributes unconditionally.
281
520.1.22 by Brian Aker
Second pass of thd cleanup
282
  @param session          thread handle
1 by brian
clean slate
283
  @param new_db_name  database name
51.1.51 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
284
  @param force_switch if force_switch is false, then the operation will fail if
1 by brian
clean slate
285
286
                        - new_db_name is NULL or empty;
287
288
                        - OR new database name is invalid
289
                          (check_db_name() failed);
290
291
                        - OR user has no privilege on the new database;
292
293
                        - OR new database does not exist;
294
51.1.51 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
295
                      if force_switch is true, then
1 by brian
clean slate
296
297
                        - if new_db_name is NULL or empty, the current
298
                          database will be NULL, @@collation_database will
299
                          be set to @@collation_server, the operation will
300
                          succeed.
301
302
                        - if new database name is invalid
303
                          (check_db_name() failed), the current database
304
                          will be NULL, @@collation_database will be set to
305
                          @@collation_server, but the operation will fail;
306
307
                        - user privileges will not be checked
520.1.21 by Brian Aker
THD -> Session rename
308
                          (Session::db_access however is updated);
1 by brian
clean slate
309
310
                          TODO: is this really the intention?
311
                                (see sp-security.test).
312
313
                        - if new database does not exist,the current database
314
                          will be NULL, @@collation_database will be set to
315
                          @@collation_server, a warning will be thrown, the
316
                          operation will succeed.
317
318
  @details The function checks that the database name corresponds to a
319
  valid and existent database, checks access rights and changes the current
320
  database with database attributes (@@collation_database session variable,
520.1.21 by Brian Aker
THD -> Session rename
321
  Session::db_access).
1 by brian
clean slate
322
323
  This function is not the only way to switch the database that is
324
  currently employed. When the replication slave thread switches the
520.1.22 by Brian Aker
Second pass of thd cleanup
325
  database before executing a query, it calls session->set_db directly.
1 by brian
clean slate
326
  However, if the query, in turn, uses a stored routine, the stored routine
327
  will use this function, even if it's run on the slave.
328
329
  This function allocates the name of the database on the system heap: this
330
  is necessary to be able to uniformly change the database from any module
331
  of the server. Up to 5.0 different modules were using different memory to
332
  store the name of the database, and this led to memory corruption:
333
  a stack pointer set by Stored Procedures was used by replication after
334
  the stack address was long gone.
335
336
  @return Operation status
51.1.51 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
337
    @retval false Success
338
    @retval true  Error
1 by brian
clean slate
339
*/
340
2087.4.1 by Brian Aker
Merge in schema identifier.
341
bool change_db(Session *session, identifier::Schema &schema_identifier)
1 by brian
clean slate
342
{
343
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
344
  if (not plugin::Authorization::isAuthorized(session->user(), schema_identifier))
1317.2.2 by Monty Taylor
Prevent unauthorized users from changing schema.
345
  {
346
    /* Error message is set in isAuthorized */
347
    return true;
348
  }
349
1578.4.11 by Brian Aker
PAss through the code removing current_session
350
  if (not check_db_name(session, schema_identifier))
1 by brian
clean slate
351
  {
1954.2.1 by Brian Aker
getSQLPath() modified to take a string so that we can const the table
352
    std::string path;
353
    schema_identifier.getSQLPath(path);
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
354
    my_error(ER_WRONG_DB_NAME, schema_identifier);
1 by brian
clean slate
355
1014.3.3 by Brian Aker
Formating fix.
356
    return true;
1 by brian
clean slate
357
  }
358
1415 by Brian Aker
Mass overhaul to use schema_identifier.
359
  if (not plugin::StorageEngine::doesSchemaExist(schema_identifier))
1 by brian
clean slate
360
  {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
361
    my_error(ER_BAD_DB_ERROR, schema_identifier);
1309.1.9 by Brian Aker
Baby steps.
362
363
    /* The operation failed. */
364
365
    return true;
1 by brian
clean slate
366
  }
367
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
368
  change_db_impl(session, schema_identifier);
1 by brian
clean slate
369
1014.3.3 by Brian Aker
Formating fix.
370
  return false;
1 by brian
clean slate
371
}
372
1273 by Brian Aker
Revert db patch.
373
/**
374
  @brief Internal implementation: switch current database to a valid one.
375
376
  @param session            Thread context.
377
  @param new_db_name    Name of the database to switch to. The function will
378
                        take ownership of the name (the caller must not free
379
                        the allocated memory). If the name is NULL, we're
380
                        going to switch to NULL db.
381
  @param new_db_charset Character set of the new database.
382
*/
383
2087.4.1 by Brian Aker
Merge in schema identifier.
384
static void change_db_impl(Session *session, identifier::Schema &schema_identifier)
1235.4.18 by Stewart Smith
replace check_db_dir_existence() with class DatabasePathName and a ::exists() method.
385
{
1273 by Brian Aker
Revert db patch.
386
  /* 1. Change current database in Session. */
387
1415 by Brian Aker
Mass overhaul to use schema_identifier.
388
#if 0
1273 by Brian Aker
Revert db patch.
389
  if (new_db_name == NULL)
390
  {
391
    /*
392
      Session::set_db() does all the job -- it frees previous database name and
393
      sets the new one.
394
    */
395
396
    session->set_db(NULL, 0);
397
  }
398
  else
1415 by Brian Aker
Mass overhaul to use schema_identifier.
399
#endif
1273 by Brian Aker
Revert db patch.
400
  {
401
    /*
402
      Here we already have a copy of database name to be used in Session. So,
403
      we just call Session::reset_db(). Since Session::reset_db() does not releases
404
      the previous database name, we should do it explicitly.
405
    */
406
1685.2.12 by Brian Aker
This fixes the lower casing of names from Schema even when we should not.
407
    session->set_db(schema_identifier.getSchemaName());
1273 by Brian Aker
Revert db patch.
408
  }
1235.4.18 by Stewart Smith
replace check_db_dir_existence() with class DatabasePathName and a ::exists() method.
409
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
410
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
411
static void change_db_impl(Session *session)
1415 by Brian Aker
Mass overhaul to use schema_identifier.
412
{
413
  session->set_db(string());
414
}
415
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
416
} /* namespace drizzled */