SQL::Tokenizer(3pm)
π SQL::Tokenizer π
okay bestie, so this page is SQL::Tokenizer(3pm) β it's a Perl module manual page, and it's honestly such a little icon. Let me give you the whole tour, no skips, no gatekeeping. π«Ά
β¨ NAME β¨
SQL::Tokenizer β a simple SQL tokenizer. that's it, that's the whole vibe. simple. humble. iconic. π
πΈ VERSION πΈ
0.20
π SYNOPSIS π
here's the glow-up moment, the whole thing in one bite:
use SQL::Tokenizer qw(tokenize_sql);
my $query= q{SELECT 1 + 1};
my @tokens= SQL::Tokenizer->tokenize($query);
# @tokens now contains ('SELECT', ' ', '1', ' ', '+', ' ', '1')
@tokens= tokenize_sql($query); # procedural interface
likeβ¦ @tokens literally comes out as 'SELECT', ' ', '1', ' ', '+', ' ', '1'. she splits, she delivers, she slays. π₯
π DESCRIPTION π
so SQL::Tokenizer is a simple tokenizer for SQL queries. and when I say simple I mean it β she does not claim to be a parser, and she does not claim to be a query verifier. absolutely not her job, she's not going to pretend. all she does is take a valid SQL query and make sane tokens out of it. that's the whole assignment. π―
she gets SQL with comments, like this:
-- This query is used to insert a message into
-- logs table
INSERT INTO log (application, message) VALUES (?, ?)
she also handles '', "" and "\'" escaping methods, so tokenizing a query like the one below? literally not a problem, bestie, she's got it:
INSERT INTO log (application, message)
VALUES ('myapp', 'Hey, this is a ''single quoted string''!')
π API π
β tokenize_sql
use SQL::Tokenizer qw(tokenize_sql);
my @tokens= tokenize_sql($query);
my $tokens= tokenize_sql($query);
$tokens= tokenize_sql( $query, $remove_white_tokens );
tokenize_sql can be imported into whatever namespace you're in, on request. it takes a SQL query and gives you back an array of tokens if you call it in list context, or an arrayref if you call it in scalar context. pick your fighter. π
β tokenize
my @tokens= SQL::Tokenizer->tokenize($query);
my $tokens= SQL::Tokenizer->tokenize($query);
$tokens= SQL::Tokenizer->tokenize( $query, $remove_white_tokens );
this is the only available class method β the one and only, main character energy fr. it takes a SQL query and returns an array of tokens in list context, or an arrayref in scalar context.
and if $remove_white_tokens is true, then white-space-only tokens get removed from the result. bye bye, spaces. π
π ACKNOWLEDGEMENTS π
these are the people who made her what she is, and we're giving them their flowers, periodt:
- Evan Harris β for implementing Shell comment style and SQL operators. π
- Charlie Hills β for spotting a lot of important issues I haven't thought of. ngl, a real one. π
- Jonas Kramer β for fixing MySQL quoted strings and treating dot as a punctuation character correctly. π
- Emanuele Zeppieri β for asking to fix
SQL::Tokenizerto support dollars as well. π - Nigel Metheringham β for extending the dollar signal support. β¨
- Devin Withers β for making it not choke on CR+LF in comments. king behaviour honestly. π
- Luc Lanthier β for simplifying the regex and making it not choke on backslashes. π¦
π§ AUTHOR π§
copyright (c) 2007, 2008, 2009, 2010, 2011 Igor Sutton Lopes <IZUT@cpan.org>. all rights reserved.
this module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
like, actually free free. go off, remix it, it's giving open source royalty.
and that's the whole page bestie, you ate that reading. this doc shipped as perl v5.30.3 on 2020-06-02 β so yeah, a lil vintage, still gorgeous, still works. mwah. ππ«Άβ¨
π¦ where this page comes from
- ubuntu jammy: libsql-tokenizer-perl 0.24-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libsql-tokenizer-perl 0.24-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libsql-tokenizer-perl 0.24-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsql-tokenizer-perl 0.24-8 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms