Finish sql... I think.... (I probably have some bugs but I don't know
them yet)