Hi all,

I had some issues where one of my models was not saving.  I was
getting the following error:

Conversion failed when converting date and/or time from character
string.
SQL Query: INSERT INTO [users] ([created], [modified], [username],
[password], [email]) VALUES ('NULL', 'NULL', N'test3',
N'f8fc703af6dcd2eeaa9f685f649fb1b869fc9ed0', N'[email protected]')

I looked at lib/Cake/Model/Datasource/Database/Sqlserver.php and saw
the following at line 235:

if ($fields[$field]['default'] === 'null') {
   $fields[$field]['default'] = null;
} else {
                                $this->value($fields[$field]['default'], 
$fields[$field]['type']);
}

It looks like the problem is that Cake is internally storing a string
with the value 'NULL' as a placeholder for an actual NULL value.  The
problem is, the comparison it makes is case sensitive, so when saving
it assumes that I was trying to save a string ('NULL') in a field that
is a datetime.  I was able to work around this be adding strtolower to
the comparison (if (strtolower($fields[$field]['default']) === 'null')
{ ... } ).  Some other people (http://cakephp.lighthouseapp.com/
projects/42648/tickets/629-errors-in-ms-sql-driver-when-a-fieldcolumn-
has-a-default-value-of-null) seem to have discussed this issue as
well.  Is the CakePHP team aware of this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to