### Start/Stop Slave/Replica Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of starting and stopping slave or replica threads. ```sql [<80024]start slave relay_thread, sql_thread, sql_thread until master_log_pos = 42 user = 'mike'$$ ``` ```sql [<80024]stop slave relay_thread, sql_thread$$ ``` ```sql [>=80024]start replica relay_thread, sql_thread, sql_thread until source_log_pos = 42 user = 'mike'$$ ``` ```sql [>=80024]stop replica relay_thread, sql_thread$$ ``` -------------------------------- ### Transaction Management Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of starting transactions, committing work, and managing savepoints. ```sql start transaction with consistent snapshot$$ ``` ```sql commit work and no chain release$$ ``` ```sql savepoint blah$$ ``` ```sql release savepoint blah$$ ``` -------------------------------- ### Drop Server Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a server if it exists. ```sql drop server if exists 'server1'$$ ``` -------------------------------- ### Prepared Statement Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of preparing, executing, and deallocating SQL statements. ```sql prepare s1 from 'select * from customer'$$ ``` ```sql prepare s2 from @select_var$$ ``` ```sql execute s1 using @'blah', @blah$$ ``` ```sql deallocate prepare s1$$ ``` -------------------------------- ### XA Transaction Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of starting, committing, and recovering XA transactions. ```sql xa start '123456789' resume$$ ``` ```sql xa commit '1'$$ ``` ```sql xa recover$$ ``` -------------------------------- ### Drop Database Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a database if it exists. ```sql drop database if exists sakila$$ ``` -------------------------------- ### Create Server Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of creating a server definition with foreign data wrapper options. ```sql create server 'server1' foreign data wrapper 'blah' options (host 'host', port 3306)$$ ``` -------------------------------- ### User Management Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of dropping users and renaming users. ```sql drop user current_user(), 'mike'@localhost$$ ``` ```sql [<80011]grant insert (a, b, c), references (d, e, f) on function *.* to mike@'localhost', friends@`anyhost` require CIPHER '12345' ISSUER 'me' with max_queries_per_hour 10000 grant option$$ ``` ```sql grant insert (a, b, c), references (d, e, f) on function *.* to mike@'localhost', friends@`anyhost'$$ ``` ```sql rename user mike to ekim, ekim to mike, me to myself$$ ``` -------------------------------- ### Drop View Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping multiple views. ```sql drop view sakila.film_list, actor_info cascade$$ ``` -------------------------------- ### Install Plugin Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Installs a server plugin using its shared object name. ```sql install plugin soname soname 'plugin'$$ ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/mike-lischke/antlr4ng/blob/main/ReadMe.md Run this command in the root of the repository after cloning to install all necessary development dependencies. ```bash npm i ``` -------------------------------- ### Change Master/Replication Source Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of changing master or replication source configurations. ```sql [<80024]change master to master_bind = 'blah', relay_log_pos = 1, ignore_server_ids = (1, 2, 3, 4)$$ ``` ```sql [>=80024]change replication source to source_bind = 'blah', relay_log_pos = 1, ignore_server_ids = (1, 2, 3, 4)$$ ``` -------------------------------- ### Drop Tablespace Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a tablespace. ```sql drop tablespace space1 wait$$ ``` -------------------------------- ### Setup and Use ANTLR4ng Parser Source: https://context7.com/mike-lischke/antlr4ng/llms.txt Demonstrates the standard setup for ANTLR4ng parsers, including lexer and token stream creation. Shows how to invoke parser rules, access syntax error information, and manage the parser's state for reuse. ```typescript import { CharStream, CommonTokenStream, ParseTreeWalker } from "antlr4ng"; import { MyLexer } from "./generated/MyLexer.js"; import { MyParser } from "./generated/MyParser.js"; // Standard parsing setup const input = CharStream.fromString("1 + 2 * 3"); const lexer = new MyLexer(input); const tokenStream = new CommonTokenStream(lexer); const parser = new MyParser(tokenStream); // Parse starting from a rule const tree = parser.expression(); // Call your start rule // Access parse information console.log(`Syntax errors: ${parser.numberOfSyntaxErrors}`); console.log(`Current token: ${parser.getCurrentToken().text}`); // Get expected tokens at current position const expected = parser.getExpectedTokens(); console.log(`Expected tokens: ${expected.toString()}`); // Check if a token type is expected if (parser.isExpectedToken(MyParser.IDENTIFIER)) { console.log("Identifier is expected here"); } // Get rule invocation stack for debugging const ruleStack = parser.getRuleInvocationStack(); console.log(`Rule stack: ${ruleStack.join(" -> ")}`); // Reset parser for reuse with new input tokenStream.seek(0); parser.reset(); const newTree = parser.expression(); // Enable tracing for debugging parser.setTrace(true); ``` -------------------------------- ### Rename Tables Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of renaming multiple tables. ```sql rename tables a to b, c to d, sakila.actor to sakila.bctor$$ ``` -------------------------------- ### Call Stored Procedure Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of calling a stored procedure with parameters. ```sql call sakila.rewards_report ((select * from actor where actor_id = 1), 22, @a)$$ ``` -------------------------------- ### DO Statement Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of the DO statement for executing a statement and assigning a variable. ```sql do (select 1 from city), @a := 1, 111 >> 222 and 333$$ ``` -------------------------------- ### Drop Event Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a specific event. ```sql drop event actor.event1$$ ``` -------------------------------- ### Truncate Table Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of truncating a table. ```sql truncate sakila.film_text$$ ``` -------------------------------- ### Create Trigger Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of creating a trigger for updating film text after a film update. ```sql CREATE TRIGGER `upd_film` AFTER UPDATE ON `film` FOR EACH ROW BEGIN IF (old.title != new.title) or (old.description != new.description) THEN UPDATE film_text SET title=new.title, `description`=new.description, film_id=new.film_id WHERE film_id=old.film_id; END IF; END$$ ``` ```sql CREATE DEFINER=CURRENT_USER TRIGGER trigger1 BEFORE INSERT ON table1 FOR EACH ROW BEGIN UPDATE table2 SET table2.type = 'translator' WHERE table2.profile_id = NEW.translator_id; END$$ ``` -------------------------------- ### Handler Statement Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of HANDLER statements for opening, closing, reading, and managing table data. ```sql handler .id1 open as b$$ ``` ```sql handler id2 close$$ ``` ```sql handler id3 read first$$ ``` ```sql handler id3 read id4 prev where actor_id = 1 limit 1,1$$ ``` ```sql handler id4 read id5 <= (123, default, (select 1)) limit 10$$ ``` -------------------------------- ### Drop Temporary Tables Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping multiple temporary tables. ```sql drop temporary tables if exists sakila.actor, sakila.city restrict$$ ``` -------------------------------- ### Drop Function Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a function if it exists. ```sql drop function if exists sakila.get_customer_balance$$ ``` -------------------------------- ### Create Tablespace Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Syntax for creating a tablespace with a datafile and logfile group. ```sql create tablespace space1 add datafile 'file1' use logfile group group1 autoextend_size = 1M no_wait, initial_size 10G$$ ``` -------------------------------- ### Create User with Password Authentication Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of creating a new MySQL user with a specified password. ```sql create user mike identified by password 'a' ``` -------------------------------- ### Drop Trigger Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a trigger if it exists. ```sql drop trigger if exists payment.payment_date$$ ``` -------------------------------- ### Purge Binary Logs Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of purging binary logs before a specific point. ```sql purge binary logs to 'blah'$$ ``` ```sql [<80024]purge master logs before (select * from customer)$$ ``` -------------------------------- ### Create User with Simple Password Authentication Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of creating a new MySQL user with a simple password string. ```sql create user mike identified by 'a' ``` -------------------------------- ### Drop Logfile Group Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a logfile group with various options. ```sql drop logfile group group1 wait wait wait, no_wait, no_wait, storage engine = InnoDB storage engine MyISAM$$ ``` -------------------------------- ### Drop Index Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping an index from a table. ```sql drop index idx_fk_staff_id on sakila.payment$$ ``` -------------------------------- ### Insert Statement Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of INSERT statements, including setting values, inserting from a select statement, and using qualified names. ```sql insert into .actor set actor_id = 1, first_name = 'Arnold', last_name = 'Schwarzenegger'$$ ``` ```sql insert low_priority ignore into .city (city_id, city, country_id) values (1, 'Munich', 2)$$ ``` ```sql insert staff (staff_id, address_id, active) (select staff_id, address_id, active from staff where staff_id < 5) union (select staff_id, address_id, active from staff where staff_id > 10)$$ ``` ```sql insert .order (a.order.*) values (1)$$ ``` ```sql insert .order (a.order.select) values (1)$$ ``` ```sql insert .order (a.*) values (1)$$ ``` -------------------------------- ### Initialize and Use Lexer Source: https://context7.com/mike-lischke/antlr4ng/llms.txt Shows how to initialize a lexer with a CharStream and retrieve tokens. Covers configuring lexer options, getting all tokens, iterating token by token, and managing lexer modes. ```typescript import { CharStream, Token } from "antlr4ng"; import { MyLexer } from "./generated/MyLexer.js"; // Create lexer with input stream const input = CharStream.fromString("let x = 10 + 20;"); const lexer = new MyLexer(input); // Configure lexer options (optional) lexer.options.minDFAEdge = 0; // Minimum cached code point (default: 0) lexer.options.maxDFAEdge = 256; // Maximum cached code point (default: 256) lexer.options.maxCodePoint = 0x10FFFF; // Full Unicode range // Get all tokens at once const allTokens = lexer.getAllTokens(); for (const token of allTokens) { console.log(`Token: type=${token.type}, text="${token.text}", line=${token.line}, column=${token.column}`); } // Or iterate one token at a time lexer.reset(); let token = lexer.nextToken(); while (token.type !== Token.EOF) { console.log(`${lexer.vocabulary.getSymbolicName(token.type)}: "${token.text}"`); token = lexer.nextToken(); } // Access lexer mode stack for multi-mode grammars console.log(`Current mode: ${lexer.mode}`); lexer.pushMode(MyLexer.STRING_MODE); // Enter string mode lexer.popMode(); // Return to previous mode ``` -------------------------------- ### SELECT with System Variables and LIMIT/OFFSET Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of selecting system variables and using LIMIT and OFFSET clauses for pagination. ```sql SELECT @@version_comment LIMIT ?$$ ``` ```sql SELECT @@version_comment LIMIT 1 , 2$$ ``` ```sql SELECT @@version_comment LIMIT 2 OFFSET 1$$ ``` -------------------------------- ### WEIGHT_STRING Function Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates the use of the WEIGHT_STRING function with different data types, levels, and ordering options. ```sql SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s)) ``` ```sql SELECT HEX(WEIGHT_STRING('ab' AS BINARY(4))) ``` ```sql SELECT HEX(WEIGHT_STRING('ab' AS CHAR(4))) ``` ```sql SELECT HEX(WEIGHT_STRING(0x007fff LEVEL 1)) ``` ```sql SELECT HEX(WEIGHT_STRING(0x007fff LEVEL 1 DESC)) ``` ```sql SELECT HEX(WEIGHT_STRING(0x007fff LEVEL 1 REVERSE)) ``` ```sql SELECT HEX(WEIGHT_STRING(0x007fff LEVEL 1 DESC REVERSE)) ``` ```sql SELECT HEX(WEIGHT_STRING('ab' AS CHAR(4) LEVEL 1-3)) ``` ```sql SELECT HEX(WEIGHT_STRING('ab' AS CHAR(4) LEVEL 1, 2, 3, 4)) ``` -------------------------------- ### Run Real World Benchmarks Source: https://github.com/mike-lischke/antlr4ng/blob/main/ReadMe.md Executes a comprehensive benchmark suite using real-world examples, such as MySQL query parsing. ```bash npm run run-benchmarks ``` -------------------------------- ### Drop Procedure Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of dropping a stored procedure. ```sql drop procedure film_in_stock$$ ``` -------------------------------- ### Delete Statement Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of DELETE statements with various options like LOW_PRIORITY, IGNORE, and complex WHERE clauses. ```sql delete low_priority quick ignore from sakila.actor where actor_id = 1 order by actor_id limit 22$$ ``` ```sql delete from sakila.city.*, payment.*, staff using { OJ (select * from actor a) as oneone inner join sakila.store as s on s.store_id = a.actor_id } where payment.payment_id = 1$$ ``` ```sql [<80017]delete sakila.city.*, payment.*, staff from { one (select * from actor a) as oneone inner join sakila.store as s on s.store_id = a.actor_id } where payment.payment_id = 1$$ ``` -------------------------------- ### Table Locking Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of locking and unlocking tables for read or write operations. ```sql lock tables sakila.actor a read local, payment write$$ ``` ```sql unlock tables$$ ``` -------------------------------- ### SQL Unicode Character Set Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates the use of different character set prefixes in SQL queries for string literals. ```sql select _utf8 0xc386C3a4; ``` ```sql select _ucs2 0x30da; ``` ```sql SELECT _big5'test' ``` ```sql SELECT _latin2'test' COLLATE latin2_czech_ci ``` ```sql SELECT _ujis'test' ``` ```sql SELECT _sjis'test' ``` ```sql SELECT _tis620'test' ``` ```sql SELECT _euckr'test' ``` ```sql SELECT _gb2312'test' ``` ```sql SELECT _cp1250'test' COLLATE cp1250_czech_ci ``` ```sql SELECT _gbk'test' ``` ```sql SELECT _utf8'test' ``` ```sql SELECT _ucs2 0xAABB ``` ```sql SELECT _binary 'test' ``` -------------------------------- ### Load Data Statement Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of LOAD DATA statements for importing data from files, with options for concurrency, ignoring errors, and character sets. ```sql load data concurrent local infile 'filename' ignore into table city charset binary columns terminated by '\t' lines starting by 'blah' ignore 20 lines (actor.actor_id, @x) set actor_id = 1, a = (select 1)$$ ``` ```sql load xml concurrent local infile 'filename' ignore into table city charset binary rows identified by 'starting' columns terminated by '\t' lines starting by 'blah' ignore 20 lines (actor.actor_id, @x)$$ ``` -------------------------------- ### SELECT from specific tables and columns Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of selecting data from specific tables, including qualified column names and quoted identifiers. ```sql select * from sakila.order$$ ``` ```sql select * from sakila.`order`$$ ``` ```sql select a.* from sakila.order$$ ``` ```sql select a.select.* from sakila.order$$ ``` ```sql select a. value. * from sakila.order$$ ``` -------------------------------- ### Install antlr4ng Package Source: https://github.com/mike-lischke/antlr4ng/blob/main/ReadMe.md Use npm to install the antlr4ng package. Ensure your project supports ES2022 or newer. ```bash npm install antlr4ng ``` -------------------------------- ### Replace Statement Examples Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of REPLACE statements, which insert or update rows based on primary or unique keys. ```sql replace delayed into language (language_id, name) values (1, 'Esperanto')$$ ``` ```sql replace staff (staff_id, address_id, active) (select staff_id, address_id, active from staff where staff_id < 5) union (select staff_id, address_id, active from staff where staff_id > 10)$$ ``` -------------------------------- ### SQL Table Creation with SELECT Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates a new table `t` and populates it with data derived from a `SELECT` statement. This example includes a floating-point literal and a value expressed in scientific notation. ```sql CREATE TABLE t SELECT 2.5 AS a, 25E-1 AS b$$ ``` -------------------------------- ### Get Week Number from Date Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use WEEK to get the week number of a date. The second argument specifies the start of the week. ```sql SELECT WEEK('2008-02-20')$$ ``` ```sql SELECT WEEK('2008-02-20',0)$$ ``` -------------------------------- ### CREATE TABLE Statements Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of CREATE TABLE statements for defining new tables with various column types, constraints, and auto-increment properties. ```sql CREATE TABLE auth_group_permissions ( id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY , group_id INTEGER NOT NULL , permission_id INTEGER NOT NULL , UNIQUE ( group_id , permission_id ) ) ;$$ ``` ```sql CREATE TABLE app_recipe ( id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY , author_id INTEGER NOT NULL , name VARCHAR( 1 ) NOT NULL , insert_date datetime NOT NULL , batch_size NUMERIC( 1 , 1 ) NOT NULL , batch_size_units VARCHAR( 1 ) NOT NULL , style_id INTEGER NULL , derived_from_recipe_id INTEGER NULL , type VARCHAR( 1 ) NOT NULL , source_url VARCHAR( 1 ) NULL , notes LONGTEXT NULL ) ;$$ ``` ```sql CREATE TABLE auth_permission ( id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY , name VARCHAR( 12 ) NOT NULL , content_type_id INTEGER NOT NULL , codename VARCHAR( 12 ) NOT NULL , UNIQUE ( content_type_id , codename ) ) ;$$ ``` -------------------------------- ### String Encryption Functions Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of various string encryption functions including DES_ENCRYPT, ENCRYPT, MD5, PASSWORD, SHA1, and SHA2. ```sql SELECT customer_address FROM customer_table WHERE crypted_credit_card = DES_ENCRYPT('credit_card_number')$$ ``` ```sql SELECT ENCRYPT('hello')$$ ``` ```sql SELECT MD5('testing')$$ ``` ```sql SELECT PASSWORD('mypass')$$ ``` ```sql SELECT SHA1('abc')$$ ``` ```sql SELECT SHA2('abc', 224)$$ ``` -------------------------------- ### Get Database Version Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Retrieves the current version of the database server. ```sql SELECT @@version ``` -------------------------------- ### SQL IPv6 Address Conversion Functions Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates conversion between IPv6 addresses and their binary representations using `INET6_ATON` and `INET6_NTOA`. Includes examples for both standard IPv6 and IPv4-mapped IPv6 addresses. ```sql SELECT INET6_NTOA(INET6_ATON('fdfe::5a55:caff:fefa:9089'))$$ ``` ```sql SELECT INET6_NTOA(INET6_ATON('10.0.5.9'))$$ ``` ```sql SELECT INET6_NTOA(UNHEX('FDFE0000000000005A55CAFFFEFA9089'))$$ ``` ```sql SELECT INET6_NTOA(UNHEX('0A000509'))$$ ``` -------------------------------- ### SQL Stored Function Creation with Delimiters Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of creating a stored function in SQL, including handling the default delimiter and using `/*! ... */` syntax for version-specific comments or directives. ```sql /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`localhost`*/ /*!50003 FUNCTION `test_restore_work`() RETURNS int(11) BEGIN DECLARE result INT; set result := 42; RETURN result; END */$$ ``` -------------------------------- ### Help Command Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Displays help information for a given topic. ```sql help 'me'$$ ``` -------------------------------- ### Create View Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Defines a virtual table based on the result-set of a SQL statement. This example creates a view named 'film_list' with joined tables and aggregated data. ```sql CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY DEFINER VIEW `film_list` AS select `film`.`film_id` AS `FID`, `film`.`title` AS `title`, `film`.`description` AS `description`, `category`.`name` AS `category`, `film`.`rental_rate` AS `price`, `film`.`length` AS `length`, `film`.`rating` AS `rating`, group_concat(concat(`actor`.`first_name`, _utf8' ', `actor`.`last_name`) separator ', ') AS `actors` from ((((`category` left join `film_category` ON ((`category`.`category_id` = `film_category`.`category_id`))) left join `film` ON ((`film_category`.`film_id` = `film`.`film_id`))) join `film_actor` ON ((`film`.`film_id` = `film_actor`.`film_id`))) join `actor` ON ((`film_actor`.`actor_id` = `actor`.`actor_id`))) group by `film`.`film_id`$$ ``` -------------------------------- ### SQL Table Creation Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Shows how to create tables, including creating a table structure based on an existing one. ```sql CREATE TABLE t1 (a1 INT, a2 INT, a3 INT, a4 DATETIME)$$ ``` ```sql CREATE TABLE t2 LIKE t1$$ ``` ```sql CREATE TABLE t3 LIKE t1$$ ``` -------------------------------- ### Prepare and Execute SQL Statement Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates how to prepare and execute a dynamic SQL statement in MySQL. ```sql SET @stmt := CONCAT("EXPLAIN FORMAT=JSON", @sql); PREPARE explain_stmt FROM @stmt; EXECUTE explain_stmt; DEALLOCATE PREPARE explain_stmt; ``` -------------------------------- ### Update Statement Example Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of an UPDATE statement with IGNORE and a complex join. ```sql update ignore { OJ actor a straight_join city c on a.actor_id = city.city_id} set c.city = 'blah', a.last_update = default$$ ``` -------------------------------- ### Implementing Visitor Pattern for Parse Tree Traversal Source: https://context7.com/mike-lischke/antlr4ng/llms.txt Shows how to extend AbstractParseTreeVisitor to implement the visitor pattern for evaluating parse trees. Includes examples of defining default results, aggregating child results, and implementing specific visit methods for different rule contexts. ```typescript import { AbstractParseTreeVisitor } from "antlr4ng"; import { MyParserVisitor } from "./generated/MyParserVisitor.js"; import { ExpressionContext, AddContext, MultiplyContext, NumberContext } from "./generated/MyParser.js"; // Create a visitor that evaluates expressions class ExpressionEvaluator extends AbstractParseTreeVisitor implements MyParserVisitor { // Default result when visiting children protected defaultResult(): number { return 0; } // Aggregate results from multiple children protected aggregateResult(aggregate: number, nextResult: number): number { return nextResult; // Use last result } // Visit addition: expr '+' expr visitAdd = (ctx: AddContext): number => { const left = this.visit(ctx.expression(0)!)!; const right = this.visit(ctx.expression(1)!)!; return left + right; }; // Visit multiplication: expr '*' expr visitMultiply = (ctx: MultiplyContext): number => { const left = this.visit(ctx.expression(0)!)!; const right = this.visit(ctx.expression(1)!)!; return left * right; }; // Visit number literal visitNumber = (ctx: NumberContext): number => { return parseInt(ctx.NUMBER().getText(), 10); }; } // Use the visitor const visitor = new ExpressionEvaluator(); const result = visitor.visit(tree); console.log(`Result: ${result}`); // e.g., "7" for "1 + 2 * 3" ``` -------------------------------- ### SQL SET Statements Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates various ways to set session and global variables, including buffer sizes. ```sql SET sort_buffer_size=10000$$ ``` ```sql SET @@local.sort_buffer_size=10000$$ ``` ```sql SET GLOBAL sort_buffer_size=1000000, SESSION sort_buffer_size=1000000$$ ``` ```sql SET @@sort_buffer_size=1000000$$ ``` ```sql SET @@global.sort_buffer_size=1000000, @@local.sort_buffer_size=1000000$$ ``` -------------------------------- ### Run Full Test Suite Source: https://github.com/mike-lischke/antlr4ng/blob/main/ReadMe.md Executes all available tests and benchmarks in the project. ```bash npm run full-test ``` -------------------------------- ### Show All Tables Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Lists all tables present in the current database. ```sql SHOW TABLES ``` -------------------------------- ### SHOW Statements Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates various SHOW statements to inspect database objects and configurations. ```sql SHOW TABLES$$ ``` ```sql SHOW TABLES FROM mem$$ ``` ```sql SHOW TABLES FROM mem WHERE foo = ?$$ ``` ```sql SHOW DATABASES$$ ``` ```sql SHOW DATABASES LIKE 'blah'$$ ``` ```sql SHOW DATABASES where b'111000111000'$$ ``` ```sql SHOW DATABASES WHERE 0x123456789abcdef$$ ``` ```sql show tables$$ ``` ```sql show binary logs$$ ``` ```sql SHOW INDEX FROM hilo_sequence_rule_eval_results FROM mem$$ ``` ```sql SHOW FULL COLUMNS FROM inventory_types FROM mem LIKE 'abc'$$ ``` ```sql SHOW INDEX FROM inventory_types FROM mem$$ ``` ```sql SHOW INDEX FROM hilo_sequence_inventory_attributes FROM mem$$ ``` ```sql SHOW INDEX FROM migration_migration_state FROM mem$$ ``` -------------------------------- ### Get Week of Year Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use WEEKOFYEAR to get the week number of the year for a given date. ```sql SELECT WEEKOFYEAR('2008-02-20')$$ ``` -------------------------------- ### Get Weekday from Datetime Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use WEEKDAY to get the weekday index (0=Sunday, 6=Saturday) for a given datetime. ```sql SELECT WEEKDAY('2008-02-03 22:23:00')$$ ``` -------------------------------- ### Fetch All Yeasts Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Retrieves all columns from the 'app_yeast' table. ```sql SELECT app_yeast . id , app_yeast . manufacturer_id , app_yeast . ident , app_yeast . name , app_yeast .description , app_yeast . type FROM app_yeast ``` -------------------------------- ### String Function: SUBSTRING (Negative Start) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts a substring from 'Sakila' starting from the 3rd character from the end. ```sql SELECT SUBSTRING('Sakila', -3) ``` -------------------------------- ### String Function: SUBSTRING (Start and Length) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts 6 characters from 'Quadratically' starting at the 5th character. ```sql SELECT SUBSTRING('Quadratically',5,6) ``` -------------------------------- ### Create Table Like Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates a new table with the same structure (columns, data types, indexes) as an existing table. This is useful for creating backup or staging tables. ```sql create table actor_copy (like sakila.actor)$$ ``` -------------------------------- ### SQL Table Dropping Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates how to drop multiple tables. ```sql DROP TABLE t1, t2, t3$$ ``` -------------------------------- ### String Function: SUBSTRING (Start Position) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts a substring from 'Quadratically' starting at the 5th character to the end. ```sql SELECT SUBSTRING('Quadratically',5) ``` -------------------------------- ### Create Database If Not Exists (Default Charset) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates a new database only if it does not already exist, using the default character set. This is a version-specific command. ```sql create database if not exists sakila char set = default$$ ``` -------------------------------- ### Get Current Unix Timestamp Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use UNIX_TIMESTAMP() to get the current number of seconds since the Unix epoch. ```sql SELECT UNIX_TIMESTAMP()$$ ``` ```sql SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19')$$ ``` ```sql SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00')$$ ``` -------------------------------- ### String Function: SUBSTRING (Negative Start and Length) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts 3 characters from 'Sakila' starting from the 5th character from the end. ```sql SELECT SUBSTRING('Sakila', -5, 3) ``` -------------------------------- ### Create Index on App Recipeyeast Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates an index on the 'yeast_id' column of the 'app_recipeyeast' table to optimize queries related to yeast in recipes. ```sql CREATE INDEX app_recipeyeast_yeast_id ON app_recipeyeast ( yeast_id ) ; ``` -------------------------------- ### Get Year and Week Number (Alternative) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use YEARWEEK to get the year and week number. The second argument specifies the mode. ```sql SELECT YEARWEEK('1987-01-01')$$ ``` ```sql SELECT YEARWEEK('1987-01-01', 4) AS week_mode_4$$ ``` -------------------------------- ### Create Synonym Database Procedure Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use this procedure to create a synonym database that contains views pointing to all tables in a source database. It handles checks for existing databases and creates views dynamically. Requires input for the source database name and the desired synonym name. ```sql BEGIN DECLARE v_done bool DEFAULT FALSE; DECLARE v_db_name_check VARCHAR(64); DECLARE v_db_err_msg TEXT; DECLARE v_table VARCHAR(64); DECLARE v_views_created INT DEFAULT 0; DECLARE db_doesnt_exist CONDITION FOR SQLSTATE '42000'; DECLARE db_name_exists CONDITION FOR SQLSTATE 'HY000'; DECLARE c_table_names CURSOR FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = in_db_name; DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; SELECT SCHEMA_NAME INTO v_db_name_check FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = in_db_name; IF v_db_name_check IS NULL THEN SET v_db_err_msg = CONCAT('Unknown database ', in_db_name); SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = v_db_err_msg; END IF; SELECT SCHEMA_NAME INTO v_db_name_check FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = in_synonym; IF v_db_name_check = in_synonym THEN SET v_db_err_msg = CONCAT('Can\'t create database ', in_synonym, '; database exists'); SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = v_db_err_msg; END IF; SET @create_db_stmt := CONCAT('CREATE DATABASE ', in_synonym); PREPARE create_db_stmt FROM @create_db_stmt; EXECUTE create_db_stmt; DEALLOCATE PREPARE create_db_stmt; SET v_done = FALSE; OPEN c_table_names; c_table_names: LOOP FETCH c_table_names INTO v_table; IF v_done THEN LEAVE c_table_names; END IF; SET @create_view_stmt = CONCAT('CREATE SQL SECURITY INVOKER VIEW ', in_synonym, '.', v_table, ' AS SELECT * FROM ', in_db_name, '.', v_table); PREPARE create_view_stmt FROM @create_view_stmt; EXECUTE create_view_stmt; DEALLOCATE PREPARE create_view_stmt; SET v_views_created = v_views_created + 1; END LOOP; CLOSE c_table_names; SELECT CONCAT('Created ', v_views_created, ' view', IF(v_views_created != 1, 's', ''), ' in the ', in_synonym, ' database') AS summary; END$$ ``` -------------------------------- ### Get Year and Week Number Combined Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use YEARWEEK to get the year and week number combined. The second argument specifies the mode. ```sql SELECT YEARWEEK('2000-01-01')$$ ``` ```sql SELECT MID(YEARWEEK('2000-01-01'),5,2) AS extracted_week$$ ``` -------------------------------- ### String Function: SUBSTR (Negative Start) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts a substring from 'Sakila' starting from the 3rd character from the end. `SUBSTR` is often a synonym for `SUBSTRING`. ```sql SELECT SUBSTR('Sakila', -3) ``` -------------------------------- ### String Function: SUBSTR (Start and Length) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts 6 characters from 'Quadratically' starting at the 5th character. `SUBSTR` is often a synonym for `SUBSTRING`. ```sql SELECT SUBSTR('Quadratically',5,6) ``` -------------------------------- ### String Function: SUBSTR (Start Position) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts a substring from 'Quadratically' starting at the 5th character to the end. `SUBSTR` is often a synonym for `SUBSTRING`. ```sql SELECT SUBSTR('Quadratically',5) ``` -------------------------------- ### Fetch All Steps with Date Order Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Retrieves all columns from the 'app_step' table, ordered by date in descending order, with a limit. ```sql SELECT app_step . id , app_step . brew_id , app_step . type , app_step . date , app_step . entry_date , app_step . volume , app_step . volume_units , app_step . temp , app_step . temp_units , app_step . gravity_read , app_step . gravity_read_temp , app_step . gravity_read_temp_units , app_step . notes FROM app_step ORDER BY app_step . date DESC LIMIT ? ``` -------------------------------- ### String Function: LOCATE with Starting Position Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Finds the starting position of the substring 'bar' within 'foobarbar', beginning the search from the 5th character. ```sql SELECT LOCATE('bar', 'foobarbar', 5) ``` -------------------------------- ### Create Database If Not Exists (Binary Charset) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates a new database only if it does not already exist, using a binary character set. This ensures byte-for-byte comparisons. ```sql create database if not exists sakila char set = binary$$ ``` -------------------------------- ### Get UTC Date and Time Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Use UTC_DATE() and UTC_TIME() to get the current UTC date and time respectively. Adding 0 can be used for type casting. ```sql SELECT UTC_DATE(), UTC_DATE() + 0$$ ``` ```sql SELECT UTC_TIME(), UTC_TIME() + 0$$ ``` ```sql SELECT UTC_TIMESTAMP(), UTC_TIMESTAMP() + 0$$ ``` -------------------------------- ### String Function: SUBSTR (Negative Start and Length) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts 3 characters from 'Sakila' starting from the 5th character from the end. `SUBSTR` is often a synonym for `SUBSTRING`. ```sql SELECT SUBSTR('Sakila', -5, 3) ``` -------------------------------- ### Create Index on App Recipehop Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates an index on the 'recipe_id' column of the 'app_recipehop' table to optimize queries related to recipe hops. ```sql CREATE INDEX app_recipehop_recipe_id ON app_recipehop ( recipe_id ) ; ``` -------------------------------- ### SQL Query for 'demo' format Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Selects pressingID and pformat for records where the format is 'demo'. ```sql ELSEIF pformat = 'demo' THEN SELECT pressingID, pformat; ``` -------------------------------- ### Create Adjunct Table Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Defines the structure for the app_adjunct table to store information about brewing adjuncts. ```sql CREATE TABLE app_adjunct ( id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY , name VARCHAR( 1 ) NOT NULL , nodegroup VARCHAR( 1 ) NOT NULL ) ``` -------------------------------- ### TRUNCATE TABLE Statement Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of the TRUNCATE TABLE statement to remove all rows from a table. ```sql TRUNCATE auth_group ;$$ ``` ```sql TRUNCATE django_content_type ;$$ ``` -------------------------------- ### CREATE DATABASE Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates a new database with specified character set. ```APIDOC ## CREATE DATABASE ### Description Creates a new database with specified character set. ### Method CREATE DATABASE ### Endpoint N/A ### Parameters #### Path Parameters - **sakila** (string) - Required - The name of the database to create. #### Query Parameters - **if not exists** - Creates the database only if it does not already exist. - **char set = default** - Sets the default character set for the database. - **char set = binary** - Sets the character set to binary. ### Request Example ```sql [<80011]create database if not exists sakila char set = default create database if not exists sakila char set = binary ``` ### Response #### Success Response (200) Indicates successful creation of the database. #### Response Example N/A ``` -------------------------------- ### String Function: SUBSTRING (FROM Clause) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts a substring from 'foobarbar' starting from the 4th character to the end. ```sql SELECT SUBSTRING('foobarbar' FROM 4) ``` -------------------------------- ### String Function: SUBSTRING (FROM and FOR Clauses) Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Extracts 2 characters from 'Sakila' starting from the 4th character from the end. ```sql SELECT SUBSTRING('Sakila' FROM -4 FOR 2) ``` -------------------------------- ### CREATE TABLE LIKE Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Creates a new table with the same structure as an existing table. ```APIDOC ## CREATE TABLE LIKE ### Description Creates a new table with the same structure as an existing table. ### Method CREATE TABLE LIKE ### Endpoint N/A ### Parameters #### Path Parameters - **actor_copy** (string) - Required - The name of the new table to create. - **sakial.actor** (string) - Required - The name of the existing table to copy structure from. ### Request Example ```sql create table actor_copy (like sakila.actor) ``` ### Response #### Success Response (200) Indicates successful creation of the new table. #### Response Example N/A ``` -------------------------------- ### Select App Style by ID Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Retrieves style information from the app_style table based on the provided ID. Includes name, BJCP code, and parent ID. ```sql SELECT app_style . id , app_style . name , app_style . bjcp_code , app_style . parent_id FROM app_style WHERE app_style . id = ? ``` -------------------------------- ### Create User Profile Table Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Defines the structure for the app_userprofile table to store user-specific brewing preferences. ```sql CREATE TABLE app_userprofile ( id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY , user_id INTEGER NOT NULL UNIQUE , pref_brew_type VARCHAR( 1 ) NOT NULL , pref_make_starter bool NOT NULL , pref_secondary_ferm bool NOT NULL , pref_dispensing_style VARCHAR( 1 ) NOT NULL , timezone VARCHAR( 1 ) NOT NULL ) ``` -------------------------------- ### SQL Formatting for 'demo tape' Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Inserts a record into the pressing_formats table for 'demo tape' format. ```sql ELSEIF pformat = 'demo tape' THEN INSERT INTO kfth.pressing_formats (PressingId, Other, FormatsId) VALUES (pressingID, NULL, 37); ``` -------------------------------- ### SQL NATURAL JOIN Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of using NATURAL JOIN, which automatically joins tables based on columns with the same names. ```sql SELECT * FROM t1 NATURAL JOIN t2 WHERE b > 1 ``` -------------------------------- ### Create Brew Table Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Defines the structure for the app_brew table to store brewing session information. ```sql CREATE TABLE app_brew ( id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY , brew_date datetime NULL , brewer_id INTEGER NOT NULL , notes LONGTEXT NULL , recipe_id INTEGER NULL , last_update_date datetime NULL , last_state VARCHAR( 1 ) NULL , is_done bool NOT NULL ) ``` -------------------------------- ### Select Schema Version Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Retrieves the ID and version from the schema_version_v2 table. ```sql SELECT this_ . id AS id0_0_ , this_ . version AS version0_0_ FROM schema_version_v2 this_ ``` -------------------------------- ### Get Year and Week Number Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Combine YEAR and WEEK functions to extract both year and week number from a date. ```sql SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0)$$ ``` -------------------------------- ### String Function: INSTR Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Finds the starting position of the first occurrence of the substring 'bar' within the string 'foobarbar'. ```sql SELECT INSTR('foobarbar', 'bar') ``` -------------------------------- ### Fetch All Brews with Date Order Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Retrieves all columns from the 'app_brew' table, ordered by brew date in descending order, with a limit. ```sql SELECT app_brew . id , app_brew . brew_date , app_brew . brewer_id , app_brew . notes , app_brew . recipe_id , app_brew . last_update_date , app_brew . last_state , app_brew . is_done FROM app_brew ORDER BY app_brew . brew_date DESC LIMIT ? ``` -------------------------------- ### Create Tablespace with Storage Options Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Defines a new tablespace with various storage and engine specific options. ```sql create tablespace space1 initial_size 123, autoextend_size = 456 max_size 789 extent_size=1005678G, nodegroup = 1000200030004000 storage engine innodb wait wait, no_wait, file_block_size 100 encryption 'got it' ``` -------------------------------- ### SQL Statements with and without Termination Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Examples of SQL statements, some terminated with a semicolon and others not, including comments and trailing spaces. ```sql select "non terminated"$$ ``` ```sql select "terminated";$$ ``` ```sql select "non terminated, space" $$ ``` ```sql select "terminated, space"; $$ ``` ```sql select "non terminated, comment" /* comment */$$ ``` ```sql select "terminated, comment"; /* comment */$$ ``` -------------------------------- ### Use Database Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Selects a database to use for subsequent operations. ```sql use less$$ ``` -------------------------------- ### SQL Query with GROUP_CONCAT and LEFT JOIN Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of using GROUP_CONCAT to aggregate data from the mysql.db table, joining with information_schema.schemata. ```sql SELECT GROUP_CONCAT( ? , ? , `d` . user , ? , `d` . host , ? , `d` . db ORDER BY `d` . user , `d` . host , `d` . db ) AS user , GROUP_CONCAT( ? , `d` . db ORDER BY `d` . db ) AS db_name FROM mysql . db `d` LEFT JOIN information_schema . schemata `s` ON `d` . db = `s` . schema_name WHERE `s` . schema_name IS NULL ORDER BY `d` . user , `d` . db ``` -------------------------------- ### Select Instance Attributes Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Retrieves instance supported status based on instance ID and attribute ID. ```sql SELECT hibinstanc0_ . supported AS col_0_0_ FROM inventory_instance_attributes hibinstanc0_ WHERE hibinstanc0_ . instance_id = ? AND hibinstanc0_ . attribute_id = ? ``` -------------------------------- ### SQL COLLATION Function Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Returns the collation name for a string expression. Examples show usage with literal strings and UTF8 strings. ```sql SELECT COLLATION('abc')$$ ``` ```sql SELECT COLLATION(_utf8'abc')$$ ``` -------------------------------- ### VALUES Constructor with UNION Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Demonstrates creating rows using the VALUES constructor and combining them with UNION. ```sql VALUES ROW(1,2),ROW(3,4),ROW(5,6) UNION VALUES ROW(10,15),ROW(20,25) ``` -------------------------------- ### SQL JOIN with multiple tables and ON clause Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Example of joining three tables (t1, t2, t3) with a specified join condition. ```sql SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3) ``` -------------------------------- ### String Functions: TO_BASE64 and FROM_BASE64 Source: https://github.com/mike-lischke/antlr4ng/blob/main/tests/benchmarks/data/statements.txt Encodes the string 'abc' into a Base64 string using `TO_BASE64` and then decodes it back using `FROM_BASE64`, demonstrating the round trip. ```sql SELECT TO_BASE64('abc'), FROM_BASE64(TO_BASE64('abc')) ```