For anyone who needs it, here's the solution. What's going on, is that at some
point in time (looks like about 5 years ago in reality) JDBC started elevating
all MySQL warnings into full errors. From what I can see, there's no way to
get around that via the JDBC API itself, but there are only two ways they can
get that behaviour:
1. Perform SHOW WARNINGS after every query and treat them as errors
2. Change the sql_mode setting in MySQL to TRADITIONAL, which does the
conversion at the RDBMS level.
If they were doing (1), all you'd have to do is execute the query "SET
max_error_count = 0" before any of your DataMapper code is run. This didn't
halt the error, so trying the next thing:
repository(:default).adapter.execute("SET sql_mode = ''")
This reverts MySQL to its default behaviour and stops DataMapper from produces
errors on warnings (JDBC has simply called SET sql_mode = 'TRADITIONAL') at
some point.
You probably actually want to be a bit smarter in reality, since the sql_mode
is actually a comma separated list of modes, so you should really just strip
TRADITIONAL from the list.
Glad to have identified the source of the problem. You could possibly put this
in the documentation on the Legacy Support page?
El 05/05/2011, a las 08:54, RipTheJacker escribió:
> for logging: http://pastie.org/1843979
>
> On May 4, 11:35 am, Chris Corbyn <[email protected]> wrote:
>> Hi,
>>
>> I'm new to DataMapper but have found myself using it as I port a PHP
>> application to Rails, which has a completely un-rails-like schema.
>>
>> My understanding is that DataMapper will only update:
>>
>> a) Fields that it knows about (i.e. ones I've defined as properties)
>> b) Dirty values (i.e. it won't rewrite potentially) stale data
>>
>> I have defined a Model class for User, just to test this, which
>> contains just a handful of the 80 or so columns in the database.
>>
>> class User
>> include DataMapper::Resource
>>
>> storage_names[:default] = :user
>>
>> property :id, Serial, :field => 'userid', :key => true
>> property :username, String
>> property :email, String
>> property :activated, Boolean, :field =>
>> 'isactivated', :default => false
>> property :full_name, String, :field => 'fullname', :default
>> => ''
>> property :password_hash, String, :field =>
>> 'passwordhash', :default => ''
>> property :password_salt, String, :field => 'salt', :default => ''
>> property :updated_at, EpochTime, :field => 'timemodified'
>> property :logged_in_at, EpochTime, :field => 'timelastlogin'
>> property :banned, Boolean, :field => 'isbanned', :default
>> => false
>> end
>>
>> Now, I can perform read operations quite happily, which got me all
>> excited, but then I tried the next logical thing: create a new user.
>>
>> new_user = User.new
>> new_user.username = 'vssavfvabf'
>> new_user.email = '[email protected]'
>> new_user.full_name = 'Testing'
>> new_user.save
>>
>> This throws the Exception:
>>
>> DataObjects::SQLError "Field 'activationcode' doesn't have a default
>> value"
>>
>> Our schema is huge and it pains me to think I may have to work through
>> it setting default values for each of the fields that don't have them
>> (which is almost all of them, since we just let MySQL set zero or an
>> empty string, or NULL if permitted).
>>
>> But that aside, why is DM even touching this field? Or if it's not,
>> what is actually happening and how can I work around it? I know the
>> insert will work just fine without specifying a value, since MySQL
>> will just use an empty string as a fallback. I'd rather not expressly
>> set all the defaults if I can avoid it, since this is an old legacy
>> application that has grown into a big hairy beast. If I was designing
>> a new schema for a new app I'd not even think twice about it and move
>> on, but alas... :)
>>
>> Any pointers?
>>
>> Cheers,
>>
>> Chris
>>
>> PS: Can I turn something on so that all the queries being executed are
>> output or written to a log or some such, for quick and dirty debugging?
>
> --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/datamapper?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.