Hi,
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: - Data truncation: Data truncated for column 'date' at row 1
I have done some researching and I believe the problem is to do with the data that is being sent by my cfqueryparam function.
Here is my create function: -
<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>
-
As you can see i am just using the cf_sql_varchar cfsqltype, as I'm not sure which is best suited.
I have tryed running the following test query which works fine: -
INSERT INTO
-
projects
-
(
-
id,
-
priority,
-
type,
-
title,
-
location,
-
description,
-
body,
-
image,
-
image_alt,
-
movie,
-
pdf_doc,
-
word_doc,
-
date,
-
time,
-
archive,
-
display
-
)
-
VALUES
-
(
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
'',
-
''
-
)
-
The cfqueryparam function must be doing something and I don't know what.
Does anyone know what the problem is?
Thanks,
chromis
13 32680 acoder 16,027
Recognized Expert Moderator MVP
What's the format/data type of the date field?
What's the format/data type of the date field?
The date field in the db is date.
acoder 16,027
Recognized Expert Moderator MVP
Then use CF_SQL_DATE for the cfsqltype.
Ok thanks that sorted the date error, but I'm getting a new error with my time argument, the cfqueryparam for that is <cfqueryparam cfsqltype="cf_s ql_time" value="#argumen ts.time#" /> and the data type is time in the db.
Error:
The cause of this output exception was that: java.lang.NullP ointerException .
So the database is getting a null value? I've enabled null for the time field in the db, but still the same problem. Any ideas?
acoder 16,027
Recognized Expert Moderator MVP
Check the docs for the cfqueryparam tag ( link for CF8) and match the cfsqltype with the ones in your database.
Hmm, I've read through those, but still struggling, here are my mappings: - CREATE TABLE IF NOT EXISTS `projects` (
-
`id` int(11) NOT NULL auto_increment,
-
`priority` tinyint(4) NOT NULL default '0',
-
`type` varchar(12) NOT NULL default '',
-
`title` text NOT NULL,
-
`location` varchar(64) NOT NULL default '',
-
`description` text NOT NULL,
-
`body` longtext NOT NULL,
-
`image` varchar(128) NOT NULL default '',
-
`image_alt` varchar(128) NOT NULL default '',
-
`movie` varchar(128) NOT NULL default '',
-
`pdf_doc` varchar(128) NOT NULL default '',
-
`word_doc` varchar(128) NOT NULL default '',
-
`date` date default '0000-00-00',
-
`time` time default '00:00:00',
-
`archive` tinyint(1) NOT NULL default '0',
-
`display` tinyint(1) NOT NULL default '1',
-
PRIMARY KEY (`id`)
-
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
-
- <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" null="yes" />,
-
<cfqueryparam cfsqltype="cf_sql_tinyint" 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_date" value="#arguments.date#" />,
-
<cfqueryparam cfsqltype="cf_sql_time" value="#arguments.time#" />,
-
<cfqueryparam cfsqltype="cf_sql_tinyint" value="#arguments.archive#" />,
-
<cfqueryparam cfsqltype="cf_sql_tinyint" value="#arguments.display#" />
Is there anything wrong in the above?
I'm getting this error now: Invalid data for CFSQLTYPE CF_SQL_TINYINT.
acoder 16,027
Recognized Expert Moderator MVP
Where you have blank values and default ones and not strings, e.g. integers, date, time, etc., use NULL, i.e. null="yes".
Ah great that's working now, thanks again acoder!
acoder 16,027
Recognized Expert Moderator MVP
No problem at all. You're welcome :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Arabian143 |
last post by:
Hey everyone ..
i have a website going .. .. ofcourse you use the Ws-FTP to upload the
photos to the page .. and i have to use SQL program to insert the file
names and values into the Database ..
|
by: RDRaider |
last post by:
How can I find which record(s) cause this error:
Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.
I have tried Profiler but I can't get it to tell me which records are
causing the error.
Here's the script I'm running:
EXEC sp_executesql N'UPDATE IMDISFIL_SQL
|
by: Bernie Yaeger |
last post by:
What causes the error 'string or binary data would be truncated'? Here's
the routine that sometimes causes the error, sometimes not:
irow("ctotal") = FormatCurrency(irow("total"), 2, TriState.False,
TriState.True, TriState.True)
ctotal is a char column in an sql server table; total is a currency column
in the same table. Notwithstanding, the conversion appears to be made, even
though the exception is being thrown.
Any help would be...
|
by: languy |
last post by:
Hi there
I'm having a problem when using the SqlDataAdapter. When calling the
Update(DataSet, string) method I get the following error message "String or
binary data would be truncated". The rows neither have data that exceeds
8000 chars nor contain any LOB fields. Furthermore the data is transferred
between two tables that are bitwise identical.
-- snip --
System.Data.SqlClient.SqlCommand command =
|
by: dileepkumar |
last post by:
I'm trying to save file data to sqlserver. file data is converted to sysyte.io.stream and passed through webservice and in Business layer i changed the stream to byte array and passed it as a parameter to my stored procedure. Image file or storing in database. but when i try to save a text file its giving an exception "string or binary data would be truncated \r\n the statement has terminated".
I used sqlDBType.Image for the parameter tyep....
| |
by: Coldfire |
last post by:
i am having error ....details are
ASP.Net application...in which I have a textbox
<asp:TextBox ID="Other" TextMode=SingleLine CssClass="serviceBox" Width="250" Height="45" Runat="server" MaxLength="1000" /></asp:TextBox>
and this textbox is in a <asp:Repeater > which has the count of 35.
The textbox value is stored in the SQL DB
And the field data-type in the SQL DB is VARCHAR(1000)
|
by: Juan Carlos Espinoza |
last post by:
i have a problem
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data truncated for column 'FGiroNPagDol' at row 1
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:717)
at com.mysql.jdbc.MysqlIO.scanForAndThrowDataTruncation(MysqlIO.java:3183)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1874)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
at...
|
by: sunkesula |
last post by:
I update a field in the database that gives the last update time.
The first time I edit the item it puts a value in this field.
The second time the applications fails with The statement has been terminated. String or binary data would be truncated.
What's the deal?? There is enough space for the date/time so I am not sure what is going on here.. Anyone have any ideas?
|
by: david |
last post by:
I've noticed that the following compiles (as C) under both VS8 and gcc
with no warnings, even though there's a possibility of data truncation
from enum to unsigned char. It does generate a warning under VS6,
however. Under VS8, I enabled run-time checks, including /RTCc
(smaller type check), but still no warning. The only way I can get a
warning under VS8 is if I configure it to compile as C++.
Two questions:
(1) why doesn't /RTCc...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |