sequel 2.12.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +62 -0
- data/README.rdoc +3 -3
- data/Rakefile +7 -0
- data/doc/advanced_associations.rdoc +44 -0
- data/doc/release_notes/3.0.0.txt +221 -0
- data/lib/sequel/adapters/amalgalite.rb +208 -0
- data/lib/sequel/adapters/db2.rb +3 -0
- data/lib/sequel/adapters/dbi.rb +9 -0
- data/lib/sequel/adapters/do.rb +0 -4
- data/lib/sequel/adapters/firebird.rb +16 -18
- data/lib/sequel/adapters/informix.rb +5 -3
- data/lib/sequel/adapters/jdbc.rb +24 -20
- data/lib/sequel/adapters/jdbc/h2.rb +15 -4
- data/lib/sequel/adapters/mysql.rb +4 -8
- data/lib/sequel/adapters/odbc.rb +0 -4
- data/lib/sequel/adapters/oracle.rb +0 -4
- data/lib/sequel/adapters/shared/mssql.rb +16 -5
- data/lib/sequel/adapters/shared/mysql.rb +87 -86
- data/lib/sequel/adapters/shared/oracle.rb +92 -3
- data/lib/sequel/adapters/shared/postgres.rb +85 -29
- data/lib/sequel/adapters/shared/progress.rb +8 -3
- data/lib/sequel/adapters/shared/sqlite.rb +53 -23
- data/lib/sequel/adapters/sqlite.rb +4 -7
- data/lib/sequel/adapters/utils/unsupported.rb +3 -3
- data/lib/sequel/connection_pool.rb +18 -25
- data/lib/sequel/core.rb +2 -21
- data/lib/sequel/database.rb +60 -44
- data/lib/sequel/database/schema_generator.rb +26 -31
- data/lib/sequel/database/schema_methods.rb +8 -3
- data/lib/sequel/database/schema_sql.rb +114 -28
- data/lib/sequel/dataset.rb +14 -41
- data/lib/sequel/dataset/convenience.rb +31 -54
- data/lib/sequel/dataset/graph.rb +7 -13
- data/lib/sequel/dataset/sql.rb +43 -54
- data/lib/sequel/extensions/inflector.rb +0 -5
- data/lib/sequel/extensions/schema_dumper.rb +238 -0
- data/lib/sequel/metaprogramming.rb +0 -20
- data/lib/sequel/model.rb +1 -2
- data/lib/sequel/model/base.rb +18 -16
- data/lib/sequel/model/inflections.rb +6 -9
- data/lib/sequel/plugins/caching.rb +0 -6
- data/lib/sequel/plugins/hook_class_methods.rb +1 -1
- data/lib/sequel/sql.rb +2 -0
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/firebird_spec.rb +35 -8
- data/spec/adapters/mysql_spec.rb +173 -266
- data/spec/adapters/oracle_spec.rb +13 -0
- data/spec/adapters/postgres_spec.rb +127 -227
- data/spec/adapters/sqlite_spec.rb +13 -171
- data/spec/core/connection_pool_spec.rb +15 -4
- data/spec/core/core_sql_spec.rb +14 -170
- data/spec/core/database_spec.rb +50 -132
- data/spec/core/dataset_spec.rb +47 -930
- data/spec/core/expression_filters_spec.rb +12 -0
- data/spec/core/schema_generator_spec.rb +37 -45
- data/spec/core/schema_spec.rb +26 -16
- data/spec/core/spec_helper.rb +0 -25
- data/spec/extensions/inflector_spec.rb +0 -3
- data/spec/extensions/schema_dumper_spec.rb +292 -0
- data/spec/extensions/serialization_spec.rb +9 -0
- data/spec/extensions/single_table_inheritance_spec.rb +6 -1
- data/spec/extensions/spec_helper.rb +1 -3
- data/spec/extensions/validation_helpers_spec.rb +4 -4
- data/spec/integration/database_test.rb +18 -0
- data/spec/integration/dataset_test.rb +112 -1
- data/spec/integration/eager_loader_test.rb +70 -9
- data/spec/integration/prepared_statement_test.rb +2 -2
- data/spec/integration/schema_test.rb +76 -27
- data/spec/integration/spec_helper.rb +0 -14
- data/spec/integration/transaction_test.rb +27 -0
- data/spec/model/associations_spec.rb +0 -36
- data/spec/model/base_spec.rb +18 -123
- data/spec/model/hooks_spec.rb +2 -235
- data/spec/model/inflector_spec.rb +15 -115
- data/spec/model/model_spec.rb +0 -120
- data/spec/model/plugins_spec.rb +0 -70
- data/spec/model/record_spec.rb +35 -93
- data/spec/model/spec_helper.rb +0 -27
- data/spec/model/validations_spec.rb +0 -931
- metadata +9 -14
- data/lib/sequel/deprecated.rb +0 -593
- data/lib/sequel/deprecated_migration.rb +0 -91
- data/lib/sequel/model/deprecated.rb +0 -204
- data/lib/sequel/model/deprecated_hooks.rb +0 -103
- data/lib/sequel/model/deprecated_inflector.rb +0 -335
- data/lib/sequel/model/deprecated_validations.rb +0 -388
- data/spec/core/core_ext_spec.rb +0 -156
- data/spec/core/migration_spec.rb +0 -263
- data/spec/core/pretty_table_spec.rb +0 -58
- data/spec/model/caching_spec.rb +0 -217
- data/spec/model/schema_spec.rb +0 -92
| @@ -67,70 +67,6 @@ context "An SQLite database" do | |
| 67 67 | 
             
                proc {@db.temp_store = :invalid}.should raise_error(Sequel::Error)
         | 
