~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/time/make_datetime.cc

Merge Revision revid:marko.makela@oracle.com-20100514133144-fe0l0b89tea4x4uu from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100514133144-fe0l0b89tea4x4uu

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Merge from mysql-5.1-innodb:

Post-merge fixes: Remove the MYSQL_VERSION_ID checks, because they only
apply to the InnoDB Plugin. Fix potential race condition accessing
trx->op_info and trx->detailed_error.
------------------------------------------------------------
revno: 3466
revision-id: marko.makela@oracle.com-20100514130815-ym7j7cfu88ro6km4
parent: marko.makela@oracle.com-20100514130228-n3n42nw7ht78k0wn
committer: Marko Mkel <marko.makela@oracle.com>
branch nick: mysql-5.1-innodb2
timestamp: Fri 2010-05-14 16:08:15 +0300
message:
  Make the InnoDB FOREIGN KEY parser understand multi-statements. (Bug #48024)
  Also make InnoDB thinks that /*/ only starts a comment. (Bug #53644).

  This fixes the bugs in the InnoDB Plugin.

  ha_innodb.h: Use trx_query_string() instead of trx_query() when
  available (MySQL 5.1.42 or later).

  innobase_get_stmt(): New function, to retrieve the currently running
  SQL statement.

  struct trx_struct: Remove mysql_query_str. Use innobase_get_stmt() instead.

  dict_strip_comments(): Add and observe the parameter sql_length. Treat
  /*/ as the start of a comment.

  dict_create_foreign_constraints(), row_table_add_foreign_constraints():
  Add the parameter sql_length.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include <drizzled/server_includes.h>
21
 
#include CSTDINT_H
22
 
#include <drizzled/functions/time/make_datetime.h>
23
 
 
24
 
/**
25
 
  @todo
26
 
  OPTIMIZATION
27
 
  - Replace the switch with a function that should be called for each
28
 
  date type.
29
 
  - Remove sprintf and opencode the conversion, like we do in
30
 
  Field_datetime.
31
 
 
32
 
  The reason for this functions existence is that as we don't have a
33
 
  way to know if a datetime/time value has microseconds in them
34
 
  we are now only adding microseconds to the output if the
35
 
  value has microseconds.
36
 
 
37
 
  We can't use a standard make_date_time() for this as we don't know
38
 
  if someone will use %f in the format specifier in which case we would get
39
 
  the microseconds twice.
40
 
*/
41
 
 
42
 
bool make_datetime(date_time_format_types format, DRIZZLE_TIME *ltime,
43
 
                          String *str)
44
 
{
45
 
  char *buff;
46
 
  const CHARSET_INFO * const cs= &my_charset_bin;
47
 
  uint32_t length= MAX_DATE_STRING_REP_LENGTH;
48
 
 
49
 
  if (str->alloc(length))
50
 
    return 1;
51
 
  buff= (char*) str->ptr();
52
 
 
53
 
  switch (format) {
54
 
  case TIME_ONLY:
55
 
    length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d",
56
 
                               ltime->neg ? "-" : "",
57
 
                               ltime->hour, ltime->minute, ltime->second);
58
 
    break;
59
 
  case TIME_MICROSECOND:
60
 
    length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d.%06ld",
61
 
                               ltime->neg ? "-" : "",
62
 
                               ltime->hour, ltime->minute, ltime->second,
63
 
                               ltime->second_part);
64
 
    break;
65
 
  case DATE_ONLY:
66
 
    length= cs->cset->snprintf(cs, buff, length, "%04d-%02d-%02d",
67
 
                               ltime->year, ltime->month, ltime->day);
68
 
    break;
69
 
  case DATE_TIME:
70
 
    length= cs->cset->snprintf(cs, buff, length,
71
 
                               "%04d-%02d-%02d %02d:%02d:%02d",
72
 
                               ltime->year, ltime->month, ltime->day,
73
 
                               ltime->hour, ltime->minute, ltime->second);
74
 
    break;
75
 
  case DATE_TIME_MICROSECOND:
76
 
    length= cs->cset->snprintf(cs, buff, length,
77
 
                               "%04d-%02d-%02d %02d:%02d:%02d.%06ld",
78
 
                               ltime->year, ltime->month, ltime->day,
79
 
                               ltime->hour, ltime->minute, ltime->second,
80
 
                               ltime->second_part);
81
 
    break;
82
 
  }
83
 
 
84
 
  str->length(length);
85
 
  str->set_charset(cs);
86
 
  return 0;
87
 
}
88