Bug #4026 Microseconds part of TIME/DATETIME types is broken (prepared statements)

Submitted: 6 Jun 2004 19:45 Modified: 9 Jun 2004 1:57
Reporter: Konstantin Osipov (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.* OS:Any (All)
Assigned to: Konstantin Osipov CPU Architecture:Any

[6 Jun 2004 19:45] Konstantin Osipov
Description:
Microseconds part provided in MYSQL_TIME structure is not returned from server as it's sent to
it.

How to repeat:
static void test_bugxxxx()
{
  MYSQL_STMT *stmt;
  MYSQL_BIND bind[2];
  MYSQL_TIME time_in, time_out;
  MYSQL_TIME datetime_in, datetime_out;
  const char *stmt_text;
  int rc;
    
  myheader("test_bugxxxx");

  /* Check that microseconds are inserted and selected successfully */

  /* Create statement handle and prepare it with select */
  stmt= mysql_stmt_init(mysql);
  stmt_text= "SELECT ?, ?";

  rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
  check_execute(stmt, rc);
  
  /* Bind input buffers */
  bzero(bind, sizeof(bind));
  bzero(&time_in, sizeof(time_in));
  bzero(&time_out, sizeof(time_out));
  bzero(&datetime_in, sizeof(datetime_in));
  bzero(&datetime_out, sizeof(datetime_out));

  bind[0].buffer_type= MYSQL_TYPE_TIME;
  bind[0].buffer= (char*) &time_in;
  bind[1].buffer_type= MYSQL_TYPE_DATETIME;
  bind[1].buffer= (char*) &datetime_in;
 time_in.hour= 23;
  time_in.minute= 59;
  time_in.second= 59;
  time_in.second_part= 123456;

  datetime_in= time_in;
  datetime_in.year= 2003;
  datetime_in.month= 12;
  datetime_in.day= 31;

  mysql_stmt_bind_param(stmt, bind);

  /* Execute the select statement */
  rc= mysql_stmt_execute(stmt);
  check_execute(stmt, rc);

  bind[0].buffer= (char*) &time_out;
  bind[1].buffer= (char*) &datetime_out;

  mysql_stmt_bind_result(stmt, bind);

  rc= mysql_stmt_fetch(stmt);
  assert(rc == 0);
  printf("%d:%d:%d.%d\n", time_out.hour, time_out.minute, time_out.second,
                          time_out.second_part);
  printf("%d:%d:%d.%d\n", datetime_out.hour, datetime_out.minute,
                          datetime_out.second, datetime_out.second_part);
  assert(memcmp(&time_in, &time_out, sizeof(time_in)) == 0);
  assert(memcmp(&datetime_in, &datetime_out, sizeof(datetime_in)) == 0);
  mysql_stmt_close(stmt);
}

Suggested fix:
TIME storage is broken in all involved parts: client library, when data is sent to the server,
server part reading data, server part sending data, client part reading data.
[7 Jun 2004 0:04] Konstantin Osipov
bk commit into 4.1 tree (konstantin:1.1896)
[9 Jun 2004 1:57] Konstantin Osipov
Fixed in 4.1.3: bk commit into 4.1 tree (konstantin:1.1896)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.