| 68 68 | 
             
              end
         | 
| 69 69 |  | 
| 70 | 
            -
              specify "should be able to execute transactions" do
         | 
| 71 | 
            -
                @db.transaction do
         | 
| 72 | 
            -
                  @db.create_table!(:t) {text :name}
         | 
| 73 | 
            -
                end
         | 
| 74 | 
            -
                
         | 
| 75 | 
            -
                @db.tables.should include(:t)
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                proc {@db.transaction do
         | 
| 78 | 
            -
                  @db.create_table!(:u) {text :name}
         | 
| 79 | 
            -
                  raise ArgumentError
         | 
| 80 | 
            -
                end}.should raise_error(ArgumentError)
         | 
| 81 | 
            -
                # no commit
         | 
| 82 | 
            -
                @db.tables.should_not include(:u)
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                proc {@db.transaction do
         | 
| 85 | 
            -
                  @db.create_table!(:v) {text :name}
         | 
| 86 | 
            -
                  raise Sequel::Rollback
         | 
| 87 | 
            -
                end}.should_not raise_error
         | 
| 88 | 
            -
                # no commit
         | 
| 89 | 
            -
                @db.tables.should_not include(:r)
         | 
| 90 | 
            -
              end
         | 
| 91 | 
            -
             | 
| 92 | 
            -
              specify "should support nested transactions" do
         | 
| 93 | 
            -
                @db.transaction do
         | 
| 94 | 
            -
                  @db.transaction do
         | 
| 95 | 
            -
                    @db.create_table!(:t) {text :name}
         | 
| 96 | 
            -
                  end
         | 
| 97 | 
            -
                end
         | 
| 98 | 
            -
                
         | 
| 99 | 
            -
                @db.tables.should include(:t)
         | 
| 100 | 
            -
             | 
| 101 | 
            -
                proc {@db.transaction do
         | 
| 102 | 
            -
                  @db.create_table!(:v) {text :name}
         | 
| 103 | 
            -
                  @db.transaction do
         | 
| 104 | 
            -
                    raise Sequel::Rollback # should roll back the top-level transaction
         | 
| 105 | 
            -
                  end
         | 
| 106 | 
            -
                end}.should_not raise_error
         | 
| 107 | 
            -
                # no commit
         | 
| 108 | 
            -
                @db.tables.should_not include(:v)
         | 
| 109 | 
            -
              end
         | 
| 110 | 
            -
              
         | 
| 111 | 
            -
              specify "should handle returning inside of transaction by committing" do
         | 
| 112 | 
            -
                @db.create_table!(:items2){text :name}
         | 
| 113 | 
            -
                def @db.ret_commit
         | 
| 114 | 
            -
                  transaction do
         | 
| 115 | 
            -
                    self[:items2] << {:name => 'abc'}
         | 
| 116 | 
            -
                    return
         | 
| 117 | 
            -
                    self[:items2] << {:name => 'd'}
         | 
| 118 | 
            -
                  end
         | 
| 119 | 
            -
                end
         | 
| 120 | 
            -
                @db[:items2].count.should == 0
         | 
| 121 | 
            -
                @db.ret_commit
         | 
| 122 | 
            -
                @db[:items2].count.should == 1
         | 
| 123 | 
            -
                @db.ret_commit
         | 
| 124 | 
            -
                @db[:items2].count.should == 2
         | 
| 125 | 
            -
                proc do
         | 
| 126 | 
            -
                  @db.transaction do
         | 
| 127 | 
            -
                    raise Interrupt, 'asdf'
         | 
| 128 | 
            -
                  end
         | 
| 129 | 
            -
                end.should raise_error(Interrupt)
         | 
| 130 | 
            -
             | 
| 131 | 
            -
                @db[:items2].count.should == 2
         | 
| 132 | 
            -
              end
         | 
| 133 | 
            -
             | 
| 134 70 | 
             
              specify "should support timestamps and datetimes and respect datetime_class" do
         | 
| 135 71 | 
             
                @db.create_table!(:time){timestamp :t; datetime :d}
         | 
| 136 72 | 
             
                t1 = Time.at(1)
         | 
| @@ -156,15 +92,6 @@ context "An SQLite database" do | |
| 156 92 | 
             
                ]
         | 
| 157 93 | 
             
              end
         | 
| 158 94 |  | 
| 159 | 
            -
              specify "should catch invalid SQL errors and raise them as Error" do
         | 
| 160 | 
            -
                proc {@db.execute 'blah blah'}.should raise_error(Sequel::Error)
         | 
