Skip to content

Split MySQL/PostgreSQL files into individual queries

Notifications You must be signed in to change notification settings

kodus/sql-split

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kodus/sql-split

A simple parser to split SQL (and/or DDL) files into individual SQL queries and strip comments.

PHP Version Build Status

Install via Composer

composer require kodus/sql-split

Features

I designed this for use with PDO and MySQL/PostgreSQL statements.

It uses a very simple recursive descent parser to minimally tokenize valid SQL - this approach ensures there is no ambiguity between quoted strings, keywords, comments, etc. but makes no attempt to validate SQL command structure or validity of the extracted statements.

It supports the following SQL/DDL features:

  • SQL and DDL Queries
  • Stored procedures, functions, views, triggers, etc.
  • PostgreSQL dollar-tags ($$ and $mytag$ delimiters)
  • The MySQL DELIMITER command

Usage

Just this:

$statements = Splitter::split(file_get_contents(...));

This will split to individual SQL statements and (by default) strip comments.

Then just loop over your $statements and run them via PDO.

That's all.

About

Split MySQL/PostgreSQL files into individual queries

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages