5.11.Example - Asynchronous Queries
Prev | Chapter5.Example Programs | Next

## 5.11.Example - Asynchronous Queries

この用例は､ Section4.4, “Asynchronous Query Processing Commands” に記述された､非同期問合せ命令を使う｡ それは､問合せは如何にしてデータベースに送られ､応用譜は､結果の返りを待つ間､阻止無しに処理を続けられるか､を例示する｡又､取消し釦は如何にして実装されるかの一部を示す｡註意: これは完全な記述譜ではない｡ This example uses the asynchronous query commands described in Section4.4, “Asynchronous Query Processing Commands”. It shows how a query could be sent to the database, and the application could continue processing without blocking while waiting for the results to come back. It also shows part of how a Cancel button might be implemented. Note: this is not a complete script.

Example5.18.非同期問合せ Asynchronous Queries

    pg_sendquery $conn "SELECT * FROM tables... WHERE conditions ORDER BY ..."
    # 非繁忙状態を待つ:
    # Wait for not-busy condition:
    while {[pg_isbusy $conn]} {
       ... Do something here, like check for user input and update the interface...
       ... Good idea to insert a delay so it doesn't busy-wait ...
       ... Check for cancel button ...
       if {$user_pressed_cancel_button} break
    }

    # 使用者が取消し釦を押したか? それなら､問合せの解消を試みる｡
    # Did the user hit the Cancel button? If so, try to cancel the query.
    if {$user_pressed_cancel_button} {
      pg_cancelrequest $conn
    }

    # 結果を何も残さず取込む (縦え取消されても):
    # Fetch results until it there are none left (even if canceled):
    while {[set res [pg_getresult $conn]] != ""} {
      if {!$user_pressed_cancel_button} {
        ... do something with the query result $res ...
      }
      pg_result $res -clear
    }

Prev | Up | Next
5.10.Example - Bytea Escaping - Picture Viewer, Part 2 - View Pictures | Home | 5.12.Example - Asynchronous Query with Event-Driven Results