Commit Graph

337 Commits

Author SHA1 Message Date
Tadas Tamosauskas
73bba4c1e1 Serialize postgres' hstore, json and array types correctly in AR update methods.
Fixes #12261. Closes #12395.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/adapters/postgresql/array_test.rb
	activerecord/test/cases/adapters/postgresql/json_test.rb
2013-12-23 16:27:54 -02:00
Carlos Antonio da Silva
56510091fb Do not consider PG array columns as number or text columns
The code uses these checks in several places to know what to do with a
particular column, for instance AR attribute query methods has a branch
like this:

    if column.number?
      !value.zero?
    end

This should never be true for array columns, since it would be the same
as running [].zero?, which results in a NoMethodError exception.

Fixing this by ensuring that array columns in PostgreSQL never return
true for number?/text? checks.

Since most of the array support was based on the postgres_ext lib, it's
worth noting it does the same thing for numeric array columns too:

https://github.com/dockyard/postgres_ext/blob/v1.0.0/lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb#L72

This extended the same logic for text columns to ensure consistency.
2013-12-23 16:26:15 -02:00
schneems
0ec45cd15d Tell how to Create a Database in Error Message
Currently if you attempt to use a database that does not exist  you get an error:

```
PG::ConnectionBad FATAL:  database "db_error" does not exist
```

The solution is easy, create and migrate your database however new developers may not know these commands by memory. Instead of requiring the developer to search for a solution, tell them how to fix the problem in the error message:

```
ActiveRecord::NoDatabase: FATAL:  database "db_error" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
```

Active Record should not know about `rake db:migrate` so this additional information needs to come from the railtie. Potential alternative implementation suggestions are welcome.
2013-12-23 10:23:48 -05:00
Damien Mathieu
1f6a9b50ee fix quoting non-strings
Closes #13444
2013-12-22 17:00:50 +01:00
Aaron Patterson
fbb79b517f fix url connections for sqlite3 2013-12-20 16:13:34 -08:00
Arthur Neves
4a720a2cde quoting: Check if id is a valid method before using it
Need to check if valud also respond_to :id before calling it, otherwise
things could explode.
2013-12-19 16:51:28 -05:00
Carlos Antonio da Silva
e4cde5d58c Fix indent in PG array tests
[ci skip]
2013-12-19 19:14:23 -02:00
Carlos Antonio da Silva
cc1f0b4c2d Merge pull request #13395 from kuldeepaggarwal/postgres-table-ref-regex
modified regex for finding table_name from a multiline sql query in postgresql
2013-12-19 05:22:28 -08:00
Kuldeep Aggarwal
b082bece5e Fix PostgreSQL insert to properly extract table name from multiline string SQL.
Previously, executing an insert SQL in PostgreSQL with a command like this:

    insert into articles(
      number)
    values(
      5152
    )

would not work because the adapter was unable to extract the correct articles table name.
2013-12-19 18:46:17 +05:30
Matthew Draper
f8b4110f00 Fix PostgreSQL range tests
The changes in c4044b2 meant the tests would error on a fresh DB.
2013-12-19 13:34:46 +10:30
Cody Cutrer
75a2e4a8df support creating temporary tables from queries
also override drop_table in AbstractMySQLAdapter to properly drop
temporary tables without committing the transaction
2013-12-14 07:07:10 -07:00
Yves Senn
63f9a7507b refactor, reuse assertions in range_test.rb. 2013-12-13 14:28:13 +01:00
Yves Senn
c4044b2f8a extract PG range tests from datatype_test.rb into range_test.rb 2013-12-13 14:17:21 +01:00
Carlos Antonio da Silva
7cf9a43268 Fix warnings on mysql2 explain test 2013-12-10 08:06:48 -02:00
Jeremy Kemper
2fd067c33b Merge pull request #13248 from yahonda/support_mysql573_explain
Support MySQL 5.7 explain
2013-12-09 23:22:32 -08:00
Yasuo Honda
b6655885ef Remove DEFAULT NULL for primary key column to support MySQL 5.7.3
Since MySQL 5.7.3 m13 does now allow primary key column is null.
2013-12-10 11:12:33 +09:00
Yasuo Honda
75f453ff4c Support MySQL 5.7 explain 2013-12-10 11:04:09 +09:00
Yves Senn
83d643407e Merge pull request #13054 from senny/remove_oracle_tests
Remove leftover Oracle tests.
2013-11-27 14:41:44 -08:00
Yves Senn
951c9ed31d the oracle adapter lives in a gem. Tests should live there as well. 2013-11-26 15:57:33 +01:00
Yves Senn
e161aeab17 remove leftover firebird adapter tests. 2013-11-26 11:05:37 +01:00
Yves Senn
6eba8d27e6 rename_index: add the new index before removing the old one.
This prevents the following error when a MySQL index on a foreign key
column is renamed:

