#134 invalid
Ardekantur

Malformed SQL in attribute-less save

Reported by Ardekantur | January 20th, 2008 @ 10:36 PM

A class file I have created:

class HackerKeyCategory < DataMapper::Base

  property :name,   :string, :nullable => false
  property :abbrev, :string, :nullable => false

  def initialize( name = nil, abbrev = nil )
    self.name = name
    self.abbrev = abbrev
  end

end

An rSpec I have created for it:

require File.join( File.dirname(__FILE__), "..", "spec_helper" )

describe HackerKeyCategory do

  it "should accept a name and an abbreviation" do
    sw = HackerKeyCategory.new 'Software Hacking', 'sw'
    sw.name.should == 'Software Hacking'
    sw.abbrev.should == 'sw'
  end

  it "should require a name" do
    xx = HackerKeyCategory.new
    # xx.attributes = { :abbrev => 'xx' }
    lambda { xx.save }.call.should_not be_true
  end

end

The second specification fails because DataMapper tries to execute this MySQL statement:

DataObject::QueryError in 'HackerKeyCategory should require a name'
Your query failed.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
INSERT INTO `hacker_key_categories`
/var/lib/gems/1.8/gems/do_mysql-0.2.3/lib/do_mysql.rb:193:in `execute_non_query'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/adapters/data_object_adapter.rb:286:in `create'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/adapters/data_object_adapter.rb:77:in `connection'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/support/connection_pool.rb:68:in `hold'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/adapters/data_object_adapter.rb:77:in `connection'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/adapters/data_object_adapter.rb:285:in `create'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/adapters/data_object_adapter.rb:209:in `send'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/adapters/data_object_adapter.rb:209:in `save'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/context.rb:60:in `save'
/var/lib/gems/1.8/gems/datamapper-0.2.5/lib/data_mapper/support/active_record_impersonation.rb:11:in `save'
./spec/models/hacker_key_category_spec.rb:14:
./spec/models/hacker_key_category_spec.rb:14:in `call'
./spec/models/hacker_key_category_spec.rb:14:

Comments and changes to this ticket

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