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
da...@endpoint.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);


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to