Class Index [+]

Quicksearch

Sequel::SQLite::DatasetMethods

Instance methods for datasets that connect to an SQLite database

Constants

SELECT_CLAUSE_METHODS
CONSTANT_MAP
EXTRACT_MAP
NOT_SPACE
COMMA
PAREN_CLOSE
AS
APOS
EXTRACT_OPEN
EXTRACT_CLOSE
NUMERIC
INTEGER
BACKTICK
BACKTICK_RE
DOUBLE_BACKTICK
BLOB_START
HSTAR

Public Instance Methods

complex_expression_sql_append(sql, op, args) click to toggle source

SQLite does not support pattern matching via regular expressions. SQLite is case insensitive (depending on pragma), so use LIKE for ILIKE.

     # File lib/sequel/adapters/shared/sqlite.rb, line 435
435:       def complex_expression_sql_append(sql, op, args)
436:         case op
437:         when :~, :'!~', :'~*', :'!~*'
438:           raise Error, "SQLite does not support pattern matching via regular expressions"
439:         when :ILIKE
440:           super(sql, :LIKE, args.map{|a| SQL::Function.new(:upper, a)})
441:         when :"NOT LIKE", :"NOT ILIKE"
442:           sql << NOT_SPACE
443:           complex_expression_sql_append(sql, (op == :"NOT ILIKE" ? :ILIKE : :LIKE), args)
444:         when :^
445:           sql << complex_expression_arg_pairs(args) do |a, b|
446:             a = literal(a)
447:             b = literal(b)
448:             "((~(#{a} & #{b})) & (#{a} | #{b}))"
449:           end
450:         when :extract
451:           part = args.at(0)
452:           raise(Sequel::Error, "unsupported extract argument: #{part.inspect}") unless format = EXTRACT_MAP[part]
453:           sql << EXTRACT_OPEN << format << COMMA
454:           literal_append(sql, args.at(1))
455:           sql << EXTRACT_CLOSE << (part == :second ? NUMERIC : INTEGER) << PAREN_CLOSE
456:         else
457:           super
458:         end
459:       end
constant_sql_append(sql, constant) click to toggle source

SQLite has CURRENT_TIMESTAMP and related constants in UTC instead of in localtime, so convert those constants to local time.

     # File lib/sequel/adapters/shared/sqlite.rb, line 463
463:       def constant_sql_append(sql, constant)
464:         if c = CONSTANT_MAP[constant]
465:           sql << c
466:         else
467:           super
468:         end
469:       end
delete() click to toggle source

SQLite performs a TRUNCATE style DELETE if no filter is specified. Since we want to always return the count of records, add a condition that is always true and then delete.

     # File lib/sequel/adapters/shared/sqlite.rb, line 474
474:       def delete
475:         @opts[:where] ? super : where(1=>1).delete
476:       end
explain(opts=nil) click to toggle source

Return an array of strings specifying a query explanation for a SELECT of the current dataset. Currently, the options are ignore, but it accepts options to be compatible with other adapters.

     # File lib/sequel/adapters/shared/sqlite.rb, line 481
481:       def explain(opts=nil)
482:         # Load the PrettyTable class, needed for explain output
483:         Sequel.extension(:_pretty_table) unless defined?(Sequel::PrettyTable)
484: 
485:         ds = db.send(:metadata_dataset).clone(:sql=>"EXPLAIN #{select_sql}")
486:         rows = ds.all
487:         Sequel::PrettyTable.string(rows, ds.columns)
488:       end
having(*cond) click to toggle source

HAVING requires GROUP BY on SQLite

     # File lib/sequel/adapters/shared/sqlite.rb, line 491
491:       def having(*cond)
492:         raise(InvalidOperation, "Can only specify a HAVING clause on a grouped dataset") unless @opts[:group]
493:         super
494:       end
quoted_identifier_append(sql, c) click to toggle source

SQLite uses the nonstandard ` (backtick) for quoting identifiers.

     # File lib/sequel/adapters/shared/sqlite.rb, line 497
497:       def quoted_identifier_append(sql, c)
498:         sql << BACKTICK << c.to_s.gsub(BACKTICK_RE, DOUBLE_BACKTICK) << BACKTICK
499:       end
select(*cols) click to toggle source

When a qualified column is selected on SQLite and the qualifier is a subselect, the column name used is the full qualified name (including the qualifier) instead of just the column name. To get correct column names, you must use an alias.

     # File lib/sequel/adapters/shared/sqlite.rb, line 505
505:       def select(*cols)
506:         if ((f = @opts[:from]) && f.any?{|t| t.is_a?(Dataset) || (t.is_a?(SQL::AliasedExpression) && t.expression.is_a?(Dataset))}) || ((j = @opts[:join]) && j.any?{|t| t.table.is_a?(Dataset)})
507:           super(*cols.map{|c| alias_qualified_column(c)})
508:         else
509:           super
510:         end
511:       end
supports_intersect_except_all?() click to toggle source

SQLite does not support INTERSECT ALL or EXCEPT ALL

     # File lib/sequel/adapters/shared/sqlite.rb, line 514
514:       def supports_intersect_except_all?
515:         false
516:       end
supports_is_true?() click to toggle source

SQLite does not support IS TRUE

     # File lib/sequel/adapters/shared/sqlite.rb, line 519
519:       def supports_is_true?
520:         false
521:       end
supports_multiple_column_in?() click to toggle source

SQLite does not support multiple columns for the IN/NOT IN operators

     # File lib/sequel/adapters/shared/sqlite.rb, line 524
524:       def supports_multiple_column_in?
525:         false
526:       end
supports_timestamp_timezones?() click to toggle source

SQLite supports timezones in literal timestamps, since it stores them as text. But using timezones in timestamps breaks SQLite datetime functions, so we allow the user to override the default per database.

     # File lib/sequel/adapters/shared/sqlite.rb, line 531
531:       def supports_timestamp_timezones?
532:         db.use_timestamp_timezones?
533:       end
supports_where_true?() click to toggle source

SQLite cannot use WHERE ‘t’.

     # File lib/sequel/adapters/shared/sqlite.rb, line 536
536:       def supports_where_true?
537:         false
538:       end

Private Instance Methods

_truncate_sql(table) click to toggle source

SQLite treats a DELETE with no WHERE clause as a TRUNCATE

     # File lib/sequel/adapters/shared/sqlite.rb, line 597
597:       def _truncate_sql(table)
598:         "DELETE FROM #{table}"
599:       end
alias_qualified_column(col) click to toggle source

If col is a qualified column, alias it to the same as the column name

     # File lib/sequel/adapters/shared/sqlite.rb, line 550
550:       def alias_qualified_column(col)
551:         case col
552:         when Symbol
553:           t, c, a = split_symbol(col)
554:           if t && !a
555:             alias_qualified_column(SQL::QualifiedIdentifier.new(t, c))
556:           else
557:             col
558:           end
559:         when SQL::QualifiedIdentifier
560:           SQL::AliasedExpression.new(col, col.column)
561:         else
562:           col
563:         end
564:       end
as_sql_append(sql, aliaz) click to toggle source

SQLite uses string literals instead of identifiers in AS clauses.

     # File lib/sequel/adapters/shared/sqlite.rb, line 543
543:       def as_sql_append(sql, aliaz)
544:         aliaz = aliaz.value if aliaz.is_a?(SQL::Identifier)
545:         sql << AS
546:         literal_append(sql, aliaz.to_s)
547:       end
identifier_list(columns) click to toggle source

SQL fragment specifying a list of identifiers

     # File lib/sequel/adapters/shared/sqlite.rb, line 567
567:       def identifier_list(columns)
568:         columns.map{|i| quote_identifier(i)}.join(COMMA)
569:       end
literal_blob_append(sql, v) click to toggle source

SQLite uses a preceding X for hex escaping strings

     # File lib/sequel/adapters/shared/sqlite.rb, line 572
572:       def literal_blob_append(sql, v)
573:         sql << BLOB_START << v.unpack(HSTAR).first << APOS
574:       end
literal_false() click to toggle source

Respect the database integer_booleans setting, using 0 or ‘f’.

     # File lib/sequel/adapters/shared/sqlite.rb, line 577
577:       def literal_false
578:         @db.integer_booleans ? '0' : "'f'"
579:       end
literal_true() click to toggle source

Respect the database integer_booleans setting, using 1 or ‘t’.

     # File lib/sequel/adapters/shared/sqlite.rb, line 582
582:       def literal_true
583:         @db.integer_booleans ? '1' : "'t'"
584:       end
select_clause_methods() click to toggle source

SQLite does not support the SQL WITH clause

     # File lib/sequel/adapters/shared/sqlite.rb, line 587
587:       def select_clause_methods
588:         SELECT_CLAUSE_METHODS
589:       end
select_lock_sql(sql) click to toggle source

Support FOR SHARE locking when using the :share lock style.

     # File lib/sequel/adapters/shared/sqlite.rb, line 592
592:       def select_lock_sql(sql)
593:         super unless @opts[:lock] == :update
594:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.