Using correct headers and functions for linux. Fixed some memory allocation/free issues.
Added debug printing for SQL statements.