Esempio n. 1
0
        public bool ExistsDatabase(IAnyDbSetting setting)
        {
            if (setting == null)
            {
                throw new ArgumentNullException(nameof(setting));
            }
            CheckDatabseProvider(setting);
            string original = setting.ConnectionString;

            try
            {
                AnyDbConnectionStringBuilder sb = new AnyDbConnectionStringBuilder(setting.ConnectionString);
                string dbName = (string)sb["Database"];
                sb["Database"]           = "mysql";
                setting.ConnectionString = sb.ToString();
                AnyDbFactory factory = new AnyDbFactory(setting);
                using (AnyDbConnection con = factory.OpenConnection())
                    using (AnyDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = $"SHOW DATABASES LIKE '{dbName}';";
                        using (IDataReader reader = cmd.ExecuteReader())
                        {
                            return(reader.Read());
                        }
                    }
            }
            finally
            {
                setting.ConnectionString = original;
            }
        }