```
ActiveRecord::StatementInvalid: Mysql2::Error: Cannot drop index 'index_engines_on_car_id': needed in a foreign key constraint: DROP INDEX `index_engines_on_car_id` ON `engines`
```

refs: #13038.
2013-11-26 10:03:55 +01:00
Aaron Patterson
314e2cc05b Merge pull request #12779 from dougbarth/dont_swallow_exceptions_during_transactional_statements_in_mysql
Don't swallow exceptions in transctional statements
2013-11-15 11:29:12 -08:00
Doug Barth
2b0406cedb Remove tests for not swallowing exceptions.
From PR, @tenderlove would prefer to not maintain these tests.
2013-11-15 10:29:30 -08:00
Yves Senn
07ae1e9b55 Unifies mysql and mysql2 casting of booleans. 2013-11-11 16:15:00 +01:00
Yves Senn
07790d5832 test cases to describe the MySQL boolean behavior. 2013-11-11 16:09:02 +01:00
Rafael Mendonça França
bd09afb5fb Don't skip tests if we don't need to.
We can conditional define the tests depending on the adapter or
connection.

Lets keep the skip for fail tests that need to be fixed.
2013-11-08 13:59:07 -02:00
Rashmi Yadav
90377f9674 Warning removed for ruby-head 2013-11-07 22:04:17 +01:00
Doug Barth
5d870c9291 Don't swallow exceptions in transctional statements
The MySQL connection adapater swallows all StandardError exceptions,
which includes Mysql::Error and Mysql2::Error. The comment in the
exception clause claims errors thrown here indicate that transactions
aren't supported by the server but that isn't necessarily true. It's
possible the MySQL server has gone away and swallowing a failed commit
may let the application return a successful response when the data has
not been saved. Also, replication libraries like Galera require that the
application handle exceptions thrown at BEGIN/COMMIT.

I'm unable to determine what version of MySQL threw an exception for
transactional statements. I tried as far back as 3.23.49 with InnoDB
disabled but BEGIN & COMMIT statements do not throw an error. If there's
a real case for this logic to continue, we could instead push this
behavior into a configuration setting.