| 161 | 
            -
                proc {@db.execute_insert 'blah blah'}.should raise_error(Sequel::Error)
         | 
| 162 | 
            -
              end
         | 
| 163 | 
            -
              
         | 
| 164 | 
            -
              specify "should not swallow non-SQLite based exceptions" do
         | 
| 165 | 
            -
                proc {@db.pool.hold{raise Interrupt, "test"}}.should raise_error(Interrupt)
         | 
| 166 | 
            -
              end
         | 
| 167 | 
            -
             | 
| 168 95 | 
             
              specify "should correctly parse the schema" do
         | 
| 169 96 | 
             
                @db.create_table!(:time2) {timestamp :t}
         | 
| 170 97 | 
             
                @db.schema(:time2, :reload=>true).should == [[:t, {:type=>:datetime, :allow_null=>true, :default=>nil, :db_type=>"timestamp", :primary_key=>false}]]
         | 
| @@ -173,61 +100,9 @@ end | |
| 173 100 |  | 
| 174 101 | 
             
            context "An SQLite dataset" do
         | 
| 175 102 | 
             
              before do
         | 
| 176 | 
            -
                SQLITE_DB.create_table! :items do
         | 
| 177 | 
            -
                  integer :id, :primary_key => true, :auto_increment => true
         | 
| 178 | 
            -
                  text :name
         | 
| 179 | 
            -
                  float :value
         | 
| 180 | 
            -
                end
         | 
| 181 103 | 
             
                @d = SQLITE_DB[:items]
         | 
| 182 | 
            -
                @d.delete # remove all records
         | 
| 183 | 
            -
              end
         | 
| 184 | 
            -
              
         | 
| 185 | 
            -
              specify "should return the correct records" do
         | 
| 186 | 
            -
                @d.to_a.should == []
         | 
| 187 | 
            -
                @d << {:name => 'abc', :value => 1.23}
         | 
| 188 | 
            -
                @d << {:name => 'abc', :value => 4.56}
         | 
| 189 | 
            -
                @d << {:name => 'def', :value => 7.89}
         | 
| 190 | 
            -
                @d.select(:name, :value).to_a.sort_by {|h| h[:value]}.should == [
         | 
| 191 | 
            -
                  {:name => 'abc', :value => 1.23},
         | 
| 192 | 
            -
                  {:name => 'abc', :value => 4.56},
         | 
| 193 | 
            -
                  {:name => 'def', :value => 7.89}
         | 
| 194 | 
            -
                ]
         | 
| 195 | 
            -
              end
         | 
| 196 | 
            -
              
         | 
| 197 | 
            -
              specify "should return the correct record count" do
         | 
| 198 | 
            -
                @d.count.should == 0
         | 
| 199 | 
            -
                @d << {:name => 'abc', :value => 1.23}
         | 
| 200 | 
            -
                @d << {:name => 'abc', :value => 4.56}
         | 
| 201 | 
            -
                @d << {:name => 'def', :value => 7.89}
         | 
| 202 | 
            -
                @d.count.should == 3
         | 
| 203 | 
            -
              end
         | 
| 204 | 
            -
             | 
| 205 | 
            -
              specify "should return the last inserted id when inserting records" do
         | 
| 206 | 
            -
                id = @d << {:name => 'abc', :value => 1.23}
         | 
| 207 | 
            -
                id.should == @d.first[:id]
         | 
| 208 104 | 
             
              end
         | 
| 209 105 |  | 
| 210 | 
            -
              specify "should update records correctly" do
         | 
| 211 | 
            -
                @d << {:name => 'abc', :value => 1.23}
         | 
| 212 | 
            -
                @d << {:name => 'abc', :value => 4.56}
         | 
| 213 | 
            -
                @d << {:name => 'def', :value => 7.89}
         | 
| 214 | 
            -
                @d.filter(:name => 'abc').update(:value => 5.3)
         | 
| 215 | 
            -
                
         | 
| 216 | 
            -
                # the third record should stay the same
         | 
| 217 | 
            -
                @d[:name => 'def'][:value].should == 7.89
         | 
| 218 | 
            -
                @d.filter(:value => 5.3).count.should == 2
         | 
| 219 | 
            -
              end
         | 
| 220 | 
            -
              
         | 
| 221 | 
            -
              specify "should delete records correctly" do
         | 
| 222 | 
            -
                @d << {:name => 'abc', :value => 1.23}
         | 
| 223 | 
            -
                @d << {:name => 'abc', :value => 4.56}
         | 
| 224 | 
            -
                @d << {:name => 'def', :value => 7.89}
         | 
| 225 | 
            -
                @d.filter(:name => 'abc').delete
         | 
| 226 | 
            -
                
         | 
| 227 | 
            -
                @d.count.should == 1
         | 
| 228 | 
            -
                @d.first[:name].should == 'def'
         | 
| 229 | 
            -
              end
         | 
| 230 | 
            -
             | 
| 231 106 | 
             
              specify "should handle string pattern matches correctly" do
         | 
| 232 107 | 
             
                @d.literal(:x.like('a')).should == "(x LIKE 'a')"
         | 
