Skip site navigation (1) Skip section navigation (2)

MySQL-ism help patch for psql

From: David Christensen <david(at)endpoint(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Magnus Hagander <magnus(at)hagander(dot)net>
Subject: MySQL-ism help patch for psql
Date: 2010-01-19 18:44:03
Message-ID: DE2D34E8-500B-4BC2-B43D-9169CE3B8773@endpoint.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hey  -hackers,

I whipped up a quick patch for supporting some of the common mysql- 
based "meta" commands; this is different than some things which have  
been discussed in the past, in that it provides just a quick direction  
to the appropriate psql command, not an actual alternative syntax for  
the same action.  This is not intended to be comprehensive, but just  
to provide proper direction

The changes are in a single hunk touching only src/bin/psql/ 
mainloop.c; I modeled the code against the logic currently in place  
for the "help" command.

First postgres patch, so bring it on^W^W^Wbe gentle.  I obviously  
don't expect this to not promote a wild debate/flamewar... ;-)  The  
formatting and specific wording for the various messages are totally  
up-in-the-air, and gladly up for debate.

Regards,

David
--
David Christensen
End Point Corporation
david(at)endpoint(dot)com
----
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
index e2914ae..cc89728 100644
--- a/src/bin/psql/mainloop.c
+++ b/src/bin/psql/mainloop.c
@@ -197,6 +197,48 @@ MainLoop(FILE *source)
                         continue;
                 }

+#define MYSQL_HELP_CHECK(o) \
+               (pg_strncasecmp(line, (o), strlen(o)) == 0 &&\
+               (line[strlen(o)] == '\0' || line[strlen(o)] == ';' ||  
isspace((unsigned char) line[strlen(o)])))
+
+#define MYSQL_HELP_OUTPUT(o) \
+               free(line);\
+               printf(_("See:\n           " \
+                                o\
+                                "\n"\
+                                "               or \\? for general  
help with psql commands\n"));\
+               fflush(stdout);\
+               continue;
+
+               /* Present the Postgres equivalent common mysqlisms */
+               if (pset.cur_cmd_interactive && query_buf->len == 0)
+               {
+                       if (MYSQL_HELP_CHECK("use"))
+                       {
+                               MYSQL_HELP_OUTPUT("\\c database");
+                       }
+                       else if (MYSQL_HELP_CHECK("show tables"))
+                       {
+                               MYSQL_HELP_OUTPUT("\\dt");
+                       }
+                       else if (MYSQL_HELP_CHECK("source"))
+                       {
+                               MYSQL_HELP_OUTPUT("\\i filename");
+                       }
+                       else if (MYSQL_HELP_CHECK("show databases"))
+                       {
+                               MYSQL_HELP_OUTPUT("\\l");
+                       }
+                       else if (MYSQL_HELP_CHECK("describe"))
+                       {
+                               MYSQL_HELP_OUTPUT("\\d tablename");
+                       }
+                       else if (MYSQL_HELP_CHECK("load data infile"))
+                       {
+                               MYSQL_HELP_OUTPUT("\\copy");
+                       }
+               }
+
                 /* echo back if flag is set */
                 if (pset.echo == PSQL_ECHO_ALL && ! 
pset.cur_cmd_interactive)
                         puts(line);


Responses

pgsql-hackers by date

Next:From: Robert HaasDate: 2010-01-19 18:46:39
Subject: Re: quoting psql varible as identifier
Previous:From: Tom LaneDate: 2010-01-19 18:43:07
Subject: Re: quoting psql varible as identifier

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group