Example #1
0
        ///<inheritdoc/>
        public IDbConnection CreateMasterConnection()
        {
            var connectionStringBuilder = new SnowflakeDbConnectionStringBuilder();

            connectionStringBuilder.ConnectionString = _connectionString;

            //NOTE: remove existing db & schema from connection string parameters
            //this is necessary to avoid connection errors as it will attempt to connect to non-existing database
            connectionStringBuilder.Remove("db");
            connectionStringBuilder.Remove("schema");

            var connection = new SnowflakeDbConnection();

            connection.ConnectionString = connectionStringBuilder.ConnectionString;
            return(connection);
        }
Example #2
0
        public override void DropDatabase(string connectionString)
        {
            //extract the test database name from connection string
            var connectionStringBuilder = new SnowflakeDbConnectionStringBuilder();

            connectionStringBuilder.ConnectionString = connectionString;
            connectionStringBuilder.TryGetValue("db", out object databaseName);

            var sqlStatement = $"DROP DATABASE {databaseName.ToString().DoubleQuote()};";

            //prepare a connection to snowflake without any targetdb or schema, we need to remove these keys else it throws an error that db doesn't exists
            var masterConnectionStringBuilder = new SnowflakeDbConnectionStringBuilder();

            masterConnectionStringBuilder.ConnectionString = connectionString;
            masterConnectionStringBuilder.Remove("db");
            masterConnectionStringBuilder.Remove("schema");

            base.ExecuteNonQuery(masterConnectionStringBuilder.ConnectionString, sqlStatement);
        }
Example #3
0
        public override bool CheckIfDbExist(string connectionString)
        {
            //extract the test database name from connection string
            var connectionStringBuilder = new SnowflakeDbConnectionStringBuilder();

            connectionStringBuilder.ConnectionString = connectionString;
            connectionStringBuilder.TryGetValue("db", out object databaseName);

            //prepare the sql statement
            var tokens = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>(RESERVED_TOKENS.YUNIQL_DB_NAME, databaseName.ToString()),
                new KeyValuePair <string, string>(RESERVED_TOKENS.YUNIQL_SCHEMA_NAME, base.SchemaName),
            };
            var sqlStatement = _tokenReplacementService.Replace(tokens, _dataService.GetSqlForCheckIfDatabaseExists());

            //prepare a connection to snowflake without any targetdb or schema, we need to remove these keys else it throws an error that db doesn't exists
            var masterConnectionStringBuilder = new SnowflakeDbConnectionStringBuilder();

            masterConnectionStringBuilder.ConnectionString = connectionString;
            masterConnectionStringBuilder.Remove("db");
            masterConnectionStringBuilder.Remove("schema");

            return(QuerySingleRow(masterConnectionStringBuilder.ConnectionString, sqlStatement));
        }
Example #4
0
        public override string GetConnectionString(string databaseName)
        {
            var connectionString = EnvironmentHelper.GetEnvironmentVariable("YUNIQL_TEST_CONNECTION_STRING");

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ApplicationException("Missing environment variable YUNIQL_TEST_CONNECTION_STRING. See WIKI for developer guides.");
            }

            //extract the default database name from connection string and replaced with test database name
            var connectionStringBuilder = new SnowflakeDbConnectionStringBuilder();

            connectionStringBuilder.ConnectionString = connectionString;
            connectionStringBuilder.Remove("db");
            connectionStringBuilder.Add("db", databaseName.DoubleQuote());
            return(connectionStringBuilder.ConnectionString);
        }