| 233 108 | 
             
                @d.literal(~:x.like('a')).should == "NOT (x LIKE 'a')"
         | 
| @@ -283,43 +158,12 @@ context "An SQLite dataset AS clause" do | |
| 283 158 | 
             
              end
         | 
| 284 159 | 
             
            end
         | 
| 285 160 |  | 
| 286 | 
            -
            context "An SQLite dataset" do
         | 
| 287 | 
            -
              before do
         | 
| 288 | 
            -
                SQLITE_DB.create_table! :items do
         | 
| 289 | 
            -
                  integer :id, :primary_key => true, :auto_increment => true
         | 
| 290 | 
            -
                  text :name
         | 
| 291 | 
            -
                  float :value
         | 
| 292 | 
            -
                end
         | 
| 293 | 
            -
                @d = SQLITE_DB[:items]
         | 
| 294 | 
            -
                @d.delete # remove all records
         | 
| 295 | 
            -
                @d << {:name => 'abc', :value => 1.23}
         | 
| 296 | 
            -
                @d << {:name => 'def', :value => 4.56}
         | 
| 297 | 
            -
                @d << {:name => 'ghi', :value => 7.89}
         | 
| 298 | 
            -
              end
         | 
| 299 | 
            -
              
         | 
| 300 | 
            -
              specify "should correctly return avg" do
         | 
| 301 | 
            -
                @d.avg(:value).to_s.should == ((1.23 + 4.56 + 7.89) / 3).to_s
         | 
| 302 | 
            -
              end
         | 
| 303 | 
            -
              
         | 
| 304 | 
            -
              specify "should correctly return sum" do
         | 
| 305 | 
            -
                @d.sum(:value).to_s.should == (1.23 + 4.56 + 7.89).to_s
         | 
| 306 | 
            -
              end
         | 
| 307 | 
            -
              
         | 
| 308 | 
            -
              specify "should correctly return max" do
         | 
| 309 | 
            -
                @d.max(:value).to_s.should == 7.89.to_s
         | 
| 310 | 
            -
              end
         | 
| 311 | 
            -
              
         | 
| 312 | 
            -
              specify "should correctly return min" do
         | 
| 313 | 
            -
                @d.min(:value).to_s.should == 1.23.to_s
         | 
| 314 | 
            -
              end
         | 
| 315 | 
            -
            end
         | 
| 316 | 
            -
             | 
| 317 161 | 
             
            context "SQLite::Dataset#delete" do
         | 
| 318 162 | 
             
              before do
         | 
| 319 163 | 
             
                SQLITE_DB.create_table! :items do
         | 
| 320 | 
            -
                   | 
| 321 | 
            -
                   | 
| 322 | 
            -
                   | 
| 164 | 
            +
                  primary_key :id
         | 
| 165 | 
            +
                  String :name
         | 
| 166 | 
            +
                  Float :value
         | 
| 323 167 | 
             
                end
         | 
| 324 168 | 
             
                @d = SQLITE_DB[:items]
         | 
| 325 169 | 
             
                @d.delete # remove all records
         | 
| @@ -349,9 +193,9 @@ end | |
| 349 193 | 
             
            context "SQLite::Dataset#update" do
         | 
| 350 194 | 
             
              before do
         | 
| 351 195 | 
             
                SQLITE_DB.create_table! :items do
         | 
| 352 | 
            -
                   | 
| 353 | 
            -
                   | 
| 354 | 
            -
                   | 
| 196 | 
            +
                  primary_key :id
         | 
| 197 | 
            +
                  String :name
         | 
| 198 | 
            +
                  Float :value
         | 
| 355 199 | 
             
                end
         | 
| 356 200 | 
             
                @d = SQLITE_DB[:items]
         | 
| 357 201 | 
             
                @d.delete # remove all records
         | 
| @@ -372,24 +216,22 @@ end | |
| 372 216 | 
             
            context "SQLite dataset" do
         | 
| 373 217 | 
             
              before do
         | 
| 374 218 | 
             
                SQLITE_DB.create_table! :test do
         | 
| 375 | 
            -
                   | 
| 376 | 
            -
                   | 
| 377 | 
            -
                   | 
| 219 | 
            +
                  primary_key :id
         | 
| 220 | 
            +
                  String :name
         | 
| 221 | 
            +
                  Float :value
         | 
| 378 222 | 
             
                end
         | 
| 379 223 | 
             
                SQLITE_DB.create_table! :items do
         | 
| 380 | 
            -
                   | 
| 381 | 
            -
                   | 
| 382 | 
            -
                   | 
| 224 | 
            +
                  primary_key :id
         | 
| 225 | 
            +
                  String :name
         | 
| 226 | 
            +
                  Float :value
         | 
| 383 227 | 
             
                end
         | 
| 384 228 | 
             
                @d = SQLITE_DB[:items]
         | 
| 385 | 
            -
                @d.delete # remove all records
         | 
| 386 229 | 
             
                @d << {:name => 'abc', :value => 1.23}
         | 
| 387 230 | 
             
                @d << {:name => 'def', :value => 4.56}
         | 
| 388 231 | 
             
                @d << {:name => 'ghi', :value => 7.89}
         | 
