Modify BaseQuery to be self-building

Builder now injects itself into the query, to allow the query to write itself.

- add `getSql` and `__toString` to BaseQuery
- add `setBuilder` and `getBuilder` to BaseQuery
- GenericBuilder calls `setBuilder` to inject itself into each query it creates
`__toString` cannot throw exceptions (causes a PHP fatal error), so the exceptions must be converted to a string.