Example #1
0
 public T[] ExecuteReader <T>(string connectionString, NpgQuery query, Func <NpgsqlDataReader, T> convertFunc)
 {
     using (var connection = new NpgsqlConnection(connectionString))
     {
         return(ExecuteReader(connection, query, convertFunc));
     }
 }
Example #2
0
 public bool IsPHmiDatabase(string connectionString, string database)
 {
     var connectionParameters = new NpgConnectionParameters();
     connectionParameters.Update(connectionString);
     connectionParameters.Database = database;
     var query = new NpgQuery(string.Format("SELECT 1 FROM settings WHERE phmi_guid = '{0}'", PHmiConstants.PHmiGuid));
     var result = _npgHelper.ExecuteScalar(connectionParameters.ConnectionString, query);
     return result != null;
 }
Example #3
0
        private string[] GetDatabasesFromConnectionStringWithoutDatabase(string cs)
        {
            var query = new NpgQuery(
                "SELECT datname FROM pg_database WHERE datallowconn = TRUE AND datname != 'template1' ORDER BY datname");

            return(ExecuteReader(
                       cs,
                       query,
                       reader => reader.GetString(0)));
        }
Example #4
0
 public object ExecuteScalar(string connectionString, NpgQuery query)
 {
     using (var connection = new NpgsqlConnection(connectionString)) {
         connection.Open();
         using (var command = new NpgsqlCommand(query.Text, connection)) {
             command.Parameters.AddRange(query.Parameters);
             return(command.ExecuteScalar());
         }
     }
 }
Example #5
0
 public int ExecuteNonQuery(NpgsqlConnection connection, NpgQuery query)
 {
     if (connection.State == ConnectionState.Closed)
     {
         connection.Open();
     }
     using (var command = new NpgsqlCommand(query.Text, connection)) {
         command.Parameters.AddRange(query.Parameters);
         int count = command.ExecuteNonQuery();
         return(count);
     }
 }
Example #6
0
 public T[] ExecuteReader <T>(NpgsqlConnection connection, NpgQuery query, Func <NpgsqlDataReader, T> convertFunc)
 {
     if (connection.State == ConnectionState.Closed)
     {
         connection.Open();
     }
     using (var command = new NpgsqlCommand(query.Text, connection))
     {
         command.Parameters.AddRange(query.Parameters);
         var reader = command.ExecuteReader();
         var result = new List <T>();
         while (reader.Read())
         {
             result.Add(convertFunc.Invoke(reader));
         }
         return(result.ToArray());
     }
 }
Example #7
0
        public string[] GetTables(NpgsqlConnection connection)
        {
            var query = new NpgQuery("SELECT tablename FROM pg_tables");

            return(ExecuteReader(connection, query, reader => reader.GetString(0)));
        }