Stop pretending that we'll ever work with another DBMS.
[mailshears.git] / lib / common / roundcube_plugin.rb
index eb450f00059d038776046dc7604417e1de3c367e..948a5b91b5577dc5ebd3c45e24ad150b99556c97 100644 (file)
@@ -28,27 +28,16 @@ module RoundcubePlugin
     # is public because it is useful in testing.
     usernames = []
 
-    # Just assume PostgreSQL for now.
-    begin
-      connection = PGconn.connect(@db_host,
-                                  @db_port,
-                                  @db_opts,
-                                  @db_tty,
-                                  @db_name,
-                                  @db_user,
-                                  @db_pass)
-
-      sql_query = "SELECT username FROM users;"
-      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)
 
-      connection.close()
-    rescue PGError => e
-      # Pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
+    sql_query = 'SELECT username FROM users;'
+    connection.query(sql_query) do |result|
+      usernames = result.field_values('username')
     end
 
+    connection.close()
+
     return usernames.map{ |u| User.new(u) }
   end
 
@@ -57,30 +46,19 @@ module RoundcubePlugin
   def get_user_id(user)
     user_id = nil
 
-    begin
-      connection = PGconn.connect(@db_host,
-                                  @db_port,
-                                  @db_opts,
-                                  @db_tty,
-                                  @db_name,
-                                  @db_user,
-                                  @db_pass)
-
-      sql_query = "SELECT user_id FROM users WHERE username = $1;"
-
-      connection.query(sql_query, [user.to_s()]) do |result|
-        if result.num_tuples > 0
-          user_id = result[0]['user_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 user_id FROM users WHERE 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
+        user_id = result[0]['user_id']
+      end
     end
 
+    connection.close()
+
     return user_id
   end