#1452 new
meh.

Syntax error with a simple Model.first.

Reported by meh. | November 27th, 2010 @ 10:47 AM

>> Repository.first.packages.first.data.features.first(:source => Repository.first.packages.first.data)
 ~ (0.000126) SELECT "id", "name", "type" FROM "packo_models_repositories" ORDER BY "id" LIMIT 1
 ~ (0.000182) SELECT "id", "repo_id", "tags_hashed", "name", "version", "slot", "revision", "repository_id" FROM "packo_models_repository_packages" WHERE "repository_id" = 1 ORDER BY "id" LIMIT 1
 ~ (0.000048) SELECT "id", "name", "type" FROM "packo_models_repositories" WHERE "id" = 1 ORDER BY "id" LIMIT 1
 ~ (0.000037) SELECT "package_id" FROM "packo_models_repository_package_sources" WHERE "package_id" = 1 ORDER BY "package_id" LIMIT 1
 ~ (0.000033) SELECT "id", "name", "type" FROM "packo_models_repositories" ORDER BY "id" LIMIT 1
 ~ (0.000074) SELECT "id", "repo_id", "tags_hashed", "name", "version", "slot", "revision", "repository_id" FROM "packo_models_repository_packages" WHERE "repository_id" = 1 ORDER BY "id" LIMIT 1
 ~ (0.000046) SELECT "id", "name", "type" FROM "packo_models_repositories" WHERE "id" = 1 ORDER BY "id" LIMIT 1
 ~ (0.000042) SELECT "package_id" FROM "packo_models_repository_package_sources" WHERE "package_id" = 1 ORDER BY "package_id" LIMIT 1
 ~ (0.000028) SELECT "id", "source_id", "name", "enabled", "source_package_id" FROM "packo_models_repository_package_source_features" WHERE ("source_package_id" = 1 AND ) ORDER BY "id" LIMIT 1
 ~ near ")": syntax error (code: 1, sql state: , query: SELECT "id", "source_id", "name", "enabled", "source_package_id" FROM "packo_models_repository_package_source_features" WHERE ("source_package_id" = 1 AND ) ORDER BY "id" LIMIT 1, uri: sqlite3:///tmp/packo_cache)
DataObjects::SyntaxError: near ")": syntax error
    /usr/lib64/ruby/gems/1.9.1/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:142:in `execute_reader'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:142:in `block in read'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:260:in `with_connection'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:138:in `read'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-core-1.0.2/lib/dm-core/repository.rb:162:in `read'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-core-1.0.2/lib/dm-core/collection.rb:1116:in `lazy_load'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-core-1.0.2/lib/dm-core/associations/one_to_many.rb:280:in `lazy_load'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-core-1.0.2/lib/dm-core/support/lazy_array.rb:277:in `to_a'
    /usr/lib64/ruby/gems/1.9.1/gems/dm-core-1.0.2/lib/dm-core/collection.rb:273:in `first'

:source is a belongs_to in the model, somehow the query object that is generated is source = 1 AND source = 1, so the problem is in multiple places.

The problem that creates the wrong SELECT is that operation_statement line 642 in dm-do-adapter/adapter.rb checks if the statement is nil or not, but operation_statement itself returns an empty string, which then generates the ghost AND.

I fixed it with:

- return statement, bind_values
+ return (statement.empty? ? nil : statement), bind_values

Everything works as expected that way, but as I said I think the problem is in the generated query object which has 2 conditions instead of just 1.

I never looked into DataMapper's source before today so I'll leave you to fix the real issue.

The models can be found here.

Comments and changes to this ticket

  • meh.

    meh. November 28th, 2010 @ 10:30 AM

    I couldn't create a simple testcase as asked by snusnu, so here's a simple way to get a working environment with my models.

    $ git clone git://github.com/distro/packo.git
    $ cd packo
    $ git checkout d5e3b3b
    $ gem build *spec
    $ gem install *.gem
    $ PACKO_DEBUG=1 PACKO_DATABASE="sqlite::memory:" irb
    require 'packo/models'; include Packo::Models
    Repository.create(:type => :source, :name => 'test', :uri => 'test', :path => 'test'). \
      packages.create(:repo_id => 1, :tags_hashed => '4e1243bd22c66e76c2ba9eddc1f91394e57f9f83', :name => 'test', :version => '0', :slot => nil, :revision => 0)
    
    Repository.first.packages.first.data.features.first(:source => Repository.first.packages.first.data)
    

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages