summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/Makefile.am3
-rw-r--r--sql-common/client.c48
-rw-r--r--sql-common/my_time.c30
3 files changed, 61 insertions, 20 deletions
diff --git a/sql-common/Makefile.am b/sql-common/Makefile.am
index 614ccffde9d..3193efee754 100644
--- a/sql-common/Makefile.am
+++ b/sql-common/Makefile.am
@@ -15,6 +15,3 @@
## Process this file with automake to create Makefile.in
EXTRA_DIST = client.c pack.c my_time.c my_user.c
-
-# Don't update the files from bitkeeper
-%::SCCS/s.%
diff --git a/sql-common/client.c b/sql-common/client.c
index 51911d913c7..53642b65be7 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2003, 2012, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1024,7 +1024,7 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd)
{
options->init_commands= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY),
MYF(MY_WME));
- init_dynamic_array(options->init_commands,sizeof(char*),0,5 CALLER_INFO);
+ init_dynamic_array(options->init_commands,sizeof(char*),5,5 CALLER_INFO);
}
if (!(tmp= my_strdup(cmd,MYF(MY_WME))) ||
@@ -1601,6 +1601,7 @@ mysql_init(MYSQL *mysql)
*/
mysql->reconnect= 0;
+ DBUG_PRINT("mysql",("mysql: 0x%lx", (long) mysql));
return mysql;
}
@@ -1622,6 +1623,11 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
{
DBUG_ENTER("mysql_ssl_set");
#ifdef HAVE_OPENSSL
+ my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR));
mysql->options.ssl_key= strdup_if_not_null(key);
mysql->options.ssl_cert= strdup_if_not_null(cert);
mysql->options.ssl_ca= strdup_if_not_null(ca);
@@ -1945,7 +1951,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
#if defined(HAVE_SMEM)
if ((!mysql->options.protocol ||
mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
- (!host || !strcmp(host,LOCAL_HOST)))
+ (!host || !strcmp(host,LOCAL_HOST)) &&
+ mysql->options.shared_memory_base_name)
{
if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) ==
INVALID_HANDLE_VALUE)
@@ -1954,7 +1961,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
("host: '%s' socket: '%s' shared memory: %s have_tcpip: %d",
host ? host : "<null>",
unix_socket ? unix_socket : "<null>",
- (int) mysql->options.shared_memory_base_name,
+ mysql->options.shared_memory_base_name,
(int) have_tcpip));
if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY)
goto error;
@@ -2308,6 +2315,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
/* Do the SSL layering. */
struct st_mysql_options *options= &mysql->options;
struct st_VioSSLFd *ssl_fd;
+ char error_string[1024];
/*
Send client_flag, max_packet_size - unencrypted otherwise
@@ -2337,9 +2345,14 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
/* Connect to the server */
DBUG_PRINT("info", ("IO layer change in progress..."));
if (sslconnect(ssl_fd, mysql->net.vio,
- (long) (mysql->options.connect_timeout)))
+ (long) (mysql->options.connect_timeout),
+ error_string))
{
- set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate);
+ set_mysql_extended_error(mysql, CR_SSL_CONNECTION_ERROR,
+ unknown_sqlstate,
+ "SSL error: %s",
+ error_string[0] ? error_string :
+ ER(CR_SSL_CONNECTION_ERROR));
goto error;
}
DBUG_PRINT("info", ("IO layer change done!"));
@@ -2765,9 +2778,18 @@ void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)),
}
+/*
+ Close a MySQL connection and free all resources attached to it.
+
+ This function is coded in such that it can be called multiple times
+ (As some clients call this after mysql_real_connect() fails)
+*/
+
void STDCALL mysql_close(MYSQL *mysql)
{
DBUG_ENTER("mysql_close");
+ DBUG_PRINT("enter", ("mysql: 0x%lx", (long) mysql));
+
if (mysql) /* Some simple safety */
{
/* If connection is still up, send a QUIT message */
@@ -2798,10 +2820,16 @@ void STDCALL mysql_close(MYSQL *mysql)
}
#endif
if (mysql != mysql->master)
+ {
mysql_close(mysql->master);
+ mysql->master= 0;
+ }
#ifndef MYSQL_SERVER
if (mysql->thd)
+ {
(*mysql->methods->free_embedded_thd)(mysql);
+ mysql->thd= 0;
+ }
#endif
if (mysql->free_me)
my_free((uchar*) mysql,MYF(0));
@@ -3227,7 +3255,7 @@ const char * STDCALL mysql_error(MYSQL *mysql)
mysql Connection
EXAMPLE
- 4.1.0-alfa -> 40100
+ MariaDB-4.1.0-alfa -> 40100
NOTES
We will ensure that a newer server always has a bigger number.
@@ -3240,7 +3268,11 @@ ulong STDCALL
mysql_get_server_version(MYSQL *mysql)
{
uint major, minor, version;
- char *pos= mysql->server_version, *end_pos;
+ const char *pos= mysql->server_version;
+ char *end_pos;
+ /* Skip possible prefix */
+ while (*pos && !my_isdigit(&my_charset_latin1, *pos))
+ pos++;
major= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1;
minor= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1;
version= (uint) strtoul(pos, &end_pos, 10);
diff --git a/sql-common/my_time.c b/sql-common/my_time.c
index bd60277d1bc..fcb9ece92f1 100644
--- a/sql-common/my_time.c
+++ b/sql-common/my_time.c
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2004, 2012, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -339,7 +339,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
{
if (str[0] == 'p' || str[0] == 'P')
add_hours= 12;
- else if (str[0] != 'a' || str[0] != 'A')
+ else if (str[0] != 'a' && str[0] != 'A')
continue; /* Not AM/PM */
str+= 2; /* Skip AM/PM */
/* Skip space after AM/PM */
@@ -729,6 +729,9 @@ void my_init_time(void)
my_time.hour= (uint) l_time->tm_hour;
my_time.minute= (uint) l_time->tm_min;
my_time.second= (uint) l_time->tm_sec;
+ my_time.neg= 0;
+ my_time.second_part= 0;
+ my_time.time_type= MYSQL_TIMESTAMP_DATETIME;
my_system_gmt_sec(&my_time, &my_time_zone, &not_used); /* Init my_time_zone */
}
@@ -1027,21 +1030,30 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type)
int my_time_to_str(const MYSQL_TIME *l_time, char *to)
{
uint extra_hours= 0;
- return sprintf(to, "%s%02u:%02u:%02u", (l_time->neg ? "-" : ""),
- extra_hours+ l_time->hour, l_time->minute, l_time->second);
+ return my_sprintf(to, (to, "%s%02u:%02u:%02u",
+ (l_time->neg ? "-" : ""),
+ extra_hours+ l_time->hour,
+ l_time->minute,
+ l_time->second));
}
int my_date_to_str(const MYSQL_TIME *l_time, char *to)
{
- return sprintf(to, "%04u-%02u-%02u",
- l_time->year, l_time->month, l_time->day);
+ return my_sprintf(to, (to, "%04u-%02u-%02u",
+ l_time->year,
+ l_time->month,
+ l_time->day));
}
int my_datetime_to_str(const MYSQL_TIME *l_time, char *to)
{
- return sprintf(to, "%04u-%02u-%02u %02u:%02u:%02u",
- l_time->year, l_time->month, l_time->day,
- l_time->hour, l_time->minute, l_time->second);
+ return my_sprintf(to, (to, "%04u-%02u-%02u %02u:%02u:%02u",
+ l_time->year,
+ l_time->month,
+ l_time->day,
+ l_time->hour,
+ l_time->minute,
+ l_time->second));
}