X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=src%2Fpostfixadmin_db.rb;h=d9112afa177be2ec1c842f2f79205882742486e0;hp=5291a53987587b0ee1da11ccee4e33c835191885;hb=0a35436490fe90a205000f4413523284724f5832;hpb=1e4cad3a4f6938ca07bc99078108d466bf146b24 diff --git a/src/postfixadmin_db.rb b/src/postfixadmin_db.rb index 5291a53..d9112af 100644 --- a/src/postfixadmin_db.rb +++ b/src/postfixadmin_db.rb @@ -20,6 +20,33 @@ class PostfixadminDb end + def get_domains_from_db() + # Just assume PostgreSQL for now. + begin + connection = PGconn.connect(@db_host, + @db_port, + @db_opts, + @db_tty, + @db_name, + @db_user, + @db_pass) + + # 'ALL' is a magic domain, and we don't want it. + sql_query = "SELECT domain FROM domain WHERE domain <> 'ALL';" + result = connection.query(sql_query) + connection.close() + rescue PGError => e + # But pretend like we're database-agnostic in case we ever are. + raise DatabaseError.new(e) + end + + # The database query returns an array of rows. Since we only asked + # for one column (domain), we can flatten the result into an + # array of domains. + return result.flatten + end + + def get_accounts_from_db() # Just assume PostgreSQL for now. begin @@ -46,5 +73,5 @@ class PostfixadminDb # array of addresses. return result.flatten end - + end