[ap4r-devel] [249] trunk/ap4r/lib/ap4r/message_store_ext.rb: Added: support two postgres module for Ruby, Ruby extention library and pure Ruby PostgreSQL interface.
kato-k at rubyforge.org
kato-k at rubyforge.org
Tue Aug 7 08:14:54 EDT 2007
Revision: 249
Author: kato-k
Date: 2007-08-07 08:14:53 -0400 (Tue, 07 Aug 2007)
Log Message:
-----------
Added: support two postgres module for Ruby, Ruby extention library and pure Ruby PostgreSQL interface.
Modified Paths:
--------------
trunk/ap4r/lib/ap4r/message_store_ext.rb
Modified: trunk/ap4r/lib/ap4r/message_store_ext.rb
===================================================================
--- trunk/ap4r/lib/ap4r/message_store_ext.rb 2007-08-06 09:33:28 UTC (rev 248)
+++ trunk/ap4r/lib/ap4r/message_store_ext.rb 2007-08-07 12:14:53 UTC (rev 249)
@@ -35,13 +35,13 @@
begin
- # Make sure we have a MySQL library before creating this class,
+ # Make sure we have a PostgreSQL library before creating this class,
# worst case we end up with a disk-based message store. Try the
- # native MySQL library, followed by the Rails MySQL library.
- begin
+ # native PostgreSQL library, followed by the pure Ruby PostgreSQL library.
+ begin
+ require 'postgres'
+ rescue LoadError
require 'postgres-pr/connection'
- rescue LoadError
- puts 'hoge'
end
class PostgreSQL < Base #:nodoc:
@@ -193,7 +193,14 @@
def connection
# Thread.current[THREAD_CURRENT_PGSQL] ||= ::PostgresPR::Connection.new @config[:host], @config[:username], @config[:password], at config[:database], @config[:port], @config[:socket]
- Thread.current[THREAD_CURRENT_PGSQL] ||= ::PostgresPR::Connection.new @config[:database], @config[:username], @config[:password], @config[:uri]
+
+ Thread.current[THREAD_CURRENT_PGSQL] ||=
+ if $:.any?{ |e| e.include?('postgres-pr') }
+ ::PostgresPR::Connection.new @config[:database], @config[:username], @config[:password], @config[:uri]
+ elsif $:.any?{ |e| e.include?('postgres')}
+ ::PGconn.connect @config[:host], @config[:port], @config[:options], @config[:tty], @config[:database], @config[:username], @config[:password]
+ end
+
end
end
@@ -205,6 +212,29 @@
end
end
+class PGconn
+ def quote str
+ PGconn.escape str
+ end
+end
+
+module PostgresPR
+ class Connection
+ def escape_string(str)
+ str.gsub(/([\0\n\r\032\'\"\\])/) do
+ case $1
+ when "\0" then "\\0"
+ when "\n" then "\\n"
+ when "\r" then "\\r"
+ when "\032" then "\\Z"
+ else "\\"+$1
+ end
+ end
+ end
+ alias :quote :escape_string
+ end
+end
+
if ReliableMsg::MessageStore::Base.use_mysql_extention
class Mysql #:nodoc:
alias original_query query
@@ -226,21 +256,3 @@
end
end
end
-
-
-module PostgresPR
- class Connection
- def escape_string(str)
- str.gsub(/([\0\n\r\032\'\"\\])/) do
- case $1
- when "\0" then "\\0"
- when "\n" then "\\n"
- when "\r" then "\\r"
- when "\032" then "\\Z"
- else "\\"+$1
- end
- end
- end
- alias :quote :escape_string
- end
-end
More information about the ap4r-devel
mailing list