| 389 232 | 
             
              end
         | 
| 390 | 
            -
              
         | 
| 391 233 | 
             
              after do
         | 
| 392 | 
            -
                SQLITE_DB.drop_table : | 
| 234 | 
            +
                SQLITE_DB.drop_table(:test, :items)
         | 
| 393 235 | 
             
              end
         | 
| 394 236 |  | 
| 395 237 | 
             
              specify "should be able to insert from a subquery" do
         | 
| @@ -55,11 +55,22 @@ context "A connection pool handling connections" do | |
| 55 55 | 
             
                @cpool.hold {:block_return}.should == :block_return
         | 
| 56 56 | 
             
              end
         | 
| 57 57 |  | 
| 58 | 
            +
              if RUBY_VERSION < '1.9.0' and (!defined?(RUBY_ENGINE) or RUBY_ENGINE != 'jruby')
         | 
| 59 | 
            +
                specify "#hold should remove dead threads from the pool if it reaches its max_size" do
         | 
| 60 | 
            +
                  Thread.new{@cpool.hold{Thread.current.exit!}}.join
         | 
| 61 | 
            +
                  @cpool.allocated.keys.map{|t| t.alive?}.should == [false]
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  Thread.new{@cpool.hold{Thread.current.exit!}}.join
         | 
| 64 | 
            +
                  @cpool.allocated.keys.map{|t| t.alive?}.should == [false, false]
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  Thread.new{@cpool.hold{}}.join
         | 
| 67 | 
            +
                  @cpool.allocated.should == {}
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
             | 
| 58 71 | 
             
              specify "#make_new should not make more than max_size connections" do
         | 
| 59 | 
            -
                @cpool. | 
| 60 | 
            -
                @cpool. | 
| 61 | 
            -
                @cpool.send(:make_new, :default).should == nil
         | 
| 62 | 
            -
                @cpool.created_count.should == 2
         | 
| 72 | 
            +
                50.times{Thread.new{@cpool.hold{sleep 0.01}}}
         | 
| 73 | 
            +
                @cpool.created_count.should == @max_size
         | 
| 63 74 | 
             
              end
         | 
| 64 75 |  | 
| 65 76 | 
             
              specify ":disconnection_proc option should set the disconnection proc to use" do
         | 
    
        data/spec/core/core_sql_spec.rb
    CHANGED
    
    | @@ -63,50 +63,6 @@ context "Array#sql_array" do | |
| 63 63 | 
             
              end
         | 
| 64 64 | 
             
            end
         | 
| 65 65 |  | 
| 66 | 
            -
            context "Array#to_sql" do
         | 
| 67 | 
            -
              deprec_specify "should concatenate multiple lines into a single string" do
         | 
| 68 | 
            -
                "SELECT * \r\nFROM items\r\n WHERE a = 1".split.to_sql. \
         | 
| 69 | 
            -
                  should == 'SELECT * FROM items WHERE a = 1'
         | 
| 70 | 
            -
              end
         | 
| 71 | 
            -
              
         | 
| 72 | 
            -
              deprec_specify "should remove superfluous white space and line breaks" do
         | 
| 73 | 
            -
                "\tSELECT * \n FROM items    ".split.to_sql. \
         | 
| 74 | 
            -
                  should == 'SELECT * FROM items'
         | 
| 75 | 
            -
              end
         | 
| 76 | 
            -
              
         | 
| 77 | 
            -
              deprec_specify "should remove ANSI SQL comments" do
         | 
| 78 | 
            -
                "SELECT *   --comment\r\n  FROM items\r\n  --comment".split.to_sql. \
         | 
| 79 | 
            -
                  should == 'SELECT * FROM items'
         | 
| 80 | 
            -
              end
         | 
| 81 | 
            -
              
         | 
| 82 | 
            -
              deprec_specify "should remove C-style comments" do
         | 
| 83 | 
            -
                "SELECT * \r\n /* comment comment\r\n comment\r\n FROM items */\r\n FROM items\r\n--comment".split.to_sql. \
         | 
| 84 | 
            -
                  should == 'SELECT * FROM items'
         | 
| 85 | 
            -
              end
         | 
| 86 | 
            -
            end
         | 
| 87 | 
            -
             | 
| 88 | 
            -
            context "String#to_sql" do
         | 
| 89 | 
            -
              deprec_specify "should concatenate multiple lines into a single string" do
         | 
| 90 | 
            -
                "SELECT * \r\nFROM items\r\nWHERE a = 1".to_sql. \
         | 
| 91 | 
            -
                  should == 'SELECT * FROM items WHERE a = 1'
         | 
| 92 | 
            -
              end
         | 
| 93 | 
            -
              
         | 
| 94 | 
            -
              deprec_specify "should remove superfluous white space and line breaks" do
         | 
| 95 | 
            -
                "\tSELECT * \r\n FROM items    ".to_sql. \
         | 
| 96 | 
            -
                  should == 'SELECT * FROM items'
         | 
| 97 | 
            -
              end
         | 
| 98 | 
            -
              
         | 
