Ejemplo n.º 1
0
        public bool ExistsDatabase()
        {
            var newServerInfoWithMasterDatabase = new ServerInformation(DbType.Postgress, _serverInf.Server, "postgres", _serverInf.UserId, _serverInf.Password);

            using (var conn = GetConnection(newServerInfoWithMasterDatabase))
            {
                conn.Open();

                var command = conn.CreateCommand();
                command.CommandText = $"select * from pg_database where datname = '{_serverInf.Database}'";

                var reader = command.ExecuteReader();
                var data   = new DataTable();
                data.Load(reader);
                return(data.Rows.Count > 0);
            }
        }
Ejemplo n.º 2
0
        public void Createdatabase()
        {
            if (ExistsDatabase())
            {
                return;
            }
            var newServerInfoWithMasterDatabase = new ServerInformation(DbType.Postgress, _serverInf.Server, "postgres", _serverInf.UserId, _serverInf.Password);

            using (var conn = new Npgsql.NpgsqlConnection(newServerInfoWithMasterDatabase.ToString()))
            {
                conn.Open();

                var command = conn.CreateCommand();
                command.CommandText = $"CREATE DATABASE \"{_serverInf.Database}\" ";

                command.ExecuteNonQuery();

                conn.Close();
            }
        }
Ejemplo n.º 3
0
 public DatabaseFactory(ServerInformation serverinfo)
 {
     ServerInformation = serverinfo;
 }
Ejemplo n.º 4
0
 public IDbConnection GetConnection(ServerInformation serverInf)
 {
     return(new Npgsql.NpgsqlConnection(serverInf.ToString()));
 }
Ejemplo n.º 5
0
 public PostgreSQLCreator(ServerInformation serverInf)
 {
     _serverInf = serverInf;
 }