ast

package
v0.0.0-...-91c5940 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2017 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SPEC_EXPRESSION_DEPTH_MAX = 50 // max expression depth

	SPEC_LOOP_STACK_SIZE               = 10  // number of nested WHILE
	SPEC_CASE_WHEN_COUNT_MAX           = 100 // max count of WHEN clauses
	SPEC_FUNCTION_ARGUMENTS_COUNT_MAX  = 100 // for function(arg, arg, arg, ...)
	SPEC_EXPRESSIONS_IN_LIST_COUNT_MAX = 100 // for IN(exp, exp, exp, ...)

	SPEC_OBJECT_NAME_NUMBER_OF_PARTS = 3 // db.schema.object

	SPEC_TABLE_INDEX_KEYLIST_DEFAULT_SIZE = 4

	SPEC_NUMBER_OF_PRINCIPALS_IN_LIST_MAX = 50

	SPEC_INSERT_INTO_COL_LIST_DEFAULT_SIZE        = 30
	SPEC_INSERT_INTO_VALUES_EXPRESSIONS_COUNT_MAX = 200  // max count of expression in VALUES clause, for INSERT INTO table VALUES (exp, exp, exp, ...)
	SPEC_INSERT_INTO_VALUES_COUNT_MAX             = 1000 // max count of VALUES clauses for INSERT INTO

	SPEC_SELECT_NUMBER_OF_COLUMNS_MAX  = 300 // max column count in SELECT clause
	SPEC_SELECT_NUMBER_OF_ORDER_BY_MAX = 20

	PASSWORD_MIN_LENGTH = 6
	PASSWORD_MAX_LENGTH = 128

	SPEC_SLEEP_MAX_SECONDS = 600 // seconds

	SPEC_FLASHTABLE_GENERATOR_START_TBLID = -100 // first value for flash tables (grouptables and sorttables)
)
View Source
const (
	EAT_OPERATOR_UNARY     bool = true
	EAT_OPERATOR_NON_UNARY bool = false
)
View Source
const (
	EAT_DATATYPE_CAST        eat_datatype_option_t = 10
	EAT_DATATYPE_DECLARATION eat_datatype_option_t = 20
)

used as option for Eat_builtin_datatype().

View Source
const (
	DEBUG_PRINT_TABLEDEF_COLDEFS option_debug_print_t = 1 + iota
	DEBUG_PRINT_TABLEDEF_NK
	DEBUG_PRINT_TABLEDEF_PAYLOAD
	DEBUG_PRINT_TABLEDEF_INDEX_COLDEFS_AFTER_NK
)
View Source
const (
	TOKEN_TABLE_NUMBER_OF_PARTS             = 3 // db schema table
	TOKEN_COLUMN_NUMBER_OF_PARTS            = 4 // db schema table column
	TOKEN_UFUNC_NUMBER_OF_PARTS             = 3 // server db schema function
	SPEC_QUALIFIED_NAME_NUMBER_OF_PARTS_MAX = 4 // max number of parts of a qualified name, e.g. mydb.dbo.mytable.mycol.
)
View Source
const (
	COMPATMASK_SERVER_PARAM_OPS = COMPAT_ALTER_SERVER_PARAMETER                                                                                                                                                                               // mask for statements managing server parameters
	COMPATMASK_BACKUP_OPS       = COMPAT_BACKUP | COMPAT_RESTORE                                                                                                                                                                              // mask for backup and restore statements
	COMPATMASK_LOGIN_OPS        = COMPAT_CREATE_LOGIN | COMPAT_ALTER_LOGIN | COMPAT_DROP_LOGIN                                                                                                                                                // mask for statements managing logins
	COMPATMASK_DATABASE_OPS     = COMPAT_CREATE_DATABASE | COMPAT_ALTER_DATABASE | COMPAT_DROP_DATABASE | COMPAT_ALTER_AUTHORIZATION                                                                                                          // mask for statements managing databases
	COMPATMASK_PRINCIPAL_OPS    = COMPAT_CREATE_USER | COMPAT_ALTER_USER | COMPAT_DROP_USER | COMPAT_CREATE_ROLE | COMPAT_ALTER_ROLE | COMPAT_DROP_ROLE                                                                                       // mask for statements managing principals
	COMPATMASK_TABLE_OPS        = COMPAT_CREATE_TABLE | COMPAT_ALTER_TABLE | COMPAT_DROP_TABLE | COMPAT_CREATE_INDEX | COMPAT_ALTER_INDEX | COMPAT_DROP_INDEX                                                                                 // mask for statements managing table definitions
	COMPATMASK_DATA_OPS         = COMPAT_SELECT | COMPAT_BULK_EXPORT | COMPAT_INSERT | COMPAT_BULK_INSERT | COMPAT_UPDATE | COMPAT_DELETE | COMPAT_TRUNCATE | COMPAT_TRUNCATE_WITH_SHRINK_FILE | COMPAT_SHRINK | COMPAT_CREATE_VARIABLE_TABLE // mask for statements dealing with records

	COMPATMASK_LOGIN_PRINCIPAL_OPS = COMPATMASK_LOGIN_OPS | COMPATMASK_PRINCIPAL_OPS
)
View Source
const DEBUG_PRINT_AST_MARGIN_CAPACITY_DEFAULT = 100
View Source
const SIZEOF_COMPATIBILITY = 64 // size in bits of Compatibility

Variables

first argument for functions DATEADD, DATEDIFF, DATENAME, DATEPART.

View Source
var G_SYSFUNC_DESCRIPTION_MAP = map[string]*Sysfunc_description{}/* 115 elements not displayed */

lookup table for function names. Internal functions used only by the compiler are not listed here (see SYSFUNC_DESCR_xxx list of constants below).

Functions

func Coalesce_colname

func Coalesce_colname(database_name string, schema_name string, table_name string, col_name string) string

func Coalesce_objname

func Coalesce_objname(database_name string, schema_name string, object_name string) string

func Debug_print_AST

func Debug_print_AST(context *rsql.Context, tok Tokener) (rsql_err *rsql.Error)

print AST tree of the batch.

'margin_idx' is the number of characters up to and including the vertical bar | or + sign you can see in the tree output.

Each debug_print_xxx() function sets this character at position margin_idx, and prints additional information.

func Get_gtabledef_from_create_table_script

func Get_gtabledef_from_create_table_script(database_name string, script []byte) (schema_name string, gtabledef *rsql.GTabledef, rsql_err *rsql.Error)

Get_gtabledef_from_create_table_script creates *GTabledef from a CREATE TABLE script. It is used by RESTORE DATABASE statement, to create tables.

func LIKE_is_range

func LIKE_is_range(s string) (prefix string, ok bool)

LIKE_is_range checks if s is a LIKE expression of the form 'prefix%'. It this is the case, both expressions below are equivalent:

a LIKE 'prefix%'

a >= 'prefix' AND a <= 'prefix\U0010FFFD'

func My_debug_print_Token_primary_tree

func My_debug_print_Token_primary_tree(tok *Token_primary, i int)

########### THIS FUNCTION IS JUST FOR MY PRIVATE USE, FOR DEBUGGING. IT SHOULD NOT BE USED FOR ANY OTHER PURPOSE !!!

func TOP_value_exists

func TOP_value_exists(xtable Xtable) bool

Types

type Column

type Column struct {
	Col_label          string // label. Empty string if no label.
	Col_label_original string // same as Col_label, but with original case. For display usage.
	Col_expression     *Token_primary
	Col_no             int
}

Column is a column of SELECT.

Col_expression contain the dataslot making up the output values of a SELECT statement.

type Compatibility

type Compatibility uint64 // category of the statement, to check if it is compatible with other statements of different category in the same batch
const (
	COMPAT_ALTER_SERVER_PARAMETER Compatibility = 1 << iota

	COMPAT_BACKUP
	COMPAT_RESTORE

	COMPAT_CREATE_LOGIN
	COMPAT_ALTER_LOGIN
	COMPAT_DROP_LOGIN

	COMPAT_CREATE_DATABASE
	COMPAT_ALTER_DATABASE
	COMPAT_DROP_DATABASE
	COMPAT_ALTER_AUTHORIZATION

	COMPAT_CREATE_USER
	COMPAT_ALTER_USER
	COMPAT_DROP_USER
	COMPAT_CREATE_ROLE
	COMPAT_ALTER_ROLE
	COMPAT_DROP_ROLE

	COMPAT_CREATE_TABLE
	COMPAT_ALTER_TABLE
	COMPAT_DROP_TABLE

	COMPAT_CREATE_INDEX
	COMPAT_ALTER_INDEX
	COMPAT_DROP_INDEX

	COMPAT_SELECT
	COMPAT_BULK_EXPORT
	COMPAT_INSERT
	COMPAT_BULK_INSERT
	COMPAT_UPDATE
	COMPAT_DELETE
	COMPAT_TRUNCATE
	COMPAT_TRUNCATE_WITH_SHRINK_FILE
	COMPAT_SHRINK
	COMPAT_CREATE_VARIABLE_TABLE
)

func (Compatibility) String

func (compat Compatibility) String() string

type Condinfo

type Condinfo struct {
	csr.Cond

	Tok_cond *Token_primary
}

type Datepartfield_t

type Datepartfield_t int16
const (
	DATEPARTFIELD_YEAR Datepartfield_t = iota + 1
	DATEPARTFIELD_QUARTER
	DATEPARTFIELD_MONTH
	DATEPARTFIELD_DAYOFYEAR
	DATEPARTFIELD_DAY
	DATEPARTFIELD_WEEK
	DATEPARTFIELD_WEEKDAY
	DATEPARTFIELD_HOUR
	DATEPARTFIELD_MINUTE
	DATEPARTFIELD_SECOND
	DATEPARTFIELD_MILLISECOND
	DATEPARTFIELD_MICROSECOND
	DATEPARTFIELD_NANOSECOND
	DATEPARTFIELD_ISO_WEEK
)

first argument for functions DATEADD, DATEDIFF, DATENAME, DATEPART.

func (Datepartfield_t) String

func (d Datepartfield_t) String() string

type Dictionary_LABEL

type Dictionary_LABEL struct {
	// contains filtered or unexported fields
}

func (*Dictionary_LABEL) Check_exists

func (dictlab *Dictionary_LABEL) Check_exists(label string) *rsql.Error

func (*Dictionary_LABEL) Get

func (dictlab *Dictionary_LABEL) Get(label string) (*Token_stmt_LABEL, *rsql.Error)

func (*Dictionary_LABEL) Initialize

func (dictlab *Dictionary_LABEL) Initialize()

func (*Dictionary_LABEL) Put

func (dictlab *Dictionary_LABEL) Put(label string, tok_label *Token_stmt_LABEL) *rsql.Error

type Lookup_table_mode_t

type Lookup_table_mode_t uint8
const (
	LOOKUP_TABLE_NORMAL    Lookup_table_mode_t = iota + 1 // if table alias exists, it is checked, but table name is not checked. If no alias, table name is checked.
	LOOKUP_TABLE_NAME_ONLY                                // only table name is checked (alias is just ignored if exists)
)

type Margin_buffer_t

type Margin_buffer_t []byte

func (*Margin_buffer_t) Debug_print_GTabledef

func (margin *Margin_buffer_t) Debug_print_GTabledef(context *rsql.Context, margin_idx int, database_name string, schema_name string, gtabledef *rsql.GTabledef)

type Option_kind_table_t

type Option_kind_table_t uint8
const (
	OPT_PERMANENT_TABLE Option_kind_table_t = 1
	OPT_VARIABLE_TABLE  Option_kind_table_t = 2
	OPT_RESTORING_TABLE Option_kind_table_t = 3 // used by RESTORE, when creating GTabledef from backup file
)

type Options_t

type Options_t uint32
const (
	OPTION_QUOTED_IDENTIFIER Options_t = 1 << iota // option for lexer: identifier may be quoted by double-quotes. The default is read from dict.MASTER server parameters.
	OPTION_ANSI_NULL_DFLT_ON                       // option for parser: for CREATE TABLE, column without NULL/NOT NULL clause are NULL. This option is set by default.
	OPTION_PARSEONLY                               // option for caller's use: only parse the batch. No execution.
	OPTION_NOEXEC                                  // option for caller's use: same as PARSEONLY.
)

func Get_default_options

func Get_default_options() Options_t

type Orderby_direction_t

type Orderby_direction_t uint8
const (
	ORDER_BY_ASC Orderby_direction_t = iota + 1
	ORDER_BY_DESC
)

type Orderby_part

type Orderby_part struct {
	Odr_expression *Token_primary
	Odr_direction  Orderby_direction_t
}

type Parser

type Parser struct {
	lex.Lexer

	Options Options_t

	Servername               string
	Server_default_collation string

	LABELS Dictionary_LABEL // contains all labels (used by GOTO) encountered in batch

	Xtable_object_stack Xtable_stack_t // stack in which SELECT, JOIN, and real tables are stacked, in order for identifiers to lookup the proper namespace during decoration

	Batch_ast_anchor Tokener // after parsing, first statement of AST tree is here

	Compatibilities Compatibility       // categories of all statements in the batch, to check if they can coexist in the same batch
	Registration    *lk.Registration    // during parsing stage, all table names are put in Registration, and locks will be acquired before decoration stage
	Temptable_bag   *rsql.Temptable_bag // contains temporary tables (@vartables)

	Insert_stmts_count int // count the number of INSERT statements in a batch. Limiting this number helps avoid long lists of INSERT statements, which may use too much memory for AST tree.
	// contains filtered or unexported fields
}

func New_parser

func New_parser(server_default_collation_string string, session_default_db_string string, options Options_t, registration *lk.Registration) (*Parser, *rsql.Error)

func (*Parser) Attach_batch

func (parser *Parser) Attach_batch(batch_text []byte) *rsql.Error

func (*Parser) Check_compatibility

func (parser *Parser) Check_compatibility(compat Compatibility) *rsql.Error

func (*Parser) Create_TOK_PRIM_LITERAL_BOOLEAN

func (parser *Parser) Create_TOK_PRIM_LITERAL_BOOLEAN(val bool) *Token_primary

Create_TOK_PRIM_LITERAL_BOOLEAN creates a 'literal boolean' token from a value.

func (*Parser) Create_TOK_PRIM_LITERAL_NULL

func (parser *Parser) Create_TOK_PRIM_LITERAL_NULL() *Token_primary

Create_TOK_PRIM_LITERAL_NULL creates a 'literal NULL' token.

func (*Parser) Create_TOK_PRIM_LITERAL_NUMBER_INTEGRAL

func (parser *Parser) Create_TOK_PRIM_LITERAL_NUMBER_INTEGRAL(number int32) *Token_primary

Create_TOK_PRIM_LITERAL_NUMBER_INTEGRAL creates a 'literal number' token from a number.

func (*Parser) Create_TOK_PRIM_LITERAL_STRING

func (parser *Parser) Create_TOK_PRIM_LITERAL_STRING(val string) *Token_primary

Create_TOK_PRIM_LITERAL_STRING creates a 'literal string' token from a value.

func (*Parser) Create_TOK_PRIM_LITERAL_SYSCOLLATOR

func (parser *Parser) Create_TOK_PRIM_LITERAL_SYSCOLLATOR(collation_name string) *Token_primary

Create_TOK_PRIM_LITERAL_SYSCOLLATOR creates a literal SYSCOLLATOR token from a collation name.

func (*Parser) Create_TOK_PRIM_OPERATOR_COMP

func (parser *Parser) Create_TOK_PRIM_OPERATOR_COMP(prim_subtype Prim_subtype_t, tok_a *Token_primary, tok_b *Token_primary) *Token_primary

Create_TOK_PRIM_OPERATOR_COMP creates a TOK_PRIM_OPERATOR_COMP_EQUAL, _GREATER, etc token, with tok_a and tok_b as operands.

func (*Parser) Create_TOK_PRIM_SYSFUNC_COMPILE_VARCHAR_TO_REGEXPLIKE

func (parser *Parser) Create_TOK_PRIM_SYSFUNC_COMPILE_VARCHAR_TO_REGEXPLIKE(expression *Token_primary, escape_char *Token_primary) *Token_primary

Create_TOK_PRIM_SYSFUNC_COMPILE_VARCHAR_TO_REGEXPLIKE creates a SYSFUNC token with SYSFUNC_COMPILE_VARCHAR_TO_REGEXPLIKE function.

func (*Parser) Create_TOK_PRIM_SYSFUNC_DMY_SYSLANGUAGE

func (parser *Parser) Create_TOK_PRIM_SYSFUNC_DMY_SYSLANGUAGE(syslanguage *Token_primary, dmy *Token_primary) *Token_primary

Create_TOK_PRIM_SYSFUNC_DMY_SYSLANGUAGE creates a SYSFUNC token with SYSFUNC_DMY_SYSLANGUAGE function.

func (*Parser) Create_TOK_PRIM_SYSFUNC_FIRSTDAYOFWEEK_SYSLANGUAGE

func (parser *Parser) Create_TOK_PRIM_SYSFUNC_FIRSTDAYOFWEEK_SYSLANGUAGE(syslanguage *Token_primary, firstdayofweek *Token_primary) *Token_primary

Create_TOK_PRIM_SYSFUNC_FIRSTDAYOFWEEK_SYSLANGUAGE creates a SYSFUNC token with SYSFUNC_FIRSTDAYOFWEEK_SYSLANGUAGE function.

func (*Parser) Create_TOK_PRIM_SYSFUNC_GETUTCDATE

func (parser *Parser) Create_TOK_PRIM_SYSFUNC_GETUTCDATE() *Token_primary

Create_TOK_PRIM_SYSFUNC_GETUTCDATE creates a SYSFUNC token with SYSFUNC_GETUTCDATE function.

func (*Parser) Create_TOK_PRIM_VARIABLE

func (parser *Parser) Create_TOK_PRIM_VARIABLE(var_name lex.Lexeme) *Token_primary

Create_TOK_PRIM_VARIABLE creates a 'variable' token from a lexeme. E.g. var_name may be LEXEME_SYSVAR_CURRENT_LANGUAGE, for the "_@current_language" variable.

func (*Parser) Eat_ASSIGNMENT_operator_and_expression

func (parser *Parser) Eat_ASSIGNMENT_operator_and_expression(token_primary_lvalue *Token_primary) (*Token_stmt_ASSIGNMENT, *rsql.Error)

Eat_ASSIGNMENT_operator_and_expression is an auxiliary function to parse assignment to a variable.

It parses the [assignment operator][expression] sequence.

It can be a plain assignment :
  - @variable = expression

or a compound assignment :
  - @variable += expression
  - @variable -= expression
  - @variable *= expression
  - etc

token_primary_lvalue is the variable or identifier to be assigned to.

Returns new Token_stmt_ASSIGNMENT token, with token_primary_lvalue as left value, and expression eaten as right value.

func (*Parser) Eat_CASE

func (parser *Parser) Eat_CASE() (*Token_primary, *rsql.Error)

Eat_CASE creates a CASE token.

NOTE: the current lexeme MUST be LEX_KEYWORD_CASE.

func (*Parser) Eat_CAST

func (parser *Parser) Eat_CAST() (*Token_primary, *rsql.Error)

Eat_CAST creates a CAST token from the current lexemes.

NOTE: the current lexeme MUST be LEX_KEYWORD_CAST.

This function eats the arguments of the CAST function which syntax is CAST(expression AS datatype).

func (*Parser) Eat_COLLATE

func (parser *Parser) Eat_COLLATE() (collation string, rsql_err *rsql.Error)

Eat_COLLATE eats a COLLATE clause and returns the collation.

NOTE: the current lexeme MUST be LEX_KEYWORD_COLLATE.

This function eats the collation locale argument of COLLATE.

func (*Parser) Eat_CONVERT

func (parser *Parser) Eat_CONVERT() (*Token_primary, *rsql.Error)

Eat_CONVERT creates a TOK_PRIM_CAST token from the current lexeme.

NOTE: the current lexeme MUST be LEX_KEYWORD_CONVERT.

This function eats the arguments of the CONVERT function which syntax is CONVERT(datatype, expression [, style ] ).

func (*Parser) Eat_EXISTS

func (parser *Parser) Eat_EXISTS() (*Token_primary, *rsql.Error)

Eat_EXISTS creates an EXISTS token.

NOTE: the current lexeme MUST be LEX_KEYWORD_EXISTS.

func (*Parser) Eat_VALUES_list_of_expressions

func (parser *Parser) Eat_VALUES_list_of_expressions() ([]*Token_primary, *rsql.Error)

Eat_VALUES_list_of_expressions eats a sequence of VALUES expressions.

If at least one expression (that is, at least one valid term) is not available, a syntax error is returned.

Keyword DEFAULT is allowed. In this case, the pointer to the expression is set to nil.

func (*Parser) Eat_atfunc

func (parser *Parser) Eat_atfunc() (*Token_primary, *rsql.Error)

Eat_atfunc creates a system @@function token from the current lexeme.

NOTE: the current lexeme MUST be LEX_ATFUNC.

func (*Parser) Eat_auxword

func (parser *Parser) Eat_auxword(auxword lex.Auxword_t) *rsql.Error

func (*Parser) Eat_builtin_datatype

func (parser *Parser) Eat_builtin_datatype(option eat_datatype_option_t) (sql_datatype rsql.Datatype_t, sql_precision uint16, sql_scale uint16, sql_fixlen_flag bool, rsql_err *rsql.Error)

Eat_builtin_datatype eats a builtin datatype.

E.g. CHAR, VARCHAR(20), VARCHAR(MAX) etc.

The argument 'option' is EAT_DATATYPE_DECLARATION or EAT_DATATYPE_CAST.

All character datatypes used internally by rsql are unicode. So, NATIONAL CHARACTER, NVARCHAR, etc are of no use and always converted to CHAR and VARCHAR. So, the datatypes CHAR, VARCHAR or TEXT contain unicode strings.

The current lexeme must be LEX_IDENTPART, or LEX_KEYWORD_NATIONAL followed by LEX_IDENTPART. Else, a syntax error is returned.

func (*Parser) Eat_coldef_and_column_constraints

func (parser *Parser) Eat_coldef_and_column_constraints(durability rsql.Durability_t, colmap map[string]*rsql.Coldef) (coldef *rsql.Coldef, indexdef *rsql.Tabledef, identity_seed int64, identity_increment int64, rsql_err *rsql.Error)

Eat_coldef_and_column_constraints eats column definition and column constraints (NULL, NOT NULL, CHECK, PRIMARY KEY, UNIQUE, iNDEX) Note: INDEX clause is in fact not a constraint, but the semantic point is moot.

It always returns a Coldef. If a UNIQUE, PRIMARY KEY, INDEX clause exists, a Tabledef is also returned.

Returned Tabledef can have Td_cluster_type==TD_CLUSTER_TYPE_UNDEFINED only for PRIMARY KEY.
For INDEX, "rowid" is appended to the key list, so that the native key of the index is unique. Native keys of base tables or index tables are always unique.

<column_definition> ::=
column_name <data_type>
    [ COLLATE collation_name ]
    [ NULL | NOT NULL ]
    [ IDENTITY [ ( seed,increment ) ]

    [ [ CONSTRAINT constraint_name ] { { PRIMARY KEY | UNIQUE } [ CLUSTERED | NONCLUSTERED ] } ]

    [ INDEX index_name [ CLUSTERED | NONCLUSTERED ] ]

We don't care about constraint name, except for PRIMARY KEY and UNIQUE, for which it becomes the index name. INDEX clause has always a name.

IMPORTANT: the returned *rsql.Tabledef can have no indexdef.Td_index_name and indexdef.Td_index_name_original.
           In this case, it is the responsability of the caller to assign proper names to these fields.

func (*Parser) Eat_coldefs_and_constraints

func (parser *Parser) Eat_coldefs_and_constraints(gtabledef *rsql.GTabledef) *rsql.Error

eat all column definitions and table constraints of a CREATE TABLE, and put them in gtabledef.

func (*Parser) Eat_column_list

func (parser *Parser) Eat_column_list() (listcol []*Column, listvar []*Token_primary, rsql_err *rsql.Error)

eat all columns of a SELECT list.

func (*Parser) Eat_compound_assignment_operator

func (parser *Parser) Eat_compound_assignment_operator() (prim_subtype_underlying_operator Prim_subtype_t, lexeme_underlying_operator lex.Lexeme, rsql_err *rsql.Error)

eats a plain or compund assignment operator.

  • if plain assignment '=', returns (TOK_PRIM_OPERATOR_COMP_EQUAL, Lexeme{}, nil)
  • if compund operator, e.g. '+=' , returns e.g. (TOK_PRIM_OPERATOR_PLUS, lex.LEXEME_OPERATOR_PLUS, nil)

func (*Parser) Eat_equal_symbol

func (parser *Parser) Eat_equal_symbol() *rsql.Error

func (*Parser) Eat_expression

func (parser *Parser) Eat_expression() (*Token_primary, *rsql.Error)

Eat_expression eats a full expression, made up of a sequence of 'terms' and 'operators'.

[unary op][unary op]...[term] [ [non-unary op][unary op][unary op]...[term] ] ...

The processing is as follows :

  - All the tokens are read and chained one after another in a main linear list which anchor is 'token_list_dummy'.
  - Each operator token is also put in an operator list with the proper precedence, and ordered in this list following its associativity direction ( ---> or <--- ).
  - If a literal integer, float or numeric literal number is preceded by unary minus operator, the operator is removed from main list and from operator precedence list, because the sign belongs to the literal number it prefixes. Then, the token's lexeme is replaced by a lexeme with negative literal number. Unary plus are just discarded.
  - Then, each operator token of each list (from strongest precedence order to weakest) is processed to graft its left and right operands, and remove them from the main list. This way, the token chain is transformed into an AST.
  - At the end of this processing, only one token must remain, linked to the list anchor 'token_list_dummy'.

A token that is grafted to an operator and removed from the chain must be TOK_PRIM_STATUS_COMPLETE, meaning that it has all its operands grafted.
If TOK_PRIM_STATUS_UNCOMPLETE, it means that the token has missing operands.
In this case, it cannot be grafted to another operator and removed from the chain. It is a mismatch syntax error.
Example: "22 + 33 is null + 44".       "22" and "33" are grafted to "+", but "is null" cannot be grafted as left operand of "+" because "is null" is not TOK_PRIM_STATUS_COMPLETE yet.

NOTE: The expression must contain at least one valid term. Else, it returns a syntax error.

The returned token status is TOK_PRIM_STATUS_COMPLETE and is the root of the expression AST tree.

func (*Parser) Eat_identpart

func (parser *Parser) Eat_identpart() (string, *rsql.Error)

func (*Parser) Eat_identpart_collation_normalized

func (parser *Parser) Eat_identpart_collation_normalized() (string, *rsql.Error)

Eat_identpart_collation_normalized returns a normalized collation if collation is supported, or an error. Collation must end with "_ci_ai", "_ci_as" or "_cs_as", e.g. "fr_cs_as" or "fr_ca_cs_as".

Supported collations are listed in G_COLLATION_MAP, which contains all collations from http://unicode.org/cldr/trac/browser/tags/release-XX/common/collation?order=name

func (*Parser) Eat_identpart_language_normalized

func (parser *Parser) Eat_identpart_language_normalized() (string, *rsql.Error)

Eat_identpart_language_normalized returns a normalized language if language is supported, or an error. Languages are e.g. "fr_ch", "fr_fr", "en_us", etc. "french" is alias for "fr_fr", "english" is alias for "en_us", etc.

func (*Parser) Eat_identpart_original

func (parser *Parser) Eat_identpart_original() (ident string, ident_original string, rsql_err *rsql.Error)

func (*Parser) Eat_keyword

func (parser *Parser) Eat_keyword(lex_subtype lex.Lex_subtype_t) *rsql.Error

func (*Parser) Eat_keyword_ON_OFF

func (parser *Parser) Eat_keyword_ON_OFF() (bool, *rsql.Error)

func (*Parser) Eat_keyword_TRUE_FALSE

func (parser *Parser) Eat_keyword_TRUE_FALSE() (bool, *rsql.Error)

func (*Parser) Eat_list_of_colnames_for_INSERT

func (parser *Parser) Eat_list_of_colnames_for_INSERT() ([]string, *rsql.Error)

Eat_list_of_colnames_for_INSERT eats a list of column names, enclosed in parentheses. The list cannot be empty.

func (*Parser) Eat_list_of_colnames_for_index

func (parser *Parser) Eat_list_of_colnames_for_index() ([]string, *rsql.Error)

func (*Parser) Eat_list_of_expressions

func (parser *Parser) Eat_list_of_expressions() ([]*Token_primary, *rsql.Error)

Eat_list_of_expressions eats a sequence of function arguments.

If at least one argument expression (that is, at least one valid term) is not available, a syntax error is returned.

func (*Parser) Eat_list_of_function_arguments

func (parser *Parser) Eat_list_of_function_arguments() ([]*Token_primary, *rsql.Error)

Eat_list_of_function_arguments eats a sequence of function arguments.

If at least one argument expression (that is, at least one valid term) is not available, a syntax error is returned.

func (*Parser) Eat_literal_NULL

func (parser *Parser) Eat_literal_NULL() (*Token_primary, *rsql.Error)

Eat_literal_NULL creates a 'literal NULL' token from the current lexeme.

NOTE; the current lexeme MUST be LEX_KEYWORD_NULL.

func (*Parser) Eat_literal_hexastring

func (parser *Parser) Eat_literal_hexastring() (*Token_primary, *rsql.Error)

Eat_literal_hexastring creates a 'literal hexastring' token from the current lexeme.

NOTE; the current lexeme MUST be LEX_LITERAL_HEXASTRING.

func (*Parser) Eat_literal_integral_int64

func (parser *Parser) Eat_literal_integral_int64() (int64, *rsql.Error)

func (*Parser) Eat_literal_integral_positive_int64

func (parser *Parser) Eat_literal_integral_positive_int64() (int64, *rsql.Error)

func (*Parser) Eat_literal_integral_positive_int64_with_limits

func (parser *Parser) Eat_literal_integral_positive_int64_with_limits(lowest int64, highest int64) (int64, *rsql.Error)

func (*Parser) Eat_literal_number

func (parser *Parser) Eat_literal_number() (*Token_primary, *rsql.Error)

Eat_literal_number creates a 'literal number' token from the current lexeme.

NOTE; the current lexeme MUST be LEX_LITERAL_NUMBER.

func (*Parser) Eat_literal_positive_float64

func (parser *Parser) Eat_literal_positive_float64() (float64, *rsql.Error)

func (*Parser) Eat_literal_string

func (parser *Parser) Eat_literal_string() (*Token_primary, *rsql.Error)

Eat_literal_string creates a 'literal string' token from the current lexeme.

NOTE; the current lexeme MUST be LEX_LITERAL_STRING.

func (*Parser) Eat_literal_stringval

func (parser *Parser) Eat_literal_stringval() (string, *rsql.Error)

func (*Parser) Eat_literal_stringval_lowercase

func (parser *Parser) Eat_literal_stringval_lowercase() (string, *rsql.Error)

func (*Parser) Eat_literal_stringval_or_identpart_lowercase

func (parser *Parser) Eat_literal_stringval_or_identpart_lowercase() (string, *rsql.Error)

func (*Parser) Eat_object_qname

func (parser *Parser) Eat_object_qname() (qname rsql.Object_qname_t, rsql_err *rsql.Error)

Eat_object_qname eats a unqualified or qualified object name (table name, index name, function name, etc).

An object name is made of the following parts : db.schema.object

If database name or schema name are missing, they are filled with current database or schema name.

The current lexeme must be LEX_IDENTPART or LEX_DOT. Else, an error is returned.

func (*Parser) Eat_object_qname_parts

func (parser *Parser) Eat_object_qname_parts() (database_name string, schema_name string, object_name string, object_name_original string, rsql_err *rsql.Error)

Eat_object_qname_parts eats a unqualified or qualified object name (table name, index name, function name, etc).

An object name is made of the following parts : db.schema.object

The current lexeme must be LEX_IDENTPART or LEX_DOT. Else, an error is returned.

IMPORTANT: IF DATABASE NAME OR SCHEMA NAME ARE MISSING, THEY ARE EMPTY STRINGS.
           Use Eat_object_qname() if you want to set empty database and schema name to default server values.

func (*Parser) Eat_operator

func (parser *Parser) Eat_operator(flag_unary bool) (*Token_primary, *rsql.Error)

Eat_operator creates an 'operator' token from the current lexeme.

NOTE: the current lexeme MUST be LEX_OPERATOR.

If flag_unary is EAT_OPERATOR_UNARY, the operator beeing eaten must be a unary operator  '+'  '-'  '~'  'NOT'. Else, an error is returned.

Only operators allowed in expressions are eaten.
That means that compound assignment operators like '+=', '*=', etc return a syntax error.

NOTE: An expression is made up of operators and terms. An operator has properties like precedence, associativity, cardinality.

The attribute 'Prim_status' is TOK_PRIM_STATUS_UNCOMPLETE, so that it cannot be grafted as child of another operator during constructing of AST for the expression.
The function parser.Eat_expression() grafts the needed operands (only elements with status TOK_PRIM_STATUS_COMPLETE are graftable) to each operator, which status will then change to TOK_PRIM_STATUS_COMPLETE.

Argument flag_unary:
      - EAT_OPERATOR_UNARY      : eat a unary operator. The function returns an error if the operator is not unary.
      - EAT_OPERATOR_NON_UNARY  : eat a non-unary operator.

NOTE: There is an interesting problem with IN operator. We can have :
      - IN ( list of arithmetic expression )
      - IN ( SELECT... )

        But the case IN ( (select name from employee) ) is difficult to solve.
          - for MS SQL Server, it is a query returning multiple rows. It uses a bottom-up parser and decides it is a query because the query is not involved in artihmetic operation (e.g. (select name from employee)+'XX'), and there is no other element in the list either.
          - but for us, it is a subquery that must return one row. Because we use a top-down predictive parser and when parsing the first element, we must decide whether it is a query or an arithmetic expression. We cannot delay the decision.
            We do this by checking the first lexeme. If it is a LEX_KEYWORD_SELECT, we choose to call the function that parses a query. Else, as in our example where the first lexeme is a LEX_LPAREN, we call the function that parses a list of expression.
            Note that this is the only pathological case, as a parenthesized select expression is normally followed by a UNION or arithmetic operator. The former will return a syntax error (which is better that running silently and wrongly), and the latter is a correct arithmetic expression in the list.
            And our pathological example will return an error at execution time if it returns more than one row. So, our SQL Server may return errors either at compile time or run time in this crazy case, but doesn't return false results.

      See also parser.Eat_term() where there is a similar problem.

IN (subquery) is replaced by equivalent '=ANY' operator.
NOT IN (subquery) is replaced by equivalent '<>ALL' operator.

func (*Parser) Eat_order_by_clause

func (parser *Parser) Eat_order_by_clause() ([]*Orderby_part, *rsql.Error)

eat list of expressions in a ORDER BY clause.

Return a list of Orderby_parts.

func (*Parser) Eat_placeholder_DEFAULT

func (parser *Parser) Eat_placeholder_DEFAULT() (*Token_primary, *rsql.Error)

Eat_placeholder_DEFAULT creates a placeholder 'DEFAULT' token from the current lexeme. Used only for INSERT VALUES(DEFAULT) or constraint clause.

NOTE: the current lexeme MUST be LEX_KEYWORD_DEFAULT.

func (*Parser) Eat_placeholder_QUALIFIED_STAR

func (parser *Parser) Eat_placeholder_QUALIFIED_STAR() (*Token_primary, *rsql.Error)

Eat_placeholder_QUALIFIED_STAR creates a placeholder for qualified star '*' token from the current lexeme.

NOTE: the current lexeme MUST be LEX_IDENTPART or LEX_DOT.

func (*Parser) Eat_placeholder_QUESTIONMARK

func (parser *Parser) Eat_placeholder_QUESTIONMARK() (*Token_primary, *rsql.Error)

Eat_placeholder_QUESTIONMARK creates a placeholder '?' token from the current lexeme. Used as placeholder for a parameter, in prepared statement for ODBC.

NOTE; the current lexeme MUST be LEX_QUESTIONMARK.

func (*Parser) Eat_placeholder_UNQUALIFIED_STAR

func (parser *Parser) Eat_placeholder_UNQUALIFIED_STAR() (*Token_primary, *rsql.Error)

Eat_placeholder_UNQUALIFIED_STAR creates a placeholder for unqualified star '*' token from the current lexeme.

NOTE: the current lexeme MUST be LEX_OPERATOR_MULT.

func (*Parser) Eat_prefix

func (parser *Parser) Eat_prefix() (name_3, name_2, name_1 string, nb_prefix_parts int, rsql_err *rsql.Error)

Eat_prefix reads all lexemes making up the prefix of a qualified name.

MYDB..CUSTOMERS.NAME  returns the parts [MYDB, "", CUSTOMERS]       nb_prefix_parts == 3
..CUSTOMERS.NAME      returns the parts ["", "", CUSTOMERS]         nb_prefix_parts == 3
...NAME               returns the parts ["", "", ""]                nb_prefix_parts == 3
STREET                returns the parts []                          nb_prefix_parts == 0
MYTABLE.*             returns the parts [MYTABLE]                   nb_prefix_parts == 1
*                     NOT ALLOWED, panics.

After the call, parser.Current_lexeme points to the last part of the qualified name, which must be an identifier or a star '*'.

NOTE: current lexeme must be a LEX_IDENTPART or LEX_DOT.

func (*Parser) Eat_punctuation

func (parser *Parser) Eat_punctuation(lex_type lex.Lex_type_t) *rsql.Error

func (*Parser) Eat_qualified_identifier

func (parser *Parser) Eat_qualified_identifier(database_name, schema_name, table_name string) (*Token_primary, *rsql.Error)

Eat_qualified_identifier creates a qualified identifier token from the current lexeme. The prefix has already been eaten and the prefix parts are passed as arguments.

NOTE: the current lexeme MUST be LEX_IDENTPART.

func (*Parser) Eat_sequence_of_statements_up_to_END

func (parser *Parser) Eat_sequence_of_statements_up_to_END() (sequence_first Tokener, sequence_last Tokener, rsql_err *rsql.Error)

Eat_sequence_of_statements_up_to_END reads a sequence of statements, up to END keyword, assuming that BEGIN keyword has just been read.

If the BEGIN..END block is empty, an error is returned.

NOTE: We assume that 'BEGIN' HAS BEEN READ !!! This function is called only by parser.get_statement() to continue the parsing of the BEGIN block.

func (*Parser) Eat_sequence_of_statements_up_to_LEX_END_OF_BATCH

func (parser *Parser) Eat_sequence_of_statements_up_to_LEX_END_OF_BATCH() (sequence_first Tokener, sequence_last Tokener, rsql_err *rsql.Error)

Eat_sequence_of_statements_up_to_LEX_END_OF_BATCH parses a sequence of statements, from current lexeme up to LEX_END_OF_BATCH lexeme.

If sequence is empty, sequence_first and sequence_last are set to nil.

USE [database name] is not only a statement, but also a compiler pragma for parser use.

func (*Parser) Eat_subquery_many

func (parser *Parser) Eat_subquery_many() (*Token_primary, *rsql.Error)

func (*Parser) Eat_subquery_one

func (parser *Parser) Eat_subquery_one() (*Token_primary, *rsql.Error)

func (*Parser) Eat_sysfunc

func (parser *Parser) Eat_sysfunc(sysfunc_description *Sysfunc_description) (*Token_primary, *rsql.Error)

Eat_sysfunc creates a system function token from the current lexeme.

NOTE: the current lexeme MUST be LEX_IDENTPART or LEX_KEYWORD.

This function eats the arguments of the function. The following cases can happen :

  • lexeme is LEX_IDENTPART : normal system function, like SIN() or GETDATE()
  • lexeme is LEX_KEYWORD : LEFT() or RIGHT() normal system function.

This function doesn't eat the special builtin functions @@ERROR, @@ROWCOUNT etc. Use Eat_atfunc() to eat them. This function doesn't eat SYSTEM_USER, CURRENT_DATE, etc, because they are not followed by parentheses and are keywords, and thus processed as keywords.

func (*Parser) Eat_sysvar

func (parser *Parser) Eat_sysvar(lexeme lex.Lexeme) (*Token_primary, *rsql.Error)

Eat_sysvar creates a 'system variable' token from the current lexeme, like _@system_user_name, _@current_user, etc.

NOTE: pass as argument lex.LEXEME_SYSVAR_SYSTEM_USER_NAME, etc. See static_tables.go file.

func (*Parser) Eat_table

func (parser *Parser) Eat_table() (*Xtable_table, *rsql.Error)

eat a unqualified or qualified table name in a FROM clause. All parts of the qualified name are filled.

This function is called by Eat_xtable_term().

The current lexeme must be LEX_IDENTPART or LEX_DOT.

func (*Parser) Eat_table_constraint_or_index

func (parser *Parser) Eat_table_constraint_or_index(durability rsql.Durability_t, colmap map[string]*rsql.Coldef) (*rsql.Tabledef, *rsql.Error)

eat table constraint (CHECK, PRIMARY KEY, UNIQUE, INDEX)

Returned Tabledef can have Td_cluster_type==TD_CLUSTER_TYPE_UNDEFINED only for PRIMARY KEY.
For INDEX, "rowid" is appended to the key list, so that the native key of the index is unique. Native keys of base tables or index tables are always unique.

  < table_constraint > ::=
  [ CONSTRAINT constraint_name ] { PRIMARY KEY | UNIQUE } [ CLUSTERED | NONCLUSTERED ] ( column [ ,...n ] )

  < table_index > ::=
  INDEX index_name [ CLUSTERED | NONCLUSTERED ] (column [ ,... n ] )

We don't care about constraint name, except for PRIMARY KEY and UNIQUE, for which it becomes the index name. INDEX clause has always a name.

IMPORTANT: the returned *rsql.Tabledef can have no indexdef.Td_index_name and indexdef.Td_index_name_original.
           In this case, it is the responsability of the caller to assign proper names to these fields.

func (*Parser) Eat_term

func (parser *Parser) Eat_term() (*Token_primary, *rsql.Error)

Eat_term creates a 'term' token by eating one or more lexemes.

An expression is made up of operators and terms. Unlike operators, a term has no precedence, associativity, cardinality, and its status is always TOK_PRIM_STATUS_COMPLETE.

A term can be :

  • TOK_PRIM_PLACEHOLDER/_QUESTIONMARK

  • TOK_PRIM_LITERAL_NULL

  • TOK_PRIM_LITERAL_BOOLEAN

  • TOK_PRIM_LITERAL_HEXASTRING

  • TOK_PRIM_LITERAL_STRING

  • TOK_PRIM_LITERAL_NUMBER

  • TOK_PRIM_VARIABLE

  • TOK_PRIM_IDENTIFIER

  • TOK_PRIM_SYSFUNC

  • TOK_PRIM_CAST

  • TOK_PRIM_UFUNC

  • TOK_PRIM_CASE

  • TOK_PRIM_EXISTS

  • TOK_PRIM_SUBQUERY/_ONE. It is a 'select' instruction enclosed in ()

  • the root token of an expression enclosed in ().

The following tokens are not terms and are never returned by this function :

  • TOK_PRIM_OPERATOR is a temporary internal node representing an operator result.

There is the same problem as mentionned for parser.Eat_operator().

In the example
    set @a = ( (select a1 from t1 union all select a2 from t2) union all select a3 from t3 )
    an error occurs at the second 'union'.
    Because our parser will consider the content of the second parenthese to be a select subquery (which is the case), and expect that a closing parenthese or an operator follows. Not a 'union'.
    Our parser is top-down recursive, and must predict if the expression to be eaten is an 'arithmetic' expression or a 'select' subquery. The parser chooses to eat a subquery if the first lexeme is 'select'. Else, it eats an arithmetic expression.
    MS SQL Server can parse this expression because it is a bottom-up parser.
    But such particular cases are very very rare, so we don't consider it is a problem.
    For us, a suquery must begin with the 'SELECT' keyword. Period.

func (*Parser) Eat_ufunc

func (parser *Parser) Eat_ufunc(database_name, schema_name string) (*Token_primary, *rsql.Error)

Eat_ufunc creates a user function token from the current lexeme.

Explicit schema name is mandatory in user function name. If not, a syntax error is raised.

The prefix has already been eaten and the prefix parts are passed as arguments.

NOTE: the current lexeme MUST be LEX_IDENTPART.

func (*Parser) Eat_variable

func (parser *Parser) Eat_variable() (*Token_primary, *rsql.Error)

Eat_variable creates a 'variable' token from the current lexeme.

NOTE: the current lexeme MUST be LEX_VARIABLE.

func (*Parser) Eat_variable_table_qname

func (parser *Parser) Eat_variable_table_qname() (qname rsql.Object_qname_t, rsql_err *rsql.Error)

Eat_variable_table_qname eats a @vartable name.

func (*Parser) Eat_variable_table_qname_parts

func (parser *Parser) Eat_variable_table_qname_parts() (database_name string, schema_name string, object_name string, object_name_original string, rsql_err *rsql.Error)

Eat_variable_table_qname_parts eats a @vartable name.

func (*Parser) Eat_xtable_from

func (parser *Parser) Eat_xtable_from() (*Xtable_from, *rsql.Error)

eat a sequence of xtable join expressions making up a FROM clause and WHERE clause.

xtable_join_expression [, [xtable_join_expression], [xtable_join_expression], ... ] [WHERE expression]

If current lexeme is not FROM keyword, this function creates a FROM clause containing only a Xtable_single{} object.

func (*Parser) Eat_xtable_join_expression

func (parser *Parser) Eat_xtable_join_expression() (Xtable, *rsql.Error)

eat a xtable join expression.

It is a xtable, optionally joined to other xtables.

A xtable is often a plain table. But it can also be a parenthesed expression which is either (SELECT ...) AS alias or (xtable_term JOIN xtable_term ...).

Examples :
  mytable
  mytable JOIN othertable on col1=col2
  (SELECT ...) as t1 JOIN othertable on col1=col2
  (t1 JOIN t2 on a=b) JOIN othertable on col1=col2

Not allowed :
  (t1)

This function eats exactly this kind of table expression :

[xtable] [ JOIN [xtable] ON expression ] [ JOIN [xtable] ON expression ] ...

This function returns a tree of joined tables found in a FROM clause.

The call tree is as follows :

  • parser.Eat_subquery_one() returns a Token_primary

  • parser.Eat_xtable_select_or_union()

  • parser.Eat_subquery_many() returns a Token_primary

  • parser.Eat_xtable_select_or_union()

  • parser.get_statement_select_or_union() returns a Token_stmt_select_or_union

  • parser.Eat_xtable_select_or_union()

  • parser.Eat_xtable_select_or_union() must begin by SELECT. Else, an error is returned.

  • parser.Eat_xtable_select() asserts that current token is SELECT.

  • parser.Eat_from_clause()

  • parser.Eat_xtable_join_expression() eats xtable_term [join xtable_term ...]

  • parser.Eat_xtable_term() eats 'table' or '(...)' or '(select...) as alias'

  • parser.Eat_table()

  • parser.Eat_xtable_join_expression()

  • parser.Eat_xtable_select_or_union() <-- only called when '( SELECT' is encountered

In the FROM clause, when left parenthese is encountered, the parser always presumes first that it may be a ( xtable_term JOIN xtable_term ... ) expression.

The parser tries hard to create a tree made of Xtables and JOINs. Only when '( SELECT' is encountered, is the function parser.Eat_xtable_select_or_union() called.

E.g.     select * from ((select a from t union all select a from t) union all (select ...
The parser will try to parse a series of JOINed tables after the '(', not a UNION expression.
So, it will fail, because a top-down parser cannot cope with this, unless backtracking is implemented.
It is not worth the effort, as I consider such convoluted SQL as pathological.

func (*Parser) Eat_xtable_select

func (parser *Parser) Eat_xtable_select() (*Xtable_select, []*Orderby_part, *rsql.Error)

eat a SELECT expression.

func (*Parser) Eat_xtable_select_or_union

func (parser *Parser) Eat_xtable_select_or_union() (Xtable, []*Orderby_part, *rsql.Error)

Eat_xtable_select_or_union parses SELECT statement, or a series of UNIONed SELECTs.

The statement line can begin with SELECT or a left parenthese.

func (*Parser) Eat_xtable_term

func (parser *Parser) Eat_xtable_term() (Xtable, *rsql.Error)

eat a xtable term in a FROM clause.

A xtable term is

  • a qualified table name (if current lexeme is LEX_IDENTPART)
  • '(' + xtable_expression + ')' where xtable_expression is a tree of xtable_term JOIN xtable_term
  • '(' + SELECT_or_UNION_expression + ')' [AS] alias

It cannot be a single table name enclosed in parentheses :

  • '(' + mytable + ')' is not allowed

This function is called by Eat_xtable_join_expression().

func (*Parser) Get_flashtable_new_tblid

func (parser *Parser) Get_flashtable_new_tblid() int64

func (*Parser) Initialize

func (parser *Parser) Initialize(server_default_collation_string string, session_default_db_string string, options Options_t, registration *lk.Registration) *rsql.Error

func (*Parser) New_token_primary

func (parser *Parser) New_token_primary(prim_type Prim_type_t, prim_subtype Prim_subtype_t, prim_lexeme lex.Lexeme) *Token_primary

New_token_primary is used each time we need a new Token_primary.

func (*Parser) Option

func (parser *Parser) Option(option Options_t) bool

func (*Parser) Parse_all_AST

func (parser *Parser) Parse_all_AST() *rsql.Error

Parse_all_AST parses all AST tree.

type Prim_associativity_t

type Prim_associativity_t uint8 // operator associativity (left or right)
const (
	TOK_PRIM_OPERATOR_ASSOCIATIVITY_RIGHT         Prim_associativity_t = 1 << iota // associativity  --->
	TOK_PRIM_OPERATOR_ASSOCIATIVITY_LEFT                                           // associativity  <---
	TOK_PRIM_OPERATOR_ASSOCIATIVITY_INVALID_VALUE Prim_associativity_t = 255       // invalid associativity value, to catch error if we try to use it.
)

type Prim_cardinality_t

type Prim_cardinality_t uint8 // operator operand specifications
const (
	TOK_PRIM_OPERATOR_CARDINALITY_ONE_OPERAND Prim_cardinality_t = 1 << iota
	TOK_PRIM_OPERATOR_CARDINALITY_TWO_OPERANDS
	TOK_PRIM_OPERATOR_CARDINALITY_SPECIAL_IS_NULL
	TOK_PRIM_OPERATOR_CARDINALITY_SPECIAL_IN_LIST
	TOK_PRIM_OPERATOR_CARDINALITY_SPECIAL_ANY_ALL
	TOK_PRIM_OPERATOR_CARDINALITY_SPECIAL_LIKE
	TOK_PRIM_OPERATOR_CARDINALITY_SPECIAL_BETWEEN
	TOK_PRIM_OPERATOR_CARDINALITY_INVALID_VALUE Prim_cardinality_t = 255 //  invalid cardinality value, to catch error if we try to use it.
)

type Prim_precedence_t

type Prim_precedence_t uint8 // operator precedence
const (
	// the precedence levels must be 0, 1, 2 ... because they are indexes in an array of lists of precedence.
	TOK_PRIM_OPERATOR_PRECEDENCE_UNARY_PLUS        Prim_precedence_t = 0   //   + (unary plus), - (unary minus), ~ (bit not)                              associativity  <---
	TOK_PRIM_OPERATOR_PRECEDENCE_MULTIPLY          Prim_precedence_t = 1   //   * (multiply), / (division), % (modulo)                                    associativity  --->
	TOK_PRIM_OPERATOR_PRECEDENCE_ADDITION          Prim_precedence_t = 2   //   + (add), - (substract), & (bit and), ^ (bit xor), | (bit or)              associativity  --->
	TOK_PRIM_OPERATOR_PRECEDENCE_COMPARISON        Prim_precedence_t = 3   //   =, >, <, >=, <=, <>, !=, !>, !< (comparison)                              associativity  --->
	TOK_PRIM_OPERATOR_PRECEDENCE_COMP2             Prim_precedence_t = 4   //   IS [NOT] NULL, [NOT] LIKE, [NOT] BETWEEN, [NOT] IN, ALL, ANY, SOME        associativity  --->
	TOK_PRIM_OPERATOR_PRECEDENCE_LOGICAL_UNARY_NOT Prim_precedence_t = 5   //   NOT (logical not)                                                         associativity  <---
	TOK_PRIM_OPERATOR_PRECEDENCE_LOGICAL_AND       Prim_precedence_t = 6   //   AND (logical and)                                                         associativity  --->
	TOK_PRIM_OPERATOR_PRECEDENCE_LOGICAL_OR        Prim_precedence_t = 7   //   OR  (logical or)                                                          associativity  --->
	TOK_PRIM_OPERATOR_PRECEDENCE_LEVELS            Prim_precedence_t = 8   //   number of prededence levels (= highest precedence index + 1)
	TOK_PRIM_OPERATOR_PRECEDENCE_INVALID_VALUE     Prim_precedence_t = 255 //   invalid precedence value, to catch error if we try to use it.

)

operator precedence (each precedence level has an associativity left-to-right or right-to-left)

type Prim_status_t

type Prim_status_t uint8 // used during AST tree creation
const (
	TOK_PRIM_STATUS_UNCOMPLETE Prim_status_t = 1 << iota // initial status for operators. During parsing, as operand tokens are grafted onto an operator, the operator status becomes TOK_PRIM_STATUS_COMPLETE.
	TOK_PRIM_STATUS_COMPLETE                             // during parsing, only tokens with TOK_PRIM_STATUS_COMPLETE can be grafted as operands onto an operator.
)

During parsing, all terms and operators of an expression are read and put in a linear chain. Operators are also put in one of the precedence lists. Then, each operator is processed by precedence order, by unchaining left and/or right token, and putting them as operator operands. Thus, tokens are removed from the linear chain, and grafted as operator operands, making an AST tree for the expression. In the end, there should remain only one token in the linear chain, which is the root of the expression AST.

func (Prim_status_t) String

func (status Prim_status_t) String() string

type Prim_subtype_t

type Prim_subtype_t uint32
const (
	TOK_PRIMARY_ANCHOR_SUB Prim_subtype_t = iota + 1 // only used by parser.Eat_expression() for the list anchor dummy variable.

	TOK_PRIM_LITERAL_SYSCOLLATOR_SUB // fr_cs_as
	TOK_PRIM_LITERAL_NULL_SUB        // NULL
	TOK_PRIM_LITERAL_BOOLEAN_SUB     // true of false
	TOK_PRIM_LITERAL_HEXASTRING_SUB  // 0x1234abef
	TOK_PRIM_LITERAL_STRING_SUB      // 'bla'
	TOK_PRIM_LITERAL_NUMBER_INTEGRAL // 123
	TOK_PRIM_LITERAL_NUMBER_MONEY    // $123.45
	TOK_PRIM_LITERAL_NUMBER_NUMERIC  // 123.45
	TOK_PRIM_LITERAL_NUMBER_FLOAT    // 123.45e3

	TOK_PRIM_VARIABLE_SUB   // @bla
	TOK_PRIM_IDENTIFIER_SUB // MYDB.sa.CUSTOMERS.NAME

	TOK_PRIM_OPERATOR_LOGICAL_AND // temporary result from operator
	TOK_PRIM_OPERATOR_LOGICAL_OR
	TOK_PRIM_OPERATOR_LOGICAL_UNARY_NOT
	TOK_PRIM_OPERATOR_IS_NULL
	TOK_PRIM_OPERATOR_IS_NOT_NULL
	TOK_PRIM_OPERATOR_IN_LIST
	TOK_PRIM_OPERATOR_NOT_IN_LIST
	TOK_PRIM_OPERATOR_LIKE
	TOK_PRIM_OPERATOR_NOT_LIKE
	TOK_PRIM_OPERATOR_ESCAPE // pseudo-operator used for    'a' LIKE 'b' ESCAPE 'c'. This pseudo-operator has no precedence, as it is eaten during processing of LIKE operator.
	TOK_PRIM_OPERATOR_ANY
	TOK_PRIM_OPERATOR_ALL
	TOK_PRIM_OPERATOR_BETWEEN
	TOK_PRIM_OPERATOR_NOT_BETWEEN
	TOK_PRIM_OPERATOR_UNARY_PLUS
	TOK_PRIM_OPERATOR_PLUS
	TOK_PRIM_OPERATOR_UNARY_MINUS
	TOK_PRIM_OPERATOR_MINUS
	TOK_PRIM_OPERATOR_MULT
	TOK_PRIM_OPERATOR_DIV
	TOK_PRIM_OPERATOR_MOD
	TOK_PRIM_OPERATOR_BIT_AND
	TOK_PRIM_OPERATOR_BIT_OR
	TOK_PRIM_OPERATOR_BIT_XOR
	TOK_PRIM_OPERATOR_BIT_UNARY_NOT
	TOK_PRIM_OPERATOR_COMP_EQUAL
	TOK_PRIM_OPERATOR_COMP_GREATER
	TOK_PRIM_OPERATOR_COMP_LESS
	TOK_PRIM_OPERATOR_COMP_GREATER_EQUAL
	TOK_PRIM_OPERATOR_COMP_LESS_EQUAL
	TOK_PRIM_OPERATOR_COMP_NOT_EQUAL

	TOK_PRIM_OPERATOR_ASSIGN_PLUS
	TOK_PRIM_OPERATOR_ASSIGN_MINUS
	TOK_PRIM_OPERATOR_ASSIGN_MULT
	TOK_PRIM_OPERATOR_ASSIGN_DIV
	TOK_PRIM_OPERATOR_ASSIGN_MOD
	TOK_PRIM_OPERATOR_ASSIGN_BIT_AND
	TOK_PRIM_OPERATOR_ASSIGN_BIT_OR
	TOK_PRIM_OPERATOR_ASSIGN_BIT_XOR

	TOK_PRIM_SYSFUNC_SUB

	TOK_PRIM_UFUNC_SUB // temporary result from operator or function

	TOK_PRIM_CAST_UNDEFINED // temporary result from CAST node. This prim_subtype is replaced by TOK_PRIM_CAST_RESTRICT/_ENLARGE/_ADJUST/_COPY during the walking of the ast.
	TOK_PRIM_CAST_RESTRICT  // temporary result from CAST node. Cast datatype to a lower datatype.
	TOK_PRIM_CAST_ENLARGE   // temporary result from CAST node. Cast datatype to a higher datatype.
	TOK_PRIM_CAST_ADJUST    // temporary result from CAST node. Cast datatype to the same datatype, but precision, scale, fixlen_flag or collation is different.
	TOK_PRIM_CAST_COPY      // temporary result from CAST node. Cast datatype to exactly the same datatype and properties. It is simply a copy.
	TOK_PRIM_CAST_ILLEGAL   // temporary result from CAST node. Cast is illegal.

	TOK_PRIM_PLACEHOLDER_DEFAULT          // DEFAULT (in function parameter parsing only)
	TOK_PRIM_PLACEHOLDER_UNQUALIFIED_STAR // unqualified '*'
	TOK_PRIM_PLACEHOLDER_QUALIFIED_STAR   // e.g. MYTABLE.*
	TOK_PRIM_PLACEHOLDER_QUESTIONMARK     // '?' placeholder for prepared statement (ODBC).

	TOK_PRIM_CASE_SUB // CASE

	TOK_PRIM_EXISTS_SUB // EXISTS

	TOK_PRIM_SUBQUERY_MANY // SELECT subquery
	TOK_PRIM_SUBQUERY_ONE  // SELECT subquery
)

func (Prim_subtype_t) String

func (prim_subtype Prim_subtype_t) String() string

type Prim_type_t

type Prim_type_t uint32
const (
	TOK_PRIMARY_ANCHOR Prim_type_t = 1 << iota // only used by parser.Eat_expression() for the list anchor dummy variable.

	TOK_PRIM_LITERAL_SYSCOLLATOR // leaf node: fr_cs_as
	TOK_PRIM_LITERAL_NULL        // leaf node: NULL
	TOK_PRIM_LITERAL_BOOLEAN     // leaf node: true of false
	TOK_PRIM_LITERAL_HEXASTRING  // leaf node: 0xabcd1234
	TOK_PRIM_LITERAL_STRING      // leaf node: 'bla'
	TOK_PRIM_LITERAL_NUMBER      // leaf node: 123e6  123  123.45 $123.45

	TOK_PRIM_VARIABLE   // leaf node: @myvar
	TOK_PRIM_IDENTIFIER // leaf node: MYDB.sa.CUSTOMERS.NAME
	TOK_PRIM_OPERATOR   // temporary result from operator
	TOK_PRIM_SYSFUNC    // temporary result from builtin function
	TOK_PRIM_UFUNC      // temporary result from user function
	TOK_PRIM_CAST       // temporary result from CAST node

	TOK_PRIM_PLACEHOLDER

	TOK_PRIM_CASE // CASE

	TOK_PRIM_EXISTS // EXISTS

	TOK_PRIM_SUBQUERY // 'select' subquery
)

func (Prim_type_t) String

func (prim_type Prim_type_t) String() string

type Sarginfo

type Sarginfo struct {
	csr.Sarg

	Tok_a_column *Token_primary // column identifier
	Tok_a        *Token_primary // column identifier (in this case, == Tok_a_column), or cast(col as ...)
	Tok_expr     *Token_primary // expression with which Tok_a will be compared
	Tok_comp     *Token_primary // comparison token
}

type Set_clause

type Set_clause struct {
	St_colname string
	St_expr    *Token_primary
}

type Sysfunc_description

type Sysfunc_description struct {
	Sd_id Sysfunc_id_t
	// contains filtered or unexported fields
}
var (
	// internal function (only the parser can invoke it, not the SQL batch). Sysfunc_description does not exist in G_SYSFUNC_DESCRIPTION_MAP.
	SYSFUNC_DESCR_COMPILE_VARCHAR_TO_REGEXPLIKE *Sysfunc_description = &Sysfunc_description{SYSFUNC_COMPILE_VARCHAR_TO_REGEXPLIKE, 0}
	SYSFUNC_DESCR_FIRSTDAYOFWEEK_SYSLANGUAGE    *Sysfunc_description = &Sysfunc_description{SYSFUNC_FIRSTDAYOFWEEK_SYSLANGUAGE, 0}
	SYSFUNC_DESCR_DMY_SYSLANGUAGE               *Sysfunc_description = &Sysfunc_description{SYSFUNC_DMY_SYSLANGUAGE, 0}
	SYSFUNC_DESCR_FIT_NO_TRUNCATE_VARBINARY     *Sysfunc_description = &Sysfunc_description{SYSFUNC_FIT_NO_TRUNCATE_VARBINARY, 0}
	SYSFUNC_DESCR_FIT_NO_TRUNCATE_VARCHAR       *Sysfunc_description = &Sysfunc_description{SYSFUNC_FIT_NO_TRUNCATE_VARCHAR, 0}

	// some useful pointers to Sysfunc_description that are used by the parser. Sysfunc_description exists in G_SYSFUNC_DESCRIPTION_MAP.
	SYSFUNC_DESCR_CONVERT           *Sysfunc_description
	SYSFUNC_DESCR_LEFT              *Sysfunc_description // name is keyword
	SYSFUNC_DESCR_RIGHT             *Sysfunc_description // name is keyword
	SYSFUNC_DESCR_CURRENT_TIMESTAMP *Sysfunc_description
	SYSFUNC_DESCR_NULLIF            *Sysfunc_description
	SYSFUNC_DESCR_IIF               *Sysfunc_description
	SYSFUNC_DESCR_DATEPART          *Sysfunc_description
	SYSFUNC_DESCR_GETUTCDATE        *Sysfunc_description
	SYSFUNC_DESCR_AGGR_SUM          *Sysfunc_description
	SYSFUNC_DESCR_AGGR_COUNT        *Sysfunc_description
)

constants to *Sysfunc_description for internal functions, or functions that have a name which is a LEX_KEYWORD.

func (*Sysfunc_description) First_arg_is_datepartfield

func (sysfunc_descr *Sysfunc_description) First_arg_is_datepartfield() bool

func (*Sysfunc_description) Is_aggregate

func (sysfunc_descr *Sysfunc_description) Is_aggregate() bool

func (*Sysfunc_description) Is_not_parenthesized

func (sysfunc_descr *Sysfunc_description) Is_not_parenthesized() bool

func (*Sysfunc_description) Is_sysvar_if_no_arg

func (sysfunc_descr *Sysfunc_description) Is_sysvar_if_no_arg() bool

func (*Sysfunc_description) Is_volatile

func (sysfunc_descr *Sysfunc_description) Is_volatile() bool

func (*Sysfunc_description) Is_volatile_or_aggregate

func (sysfunc_descr *Sysfunc_description) Is_volatile_or_aggregate() bool

type Sysfunc_id_t

type Sysfunc_id_t uint16
const (
	SYSFUNC_atatDATEFIRST  Sysfunc_id_t = iota + 1
	SYSFUNC_atatDATEFORMAT              // not a MS SQL function
	SYSFUNC_atatLANGUAGE
	SYSFUNC_atatVERSION
	SYSFUNC_atatSERVERNAME
	SYSFUNC_atatSERVICENAME
	SYSFUNC_atatIDENTITY
	SYSFUNC_atatROWCOUNT
	SYSFUNC_atatERROR
	SYSFUNC_atatTRANCOUNT

	SYSFUNC_SCOPE_IDENTITY

	SYSFUNC_SUSER_NAME
	SYSFUNC_SUSER_ID
	SYSFUNC_DB_NAME
	SYSFUNC_DB_ID
	SYSFUNC_SCHEMA_NAME
	SYSFUNC_SCHEMA_ID
	SYSFUNC_USER_NAME
	SYSFUNC_USER_ID
	SYSFUNC_DATABASE_PRINCIPAL_ID
	SYSFUNC_OBJECT_NAME
	SYSFUNC_OBJECT_ID

	SYSFUNC_COMPILE_VARCHAR_TO_REGEXPLIKE
	SYSFUNC_FIRSTDAYOFWEEK_SYSLANGUAGE
	SYSFUNC_DMY_SYSLANGUAGE
	SYSFUNC_FIT_NO_TRUNCATE_VARBINARY
	SYSFUNC_FIT_NO_TRUNCATE_VARCHAR

	SYSFUNC_DATENAME
	SYSFUNC_DATEPART
	SYSFUNC_DAY
	SYSFUNC_MONTH
	SYSFUNC_YEAR
	SYSFUNC_EOMONTH
	SYSFUNC_BOMONTH
	SYSFUNC_DATEDIFF
	SYSFUNC_DATEADD
	SYSFUNC_DATEFROMPARTS
	SYSFUNC_TIMEFROMPARTS
	SYSFUNC_DATETIMEFROMPARTS
	SYSFUNC_DATETIME2FROMPARTS
	SYSFUNC_GETUTCDATE
	SYSFUNC_UTC_TO_LOCAL // the parser replaces GETDATE by this internal function
	SYSFUNC_SWITCHOFFSET
	SYSFUNC_TODATETIMEOFFSET
	SYSFUNC_SYSDATETIMEOFFSET

	SYSFUNC_ABS
	SYSFUNC_ACOS
	SYSFUNC_ASIN
	SYSFUNC_ATAN
	SYSFUNC_ATN2
	SYSFUNC_CEILING
	SYSFUNC_COS
	SYSFUNC_COT
	SYSFUNC_DEGREES
	SYSFUNC_EXP
	SYSFUNC_FLOOR
	SYSFUNC_LOG
	SYSFUNC_LOG10
	SYSFUNC_PI
	SYSFUNC_POWER
	SYSFUNC_RADIANS
	SYSFUNC_RAND
	SYSFUNC_ROUND
	SYSFUNC_SIGN
	SYSFUNC_SIN
	SYSFUNC_SQRT
	SYSFUNC_SQUARE
	SYSFUNC_TAN

	SYSFUNC_ASCII
	SYSFUNC_CHAR
	SYSFUNC_CHARINDEX
	SYSFUNC_CHARLEN
	SYSFUNC_DATALENGTH
	SYSFUNC_DIFFERENCE
	SYSFUNC_LEFT
	SYSFUNC_LEN
	SYSFUNC_LOWER
	SYSFUNC_LTRIM
	SYSFUNC_NCHAR
	SYSFUNC_PATINDEX
	SYSFUNC_QUOTENAME
	SYSFUNC_REPLACE
	SYSFUNC_REPLICATE
	SYSFUNC_REVERSE
	SYSFUNC_RIGHT
	SYSFUNC_RTRIM
	SYSFUNC_SOUNDEX
	SYSFUNC_SPACE
	SYSFUNC_STR
	SYSFUNC_STUFF
	SYSFUNC_SUBSTRING
	SYSFUNC_TRIM
	SYSFUNC_UNICODE
	SYSFUNC_UPPER
	SYSFUNC_CONCAT

	SYSFUNC_FORMAT
	SYSFUNC_CONVERT

	SYSFUNC_ISDATE
	SYSFUNC_ISNUMERIC
	SYSFUNC_ISNULL
	SYSFUNC_IIF
	SYSFUNC_CHOOSE
	SYSFUNC_COALESCE
	SYSFUNC_TYPEOF

	SYSFUNC_NULLIF // the parser replaces it by iif function

	SYSFUNC_RANDOM_VARCHAR
	SYSFUNC_RANDOM_INT
	SYSFUNC_RANDOM_BIGINT
	SYSFUNC_RANDOM_NUMERIC
	SYSFUNC_RANDOM_FLOAT
	SYSFUNC_RANDOM_DATE

	SYSFUNC_AGGR_COUNT
	SYSFUNC_AGGR_COUNT_BIG
	SYSFUNC_AGGR_SUM
	SYSFUNC_AGGR_MIN
	SYSFUNC_AGGR_MAX
	SYSFUNC_AGGR_AVG
)

type Sysfunc_properties_t

type Sysfunc_properties_t uint16
const (
	SYSFUNCPROP_IS_NOT_PARENTHESIZED       Sysfunc_properties_t = 1 << iota // for CURRENT_USER, etc
	SYSFUNCPROP_FIRST_ARG_IS_DATEPARTFIELD                                  // for SYSFUNC_DATEADD, SYSFUNC_DATEDIFF, SYSFUNC_DATENAME, SYSFUNC_DATEPART
	SYSFUNCPROP_IS_VOLATILE                                                 // the function should not be constant folded
	SYSFUNCPROP_IS_AGGREGATE                                                // the function should not be constant folded
	SYSFUNCPROP_IS_SYSVAR_IF_NO_ARG
)

type Tbl_map

type Tbl_map map[string]Xtable

this map is used to check that in Xtable_select, the last part of table qualified names and aliases have no duplicate.

type Tok_category_t

type Tok_category_t uint16
const (
	TOK_PRIMARY Tok_category_t = iota + 1
	TOK_STMT_DECLARE_VARIABLE
	TOK_STMT_ASSIGNMENT
	TOK_STMT_IF
	TOK_STMT_WHILE
	TOK_STMT_GOTO
	TOK_STMT_BREAK
	TOK_STMT_CONTINUE
	TOK_STMT_SLEEP
	TOK_STMT_SHUTDOWN
	TOK_STMT_INSERT_INTO
	TOK_STMT_BULK_INSERT
	TOK_STMT_BULK_EXPORT
	TOK_STMT_SELECT_OR_UNION
	TOK_STMT_DELETE
	TOK_STMT_UPDATE
	TOK_STMT_TRUNCATE_TABLE
	TOK_STMT_SHRINK_TABLE
	TOK_STMT_THROW
	TOK_STMT_PRINT
	TOK_STMT_ASSERT_       // used only for SQK batch tests. User should not use it.
	TOK_STMT_ASSERT_NULL_  // used only for SQK batch tests. User should not use it.
	TOK_STMT_ASSERT_ERROR_ // used only for SQK batch tests. User should not use it.
	TOK_STMT_SHOW_COLLATIONS
	TOK_STMT_SHOW_LANGUAGES
	TOK_STMT_SHOW_LOCKS
	TOK_STMT_SHOW_WORKERS
	TOK_STMT_SHOW_INFO
	TOK_STMT_SHOW
	TOK_STMT_BACKUP
	TOK_STMT_RESTORE
	TOK_STMT_DUMP
	TOK_STMT_SET_NOCOUNT
	TOK_STMT_SET_LANGUAGE   // This instruction changes the value of the variable "_@current_language".
	TOK_STMT_SET_DATEFIRST  // This instruction changes the value of the variable "_@current_language".
	TOK_STMT_SET_DATEFORMAT // This instruction changes the value of the variable "_@current_language".
	TOK_STMT_USE            // This instruction changes the value of the variable "_@current_db". It is also a compiler pragma, to complete incomplete objects name (e.g. table name) during parsing stage.
	TOK_STMT_RETURN
	TOK_STMT_LABEL
	TOK_STMT_DEBUG_TABLE_LOCK
	TOK_STMT_CREATE_LOGIN
	TOK_STMT_ALTER_LOGIN
	TOK_STMT_DROP_LOGIN
	TOK_STMT_CREATE_DATABASE
	TOK_STMT_ALTER_DATABASE
	TOK_STMT_DROP_DATABASE
	TOK_STMT_CREATE_USER
	TOK_STMT_ALTER_USER
	TOK_STMT_DROP_USER
	TOK_STMT_CREATE_ROLE
	TOK_STMT_ALTER_ROLE
	TOK_STMT_DROP_ROLE
	TOK_STMT_GRANT
	TOK_STMT_DENY
	TOK_STMT_REVOKE
	TOK_STMT_ALTER_AUTHORIZATION
	TOK_STMT_CREATE_TABLE
	TOK_STMT_ALTER_TABLE
	TOK_STMT_DROP_TABLE
	TOK_STMT_CREATE_INDEX
	TOK_STMT_ALTER_INDEX
	TOK_STMT_DROP_INDEX
	TOK_STMT_SET_LEXER_OR_PARSER_OPTION // pragma for lexer or parser
	TOK_STMT_ALTER_SERVER_PARAMETER
	TOK_STMT_BEGIN_TRANSACTION
	TOK_STMT_COMMIT_TRANSACTION
	TOK_STMT_ROLLBACK_TRANSACTION
)

func (Tok_category_t) String

func (category Tok_category_t) String() string

type Token

type Token struct {
	Tok_category   Tok_category_t // category, e.g. TOK_STMT_PRINT, TOK_PRIMARY, etc.
	Tok_batch_line lex.Coord_t    // line no (starting from 1) and position (starting from 1) in batch.

	Tok_prev Tokener
	Tok_next Tokener
}

The AST is made up of tokens. All tokens have the struct Token as first member.

func (*Token) Batch_line

func (tok *Token) Batch_line() lex.Coord_t

func (*Token) Category

func (tok *Token) Category() Tok_category_t

func (*Token) Next

func (tok *Token) Next() Tokener

func (*Token) Prev

func (tok *Token) Prev() Tokener

func (*Token) Set_batch_line

func (tok *Token) Set_batch_line(batch_line lex.Coord_t)

func (*Token) Set_next

func (tok *Token) Set_next(a Tokener)

func (*Token) Set_prev

func (tok *Token) Set_prev(a Tokener)

type Token_primary

type Token_primary struct {
	Token // tok_category is always TOK_PRIMARY

	Prim_type    Prim_type_t
	Prim_subtype Prim_subtype_t

	Prim_database_name string
	Prim_schema_name   string
	Prim_table_name    string // in fact, it is the exposed name. So, it may be an alias name.
	Prim_name          string // for variable name and column name, literal string and number, operator

	Prim_sql_datatype    rsql.Datatype_t // for variable declaration and explicit CAST token. (never contains DATATYPE_CHAR, it is DATATYPE_VARCHAR with fixlen_flag==true instead)
	Prim_sql_precision   uint16          // same
	Prim_sql_scale       uint16          // same
	Prim_sql_fixlen_flag bool            // same
	Prim_sql_collate     string          // same. For COLLATE clause. Note that COLLATE clause for variable declaration (DECLARE statement) is forbidden. A VARCHAR variable has always the server default collation, like MS SQL Server.

	Prim_sql_datepartfield Datepartfield_t // datepartfield argument for DATEPART() and DATENAME() functions, like DATEPARTFIELD_YEAR etc.

	Prim_cardinality                   Prim_cardinality_t // operator: number of operands. It indicates to parser_eat_expression() how it must reorganize the neighbour tokens.
	Prim_any_all_comp_operator_subtype Prim_subtype_t     // Prim_subtype of the comparison operator for ANY and ALL operators

	Prim_status Prim_status_t // operator: in the expression reorganization, TOK_PRIM_STATUS_UNCOMPLETE, TOK_PRIM_STATUS_COMPLETE.

	Prim_collation_strength rsql.Collstrength_t // used by the decorator, computed from Prim_sql_collate or arguments collations. COLLSTRENGTH_0 (server default collation), COLLSTRENGTH_1 (for column identifier), COLLSTRENGTH_2 (COLLATE clause)
	Prim_collation          string              // same

	Prim_sysfunc_descr *Sysfunc_description // see G_SYSFUNC_DESCRIPTION_MAP
	Prim_left          *Token_primary       // left operand. For TOK_PRIM_EXISTS, points to TOK_PRIM_SUBQUERY_MANY.
	Prim_right         *Token_primary       // right operand. For TOK_PRIM_OPERATOR_IN_SUBQUERY, points to a subquery. For TOK_PRIM_OPERATOR_ALL/ANY, points to the comparison operator token.
	Prim_listexpr      []*Token_primary     // function arguments
	Prim_syscollator   *Token_primary       // supplementary operand. Points to a syscollator token if and only if the operator or function needs it. It must be a literal value or a variable, because the decorator doesn't walk it to emit bytecode.
	Prim_syslanguage   *Token_primary       // supplementary operand. Points to a syslanguage token if and only if the operator or function needs it. It must be a literal value or a variable, because the decorator doesn't walk it to emit bytecode.

	Prim_instruction_code rsql.Instrcode_t // INSTR_ADD_INT, INSTR_SUBSTR_INT, etc

	Prim_xtable_subquery Xtable // for TOK_PRIM_SUBQUERY only.
	//
	// Prim_xtable_namespace Xtable // TOK_PRIM_IDENTIFIER points to the Xtable at the origin of its namespace, which is Xtable_select, Xtable_join, or Xtable_union. (but not Xtable_table).
	//                                                      // RSQL_SYSFUNC_AGGR_COUNT, SUM, etc point to the Xtable_select they belong to.
	//
	//      Token_primary   *prim_clone_working;            // just a working pointer to the cloned token, used by ast_clone_subtree() in the parser to clone a subtree for GROUP BY
	//
	Prim_xtable_ds Xtable // xtable to which Prim_dataslot belongs. Can be a real table, SELECT or UNION.
	Prim_col_no    uint16 // column number of dataslot in real table, SELECT or UNION
	Prim_dataslot  rsql.IDataslot
	// contains filtered or unexported fields
}

All expressions are made up of Token_primary tokens. An expression is a tree of these tokens.

func Clone

func Clone(tok *Token_primary) (*Token_primary, *rsql.Error)

Clone clones tok, as well as all its arguments recursively.

func New_TOK_PRIM_IDENTIFIER

func New_TOK_PRIM_IDENTIFIER(ident_string string, tok_batch_line lex.Coord_t) *Token_primary

New_TOK_PRIM_IDENTIFIER is used when parsing SELECT, to create column Token_primary for '*' star placeholder.

type Token_stmt_ALTER_AUTHORIZATION

type Token_stmt_ALTER_AUTHORIZATION struct {
	Token

	Aa_database_name      string
	Aa_change_owner_login string
}

Token for ALTER AUTHORIZATION.

type Token_stmt_ALTER_DATABASE

type Token_stmt_ALTER_DATABASE struct {
	Token

	Ad_database_name string

	Ad_change_name string
	Ad_status      lex.Auxword_t
	Ad_mode        lex.Auxword_t
	Ad_access      lex.Auxword_t
}

Token for ALTER DATABASE.

type Token_stmt_ALTER_INDEX

type Token_stmt_ALTER_INDEX struct {
	Token

	Ai_table_qname rsql.Object_qname_t
	Ai_index_name  string

	Ai_change_index_name          string
	Ai_change_index_name_original string
}

Token for ALTER INDEX.

type Token_stmt_ALTER_LOGIN

type Token_stmt_ALTER_LOGIN struct {
	Token

	Al_login_name string

	Al_change_name             string
	Al_change_password_hash    string
	Al_change_default_database string
	Al_change_default_language string
	Al_change_disable_option   lex.Auxword_t
}

Token for ALTER LOGIN.

type Token_stmt_ALTER_ROLE

type Token_stmt_ALTER_ROLE struct {
	Token

	Ar_database_name string
	Ar_role_name     string

	Ar_add_member_name  string // only one of these 3 fields is filled with non-empty string
	Ar_drop_member_name string //  see above
	Ar_change_name      string //  see above
}

Token for ALTER ROLE.

type Token_stmt_ALTER_SERVER_PARAMETER

type Token_stmt_ALTER_SERVER_PARAMETER struct {
	Token

	Asp_param        dict.Server_parameter_t
	Asp_value_int    int64
	Asp_value_string string
}

Token for ALTER SERVER_PARAMETER parameters.

type Token_stmt_ALTER_TABLE

type Token_stmt_ALTER_TABLE struct {
	Token

	At_table_qname rsql.Object_qname_t

	At_change_table_name          string
	At_change_table_name_original string

	At_column_name                 string
	At_change_column_name          string
	At_change_column_name_original string
	At_change_column_nullability   dict.Alter_column_nullability_t
}

Token for ALTER TABLE.

type Token_stmt_ALTER_USER

type Token_stmt_ALTER_USER struct {
	Token

	Au_database_name string
	Au_user_name     string

	Au_change_name  string // may be ""
	Au_change_login string // may be ""
}

Token for ALTER USER.

type Token_stmt_ASSERT_

type Token_stmt_ASSERT_ struct {
	Token

	As_expr *Token_primary // always BOOLEAN
}

Token for _ASSERT_.

THIS FUNCTION _ASSERT_(expr) IS USED ONLY TO TEST SQL SCRIPTS. THE USER SHOULD NOT USE IT.

type Token_stmt_ASSERT_ERROR_

type Token_stmt_ASSERT_ERROR_ struct {
	Token

	As_expr *Token_primary // any type

	As_error_suffix *Token_primary // message error suffix as string
}

Token for _ASSERT_ERROR_.

THIS FUNCTION _ASSERT_ERROR_(expr, 'error suffix') IS USED ONLY TO TEST SQL SCRIPTS. THE USER SHOULD NOT USE IT.

type Token_stmt_ASSERT_NULL_

type Token_stmt_ASSERT_NULL_ struct {
	Token

	As_expr *Token_primary // always BOOLEAN
}

Token for _ASSERT_NULL_.

THIS FUNCTION _ASSERT_NULL_(expr) IS USED ONLY TO TEST SQL SCRIPTS. THE USER SHOULD NOT USE IT.

type Token_stmt_ASSIGNMENT

type Token_stmt_ASSIGNMENT struct {
	Token

	Set_instruction_code rsql.Instrcode_t

	Set_lvalue *Token_primary
	Set_rvalue *Token_primary
}

Token for assignment of an expression to a variable.

type Token_stmt_BACKUP

type Token_stmt_BACKUP struct {
	Token

	Bk_database_name string
	Bk_filename      string

	Bk_server_default_collation string // sorting order tables
}

Token for Token_stmt_BACKUP

type Token_stmt_BEGIN_TRANSACTION

type Token_stmt_BEGIN_TRANSACTION struct {
	Token
}

Token for BEGIN TRANSACTION.

type Token_stmt_BREAK

type Token_stmt_BREAK struct {
	Token

	Br_attached_loop *Token_stmt_WHILE
}

Token_stmt_BREAK represents the statement BREAK.

type Token_stmt_BULK_EXPORT

type Token_stmt_BULK_EXPORT struct {
	Token

	Be_filename string // file to import

	Be_opt_codepage        string
	Be_opt_rowterminator   string
	Be_opt_fieldterminator string
	Be_opt_date_format     string
	Be_opt_time_format     string
	Be_opt_datetime_format string

	Be_xtable Xtable // XT_TABLE, XT_SELECT, or XT_UNION
}

Token for BULK EXPORT.

type Token_stmt_BULK_INSERT

type Token_stmt_BULK_INSERT struct {
	Token

	Bi_table_qname rsql.Object_qname_t
	Bi_filename    string // file to import

	Bi_opt_codepage        string
	Bi_opt_rowterminator   string
	Bi_opt_fieldterminator string
	Bi_opt_firstrow        uint64
	Bi_opt_lastrow         uint64
	Bi_opt_keepidentity    bool
	Bi_opt_newidentity     bool
	Bi_opt_rtrim           bool

	Bi_gtabledef   *rsql.GTabledef // as we pass VALUES as rows of base table, the table layout and column datatypes should be identical when the VM will insert them. The lock manager ensures that GTabledef of the table is not modified.
	Bi_syslanguage *Token_primary  // used by VM to convert field from file to DATE, TIME or DATETIME.
}

Token for BULK INSERT.

type Token_stmt_COMMIT_TRANSACTION

type Token_stmt_COMMIT_TRANSACTION struct {
	Token
}

Token for COMMIT TRANSACTION.

type Token_stmt_CONTINUE

type Token_stmt_CONTINUE struct {
	Token

	Cont_attached_loop *Token_stmt_WHILE
}

Token_stmt_CONTINUE represents the statement CONTINUE.

type Token_stmt_CREATE_DATABASE

type Token_stmt_CREATE_DATABASE struct {
	Token

	Cd_database_name string
}

Token for CREATE DATABASE.

type Token_stmt_CREATE_INDEX

type Token_stmt_CREATE_INDEX struct {
	Token

	Ci_table_qname         rsql.Object_qname_t
	Ci_index_name          string // may be empty string. Index name will be generated automatically during index creation.
	Ci_index_name_original string //   same
	Ci_index_type          rsql.Td_index_type_t
	Ci_cluster_type        rsql.Td_cluster_type_t
	Ci_colname_list        []string
}

Token for CREATE INDEX.

type Token_stmt_CREATE_LOGIN

type Token_stmt_CREATE_LOGIN struct {
	Token

	Cl_login_name       string
	Cl_password_hash    string // LEX_LITERAL_STRING
	Cl_default_database string // default is "trashdb"
	Cl_default_language string
}

Token for CREATE LOGIN.

type Token_stmt_CREATE_ROLE

type Token_stmt_CREATE_ROLE struct {
	Token

	Cr_database_name string
	Cr_role_name     string
}

Token for CREATE ROLE.

type Token_stmt_CREATE_TABLE

type Token_stmt_CREATE_TABLE struct {
	Token

	Ct_database_name string
	Ct_schema_name   string
	Ct_gtabledef     *rsql.GTabledef
}

Token for CREATE TABLE.

type Token_stmt_CREATE_USER

type Token_stmt_CREATE_USER struct {
	Token

	Cu_database_name string
	Cu_user_name     string
	Cu_login_name    string
}

Token for CREATE USER.

type Token_stmt_DECLARE_variable

type Token_stmt_DECLARE_variable struct {
	Token

	Decl_variable *Token_primary
}

Token for declaration of variable. It is not a real statement but a compiler directive, as it won't be executed by the VM.

type Token_stmt_DELETE

type Token_stmt_DELETE struct {
	Token

	De_target_database_name string
	De_target_schema_name   string
	De_target_table_name    string

	De_from         *Xtable_from
	De_target_table *Xtable_table
}

Token for DELETE.

type Token_stmt_DENY

type Token_stmt_DENY struct {
	Token

	De_object_qname            rsql.Object_qname_t
	De_permission              rsql.Permission_t
	De_list_of_principal_names []string
}

Token for DENY permission.

type Token_stmt_DROP_DATABASE

type Token_stmt_DROP_DATABASE struct {
	Token

	Dd_database_name string
}

Token for DROP DATABASE.

type Token_stmt_DROP_INDEX

type Token_stmt_DROP_INDEX struct {
	Token

	Di_table_qname rsql.Object_qname_t
	Di_index_name  string
}

Token for DROP INDEX. Index can be clustered or nonclustered.

type Token_stmt_DROP_LOGIN

type Token_stmt_DROP_LOGIN struct {
	Token

	Dl_login_name string
}

Token for DROP LOGIN.

type Token_stmt_DROP_ROLE

type Token_stmt_DROP_ROLE struct {
	Token

	Dr_database_name string
	Dr_role_name     string
}

Token for DROP ROLE.

type Token_stmt_DROP_TABLE

type Token_stmt_DROP_TABLE struct {
	Token

	Dt_table_qname rsql.Object_qname_t
}

Token for DROP TABLE.

type Token_stmt_DROP_USER

type Token_stmt_DROP_USER struct {
	Token

	Du_database_name string
	Du_user_name     string
}

Token for DROP USER.

type Token_stmt_DUMP

type Token_stmt_DUMP struct {
	Token

	Dp_instruction_code rsql.Instrcode_t // INSTR_DUMP_PARAMETERS, INSTR_DUMP_LOGINS, INSTR_DUMP_DATABASE

	Dp_database_name   string
	Dp_option_DDL_ONLY bool
	Dp_filename        string

	Dp_server_default_collation string // sorting order for output
}

Token for DUMP.

type Token_stmt_GOTO

type Token_stmt_GOTO struct {
	Token

	Gt_label string

	Gt_all_labels Dictionary_LABEL // for all Token_stmt_GOTO, this field points to the same collection of labels, parser.LABELS. This is needed by 'emit' package, to generate GOTO instructions.
}

Token_stmt_GOTO represents the statement GOTO.

type Token_stmt_GRANT

type Token_stmt_GRANT struct {
	Token

	Gr_object_qname            rsql.Object_qname_t
	Gr_permission              rsql.Permission_t
	Gr_list_of_principal_names []string
}

Token for GRANT permission.

type Token_stmt_IF

type Token_stmt_IF struct {
	Token

	If_cond *Token_primary
	If_then Tokener // points at first token of a list of tokens
	If_else Tokener // points at first token of a list of tokens

	If_basicblock_pre        *rsql.Basicblock
	If_basicblock_then_start *rsql.Basicblock
	If_basicblock_then_end   *rsql.Basicblock
	If_basicblock_else_start *rsql.Basicblock
	If_basicblock_else_end   *rsql.Basicblock
	If_basicblock_post       *rsql.Basicblock
}

Token_stmt_IF represents the statement IF.

type Token_stmt_INSERT_INTO

type Token_stmt_INSERT_INTO struct {
	Token

	Ins_instruction_code rsql.Instrcode_t // INSTR_STMT_INSERT_VALUES or INSTR_STMT_INSERT_SELECT

	Ins_table_qname rsql.Object_qname_t

	Ins_listcol                    []string
	Ins_listcol_base_seqno         []uint16 // base seqno of columns in Ins_listcol
	Ins_explicit_IDENTITY_provided bool     // IDENTITY column name exists in Ins_listcol

	Ins_values_array [][]*Token_primary // VALUES clause if any

	Ins_xtable                Xtable           // SELECT clause if any
	Ins_conversion_tokens     []*Token_primary // for SELECT clause, convert dataslots from SELECT columns into Ins_base_row. Only necessary conversions are appended to this list.
	Ins_conversion_basicblock *rsql.Basicblock // for SELECT clause, instructions generated for Ins_conversion_tokens

	Ins_gtabledef *rsql.GTabledef // as we pass VALUES as rows of base table, the table layout and column datatypes should be identical when the VM will insert them. The lock manager ensures that GTabledef of the table is not modified.
	Ins_base_row  rsql.Row        // Row of base table
}

Token for INSERT INTO table.

Recods to insert come from a VALUES clause with a list of records, or from a SELECT clause.

type Token_stmt_LABEL

type Token_stmt_LABEL struct {
	Token

	Lab_label string

	Lab_basicblock_pre   *rsql.Basicblock
	Lab_basicblock_label *rsql.Basicblock
}

Token_stmt_LABEL represents the statement LABEL.

type Token_stmt_PRINT

type Token_stmt_PRINT struct {
	Token

	Pr_listexpr []*Token_primary
}

Token for PRINT.

type Token_stmt_RESTORE

type Token_stmt_RESTORE struct {
	Token

	Rt_database_name  string
	Rt_filename       string
	Rt_option_replace bool
	Rt_option_no_user bool
	Rt_option_verbose bool
}

Token for Token_stmt_RESTORE

type Token_stmt_RETURN

type Token_stmt_RETURN struct {
	Token

	Ret_expression *Token_primary
}

Token_stmt_RETURN represents the statement RETURN.

type Token_stmt_REVOKE

type Token_stmt_REVOKE struct {
	Token

	Re_object_qname            rsql.Object_qname_t
	Re_permission              rsql.Permission_t
	Re_list_of_principal_names []string
	Re_from_all                bool
}

Token for REVOKE permission.

type Token_stmt_ROLLBACK_TRANSACTION

type Token_stmt_ROLLBACK_TRANSACTION struct {
	Token
}

Token for ROLLBACK TRANSACTION.

type Token_stmt_SELECT_or_UNION

type Token_stmt_SELECT_or_UNION struct {
	Token

	Su_xtable Xtable
}

Token for SELECT, or series of UNIONed SELECTs.

type Token_stmt_SET_LEXER_OR_PARSER_OPTION

type Token_stmt_SET_LEXER_OR_PARSER_OPTION struct {
	Token
}

Token for SET QUOTED_IDENTIFIER ON (or OFF), SET_PARSEONLY ON, etc.

It is a dummy token. It is skipped during all processings.

type Token_stmt_SET_NOCOUNT

type Token_stmt_SET_NOCOUNT struct {
	Token

	Sc_nocount bool
}

Token for SET NOCOUNT.

type Token_stmt_SET_SYSLANGUAGE

type Token_stmt_SET_SYSLANGUAGE struct {
	Token

	Sl_language   string
	Sl_datefirst  int32
	Sl_dateformat string
}

Token for SET LANGUAGE, SET DATEFIRST, SET DATEFORMAT. This statement changes the value of variable "_@current_language".

type Token_stmt_SHOW

type Token_stmt_SHOW struct {
	Token

	Sh_instruction_code rsql.Instrcode_t // INSTR_SHOW_TABLE, etc

	Sh_output_type rsql.Sh_output_type_t
	Sh_template    *template.Template
	Sh_option_ALL  bool // if true, search objects in all databases
	Sh_option_PERM bool // display permissions
	Sh_LIKE        bool

	Sh_database_name string
	Sh_schema_name   string
	Sh_object_name   string
	Sh_LIKE_pattern  string
	Sh_flag_unique   bool

	Sh_server_default_collation string // sorting order for SHOW output
}

Token for SHOW

type Token_stmt_SHOW_COLLATIONS

type Token_stmt_SHOW_COLLATIONS struct {
	Token
}

Token for SHOW COLLATIONS

type Token_stmt_SHOW_INFO

type Token_stmt_SHOW_INFO struct {
	Token

	Shinf_version                  string
	Shinf_server_directory         string
	Shinf_servername               string
	Shinf_server_default_collation string

	Shinf_login            *Token_primary
	Shinf_current_user     *Token_primary
	Shinf_current_database *Token_primary
	Shinf_current_schema   *Token_primary
	Shinf_current_language *Token_primary
}

Token for SHOW INFO

type Token_stmt_SHOW_LANGUAGES

type Token_stmt_SHOW_LANGUAGES struct {
	Token
}

Token for SHOW LANGUAGES

type Token_stmt_SHOW_LOCKS

type Token_stmt_SHOW_LOCKS struct {
	Token
}

Token for SHOW LOCKS

type Token_stmt_SHOW_WORKERS

type Token_stmt_SHOW_WORKERS struct {
	Token
}

Token for SHOW WORKERS

type Token_stmt_SHRINK_TABLE

type Token_stmt_SHRINK_TABLE struct {
	Token

	Sk_table_qname rsql.Object_qname_t

	Sk_gtabledef *rsql.GTabledef
}

Token for SHRINK TABLE.

type Token_stmt_SHUTDOWN

type Token_stmt_SHUTDOWN struct {
	Token

	Sd_nowait bool
}

type Token_stmt_SLEEP

type Token_stmt_SLEEP struct {
	Token

	Sl_duration float64
}

type Token_stmt_THROW

type Token_stmt_THROW struct {
	Token

	Th_error_number *Token_primary // int
	Th_message      *Token_primary // varchar
	Th_severity     *Token_primary // int
	Th_state        *Token_primary // int
}

type Token_stmt_TRUNCATE_TABLE

type Token_stmt_TRUNCATE_TABLE struct {
	Token

	Tt_table_qname rsql.Object_qname_t
	Tt_shrink_file bool

	Tt_gtabledef *rsql.GTabledef
}

Token for TRUNCATE TABLE.

type Token_stmt_UPDATE

type Token_stmt_UPDATE struct {
	Token

	Ud_from         *Xtable_from
	Ud_target_table *Xtable_table // contains rsql.Object_qname_t of target table

	Ud_set_list   []Set_clause     // list of SET clauses
	Ud_basicblock *rsql.Basicblock // basic block containing expressions for SET clauses

	Ud_insertion_base_tokens []*Token_primary // base row to insert. It is a shallow copy of target table row, except for columns that have a SET clause.

	Ud_indexes_to_update map[string]*rsql.Tabledef // indexes to update, because they contain columns that are updated. If nil, all indexes must be updated.
}

Token for UPDATE.

type Token_stmt_USE

type Token_stmt_USE struct {
	Token

	Use_database_name string

	Use_database_name_OUT *Token_primary // OUT variable (that is, variable modified directly by the statement)
	Use_database_dbid_OUT *Token_primary //     same
	Use_schema_name_OUT   *Token_primary //     same
	Use_schema_schid_OUT  *Token_primary //     same
	Use_user_name_OUT     *Token_primary //     same
	Use_user_palid_OUT    *Token_primary //     same
}

Token for USE database name. This statement changes the value of variables "_@current_db_name", "_@current_db_id", "_@current_user_name", "_@current_user_id".

compiler pragma: during parsing stage, when the parser eats this statement, it changes parser.current_default_database.
                 This value is used by the parser to complete the column or table identifiers, if the database part is missing.

type Token_stmt_WHILE

type Token_stmt_WHILE struct {
	Token

	While_cond *Token_primary
	While_body Tokener // points at first token of a list of tokens

	While_basicblock_pre        *rsql.Basicblock
	While_basicblock_cond_start *rsql.Basicblock
	While_basicblock_while_end  *rsql.Basicblock
	While_basicblock_post       *rsql.Basicblock
}

Token_stmt_WHILE represents the statement WHILE.

type Tokener

type Tokener interface {
	Category() Tok_category_t
	Prev() Tokener
	Next() Tokener
	Set_prev(Tokener)
	Set_next(Tokener)
	Batch_line() lex.Coord_t
	Set_batch_line(lex.Coord_t)
}

The Tokener interface contains a pointer to any type of token.

type Xt_type_t

type Xt_type_t uint8
const (
	XT_TABLE Xt_type_t = iota + 1
	XT_JOIN
	XT_SINGLE // used for SELECT without FROM clause
	XT_FROM
	XT_SELECT
	XT_UNION
)

func (Xt_type_t) String

func (xt_type Xt_type_t) String() string

type Xtable

type Xtable interface {
	Type() Xt_type_t
	Cursor() csr.Cursor
	Col_count() int
	Lookup_name(database_name string, schema_name string, table_name string, column_name string) (xtable_ds Xtable, col_no uint16, dataslot rsql.IDataslot, collation string, rsql_err *rsql.Error)
	Lookup_table(mode Lookup_table_mode_t, database_name string, schema_name string, table_name string) (result *Xtable_table, rsql_err *rsql.Error)
	Append_star_columns(list_columns []*Column, database_name string, schema_name string, table_name string) (list_result []*Column, found bool, rsql_err *rsql.Error)
	Put_in_map(tbl_map Tbl_map) *rsql.Error // check that in Xtable_select, there is no duplicate of table exposed names (that is: aliases, and last part of qualified names if no alias)
}

type Xtable_from

type Xtable_from struct {
	Fr_list  []Xtable       // list of Xtables. The decorator will reorganize them as a JOIN tree, and Fr_list will then only contain a pointer to the tree root Xtable.
	Fr_where *Token_primary // WHERE clause. Can be nil.

	Fr_cursor *csr.Cursor_from
}

FROM clause

func (*Xtable_from) Append_star_columns

func (xtable_from *Xtable_from) Append_star_columns(list_columns []*Column, database_name string, schema_name string, table_name string) (list_result []*Column, found bool, rsql_err *rsql.Error)

Append_star_columns appends to list_columns all columns of the table described in arguments.

This function is used by the parser (not by the decorator).

func (*Xtable_from) Col_count

func (xtable_from *Xtable_from) Col_count() int

func (*Xtable_from) Cursor

func (xtable_from *Xtable_from) Cursor() csr.Cursor

func (*Xtable_from) Lookup_name

func (xtable_from *Xtable_from) Lookup_name(database_name string, schema_name string, table_name string, column_name string) (xtable_ds Xtable, col_no uint16, dataslot rsql.IDataslot, collation string, rsql_err *rsql.Error)

Lookup_name returns the dataslot corresponding to the name. Returns nil if not found.

This function is used by the decorator.

func (*Xtable_from) Lookup_table

func (xtable_from *Xtable_from) Lookup_table(mode Lookup_table_mode_t, database_name string, schema_name string, table_name string) (result *Xtable_table, rsql_err *rsql.Error)

Lookup_table returns *Xtable_table corresponding to the name. Returns nil if not found.

This function is used by the decorator, for DELETE.

Argument table_name can be an alias name.

func (*Xtable_from) Put_in_map

func (xtable_from *Xtable_from) Put_in_map(tbl_map Tbl_map) *rsql.Error

func (*Xtable_from) Type

func (xtable_from *Xtable_from) Type() Xt_type_t

type Xtable_join

type Xtable_join struct {
	Jn_type  csr.Join_type_t
	Jn_left  Xtable
	Jn_right Xtable
	Jn_on    *Token_primary // ON is mandatory, except if it is created by reorganizing xtables in FROM list into a tree of JOINs.

	Jn_cursor *csr.Cursor_join
}

Xtable JOIN Xtable

func New_Xtable_join_with_cursor

func New_Xtable_join_with_cursor(join_type csr.Join_type_t, xtable_left Xtable, xtable_right Xtable, on_expression *Token_primary) *Xtable_join

func (*Xtable_join) Append_star_columns

func (xtable_join *Xtable_join) Append_star_columns(list_columns []*Column, database_name string, schema_name string, table_name string) (list_result []*Column, found bool, rsql_err *rsql.Error)

Append_star_columns appends to list_columns all columns of the table described in arguments.

This function is used by the parser (not by the decorator).

func (*Xtable_join) Col_count

func (xtable_join *Xtable_join) Col_count() int

func (*Xtable_join) Cursor

func (xtable_join *Xtable_join) Cursor() csr.Cursor

func (*Xtable_join) Lookup_name

func (xtable_join *Xtable_join) Lookup_name(database_name string, schema_name string, table_name string, column_name string) (xtable_ds Xtable, col_no uint16, dataslot rsql.IDataslot, collation string, rsql_err *rsql.Error)

Lookup_name returns the dataslot corresponding to the name. Returns nil if not found.

This function is used by the decorator.

func (*Xtable_join) Lookup_table

func (xtable_join *Xtable_join) Lookup_table(mode Lookup_table_mode_t, database_name string, schema_name string, table_name string) (result *Xtable_table, rsql_err *rsql.Error)

Lookup_table returns *Xtable_table corresponding to the name. Returns nil if not found.

This function is used by the decorator, for DELETE.

Argument table_name can be an alias name.

func (*Xtable_join) Put_in_map

func (xtable_join *Xtable_join) Put_in_map(tbl_map Tbl_map) *rsql.Error

func (*Xtable_join) Type

func (xtable_join *Xtable_join) Type() Xt_type_t

type Xtable_select

type Xtable_select struct {
	Sel_TOP_value int64

	Sel_varlist                []*Token_primary // assignment of @variable in SELECT. Only allowed for top level SELECT.
	Sel_list_cast_to_var       []*Token_primary // tokens that copies Sel_columns to Sel_varlist
	Sel_cast_to_var_basicblock *rsql.Basicblock // CAST intructions to assign SELECT result to @variable

	Sel_columns     []*Column
	Sel_columns_map map[string]*Column // map used for name lookup. If value is nil, it means that column name is ambiguous.

	Sel_from *Xtable_from // FROM clause of the SELECT. For grouping SELECT, a new Xtable_from is created, that reads grouptable.

	Sel_grouping_flag                  bool             // true if GROUP BY or aggregate function detected
	Sel_grouping_explicit_GROUP_BY     bool             // true if GROUP BY clause exists. Else, only aggregate functions exist in the SELECT.
	Sel_grouptable_feeding_from        *Xtable_from     // Xtable that feeds grouptable. It is the original FROM clause of the SELECT.
	Sel_grouptable_feeding_cursor_from *csr.Cursor_from // cursor that feeds grouptable
	Sel_groupby_expressions            []*Token_primary // GROUP BY expressions
	Sel_grouptable_gtabledef           *rsql.GTabledef  // GTabledef of grouptable
	Sel_grouptable_insertion_row       rsql.Row         // insertion row
	Sel_grouptable_upsert_row          rsql.Row         // grouptable row for upsert
	Sel_grouptable_aggrfuncs_to_inject []*Token_primary // aggregate functions to inject in grouptable row
	Sel_grouptable_output_row          rsql.Row         // grouptable row for output
	Sel_grouptable_having              *Token_primary   // HAVING clause

	Sel_orderby           []*Orderby_part
	Sel_orderby_dataslots []rsql.IDataslot
	Sel_cursor_orderby    *csr.Cursor_table // the statement SELECT will insert all records into this table, and then send them to the client

	Sel_alias string

	Sel_cursor *csr.Cursor_select
}

SELECT expression

func Get_first_SELECT

func Get_first_SELECT(xtable Xtable) *Xtable_select

func (*Xtable_select) Append_star_columns

func (xtable_select *Xtable_select) Append_star_columns(list_columns []*Column, database_name string, schema_name string, table_name string) (list_result []*Column, found bool, rsql_err *rsql.Error)

Append_star_columns appends to list_columns all columns of the table described in arguments.

This function is used by the parser (not by the decorator).

func (*Xtable_select) Col_count

func (xtable_select *Xtable_select) Col_count() int

func (*Xtable_select) Cursor

func (xtable_select *Xtable_select) Cursor() csr.Cursor

func (*Xtable_select) Lookup_name

func (xtable_select *Xtable_select) Lookup_name(database_name string, schema_name string, table_name string, column_name string) (xtable_ds Xtable, col_no uint16, dataslot rsql.IDataslot, collation string, rsql_err *rsql.Error)

Lookup_name returns the dataslot corresponding to the name. Returns nil if not found.

This function is used by the decorator.

func (*Xtable_select) Lookup_table

func (xtable_select *Xtable_select) Lookup_table(mode Lookup_table_mode_t, database_name string, schema_name string, table_name string) (result *Xtable_table, rsql_err *rsql.Error)

Lookup_table returns *Xtable_table corresponding to the name. Returns nil if not found.

This function is used by the decorator, for DELETE.

Argument table_name can be an alias name.

func (*Xtable_select) Put_in_map

func (xtable_select *Xtable_select) Put_in_map(tbl_map Tbl_map) *rsql.Error

func (*Xtable_select) Type

func (xtable_select *Xtable_select) Type() Xt_type_t

type Xtable_single

type Xtable_single struct {
	Sg_cursor *csr.Cursor_single
}

Xtable_single is a special Xtable, used only for SELECT without FROM clause.

func (*Xtable_single) Append_star_columns

func (xtable_single *Xtable_single) Append_star_columns(list_columns []*Column, database_name string, schema_name string, table_name string) (list_result []*Column, found bool, rsql_err *rsql.Error)

Append_star_columns appends to list_columns all columns of the table described in arguments.

This function is used by the parser (not by the decorator).

func (*Xtable_single) Col_count

func (xtable_single *Xtable_single) Col_count() int

func (*Xtable_single) Cursor

func (xtable_single *Xtable_single) Cursor() csr.Cursor

func (*Xtable_single) Lookup_name

func (xtable_single *Xtable_single) Lookup_name(database_name string, schema_name string, table_name string, column_name string) (xtable_ds Xtable, col_no uint16, dataslot rsql.IDataslot, collation string, rsql_err *rsql.Error)

Lookup_name returns the dataslot corresponding to the name. Returns nil if not found.

This function is used by the decorator.

func (*Xtable_single) Lookup_table

func (xtable_single *Xtable_single) Lookup_table(mode Lookup_table_mode_t, database_name string, schema_name string, table_name string) (result *Xtable_table, rsql_err *rsql.Error)

Lookup_table returns *Xtable_table corresponding to the name. Returns nil if not found.

This function is used by the decorator, for DELETE.

Argument table_name can be an alias name.

func (*Xtable_single) Put_in_map

func (xtable_single *Xtable_single) Put_in_map(tbl_map Tbl_map) *rsql.Error

func (*Xtable_single) Type

func (xtable_single *Xtable_single) Type() Xt_type_t

type Xtable_stack_t

type Xtable_stack_t []Xtable

func (*Xtable_stack_t) Count

func (stack *Xtable_stack_t) Count() int

func (*Xtable_stack_t) Is_SELECT_level

func (stack *Xtable_stack_t) Is_SELECT_level() bool

func (*Xtable_stack_t) Pop

func (stack *Xtable_stack_t) Pop() Xtable

func (*Xtable_stack_t) Push

func (stack *Xtable_stack_t) Push(xtable Xtable)

func (*Xtable_stack_t) Top

func (stack *Xtable_stack_t) Top() Xtable

type Xtable_table

type Xtable_table struct {
	Tbl_qname      rsql.Object_qname_t
	Tbl_alias      string
	Tbl_hint_index string

	Tbl_gtabledef *rsql.GTabledef
	Tbl_cursor    *csr.Cursor_table
}

table [ [AS] alias ]

func (*Xtable_table) Append_star_columns

func (xtable_table *Xtable_table) Append_star_columns(list_columns []*Column, database_name string, schema_name string, table_name string) (list_result []*Column, found bool, rsql_err *rsql.Error)

Append_star_columns appends to list_columns all columns of the table described in arguments.

This function is used by the parser (not by the decorator).

func (*Xtable_table) Col_count

func (xtable_table *Xtable_table) Col_count() int

func (*Xtable_table) Cursor

func (xtable_table *Xtable_table) Cursor() csr.Cursor

func (*Xtable_table) Lookup_name

func (xtable_table *Xtable_table) Lookup_name(database_name string, schema_name string, table_name string, column_name string) (xtable_ds Xtable, col_no uint16, dataslot rsql.IDataslot, collation string, rsql_err *rsql.Error)

Lookup_name returns the dataslot corresponding to the name. Returns nil if not found.

This function lazily creates the dataslot object in cursor (when the cursor was created, dataslots where not created).

This function is used by the decorator.

func (*Xtable_table) Lookup_table

func (xtable_table *Xtable_table) Lookup_table(mode Lookup_table_mode_t, database_name string, schema_name string, table_name string) (result *Xtable_table, rsql_err *rsql.Error)

Lookup_table returns *Xtable_table corresponding to the name. Returns nil if not found.

This function is used by the decorator, by DELETE statement.

Argument table_name can be an alias name.

func (*Xtable_table) Put_in_map

func (xtable_table *Xtable_table) Put_in_map(tbl_map Tbl_map) *rsql.Error

func (*Xtable_table) Type

func (xtable_table *Xtable_table) Type() Xt_type_t

type Xtable_union

type Xtable_union struct {
	Un_equalized_row []*Token_primary // rows from each SELECT and UNION members are copied here. Column names and collations are same as first SELECT member.

	Un_members []*struct {
		Xtbl                  Xtable           // SELECT or UNION
		ALL_flag              bool             // true if Xtbl is preceded by UNION ALL
		No_duplicate          bool             // see example in comment above: true for  a, b, c, ..., p
		Cast_to_equalized_row []*Token_primary // CAST instuctions to cast or copy each columns from Xtbl to Un_equalized_row. Dataslots of Cast_to_equalized_row are the same as Un_equalized_row.
	} // list of Xtables

	Un_orderby        []*Orderby_part
	Un_cursor_orderby *csr.Cursor_table // the SELECT members will insert all records into this table, and then send them to the client

	Un_alias string

	Un_cursor *csr.Cursor_union
}

series of SELECT UNION [ALL] ... SELECT

a UNION b    is the set of all records of a and b, with duplicates removed.

Corollary:   In a series of unions, e.g.     a UNION [ALL] b UNION [ALL] c UNION d UNION ALL e
                             is same as      a UNION b UNION c UNION d UNION ALL e
             Each "UNION" without ALL transforms all preceding "UNION ALL" into "UNION".

             After this transformation, a series of unioned Xtables is always of the form:
             a UNION b UNION c ... UNION p   UNION ALL q UNION ALL r ... UNION ALL z

func (*Xtable_union) Append_star_columns

func (xtable_union *Xtable_union) Append_star_columns(list_columns []*Column, database_name string, schema_name string, table_name string) (list_result []*Column, found bool, rsql_err *rsql.Error)

Append_star_columns appends to list_columns all columns of the table described in arguments.

This function is used by the parser (not by the decorator).

func (*Xtable_union) Col_count

func (xtable_union *Xtable_union) Col_count() int

func (*Xtable_union) Cursor

func (xtable_union *Xtable_union) Cursor() csr.Cursor

func (*Xtable_union) Lookup_name

func (xtable_union *Xtable_union) Lookup_name(database_name string, schema_name string, table_name string, column_name string) (xtable_ds Xtable, col_no uint16, dataslot rsql.IDataslot, collation string, rsql_err *rsql.Error)

Lookup_name returns the dataslot corresponding to the name. Returns nil if not found.

This function is used by the decorator.

func (*Xtable_union) Lookup_table

func (xtable_union *Xtable_union) Lookup_table(mode Lookup_table_mode_t, database_name string, schema_name string, table_name string) (result *Xtable_table, rsql_err *rsql.Error)

Lookup_table returns *Xtable_table corresponding to the name. Returns nil if not found.

This function is used by the decorator, for DELETE.

Argument table_name can be an alias name.

func (*Xtable_union) Put_in_map

func (xtable_union *Xtable_union) Put_in_map(tbl_map Tbl_map) *rsql.Error

func (*Xtable_union) Type

func (xtable_union *Xtable_union) Type() Xt_type_t

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL