Tree [8d6264] master /

File Date Author Commit
core 2014-08-21 [8d6264] Use 'stack.h' for tracking subquery openings
gui 2014-07-23 dnsmkl dnsmkl [0431d9] Move 'private' includes .hpp->.cpp
testing 2013-02-23 [3fdf59] Add more keywords & refactorings
tools 2012-07-01 [988f31] Fix from Carlos
unused 2011-08-10 dnsmkl dnsmkl [6e61fe] Add file with some general formating functions
.gitignore 2014-04-27 dnsmkl dnsmkl [1c7974] Gitignore *.o files
LICENSE 2011-04-17 dnsmkl dnsmkl [7cb509] Initial version of files. 2013-02-23 [6ea4a5] Fix markdown syntax in
formatting.conf 2014-05-02 dnsmkl dnsmkl [cc8101] Add explanations to conf file
makefile 2014-07-22 dnsmkl dnsmkl [36dc01] Shorten C++ building

Read Me

Free SQL Formatter

This is a tool that adds linebreaks and indentation to sql source code.
Licensed under LGPL. Full license is available in file 'LICENCE', which you should have received with the program

How it works

fsqlf simply goes through provided input text, and tries to recognise predefined set of keywords. If keyword is recognized it adds spacing around it using settings in configuration file (and to some level settings from CLI/GUI).

Table of content:

  1. Current state of development
  2. Compilation
    2.1 Requirements
    2.2 Compilation process
  3. TODO lists
  4. Usage
    4.1 Usage commandline
    4.2 Usage graphical user interface
  5. Project site
    APPENDIX - wxWidgets installation

1. Current state of development

My use case is formatting generated SQL code - make something readable out of one long line of SQL code

Current list of implemented capabilities:

  • indent subqueries
  • new line in cases where it seems appropriate (items in SELECT list. Keywords FROM, JOIN, ON, WHERE, AND, OR, DELETE, INSERT, UPDATE, SET)
  • capitalisation of recognised keywords (not all - I like some keywrods lowercase, but this should be configurable eventualy)
  • gui
  • configurations read from file

(see TODO list what is planed for future)

2.1 Compilation - Requirements

The following list actualy should be suficient. Look into 'makefile' for compilation instructions

Stuff that I got installed:

  • flex #
  • gcc
  • wxWidgets # needed for Graphical User Interface (GUI). If you want to build Windows executables on Linux machine see 'APPENDIX.1 - wxWidgets installation'
  • g++ # for compiling GUI
  • make # This makes all compiling automated
  • mingw32 # cross compiler which is used to produce Windows executables under Linux
  • zip # used only for creating zip archive with source code and executable files
  • git # used for version control and creating zip archive with source code and executable files
  • bash,tr,awk,diff # used for some testing

2.2 Compilation process

General instructions

  • Use 'flex' on core/fsqlf.lex
  • Compile its output with C compiler and name the executable 'fsqlf.exe' if you on Windows and 'fsqlf' in other cases (such name is needed for gui to be able to call it)
  • Compile 'gui/wx_fsqlf.cpp' with C++ compiler
  • Put both executables 'fsqlf' and 'wx_fsqlf' into one directory.

If you use Linux and have installed same programs as I do (see section 2.1), then you can use the make file

# make all      # Compile source for LINUX and WINDOWS. Excutables can be found in 'bin/' directory:  'fsqlf', 'fsqlf.exe', 'gui_wx_basic', 'gui_wx_basic.exe'
# make test     # Compile and run program on test file 'test.sql' and print output to console
# make zip      # Create zip archive with executables and source code binaries (for publishing)
# make clean    # Remove all files created with other make commands

3. TODO list:

  • paranthesis in restrictions (e.g. AND (a=1 OR b=1) )
  • improve GUI
  • make 3 configuration modes:
  • 'case' statements (prerequisite: redo stack function)
  • improve analytical function formatting
  • alignment of comments
  • in equality condition align all comparison signs ('=' , '<>', etc.)

4.1 Usage commandline


# bin/fsqlf.exe                         # read from stdin, write to stdout
# bin/fsqlf.exe input_file              # read from file, write to stdout
# bin/fsqlf.exe input_file output_file  # use files for reading and writing
# bin/fsqlf.exe --help                  # info on more options

Usage in Linux is equivalent, just without the extention '.exe'
Formatting configurations can be changed in 'formatting.conf'

4.2 Usage graphical user interface

Go to directory 'bin/' (this is needed so 'wx_fsqlf.exe' would be started in the same folder where 'fsqlf.exe' is located)
In Windows execute 'wx_fsqlf.exe'
In Linux execute 'wx_fsqlf'

When it starts, just fill your code into the formater window and press 'Format'
Formating configurations can be changed in 'formatting.conf'

5. Project site

Most recent source code can be found at sourceforge.
Project site address
Source can also be forked at github

APPENDIX.1 - wxWidgets installation

I use debian, so I describe what I did. Your system probably is different, but maybe this will at least give you an idea in which direction to go.

Install for normal compilation

Install WxWidgets

# apt-get install wx2.8-headers libwxgtk2.8-0 libwxgtk2.8-dev
# cd /usr/include
# ls | grep wx
# ln -sv wx-2.8/wx wx

Install for cross-compiling windows binaries on linux

Install mingw (cross) compiler

# apt-get install mingw32

Download wxWidgets source from
(some forums mention that sources provided by ubuntu/debian are not good)

Build wxWidgets with mingw

# ./configure --prefix=/usr/i586-mingw32msvc --host=i586-mingw32msvc --build=`./config.guess` --enable-unicode --disable-shared
# make
# make install
# cd /usr/i586-mingw32msvc/include
# ln -sv wx-2.8/wx wx


This was done by following instructions found in
with little adjustment by after reading