1
/*-------------------------------------------------------------------------
4
* lexical token lookup for reserved words in postgres embedded SQL
7
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.30 2004-09-27 09:59:17 meskes Exp $
9
*-------------------------------------------------------------------------
11
#include "postgres_fe.h"
20
* List of (keyword-name, keyword-token-value) pairs.
22
* !!WARNING!!: This list must be sorted, because binary
23
* search is used to locate entries.
25
static ScanKeyword ScanKeywords[] = {
27
{"allocate", SQL_ALLOCATE},
28
{"autocommit", SQL_AUTOCOMMIT},
32
{"cardinality", SQL_CARDINALITY},
33
{"connect", SQL_CONNECT},
34
{"connection", SQL_CONNECTION},
35
{"continue", SQL_CONTINUE},
37
{"current", SQL_CURRENT},
39
{"datetime_interval_code", SQL_DATETIME_INTERVAL_CODE},
40
{"datetime_interval_precision", SQL_DATETIME_INTERVAL_PRECISION},
41
{"describe", SQL_DESCRIBE},
42
{"descriptor", SQL_DESCRIPTOR},
43
{"disconnect", SQL_DISCONNECT},
49
{"identified", SQL_IDENTIFIED},
50
{"indicator", SQL_INDICATOR},
51
{"key_member", SQL_KEY_MEMBER},
52
{"length", SQL_LENGTH},
55
{"nullable", SQL_NULLABLE},
56
{"octet_length", SQL_OCTET_LENGTH},
58
{"output", SQL_OUTPUT},
59
{"reference", SQL_REFERENCE},
60
{"returned_length", SQL_RETURNED_LENGTH},
61
{"returned_octet_length", SQL_RETURNED_OCTET_LENGTH},
63
{"section", SQL_SECTION},
65
{"signed", SQL_SIGNED},
66
{"sql", SQL_SQL}, /* strange thing, used for into sql
67
* descriptor MYDESC; */
68
{"sqlerror", SQL_SQLERROR},
69
{"sqlprint", SQL_SQLPRINT},
70
{"sqlwarning", SQL_SQLWARNING},
72
{"struct", SQL_STRUCT},
73
{"unsigned", SQL_UNSIGNED},
76
{"whenever", SQL_WHENEVER},
80
* ScanECPGKeywordLookup - see if a given word is a keyword
82
* Returns a pointer to the ScanKeyword table entry, or NULL if no match.
84
* The match is done case-insensitively. Note that we deliberately use a
85
* dumbed-down case conversion that will only translate 'A'-'Z' into 'a'-'z',
86
* even if we are in a locale where tolower() would produce more or different
87
* translations. This is to conform to the SQL99 spec, which says that
88
* keywords are to be matched in this way even though non-keyword identifiers
89
* receive a different case-normalization mapping.
92
ScanECPGKeywordLookup(char *text)
96
char word[NAMEDATALEN];
101
/* We assume all keywords are shorter than NAMEDATALEN. */
102
if (len >= NAMEDATALEN)
106
* Apply an ASCII-only downcasing. We must not use tolower() since it
107
* may produce the wrong translation in some locales (eg, Turkish),
108
* and we don't trust isupper() very much either. In an ASCII-based
109
* encoding the tests against A and Z are sufficient, but we also
110
* check isupper() so that we will work correctly under EBCDIC. The
111
* actual case conversion step should work for either ASCII or EBCDIC.
113
for (i = 0; i < len; i++)
117
if (ch >= 'A' && ch <= 'Z' && isupper((unsigned char) ch))
124
* Now do a binary search using plain strcmp() comparison.
126
low = &ScanKeywords[0];
127
high = endof(ScanKeywords) - 1;
133
middle = low + (high - low) / 2;
134
difference = strcmp(middle->name, word);
137
else if (difference < 0)