| 99 | 
            -
              deprec_specify "should remove ANSI SQL comments" do
         | 
| 100 | 
            -
                "SELECT *   --comment \r\n FROM items\r\n  --comment".to_sql. \
         | 
| 101 | 
            -
                  should == 'SELECT * FROM items'
         | 
| 102 | 
            -
              end
         | 
| 103 | 
            -
              
         | 
| 104 | 
            -
              deprec_specify "should remove C-style comments" do
         | 
| 105 | 
            -
                "SELECT * \r\n/* comment comment\r\ncomment\r\nFROM items */\r\nFROM items\r\n--comment".to_sql. \
         | 
| 106 | 
            -
                  should == 'SELECT * FROM items'
         | 
| 107 | 
            -
              end
         | 
| 108 | 
            -
            end
         | 
| 109 | 
            -
             | 
| 110 66 | 
             
            context "String#lit" do
         | 
| 111 67 | 
             
              specify "should return an LiteralString object" do
         | 
| 112 68 | 
             
                'xyz'.lit.should be_a_kind_of(Sequel::LiteralString)
         | 
| @@ -118,13 +74,6 @@ context "String#lit" do | |
| 118 74 | 
             
                  "UPDATE t SET stamp = NOW()"
         | 
| 119 75 | 
             
              end
         | 
| 120 76 |  | 
| 121 | 
            -
              deprec_specify "should be aliased as expr" do
         | 
| 122 | 
            -
                'xyz'.expr.should be_a_kind_of(Sequel::LiteralString)
         | 
| 123 | 
            -
                'xyz'.expr.to_s.should == 'xyz'
         | 
| 124 | 
            -
                Sequel::Database.new[:t].update_sql(:stamp => "NOW()".expr).should == \
         | 
| 125 | 
            -
                  "UPDATE t SET stamp = NOW()"
         | 
| 126 | 
            -
              end
         | 
| 127 | 
            -
             | 
| 128 77 | 
             
              specify "should return a PlaceholderLiteralString object if args are given" do
         | 
| 129 78 | 
             
                a = 'DISTINCT ?'.lit(:a)
         | 
| 130 79 | 
             
                a.should be_a_kind_of(Sequel::SQL::PlaceholderLiteralString)
         | 
| @@ -146,18 +95,6 @@ context "String#to_sequel_blob" do | |
| 146 95 | 
             
              end
         | 
| 147 96 | 
             
            end
         | 
| 148 97 |  | 
| 149 | 
            -
            context "String#split_sql" do
         | 
| 150 | 
            -
              deprec_specify "should split a string containing multiple statements" do
         | 
| 151 | 
            -
                "DROP TABLE a; DROP TABLE c".split_sql.should == \
         | 
| 152 | 
            -
                  ['DROP TABLE a', 'DROP TABLE c']
         | 
| 153 | 
            -
              end
         | 
| 154 | 
            -
              
         | 
| 155 | 
            -
              deprec_specify "should remove comments from the string" do
         | 
| 156 | 
            -
                "DROP TABLE a;/* DROP TABLE b; DROP TABLE c;*/DROP TABLE d".split_sql.should == \
         | 
| 157 | 
            -
                  ['DROP TABLE a', 'DROP TABLE d']
         | 
| 158 | 
            -
              end
         | 
| 159 | 
            -
            end
         | 
| 160 | 
            -
             | 
| 161 98 | 
             
            context "#desc" do
         | 
| 162 99 | 
             
              before do
         | 
| 163 100 | 
             
                @ds = Sequel::Dataset.new(nil)
         | 
| @@ -300,6 +237,10 @@ context "Symbol" do | |
| 300 237 | 
             
                @ds.literal(:xyz.qualify(:abc)).should == '"ABC"."XYZ"'
         | 
| 301 238 | 
             
              end
         | 
| 302 239 |  | 
| 240 | 
            +
              specify "#qualify should work on QualifiedIdentifiers" do
         | 
| 241 | 
            +
                @ds.literal(:xyz.qualify(:abc).qualify(:def)).should == '"DEF"."ABC"."XYZ"'
         | 
| 242 | 
            +
              end
         | 
| 243 | 
            +
             | 
| 303 244 | 
             
              specify "should be able to qualify an identifier" do
         | 
| 304 245 | 
             
                @ds.literal(:xyz.identifier.qualify(:xyz__abc)).should == '"XYZ"."ABC"."XYZ"'
         | 
| 305 246 | 
             
              end
         | 
| @@ -365,10 +306,12 @@ context "Symbol" do | |
| 365 306 | 
             
                :abc.cast(:integer).to_s(@ds).should == "CAST(abc AS integer)"
         | 
| 366 307 | 
             
              end
         | 
| 367 308 |  | 
| 368 | 
            -
               | 
| 369 | 
            -
                 | 
| 309 | 
            +
              specify "should support sql array accesses via sql_subscript" do
         | 
| 310 | 
            +
                @ds.literal(:abc.sql_subscript(1)).should == "abc[1]"
         | 
| 311 | 
            +
                @ds.literal(:abc__def.sql_subscript(1)).should == "abc.def[1]"
         | 
