fix #529
sql fixes