473,602 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data truncation: Data truncated for column 'date' at row 1

113 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1.     <cffunction name="create" access="public" output="false" returntype="struct" hint="CRUD Method">
  2.         <!--- arguments for the constructor, all of which are optional (no-arg constructor) --->
  3.         <cfargument name="dsn" displayName="dsn" type="string" hint="Datasource name" 
  4.             required="true" default="" />        
  5.         <cfargument name="id" displayName="id" type="string" hint="The project ID (UUID)" 
  6.             required="true" default="0" />    
  7.         <cfargument name="priority" displayName="priority" type="string" hint="The project priority (Sort order)" 
  8.             required="false" default="1" />
  9.         <cfargument name="type" displayName="type" type="string" hint="The project type" 
  10.             required="false" default="" />            
  11.         <cfargument name="title" displayName="title" type="string" hint="The project title" 
  12.             required="false" default="" />
  13.         <cfargument name="location" displayName="location" type="string" hint="The project location"
  14.             required="false" default="" />
  15.         <cfargument name="description" displayName="description" type="string" hint="The project description"
  16.             required="false" default="" />             
  17.         <cfargument name="body" displayName="body" type="string" hint="The project body description"
  18.             required="false" default="" />                   
  19.         <cfargument name="image" displayName="image" type="string" hint="The project image name" 
  20.             required="false" default="" />
  21.         <cfargument name="image_alt" displayName="image_alt" type="string" hint="The project image alternative text"
  22.             required="false" default="" />
  23.         <cfargument name="movie" displayName="movie" type="string" hint="The project movie"
  24.             required="false" default="" />            
  25.         <cfargument name="pdf_doc" displayName="pdf_doc" type="string" hint="The project pdf reference" 
  26.             required="false" default="" />            
  27.         <cfargument name="word_doc" displayName="word_doc" type="string" hint="The project work doc reference" 
  28.             required="false" default="" />                   
  29.         <cfargument name="date" displayName="date" type="string" hint="The date the project was added"
  30.             required="false" default="" /> 
  31.         <cfargument name="time" displayName="time" type="string" hint="The time the project was added"
  32.             required="false" default="" />             
  33.         <cfargument name="archive" displayName="archive" type="string" hint="The project should be archived"
  34.             required="false" default="" />       
  35.         <cfargument name="display" displayName="display" type="string" hint="The project should be shown"
  36.             required="false" default="" />  
  37.  
  38.         <!--- initialize variables --->
  39.         <cfset var results = StructNew() />
  40.         <cfset var qInsert = 0 />
  41.  
  42.         <!--- defaults --->
  43.         <cfset results.success = true />
  44.         <cfset results.message = "The project was inserted successfully." />
  45.  
  46.         <!--- <cftry> --->
  47.             <cftransaction>
  48.                 <cfquery name="qInsert" datasource="#arguments.dsn#">
  49.                     INSERT INTO
  50.                     projects
  51.                     (
  52.                         id,
  53.                         priority,
  54.                         type,
  55.                         title,
  56.                         location,
  57.                         description,
  58.                         body,
  59.                         image,
  60.                         image_alt,
  61.                         movie,
  62.                         pdf_doc,
  63.                         word_doc,                        
  64.                         date,
  65.                         time,
  66.                         archive,
  67.                         display
  68.                     )
  69.                     VALUES
  70.                     (
  71.                         <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" null="yes" />,
  72.                         <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.priority#" />,
  73.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.type#" />,                        
  74.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.title#" />,
  75.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.location#" />,
  76.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.description#" />,                        
  77.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.body#" />,
  78.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.image#" />,
  79.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.image_alt#" />,
  80.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.movie#" />,                        
  81.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.pdf_doc#" />,       
  82.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.word_doc#" />,                                           
  83.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.date#" />,
  84.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.time#" />,                        
  85.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.archive#" />,
  86.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.display#" />                                                            
  87.                     )
  88.                 </cfquery>
  89.  
  90.                 <!--- Select insert id --->
  91.                 <cfquery name="qMaxID" datasource="#arguments.dsn#">
  92.                     SELECT max( id ) AS maxID FROM projects
  93.                 </cfquery>
  94.  
  95.                 <!--- Add last insert id to results --->   
  96.                 <cfset results.lastInsertID = StructFind(qMaxID,"maxID") />       
  97.  
  98.             </cftransaction>  
  99.         <!--- 
  100.             <cfcatch type="database">
  101.                 <cfset results.success = false />
  102.                 <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." />
  103.                 <cfif cfcatch.detail NEQ "">
  104.                     <cfset results.message = results.message & "Error details: <br />" & cfcatch.detail />
  105.                 </cfif>
  106.             </cfcatch>
  107.         </cftry> --->
  108.  
  109.         <!--- return the struct --->
  110.         <cfreturn StructCopy(results) />
  111.       </cffunction>   
  112.  
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:

