SQL::SplitStatement::Tokenizer(3pm) User Contributed Perl Documentation SQL::SplitStatement::Tokenizer(3pm)

SQL::SplitStatement::Tokenizer - A simple SQL tokenizer.

 use SQL::SplitStatement::Tokenizer qw(tokenize_sql);
 my $query= q{SELECT 1 + 1};
 my @tokens= tokenize_sql($query);
 # @tokens now contains ('SELECT', ' ', '1', ' ', '+', ' ', '1')

SQL::SplitStatement::Tokenizer is a simple tokenizer for SQL queries. It does not claim to be a parser or query verifier. It just creates sane tokens from a valid SQL query.

It supports SQL with comments like:

 -- This query is used to insert a message into
 -- logs table
 INSERT INTO log (application, message) VALUES (?, ?)

Also supports '', "" and "\'" escaping methods, so tokenizing queries like the one below should not be a problem:

 INSERT INTO log (application, message)
 VALUES ('myapp', 'Hey, this is a ''single quoted string''!')

    use SQL::SplitStatement::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 to current namespace on request. It receives a SQL query, and returns an array of tokens if called in list context, or an arrayref if called in scalar context.

If $remove_white_tokens is true, white spaces only tokens will be removed from result.

Copyright (c) 2007, 2008, 2009, 2010, 2011 Igor Sutton Lopes "<IZUT@cpan.org>". All rights reserved.

Copyright (c) 2021 Veesh Goldman "<veesh@cpan.org>"

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2022-10-16 perl v5.36.0