源码mysql关闭服务器,mysql 服务器端命令源码(五)--show create database

bool mysqld_show_create_db(THD *thd, char *dbname,

HA_CREATE_INFO *create_info)

{

char buff[2048];

String buffer(buff, sizeof(buff), system_charset_info);

#ifndef NO_EMBEDDED_ACCESS_CHECKS

Security_context *sctx= thd->security_ctx;

uint db_access;

#endif

HA_CREATE_INFO create;

uint create_options = create_info ? create_info->options : 0;

Protocol *protocol=thd->protocol;

DBUG_ENTER("mysql_show_create_db");

#ifndef NO_EMBEDDED_ACCESS_CHECKS

if (test_all_bits(sctx->master_access, DB_ACLS))

db_access=DB_ACLS;

else

db_access= (acl_get(sctx->host, sctx->ip, sctx->priv_user, dbname, 0) |

sctx->master_access);

if (!(db_access & DB_ACLS) && check_grant_db(thd,dbname))

{

my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),

sctx->priv_user, sctx->host_or_ip, dbname);

general_log_print(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),

sctx->priv_user, sctx->host_or_ip, dbname);

DBUG_RETURN(TRUE);

}

#endif

if (is_schema_db(dbname))

{

dbname= INFORMATION_SCHEMA_NAME.str;

create.default_table_charset= system_charset_info;

}

else

{

if (check_db_dir_existence(dbname))

{

my_error(ER_BAD_DB_ERROR, MYF(0), dbname);

DBUG_RETURN(TRUE);

}

load_db_opt_by_name(thd, dbname, &create);

}

List field_list;

field_list.push_back(new Item_empty_string("Database",NAME_CHAR_LEN));

field_list.push_back(new Item_empty_string("Create Database",1024));

if (protocol->send_result_set_metadata(&field_list,

Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))

DBUG_RETURN(TRUE);

protocol->prepare_for_resend();

protocol->store(dbname, strlen(dbname), system_charset_info);

buffer.length(0);

buffer.append(STRING_WITH_LEN("CREATE DATABASE "));

if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)

buffer.append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));

append_identifier(thd, &buffer, dbname, strlen(dbname));

if (create.default_table_charset)

{

buffer.append(STRING_WITH_LEN(" /*!40100"));

buffer.append(STRING_WITH_LEN(" DEFAULT CHARACTER SET "));

buffer.append(create.default_table_charset->csname);

if (!(create.default_table_charset->state & MY_CS_PRIMARY))

{

buffer.append(STRING_WITH_LEN(" COLLATE "));

buffer.append(create.default_table_charset->name);

}

buffer.append(STRING_WITH_LEN(" */"));

}

protocol->store(buffer.ptr(), buffer.length(), buffer.charset());

if (protocol->write())

DBUG_RETURN(TRUE);

my_eof(thd);

DBUG_RETURN(FALSE);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值