| 312 | 
            +
                @ds.literal(:abc.sql_subscript(1)|2).should == "abc[1, 2]"
         | 
| 370 313 | 
             
              end
         | 
| 371 | 
            -
             | 
| 314 | 
            +
             | 
| 372 315 | 
             
              specify "should support cast_numeric and cast_string" do
         | 
| 373 316 | 
             
                x = :abc.cast_numeric
         | 
| 374 317 | 
             
                x.should be_a_kind_of(Sequel::SQL::NumericExpression)
         | 
| @@ -384,16 +327,16 @@ context "Symbol" do | |
| 384 327 |  | 
| 385 328 | 
             
                x = :abc.cast_string(:varchar)
         | 
| 386 329 | 
             
                x.should be_a_kind_of(Sequel::SQL::StringExpression)
         | 
| 387 | 
            -
                x.to_s(@ds).should == "CAST(abc AS varchar)"
         | 
| 330 | 
            +
                x.to_s(@ds).should == "CAST(abc AS varchar(255))"
         | 
| 388 331 | 
             
              end
         | 
| 389 332 |  | 
| 390 333 | 
             
              specify "should allow database independent types when casting" do
         | 
| 391 334 | 
             
                m = MockDatabase.new
         | 
| 392 335 | 
             
                m.instance_eval do
         | 
| 393 | 
            -
                   def  | 
| 394 | 
            -
                     return :foo if  | 
| 395 | 
            -
                     return :bar if  | 
| 396 | 
            -
                      | 
| 336 | 
            +
                   def cast_type_literal(type)
         | 
| 337 | 
            +
                     return :foo if type == Integer
         | 
| 338 | 
            +
                     return :bar if type == String
         | 
| 339 | 
            +
                     type
         | 
| 397 340 | 
             
                   end
         | 
| 398 341 | 
             
                end
         | 
| 399 342 | 
             
                @ds2 = Sequel::Dataset.new(m)
         | 
| @@ -406,110 +349,11 @@ context "Symbol" do | |
| 406 349 | 
             
                :abc.cast_numeric(String).to_s(@ds2).should == "CAST(abc AS bar)"
         | 
| 407 350 | 
             
              end
         | 
| 408 351 |  | 
| 409 | 
            -
              deprec_specify "should support subscript access using | operator" do
         | 
| 410 | 
            -
                (:abc|1).to_s(@ds).should == 'abc[1]'
         | 
| 411 | 
            -
                (:abc|[1]).to_s(@ds).should == 'abc[1]'
         | 
| 412 | 
            -
                (:abc|[1, 2]).to_s(@ds).should == 'abc[1, 2]'
         | 
| 413 | 
            -
                (:abc|1|2).to_s(@ds).should == 'abc[1, 2]'
         | 
| 414 | 
            -
              end
         | 
| 415 | 
            -
             | 
| 416 352 | 
             
              specify "should support SQL EXTRACT function via #extract " do
         | 
| 417 353 | 
             
                :abc.extract(:year).to_s(@ds).should == "extract(year FROM abc)"
         | 
| 418 354 | 
             
              end
         | 
| 419 355 | 
             
            end
         | 
| 420 356 |  | 
| 421 | 
            -
            context "String#to_time" do
         | 
| 422 | 
            -
              deprec_specify "should convert the string into a Time object" do
         | 
| 423 | 
            -
                "2007-07-11".to_time.should == Time.parse("2007-07-11")
         | 
| 424 | 
            -
                "06:30".to_time.should == Time.parse("06:30")
         | 
| 425 | 
            -
              end
         | 
| 426 | 
            -
              
         | 
| 427 | 
            -
              deprec_specify "should raise InvalidValue for an invalid time" do
         | 
| 428 | 
            -
                proc {'0000-00-00'.to_time}.should raise_error(Sequel::InvalidValue)
         | 
| 429 | 
            -
              end
         | 
| 430 | 
            -
            end
         | 
| 431 | 
            -
             | 
| 432 | 
            -
            context "String#to_date" do
         | 
| 433 | 
            -
              after do
         | 
| 434 | 
            -
                Sequel.convert_two_digit_years = true
         | 
| 435 | 
            -
              end
         | 
| 436 | 
            -
             | 
| 437 | 
            -
              deprec_specify "should convert the string into a Date object" do
         | 
| 438 | 
            -
                "2007-07-11".to_date.should == Date.parse("2007-07-11")
         | 
| 439 | 
            -
              end
         | 
| 440 | 
            -
              
         | 
| 441 | 
            -
              deprec_specify "should convert 2 digit years by default" do
         | 
| 442 | 
            -
                "July 11, 07".to_date.should == Date.parse("2007-07-11")
         | 
| 443 | 
            -
              end
         | 
| 444 | 
            -
             | 
| 445 | 
            -
              deprec_specify "should not convert 2 digit years if set not to" do
         | 
| 446 | 
            -
                Sequel.convert_two_digit_years = false
         | 
| 447 | 
            -
                "July 11, 07".to_date.should == Date.parse("0007-07-11")
         | 
| 448 | 
            -
              end
         | 
| 449 | 
            -
             | 
