2004-02-19 20:40:09 +01:00
|
|
|
/*
|
|
|
|
* psql - the PostgreSQL interactive terminal
|
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Copyright (c) 2000-2016, PostgreSQL Global Development Group
|
2004-02-19 20:40:09 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/bin/psql/psqlscan.h
|
2004-02-19 20:40:09 +01:00
|
|
|
*/
|
|
|
|
#ifndef PSQLSCAN_H
|
|
|
|
#define PSQLSCAN_H
|
|
|
|
|
|
|
|
#include "pqexpbuffer.h"
|
|
|
|
|
|
|
|
#include "prompt.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Abstract type for lexer's internal state */
|
|
|
|
typedef struct PsqlScanStateData *PsqlScanState;
|
|
|
|
|
|
|
|
/* Termination states for psql_scan() */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSCAN_SEMICOLON, /* found command-ending semicolon */
|
|
|
|
PSCAN_BACKSLASH, /* found backslash command */
|
|
|
|
PSCAN_INCOMPLETE, /* end of line, SQL statement incomplete */
|
|
|
|
PSCAN_EOL /* end of line, SQL possibly complete */
|
|
|
|
} PsqlScanResult;
|
|
|
|
|
|
|
|
/* Different ways for scan_slash_option to handle parameter words */
|
|
|
|
enum slash_option_type
|
|
|
|
{
|
|
|
|
OT_NORMAL, /* normal case */
|
|
|
|
OT_SQLID, /* treat as SQL identifier */
|
|
|
|
OT_SQLIDHACK, /* SQL identifier, but don't downcase */
|
|
|
|
OT_FILEPIPE, /* it's a filename or pipe */
|
2004-12-19 20:39:47 +01:00
|
|
|
OT_WHOLE_LINE, /* just snarf the rest of the line */
|
2011-08-26 19:52:23 +02:00
|
|
|
OT_NO_EVAL /* no expansion of backticks or variables */
|
2004-02-19 20:40:09 +01:00
|
|
|
};
|
|
|
|
|
2016-03-18 20:05:49 +01:00
|
|
|
/* Callback functions to be used by the lexer */
|
|
|
|
typedef struct PsqlScanCallbacks
|
|
|
|
{
|
|
|
|
/* Fetch value of a variable, as a pfree'able string; NULL if unknown */
|
|
|
|
/* This pointer can be NULL if no variable substitution is wanted */
|
|
|
|
char *(*get_variable) (const char *varname, bool escape, bool as_ident);
|
|
|
|
/* Print an error message someplace appropriate */
|
|
|
|
void (*write_error) (const char *fmt,...) pg_attribute_printf(1, 2);
|
|
|
|
} PsqlScanCallbacks;
|
|
|
|
|
2004-02-19 20:40:09 +01:00
|
|
|
|
2016-03-18 20:05:49 +01:00
|
|
|
extern PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks);
|
2004-02-19 20:40:09 +01:00
|
|
|
extern void psql_scan_destroy(PsqlScanState state);
|
|
|
|
|
|
|
|
extern void psql_scan_setup(PsqlScanState state,
|
2016-03-18 20:05:49 +01:00
|
|
|
const char *line, int line_len,
|
|
|
|
int encoding, bool std_strings);
|
2004-02-19 20:40:09 +01:00
|
|
|
extern void psql_scan_finish(PsqlScanState state);
|
|
|
|
|
|
|
|
extern PsqlScanResult psql_scan(PsqlScanState state,
|
2004-08-29 07:07:03 +02:00
|
|
|
PQExpBuffer query_buf,
|
|
|
|
promptStatus_t *prompt);
|
2004-02-19 20:40:09 +01:00
|
|
|
|
|
|
|
extern void psql_scan_reset(PsqlScanState state);
|
|
|
|
|
|
|
|
extern bool psql_scan_in_quote(PsqlScanState state);
|
|
|
|
|
|
|
|
extern char *psql_scan_slash_command(PsqlScanState state);
|
|
|
|
|
|
|
|
extern char *psql_scan_slash_option(PsqlScanState state,
|
2004-08-29 07:07:03 +02:00
|
|
|
enum slash_option_type type,
|
|
|
|
char *quote,
|
|
|
|
bool semicolon);
|
2004-02-19 20:40:09 +01:00
|
|
|
|
|
|
|
extern void psql_scan_slash_command_end(PsqlScanState state);
|
|
|
|
|
|
|
|
#endif /* PSQLSCAN_H */
|