Bug #4030 Client side conversion string -> date type doesn't work (prepared statements)
Submitted: 7 Jun 2004 0:29 Modified: 24 Jun 2004 20:00
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

[7 Jun 2004 0:29] Konstantin Osipov
Description:
Conversion of string columns to date/time is not supported by libmysql.c/fetch_results.

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

  myheader("test_bugxxxx");

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

  /* Execute a query with time values in prepared mode */
  stmt= mysql_stmt_init(mysql);
  stmt_text= "SELECT '23:59:59.123456', '2003-12-31 23:59:59.123456'";
  rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
  check_execute(stmt, rc);
  rc= mysql_stmt_execute(stmt);
  check_execute(stmt, rc);

  /* Bind output buffers */
  bzero(bind, sizeof(bind));
  bzero(&time_canonical, sizeof(time_canonical));
  bzero(&time_out, sizeof(time_out));
  bzero(&datetime_canonical, sizeof(datetime_canonical));
  bzero(&datetime_out, sizeof(datetime_out));

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

  time_canonical.hour= 23;  time_canonical.minute= 59;
  time_canonical.second= 59;
  time_canonical.second_part= 123456;

  datetime_canonical= time_canonical;
  datetime_canonical.year= 2003;
  datetime_canonical.month= 12;
  datetime_canonical.day= 31;

  mysql_stmt_bind_result(stmt, bind);

  rc= mysql_stmt_fetch(stmt);
  assert(rc == 0);
  printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second,
                           time_out.second_part);
  printf("%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month,
                                    datetime_out.day, datetime_out.hour,
                                    datetime_out.minute, datetime_out.second,
                                    datetime_out.second_part);
  assert(memcmp(&time_canonical, &time_out, sizeof(time_out)) == 0);
  assert(memcmp(&datetime_canonical, &datetime_out, sizeof(datetime_out)) == 0);
  mysql_stmt_close(stmt);
}

This test prints:

#####################################
2 of (1/1): test_bugxxxx  
#####################################
0:0:0.0
0-0-0 0:0:0.0
lt-client_test: client_test.c:9927: test_bugxxxx: Assertion `memcmp(&time_canoni
cal, &time_out, sizeof(time_out)) == 0' failed.
[23 Jun 2004 21:48] Konstantin Osipov
A short patch fixing this bug only:
 bk commit - 4.1 tree (konstantin:1.1962) BUG#4030
[24 Jun 2004 11:48] Michael Widenius
Waiting for new patch.
[24 Jun 2004 20:00] Konstantin Osipov
Fixed in 4.1.3: bk commit into 4.1 tree (konstantin:1.1962)