标题: sql log解析,实现了一部分
[打印本页]
作者: leeinneu
时间: 2008-4-9 23:19
标题: sql log解析,实现了一部分
刚刚开始学习批处理,想把一段sql log解析为可执行的sql。
sql log如下:
DEBUG [X-XXXX.class] @ XXX - Checked out connection 256294 from pool.
DEBUG [X-XXXX.class] @ XXX - {conn-100006} Connection
DEBUG [X-XXXX.class] @ XXX - {conn-100006} Preparing Statement: SELECT * FROM leeinneu WHERE NAME= ? ORDER BY NAME
DEBUG [X-XXXX.class] @ XXX - {pstm-100007} Executing Statement: SELECT * FROM leeinneu WHERE NAME= ? ORDER BY NAME
DEBUG [X-XXXX.class] @ XXX - {pstm-100007} Parameters: leeinneu
DEBUG [X-XXXX.class] @ XXX - {pstm-100007} Types: [java.lang.String]
DEBUG [X-XXXX.class] @ XXX - {rset-100008} ResultSet
DEBUG [X-XXXX.class] @ XXX - {rset-100008} Header: [name]
DEBUG [X-XXXX.class] @ XXX - {rset-100008} Result: [leeinneu]
DEBUG [X-XXXX.class] @ XXX - {rset-100008} Result: [leeinneu]
DEBUG [X-XXXX.class] @ XXX - Returned connection 256294 to pool.
想解析成下面的格式:
Executing Statement:
----------------------------------------------------
SELECT
*
FROM
leeinneu
WHERE
name = leeinneu
ORDER BY
name
----------------------------------------------------
Result: XXXXXXXXXX, leeinneu
----------------------------------------------------
用java实现了,但是想用批处理来实现,另外上面的log信息可能很多,经常有几十k的。自己编了一小段,只能分离出执行,参数,和结果的,但是接下来的参替换等还不知道怎么开始,欢迎大家多多指点。先把自己写的一点点贴出来,刚刚开始,一些技巧和规范都不知道,相信你的一点小提示会给很大的帮助,先谢了:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set cnstExcu="Executing Statement:"
set cnstPara="Parameters:"
set cnstRslt="Result:"
set varExcu="varExcu"
set varPara="varPara"
set varRslt="varRslt"
call :select %cnstExcu% %varExcu%
call :select %cnstPara% %varPara%
call :select %cnstRslt% %varRslt%
echo !varExcu!>>sqlbat.txt
set varFmtPara="varFmtPara"
call :formatPara !varPara! %varFmtPara%
echo !varFmtPara!>>sqlbat.txt
echo !varRslt!>>sqlbat.txt
pause
goto :eof
:select
echo start
for /f "tokens=2 delims=:" %%i in ('findstr /i /c:%1 lee.txt') do set %~2=%%i
goto :eof
:formatPara
set pathbak=
set pathbak=%path%
set path=%1
set formatPara=%path:[= %
set path=!formatPara!
set formatPara=%path:]= %
path=%pathbak%
set %~2=!formatPara!
goto :eof
[
Last edited by leeinneu on 2008-4-9 at 11:20 PM ]