activerecord-sqlserver-adapter 4.1.8 → 4.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -0
  3. data/CHANGELOG.md +60 -0
  4. data/Gemfile +45 -0
  5. data/Guardfile +29 -0
  6. data/MIT-LICENSE +5 -5
  7. data/README.md +193 -0
  8. data/RUNNING_UNIT_TESTS.md +95 -0
  9. data/Rakefile +48 -0
  10. data/activerecord-sqlserver-adapter.gemspec +28 -0
  11. data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +5 -15
  12. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +25 -0
  13. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +6 -4
  14. data/lib/active_record/connection_adapters/sqlserver/core_ext/odbc.rb +9 -3
  15. data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +3 -1
  16. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +130 -151
  17. data/lib/active_record/connection_adapters/sqlserver/errors.rb +0 -25
  18. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +39 -78
  19. data/lib/active_record/connection_adapters/sqlserver/schema_cache.rb +71 -47
  20. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +14 -30
  21. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +112 -108
  22. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +4 -2
  23. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +1 -1
  24. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +1 -1
  25. data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +52 -7
  26. data/lib/active_record/connection_adapters/sqlserver/transaction.rb +52 -0
  27. data/lib/active_record/connection_adapters/sqlserver/type.rb +46 -0
  28. data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +15 -0
  29. data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +15 -0
  30. data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +13 -0
  31. data/lib/active_record/connection_adapters/sqlserver/type/castable.rb +15 -0
  32. data/lib/active_record/connection_adapters/sqlserver/type/char.rb +15 -0
  33. data/lib/active_record/connection_adapters/sqlserver/type/core_ext/value.rb +39 -0
  34. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +14 -0
  35. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +37 -0
  36. data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +13 -0
  37. data/lib/active_record/connection_adapters/sqlserver/type/float.rb +17 -0
  38. data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +13 -0
  39. data/lib/active_record/connection_adapters/sqlserver/type/money.rb +21 -0
  40. data/lib/active_record/connection_adapters/sqlserver/type/quoter.rb +32 -0
  41. data/lib/active_record/connection_adapters/sqlserver/type/real.rb +17 -0
  42. data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +13 -0
  43. data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +21 -0
  44. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +24 -0
  45. data/lib/active_record/connection_adapters/sqlserver/type/string.rb +12 -0
  46. data/lib/active_record/connection_adapters/sqlserver/type/text.rb +15 -0
  47. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +59 -0
  48. data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +15 -0
  49. data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +22 -0
  50. data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +15 -0
  51. data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +12 -0
  52. data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +15 -0
  53. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +20 -0
  54. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +20 -0
  55. data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +23 -0
  56. data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +20 -0
  57. data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +20 -0
  58. data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +20 -0
  59. data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +20 -0
  60. data/lib/active_record/connection_adapters/sqlserver/utils.rb +118 -12
  61. data/lib/active_record/connection_adapters/sqlserver/version.rb +11 -0
  62. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +133 -198
  63. data/lib/active_record/connection_adapters/sqlserver_column.rb +15 -86
  64. data/lib/active_record/sqlserver_base.rb +2 -0
  65. data/lib/arel/visitors/sqlserver.rb +120 -393
  66. data/lib/{arel/arel_sqlserver.rb → arel_sqlserver.rb} +1 -3
  67. data/test/cases/adapter_test_sqlserver.rb +420 -0
  68. data/test/cases/coerced_tests.rb +642 -0
  69. data/test/cases/column_test_sqlserver.rb +703 -0
  70. data/test/cases/connection_test_sqlserver.rb +216 -0
  71. data/test/cases/database_statements_test_sqlserver.rb +57 -0
  72. data/test/cases/execute_procedure_test_sqlserver.rb +38 -0
  73. data/test/cases/helper_sqlserver.rb +36 -0
  74. data/test/cases/migration_test_sqlserver.rb +66 -0
  75. data/test/cases/order_test_sqlserver.rb +147 -0
  76. data/test/cases/pessimistic_locking_test_sqlserver.rb +90 -0
  77. data/test/cases/schema_dumper_test_sqlserver.rb +175 -0
  78. data/test/cases/schema_test_sqlserver.rb +54 -0
  79. data/test/cases/scratchpad_test_sqlserver.rb +9 -0
  80. data/test/cases/showplan_test_sqlserver.rb +65 -0
  81. data/test/cases/specific_schema_test_sqlserver.rb +118 -0
  82. data/test/cases/transaction_test_sqlserver.rb +61 -0
  83. data/test/cases/utils_test_sqlserver.rb +91 -0
  84. data/test/cases/uuid_test_sqlserver.rb +41 -0
  85. data/test/config.yml +35 -0
  86. data/test/fixtures/1px.gif +0 -0
  87. data/test/migrations/transaction_table/1_table_will_never_be_created.rb +11 -0
  88. data/test/models/sqlserver/customers_view.rb +3 -0
  89. data/test/models/sqlserver/datatype.rb +3 -0
  90. data/test/models/sqlserver/datatype_migration.rb +3 -0
  91. data/test/models/sqlserver/dollar_table_name.rb +3 -0
  92. data/test/models/sqlserver/edge_schema.rb +13 -0
  93. data/test/models/sqlserver/fk_has_fk.rb +3 -0
  94. data/test/models/sqlserver/fk_has_pk.rb +3 -0
  95. data/test/models/sqlserver/natural_pk_data.rb +4 -0
  96. data/test/models/sqlserver/natural_pk_int_data.rb +3 -0
  97. data/test/models/sqlserver/no_pk_data.rb +3 -0
  98. data/test/models/sqlserver/quoted_table.rb +7 -0
  99. data/test/models/sqlserver/quoted_view_1.rb +3 -0
  100. data/test/models/sqlserver/quoted_view_2.rb +3 -0
  101. data/test/models/sqlserver/string_default.rb +3 -0
  102. data/test/models/sqlserver/string_defaults_big_view.rb +3 -0
  103. data/test/models/sqlserver/string_defaults_view.rb +3 -0
  104. data/test/models/sqlserver/tinyint_pk.rb +3 -0
  105. data/test/models/sqlserver/upper.rb +3 -0
  106. data/test/models/sqlserver/uppered.rb +3 -0
  107. data/test/models/sqlserver/uuid.rb +3 -0
  108. data/test/schema/datatypes/2012.sql +64 -0
  109. data/test/schema/sqlserver_specific_schema.rb +181 -0
  110. data/test/support/coerceable_test_sqlserver.rb +45 -0
  111. data/test/support/load_schema_sqlserver.rb +29 -0
  112. data/test/support/minitest_sqlserver.rb +1 -0
  113. data/test/support/paths_sqlserver.rb +48 -0
  114. data/test/support/rake_helpers.rb +41 -0
  115. data/test/support/sql_counter_sqlserver.rb +32 -0
  116. metadata +271 -21
  117. data/CHANGELOG +0 -39
  118. data/VERSION +0 -1
  119. data/lib/active_record/connection_adapters/sqlserver/core_ext/relation.rb +0 -17
  120. data/lib/active_record/sqlserver_test_case.rb +0 -17
  121. data/lib/arel/nodes_sqlserver.rb +0 -14
  122. data/lib/arel/select_manager_sqlserver.rb +0 -62
data/CHANGELOG DELETED
@@ -1,39 +0,0 @@
1
- ## v4.1.8
2
-
3
- * Allow 2017 in supported versions.
4
-
5
- ## v4.1.7
6
-
7
- * Fix `user_options`.
8
-
9
- ## v4.1.6
10
-
11
- * Fix parens around `enable_default_unicode_types`. Fixes #562
12
-
13
- ## v4.1.5
14
-
15
- * Added vNext to supported list.
16
-
17
- ## v4.1.4
18
-
19
- * Added 2016 to supported list.
20
-
21
- ## v4.1.3
22
-
23
- #### Fixed
24
-
25
- * Partial indexes using `:where` in schema dumper. Fixes #153
26
-
27
-
28
- ## v4.1.2
29
-
30
- #### Fixed
31
-
32
- * Bundling and test running. Noted current failures.
33
- * Fix `remove_column` arity. Fixes #359
34
-
35
-
36
- ## v4.1.1
37
-
38
- * No information :/
39
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 4.1.8
@@ -1,17 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module Sqlserver
4
- module CoreExt
5
- module Relation
6
- private
7
-
8
- def tables_in_string(string)
9
- super - ['__rnt']
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
16
-
17
- ActiveRecord::Relation.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::Relation
@@ -1,17 +0,0 @@
1
- require 'active_record/test_case.rb'
2
-
3
- # TODO: I'm struggling to figure out how to unsubscribe from only one 'sql.active_record'
4
- # This is a temporary hack until we can just get the sqlserver_ignored regex in rails
5
- ActiveSupport::Notifications.notifier.listeners_for('sql.active_record').each do |listener|
6
- if listener.inspect =~ /ActiveRecord::SQLCounter/
7
- ActiveSupport::Notifications.unsubscribe(listener)
8
- end
9
- end
10
-
11
- module ActiveRecord
12
- class SQLCounter
13
- sqlserver_ignored = [/SELECT SCOPE_IDENTITY/, /INFORMATION_SCHEMA\.(TABLES|VIEWS|COLUMNS)/, /SELECT @@version/, /SELECT @@TRANCOUNT/, /(BEGIN|COMMIT|ROLLBACK|SAVE) TRANSACTION/]
14
- ignored_sql.concat sqlserver_ignored
15
- end
16
- ActiveSupport::Notifications.subscribe('sql.active_record', SQLCounter.new)
17
- end
@@ -1,14 +0,0 @@
1
- module Arel
2
- module Nodes
3
- # Extending the Ordering class to be comparison friendly which allows us to call #uniq on a
4
- # collection of them. See SelectManager#order for more details.
5
- class Ordering < Arel::Nodes::Unary
6
- def eql?(other)
7
- # Arel::Nodes::Ascending or Arel::Nodes::Desecnding
8
- other.is_a?(Arel::Nodes::Ordering) &&
9
- expr == other.expr
10
- end
11
- alias_method :==, :eql?
12
- end
13
- end
14
- end
@@ -1,62 +0,0 @@
1
- module Arel
2
- class SelectManager < Arel::TreeManager
3
- AR_CA_SQLSA_NAME = 'ActiveRecord::ConnectionAdapters::SQLServerAdapter'.freeze
4
-
5
- # Getting real Ordering objects is very important for us. We need to be able to call #uniq on
6
- # a colleciton of them reliably as well as using their true object attributes to mutate them
7
- # to grouping objects for the inner sql during a select statment with an offset/rownumber. So this
8
- # is here till ActiveRecord & ARel does this for us instead of using SqlLiteral objects.
9
- alias_method :order_without_sqlserver, :order
10
- def order(*expr)
11
- return order_without_sqlserver(*expr) unless engine_activerecord_sqlserver_adapter?
12
- @ast.orders.concat(expr.map do |x|
13
- case x
14
- when Arel::Attributes::Attribute
15
- table = Arel::Table.new(x.relation.table_alias || x.relation.name)
16
- e = table[x.name]
17
- Arel::Nodes::Ascending.new e
18
- when Arel::Nodes::Ordering
19
- x
20
- when String
21
- x.split(',').map do |s|
22
- s = x if x.strip =~ /\A\b\w+\b\(.*,.*\)(\s+(ASC|DESC))?\Z/i # Allow functions with comma(s) to pass thru.
23
- s.strip!
24
- d = s =~ /(ASC|DESC)\Z/i ? Regexp.last_match[1].upcase : nil
25
- e = d.nil? ? s : s.mb_chars[0...-d.length].strip
26
- e = Arel.sql(e)
27
- d && d == 'DESC' ? Arel::Nodes::Descending.new(e) : Arel::Nodes::Ascending.new(e)
28
- end
29
- else
30
- e = Arel.sql(x.to_s)
31
- Arel::Nodes::Ascending.new e
32
- end
33
- end.flatten)
34
- self
35
- end
36
-
37
- # A friendly over ride that allows us to put a special lock object that can have a default or pass
38
- # custom string hints down. See the visit_Arel_Nodes_LockWithSQLServer delegation method.
39
- alias_method :lock_without_sqlserver, :lock
40
- def lock(locking = true)
41
- if engine_activerecord_sqlserver_adapter?
42
- case locking
43
- when true
44
- locking = Arel.sql('WITH(HOLDLOCK, ROWLOCK)')
45
- when Arel::Nodes::SqlLiteral
46
- when String
47
- locking = Arel.sql locking
48
- end
49
- @ast.lock = Arel::Nodes::Lock.new(locking)
50
- self
51
- else
52
- lock_without_sqlserver(locking)
53
- end
54
- end
55
-
56
- private
57
-
58
- def engine_activerecord_sqlserver_adapter?
59
- @engine.connection && @engine.connection.class.name == AR_CA_SQLSA_NAME
60
- end
61
- end
62
- end