In a large statically-typed software project with non-dynamic manual sql statements inside of it, how do you verify all the sql syntax?

One of the things I seem to struggle with frequently is the need to deploy a software application to test the database interaction. More often than I’d like, I have a syntax error or typo in my sql statement that triggers a runtime error when the statement is invoked.
In some of these projects, there is a very large number of sql queries (>100), which makes it very time consuming if I need check each one. Also, deployment and runtime steps can be so time consuming that it slows me down when checking sql I modified.

Most of the time after checking out an unfamiliar codebase or one I haven’t touched in some time, it is taken on faith that all of the sql works correctly.

What are standard practices around verifying database interaction in applications in a non-manualmore automatic fashion?

You should write test cases for all the database interactions. Given that syntax checking is a concern, you should run them against a test database running the same database software your application is using. If you can get a good representative data sample, then this also provides an opportunity to check your queries for performance.

You could refactor your applications to use Hibernate, or some other framework which generates queries for you automatically, but it sounds like this is legacy code that was not written with such frameworks in mind.

I found this on SO: https://stackoverflow.com/questions/5015613/online-sql-syntax-checker-conforming-to-multiple-databases …also this: https://stackoverflow.com/questions/7753081/are-there-any-sql-validators-that-can-check-syntax-against-multiple-database-ser

One link seems to be a formatter that also checkes syntax: http://www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl and an online version: http://www.dpriver.com/pp/sqlformat.htm

Unfortunately, it looks like it’s a desktop application or VS add-in so it might only do MS SQL. For what you’re suggesting, it would be better to have some tool that can be run from the command line as a part of build process. The closest thing I can think of to that would be attempting to get an execution plan for each query because that would let you know if there’s any syntax errors, but your build process would need to make a connection to the database to actually get the query plan.

From the links above, I’ve found an online tool here: http://developer.mimer.com/validator/
It validates against SQL ANSI standards.

Also found an online tool for MySQL: http://www.piliapp.com/mysql-syntax-check/

For MS SQL there’s this one: http://www.ubitsoft.com/products/t-sql-analyzer/

And there’s also http://sqlfiddle.com/ which is a lot more than a validator.

And when you verify that the syntax is ok, how you plan to verify that your queries are ok and return the expected data?. Is perfectly posible, in fact the most usual, that your queries are syntactically correct but logically incorrect.

Test your application, if test manually its time consuming and impractical (and of course it is in every non trivial system) do automatic testing.

To expand on TMN’s answer, it’s very important to extract database logic into it’s own layer. You should have classes that wrap every call to the database. This makes unit testing your database classes much easier. Once you have verified that all your Data Access Layer classes are working correctly with THEIR unit tests, you can mock them out in other classes unit tests because you are no longer testing data access in that particular test.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật