ef9e165cb882a93c83bacc4b49c55db22daf30e4
[php-sqllint.git] / README.rst
1 ***********
2 PHP-SQLlint
3 ***********
4
5 Command line tool to validate (syntax check) SQL files.
6 Primarily for MySQL ``.sql`` files.
7
8 Can be used in git pre-commit hooks to catch errors.
9 Use it from your shell, offline and without any SQL server.
10
11 You can also use it to format SQL queries.
12
13
14 =====
15 Usage
16 =====
17 Syntax check::
18
19     $ php-sqllint tests/files/create-missingcomma.sql 
20     Checking SQL syntax of tests/files/create-missingcomma.sql
21      Line 3, col 5 at "pid": A comma or a closing bracket was expected.
22      Line 3, col 13 at "11": Unexpected beginning of statement.
23      Line 3, col 17 at "DEFAULT": Unrecognized statement type.
24
25 Emacs mode::
26
27     $ php-sqllint -r emacs tests/files/create-noname.sql 
28     tests/files/create-noname.sql:1.12:Error: The name of the entity was expected.
29     tests/files/create-noname.sql:1.13:Error: A closing bracket was expected.
30     tests/files/create-noname.sql:1.13:Error: At least one column definition was expected.
31
32
33 Formatting::
34
35     $ php-sqllint --format tests/files/select-unformatted.sql
36     SELECT
37       id,
38       NAME,
39       url
40     FROM
41       users
42     WHERE
43       DATE > NOW() AND id != 0
44     ORDER BY NAME
45     LIMIT 10
46
47 You can enable ANSI coloring by passing the ``--colors`` option.
48
49
50 ====
51 Bugs
52 ====
53 Does ``php-sqllint`` not detect a syntax error, or doesn't support a certain
54 SQL statement?
55 Then please report a bug at `udan11/sql-parser`__.
56
57 __ https://github.com/udan11/sql-parser
58
59
60 ============
61 Dependencies
62 ============
63 - PEAR's `Console_Commandline`__
64 - `udan11's SqlParser`__, which is used by `phpMyAdmin`__
65
66 __ http://pear.php.net/package/Console_CommandLine
67 __ https://github.com/udan11/sql-parser
68 __ https://www.phpmyadmin.net/
69
70
71 Dependency installation
72 =======================
73 ::
74
75     $ composer install
76
77 Now you can use ``./bin/php-sqllint`` without building the phar yourself.
78
79
80 ========
81 Building
82 ========
83 You'll need `phing`__, the PHP build tool::
84
85     $ phing
86
87 __ https://www.phing.info/
88
89 The result are ``.phar`` files in ``dist/`` directory that you can execute::
90
91     $ ./dist/php-sqllint-0.0.1.phar tests/files/create-noname.sql 
92     Checking SQL syntax of tests/files/create-noname.sql
93      Line 1, col 12 at "(": The name of the entity was expected.
94
95
96 =================
97 About PHP-SQLlint
98 =================
99
100 License
101 =======
102 ``php-sqllint`` is licensed under the `AGPL v3`__ or later.
103
104 __ http://www.gnu.org/licenses/agpl.html
105
106
107 Homepage
108 ========
109 Home page
110    http://cweiske.de/php-sqllint.htm
111 Source code
112    http://git.cweiske.de/php-sqllint.git
113
114    Mirror: https://github.com/cweiske/php-sqllint
115
116
117 Author
118 ======
119 Written by Christian Weiske, cweiske@cweiske.de