The exception swallowing has been there since the beginning:
db045dbbf60b53dbe013ef25554fd013baf88134
2013-11-05 11:47:08 -08:00
Jan Bernacki
510601ce8e short arrays in inspect 2013-10-30 08:47:54 +04:00
Yves Senn
dc8fac1cac Merge pull request #12643 from severin/pg_cast_json_on_write
cast json values on write to be consistent with reading from the db.
2013-10-25 08:17:40 -07:00
Severin Schoepke
c3606afb2a cast json values on write to be consistent with reading from the db.
See also commit 5ac2341fab689344991b2a4817bd2bc8b3edac9d
2013-10-25 17:05:42 +02:00
Yves Senn
2dc579baf4 Merge pull request #12633 from senny/no_more_time_zone_leaks
prevent global timezone state from leaking out of test cases.
2013-10-25 06:10:11 -07:00
Yves Senn
abe91cb3bf prevent global timezone state from leaking out of test cases. 2013-10-25 14:40:57 +02:00
Yves Senn
0492ea6d39 ActiveRecord::Store works together with PG hstore columns.
This is necessary because as of 5ac2341 `hstore` columns are always stored
as `Hash` with `String` keys. `ActiveRecord::Store` expected the attribute to
be an instance of `HashWithIndifferentAccess`, which led to the bug.
2013-10-25 08:35:35 +02:00
Yves Senn
557b8b6947 test to verify the ActiveRecord::Store behavior with PG's json type 2013-10-25 08:34:59 +02:00
Rafael Mendonça França
9541a72858 Dump the default function when the primary key is uuid
Fixes #12489
2013-10-14 01:46:35 -03:00
Aaron Patterson
2ae9166d8f log the statement name along with the SQL 2013-10-04 16:51:35 -07:00
Aaron Patterson
46c57ec4d9 stop adding singleton methods to the SQLite3 connection 2013-10-04 15:18:53 -07:00
Aaron Patterson
6828ae7779 stop adding singleton methods to the mysql2 adapter 2013-10-04 15:16:49 -07:00
Aaron Patterson
cc04a4a903 stop adding singleton methods to the PG connection 2013-10-04 15:13:14 -07:00
Rafael Mendonça França
9f1b43b924 Merge pull request #12315 from gaurish/super
TypeError: superclass mismatch for class PostgreSQLAdapter
2013-09-23 11:08:10 -07:00
Gaurish Sharma
2a6cb8ab2e We shouldn't override PostgreSQLAdapter's superclass inheritance while monkeypatching
Changing Inheritance section leads to following error on JRuby

    TypeError: superclass mismatch for class PostgreSQLAdapter

After this change,
Jruby: The above error no longer appear. Tests are still failing but they do run. Progress!
MRI: No change, all green(tested by running take test_test_postgresql)

Thanks to Aditya Sanghi(@asanghi) for help
2013-09-23 21:33:20 +05:30
Rafael Mendonça França
afcca464db Merge pull request #11382 from kennyj/fix_10751-2
Dump UUID default functions to schema.rb [2nd version]. Fixes #10751.

Conflicts:
	activerecord/CHANGELOG.md
2013-09-22 16:01:01 -03:00
Rafael Mendonça França
7f2e64520f Merge pull request #10500 from kennyj/fix_10450
Fixed a bug in  when using has_many association with :inverse_of option and UUID primary key.

Conflicts:
	activerecord/CHANGELOG.md
2013-09-22 14:38:39 -03:00
Ben Cherry
5f631d63ae Test that PostgreSQL adapter includes usec when quoting DateTime 2013-08-28 18:23:59 -07:00
Yves Senn
27dc4fa28e PG adapter deals with negative money values formatted with parenthesis.
Closes #11899.
2013-08-26 11:14:56 +02:00
Ben Woosley
f87d8c7146 Stop interpreting SQL 'string' columns as :string type.
SQL doesn't have a string type, and interpreting 'string' as text is
contrary to at least SQLite3's behavior:

"Note that a declared type of 'STRING' has an affinity of NUMERIC, not TEXT."
http://www.sqlite.org/datatype3.html
2013-08-17 07:27:18 -07:00
Yves Senn
a4d4af4083 Merge pull request #11574 from jetthoughts/11552_rescue_on_invalid_inet_assign
Fix assign ip address with invalid values raise exception
2013-08-14 11:27:40 -07:00
Paul Nikitochkin
0aa95a71b0 Rescue invalid ip address exceptions on assign.
In order that set attribute should not be bang method
2013-08-14 21:04:31 +03:00
Paul Nikitochkin
f55504a1c9 Removed redundant asserts for assigns attribute operation 2013-08-14 19:29:47 +03:00