2 * psql - the PostgreSQL interactive terminal
4 * Copyright (c) 2000-2008, PostgreSQL Global Development Group
16 PRINT_NOTHING
= 0, /* to make sure someone initializes this */
23 /* add your favourite output format here ... */
27 typedef struct printTableOpt
29 enum printFormat format
; /* one of the above */
30 bool expanded
; /* expanded/vertical output (if supported by
32 unsigned short int border
; /* Print a border around the table. 0=none,
33 * 1=dividing lines, 2=full */
34 unsigned short int pager
; /* use pager for output (if to stdout and
35 * stdout is a tty) 0=off 1=on 2=always */
36 bool tuples_only
; /* don't output headers, row counts, etc. */
37 bool start_table
; /* print start decoration, eg <table> */
38 bool stop_table
; /* print stop decoration, eg </table> */
39 unsigned long prior_records
; /* start offset for record counters */
40 char *fieldSep
; /* field separator for unaligned text mode */
41 char *recordSep
; /* record separator for unaligned text mode */
42 bool numericLocale
; /* locale-aware numeric units separator and
44 char *tableAttr
; /* attributes for HTML <table ...> */
45 int encoding
; /* character encoding */
46 int env_columns
; /* $COLUMNS on psql start, 0 is unset */
47 int columns
; /* target width for wrapped format */
51 * Table footers are implemented as a singly-linked list.
53 * This is so that you don't need to know the number of footers in order to
54 * initialise the printTableContent struct, which is very convenient when
55 * preparing complex footers (as in describeOneTableDetails).
57 typedef struct printTableFooter
60 struct printTableFooter
*next
;
64 * The table content struct holds all the information which will be displayed
67 typedef struct printTableContent
69 const printTableOpt
*opt
;
70 const char *title
; /* May be NULL */
71 int ncolumns
; /* Specified in Init() */
72 int nrows
; /* Specified in Init() */
73 const char **headers
; /* NULL-terminated array of header strings */
74 const char **header
; /* Pointer to the last added header */
75 const char **cells
; /* NULL-terminated array of cell content
77 const char **cell
; /* Pointer to the last added cell */
78 printTableFooter
*footers
; /* Pointer to the first footer */
79 printTableFooter
*footer
; /* Pointer to the last added footer */
80 char *aligns
; /* Array of alignment specifiers; 'l' or 'r',
82 char *align
; /* Pointer to the last added alignment */
85 typedef struct printQueryOpt
87 printTableOpt topt
; /* the options above */
88 char *nullPrint
; /* how to print null entities */
89 bool quote
; /* quote all values as much as possible */
90 char *title
; /* override title */
91 char **footers
; /* override footer (default is "(xx rows)") */
92 bool default_footer
; /* print default footer if footers==NULL */
93 bool translate_header
; /* do gettext on column headers */
94 const bool *translate_columns
; /* translate_columns[i-1] => do gettext on col i */
98 extern FILE *PageOutput(int lines
, unsigned short int pager
);
99 extern void ClosePager(FILE *pagerpipe
);
101 extern void html_escaped_print(const char *in
, FILE *fout
);
103 extern void printTableInit(printTableContent
*const content
,
104 const printTableOpt
*opt
, const char *title
,
105 const int ncolumns
, const int nrows
);
106 extern void printTableAddHeader(printTableContent
*const content
,
107 const char *header
, const bool translate
, const char align
);
108 extern void printTableAddCell(printTableContent
*const content
,
109 const char *cell
, const bool translate
);
110 extern void printTableAddFooter(printTableContent
*const content
,
112 extern void printTableSetFooter(printTableContent
*const content
,
114 extern void printTableCleanup(printTableContent
*const content
);
115 extern void printTable(const printTableContent
*cont
, FILE *fout
, FILE *flog
);
116 extern void printQuery(const PGresult
*result
, const printQueryOpt
*opt
,
117 FILE *fout
, FILE *flog
);
119 extern void setDecimalLocale(void);
122 #define DEFAULT_PAGER "more"
124 #define DEFAULT_PAGER "less"