
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
-
jmoses January 21st, 2008 @ 08:36 AM
This SQL (for MySQL at least) should be:
INSERT INTO `hacker_key_categories` VALUES ();
-
Kevin Bullock January 23rd, 2008 @ 09:52 AM
The specs pass when running against DataMapper trunk (r707 as of this writing). This seems to be a duplicate of #85 .
-
Dan Kubb (dkubb) April 15th, 2008 @ 03:29 AM
- Milestone cleared.
-
Sam Smoot May 8th, 2008 @ 05:13 PM
- State changed from new to invalid
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »