Commit f77e2692 authored by Michael Widenius's avatar Michael Widenius

Added client functions:

- mysql_get_server_name()
  This returns MySQL or MariaDB depending on the server type
- mariadb_connection()
  This returns 1 if you are connected to a MariaDB server

Modifed the MySQL command line client to print out if you are connected to MariaDB or MySQL
Better default prompt (shows server you are connected to and base directory)

client/mysql.cc:
  Print out if you are connected to MariaDB or MySQL
  Better default prompt (shows server you are connected to and base directory)
  Added option \N to prompt to print server name.
configure.in:
  Changed maria to MariaDB in version string
include/mysql.h:
  Added mysql_get_server_name() and mariadb_connection()
include/mysql.h.pp:
  Update for new API functions
libmysql/libmysql.c:
  Added client functions:
  - mysql_get_server_name()
    This returns MySQL or MariaDB depending on the server type
  - mariadb_connection()
    This returns 1 if you are connected to a MariaDB server
parent 12f18c88
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
const char *VER= "14.15"; const char *VER= "14.16";
/* Don't try to make a nice table if the data is too big */ /* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024 #define MAX_COLUMN_LENGTH 1024
...@@ -1076,7 +1076,7 @@ int main(int argc,char *argv[]) ...@@ -1076,7 +1076,7 @@ int main(int argc,char *argv[])
delimiter_str= delimiter; delimiter_str= delimiter;
default_prompt = my_strdup(getenv("MYSQL_PS1") ? default_prompt = my_strdup(getenv("MYSQL_PS1") ?
getenv("MYSQL_PS1") : getenv("MYSQL_PS1") :
"mysql> ",MYF(MY_WME)); "\\N [\\d]> ",MYF(MY_WME));
current_prompt = my_strdup(default_prompt,MYF(MY_WME)); current_prompt = my_strdup(default_prompt,MYF(MY_WME));
prompt_counter=0; prompt_counter=0;
...@@ -1156,10 +1156,11 @@ int main(int argc,char *argv[]) ...@@ -1156,10 +1156,11 @@ int main(int argc,char *argv[])
signal(SIGINT, handle_sigint); // Catch SIGINT to clean up signal(SIGINT, handle_sigint); // Catch SIGINT to clean up
signal(SIGQUIT, mysql_end); // Catch SIGQUIT to clean up signal(SIGQUIT, mysql_end); // Catch SIGQUIT to clean up
put_info("Welcome to the MySQL monitor. Commands end with ; or \\g.", put_info("Welcome to the MariaDB monitor. Commands end with ; or \\g.",
INFO_INFO); INFO_INFO);
sprintf((char*) glob_buffer.ptr(), sprintf((char*) glob_buffer.ptr(),
"Your MySQL connection id is %lu\nServer version: %s\n", "Your %s connection id is %lu\nServer version: %s\n",
mysql_get_server_name(&mysql),
mysql_thread_id(&mysql), server_version_string(&mysql)); mysql_thread_id(&mysql), server_version_string(&mysql));
put_info((char*) glob_buffer.ptr(),INFO_INFO); put_info((char*) glob_buffer.ptr(),INFO_INFO);
...@@ -4369,6 +4370,7 @@ com_status(String *buffer __attribute__((unused)), ...@@ -4369,6 +4370,7 @@ com_status(String *buffer __attribute__((unused)),
tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : ""); tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
#endif #endif
tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter); tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
tee_fprintf(stdout, "Server:\t\t\t%s\n", mysql_get_server_name(&mysql));
tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&mysql)); tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&mysql));
tee_fprintf(stdout, "Protocol version:\t%d\n", mysql_get_proto_info(&mysql)); tee_fprintf(stdout, "Protocol version:\t%d\n", mysql_get_proto_info(&mysql));
tee_fprintf(stdout, "Connection:\t\t%s\n", mysql_get_host_info(&mysql)); tee_fprintf(stdout, "Connection:\t\t%s\n", mysql_get_host_info(&mysql));
...@@ -4700,7 +4702,7 @@ static void mysql_end_timer(ulong start_time,char *buff) ...@@ -4700,7 +4702,7 @@ static void mysql_end_timer(ulong start_time,char *buff)
strmov(strend(buff),")"); strmov(strend(buff),")");
} }
static const char* construct_prompt() static const char *construct_prompt()
{ {
processed_prompt.free(); // Erase the old prompt processed_prompt.free(); // Erase the old prompt
time_t lclock = time(NULL); // Get the date struct time_t lclock = time(NULL); // Get the date struct
...@@ -4729,6 +4731,12 @@ static const char* construct_prompt() ...@@ -4729,6 +4731,12 @@ static const char* construct_prompt()
case 'd': case 'd':
processed_prompt.append(current_db ? current_db : "(none)"); processed_prompt.append(current_db ? current_db : "(none)");
break; break;
case 'N':
if (connected)
processed_prompt.append(mysql_get_server_name(&mysql));
else
processed_prompt.append("unkown");
break;
case 'h': case 'h':
{ {
const char *prompt; const char *prompt;
......
...@@ -13,7 +13,7 @@ AC_CANONICAL_SYSTEM ...@@ -13,7 +13,7 @@ AC_CANONICAL_SYSTEM
# #
# When merging new MySQL releases, update the version number to match the # When merging new MySQL releases, update the version number to match the
# MySQL version number, but reset the maria subrelease (-beta1). # MySQL version number, but reset the maria subrelease (-beta1).
AM_INIT_AUTOMAKE(mysql, 5.1.38-maria-beta1) AM_INIT_AUTOMAKE(mysql, 5.1.38-MariaDB-beta1)
AM_CONFIG_HEADER([include/config.h:config.h.in]) AM_CONFIG_HEADER([include/config.h:config.h.in])
PROTOCOL_VERSION=10 PROTOCOL_VERSION=10
......
...@@ -527,6 +527,7 @@ int STDCALL mysql_set_server_option(MYSQL *mysql, ...@@ -527,6 +527,7 @@ int STDCALL mysql_set_server_option(MYSQL *mysql,
int STDCALL mysql_ping(MYSQL *mysql); int STDCALL mysql_ping(MYSQL *mysql);
const char * STDCALL mysql_stat(MYSQL *mysql); const char * STDCALL mysql_stat(MYSQL *mysql);
const char * STDCALL mysql_get_server_info(MYSQL *mysql); const char * STDCALL mysql_get_server_info(MYSQL *mysql);
const char * STDCALL mysql_get_server_name(MYSQL *mysql);
const char * STDCALL mysql_get_client_info(void); const char * STDCALL mysql_get_client_info(void);
unsigned long STDCALL mysql_get_client_version(void); unsigned long STDCALL mysql_get_client_version(void);
const char * STDCALL mysql_get_host_info(MYSQL *mysql); const char * STDCALL mysql_get_host_info(MYSQL *mysql);
...@@ -560,6 +561,7 @@ void STDCALL mysql_debug(const char *debug); ...@@ -560,6 +561,7 @@ void STDCALL mysql_debug(const char *debug);
void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int STDCALL mysql_thread_safe(void); unsigned int STDCALL mysql_thread_safe(void);
my_bool STDCALL mysql_embedded(void); my_bool STDCALL mysql_embedded(void);
my_bool STDCALL mariadb_connection(MYSQL *mysql);
MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con); MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con);
MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
const char* host, const char* host,
......
...@@ -487,6 +487,7 @@ int mysql_set_server_option(MYSQL *mysql, ...@@ -487,6 +487,7 @@ int mysql_set_server_option(MYSQL *mysql,
int mysql_ping(MYSQL *mysql); int mysql_ping(MYSQL *mysql);
const char * mysql_stat(MYSQL *mysql); const char * mysql_stat(MYSQL *mysql);
const char * mysql_get_server_info(MYSQL *mysql); const char * mysql_get_server_info(MYSQL *mysql);
const char * mysql_get_server_name(MYSQL *mysql);
const char * mysql_get_client_info(void); const char * mysql_get_client_info(void);
unsigned long mysql_get_client_version(void); unsigned long mysql_get_client_version(void);
const char * mysql_get_host_info(MYSQL *mysql); const char * mysql_get_host_info(MYSQL *mysql);
...@@ -520,6 +521,7 @@ void mysql_debug(const char *debug); ...@@ -520,6 +521,7 @@ void mysql_debug(const char *debug);
void myodbc_remove_escape(MYSQL *mysql,char *name); void myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int mysql_thread_safe(void); unsigned int mysql_thread_safe(void);
my_bool mysql_embedded(void); my_bool mysql_embedded(void);
my_bool mariadb_connection(MYSQL *mysql);
MYSQL_MANAGER* mysql_manager_init(MYSQL_MANAGER* con); MYSQL_MANAGER* mysql_manager_init(MYSQL_MANAGER* con);
MYSQL_MANAGER* mysql_manager_connect(MYSQL_MANAGER* con, MYSQL_MANAGER* mysql_manager_connect(MYSQL_MANAGER* con,
const char* host, const char* host,
......
...@@ -1430,6 +1430,18 @@ mysql_get_server_info(MYSQL *mysql) ...@@ -1430,6 +1430,18 @@ mysql_get_server_info(MYSQL *mysql)
} }
my_bool STDCALL mariadb_connection(MYSQL *mysql)
{
return strinstr(mysql->server_version, "MariaDB") != 0;
}
const char * STDCALL
mysql_get_server_name(MYSQL *mysql)
{
return mariadb_connection(mysql) ? "MariaDB" : "MySQL";
}
const char * STDCALL const char * STDCALL
mysql_get_host_info(MYSQL *mysql) mysql_get_host_info(MYSQL *mysql)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment