Unix Technical Forum

query output in psql PROMPT

This is a discussion on query output in psql PROMPT within the Pgsql Patches forums, part of the PostgreSQL category; --> A simple patch allow query output in psql PROMPT strings: Index: prompt.c ================================================== ================= RCS file: /projects/cvsroot/pgsql/src/bin/psql/prompt.c,v retrieving revision ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:58 PM
strk
 
Posts: n/a
Default query output in psql PROMPT

A simple patch allow query output in psql PROMPT strings:

Index: prompt.c
================================================== =================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/prompt.c,v
retrieving revision 1.38
diff -U2 -r1.38 prompt.c
--- prompt.c 1 Jan 2005 05:43:08 -0000 1.38
+++ prompt.c 14 Jan 2005 14:39:24 -0000
@@ -61,4 +61,7 @@
* %[ ... %] - tell readline that the contained text is invisible
*
+ * %.query. - the value of the first field in the first row returned
+ * by the specified query.
+ *
* If the application-wide prompts become NULL somehow, the returned string
* will be empty (not NULL!).
@@ -272,4 +275,29 @@
}

+ /* execute db proc */
+ case '.':
+ {
+ char *cmd = pg_strdup(p + 1);
+ PGresult *res;
+ int cmdend;
+
+ cmdend = strcspn(cmd, ".");
+ cmd[cmdend] = '\0';
+ if (cmd)
+ {
+ res = PSQLexec(cmd, false);
+ }
+ if (res && PQntuples(res) )
+ {
+ memcpy(buf, PQgetvalue(res, 0, 0), MAX_PROMPT_SIZE-1);
+ PQclear(res);
+ }
+ if (strlen(buf) > 0 && buf[strlen(buf) - 1] == '\n')
+ buf[strlen(buf) - 1] = '\0';
+ free(cmd);
+ p += cmdend + 1;
+ break;
+ }
+
/* interpolate variable */
case ':':

--

For standing up against patentability of software,

Thank You, Poland!

Read the intervention: http://kwiki.ffii.org/ConsPolon041221En
Send your thanks: thankyoupoland.info
Read/do more: http://www.noepatents.org/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com