activerecord-jdbc-adapter-ficoh 1.3.21-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.travis.yml +462 -0
- data/.yardopts +4 -0
- data/Appraisals +36 -0
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +68 -0
- data/History.md +1191 -0
- data/LICENSE.txt +25 -0
- data/README.md +277 -0
- data/RUNNING_TESTS.md +88 -0
- data/Rakefile +298 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +63 -0
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +64 -0
- data/lib/arel/visitors/db2.rb +137 -0
- data/lib/arel/visitors/derby.rb +112 -0
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +32 -0
- data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
- data/lib/arel/visitors/sql_server.rb +225 -0
- data/lib/arel/visitors/sql_server/ng42.rb +293 -0
- data/lib/arjdbc.rb +22 -0
- data/lib/arjdbc/db2.rb +4 -0
- data/lib/arjdbc/db2/adapter.rb +802 -0
- data/lib/arjdbc/db2/as400.rb +137 -0
- data/lib/arjdbc/db2/column.rb +177 -0
- data/lib/arjdbc/db2/connection_methods.rb +45 -0
- data/lib/arjdbc/derby.rb +3 -0
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +567 -0
- data/lib/arjdbc/derby/connection_methods.rb +16 -0
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +104 -0
- data/lib/arjdbc/firebird.rb +4 -0
- data/lib/arjdbc/firebird/adapter.rb +468 -0
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2.rb +3 -0
- data/lib/arjdbc/h2/adapter.rb +335 -0
- data/lib/arjdbc/h2/connection_methods.rb +22 -0
- data/lib/arjdbc/hsqldb.rb +3 -0
- data/lib/arjdbc/hsqldb/adapter.rb +304 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +23 -0
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +5 -0
- data/lib/arjdbc/informix/adapter.rb +160 -0
- data/lib/arjdbc/informix/connection_methods.rb +9 -0
- data/lib/arjdbc/jdbc.rb +62 -0
- data/lib/arjdbc/jdbc/adapter.rb +997 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/arel_support.rb +149 -0
- data/lib/arjdbc/jdbc/base_ext.rb +34 -0
- data/lib/arjdbc/jdbc/callbacks.rb +52 -0
- data/lib/arjdbc/jdbc/column.rb +83 -0
- data/lib/arjdbc/jdbc/connection.rb +26 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +59 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/error.rb +75 -0
- data/lib/arjdbc/jdbc/extension.rb +69 -0
- data/lib/arjdbc/jdbc/java.rb +13 -0
- data/lib/arjdbc/jdbc/type_cast.rb +154 -0
- data/lib/arjdbc/jdbc/type_converter.rb +142 -0
- data/lib/arjdbc/mssql.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +822 -0
- data/lib/arjdbc/mssql/column.rb +207 -0
- data/lib/arjdbc/mssql/connection_methods.rb +72 -0
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +231 -0
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/types.rb +343 -0
- data/lib/arjdbc/mssql/utils.rb +82 -0
- data/lib/arjdbc/mysql.rb +3 -0
- data/lib/arjdbc/mysql/adapter.rb +998 -0
- data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
- data/lib/arjdbc/mysql/column.rb +167 -0
- data/lib/arjdbc/mysql/connection_methods.rb +137 -0
- data/lib/arjdbc/mysql/explain_support.rb +82 -0
- data/lib/arjdbc/mysql/schema_creation.rb +58 -0
- data/lib/arjdbc/oracle.rb +4 -0
- data/lib/arjdbc/oracle/adapter.rb +968 -0
- data/lib/arjdbc/oracle/column.rb +136 -0
- data/lib/arjdbc/oracle/connection_methods.rb +21 -0
- data/lib/arjdbc/postgresql.rb +3 -0
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
- data/lib/arjdbc/postgresql/adapter.rb +1498 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/oid.rb +412 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +8 -0
- data/lib/arjdbc/postgresql/base/schema_definitions.rb +132 -0
- data/lib/arjdbc/postgresql/column.rb +640 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +44 -0
- data/lib/arjdbc/postgresql/explain_support.rb +53 -0
- data/lib/arjdbc/postgresql/oid/bytea.rb +3 -0
- data/lib/arjdbc/postgresql/oid_types.rb +265 -0
- data/lib/arjdbc/postgresql/schema_creation.rb +60 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +3 -0
- data/lib/arjdbc/sqlite3/adapter.rb +654 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +36 -0
- data/lib/arjdbc/sqlite3/explain_support.rb +29 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +47 -0
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +66 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +239 -0
- data/lib/arjdbc/tasks/databases4.rake +39 -0
- data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
- data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
- data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +65 -0
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/serialized_attributes.rb +98 -0
- data/lib/arjdbc/util/table_copier.rb +108 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +17 -0
- data/pom.xml +285 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +10 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +11 -0
- data/rakelib/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +151 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/db.rake +58 -0
- data/rakelib/rails.rake +77 -0
- data/src/java/arjdbc/ArJdbcModule.java +288 -0
- data/src/java/arjdbc/db2/DB2Module.java +77 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +128 -0
- data/src/java/arjdbc/derby/DerbyModule.java +180 -0
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +153 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
- data/src/java/arjdbc/h2/H2Module.java +50 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +86 -0
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +74 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +76 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +43 -0
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +77 -0
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +156 -0
- data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
- data/src/java/arjdbc/jdbc/DriverWrapper.java +128 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +32 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4541 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
- data/src/java/arjdbc/jdbc/WithResultSet.java +37 -0
- data/src/java/arjdbc/mssql/MSSQLModule.java +91 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +193 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +140 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +456 -0
- data/src/java/arjdbc/oracle/OracleModule.java +81 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +477 -0
- data/src/java/arjdbc/postgresql/ByteaUtils.java +171 -0
- data/src/java/arjdbc/postgresql/DriverImplementation.java +78 -0
- data/src/java/arjdbc/postgresql/PGDriverImplementation.java +535 -0
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +189 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +489 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +93 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +405 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/DateTimeUtils.java +517 -0
- data/src/java/arjdbc/util/NumberUtils.java +50 -0
- data/src/java/arjdbc/util/ObjectSupport.java +65 -0
- data/src/java/arjdbc/util/QuotingUtils.java +139 -0
- data/src/java/arjdbc/util/StringCache.java +60 -0
- data/src/java/arjdbc/util/StringHelper.java +155 -0
- metadata +288 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
3
|
+
module ArJdbc
|
4
|
+
module MSSQL
|
5
|
+
module LockMethods
|
6
|
+
|
7
|
+
# @private
|
8
|
+
SELECT_FROM_WHERE_RE = /\A(\s*SELECT\s.*?)(\sFROM\s)(.*?)(\sWHERE\s.*|)\Z/mi
|
9
|
+
|
10
|
+
# Microsoft SQL Server uses its own syntax for SELECT .. FOR UPDATE:
|
11
|
+
# SELECT .. FROM table1 WITH(ROWLOCK,UPDLOCK), table2 WITH(ROWLOCK,UPDLOCK) WHERE ..
|
12
|
+
#
|
13
|
+
# This does in-place modification of the passed-in string.
|
14
|
+
def add_lock!(sql, options)
|
15
|
+
if (lock = options[:lock]) && sql =~ /\A\s*SELECT/mi
|
16
|
+
# Check for and extract the :limit/:offset sub-query
|
17
|
+
if sql =~ /\A(\s*SELECT t\.\* FROM \()(.*)(\) AS t WHERE t._row_num BETWEEN \d+ AND \d+\s*)\Z/m
|
18
|
+
prefix, subselect, suffix = [$1, $2, $3]
|
19
|
+
add_lock!(subselect, options)
|
20
|
+
return sql.replace(prefix + subselect + suffix)
|
21
|
+
end
|
22
|
+
unless sql =~ SELECT_FROM_WHERE_RE
|
23
|
+
# If you get this error, this driver probably needs to be fixed.
|
24
|
+
raise NotImplementedError, "Don't know how to add_lock! to SQL statement: #{sql.inspect}"
|
25
|
+
end
|
26
|
+
select_clause, from_word, from_tables, where_clause = $1, $2, $3, $4
|
27
|
+
with_clause = lock.is_a?(String) ? " #{lock} " : " WITH(ROWLOCK,UPDLOCK) "
|
28
|
+
|
29
|
+
# Split the FROM clause into its constituent tables, and add the with clause after each one.
|
30
|
+
new_from_tables = []
|
31
|
+
scanner = StringScanner.new(from_tables)
|
32
|
+
until scanner.eos?
|
33
|
+
prev_pos = scanner.pos
|
34
|
+
if scanner.scan_until(/,|(INNER\s+JOIN|CROSS\s+JOIN|(LEFT|RIGHT|FULL)(\s+OUTER)?\s+JOIN)\s+/mi)
|
35
|
+
join_operand = scanner.pre_match[prev_pos..-1]
|
36
|
+
join_operator = scanner.matched
|
37
|
+
else
|
38
|
+
join_operand = scanner.rest
|
39
|
+
join_operator = ""
|
40
|
+
scanner.terminate
|
41
|
+
end
|
42
|
+
|
43
|
+
# At this point, we have something like:
|
44
|
+
# join_operand == "appointments "
|
45
|
+
# join_operator == "INNER JOIN "
|
46
|
+
# or:
|
47
|
+
# join_operand == "appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]"
|
48
|
+
# join_operator == ""
|
49
|
+
if join_operand =~ /\A(.*)(\s+ON\s+.*)\Z/mi
|
50
|
+
table_spec, on_clause = $1, $2
|
51
|
+
else
|
52
|
+
table_spec = join_operand
|
53
|
+
on_clause = ""
|
54
|
+
end
|
55
|
+
|
56
|
+
# Add the "WITH(ROWLOCK,UPDLOCK)" option to the table specification
|
57
|
+
table_spec << with_clause unless table_spec =~ /\A\(\s*SELECT\s+/mi # HACK - this parser isn't so great
|
58
|
+
join_operand = table_spec + on_clause
|
59
|
+
|
60
|
+
# So now we have something like:
|
61
|
+
# join_operand == "appointments WITH(ROWLOCK,UPDLOCK) "
|
62
|
+
# join_operator == "INNER JOIN "
|
63
|
+
# or:
|
64
|
+
# join_operand == "appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]"
|
65
|
+
# join_operator == ""
|
66
|
+
|
67
|
+
new_from_tables << join_operand
|
68
|
+
new_from_tables << join_operator
|
69
|
+
end
|
70
|
+
sql.replace( select_clause.to_s << from_word.to_s << new_from_tables.join << where_clause.to_s )
|
71
|
+
end
|
72
|
+
sql
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,343 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module MSSQL
|
3
|
+
|
4
|
+
def initialize_type_map(m)
|
5
|
+
#m.register_type %r{.*}, UnicodeStringType.new
|
6
|
+
# Exact Numerics
|
7
|
+
register_class_with_limit m, /^bigint./, BigIntegerType
|
8
|
+
m.alias_type 'bigint', 'bigint(8)'
|
9
|
+
register_class_with_limit m, /^int\(|\s/, ActiveRecord::Type::Integer
|
10
|
+
m.alias_type /^integer/, 'int(4)'
|
11
|
+
m.alias_type 'int', 'int(4)'
|
12
|
+
register_class_with_limit m, /^smallint./, SmallIntegerType
|
13
|
+
m.alias_type 'smallint', 'smallint(2)'
|
14
|
+
register_class_with_limit m, /^tinyint./, TinyIntegerType
|
15
|
+
m.alias_type 'tinyint', 'tinyint(1)'
|
16
|
+
m.register_type /^bit/, ActiveRecord::Type::Boolean.new
|
17
|
+
m.register_type %r{\Adecimal} do |sql_type|
|
18
|
+
scale = extract_scale(sql_type)
|
19
|
+
precision = extract_precision(sql_type)
|
20
|
+
DecimalType.new :precision => precision, :scale => scale
|
21
|
+
#if scale == 0
|
22
|
+
# ActiveRecord::Type::Integer.new(:precision => precision)
|
23
|
+
#else
|
24
|
+
# DecimalType.new(:precision => precision, :scale => scale)
|
25
|
+
#end
|
26
|
+
end
|
27
|
+
m.alias_type %r{\Anumeric}, 'decimal'
|
28
|
+
m.register_type /^money/, MoneyType.new
|
29
|
+
m.register_type /^smallmoney/, SmallMoneyType.new
|
30
|
+
# Approximate Numerics
|
31
|
+
m.register_type /^float/, ActiveRecord::Type::Float.new
|
32
|
+
m.register_type /^real/, RealType.new
|
33
|
+
# Date and Time
|
34
|
+
m.register_type /^date\(?/, ActiveRecord::Type::Date.new
|
35
|
+
m.register_type /^datetime\(?/, DateTimeType.new
|
36
|
+
m.register_type /smalldatetime/, SmallDateTimeType.new
|
37
|
+
m.register_type %r{\Atime} do |sql_type|
|
38
|
+
TimeType.new :precision => extract_precision(sql_type)
|
39
|
+
end
|
40
|
+
# Character Strings
|
41
|
+
register_class_with_limit m, %r{\Achar}i, CharType
|
42
|
+
#register_class_with_limit m, %r{\Avarchar}i, VarcharType
|
43
|
+
m.register_type %r{\Anvarchar}i do |sql_type|
|
44
|
+
limit = extract_limit(sql_type)
|
45
|
+
if limit == 2_147_483_647 # varchar(max)
|
46
|
+
VarcharMaxType.new
|
47
|
+
else
|
48
|
+
VarcharType.new :limit => limit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
#m.register_type 'varchar(max)', VarcharMaxType.new
|
52
|
+
m.register_type /^text/, TextType.new
|
53
|
+
# Unicode Character Strings
|
54
|
+
register_class_with_limit m, %r{\Anchar}i, UnicodeCharType
|
55
|
+
#register_class_with_limit m, %r{\Anvarchar}i, UnicodeVarcharType
|
56
|
+
m.register_type %r{\Anvarchar}i do |sql_type|
|
57
|
+
limit = extract_limit(sql_type)
|
58
|
+
if limit == 1_073_741_823 # nvarchar(max)
|
59
|
+
UnicodeVarcharMaxType.new
|
60
|
+
else
|
61
|
+
UnicodeVarcharType.new :limit => limit
|
62
|
+
end
|
63
|
+
end
|
64
|
+
#m.register_type 'nvarchar(max)', UnicodeVarcharMaxType.new
|
65
|
+
m.alias_type 'string', 'nvarchar(4000)'
|
66
|
+
m.register_type /^ntext/, UnicodeTextType.new
|
67
|
+
# Binary Strings
|
68
|
+
register_class_with_limit m, %r{\Aimage}i, ImageType
|
69
|
+
register_class_with_limit m, %r{\Abinary}i, BinaryType
|
70
|
+
register_class_with_limit m, %r{\Avarbinary}i, VarbinaryType
|
71
|
+
#m.register_type 'varbinary(max)', VarbinaryMaxType.new
|
72
|
+
# Other Data Types
|
73
|
+
m.register_type 'uniqueidentifier', UUIDType.new
|
74
|
+
# TODO
|
75
|
+
#m.register_type 'timestamp', SQLServer::Type::Timestamp.new
|
76
|
+
m.register_type 'xml', XmlType.new
|
77
|
+
end
|
78
|
+
|
79
|
+
def clear_cache!
|
80
|
+
super
|
81
|
+
reload_type_map
|
82
|
+
end
|
83
|
+
|
84
|
+
# @private
|
85
|
+
class BigIntegerType < ActiveRecord::Type::BigInteger
|
86
|
+
def type; :bigint end
|
87
|
+
end
|
88
|
+
|
89
|
+
# @private
|
90
|
+
SmallIntegerType = ActiveRecord::Type::Integer
|
91
|
+
|
92
|
+
# @private
|
93
|
+
class TinyIntegerType < ActiveRecord::Type::Integer
|
94
|
+
def max_value; 256 end
|
95
|
+
def min_value; 0 end
|
96
|
+
end
|
97
|
+
|
98
|
+
# @private
|
99
|
+
class RealType < ActiveRecord::Type::Float
|
100
|
+
def type; :real end
|
101
|
+
end
|
102
|
+
|
103
|
+
# @private
|
104
|
+
class DecimalType < ActiveRecord::Type::Decimal
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def cast_value(value)
|
109
|
+
return 0 if value.equal? false
|
110
|
+
return 1 if value.equal? true
|
111
|
+
|
112
|
+
if @scale == 0 # act-like an integer
|
113
|
+
return value.to_i rescue nil
|
114
|
+
end
|
115
|
+
|
116
|
+
case value
|
117
|
+
when ::Float
|
118
|
+
if precision
|
119
|
+
BigDecimal(value, float_precision)
|
120
|
+
else
|
121
|
+
value.to_d
|
122
|
+
end
|
123
|
+
when ::Numeric, ::String
|
124
|
+
BigDecimal(value, precision.to_i)
|
125
|
+
else
|
126
|
+
if value.respond_to?(:to_d)
|
127
|
+
value.to_d
|
128
|
+
else
|
129
|
+
BigDecimal(value.to_s, precision.to_i)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def float_precision
|
135
|
+
if precision.to_i > ::Float::DIG + 1
|
136
|
+
::Float::DIG + 1
|
137
|
+
else
|
138
|
+
precision.to_i
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
#def max_value; ::Float::INFINITY end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
# @private
|
147
|
+
class MoneyType < DecimalType
|
148
|
+
def type; :money end
|
149
|
+
def initialize(options = {})
|
150
|
+
super; @precision = 19; @scale = 4
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# @private
|
155
|
+
class SmallMoneyType < MoneyType
|
156
|
+
def type; :smallmoney end
|
157
|
+
def initialize(options = {})
|
158
|
+
super; @precision = 10; @scale = 4
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# @private
|
163
|
+
class DateTimeType < ActiveRecord::Type::DateTime
|
164
|
+
|
165
|
+
def type_cast_for_schema(value)
|
166
|
+
value.acts_like?(:string) ? "'#{value}'" : "'#{value.to_s(:db)}'"
|
167
|
+
end
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
def cast_value(value)
|
172
|
+
value = value.respond_to?(:usec) ? value : super
|
173
|
+
return unless value
|
174
|
+
value.change usec: cast_usec(value)
|
175
|
+
end
|
176
|
+
|
177
|
+
def cast_usec(value)
|
178
|
+
return 0 if !value.respond_to?(:usec) || value.usec.zero?
|
179
|
+
seconds = value.usec.to_f / 1_000_000.0
|
180
|
+
second_precision = 0.00333
|
181
|
+
ss_seconds = ((seconds * (1 / second_precision)).round / (1 / second_precision)).round(3)
|
182
|
+
(ss_seconds * 1_000_000).to_i
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
# @private
|
188
|
+
class SmallDateTimeType < DateTimeType
|
189
|
+
def cast_usec(value); 0 end
|
190
|
+
def cast_usec_for_database(value); '.000' end
|
191
|
+
end
|
192
|
+
|
193
|
+
# @private
|
194
|
+
class TimeType < ActiveRecord::Type::Time
|
195
|
+
|
196
|
+
def initialize(options = {})
|
197
|
+
super; @precision = nil if @precision == 7
|
198
|
+
end
|
199
|
+
|
200
|
+
def type_cast_for_schema(value)
|
201
|
+
value.acts_like?(:string) ? "'#{value}'" : super
|
202
|
+
end
|
203
|
+
|
204
|
+
private
|
205
|
+
|
206
|
+
def cast_value(value)
|
207
|
+
value = value.respond_to?(:usec) ?
|
208
|
+
value.change(year: 2000, month: 01, day: 01) :
|
209
|
+
cast_value_like_super(value)
|
210
|
+
|
211
|
+
return if value.blank?
|
212
|
+
value.change usec: cast_usec(value)
|
213
|
+
end
|
214
|
+
|
215
|
+
def cast_value_like_super(value)
|
216
|
+
return value unless value.is_a?(::String)
|
217
|
+
return if value.empty?
|
218
|
+
|
219
|
+
dummy_value = "2000-01-01 #{value}"
|
220
|
+
|
221
|
+
fast_string_to_time(dummy_value) || DateTime.parse(dummy_value).to_time # rescue nil
|
222
|
+
end
|
223
|
+
|
224
|
+
def cast_usec(value)
|
225
|
+
(usec_to_seconds_frction(value) * 1_000_000).to_i
|
226
|
+
end
|
227
|
+
|
228
|
+
def usec_to_seconds_frction(value)
|
229
|
+
(value.usec.to_f / 1_000_000.0).round(precision || 7)
|
230
|
+
end
|
231
|
+
|
232
|
+
#def quote_usec(value)
|
233
|
+
# usec_to_seconds_frction(value).to_s.split('.').last
|
234
|
+
#end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
# @private
|
239
|
+
StringType = ActiveRecord::Type::String
|
240
|
+
|
241
|
+
# @private
|
242
|
+
class CharType < StringType
|
243
|
+
def type; :char end
|
244
|
+
end
|
245
|
+
|
246
|
+
# @private
|
247
|
+
class VarcharType < StringType
|
248
|
+
def type; :varchar end
|
249
|
+
def initialize(options = {})
|
250
|
+
super; @limit = 8000 if @limit.to_i == 0
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
# @private
|
255
|
+
class TextType < StringType
|
256
|
+
def type; :text_basic end
|
257
|
+
end
|
258
|
+
|
259
|
+
# @private
|
260
|
+
class VarcharMaxType < TextType
|
261
|
+
def type; :varchar_max end
|
262
|
+
def limit; @limit ||= 2_147_483_647 end
|
263
|
+
end
|
264
|
+
|
265
|
+
# @private
|
266
|
+
class UnicodeCharType < StringType
|
267
|
+
def type; :nchar end
|
268
|
+
end
|
269
|
+
|
270
|
+
# @private
|
271
|
+
class UnicodeVarcharType < StringType
|
272
|
+
def type; :string end
|
273
|
+
def initialize(options = {})
|
274
|
+
super; @limit = 4000 if @limit.to_i == 0
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# @private
|
279
|
+
class UnicodeVarcharMaxType < TextType
|
280
|
+
def type; :text end # :nvarchar_max end
|
281
|
+
def limit; @limit ||= 2_147_483_647 end
|
282
|
+
end
|
283
|
+
|
284
|
+
# @private
|
285
|
+
class UnicodeTextType < TextType
|
286
|
+
def type; :ntext end
|
287
|
+
def limit; @limit ||= 2_147_483_647 end
|
288
|
+
end
|
289
|
+
|
290
|
+
# @private
|
291
|
+
class BinaryType < ActiveRecord::Type::Binary
|
292
|
+
def type; :binary_basic end
|
293
|
+
end
|
294
|
+
|
295
|
+
# @private
|
296
|
+
class ImageType < BinaryType # ActiveRecord::Type::Binary
|
297
|
+
def type; :binary end
|
298
|
+
def limit; @limit ||= 2_147_483_647 end
|
299
|
+
end
|
300
|
+
|
301
|
+
# @private
|
302
|
+
class VarbinaryType < BinaryType # ActiveRecord::Type::Binary
|
303
|
+
def type; :varbinary end
|
304
|
+
def initialize(options = {})
|
305
|
+
super; @limit = 8000 if @limit.to_i == 0
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
# @private
|
310
|
+
class VarbinaryMaxType < BinaryType # ActiveRecord::Type::Binary
|
311
|
+
def type; :varbinary_max end
|
312
|
+
def limit; @limit ||= 2_147_483_647 end
|
313
|
+
end
|
314
|
+
|
315
|
+
# @private
|
316
|
+
class UUIDType < ActiveRecord::Type::String
|
317
|
+
def type; :uuid end
|
318
|
+
|
319
|
+
alias_method :type_cast_for_database, :type_cast_from_database
|
320
|
+
|
321
|
+
ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}?\z}x
|
322
|
+
def type_cast(value); value.to_s[ACCEPTABLE_UUID, 0] end
|
323
|
+
end
|
324
|
+
|
325
|
+
# @private
|
326
|
+
class XmlType < ActiveRecord::Type::String
|
327
|
+
def type; :xml end
|
328
|
+
|
329
|
+
def type_cast_for_database(value)
|
330
|
+
return unless value
|
331
|
+
Data.new(super)
|
332
|
+
end
|
333
|
+
|
334
|
+
class Data
|
335
|
+
def initialize(value)
|
336
|
+
@value = value
|
337
|
+
end
|
338
|
+
def to_s; @value end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
343
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# NOTE: file contains code adapted from **sqlserver** adapter, license follows
|
2
|
+
=begin
|
3
|
+
Copyright (c) 2008-2015
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
=end
|
24
|
+
|
25
|
+
module ArJdbc
|
26
|
+
module MSSQL
|
27
|
+
module Utils
|
28
|
+
|
29
|
+
module_function
|
30
|
+
|
31
|
+
GET_TABLE_NAME_INSERT_UPDATE_RE =
|
32
|
+
/^\s*(INSERT|EXEC sp_executesql N'INSERT)(?:\s+INTO)?\s+([^\(\s]+)\s*|^\s*update\s+([^\(\s]+)\s*/i
|
33
|
+
|
34
|
+
GET_TABLE_NAME_FROM_RE = /\bFROM\s+([^\(\)\s,]+)\s*/i
|
35
|
+
|
36
|
+
def get_table_name(sql, qualified = nil)
|
37
|
+
if sql =~ GET_TABLE_NAME_INSERT_UPDATE_RE
|
38
|
+
tn = $2 || $3
|
39
|
+
qualified ? tn : unqualify_table_name(tn)
|
40
|
+
elsif sql =~ GET_TABLE_NAME_FROM_RE
|
41
|
+
qualified ? $1 : unqualify_table_name($1)
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def unquote_table_name(table_name)
|
48
|
+
remove_identifier_delimiters(table_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
def unquote_column_name(column_name)
|
52
|
+
remove_identifier_delimiters(column_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
def unquote_string(string)
|
56
|
+
string.to_s.gsub("''", "'")
|
57
|
+
end
|
58
|
+
|
59
|
+
def unqualify_table_name(table_name)
|
60
|
+
remove_identifier_delimiters(table_name.to_s.split('.').last)
|
61
|
+
end
|
62
|
+
|
63
|
+
def unqualify_table_schema(table_name)
|
64
|
+
schema_name = table_name.to_s.split('.')[-2]
|
65
|
+
schema_name.nil? ? nil : remove_identifier_delimiters(schema_name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def unqualify_db_name(table_name)
|
69
|
+
table_names = table_name.to_s.split('.')
|
70
|
+
table_names.length == 3 ? remove_identifier_delimiters(table_names.first) : nil
|
71
|
+
end
|
72
|
+
|
73
|
+
# private
|
74
|
+
|
75
|
+
# See "Delimited Identifiers": http://msdn.microsoft.com/en-us/library/ms176027.aspx
|
76
|
+
def remove_identifier_delimiters(keyword)
|
77
|
+
keyword.to_s.tr("\]\[\"", '')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|