Format column throw exception when this column contains null value - ms-access

I have a table that naming MVorders. it contains a column(orderdate) that type is date/time, and it's contains null value, then format column throw exception.
e.g. sql : SELECT format(MVorders.orderdate, "yyyy-MM-dd 00:00:00") FROM MVorders
Env: UCanAccess 4.0.4.
Thanks!
Reference:

SELECT IIF(ISNULL(orderdate), '', Format(orderdate, 'yyyy-MM-dd 00:00:00')) AS FormattedOrderDate FROM MVorders

You have encountered a known deficiency in the UCanAccess implementation of the FORMAT function. It has been reported to the UCanAccess development team.

Related

Attunity zero timestamp value insert into mySQL DB

we are using Attunity tool to insert data from mySQL Database into other mySQL Database and there is a problem with '0000-00-00 00:00:00' values in columns defined as a timestamp in source database.
Attunity task doesn`t return any error message, only run forever.
There is this sentence in a manual:
'If the DATETIME and TIMESTAMP data types are specified with a “zero” value (i.e. 0000-00-00), you need to make sure that the target database in the replication task supports "zero" values for the DATETIME and TIMESTAMP data types. If they are not supported, you can use a transformation to specify a supported value (e.g. 1970.) Otherwise, they will be recorded as null on the target.'
Neverthelessif I try to convert value using expression builder, by test expression function works, but by running the job same behavior, no error message just run doesnt finish and doesnt insert any values.
Tried following functions working in expression builder correctly:
replace($column_name, '0000-00-00 00:00:00','1000-01-01 00:00:00')
Expression builder supports SQLite functions.
CASE WHEN $column_name
= '0000-00-00 00:00:00'
THEN '1000-01-01 00:00:00' ELSE $column_name
END
It seems attunity tool first fail to insert data, just then performs the operation, and its too late afterwards.
Converting data type within attunity to string doesn`t help neither.
I run out of ideas what else to try.
Could you help?
Thank you

Google Apps Script - MySQL data import using JDCB does not work with Date 0000-00-00 [duplicate]

