Added changes to sql file into CMakeLists.txt files. Moved obsolete functions into a legacy.sql file. Cleaned up boolean to text casting.