aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/sqlite3
Commit message (Collapse)AuthorAgeFilesLines
* Share the column and table name quote cache between connectionsJean Boussier2019-07-091-2/+2
|
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Allow column name with function (e.g. `length(title)`) as safe SQL stringRyuta Kamizono2019-06-101-2/+8
| | | | | | | | | | | | | | | | Currently, almost all "Dangerous query method" warnings are false alarm. As long as almost all the warnings are false alarm, developers think "Let's ignore the warnings by using `Arel.sql()`, it actually is false alarm in practice.", so I think we should effort to reduce false alarm in order to make the warnings valuable. This allows column name with function (e.g. `length(title)`) as safe SQL string, which is very common false alarm pattern, even in the our codebase. Related 6c82b6c99, 6607ecb2a, #36420. Fixes #32995.
* Allow `column_name AS alias` as safe SQL stringRyuta Kamizono2019-06-101-0/+1
|
* Refactor `disallow_raw_sql!` to avoid `split(/\s*,\s*/)` to order argsRyuta Kamizono2019-06-091-4/+13
| | | | | `split(/\s*,\s*/)` to order args and then `permit.match?` one by one is much slower than `permit.match?` once.
* Allow quoted identifier string as safe SQL stringRyuta Kamizono2019-06-061-0/+20
| | | | | | | | | | | | | Currently `posts.title` is regarded as a safe SQL string, but `"posts"."title"` (it is a result of `quote_table_name("posts.title")`) is regarded as an unsafe SQL string even though a result of `quote_table_name` should obviously be regarded as a safe SQL string, since the column name matcher doesn't respect quotation, it is a little annoying. This changes the column name matcher to allow quoted identifiers as safe SQL string, now all results of the `quote_table_name` are regarded as safe SQL string.
* Put all `explain` methods into `DatabaseStatements` moduleRyuta Kamizono2019-05-221-1/+5
| | | | | Almost all database statements methods except `explain` was moved into `DatabaseStatements` at #35922. This moves the last one method.
* Remove ignored_sql from SQLCounter by adding "TRANSACTION" to log nameYasuo Honda2019-05-081-3/+3
| | | | | | | | | | This commit adds "TRANSACTION" to savepoint and commit, rollback statements because none of savepoint statements were removed by #36153 since they are not "SCHEMA" statements. Although, only savepoint statements can be labeled as "TRANSACTION" I think all of transaction related method should add this label. Follow up #36153
* moves sqlite3 methods that mirror Abstract::DatabaseStatements into ↵Michael Glass2019-04-101-0/+80
| | | | Sqlite3::DatabaseStatements and make those that are private in Abstract::DatabaseStatements private for sqlite3
* Except `table_name` from column objectsRyuta Kamizono2019-04-081-1/+1
| | | | | | | | | The `table_name` was added at #23677 to detect whether serial column or not correctly. We can do that detection before initialize column object, it makes column object size smaller, and it probably helps column object de-duplication.
* Use `execute_batch2` rather than `execute_batch` to fix performance ↵Ryuta Kamizono2019-04-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | regression for fixture loading d8d6bd5 makes fixture loading to bulk statements by using `execute_batch` for sqlite3 adapter. But `execute_batch` is slower and it caused the performance regression for fixture loading. In sqlite3 1.4.0, it have new batch method `execute_batch2`. I've confirmed `execute_batch2` is extremely faster than `execute_batch`. So I think it is worth to upgrade sqlite3 to 1.4.0 to use that method. Before: ``` % ARCONN=sqlite3 bundle exec ruby -w -Itest test/cases/associations/eager_test.rb -n test_eager_loading_too_may_ids Using sqlite3 Run options: -n test_eager_loading_too_may_ids --seed 35790 # Running: . Finished in 202.437406s, 0.0049 runs/s, 0.0049 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips ARCONN=sqlite3 bundle exec ruby -w -Itest -n test_eager_loading_too_may_ids 142.57s user 60.83s system 98% cpu 3:27.08 total ``` After: ``` % ARCONN=sqlite3 bundle exec ruby -w -Itest test/cases/associations/eager_test.rb -n test_eager_loading_too_may_ids Using sqlite3 Run options: -n test_eager_loading_too_may_ids --seed 16649 # Running: . Finished in 8.471032s, 0.1180 runs/s, 0.1180 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips ARCONN=sqlite3 bundle exec ruby -w -Itest -n test_eager_loading_too_may_ids 10.71s user 1.36s system 95% cpu 12.672 total ```
* SQLite3: Make fixture loading to bulk statementsRyuta Kamizono2019-03-171-0/+7
|
* Make `truncate_tables` to bulk statementsRyuta Kamizono2019-03-171-0/+31
| | | | | | | | | | | | | | | | | | Before: ``` (16.4ms) TRUNCATE TABLE `author_addresses` (20.5ms) TRUNCATE TABLE `authors` (19.4ms) TRUNCATE TABLE `posts` ``` After: ``` Truncate Tables (19.5ms) TRUNCATE TABLE `author_addresses`; TRUNCATE TABLE `authors`; TRUNCATE TABLE `posts` ```
* Allow `remove_foreign_key` with both `to_table` and `options`Ryuta Kamizono2019-03-061-1/+1
| | | | | | | Foreign keys could be created to the same table. So `remove_foreign_key :from_table, :to_table` is sometimes ambiguous. This allows `remove_foreign_key` to remove the select one on the same table with giving both `to_table` and `options`.
* Refactor `remove_foreign_key` to delete the foreign key before `alter_table`Ryuta Kamizono2019-02-161-4/+2
|
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`Ryuta Kamizono2019-02-111-0/+28
| | | | | | | | | | | | I implemented Foreign key create in `create_table` for SQLite3 at #24743. This follows #24743 to implement `add_foreign_key` and `remove_foreign_key`. Unfortunately SQLite3 has one limitation that `PRAGMA foreign_key_list(table-name)` doesn't have constraint name. So we couldn't implement find/remove foreign key by name for now. Fixes #35207. Closes #31343.
* Make `t.timestamps` with precision by defaultRyuta Kamizono2019-01-261-1/+1
|
* Change `SQLite3Adapter` to always represent boolean values as integersRafael Mendonça França2019-01-171-4/+4
|
* Fix join table column quoting with SQLite.Gannon McGibbon2018-12-051-0/+4
|
* Use squiggly heredoc to strip odd indentation in the executed SQLRyuta Kamizono2018-11-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ``` LOG: execute <unnamed>: SELECT t.oid, t.typname FROM pg_type as t WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool') LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric') OR t.typtype IN ('r', 'e', 'd') OR t.typinput::varchar = 'array_in' OR t.typelem != 0 LOG: statement: SHOW TIME ZONE LOG: statement: SELECT 1 LOG: execute <unnamed>: SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND c.relname = 'accounts' AND n.nspname = ANY (current_schemas(false)) ``` After: ``` LOG: execute <unnamed>: SELECT t.oid, t.typname FROM pg_type as t WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool') LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric') OR t.typtype IN ('r', 'e', 'd') OR t.typinput::varchar = 'array_in' OR t.typelem != 0 LOG: statement: SHOW TIME ZONE LOG: statement: SELECT 1 LOG: execute <unnamed>: SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND c.relname = 'accounts' AND n.nspname = ANY (current_schemas(false)) ```
* Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-5/+5
| | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* SQLite3: Support multiple args function for expression indexesRyuta Kamizono2018-09-141-11/+12
| | | | | Follow up #33874. Related #23393.
* SQLite3 adapter supports expression indexesgkemmey2018-09-131-1/+5
|
* Normalize time value not to be affected by summer timeRyuta Kamizono2018-07-251-0/+1
| | | | Follow up of #33358 for SQLite3.
* SQLite: Don't leak internal schema objectsRyuta Kamizono2018-07-091-1/+5
| | | | | | | | | | | | | | Related #31201. If creating custom primary key (like a string) in SQLite, it would also create an internal index implicitly which named begin with "sqlite_". It need to be hidden since the internal object names are reserved and prohibited for public use. See https://www.sqlite.org/fileformat2.html#intschema Fixes #33320.
* Normalize date component when writing to time columnsAndrew White2018-03-111-1/+1
| | | | | | | | | | | | | | | For legacy reasons Rails stores time columns on sqlite as full timestamp strings. However because the date component wasn't being normalized this meant that when they were read back they were being prefixed with 2001-01-01 by ActiveModel::Type::Time. This had a twofold result - first it meant that the fast code path wasn't being used because the string was invalid and second it was corrupting the second fractional component being read by the Date._parse code path. Fix this by a combination of normalizing the timestamps on writing and also changing Active Model to be more lenient when detecting whether a string starts with a date component before creating the dummy time value for parsing.
* Avoid using index_xinfo, only available in sqlite >= 3.8.9Paul Kuruvilla2017-10-251-9/+12
|
* Save index order :desc to schema.rb (sqlite). Fixes #30902Paul Kuruvilla2017-10-241-2/+9
| | | | | Although the sqlite adapter supports index sort orders, they weren't being written to db/schema.rb.
* Remove deprecated argument `name` from `#indexes`Rafael Mendonça França2017-10-231-7/+1
|
* Extract `integer_like_primary_key_type` to ease to handle it for adaptersRyuta Kamizono2017-09-251-6/+3
|
* Move integer-like primary key normalization to `new_column_definition`Ryuta Kamizono2017-09-232-19/+7
| | | | | | Currently the normalization only exists in `primary_key` shorthand. It should be moved to `new_column_definition` to also affect to `add_column` with primary key.
* Refactor `SchemaDumper` to make it possible to adapter specific customizationRyuta Kamizono2017-08-222-2/+5
| | | | | | | Currently `SchemaDumper` is only customizable for column options. But 3rd party connection adapters (oracle-enhanced etc) need to customizable for table or index dumping also. To make it possible, I introduced adapter specific `SchemaDumper` classes for that.
* Place `update_table_definition` consistently in `SchemaStatements`Ryuta Kamizono2017-08-211-0/+4
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-196-0/+12
|
* Change sqlite3 boolean serialization to use 1 and 0Lisa Ugray2017-07-111-0/+16
| | | | | | | | | | | | | | | | | | | | Abstract boolean serialization has been using 't' and 'f', with MySQL overriding that to use 1 and 0. This has the advantage that SQLite natively recognizes 1 and 0 as true and false, but does not natively recognize 't' and 'f'. This change in serialization requires a migration of stored boolean data for SQLite databases, so it's implemented behind a configuration flag whose default false value is deprecated. The flag itself can be deprecated in a future version of Rails. While loaded models will give the correct result for boolean columns without migrating old data, where() clauses will interact incorrectly with old data. While working in this area, also change the abstract adapter to use `"TRUE"` and `"FALSE"` as quoted values and `true` and `false` for unquoted. These are supported by PostreSQL, and MySQL remains overriden.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-026-6/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-026-0/+6
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-016-0/+6
| |
* | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-021-1/+1
|\ \ | | | | | | | | | Make ActiveSupport frozen-string-literal friendly.
| * | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-1/+1
| |/
* / Don't cache queries for schema statementsRyuta Kamizono2017-06-301-1/+1
|/ | | | | | `test_middleware_caches` is sometimes failed since #29454. The failure is due to schema statements are affected by query caching. Bypassing query caching for schema statements to avoid the issue.
* Refactor `indexes` things in connection adaptersRyuta Kamizono2017-04-161-0/+35
| | | | | | | * Use keyword arguments in `IndexDefinition` to ease to ignore unused options and to avoid to initialize incorrect empty value. * Place it in `SchemaStatements` for consistency. * And tiny tweaks.
* Make internal methods to privateRyuta Kamizono2017-03-271-0/+25
|
* Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-0/+32
|
* Merge pull request #26630 from kamipo/quoted_binaryRafael França2017-02-131-8/+4
|\ | | | | Extract `quoted_binary` and use it rather than override `_quote`
| * Extract `quoted_binary` and use it rather than override `_quote`Ryuta Kamizono2016-09-271-8/+4
| | | | | | | | | | | | | | Each databases have different binary representation. Therefore all adapters overrides `_quote` for quoting binary. Extract `quoted_binary` for quoting binary and use it rather than override `_quote`.
* | Refactor `ColumnDefinition` to contain `options` hashRyuta Kamizono2017-02-091-8/+1
| | | | | | | | | | | | Column options are passed as an hash args then used as `options` hash in `add_column_options!`. Converting args to attributes is inconvinient for using options as an hash.
* | `primary_key` and `references` columns should be identical typeRyuta Kamizono2017-02-071-0/+5
| | | | | | | | | | | | | | | | Follow up to #26266. The default type of `primary_key` and `references` were changed to `bigint` since #26266. But legacy migration and sqlite3 adapter should keep its previous behavior.
* | Correctly dump integer-like primary key with default nilRyuta Kamizono2017-02-041-1/+5
| | | | | | | | | | | | | | The PR #27384 changed integer-like primary key to be autoincrement unless an explicit default. This means that integer-like primary key is restored as autoincrement unless dumping the default nil explicitly. We should dump integer-like primary key with default nil correctly.