Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting wrong time for large hours values (hhh:mm:ss) #70

Closed
skogamor opened this issue Mar 1, 2021 · 8 comments
Closed

Exporting wrong time for large hours values (hhh:mm:ss) #70

skogamor opened this issue Mar 1, 2021 · 8 comments

Comments

@skogamor
Copy link

skogamor commented Mar 1, 2021

I have a column that shows the difference between two dates as TIME type. According to the MySQL reference, TIME can contain large hours values ("hhh: mm: ss").
When exporting the table, all hours > 24 are currently truncated.

@adriancs2
Copy link
Member

Thanks for the info. Will work on this.

@adriancs2
Copy link
Member

adriancs2 commented Mar 2, 2021

I have modified the source code. You may test with the following file and see if the problem still exist
MySqlBackup(NetFramework)_debug_issue_70_v1.zip

I have modified the file
/methods/QueryExpress.cs
line 332
change from

sb.AppendFormat(dtime.ToString("HH:mm:ss", _dateFormatInfo));

to

sb.AppendFormat("{0}:{1}:{2}", mdt.Hour, mdt.Minute, mdt.Second);

@skogamor
Copy link
Author

skogamor commented Mar 2, 2021

Thanks for the fast respond. Your change looks good, but the result is still the same as before.
However, I am not sure whether I have integrated the package correctly. So far I had this as a NuGet package. I just replaced the old reference with the MySqlBackup.dll from bin/Release/.

@skogamor
Copy link
Author

skogamor commented Mar 6, 2021

@adriancs2
Today I finally had some time to debug your code. In my case the object ob is of type TimeSpan.
So in /methods/QueryExpress.cs I made some minor changes (line 277ff):

else if (ob is TimeSpan)
{
    TimeSpan ts = (TimeSpan)ob;
    int tsTotalHours = (int)ts.TotalHours;
    int tsHours = (tsTotalHours >= 24 || tsTotalHours <= -24) ? tsTotalHours : ts.Hours;

    if (wrapStringWithSingleQuote)
        sb.AppendFormat("'");
    
    sb.AppendFormat(tsHours.ToString().PadLeft(2, '0'));
    sb.AppendFormat(":");
    sb.AppendFormat(ts.Duration().Minutes.ToString().PadLeft(2, '0'));
    sb.AppendFormat(":");
    sb.AppendFormat(ts.Duration().Seconds.ToString().PadLeft(2, '0'));

    if (wrapStringWithSingleQuote)
        sb.AppendFormat("'");
}

Added:

int tsTotalHours = (int)ts.TotalHours;
int tsHours = (tsTotalHours >= 24 || tsTotalHours <= -24) ? tsTotalHours : ts.Hours;

Changed:
sb.AppendFormat(ts.Hours.ToString().PadLeft(2, '0')); to sb.AppendFormat(ts.Hours.ToString().PadLeft(2, '0'));

This works fine for me.

@adriancs2
Copy link
Member

adriancs2 commented Mar 6, 2021

@skogamor
Nice work!

Here is the second edit, you may try it out:
MySqlBackup(NetFramework)_debug_issue_70_v2.zip

Since the ts.TotalHours is needed to be cast as anyway, so I applied (int)ts.TotalHours directly in the AppendFormat:

else if (ob is TimeSpan)
{
	TimeSpan ts = (TimeSpan)ob;

	if (wrapStringWithSingleQuote)
		sb.AppendFormat("'");

	sb.AppendFormat(((int)ts.TotalHours).ToString().PadLeft(2, '0'));
	sb.AppendFormat(":");
	sb.AppendFormat(ts.Minutes.ToString().PadLeft(2, '0'));
	sb.AppendFormat(":");
	sb.AppendFormat(ts.Seconds.ToString().PadLeft(2, '0'));

	if (wrapStringWithSingleQuote)
		sb.AppendFormat("'");
}

@skogamor
Copy link
Author

skogamor commented Mar 6, 2021

@adriancs2
Yep, that seems to work too.
I forgot to mention this in my last post .. I recommend adding ts.Duration(). for minutes and seconds. Otherwise, the sb for negative times is something like '-10:-30:-15'.

Do you already know when the next release will appear?

@adriancs2
Copy link
Member

adriancs2 commented Mar 10, 2021

@skogamor
Hi, new nuget package is released. You may download it at the following:
https://github.com/MySqlBackupNET/MySqlBackup.Net/releases
https://www.nuget.org/packages/MySqlBackup.NET/
Alternatively, you may include the source code directly into your project.

@skogamor
Copy link
Author

@adriancs2
Hi, the issue has been fixed with latest new nuget package.
thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants