aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* Clarify 'database does not exist' message and implementation.Jeremy Kemper2014-04-011-2/+2
| | | | | | | | | | | * Clarify what the situation is and what to do. * Advise loading schema using `rake db:setup` instead of migrating. * Use a rescue in the initializer rather than extending the error message in-place. * Preserve the original backtrace of other errors by using `raise` rather than raising again with `raise error`. References 0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763
* Fix regression on `.select_*` methods.Arthur Neves2014-01-301-2/+2
| | | | | | | | | | | | | | | | | | This was a common pattern: ``` query = author.posts.select(:title) connection.select_one(query) ``` However `.select` returns a ActiveRecord::AssociationRelation, which has the bind information, so we can use that to get the right sql query. Also fix select_rows on postgress and sqlite3 that were not using the binds [fixes #7538] [fixes #12017] [related #13731] [related #12056]
* Raise NoDatabaseError when db does not existschneems2013-12-241-0/+6
| | | Building on the work of #13427 this PR adds a helpful error message to the adapters: mysql, mysql2, and sqlite3
* Fix mysql to support duplicated column namesKassio Borges2013-12-131-3/+8
| | | | | | | | | | This will fix the [broken test](https://github.com/rails/rails/commit/4a2650836680f51490e999c3c8441a2f9adff96e) `test_with_limiting_with_custom_select`. The query's result was built in a hash with column name as key, if the result have a duplicated column name the last value was overriding the first one.
* Merge pull request #12779 from ↵Aaron Patterson2013-11-151-2/+0
|\ | | | | | | | | dougbarth/dont_swallow_exceptions_during_transactional_statements_in_mysql Don't swallow exceptions in transctional statements
| * Don't swallow exceptions in transctional statementsDoug Barth2013-11-051-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Unifies mysql and mysql2 casting of booleans.Yves Senn2013-11-111-6/+0
| |
* | Don't use Active Support where we don't need toRafael Mendonça França2013-11-091-1/+1
| |
* | log bind variables after they were type casted.Yves Senn2013-11-091-2/+6
|/ | | | | | | | | | | | | | | The log output used to be confusing in situation where type casting has "unexpected" effects. For example when finding records with a `String`. BEFORE: irb(main):002:0> Event.find("im-no-integer") D, [2013-11-09T11:10:28.998857 #1706] DEBUG -- : Event Load (4.5ms) SELECT "events".* FROM "events" WHERE "events"."id" = $1 LIMIT 1 [["id", "im-no-integer"]] AFTER: irb(main):002:0> Event.find("im-no-integer") D, [2013-11-09T11:10:28.998857 #1706] DEBUG -- : Event Load (4.5ms) SELECT "events".* FROM "events" WHERE "events"."id" = $1 LIMIT 1 [["id", 0]]
* fix code typo in `MysqlAdapter` .Closes #12647.Yves Senn2013-10-301-1/+1
|
* Remove invalid commentRafael Mendonça França2013-09-111-4/+0
| | | | This is not valid anymore after 08477a651648ba4417ded128aa37b9ae0dcbc9ce
* Check if the SQL is not a prepared statementRafael Mendonça França2013-09-111-1/+1
| | | | | | | | | When the adapter is with prepared statement disabled and the binds array is not empty the connection adapter will try to set the binds values and will fail. Now we are checking if the adapter has the prepared statement disabled. Fixes #12023
* chmod -xAkira Matsuda2013-08-121-0/+0
|
* Set field encoding to client_encoding for mysql adapter.Koichi Sasada2013-08-081-0/+8
|
* Free result_metadata directly instead of freeing 2nd, redundant call.Peter Kovacs2013-08-051-1/+1
| | | `result_metadata` returns a new object each time it is called, so calling `result_metadata.free` is essentially a noop. Instead call `free` directly on the metadata when we're done with it.
* Revert "Merge pull request #11120 from awilliams/ar_mysql2_boolean_quoting"Yves Senn2013-07-171-0/+6
| | | | | This reverts commit cb1d07e43926bcec95cb8b4a663ca9889173395a, reversing changes made to 754a373e301d2df0b12a11083405252722bc8366.
* Unifies mysql and mysql2 casting of booleansawilliams2013-07-161-6/+0
| | | | | Using the mysql2 adapter, boolean values were sometimes being incorrectly cast to 't' or 'f'. This changes the cast to match the mysql adapter behavior, ie 1 and 0.
* tiny types should only be integers when the length is <= 1. fixes #10620Aaron Patterson2013-05-151-3/+9
|
* fix typosVipul A M2013-04-211-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-03-301-2/+2
|\ | | | | | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/adapter_test.rb guides/source/testing.md [ci skip]
| * nodoc AR::ConnectionHandling for adapters [ci skip]Francesco Rodriguez2013-03-151-2/+2
| |
* | respect auto_increment in rename_column for mysqlVipul A M2013-03-271-2/+2
|/
* Do not type cast all the database url values.Rafael Mendonça França2013-02-241-1/+1
| | | | | | We should only type cast when we need to use. Related to 4b005fb371c2e7af80df7da63be94509b1db038c
* Session variables for mysql, mysql2, and postgresql adapters can be setAaron Stone2012-12-081-12/+5
| | | | | | | | | in the new 'variables:' hash in each database config section in database.yml. The key-value pairs of this hash will be sent in a 'SET key = value, ...' query on new database connections. The configure_connection methods from mysql and mysql2 into are consolidated into the abstract_mysql base class.
* Be a bit less conservative with mysql in adapterCarlos Antonio da Silva2012-11-191-1/+1
|
* Bump mysql gem version to the newly 2.9.0, fix build.Carlos Antonio da Silva2012-11-171-1/+1
|
* The default value of a text/blob in mysql strict mode should be nilJon Leighton2012-10-191-4/+2
| | | | | | | | | In non-strict mode it is '', but if someone is in strict mode then we should honour the strict semantics. Also, this removes the need for a completely horrible hack in dirty.rb. Closes #7780
* Ensure disconnecting or reconnecting resets the transaction stateJon Leighton2012-09-151-1/+2
|
* Remove expired comment. This method is used from other place.kennyj2012-09-111-2/+0
|
* Refactor AR::Result or inherits. Because we have redundant codes aboutkennyj2012-08-221-8/+1
|
* teaching the mysql adapter how to typecast strings returned from the databaseAaron Patterson2012-07-131-2/+132
|
* Fixing texts; down to three failing tests.Jeremy Cole2012-07-131-14/+23
| | | | | Conflicts: activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
* Only use prepared statements when bind variables are presentJeremy Cole2012-07-131-34/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prepared statements (prepare/execute/close) were being used unnecessarily when no bind variables were present, and disabling prepared statement using prepared_statements:false was principally broken. While bind variables were correctly substituted with prepared_statements:false, the prepared statement interface was still used, costing an extra two round trips per query. In addition to making this behavioral change, I also cleaned up the internals of exec_stmt and exec_without_stmt so that they behave the same (calling log and constructing the ActiveRecord::Result in the same way). Moving the check for binds.empty? to exec_query also will mean that several code paths explicitly calling exec_without_stmt could be cleaned up to once again call exec_query instead. I have also left the check for binds.empty? in exec_stmt, since it is not a private method and could be called directly with an empty binds array. For the sake of clarity in this patch, I have not made those changes. = The previous behavior = When issuing a Foo.find(1) with prepared_statements:true, the bind variable is present in the prepared query, and execute shows a value passed: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Prepare SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = ? LIMIT 1 Execute SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Close stmt Quit When issuing a Foo.find(1) with prepared_statements:false, the bind variable has already been removed and substituted with the value, but the prepared statement interface is used anyway: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Prepare SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Execute SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Close stmt Quit = With this patch applied = When issuing a Foo.find(1) with prepared_statements:true, the bind variable is present in the prepared query, and execute shows a value passed: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Prepare SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = ? LIMIT 1 Execute SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Close stmt Quit When issuing a Foo.find(1) with prepared_statements:false, the bind variable has been removed and substituted with the value, and the query interface is used instead of the prepared statement interface: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Query SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Quit
* Add config option, rdoc, tests for mysql(2) STRICT_ALL_TABLES mode.Michael Pearson2012-05-051-2/+5
|
* Default to 'strict mode' in MySQLMichael Pearson2012-05-051-0/+5
|
* use Process.pid rather than $$Aaron Patterson2012-02-161-1/+1
|
* made the result set object act more like an arrayAaron Patterson2012-01-311-1/+1
|
* Support establishing connection on ActiveRecord::Model.Jon Leighton2011-12-281-1/+1
| | | | | This is the 'top level' connection, inherited by any models that include ActiveRecord::Model or inherit from ActiveRecord::Base.
* remove checks for encodings availabilitySergey Nartimov2011-12-251-46/+42
|
* I herd you like modules.Jon Leighton2011-12-241-2/+2
|
* Only use LOWER for mysql case insensitive uniqueness check when column has a ↵Joseph Palermo2011-10-091-2/+2
| | | | case sensitive collation.
* LRU cache in mysql and sqlite are now per-process caches.Aaron Patterson2011-09-071-11/+16
|
* Database adapters use a statement pool.Aaron Patterson2011-09-061-1/+2
| | | | | | Database adapters use a statement pool for limiting the number of open prepared statments on the database. The limit defaults to 1000, but can be adjusted in your database config by changing 'statement_limit'.
* adding a statement pool for mysql and sqlite3Aaron Patterson2011-09-061-4/+29
|
* Move the bulk alter table code into the abstract mysql adapter, hence it is ↵Jon Leighton2011-08-291-47/+0
| | | | supported for mysql2 as well now.
* Extract simplified_type into the abstract classJon Leighton2011-08-291-7/+3
|
* Create an AbstractMysqlAdapter to abstract the common code between ↵Jon Leighton2011-08-291-569/+98
| | | | MysqlAdapter and Mysql2Adapter.
* prevent sql injection attacks by escaping quotes in column namesAaron Patterson2011-08-161-1/+1
|
* Use new SelectManager#source methodJon Leighton2011-08-151-1/+1
|
* Use new SelectManager#projections= methodJon Leighton2011-08-151-1/+1
|