| 450 | 
            -
              deprec_specify "should raise InvalidValue for an invalid date" do
         | 
| 451 | 
            -
                proc {'0000-00-00'.to_date}.should raise_error(Sequel::InvalidValue)
         | 
| 452 | 
            -
              end
         | 
| 453 | 
            -
            end
         | 
| 454 | 
            -
             | 
| 455 | 
            -
            context "String#to_datetime" do
         | 
| 456 | 
            -
              after do
         | 
| 457 | 
            -
                Sequel.convert_two_digit_years = true
         | 
| 458 | 
            -
              end
         | 
| 459 | 
            -
             | 
| 460 | 
            -
              deprec_specify "should convert the string into a DateTime object" do
         | 
| 461 | 
            -
                "2007-07-11 10:11:12a".to_datetime.should == DateTime.parse("2007-07-11 10:11:12a")
         | 
| 462 | 
            -
              end
         | 
| 463 | 
            -
              
         | 
| 464 | 
            -
              deprec_specify "should convert 2 digit years by default" do
         | 
| 465 | 
            -
                "July 11, 07 10:11:12a".to_datetime.should == DateTime.parse("2007-07-11 10:11:12a")
         | 
| 466 | 
            -
              end
         | 
| 467 | 
            -
             | 
| 468 | 
            -
              deprec_specify "should not convert 2 digit years if set not to" do
         | 
| 469 | 
            -
                Sequel.convert_two_digit_years = false
         | 
| 470 | 
            -
                "July 11, 07 10:11:12a".to_datetime.should == DateTime.parse("0007-07-11 10:11:12a")
         | 
| 471 | 
            -
              end
         | 
| 472 | 
            -
             | 
| 473 | 
            -
              deprec_specify "should raise InvalidValue for an invalid date" do
         | 
| 474 | 
            -
                proc {'0000-00-00'.to_datetime}.should raise_error(Sequel::InvalidValue)
         | 
| 475 | 
            -
              end
         | 
| 476 | 
            -
            end
         | 
| 477 | 
            -
             | 
| 478 | 
            -
            context "String#to_sequel_time" do
         | 
| 479 | 
            -
              after do
         | 
| 480 | 
            -
                Sequel.datetime_class = Time
         | 
| 481 | 
            -
                Sequel.convert_two_digit_years = true
         | 
| 482 | 
            -
              end
         | 
| 483 | 
            -
             | 
| 484 | 
            -
              deprec_specify "should convert the string into a Time object by default" do
         | 
| 485 | 
            -
                "2007-07-11 10:11:12a".to_sequel_time.class.should == Time
         | 
| 486 | 
            -
                "2007-07-11 10:11:12a".to_sequel_time.should == Time.parse("2007-07-11 10:11:12a")
         | 
| 487 | 
            -
              end
         | 
| 488 | 
            -
              
         | 
| 489 | 
            -
              deprec_specify "should convert the string into a DateTime object if that is set" do
         | 
| 490 | 
            -
                Sequel.datetime_class = DateTime
         | 
| 491 | 
            -
                "2007-07-11 10:11:12a".to_sequel_time.class.should == DateTime
         | 
| 492 | 
            -
                "2007-07-11 10:11:12a".to_sequel_time.should == DateTime.parse("2007-07-11 10:11:12a")
         | 
| 493 | 
            -
              end
         | 
| 494 | 
            -
              
         | 
| 495 | 
            -
              deprec_specify "should convert 2 digit years by default if using DateTime class" do
         | 
| 496 | 
            -
                Sequel.datetime_class = DateTime
         | 
| 497 | 
            -
                "July 11, 07 10:11:12a".to_sequel_time.should == DateTime.parse("2007-07-11 10:11:12a")
         | 
| 498 | 
            -
              end
         | 
| 499 | 
            -
             | 
| 500 | 
            -
              deprec_specify "should not convert 2 digit years if set not to when using DateTime class" do
         | 
| 501 | 
            -
                Sequel.datetime_class = DateTime
         | 
| 502 | 
            -
                Sequel.convert_two_digit_years = false
         | 
| 503 | 
            -
                "July 11, 07 10:11:12a".to_sequel_time.should == DateTime.parse("0007-07-11 10:11:12a")
         | 
| 504 | 
            -
              end
         | 
| 505 | 
            -
             | 
| 506 | 
            -
              deprec_specify "should raise InvalidValue for an invalid time" do
         | 
| 507 | 
            -
                proc {'0000-00-00'.to_sequel_time}.should raise_error(Sequel::InvalidValue)
         | 
| 508 | 
            -
                Sequel.datetime_class = DateTime
         | 
| 509 | 
            -
                proc {'0000-00-00'.to_sequel_time}.should raise_error(Sequel::InvalidValue)
         | 
| 510 | 
            -
              end
         | 
| 511 | 
            -
            end
         | 
| 512 | 
            -
             | 
| 513 357 | 
             
            context "Sequel::SQL::Function#==" do
         | 
| 514 358 | 
             
              specify "should be true for functions with the same name and arguments, false otherwise" do
         | 
| 515 359 | 
             
                a = :date.sql_function(:t)
         |