Fwd: mysql5 version Zawodny's patch adding cd and ls commands to the mysql client

Richard Bronosky BrunosJunk at Bronosky.com
Wed Oct 3 13:03:16 PDT 2007


I'd started with his original from
http://jeremy.zawodny.com/blog/archives/002230.html and updated it to
work with the 5.0.45 source.  I have included the result at the end of
this email.  Here is how you can use it:
1. sudo port fetch mysql5
2. put the contents of the patch below into a new file called -
/opt/local/var/macports/sources/rsync.macports.org/release/ports/databases/mysql5/files/patch-client-mysql.cc.diff
3. cd /opt/local/var/macports/sources/rsync.macports.org/release/ports/databases/mysql5
4. after the "patchfiles \" line add a line with: "
patch-client-mysql.cc.diff \"
5. sudo port patch
6. sudo port build
7. sudo port install

The patch demonstrates how easy it is to add your own custom commands.
 You really could go crazy tweaking your mysql client.

Enjoy!

--
.!# RichardBronosky #!.

--- client/mysql.cc.orig        2007-07-04 09:06:09.000000000 -0400
+++ client/mysql.cc     2007-10-01 17:23:50.000000000 -0400
@@ -200,6 +200,7 @@
           com_rehash(String *str, char*), com_tee(String *str, char*),
            com_notee(String *str, char*), com_charset(String *str,char*),
            com_prompt(String *str, char*), com_delimiter(String *str, char*),
+           com_ls(String *str, char*),
      com_warnings(String *str, char*), com_nowarnings(String *str, char*);

 #ifdef USE_POPEN
@@ -238,6 +239,7 @@

 static COMMANDS commands[] = {
   { "?",      '?', com_help,   1, "Synonym for `help'." },
+  { "cd",     'C', com_use,    1, "Synonym for `use'." },
   { "clear",  'c', com_clear,  0, "Clear command."},
   { "connect",'r', com_connect,1,
     "Reconnect to the server. Optional arguments are db and host." },
@@ -250,6 +252,7 @@
     "Send command to mysql server, display result vertically."},
   { "exit",   'q', com_quit,   0, "Exit mysql. Same as quit."},
   { "go",     'g', com_go,     0, "Send command to mysql server." },
+  { "ls",     'l', com_ls,     0, "List databases or tables." },
   { "help",   'h', com_help,   1, "Display this help." },
 #ifdef USE_POPEN
   { "nopager",'n', com_nopager,0, "Disable pager, print to stdout." },
@@ -2251,6 +2254,25 @@
   return;
 }

+static int
+com_ls(String *buffer __attribute__((unused)), char *line)
+{
+
+  if (!connected && reconnect())
+    return status.batch ? 1 : -1;
+
+  if (!current_db)
+  {
+    buffer->set_ascii("SHOW DATABASES", 14);
+    com_go(buffer, 0);
+  }
+  else
+  {
+    buffer->set_ascii("SHOW TABLES", 11);
+    com_go(buffer, 0);
+  }
+  return 0;
+}

 static int
 com_ego(String *buffer,char *line)



More information about the macports-users mailing list