Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ adapters are available:

```yml
development:
adapter: mysql2 # or mysql
adapter: mysql2
database: blog_development
username: blog
password: 1234
Expand All @@ -80,7 +80,7 @@ or preferably using the *properties:* syntax:

```yml
production:
adapter: mysql
adapter: mysql2
username: blog
password: blog
url: "jdbc:mysql://localhost:3306/blog?profileSQL=true"
Expand Down
11 changes: 10 additions & 1 deletion lib/arjdbc/abstract/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ def translate_exception(exception, message:, sql:, binds:)
# this version of log() automatically fills type_casted_binds from binds if necessary
def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil, async: false)
if binds.any? && (type_casted_binds.nil? || type_casted_binds.empty?)
type_casted_binds = ->{ binds.map(&:value_for_database) } # extract_raw_bind_values
type_casted_binds = lambda {
# extract_raw_bind_values
binds.map do |bind|
if bind.respond_to?(:value_for_database)
bind.value_for_database
else
bind
end
end
}
end
super
end
Expand Down
4 changes: 3 additions & 1 deletion lib/arjdbc/abstract/transaction_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def supports_transaction_isolation?
def begin_db_transaction
log('BEGIN', 'TRANSACTION') do
with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
conn.begin
result = conn.begin
verified!
result
end
end
end
Expand Down
14 changes: 12 additions & 2 deletions lib/arjdbc/mysql/adapter_hash_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def build_connection_config(config)

load_jdbc_driver

config[:driver] ||= database_driver_name
# don't set driver if it's explicitly set to false
# allow Java's service discovery mechanism (with connector/j 8.0)
config[:driver] ||= database_driver_name if config[:driver] != false

host = (config[:host] ||= "localhost")
port = (config[:port] ||= 3306)
Expand Down Expand Up @@ -40,7 +42,7 @@ def database_driver_name
def build_properties(config)
properties = config[:properties] || {}

properties["zeroDateTimeBehavior"] ||= "CONVERT_TO_NULL"
properties["zeroDateTimeBehavior"] ||= default_zero_date_time_behavior(config[:driver])

properties["jdbcCompliantTruncation"] ||= false

Expand Down Expand Up @@ -88,6 +90,14 @@ def build_properties(config)
properties
end

def default_zero_date_time_behavior(driver)
return "CONVERT_TO_NULL" if driver == false

return "CONVERT_TO_NULL" if driver.start_with?("com.mysql.cj.")

"convertToNull"
end

# See https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-charsets.html
# to charset-name (characterEncoding=...)
def convert_mysql_encoding(config)
Expand Down
16 changes: 14 additions & 2 deletions lib/arjdbc/postgresql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def enum_types
type.typname AS name,
type.OID AS oid,
n.nspname AS schema,
string_agg(enum.enumlabel, ',' ORDER BY enum.enumsortorder) AS value
array_agg(enum.enumlabel ORDER BY enum.enumsortorder) AS value
FROM pg_enum AS enum
JOIN pg_type AS type ON (type.oid = enum.enumtypid)
JOIN pg_namespace n ON type.typnamespace = n.oid
Expand Down Expand Up @@ -842,6 +842,15 @@ class PostgreSQLAdapter < AbstractAdapter
# setting, you should immediately run <tt>bin/rails db:migrate</tt> to update the types in your schema.rb.
class_attribute :datetime_type, default: :timestamp

##
# :singleton-method:
# Toggles automatic decoding of date columns.
#
# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date").class #=> String
# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.decode_dates = true
# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date").class #=> Date
class_attribute :decode_dates, default: false

# Try to use as much of the built in postgres logic as possible
# maybe someday we can extend the actual adapter
include ActiveRecord::ConnectionAdapters::PostgreSQL::ReferentialIntegrity
Expand All @@ -855,9 +864,12 @@ class PostgreSQLAdapter < AbstractAdapter
include ArJdbc::Abstract::DatabaseStatements
include ArJdbc::Abstract::StatementCache
include ArJdbc::Abstract::TransactionSupport
include ArJdbc::PostgreSQL
include ArJdbc::PostgreSQLConfig

# NOTE: after AR refactor quote_column_name became class and instance method
include ArJdbc::PostgreSQL
extend ArJdbc::PostgreSQL

require 'arjdbc/postgresql/oid_types'
include ::ArJdbc::PostgreSQL::OIDTypes
include ::ArJdbc::PostgreSQL::DatabaseStatements
Expand Down
8 changes: 7 additions & 1 deletion lib/arjdbc/postgresql/adapter_hash_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ def build_connection_config(config)
port = (config[:port] ||= ENV["PGPORT"] || 5432)
database = config[:database] || config[:dbname] || ENV["PGDATABASE"]

config[:url] ||= "jdbc:postgresql://#{host}:#{port}/#{database}"
app = config[:application_name] || config[:appname] || config[:application]

config[:url] ||= if app
"jdbc:postgresql://#{host}:#{port}/#{database}?ApplicationName=#{app}"
else
"jdbc:postgresql://#{host}:#{port}/#{database}"
end

config[:url] << config[:pg_params] if config[:pg_params]

Expand Down
Loading
Loading