TAILIEUCHUNG - Beginning Databases with Postgre SQL phần 8

khi có thay đổi các bảng cơ sở dữ liệu. Điều này cho chúng ta một phương tiện thực thi toàn vẹn tham chiếu. Toàn vẹn tham chiếu đơn giản, tốt nhất để dính vào hạn chế, vì họ là đơn giản hơn, hiệu quả, và ít lỗi dễ bị. các chức năng, THỦ TỤC LƯU TRỮ, và gây ra | CHAPTER 14 ACCESSING POSTGRESQL FROM C USING EMBEDDED SQL 439 Handling Empty Results So far in our sample programs in this chapter we have been careful to make sure that when we retrieve data we obtain exactly one row. The column values are then extracted into host variables for our program to use. By making a small change to our select program to look up customers according to ZIP code we can demonstrate handling cases where no rows are returned. The following sample program detects the case where no data is returned from a SELECT include include include EXEC SQL include sqlca EXEC SQL whenever sqlwarning sqlprint EXEC SQL whenever sqlerror do GiveUp void GiveUp fprintf stderr Fatal Error n sqlprint exit 1 main int argc char argv EXEC SQL BEGIN declare section int id char title 4 int title_ind char zip 10 varchar lname 32 varchar town 64 int town_ind EXEC SQL END declare section if argc 2 printf Usage select zipcode n exit 1 strncpy zip argv 1 sizeof zip EXEC SQL CONNECT TO bpfinal 440 CHAPTER 14 ACCESSING POSTGRESQL FROM C USING EMBEDDED SQL EXEC SQL SELECT customer_id title lname town into id title title_ind lname town town_ind FROM customer WHERE zipcode zip if 2 0 printf no customer found n else printf title is sNULL n title_ind not printf town is sNULL n town_ind not printf customer id d n id printf . s . s . s n sizeof title title EXEC SQL DISCONNECT ALL In this program we use the fact the SQL control area will contain information about the number of rows returned in 2 . If this is zero then we found no rows. Let s use the program to query some data. make select2 . select2 NT2 2TX title is not NULL town is not NULL customer id 3 Miss Matthew Nicetown . select2 BG4 2XE no customer found . select2 BG4 2WE Fatal Error sql error SQL error -203 in line 37. When we specify a zipcode search where we find a customer with a zipcode that matches we print out the .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.