0

我使用 OSQL (SQL Server 2000) 并有一个批处理文件,它将 html 源分块为 8xxx 字节的数据。我怎样才能将块恢复到 sql 记录中?以下是详细信息:

osql 语句的批处理文件:

    echo use database;>tempsql.sql
    echo set indentity_insert tablename ON;>>tempsql.sql
    echo insert into tablename (ID, Name, Date, Body_HTML)>>tempsql.sql
    echo values ('%id%', '%name%', '%cdate%', '%body_html%');>>tempsql.sql
    echo set indentity_insert tablename OFF;>>tempsql.sql
    echo go>>tempsql.sql
    osql -U user -P pass -d database < tempsql.sql -o sqloutput.rpt

所有变量 BUT %Body_Html% 都适合 8k 堆栈,但 %body_html% 的数据大于 8k(最多 50k),因此必须将其“分块”以适合堆栈。下面只是块例程的一部分,供您查看(非常感谢 jeb 和 dbenham):

    @echo off
    set count=0
    setlocal EnableDelayedExpansion EnableExtensions
    for /f "tokens=*" %%a in ("newhtml.htm") do set FileSize=%%~za
    echo FileSize is %FileSize% bytes
    if %FileSize% GTR 8159 goto split
    rem skip regular insert routine, pick up at :split
    :split
        set count=0
set /a all_sub=%FileSize% / 8159
set /a all_rem=%FileSize% %% 8159
if %all_rem% NEQ 0 set /a all_ttl=%all_sub% + 1
echo %all_sub% full page(s), %all_rem% bytes(s) leftover, %all_ttl% total pages
chunk newhtml.htm basenam -s8159 -o
set count=0
     :: now get accurate file count of basenam.*
for /f "tokens=1*" %%a in ('dir basenam.* ^| find "File"') do (
    set setfiles=%%a
)
echo  %setfiles%>setfiles
set count=0
     ::now show where the break is
     echo Loop %count%
SETLOCAL DisableDelayedExpansion 
set "all="
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ basenam.00%count%"`) do (
    set "line=%%a"
    SETLOCAL EnableDelayedExpansion
    set "line=!line:#=#S!"
    set "line=!line:*:=!"
    for /F "delims=" %%p in ("!all!#L!line!") do (
        ENDLOCAL
        set "all=%%p"
    )
)
SETLOCAL EnableDelayedExpansion
if defined all (
set "all=!all:~2!"
set ^"all=!all:#L=^

!"
set "all=!all:#S=#!")
:: now display file in 8159 byte chunks, does emit a blank line in between
echo !all!
set /a count=!count! + 1
for /f "tokens=*" %%m in (setfiles) do set setfiles=%%m
if %count% EQU !setfiles! goto end
goto loop1
:end

那么如何将我的块例程与我的 osql 例程合并?我知道我可能不得不嵌套一些 FOR 循环,但我想不出基于上述参数的方法。

和块,可以在这里找到:http ://www.oldskool.org/pc/chunk

编辑:所以看起来我可能需要在 osql 循环中以不同的方式思考逻辑,我怎么能 1)读取多个变量或 2)读取文件,作为变量 %body_html% 到 oqsl 结果文件(sqloutput. rpt)

我应该像这样分解回声语句:

    echo use database;>tempsql.sql
    echo set indentity_insert tablename ON;>>tempsql.sql
    echo insert into tablename (ID, Name, Date, Body_HTML)>>tempsql.sql
    echo values ('%id%', '%name%', '%cdate%', '>>tempsql.sql
    rem  %body_html%
    rem put chunk routine here
    rem echo !All!>>tempsql.sql
    echo ';>>tempsql.sql
    echo set indentity_insert tablename OFF;>>tempsql.sql
    echo go>>tempsql.sql

现在我认为这可能会奏效,尽管它并不漂亮。稍后会发布我的结果。

4

1 回答 1

0

所以这个 inded(逻辑)在生成 sql 文件时起作用,并将整个 html 插入到 tempsql 文件中。如果有人有兴趣,我会发布代码。

于 2012-05-18T21:53:12.930 回答