I have a database table containing dates
(`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00').
I'm using MySQL. From the program sometimes data is passed without the date to the database. So, the date value is auto assigned to 0000-00-00 00:00:00
when the table data is called with the date column it gives error
...'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp.......
I tried to pass null value to the date when inserting data, but it gets assign to the current time.
Is there any way I can get the ResultSet without changing the table structure?
You can use this JDBC URL directly in your data source configuration:
jdbc:mysql://yourserver:3306/yourdatabase?zeroDateTimeBehavior=convertToNull
Whether or not the "date" '0000-00-00" is a valid "date" is irrelevant to the question.
"Just change the database" is seldom a viable solution.
Facts:
MySQL allows a date with the value of zeros.
This "feature" enjoys widespread use with other languages.
So, if I "just change the database", thousands of lines of PHP code will break.
Java programmers need to accept the MySQL zero-date and they need to put a zero date back into the database, when other languages rely on this "feature".
A programmer connecting to MySQL needs to handle null and 0000-00-00 as well as valid dates. Changing 0000-00-00 to null is not a viable option, because then you can no longer determine if the date was expected to be 0000-00-00 for writing back to the database.
For 0000-00-00, I suggest checking the date value as a string, then changing it to ("y",1), or ("yyyy-MM-dd",0001-01-01), or into any invalid MySQL date (less than year 1000, iirc). MySQL has another "feature": low dates are automatically converted to 0000-00-00.
I realize my suggestion is a kludge. But so is MySQL's date handling.
And two kludges don't make it right. The fact of the matter is, many programmers will have to handle MySQL zero-dates forever.
Append the following statement to the JDBC-mysql protocol:
?zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=UTF-8&characterSetResults=UTF-8
for example:
jdbc:mysql://localhost/infra?zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=UTF-8&characterSetResults=UTF-8
Instead of using fake dates like 0000-00-00 00:00:00 or 0001-01-01 00:00:00 (the latter should be accepted as it is a valid date), change your database schema, to allow NULL values.
ALTER TABLE table_name MODIFY COLUMN date TIMESTAMP NULL
As an exteme turnaround, when you cannot do an alter to your date column or to update the values, or while these modifications take place, you can do a select using a case/when.
SELECT CASE ModificationDate WHEN '0000-00-00 00:00:00' THEN '1970-01-01 01:00:00' ELSE ModificationDate END AS ModificationDate FROM Project WHERE projectId=1;
you can try like This
ArrayList<String> dtlst = new ArrayList<String>();
String qry1 = "select dt_tracker from gs";
Statement prepst = conn.createStatement();
ResultSet rst = prepst.executeQuery(qry1);
while(rst.next())
{
String dt = "";
try
{
dt = rst.getDate("dt_tracker")+" "+rst.getTime("dt_tracker");
}
catch(Exception e)
{
dt = "0000-00-00 00:00:00";
}
dtlst.add(dt);
}
I wrestled with this problem and implemented the URL concatenation solution contributed by #Kushan in the accepted answer above. It worked in my local MySql instance. But when I deployed my Play/Scala app to Heroku it no longer would work. Heroku also concatenates several args to the DB URL that they provide users, and this solution, because of Heroku's use concatenation of "?" before their own set of args, will not work. However I found a different solution which seems to work equally well.
SET sql_mode = 'NO_ZERO_DATE';
I put this in my table descriptions and it solved the problem of
'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
There was no year 0000 and there is no month 00 or day 00. I suggest you try
0001-01-01 00:00:00
While a year 0 has been defined in some standards, it is more likely to be confusing than useful IMHO.
just cast the field as char
Eg: cast(updatedate) as char as updatedate
I know this is going to be a late answer, however here is the most correct answer.
In MySQL database, change your timestamp default value into CURRENT_TIMESTAMP. If you have old records with the fake value, you will have to manually fix them.
You can remove the "not null" property from your column in mysql table if not necessary. when you remove "not null" property no need for "0000-00-00 00:00:00" conversion and problem is gone.
At least worked for me.
I believe this is help full for who are getting this below Exception on to pumping data through logstash
Error: logstash.inputs.jdbc - Exception when executing JDBC query {:exception=>#}
Answer:jdbc:mysql://localhost:3306/database_name?zeroDateTimeBehavior=convertToNull"
or if you are working with mysql

cakePHP incorrect datetime format

I am new to cakePHP.
Currently I am facing this trouble, it show me this error when I login to cakePHP project.
**Database Error**
Error: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2015-10-22T15:42:20+08:00' for column 'last_login' at row 1
SQL Query: UPDATE `cakephpdb`.`users` SET `last_login` = '2015-10-22T15:42:20+08:00', `modified` = '2015-10-22 15:42:20' WHERE `cakephpdb`.`users`.`id` = '37'
I think this can be configure in cakePHP config file (which just edit in 1 file that can affect the entire project) or maybe change the MySQL setting.
Below is detail:
CakePHP project: Hosted and run in IIS server
MySQL: in another server
MySQL version: 5.5.38
Many thanks for help! Thank you.
Invalid datetime format: 1292 Incorrect datetime value: '2015-10-22T15:42:20+08:00'
Pass the correct datetime format: YYY-MM-DD HH:MM:SS This is what I would assume the field expects. Use date() to reformat your date or the DateTime class of whatever CakePHP version you're using.
I think here is the format of datatime you are trying to pass is the issue.
Make it change with PHP date function in proper format (YYYY-MM-DD HH:MM:SS).
date('Y-m-d H:i:s',strtotime($yourdate));
I think this will work in this case.
Thanks.
Very weird that if I am using XAMPP at localhost, it can be store perfectly. But when I launch in live (using IIS), it can't store with this datetime format "2015-10-22T15:42:20+08:00".
So I found out that cakePHP is using:
date(DATE_ATOM)
I change it to:
date('Y-m-d H:i:s')
now is it worked.
Thanks to #burzum and #Chandresh. :)

BLToolKit: how to fetch 'empty' datetime field?

Request Execute is failed if one of fields to be mapped has DateTime field and corresponding value in DB has '0000-00-00' or '0001-01-01'. The following error is returned
Unable to convert MySQL date/time value to System.DateTime
Is there any possibility to fetch such value?
I've tried to specify the 'DateTime?' value as property type - it doesn't help too (actually, I didn't expect that to be helpful).
P.S. I use MySql 5.1
I came across a similar problem using NHibernate with the same error in an exception.
It's due to MySQL's unique "feature" of allowing invalid dates in a DATE field, especially using 0000-00-00 as a default value for DATE NOT NULL columns. When such a date is encountered, it throws an exception when converting itself to a DateTime.
The suggested solution for this was to add
Allow Zero Datetime=True;
to the connection string, however in practice this did not work for me. I eventually solved the problem by altering the connection string adding
Convert Zero DateTime=true;
so your app.config section would look something like this
<connectionStrings>
<add
name="ConnectionString.MySql"
connectionString="Server=localhost;Port=3306;Database=BLT;Uid=someuser;Convert Zero DateTime=true;"
providerName="MySql.Data.MySqlClient"/>
Have you tried the MapValue attribute? I'm not sure if this will work but...
[MapValue(null, "0000-00-00")]
[MapValue(null, "0001-01-01")]
public DateTime? theDate;
i think you have to control it by another property.
[MapField("the_date")]
public DateTime? theDate; // Map
[MapIgnore]
public DateTime theDateControl
{
set {
if(theDate.HasValue)
{
....
}
}
}

Entity Framework - MySQL - Datetime format issue

I have a simple table with few date fields.
Whenever I run following query:
var docs = ( from d in base.EntityDataContext.document_reviews
select d ).ToList();
I get following exception:
Unable to convert MySQL date/time value to System.DateTime.
MySql.Data.Types.MySqlConversionException: Unable to convert MySQL date/time value to System.DateTime
The document reviews table has two date/time fields. One of them is nullable.
I have tried placing following in connection string:
Allow Zero Datetime=true;
But I am still getting exception.
Anyone with a solution?
#effkay - if you solved this it would be great if you could post the answer.
Also if anyone else has a solution that would be great too :).
Edit:
The solution can be found in the http://dev.mysql.com/doc/refman/5.1/en/connector-net-connection-options.html connector documentation.
I needed to set "Convert Zero Datetime" to true, and now it works.
hth.
You need to set Convert Zero Datetime=True in connection string of running application