2011年5月20日金曜日

OSqlEditでSchemeマクロ

OSqlEdit 8.1.0.0から、Schemeマクロでグリッドにアクセスすることができます。

たとえば、↓をファイル「in_clause.scm」に保存し、

; let*: PL/SQLのdeclareみたいなもの
(let* ((oport (open-output-string))   ; 出力先
       (sel (grid-get-selected-area)) ; 選択範囲
       (col (list-ref sel 1))         ; 選択範囲のうちの左端カラム
       (first-row (list-ref sel 0))   ; 選択範囲のうちの最上行
       (last-row (list-ref sel 2)))   ; 選択範囲のうちの最下行
  ; ループ
  (do ((row first-row (+ row 1))) ; 変数rowをfirst-rowから1ずつ増加させる
      ((> row last-row))          ; ループ終了条件。last-rowを超えたらやめる
    ; 出力
    (display (string-append "'" (grid-get-cell-string row col) "'"
                            (if (< row last-row) "," ""))
             oport)
    (newline oport))
  (editor-paste-string (get-output-string oport))
  (close-output-port oport))

検索結果を選択したあとに「ツール → マクロを実行(ファイル)」で実行すれば、検索結果のグリッドせ選択している部分をIN句で使えるようにエディタに出力します。


0 件のコメント:

コメントを投稿