Skip to content

Microseconds #249

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

Merged
merged 14 commits into from
Sep 8, 2014
Merged

Microseconds #249

merged 14 commits into from
Sep 8, 2014

Conversation

arnehormann
Copy link
Member

first attempt to add full support for microsecond resolution, comes with a major improvement of the tests for TIME, DATE and DATETIME.

At the very least, this can be built upon.

passes all tests except TIME(1) -> string in binary protocol.
TIMESTAMP support with microsecond resolution is still incomplete.
@julienschmidt julienschmidt added this to the v1.3 milestone Jun 3, 2014
@arnehormann
Copy link
Member Author

Travis fails because Go 1.1 does not support positional parameters in fmt.Sprintf yet and the MySQL version is to old to recognize DATETIME/DATE/TIME with fractional seconds syntactically.
I'll adapt the tests so we skip the syntax-problems where applicable and get rid of the positional parameter.

@arnehormann
Copy link
Member Author

phew @julienschmidt PTAL

All others: please have a look at it, too.
First off, I'm sorry for the noise, I couldn't debug this locally.
Second, we are now able to specify the microsecond resolution to the digit.
Yay!

@arnehormann arnehormann changed the title Microsecs Microseconds Jun 5, 2014
name string
length uint32 // length as string: DATETIME(4) => 24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this field? I can only see it being set, not read somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a time when I deeply mistrusted the decimals field, I did use it.
I think we should still keep it for two reasons:

  • it provides a hint useable for the maximal allocation size in all types
  • with it, mysqlField is perfectly aligned on 64bit boundaries

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use it, we don't need it 😄 #YAGNI

Regarding alignment: The compiler takes care of it if matters on the target architecture. On a 32bit architecture this is just a waste of space.

@arnehormann
Copy link
Member Author

PTAL

@julienschmidt
Copy link
Member

Sorry, I don't have forgotten you, but I currently don't have the time to review this properly (exams phase; double credit load).
These changes are quite complex and should be carefully reviewed IMO.
Please excuse me for needing some more time.

I invite anyone else to review the changes and write their opinion 😉

dstlen = 8
case 1, 2, 3, 4, 5, 6:
dstlen = 8 + 1 + decimals
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A default case is missing to handle decimals you don't know about (e.g. from garbled protocol data).
If dstlen == 0 is the correct answer already, please make it explicit.

@arnehormann
Copy link
Member Author

PTAL - and thanks for the review, @nightlyone

@nightlyone
Copy link

LGTM, but please wait for @julienschmidt

@arnehormann
Copy link
Member Author

As by our policy, I will.
Each PR has to be LGTMed by a team member - and I won't/can't LGTM my own code.

Again, thanks for the review!

@julienschmidt
Copy link
Member

Many thanks from me also!
I'll try to do a review ASAP, hopefully this evening or tomorrow.

@@ -11,7 +11,6 @@ package mysql
const (
minProtocolVersion byte = 10
maxPacketSize = 1<<24 - 1
timeFormat = "2006-01-02 15:04:05"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not leave this here instead moving it to utils.go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I thought it's only used in utils.go, but that's wrong.
It's also used in packets.go.
I'll change that.

@julienschmidt
Copy link
Member

Did you test this with older MySQL versions? I'm still not convinced that this doesn't break the compatibility, especially the tests 😉

@arnehormann
Copy link
Member Author

I did on 5.0.35 - and the Travis version is pretty old, too.

rows, err = dbt.db.Query(`SELECT cast("00:00:00.1" as TIME(1)) = "00:00:00.1"`)
if err == nil {
    rows.Scan(&withFrac)
    rows.Close()
}

is the part in the tests allowing for backward compatibility - it skips tests the server doesn't support.

@julienschmidt
Copy link
Member

Lets trade: One LGTM for one successful MySQL 4.1 test 😄

@arnehormann
Copy link
Member Author

4.1.12 on a Win XP VM successfully tested.
But I cheated (a little).
PTAL - still LGTM (pretty please)?

@julienschmidt
Copy link
Member

fine 😒

@arnehormann
Copy link
Member Author

I checked and confirmed that a timestamp can be stored in a table and retrieved from it, I also started on a test. Will probably commit and merge it tomorrow. Let's turn that frown upside down..

arnehormann added a commit that referenced this pull request Sep 8, 2014
@arnehormann arnehormann merged commit 8111ee3 into go-sql-driver:master Sep 8, 2014
@arnehormann arnehormann deleted the microsecs branch September 8, 2014 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants