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

server: fix insert zero timestamp bug with prepared statement #7506

Merged
merged 5 commits into from
Aug 28, 2018
Merged

server: fix insert zero timestamp bug with prepared statement #7506

merged 5 commits into from
Aug 28, 2018

Conversation

lysu
Copy link
Contributor

@lysu lysu commented Aug 27, 2018

What problem does this PR solve?

fixes #7501

What is changed and how it works?

in protocol layer return "types.ZeroDatetimeStr" instead of "0" to make later types.parseDatetime happy.

Check List

Tests

  • Unit test
  • Manual test
    mysql_stmt= mysql_stmt_init(&mysql);
    if(!mysql_stmt)
    {
        my_chk_stmt(&mysql, mysql_stmt, __LINE__);
    }

    stmt= const_cast<char *>("INSERT INTO timestamp_insert ( id, tstamp ) VALUES ( ?, ? )");
    if(mysql_stmt_prepare(mysql_stmt, stmt, strlen(stmt)))
    {
        my_chk_stmt(&mysql, mysql_stmt, __LINE__);
    }

    memset(mysql_bind_param, 0, sizeof(mysql_bind_param));
    mysql_bind_param[0].buffer_type= MYSQL_TYPE_LONG;
    mysql_bind_param[0].buffer= (char*)&id;
    mysql_bind_param[0].is_null= 0;
    mysql_bind_param[0].length= 0;
    mysql_bind_param[1].buffer_type= MYSQL_TYPE_TIMESTAMP;
    mysql_bind_param[1].buffer= &tstamp;
    mysql_bind_param[1].is_null= 0;
    mysql_bind_param[1].length= 0;
    if(mysql_stmt_bind_param(mysql_stmt, mysql_bind_param))
    {
        my_chk_stmt(&mysql, mysql_stmt, __LINE__);
    }

    tstamp.year= 0;
    tstamp.month= 0;
    tstamp.day= 0;
    tstamp.hour= 0;
    tstamp.minute= 0;
    tstamp.second= 0;
    tstamp.second_part= 0;

    if(mysql_stmt_execute(mysql_stmt))
    {
        my_chk_stmt(&mysql, mysql_stmt, __LINE__);
    }

Code changes

  • impl change

Side effects

  • no

Related changes

  • Need to cherry-pick to the release branch
  • Need to be included in the release note

This change is Reviewable

@lysu lysu added type/compatibility type/bugfix This PR fixes a bug. labels Aug 27, 2018
@lysu
Copy link
Contributor Author

lysu commented Aug 27, 2018

/run-all-tests

@lysu lysu requested a review from jackysp August 27, 2018 14:13
@@ -354,7 +354,7 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy
pos++
switch length {
case 0:
args[i] = "0"
args[i] = "00000000000000"
Copy link
Member

Choose a reason for hiding this comment

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

Use a constant.

@@ -120,7 +120,7 @@ func (ts ConnTestSuite) TestParseStmtArgs(c *C) {
[]byte{0x00},
},
nil,
"0",
"00000000000000",
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@jackysp
Copy link
Member

jackysp commented Aug 28, 2018

Why not add a case for types.parseDatetime?

@lysu
Copy link
Contributor Author

lysu commented Aug 28, 2018

@jackysp we don't modify that, I think modified ut cover first half part, and add a second half part integration test using 'prepare s from '....'' to re-display and show fix result is enough

jackysp
jackysp previously approved these changes Aug 28, 2018
Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

@jackysp jackysp dismissed their stale review August 28, 2018 04:14

Need another LGTM

@jackysp jackysp added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 28, 2018
Copy link

@imtbkcat imtbkcat left a comment

Choose a reason for hiding this comment

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

LGTM

@imtbkcat
Copy link

/run-all-tests

@lysu lysu merged commit 5b689e8 into pingcap:master Aug 28, 2018
@lysu lysu deleted the dev-fix-prepare-ts-zero-insert branch August 28, 2018 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1. type/bugfix This PR fixes a bug. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

insert timestamp failure with 0000-00-00 00:00:00.000000 in prepare statement
4 participants