Header And Logo

PostgreSQL
| The world's most advanced open source database.

ecpg_keywords.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * ecpg_keywords.c
00004  *    lexical token lookup for reserved words in postgres embedded SQL
00005  *
00006  * IDENTIFICATION
00007  *    src/interfaces/ecpg/preproc/ecpg_keywords.c
00008  *
00009  *-------------------------------------------------------------------------
00010  */
00011 
00012 #include "postgres_fe.h"
00013 
00014 #include <ctype.h>
00015 
00016 #include "extern.h"
00017 #include "preproc.h"
00018 
00019 /* Globals from keywords.c */
00020 extern const ScanKeyword SQLScanKeywords[];
00021 extern const int NumSQLScanKeywords;
00022 
00023 /*
00024  * List of (keyword-name, keyword-token-value) pairs.
00025  *
00026  * !!WARNING!!: This list must be sorted, because binary
00027  *       search is used to locate entries.
00028  */
00029 static const ScanKeyword ECPGScanKeywords[] = {
00030     /* name, value, category */
00031 
00032     /*
00033      * category is not needed in ecpg, it is only here so we can share the
00034      * data structure with the backend
00035      */
00036     {"allocate", SQL_ALLOCATE, 0},
00037     {"autocommit", SQL_AUTOCOMMIT, 0},
00038     {"bool", SQL_BOOL, 0},
00039     {"break", SQL_BREAK, 0},
00040     {"call", SQL_CALL, 0},
00041     {"cardinality", SQL_CARDINALITY, 0},
00042     {"connect", SQL_CONNECT, 0},
00043     {"count", SQL_COUNT, 0},
00044     {"datetime_interval_code", SQL_DATETIME_INTERVAL_CODE, 0},
00045     {"datetime_interval_precision", SQL_DATETIME_INTERVAL_PRECISION, 0},
00046     {"describe", SQL_DESCRIBE, 0},
00047     {"descriptor", SQL_DESCRIPTOR, 0},
00048     {"disconnect", SQL_DISCONNECT, 0},
00049     {"found", SQL_FOUND, 0},
00050     {"free", SQL_FREE, 0},
00051     {"get", SQL_GET, 0},
00052     {"go", SQL_GO, 0},
00053     {"goto", SQL_GOTO, 0},
00054     {"identified", SQL_IDENTIFIED, 0},
00055     {"indicator", SQL_INDICATOR, 0},
00056     {"key_member", SQL_KEY_MEMBER, 0},
00057     {"length", SQL_LENGTH, 0},
00058     {"long", SQL_LONG, 0},
00059     {"nullable", SQL_NULLABLE, 0},
00060     {"octet_length", SQL_OCTET_LENGTH, 0},
00061     {"open", SQL_OPEN, 0},
00062     {"output", SQL_OUTPUT, 0},
00063     {"reference", SQL_REFERENCE, 0},
00064     {"returned_length", SQL_RETURNED_LENGTH, 0},
00065     {"returned_octet_length", SQL_RETURNED_OCTET_LENGTH, 0},
00066     {"scale", SQL_SCALE, 0},
00067     {"section", SQL_SECTION, 0},
00068     {"short", SQL_SHORT, 0},
00069     {"signed", SQL_SIGNED, 0},
00070     {"sql", SQL_SQL, 0},        /* strange thing, used for into sql descriptor
00071                                  * MYDESC; */
00072     {"sqlerror", SQL_SQLERROR, 0},
00073     {"sqlprint", SQL_SQLPRINT, 0},
00074     {"sqlwarning", SQL_SQLWARNING, 0},
00075     {"stop", SQL_STOP, 0},
00076     {"struct", SQL_STRUCT, 0},
00077     {"unsigned", SQL_UNSIGNED, 0},
00078     {"var", SQL_VAR, 0},
00079     {"whenever", SQL_WHENEVER, 0},
00080 };
00081 
00082 /*
00083  * ScanECPGKeywordLookup - see if a given word is a keyword
00084  *
00085  * Returns a pointer to the ScanKeyword table entry, or NULL if no match.
00086  * Keywords are matched using the same case-folding rules as in the backend.
00087  */
00088 const ScanKeyword *
00089 ScanECPGKeywordLookup(const char *text)
00090 {
00091     const ScanKeyword *res;
00092 
00093     /* First check SQL symbols defined by the backend. */
00094     res = ScanKeywordLookup(text, SQLScanKeywords, NumSQLScanKeywords);
00095     if (res)
00096         return res;
00097 
00098     /* Try ECPG-specific keywords. */
00099     res = ScanKeywordLookup(text, ECPGScanKeywords, lengthof(ECPGScanKeywords));
00100     if (res)
00101         return res;
00102 
00103     return NULL;
00104 }