Cayenneのbindを含むクエリログをクエリに変換する

実行されたsql文を監視するで取得したクエリログと同じクエリを PgAdminとかで実行したい時がよくありますが、

SELECT t0.CREATE_DATE, t0.CREATE_USER_ID, t0.NOTE, t0.OWNER_ID, t0.PARENT_ID, t0.TOPIC_NAME, t0.UPDATE_DATE, t0.UPDATE_USER_ID, t0.CATEGORY_ID, t0.TOPIC_ID FROM eip_t_msgboard_topic t0, eip_t_msgboard_category t1, eip_t_msgboard_category_map t2 WHERE t0.CATEGORY_ID = t1.CATEGORY_ID AND t1.CATEGORY_ID = t2.CATEGORY_ID AND ((t0.PARENT_ID = ?) AND (((t1.PUBLIC_FLAG = ?) AND ((t2.STATUS = ?) OR (t2.STATUS = ?))) OR ((t1.PUBLIC_FLAG = ?) AND (t2.USER_ID = ?))) AND (t0.TOPIC_ID IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?))) [bind: 0, 'T', 'O', 'A', 'F', 23, 6023, 6043, 5963, 5943, 5923, 5903, 5883, 5863, 5843, 5823, 5703, 5623, 5623, 5603, 5363, 5403, 5383, 5323, 5303, 5283, 5263, 5243, 5203, 5143, 5123, 5103, 5083, 5043, 4903, 4863, 4743, 4763, 4743, 4723, 4723, 4563, 4563, 3703, 4603, 623]

のようなクエリログの?を手作業で一つ一つ置き換えていくのは面倒です。

次のようなjavascriptで簡単に変換できます。

<html>
<head><title>Do</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<script language="JavaScript">
function doScript(val){

arr=val.split("[bind: ");

arr[1]=arr[1].substr( 0, arr[1].length-1 ) ;
bind = arr[1].split(",");

val2=arr[0];
for(b in bind){
  val2=val2.replace("?",bind[b]);
}


 document.getElementById('result').value =val2;
}
</script>

<form id="editor" action="/search" method="GET" onsubmit="doScript(this.val.value);return false;">
  <textarea name="val" > 置き換えたい文字</textarea>
  <input type="submit" value="DoScript">


<textarea id="result">出力</textarea>
</body></html>

ただし、bindする文字列に”,”を含むような場合は非対応です…