Tuesday, January 8, 2013

Re: created and modified fields with microsoft sql server

Can you kindly paste your CakePHP code that does the insert? :)

On Tuesday, January 8, 2013 11:51:15 PM UTC+8, carlos....@gmail.com wrote:
Hi,

i'm new at cakephp, and i've a problem with MSSQL and created/modified fields

I did the blog example in mysql without problems. Now, i try to do the same in mssql server and it doesn't work properly.

I created the table:

CREATE TABLE [enqDocencia].[posts](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [title] [varchar](50) NULL,
    [body] [text] NULL,
    [created] [datetime] NULL,
    [modified] [datetime] NULL,
 CONSTRAINT [PK__posts__3213E83F1CF15040] PRIMARY KEY CLUSTERED
)

ALTER TABLE [enqDocencia].[posts] ADD  CONSTRAINT [DF__posts__created__1ED998B2]  DEFAULT (NULL) FOR [created]
GO

ALTER TABLE [enqDocencia].[posts] ADD  CONSTRAINT [DF__posts__modified__1FCDBCEB]  DEFAULT (NULL) FOR [modified]
GO

as you can see, i added created and modified fields

the problem is that, when i try to add a "blog entry" in cakephp, it returns me this error:

Error: SQLSTATE[22007]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string.

SQL Query: INSERT INTO [posts] ([created], [modified], [title], [body]) VALUES ('NULL', 'NULL', N'title_ex', N'body post text')

Notice: If you want to customize this error message, create cakephptest\View\Errors\pdo_error.ctp


as you can see, this SQL sentence has two errors:

- first, it try tu put 'null' value at 'created' field, but it should be getdate() (current timestamp)

- also, it put NULL inside two character    '  '          ; then for mssql, is a "string", not  NULL value (it should be without ' ' )


i'm very confused, what can I do? I'm doing something wrong?


Thanks,





--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: