I have a query which updates the projects table of my database, however when I try to run my query with blank values i get the following error:
Expand|Select|Wrap|Line Numbers
- Data truncation: Data truncated for column 'date' at row 1
Here is my create function:
Expand|Select|Wrap|Line Numbers
- <cffunction name="create" access="public" output="false" returntype="struct" hint="CRUD Method">
- <!--- arguments for the constructor, all of which are optional (no-arg constructor) --->
- <cfargument name="dsn" displayName="dsn" type="string" hint="Datasource name"
- required="true" default="" />
- <cfargument name="id" displayName="id" type="string" hint="The project ID (UUID)"
- required="true" default="0" />
- <cfargument name="priority" displayName="priority" type="string" hint="The project priority (Sort order)"
- required="false" default="1" />
- <cfargument name="type" displayName="type" type="string" hint="The project type"
- required="false" default="" />
- <cfargument name="title" displayName="title" type="string" hint="The project title"
- required="false" default="" />
- <cfargument name="location" displayName="location" type="string" hint="The project location"
- required="false" default="" />
- <cfargument name="description" displayName="description" type="string" hint="The project description"
- required="false" default="" />
- <cfargument name="body" displayName="body" type="string" hint="The project body description"
- required="false" default="" />
- <cfargument name="image" displayName="image" type="string" hint="The project image name"
- required="false" default="" />
- <cfargument name="image_alt" displayName="image_alt" type="string" hint="The project image alternative text"
- required="false" default="" />
- <cfargument name="movie" displayName="movie" type="string" hint="The project movie"
- required="false" default="" />
- <cfargument name="pdf_doc" displayName="pdf_doc" type="string" hint="The project pdf reference"
- required="false" default="" />
- <cfargument name="word_doc" displayName="word_doc" type="string" hint="The project work doc reference"
- required="false" default="" />
- <cfargument name="date" displayName="date" type="string" hint="The date the project was added"
- required="false" default="" />
- <cfargument name="time" displayName="time" type="string" hint="The time the project was added"
- required="false" default="" />
- <cfargument name="archive" displayName="archive" type="string" hint="The project should be archived"
- required="false" default="" />
- <cfargument name="display" displayName="display" type="string" hint="The project should be shown"
- required="false" default="" />
- <!--- initialize variables --->
- <cfset var results = StructNew() />
- <cfset var qInsert = 0 />
- <!--- defaults --->
- <cfset results.success = true />
- <cfset results.message = "The project was inserted successfully." />
- <!--- <cftry> --->
- <cftransaction>
- <cfquery name="qInsert" datasource="#arguments.dsn#">
- INSERT INTO
- projects
- (
- id,
- priority,
- type,
- title,
- location,
- description,
- body,
- image,
- image_alt,
- movie,
- pdf_doc,
- word_doc,
- date,
- time,
- archive,
- display
- )
- VALUES
- (
- <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" null="yes" />,
- <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.priority#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.type#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.title#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.location#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.description#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.body#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.image#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.image_alt#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.movie#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.pdf_doc#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.word_doc#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.date#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.time#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.archive#" />,
- <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.display#" />
- )
- </cfquery>
- <!--- Select insert id --->
- <cfquery name="qMaxID" datasource="#arguments.dsn#">
- SELECT max( id ) AS maxID FROM projects
- </cfquery>
- <!--- Add last insert id to results --->
- <cfset results.lastInsertID = StructFind(qMaxID,"maxID") />
- </cftransaction>
- <!---
- <cfcatch type="database">
- <cfset results.success = false />
- <cfset results.message = "An error occured whilst attempting to update the database, please check you have filled in all the fields correctly and try again." />
- <cfif cfcatch.detail NEQ "">
- <cfset results.message = results.message & "Error details: <br />" & cfcatch.detail />
- </cfif>
- </cfcatch>
- </cftry> --->
- <!--- return the struct --->
- <cfreturn StructCopy(results) />
- </cffunction>
I have tryed running the following test query which works fine:
Expand|Select|Wrap|Line Numbers
- INSERT INTO
- projects
- (
- id,
- priority,
- type,
- title,
- location,
- description,
- body,
- image,
- image_alt,
- movie,
- pdf_doc,
- word_doc,
- date,
- time,
- archive,
- display
- )
- VALUES
- (
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- ''
- )
Does anyone know what the problem is?
Thanks,
chromis