GizStackGizStack
View .mdOpen in ChatGPTOpen in Claude

gizmodel/sql/parseroutine

The SQL parser: blocks, routines, packages, object types and triggers.

gizlang
import * as Parseroutine from "gizmodel/sql/parseroutine";

Methods

Parser.parenthesized

gizlang
function Parser.parenthesized(self: mut Parser): string

The SQL text inside parentheses, checked as an expression.

Effects: fail, read, alloc.

Parser.blockFollows

gizlang
function Parser.blockFollows(self: Parser): bool

After BEGIN: a block (PL/SQL, T-SQL, SQLite's trigger body) rather than a transaction.

Effects: fail, alloc.

Parser.blockText

gizlang
function Parser.blockText(self: mut Parser): string

A procedural block's source from here to its END (and a name after it): [DECLARE ...] BEGIN ... END. IF, LOOP and CASE statements close with END IF, END LOOP, END CASE.

Effects: fail, alloc.

Parser.routineName

gizlang
function Parser.routineName(self: mut Parser): string

A routine's name: the last part of a qualified one, lower-case.

Effects: fail, alloc.

Parser.declaredType

gizlang
function Parser.declaredType(self: mut Parser): string

A type as declared, its source kept when it names another's (Oracle's t.c%TYPE, r%ROWTYPE).

Effects: fail, alloc.

Parser.routineParams

gizlang
function Parser.routineParams(self: mut Parser): Vec<Param>

Parameters in parentheses, in PostgreSQL's ([mode] [name] type [DEFAULT x]), Oracle's (name [IN|OUT|IN OUT] type [DEFAULT|:= x]) or SQL Server's (@name type [= x] [OUTPUT]) form.

Effects: fail, read, alloc.

Parser.unit

gizlang
function Parser.unit(self: Parser, from: i64, s: Statement): Statement

s, a CREATE of a PL/SQL unit that began at token from, with its text (the terminating ; of a block included).

Effects: fail, alloc.

Parser.objectType

gizlang
function Parser.objectType(self: mut Parser, name: string): Statement

Oracle's CREATE TYPE t [UNDER p] AS OBJECT (attribute type, ..., member declarations) as op create_object_type: name the type, table its parent, columns each attribute as "name type", text each member as "kind function|procedure name".

Effects: fail, alloc.

Parser.typeBody

gizlang
function Parser.typeBody(self: mut Parser): Statement

Oracle's CREATE TYPE BODY t IS member definitions END as the body of a package named t (op create_package, options "type"): each member is a routine t.name; a member also takes SELF first.

Effects: fail, read, alloc.

Parser.package

gizlang
function Parser.package(self: mut Parser): Statement

Oracle's CREATE PACKAGE [BODY] p IS ... END [p], as op create_package (what: spec or body). A body's functions and procedures are its inner CREATE statements, each named p.name (a call p.f(...) names it so). The other items (variables, constants, types, cursors, exceptions, pragmas) are text; a body's text ends with the initialization block after a \u0001.

Effects: fail, read, alloc.

Parser.routine

gizlang
function Parser.routine(self: mut Parser, kind: string, orReplace: bool, owner: string): Statement

CREATE FUNCTION or PROCEDURE, in PostgreSQL's (RETURNS ... LANGUAGE ... AS 'body'), Oracle's (RETURN type IS|AS block) or SQL Server's (AS BEGIN ... END) form. owner: a package's name and a dot, else "".

Effects: fail, read, alloc.

Parser.routineAttrAhead

gizlang
function Parser.routineAttrAhead(self: Parser): bool

Whether a routine attribute that pg_proc keeps comes next (Parser.routineAttr).

Effects: fail.

Parser.routineAttr

gizlang
function Parser.routineAttr(self: mut Parser): string

One routine attribute as an attrs line (routine.giz withAttr): volatile=i|s|v, secdef=t|f, leakproof=t|f, parallel=s|r|u, cost=N, rows=N, set:NAME=ITEMS (the value's items joined by U+0007) or reset:NAME.

Effects: fail, alloc.

Parser.trigger

gizlang
function Parser.trigger(self: mut Parser, orReplace: bool): Statement

CREATE TRIGGER in PostgreSQL's (EXECUTE FUNCTION f()), Oracle's or SQLite's (an inline block) form.

Effects: fail, read, alloc.