ColdFusion MX Bible phần 3

Cú pháp là một chút khác nhau, nhưng nguyên tắc là rất tương tự, phải không? Nó thực sự chỉ là vấn đề học tập cả hai phương pháp để thực hiện các giao dịch và sau đó kiểm soát chúng càng gần đến máy chủ cơ sở dữ liệu như ứng dụng của bạn cho phép bạn làm như vậy. | 208 Part II Using ColdFusion MX with Databases Listing 10-2 continued RAISERROR 50001 The Orderitem could not be inserted. ROLLBACK TRANSACTION RETURN END UPDATE Inventoryitem SET AvailableToSell AvailableToSell - 10 WHERE ItemNumber CAS30-BLK IF ERROR 0 BEGIN RAISERROR 50002 The InventoryItem could not be updated. ROLLBACK TRANSACTION RETURN END COMMIT TRANSACTION The syntax is a little different but the principles are very similar aren t they It s really just a matter of learning both methods for implementing transactions and then controlling them as close to the database server as your application enables you to do so. A good example of when you need to control a transaction within ColdFusion is whenever you are passing multiple rows of data from ColdFusion to the database server and you want to encapsulate all those queries into a single transaction. Listing 10-3 illustrates this example. Listing 10-3 Inserting multiple rows within a single transaction cftransaction cfloop index i from 1 to ArrayLen arItemNumber cfquery name InsertOrderItems datasource CFMXBible INSERT INTO OrderItem SalesOrderID ItemNumber Description UnitPrice Quantity VALUES Val arSalesOrderID i Trim arItemNumber i Trim arDescription i Val arUnitPrice i Val arQuantity i Chapter 10 Using Advanced Database Techniques 209 cfquery cfloop cftransaction You currently have no easy and effective way to directly send multidimensional data from ColdFusion to a database server in a single statement. Until such a method exists you must loop over ColdFusion arrays or structures and call CFQUERY once for each unit of data to be stored in the database. CFTRANSACTION and exception handling The default behavior of the CFTRANSACTION tag is such that if you do not explicitly command it to commit or rollback it does so implicitly for you. This is the technique shown in Listings 10-1 and 10-3. Many ColdFusion developers are used to coding that way but if you rely on the implicit behavior that CFTRANSACTION .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.