批处理OSQL命令,如何将多个块插入记录

时间:2023-01-25 02:06:47

Im using OSQL (SQL Server 2000) and have a batch file that chunks up an html source into 8xxx bytes of data. how can i get the chunks back into an sql record? here are the details:

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

batch file for osql statement:

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

all of the variables BUT %Body_Html% fit in the 8k stack, but the data for %body_html% is larger than 8k (up to 50k) so it has to be "chunked" down to fit in the stack. below is just part of the chunk routine for you to review (many thanks to jeb and dbenham for this):

所有变量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

so how can i merge my chunk routine with my osql routine? i know that i will probably have to nest some FOR loops, but cant think of a way to do this based on above parameters.

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

and Chunk, can be found here: http://www.oldskool.org/pc/chunk

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

edit: so it would seem that maybe i need to think the logic a different way in the osql loop, how could i 1) read mulitple variables or 2) read a file, as variable %body_html% into the oqsl results file (sqloutput.rpt)

编辑:所以似乎我可能需要在osql循环中以不同的方式思考逻辑,我怎么能1)读取多个变量或2)读取文件,作为变量%body_html%进入oqsl结果文件(sqloutput。 RPT)

should i break up the echo statements like this:

我应该打破这样的echo语句:

    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

now i think that might work, though it is not pretty. will post my results later.

现在我认为这可能有用,虽然它不漂亮。将在稍后发布我的结果。

1 个解决方案

#1


0  

so this inded (the logic) worked as far as generating the sql file with the entire html inserted into the tempsql file. if anyone is interested, i will post the code.

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

#1


0  

so this inded (the logic) worked as far as generating the sql file with the entire html inserted into the tempsql file. if anyone is interested, i will post the code.

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