Expand|Select|Wrap|Line Numbers
  1.                     INSERT INTO
  2.                     projects
  3.                     (
  4.                         id,
  5.                         priority,
  6.                         type,
  7.                         title,
  8.                         location,
  9.                         description,
  10.                         body,
  11.                         image,
  12.                         image_alt,
  13.                         movie,
  14.                         pdf_doc,
  15.                         word_doc,                        
  16.                         date,
  17.                         time,
  18.                         archive,
  19.                         display
  20.                     )
  21.                     VALUES
  22.                     (
  23.                         '',
  24.                         '',
  25.                         '',                        
  26.                         '',
  27.                         '',
  28.                         '',                        
  29.                         '',
  30.                         '',
  31.                         '',
  32.                         '',                        
  33.                         '',       
  34.                         '',                                           
  35.                         '',
  36.                         '',                        
  37.                         '',
  38.                         ''                                                            
  39.                     )
  40.  
The cfqueryparam function must be doing something and I don't know what.

Does anyone know what the problem is?

Thanks,

chromis
Nov 21 '08 #1
13 32680
acoder
16,027 Recognized Expert Moderator MVP
What's the format/data type of the date field?
Nov 21 '08 #2
chromis
113 New Member
What's the format/data type of the date field?
The date field in the db is date.
Nov 21 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Then use CF_SQL_DATE for the cfsqltype.
Nov 21 '08 #4
chromis
113 New Member
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?
Nov 21 '08 #5
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.
Nov 21 '08 #6
chromis
113 New Member
Hmm, I've read through those, but still struggling, here are my mappings:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE IF NOT EXISTS `projects` (
  2.   `id` int(11) NOT NULL auto_increment,
  3.   `priority` tinyint(4) NOT NULL default '0',
  4.   `type` varchar(12) NOT NULL default '',
  5.   `title` text NOT NULL,
  6.   `location` varchar(64) NOT NULL default '',
  7.   `description` text NOT NULL,
  8.   `body` longtext NOT NULL,
  9.   `image` varchar(128) NOT NULL default '',
  10.   `image_alt` varchar(128) NOT NULL default '',
  11.   `movie` varchar(128) NOT NULL default '',
  12.   `pdf_doc` varchar(128) NOT NULL default '',
  13.   `word_doc` varchar(128) NOT NULL default '',
  14.   `date` date default '0000-00-00',
  15.   `time` time default '00:00:00',
  16.   `archive` tinyint(1) NOT NULL default '0',
  17.   `display` tinyint(1) NOT NULL default '1',
  18.   PRIMARY KEY  (`id`)
  19. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
  20.  
Expand|Select|Wrap|Line Numbers
  1.                         <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" null="yes" />,
  2.                         <cfqueryparam cfsqltype="cf_sql_tinyint" value="#arguments.priority#" />,
  3.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.type#" />,                        
  4.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.title#" />,
  5.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.location#" />,
  6.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.description#" />,                        
  7.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.body#" />,
  8.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.image#" />,
  9.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.image_alt#" />,
  10.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.movie#" />,                        
  11.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.pdf_doc#" />,       
  12.                         <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.word_doc#" />,                                           
  13.                         <cfqueryparam cfsqltype="cf_sql_date" value="#arguments.date#" />,
  14.                         <cfqueryparam cfsqltype="cf_sql_time" value="#arguments.time#" />,                        
  15.                         <cfqueryparam cfsqltype="cf_sql_tinyint" value="#arguments.archive#" />,
  16.                         <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.
Nov 21 '08 #7
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".
Nov 21 '08 #8
chromis
113 New Member
Ah great that's working now, thanks again acoder!
Nov 21 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
No problem at all. You're welcome :)
Nov 21 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
18814
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 ..
3
40173
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
1
2803
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...
1
8064
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 =
0
1752
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....
7
17699
Coldfire
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)
12
4784
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...
2
19315
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?
2
2610
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...
0
7993
marktang
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...
0
7920
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,...
0
8401
Oralloy
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...
0
8404
jinu1996
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...
0
6730
agi2029
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...
0
3900
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...
1
2418
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
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.