PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2024, 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 /* Quoting request types for get_variable() callback */
52 typedef enum
53 {
54  PQUOTE_PLAIN, /* just return the actual value */
55  PQUOTE_SQL_LITERAL, /* add quotes to make a valid SQL literal */
56  PQUOTE_SQL_IDENT, /* quote if needed to make a SQL identifier */
57  PQUOTE_SHELL_ARG, /* quote if needed to be safe in a shell cmd */
59 
60 /* Callback functions to be used by the lexer */
61 typedef struct PsqlScanCallbacks
62 {
63  /* Fetch value of a variable, as a free'able string; NULL if unknown */
64  /* This pointer can be NULL if no variable substitution is wanted */
65  char *(*get_variable) (const char *varname, PsqlScanQuoteType quote,
66  void *passthrough);
68 
69 
72 
73 extern void psql_scan_set_passthrough(PsqlScanState state, void *passthrough);
74 
76  const char *line, int line_len,
77  int encoding, bool std_strings);
79 
81  PQExpBuffer query_buf,
82  promptStatus_t *prompt);
83 
85 
87 
89 
90 #endif /* PSQLSCAN_H */
int32 encoding
Definition: pg_database.h:41
struct PsqlScanStateData * PsqlScanState
Definition: psqlscan.h:27
void psql_scan_reset(PsqlScanState state)
PsqlScanResult
Definition: psqlscan.h:31
@ PSCAN_BACKSLASH
Definition: psqlscan.h:33
@ PSCAN_EOL
Definition: psqlscan.h:35
@ PSCAN_INCOMPLETE
Definition: psqlscan.h:34
@ PSCAN_SEMICOLON
Definition: psqlscan.h:32
enum _promptStatus promptStatus_t
void psql_scan_destroy(PsqlScanState state)
PsqlScanQuoteType
Definition: psqlscan.h:53
@ PQUOTE_SQL_LITERAL
Definition: psqlscan.h:55
@ PQUOTE_PLAIN
Definition: psqlscan.h:54
@ PQUOTE_SHELL_ARG
Definition: psqlscan.h:57
@ PQUOTE_SQL_IDENT
Definition: psqlscan.h:56
PsqlScanResult psql_scan(PsqlScanState state, PQExpBuffer query_buf, promptStatus_t *prompt)
struct PsqlScanCallbacks PsqlScanCallbacks
PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks)
void psql_scan_set_passthrough(PsqlScanState state, void *passthrough)
void psql_scan_setup(PsqlScanState state, const char *line, int line_len, int encoding, bool std_strings)
_promptStatus
Definition: psqlscan.h:40
@ PROMPT_READY
Definition: psqlscan.h:41
@ PROMPT_COPY
Definition: psqlscan.h:48
@ PROMPT_PAREN
Definition: psqlscan.h:47
@ PROMPT_COMMENT
Definition: psqlscan.h:43
@ PROMPT_CONTINUE
Definition: psqlscan.h:42
@ PROMPT_SINGLEQUOTE
Definition: psqlscan.h:44
@ PROMPT_DOLLARQUOTE
Definition: psqlscan.h:46
@ PROMPT_DOUBLEQUOTE
Definition: psqlscan.h:45
void psql_scan_reselect_sql_lexer(PsqlScanState state)
bool psql_scan_in_quote(PsqlScanState state)
void psql_scan_finish(PsqlScanState state)
Definition: regguts.h:323