mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update CreateDatabase
This commit is contained in:
parent
ce1a038e60
commit
8f09003d78
@ -12,7 +12,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT NAME FROM MASTER.DBO.SYSDATABASES ORDER BY NAME";
|
||||
return "SHOW DATABASES";
|
||||
}
|
||||
}
|
||||
protected override string GetColumnInfosByTableNameSql
|
||||
@ -248,6 +248,35 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
///by current connection string
|
||||
/// </summary>
|
||||
/// <param name="databaseDirectory"></param>
|
||||
/// <returns></returns>
|
||||
public override bool CreateDatabase(string databaseName, string databaseDirectory = null)
|
||||
{
|
||||
if (databaseDirectory != null)
|
||||
{
|
||||
if (!FileHelper.IsExistDirectory(databaseDirectory))
|
||||
{
|
||||
FileHelper.CreateDirectory(databaseDirectory);
|
||||
}
|
||||
}
|
||||
var oldDatabaseName = this.Context.Ado.Connection.Database;
|
||||
var connection = this.Context.CurrentConnectionConfig.ConnectionString;
|
||||
connection = connection.Replace(oldDatabaseName, "sys");
|
||||
var newDb = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = this.Context.CurrentConnectionConfig.DbType,
|
||||
IsAutoCloseConnection = true,
|
||||
ConnectionString = connection
|
||||
});
|
||||
if (!GetDataBaseList(newDb).Any(it => it.Equals(databaseName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
newDb.Ado.ExecuteCommand(string.Format(CreateDataBaseSql, databaseName, databaseDirectory));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override bool AddTableRemark(string tableName, string description)
|
||||
{
|
||||
string sql = string.Format(this.AddTableRemarkSql, this.SqlBuilder.GetTranslationTableName(tableName), description);
|
||||
|
Loading…
Reference in New Issue
Block a user