Exemplo n.º 1
0
        public void SchemaDrop(string schemaName, bool force, bool throwIfNotExists)
        {
            if (String.IsNullOrWhiteSpace(schemaName))
            {
                throw new ArgumentNullException(nameof(schemaName));
            }

            try
            {
                var sqlCommand = new PgSqlCommand();
                sqlCommand.AppendCommand(SQLStatements.SchemaDrop(schemaName, force, throwIfNotExists));
                var resp = new DbExecuter(ConnectionString).ExecuteNonQuery(sqlCommand);
            }
            catch (PostgresException pex)
            {
                if (pex.SqlState == "2BP01")
                {
                    throw new DependentObjectsException(pex.Detail);
                }

                if (pex.SqlState == "3F000")
                {
                    throw new SchemaDoesntExistsException(schemaName);
                }

                throw;
            }
        }
Exemplo n.º 2
0
        public Schema SchemaRename(string schemaName, string newSchemaName)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(schemaName))
                {
                    throw new ArgumentNullException(nameof(schemaName));
                }

                if (String.IsNullOrWhiteSpace(newSchemaName))
                {
                    throw new ArgumentNullException(nameof(newSchemaName));
                }

                var sqlCommand = new PgSqlCommand();
                sqlCommand.AppendCommand(SQLStatements.SchemaRename(schemaName, newSchemaName));
                var resp = new DbExecuter(ConnectionString).ExecuteNonQuery(sqlCommand);

                return(GetSchema(newSchemaName));
            }
            catch (PostgresException pex)
            {
                if (pex.SqlState == "3F000")
                {
                    throw new SchemaDoesntExistsException(schemaName);
                }

                if (pex.SqlState == "42P06")
                {
                    throw new SchemaAlreadyExistsException(newSchemaName);
                }

                throw;
            }
        }
Exemplo n.º 3
0
        public Schema CreateSchema(string schemaName, bool throwIfAlreadyExists)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(schemaName))
                {
                    throw new ArgumentNullException(nameof(schemaName));
                }

                //schemaName = schemaName.ToLower();

                var sqlCommand = new PgSqlCommand();
                sqlCommand.AppendCommand(SQLStatements.SchemaCreate(schemaName, throwIfAlreadyExists));
                var resp = new DbExecuter(ConnectionString).ExecuteNonQuery(sqlCommand);

                return(GetSchema(schemaName));
            }
            catch (PostgresException pex)
            {
                if (pex.SqlState == "42P06")
                {
                    throw new SchemaAlreadyExistsException(schemaName);
                }

                throw;
            }
        }
Exemplo n.º 4
0
        public int ExecuteNonQuery(string sqlStatement)
        {
            var sqlCommand = new PgSqlCommand();

            sqlCommand.AppendCommand(sqlStatement);
            return(ExecuteNonQuery(sqlCommand));
        }
Exemplo n.º 5
0
        public TOut ExecuteScalar <TOut>(string sqlStatement)
        {
            var sqlCommand = new PgSqlCommand();

            sqlCommand.AppendCommand(sqlStatement);
            return(ExecuteScalar <TOut>(sqlCommand));
        }
Exemplo n.º 6
0
        public IEnumerable <JObject> ExecuteReader(string sqlStatement)
        {
            var sqlCommand = new PgSqlCommand();

            sqlCommand.AppendCommand(sqlStatement);
            return(ExecuteReader(sqlCommand));
        }
Exemplo n.º 7
0
        public void DomainDrop(string domainName, bool throwIfNotExists)
        {
            if (String.IsNullOrWhiteSpace(domainName))
            {
                throw new ArgumentNullException(nameof(domainName));
            }

            var sqlCommand = new PgSqlCommand();

            sqlCommand.AppendCommand(SQLStatements.DomainDrop(domainName, throwIfNotExists));
            new DbExecuter(ConnectionString).ExecuteNonQuery(sqlCommand);
        }
Exemplo n.º 8
0
        public void ExtensionCreate(string extensionName, bool throwIfAlreadyExists)
        {
            if (String.IsNullOrWhiteSpace(extensionName))
            {
                throw new ArgumentNullException(nameof(extensionName));
            }

            var sqlCommand = new PgSqlCommand();

            sqlCommand.AppendCommand(SQLStatements.ExtensionCreate(extensionName, throwIfAlreadyExists));
            new DbExecuter(ConnectionString).ExecuteNonQuery(sqlCommand);
        }
Exemplo n.º 9
0
        public void DomainCreate(string domainName, string postgresTypeName, bool throwIfExists)
        {
            if (String.IsNullOrWhiteSpace(domainName))
            {
                throw new ArgumentNullException(nameof(domainName));
            }

            var sqlCommand = new PgSqlCommand();

            sqlCommand.AppendCommand(SQLStatements.DomainCreate(domainName, postgresTypeName));
            if (!throwIfExists)
            {
                if (!DomainExists(domainName))
                {
                    new DbExecuter(ConnectionString).ExecuteNonQuery(sqlCommand);
                }
            }
            else
            {
                new DbExecuter(ConnectionString).ExecuteNonQuery(sqlCommand);
            }
        }