Stop pretending that we'll ever work with another DBMS.
[mailshears.git] / lib / common / davical_plugin.rb
index cd34a982529f70c09e156567e34cbcab97b7fc8e..363e08ef298cfc402aaf051ad486fedd3f553323 100644 (file)
@@ -30,28 +30,18 @@ module DavicalPlugin
     #
     usernames = []
 
-    begin
-      connection = PGconn.connect(@db_host,
-                                  @db_port,
-                                  @db_opts,
-                                  @db_tty,
-                                  @db_name,
-                                  @db_user,
-                                  @db_pass)
-
-      # User #1 is the super-user, and not tied to an email address.
-      sql_query =  "SELECT username FROM usr WHERE user_no > 1"
-
-      connection.query(sql_query) do |result|
-        usernames = result.field_values('username')
-      end
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
+
+    # User #1 is the super-user, and not tied to an email address.
+    sql_query = 'SELECT username FROM usr WHERE user_no > 1'
 
-      connection.close()
-    rescue PGError => e
-      # Pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
+    connection.query(sql_query) do |result|
+      usernames = result.field_values('username')
     end
 
+    connection.close()
+
     return usernames.map{ |u| User.new(u) }
   end
 
@@ -61,33 +51,22 @@ module DavicalPlugin
   def get_principal_id(user)
     principal_id = nil
 
-    begin
-      connection = PGconn.connect(@db_host,
-                                  @db_port,
-                                  @db_opts,
-                                  @db_tty,
-                                  @db_name,
-                                  @db_user,
-                                  @db_pass)
-
-      sql_query =  "SELECT principal.principal_id "
-      sql_query += "FROM (principal INNER JOIN usr "
-      sql_query += "      ON principal.user_no = usr.user_no) "
-      sql_query += "WHERE usr.username = $1;"
-
-      connection.query(sql_query, [user.to_s()]) do |result|
-        if result.num_tuples > 0
-          principal_id = result[0]['principal_id']
-        end
-      end
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
 
-      connection.close()
+    sql_query =  'SELECT principal.principal_id '
+    sql_query += 'FROM (principal INNER JOIN usr '
+    sql_query += '      ON principal.user_no = usr.user_no) '
+    sql_query += 'WHERE usr.username = $1;'
 
-    rescue PGError => e
-      # Pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
+    connection.query(sql_query, [user.to_s()]) do |result|
+      if result.num_tuples > 0
+        principal_id = result[0]['principal_id']
+      end
     end
 
+    connection.close()
+
     return principal_id
   end