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

A fraction part of datetime/timestamp value is truncated #62

Closed
uki00a opened this issue Jul 7, 2020 · 0 comments · Fixed by #63
Closed

A fraction part of datetime/timestamp value is truncated #62

uki00a opened this issue Jul 7, 2020 · 0 comments · Fixed by #63

Comments

@uki00a
Copy link
Member

uki00a commented Jul 7, 2020

Summary

  • The datetime/timestamp value can include a trailing fractional seconds part. (like this: YYYY-MM-DD hh:mm:ss[.fraction])
  • deno_mysql currently truncates a fraction part of these types.

Steps to reproduce

import { Client, Connection } from "https://deno.land/x/mysql@2.2.0/mod.ts";
import { assertEquals } from "https://deno.land/std@0.60.0/testing/asserts.ts";

const client = await new Client().connect({
  hostname: "localhost",
  port: 3306,
  username: "test",
  db: "test",
  password: "test",
});

await client.query(`DROP TABLE IF EXISTS test`);
await client.query(`CREATE TABLE test (
  id int(11) NOT NULL AUTO_INCREMENT,
  datetime datetime(6) NOT NULL,
  PRIMARY KEY (id)
) ENGINE=MEMORY DEFAULT CHARSET=utf8mb4`);

const datetime = new Date();
await client.execute(`
  INSERT INTO test (datetime)
  VALUES (?)`, [datetime]);

const expected = datetime;
const [{ datetime: actual }] = await client.query(`SELECT datetime FROM test`);
assertEquals(expected.toISOString(), actual.toISOString()); // See https://github.com/denoland/deno/issues/6643 for why not simply using `assertEquals(actual, expected)`.

Expected behavior:

The above code shouldn't fail.

Actual behavior:

The above code fails with the fowlloing logs:

INFO connecting localhost:3306
INFO connected to localhost
error: Uncaught AssertionError: Values are not equal:


    [Diff] Actual / Expected


-   "2020-07-07T19:32:24.464Z"
+   "2020-07-07T19:32:24.000Z"

  throw new AssertionError(message);
        ^
    at assertEquals (asserts.ts:183:9)
    at file:///home/uki00a/work/test.ts:22:1

Environment

  • deno v1.1.3
  • deno_mysql v2.2.0
  • MySQL v5.7

Ref

https://dev.mysql.com/doc/refman/5.6/en/datetime.html

@uki00a uki00a changed the title a faction part of datetime/timestamp value is truncated A faction part of datetime/timestamp value is truncated Jul 7, 2020
@uki00a uki00a changed the title A faction part of datetime/timestamp value is truncated A fraction part of datetime/timestamp value is truncated Jul 7, 2020
manyuanrong pushed a commit that referenced this issue Jul 12, 2020
Update sql_builder to v1.6.0
FIx #62
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

Successfully merging a pull request may close this issue.

1 participant