Release 0.2.2
[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
48 Syntax highlighting
49 ===================
50 ANSI colors are applied automatically when not piping; you can use the
51 ``--highlight`` option to override the automatism.
52
53 ``--highlight`` option values:
54
55 ``none``
56   No highlighting. Use it to disable automatic highlighting
57 ``ansi``
58   ANSI escape codes for your shell
59 ``html``
60   HTML tags
61
62
63 ====
64 Bugs
65 ====
66 Does ``php-sqllint`` not detect a syntax error, or doesn't support a certain
67 SQL statement?
68 Then please report a bug at `phpmyadmin/sql-parser`__.
69
70 __ https://github.com/phpmyadmin/sql-parser
71
72
73 ========
74 Download
75 ========
76 The download files are equipped with all dependencies.
77 Just download and run.
78
79 .. LATESTRELEASE
80
81 See `php-sqllint downloads page <http://cweiske.de/php-sqllint-download.htm>`_
82 for all released versions.
83
84
85 ============
86 Dependencies
87 ============
88 - PEAR's `Console_Commandline`__
89 - `phpMyAdmin's SqlParser`__
90
91 __ http://pear.php.net/package/Console_CommandLine
92 __ https://github.com/phpmyadmin/sql-parser
93
94
95 Dependency installation
96 =======================
97 ::
98
99     $ composer install
100
101 Now you can use ``./bin/php-sqllint`` without building the phar yourself.
102
103
104 ========
105 Building
106 ========
107
108 Preparation
109 ===========
110 1. Write new version number into ``VERSION``
111
112
113 Create the release
114 ==================
115 You'll need `phing`__, the PHP build tool::
116
117     $ phing
118
119 __ https://www.phing.info/
120
121 The result are ``.phar`` files in ``dist/`` directory that you can execute::
122
123     $ ./dist/php-sqllint-0.0.1.phar tests/files/create-noname.sql 
124     Checking SQL syntax of tests/files/create-noname.sql
125      Line 1, col 12 at "(": The name of the entity was expected.
126
127
128 =================
129 About PHP-SQLlint
130 =================
131
132 License
133 =======
134 ``php-sqllint`` is licensed under the `AGPL v3`__ or later.
135
136 __ http://www.gnu.org/licenses/agpl.html
137
138
139 Homepage
140 ========
141 Home page
142    http://cweiske.de/php-sqllint.htm
143 Source code
144    http://git.cweiske.de/php-sqllint.git
145
146    Mirror: https://github.com/cweiske/php-sqllint
147
148
149 Author
150 ======
151 Written by `Christian Weiske`__, cweiske+php-sqllint@cweiske.de
152
153 __ http://cweiske.de/