MySQL Null Field
5 Message(s) by 3 Author(s) originally posted in cfml database access
| From: MK_Ultra |
Date: Tuesday, October 23, 2007
|
We are changing the
database our
website uses from MS-SQL to MySQL and in the
course of
testing it I have found that the following piece of
code will give an
error "Incorrect
integer value: for column GraftYear" if the user doesn't
type
anything for the graft year value, which is optional.
<CFQUERY name="insertblocks" >
INSERT T_Block (Season,KPIN,BlockName,GraftYear,CreateDtTm)
VALUES (
<CFQUERYPARAM value= "#request.season#" cfsqltype="cf_sql_varchar" maxLength
= "4">,
<CFQUERYPARAM value= "#attributes.kpin#" cfsqltype="cf_sql_integer">,
<CFQUERYPARAM value="#UCase(Trim(blockdetails[i][1]))#"
cfsqltype="cf_sql_varchar" maxLength = "30">,
<CFQUERYPARAM value="#blockdetails[i][5]#" cfsqltype="cf_sql_varchar"
maxLength = "4">,
#CreateODBCDateTime(Now())#)
</CFQUERY>
It works fine with MS-SQL, which inserts the value 0 when passed an empty
string , which is what I think is happening here in this case. When I do a
manual insertion on the
table with an empty string then MySQL stores a zero the
same as MS. I know that I'll have similar problems with other parts of the
site so I am wondering if there is a reason why this is happening. The table is
set to allow
null values in this field, and the default value is NULL. Should I
set the default value to zero maybe?
Any help much appreciated...
| From: cf_dev2 |
Date: Wednesday, October 24, 2007
|
Incorrect integer value
For one thing, if GraftYear is an "integer" the cfsqltype should not be
cf_sql_integer not "cf_sql_varchar". Similar
comment about the CreateDtTm
column cfsqltype. Should not it be cf_sql_date, cf_sql_timestamp, etc?
If you want to insert a 0 when the
variable is an empty string, you can use
the
ColdFusion val() function. It converts non-numeric values to 0. If you want to
insert a NULL when the value entered isn't numeric try using a conditional
test within the "null" attribute.
<CFQUERYPARAM value="#theVariable#" cfsqltype="cf_sql_integer" null="#not
IsNumeric(theVariable)#">
<CFQUERYPARAM
| From: cf_dev2 |
Date: Wednesday, October 24, 2007
|
should not be cf_sql_integer
Argh. The CFSQLTYPE [i]should[/i] be cf_sql_integer.
| From: MK_Ultra |
Date: Wednesday, October 24, 2007
|
I changed it to the following:
<CFQUERYPARAM value="#Val(blockdetails[i][5])#" cfsqltype="cf_sql_integer"
maxLength = "4">
and it works the same as with MS-SQL, which didn't mind that CFSQLTYPE was
incorrectly set to varchar. I had to use Val, otherwise it still gave an error.
Thanks!
| From: GArlington |
Date: Wednesday, October 24, 2007
|
wrote in message:
I changed it to the following:
<CFQUERYPARAM value="#Val(blockdetails[i][5])#" cfsqltype="cf_sql_integer"
maxLength = "4">
and it works the same as with MS-SQL, which didn't mind that CFSQLTYPE was
incorrectly set to varchar. I had to use Val, otherwise it still gave an error.
Thanks!
Please, read ColdFusion docs on
<CFQUERYPARAM ...> nd pay attention to "null"
attribute.
Next Message: Problem accessing MS Access database
Blogs related to MySQL Null Field
How to cite a web site - Transaction essentials } finally ...
... Session session1 =
null; Session session2 =
null; try { utx.begin(); session1 = auctionDatabase.openSession(); session2 = billingDatabase.openSession(); concludeAuction(session1); billAuction(session2); session1.flush();
...
CHAPTER 10 Transactions and concurrency utx.rollback(); } catch
With these two settings enabled the code can be simplified to the following: UserTransaction utx = (UserTransaction) new InitialContext() .lookup(”java:comp/UserTransaction”); Session session1 =
null; Session session2 =
null;
...
Web site management - Transaction essentials 10.1.3 Transactions ...
Here it is again with exception handling: EntityManager em =
null; EntityTransaction tx =
null; try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); concludeAuction(em); tx.commit(); } catch (RuntimeException ex)
...
Web hosting domains - CHAPTER 10 Transactions and concurrency ...
... you need to call the JTA UserTransaction interface to control transaction boundaries programmatically: UserTransaction utx = (UserTransaction) new InitialContext() .lookup(”java:comp/UserTransaction”); EntityManager em =
null;
...
mysql web applications
... mysql where datetime
mysql where
field mysql where id
mysql where id in
mysql where in
mysql where in array
mysql where in clause
mysql where in select
mysql where in syntax
mysql where is not
mysql where is not
null mysql where
...
Re: Trouble storing monetary values in MySQL 5
Here's a column def I use with
MySQL 5: > > hourlyRate decimal(10,2) not
null > > That says use 2 fractional digits and 8 (10 - 2) integral digits. > > cheers, > barneyb > > On 9/30/07, Rick Faircloth wrote: > > Hi, all.
...