PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
psqlscan.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * psqlscan.h
4  * lexical scanner for SQL commands
5  *
6  * This lexer used to be part of psql, and that heritage is reflected in
7  * the file name as well as function and typedef names, though it can now
8  * be used by other frontend programs as well. It's also possible to extend
9  * this lexer with a compatible add-on lexer to handle program-specific
10  * backslash commands.
11  *
12  *
13  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
14  * Portions Copyright (c) 1994, Regents of the University of California
15  *
16  * src/include/fe_utils/psqlscan.h
17  *
18  *-------------------------------------------------------------------------
19  */
20 #ifndef PSQLSCAN_H
21 #define PSQLSCAN_H
22 
23 #include "pqexpbuffer.h"
24 
25 
26 /* Abstract type for lexer's internal state */
28 
29 /* Termination states for psql_scan() */
30 typedef enum
31 {
32  PSCAN_SEMICOLON, /* found command-ending semicolon */
33  PSCAN_BACKSLASH, /* found backslash command */
34  PSCAN_INCOMPLETE, /* end of line, SQL statement incomplete */
35  PSCAN_EOL /* end of line, SQL possibly complete */
37 
38 /* Prompt type returned by psql_scan() */
39 typedef enum _promptStatus
40 {
50 
51 /* Callback functions to be used by the lexer */
52 typedef struct PsqlScanCallbacks
53 {
54  /* Fetch value of a variable, as a pfree'able string; NULL if unknown */
55  /* This pointer can be NULL if no variable substitution is wanted */
56  char *(*get_variable) (const char *varname, bool escape, bool as_ident);
57  /* Print an error message someplace appropriate */
58  /* (very old gcc versions don't support attributes on function pointers) */
59 #if defined(__GNUC__) && __GNUC__ < 4
60  void (*write_error) (const char *fmt,...);
61 #else
62  void (*write_error) (const char *fmt,...) pg_attribute_printf(1, 2);
63 #endif
65 
66 
67 extern PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks);
68 extern void psql_scan_destroy(PsqlScanState state);
69 
70 extern void psql_scan_setup(PsqlScanState state,
71  const char *line, int line_len,
72  int encoding, bool std_strings);
73 extern void psql_scan_finish(PsqlScanState state);
74 
75 extern PsqlScanResult psql_scan(PsqlScanState state,
76  PQExpBuffer query_buf,
77  promptStatus_t *prompt);
78 
79 extern void psql_scan_reset(PsqlScanState state);
80 
81 extern void psql_scan_reselect_sql_lexer(PsqlScanState state);
82 
83 extern bool psql_scan_in_quote(PsqlScanState state);
84 
85 #endif /* PSQLSCAN_H */
PsqlScanResult
Definition: psqlscan.h:30
struct PsqlScanCallbacks PsqlScanCallbacks
PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks)
#define pg_attribute_printf(f, a)
Definition: c.h:634
_promptStatus
Definition: psqlscan.h:39
void psql_scan_reset(PsqlScanState state)
void(* write_error)(const char *fmt,...) pg_attribute_printf(1
Definition: psqlscan.h:62
void psql_scan_destroy(PsqlScanState state)
static char * encoding
Definition: initdb.c:121
Definition: regguts.h:298
enum _promptStatus promptStatus_t
PsqlScanResult psql_scan(PsqlScanState state, PQExpBuffer query_buf, promptStatus_t *prompt)
struct PsqlScanStateData * PsqlScanState
Definition: psqlscan.h:27
void psql_scan_setup(PsqlScanState state, const char *line, int line_len, int encoding, bool std_strings)
void psql_scan_reselect_sql_lexer(PsqlScanState state)
bool psql_scan_in_quote(PsqlScanState state)
void psql_scan_finish(PsqlScanState state)