~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Brian Aker
  • Date: 2009-07-16 06:32:37 UTC
  • mfrom: (1095.1.3 merge)
  • Revision ID: brian@gaz-20090716063237-0iyo47mgo46uqaiy
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include <drizzled/item/empty_string.h>
43
43
#include "drizzled/plugin_registry.h"
44
44
#include <drizzled/info_schema.h>
 
45
#include <drizzled/message/schema.pb.h>
45
46
 
46
47
#include <string>
47
48
#include <iostream>
282
283
  return false;
283
284
}
284
285
 
285
 
bool mysqld_show_create_db(Session *session, char *dbname,
286
 
                           HA_CREATE_INFO *create_info)
 
286
/**
 
287
  Get a CREATE statement for a given database.
 
288
 
 
289
  The database is identified by its name, passed as @c dbname parameter.
 
290
  The name should be encoded using the system character set (UTF8 currently).
 
291
 
 
292
  Resulting statement is stored in the string pointed by @c buffer. The string
 
293
  is emptied first and its character set is set to the system character set.
 
294
 
 
295
  If HA_LEX_CREATE_IF_NOT_EXISTS flag is set in @c create_info->options, then
 
296
  the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
 
297
  in @c create_options are ignored.
 
298
 
 
299
  @param  session           The current thread instance.
 
300
  @param  dbname        The name of the database.
 
301
  @param  buffer        A String instance where the statement is stored.
 
302
  @param  create_info   If not NULL, the options member influences the resulting
 
303
                        CRATE statement.
 
304
 
 
305
  @returns true if errors are detected, false otherwise.
 
306
*/
 
307
 
 
308
static bool store_db_create_info(const char *dbname, String *buffer, bool if_not_exists)
 
309
{
 
310
  drizzled::message::Schema schema;
 
311
 
 
312
  if (!my_strcasecmp(system_charset_info, dbname,
 
313
                     INFORMATION_SCHEMA_NAME.c_str()))
 
314
  {
 
315
    dbname= INFORMATION_SCHEMA_NAME.c_str();
 
316
  }
 
317
  else
 
318
  {
 
319
    int r= get_database_metadata(dbname, &schema);
 
320
    if(r < 0)
 
321
      return true;
 
322
  }
 
323
 
 
324
  buffer->length(0);
 
325
  buffer->free();
 
326
  buffer->set_charset(system_charset_info);
 
327
  buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
 
328
 
 
329
  if (if_not_exists)
 
330
    buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
 
331
 
 
332
  buffer->append_identifier(dbname, strlen(dbname));
 
333
 
 
334
  if (schema.has_collation() && strcmp(schema.collation().c_str(),
 
335
                                       default_charset_info->name))
 
336
  {
 
337
    buffer->append(" COLLATE = ");
 
338
    buffer->append(schema.collation().c_str());
 
339
  }
 
340
 
 
341
  return false;
 
342
}
 
343
 
 
344
bool mysqld_show_create_db(Session *session, char *dbname, bool if_not_exists)
287
345
{
288
346
  char buff[2048];
289
347
  String buffer(buff, sizeof(buff), system_charset_info);
290
348
  Protocol *protocol=session->protocol;
291
349
 
292
 
  if (store_db_create_info(dbname, &buffer, create_info))
 
350
  if (store_db_create_info(dbname, &buffer, if_not_exists))
293
351
  {
294
352
    /*
295
353
      This assumes that the only reason for which store_db_create_info()
768
826
  return(0);
769
827
}
770
828
 
771
 
/**
772
 
  Get a CREATE statement for a given database.
773
 
 
774
 
  The database is identified by its name, passed as @c dbname parameter.
775
 
  The name should be encoded using the system character set (UTF8 currently).
776
 
 
777
 
  Resulting statement is stored in the string pointed by @c buffer. The string
778
 
  is emptied first and its character set is set to the system character set.
779
 
 
780
 
  If HA_LEX_CREATE_IF_NOT_EXISTS flag is set in @c create_info->options, then
781
 
  the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
782
 
  in @c create_options are ignored.
783
 
 
784
 
  @param  session           The current thread instance.
785
 
  @param  dbname        The name of the database.
786
 
  @param  buffer        A String instance where the statement is stored.
787
 
  @param  create_info   If not NULL, the options member influences the resulting
788
 
                        CRATE statement.
789
 
 
790
 
  @returns true if errors are detected, false otherwise.
791
 
*/
792
 
 
793
 
bool store_db_create_info(const char *dbname, String *buffer, HA_CREATE_INFO *create_info)
794
 
{
795
 
  HA_CREATE_INFO create;
796
 
  uint32_t create_options = create_info ? create_info->options : 0;
797
 
 
798
 
  if (!my_strcasecmp(system_charset_info, dbname,
799
 
                     INFORMATION_SCHEMA_NAME.c_str()))
800
 
  {
801
 
    dbname= INFORMATION_SCHEMA_NAME.c_str();
802
 
    create.default_table_charset= system_charset_info;
803
 
  }
804
 
  else
805
 
  {
806
 
    if (check_db_dir_existence(dbname))
807
 
      return true;
808
 
 
809
 
    load_db_opt_by_name(dbname, &create);
810
 
  }
811
 
 
812
 
  buffer->length(0);
813
 
  buffer->free();
814
 
  buffer->set_charset(system_charset_info);
815
 
  buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
816
 
 
817
 
  if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
818
 
    buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
819
 
 
820
 
  buffer->append_identifier(dbname, strlen(dbname));
821
 
 
822
 
  return false;
823
 
}
824
 
 
825
829
static void store_key_options(String *packet, Table *table, KEY *key_info)
826
830
{
827
831
  char *end, buff[32];