~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/errmsg_print.cc

  • Committer: Stewart Smith
  • Date: 2009-05-15 06:57:12 UTC
  • mto: (991.1.5 for-brian)
  • mto: This revision was merged to the branch mainline in revision 1022.
  • Revision ID: stewart@flamingspork.com-20090515065712-bmionylacjmexmmm
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.

Also fix DEFAULT keyword handling for auto-increment so that it defaults to
NULL and not 0 so that the following is valid and generates two auto-inc
values:

create table t1 (a int auto_increment primary key)
insert into t1 (a) values (default);
insert into t1 (a) values (default);

Important to note that 0 is no longer magic. So this gives you duplicate
primary key error:

insert into t1 (a) values(0);
insert into t1 (a) values(0);

as you've inserted the explicit value of 0 twice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Mark Atwood
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
22
22
   errmsg_printf()
23
23
*/
24
24
 
25
 
#include "config.h"
26
 
 
27
 
#include <drizzled/definitions.h>
 
25
#include <drizzled/server_includes.h>
 
26
#include <drizzled/errmsg.h>
28
27
#include <drizzled/errmsg_print.h>
29
 
#include <drizzled/plugin/error_message.h>
30
 
 
31
 
#include <cerrno>
32
 
#include <cstring>
33
 
 
34
 
namespace drizzled
35
 
{
 
28
#include <drizzled/current_session.h>
 
29
 
 
30
// need this for stderr
 
31
#include <string.h>
 
32
 
 
33
void sql_print_error(const char *format, ...)
 
34
{
 
35
  va_list args;
 
36
  va_start(args, format);
 
37
  errmsg_vprintf(current_session, ERROR_LEVEL, format, args);
 
38
  va_end(args);
 
39
  return;
 
40
}
 
41
 
 
42
void sql_print_warning(const char *format, ...)
 
43
{
 
44
  va_list args;
 
45
  va_start(args, format);
 
46
  errmsg_vprintf(current_session, WARNING_LEVEL, format, args);
 
47
  va_end(args);
 
48
  return;
 
49
}
 
50
 
 
51
void sql_print_information(const char *format, ...)
 
52
{
 
53
  va_list args;
 
54
  va_start(args, format);
 
55
  errmsg_vprintf(current_session, INFORMATION_LEVEL, format, args);
 
56
  va_end(args);
 
57
  return;
 
58
}
36
59
 
37
60
void sql_perror(const char *message)
38
61
{
39
 
  char errmsg[STRERROR_MAX];
40
 
  errmsg[0]= 0;
41
 
  strerror_r(errno, errmsg, sizeof(errmsg));
42
 
  errmsg_printf(error::ERROR, "%s: %s\n", message, errmsg);
43
 
}
44
 
 
45
 
// @todo Cap the size of message.
46
 
void sql_perror(const std::string &message)
47
 
{
48
 
  static std::string empty;
49
 
  sql_perror(message, empty);
50
 
}
51
 
 
52
 
// @todo Cap the size of message/extra.
53
 
void sql_perror(std::string message, const std::string &extra)
54
 
{
55
 
  char errmsg[STRERROR_MAX];
56
 
  errmsg[0]= 0;
57
 
  strerror_r(errno, errmsg, sizeof(errmsg));
58
 
 
59
 
  if (not extra.empty())
60
 
  {
61
 
    if (message.at(message.size()) != ' ')
62
 
      message+= " ";
63
 
 
64
 
    message+= "'";
65
 
    message+= extra;
66
 
    message+= "'";
67
 
  }
68
 
 
69
 
  errmsg_printf(error::ERROR, "%s: %s\n", message.c_str(), errmsg);
70
 
}
71
 
 
72
 
bool errmsg_printf (error::level_t priority, char const *format, ...)
 
62
  // is stderr threadsafe?
 
63
  errmsg_printf(ERRMSG_LVL_ERROR, "%s: %s", message, strerror(errno));
 
64
}
 
65
 
 
66
 
 
67
bool errmsg_printf (int priority, char const *format, ...)
73
68
{
74
69
  bool rv;
75
70
  va_list args;
76
71
  va_start(args, format);
77
 
  rv= plugin::ErrorMessage::vprintf(priority, format, args);
 
72
  rv= errmsg_vprintf(current_session, priority, format, args);
78
73
  va_end(args);
79
74
  return rv;
80
75
}
81
 
 
82
 
} /* namespace drizzled */