Permalink
Browse files

add connection error handling .

  • Loading branch information...
shirou committed Apr 20, 2012
1 parent ff11c63 commit 087ba72d579acfef8c85f13bf4b40ac6b844d23c
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/fluent/plugin/out_pghstore.rb
@@ -93,8 +93,9 @@ def table_exists?(table)
SELECT COUNT(*) FROM pg_tables WHERE tablename = '#{table}';
SQL
conn = get_connection()
+ raise "Could not connect the database at startup. abort." if conn == nil
res = conn.exec(sql)
- conn.close
+ conn.close
if res[0]["count"] == "1"
return true
else
@@ -114,10 +115,17 @@ def create_table(tablename)
sql += @table_option if @table_option
conn = get_connection()
- conn.exec(sql)
+ raise "Could not connect the database at create_table. abort." if conn == nil
+
+ begin
+ conn.exec(sql)
+ rescue PGError => e
+ $log.error "Error at create_table:" + e.message
+ $log.error "SQL:" + sql
+ end
conn.close
- $log.warn "#{tablename} table is not exists. created."
+ $log.warn "table #{tablename} was not exist. created it."
end
end

0 comments on commit 087ba72

Please sign in to comment.