1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

出力されたSQLログを実行形式に置換整形するマクロ(JScript)

1
Last updated at Posted at 2023-02-08

手順
①ログからSQLとパラメータの2行取り出しサクラエディタに貼り付ける。
②マクロ(tool.js)実行するとバインド変数(プレースホルダ)がパラメータに置換される。

ログ(実行前)
1 select A from B where c=? and d in (?,?)
2 [AAA, BBB, CCC]
3
ログ(実行結果)
1 select A from B where c='AAA' and d in ('BBB','CCC')
2
3

2行目の値は削除され1行目にマージされる。

対象フォーマット

  • 1行目:パラメータ「?」を含むSQL。
  • 2行目:パラメータの値。前後にブラケット括弧 [、] がある、連結はカンマ+スペースである。
    (?は10個まで対応。不足してればループ回数増やせばいい。)
  • 2行目以降は影響なし

実行マクロ

tool.js
//?を引数に置き換えるツール

//描画非表示
SetDrawSwitch(0);

//?にダブルクォート付加
replaceAll('?', '¥'?¥'', 26);

//ループ回数:10回繰り返す
var i = 0;
for(i ; i<10 ; i++){
    //ファイル先頭へ移動し、下へ移動
    GoFileTop();
    Down();

    //先頭から 1個目のカンマorブラケット括弧 まで切り取り
    //検索
        //有効検索オプション
        //4:正規表現
        //16:検索ダイアログ閉じ
        //2048:検索履歴から削除
    var text = SearchNext('^.*?[,[]]]', 2068);

    //検索結果を取得
    text = GetselectedString(text);

    //前後トリム
    var textTrim = text.slice(1, -1);

    //?を置換
    GoFileTop();
    replace('?', textTrim, 26);

    //break処理。ブラケット括弧がなければループ抜ける
    GoFileTop();
    var bracketEnd = SearchNext(']', 2068);
    bracketEnd = GetselectedString(bracketEnd);
    if(bracketEnd == '') break;
};

//画面表示&再描画
SetDrawSwitch(1);
Redraw(0);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?