⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbiwriteblock.html

📁 Delphi API应用手册
💻 HTML
字号:
<HTML>
<HEAD>
<TITLE>BDE API Examples (DbiReadBlock, DbiWriteBlock, DbiSetFieldMap)</TITLE>
<META NAME="KEYWORDS" CONTENT="BDE, Borland">
<META NAME="DESCRIPTION" CONTENT="">
</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000000" ALINK="#999999" VLINK="#666666">

<CENTER>
<TABLE CELLPADDING="4" CELLSPACING="4" BORDER="0" WIDTH="600">

<TR>

<TD ALIGN="CENTER" VALIGN="TOP" COLSPAN="1"><NOBR><A HREF="/"><IMG SRC="/images/bolus.gif" ALT="[View Borland Home Page]" BORDER="0"></A><A HREF="/products.html"><IMG SRC="/images/products.gif" ALT="[View Product List]" BORDER="0"></A><A HREF="/searchsite/"><IMG SRC="/images/search.gif" ALT="[Search This Web Site]" BORDER="0"></A><A HREF="/download.html"><IMG SRC="/images/downloads.gif" ALT="[View Available Downloads]" BORDER="0"></A><A HREF="/membership.html"><IMG SRC="/images/membership.gif" ALT="[Join Borland Online]" BORDER="0"></A><A HREF="/newsgroups/"><IMG SRC="/images/newsgroups.gif" ALT="[Enter Discussion Area]" BORDER="0"></A><A HREF="/feedback/"><IMG SRC="/images/feedback.gif" ALT="[Send Email To Webmaster]" BORDER="0"></A></NOBR></TD>
</TR>

<TR>

<TR><TD ALIGN="LEFT" VALIGN="TOP" COLSPAN="1"><font size=2>

<h2>BDE API Examples (DbiReadBlock, DbiWriteBlock, DbiSetFieldMap)</h2>

(DbiReadBlock)Reads a specified number of records (starting from the next position of the cursor) into a buffer.<BR>
(DbiSetFieldMap)Sets a field map of the table associated with the given cursor.<BR>
(DbiWriteBlock)Writes a block of records to the table associated with the cursor.<BR>

<hr size=2 noshade>

<h3>Move data from one table to another table with a different structure in the fastest way possible.</H3>

 This example uses the following input:<BR> <I>MoveFast(STable, DTable, [2, 3, 5], [4, 1, 7], 1024000);</I><BR>
NOTE: This procedure will take two tables of the same type and move data between the two even if they have
a different structure.  The above input example maps source table fields 2, 3 and 5 to 4, 1 and 7 respectively.
The matching fields must be of same type and size because no field level translation is being done. Changing the 
BlockSize parameter can have an effect of speed.  If you are moving massive amounts of data and have plenty of
RAM in the machine, experiment with increasing the BlockSize parameter.

<PRE>procedure MoveFast(SourceTable, DestTable: TTable; const SourceMap,
             DestMap: array of word; BlockSize: longint);
var
  pRecBuffs: pBYTE;
  TotalSize, Records, RecordsToRead, RecordsProcessed: longint;
  pSMapFields, pSFields, pDMapFields, pDFields, pD, pS: pFLDDesc;
  MapFieldCount, B: byte;
  Props: CURProps;


begin
  if sizeof(SourceMap) <> sizeof(DestMap) then
    raise EDatabaseError.Create('Source and destination field mappings must be same in size');

  pRecBuffs := nil;  pSFields := nil; pSMapFields := nil;
  pDFields := nil; pDMapFields := nil; RecordsProcessed := 0;
  try
    Check(DbiSetToBegin(SourceTable.Handle));

    MapFieldCount := sizeof(SourceMap) div sizeof(WORD);
    pSMapFields := AllocMem(MapFieldCount * sizeof(FLDDesc));

    pSFields := AllocMem(SourceTable.FieldCount * sizeof(FLDDesc));
    Check(DbiGetFieldDescs(SourceTable.Handle, pSFields));
    // Create the source field mappings...
    for B := 0 to MapFieldCount - 1 do
    begin
      Inc(pSFields, SourceMap[B] - 1);
      Move(pSFields^, pSMapFields^, sizeof(FLDDesc));
      Inc(pSMapFields);
      Dec(pSFields, SourceMap[B] - 1);
    end;
    Dec(pSMapFields, MapFieldCount);

    pDMapFields := AllocMem(MapFieldCount * sizeof(FLDDesc));

    pDFields := AllocMem(DestTable.FieldCount * sizeof(FLDDesc));
    Check(DbiGetFieldDescs(DestTable.Handle, pDFields));
    // Create the destination field mappings...
    for B := 0 to MapFieldCount - 1 do
    begin
      Inc(pDFields, DestMap[B] - 1);
      Move(pDFields^, pDMapFields^, sizeof(FLDDesc));
      Inc(pDMapFields);
      Dec(pDFields, DestMap[B] - 1);
    end;
    Dec(pDMapFields, MapFieldCount);
    // Check all fields to make sure they are comparable types and sizes...
    pS := pSMapFields;
    pD := pDMapFields;
    for B := 1 to MapFieldCount do
    begin
      if pS^.iFldType <> pD^.iFldType then
         raise EDatabaseError.Create('Source field: ' + pS^.szName + ' Type (' +
            IntToStr(pS^.iFldType) + ') is not the same base type as the ' +
            'destination field: ' + pD^.szName + ' Type (' +
            IntToStr(pD^.iFldType) + ')');
      if (pS^.iUnits1 <> pD^.iUnits1) or  (pS^.iUnits1 <> pD^.iUnits1) then
         raise EDatabaseError.Create('Source field size: ' + pS^.szName + ' Size (' +
            IntToStr(pS^.iUnits1) + ', ' + IntToStr(pS^.iUnits1) +
            ') is not the same base type as the destination size: ' + pD^.szName + ' Size (' +
            IntToStr(pD^.iUnits1) + ', ' + IntToStr(pD^.iUnits1) + ')');
      Inc(pS);
      Inc(pD);
    end;
    // Set the field maps on the tables...
    Check(DbiSetFieldMap(SourceTable.Handle, MapFieldCount, pSMapFields));
    Check(DbiSetFieldMap(DestTable.Handle, MapFieldCount, pDMapFields));

    Check(DbiGetCursorProps(DestTable.Handle, Props));

    // Determine the amount of records that can be move in the block size given...
    Check(DbiGetRecordCount(SourceTable.Handle, Records));
    TotalSize := Props.iRecBufSize * Records;
    if TotalSize < BlockSize then
      BlockSize := TotalSize;
    RecordsToRead := BlockSize div Props.iRecBufSize;
    pRecBuffs := AllocMem(BlockSize * sizeof(BYTE));
    // Read and write the data...
    while RecordsToRead > 0 do
    begin
      Check(DbiReadBlock(SourceTable.Handle, RecordsToRead, pRecBuffs));
      Check(DbiWriteBlock(DestTable.Handle, RecordsToRead, pRecBuffs));
      Inc(RecordsProcessed, RecordsToRead);
      if RecordsToRead > (Records - RecordsProcessed) then
        RecordsToRead := (Records - RecordsProcessed);
    end;

  finally
    if pRecBuffs <> nil then
      FreeMem(pRecBuffs);
    if pSFields <> nil then
      FreeMem(pSFields);
    if pSMapFields <> nil then
      FreeMem(pSMapFields);
    if pDFields <> nil then
      FreeMem(pDFields);
    if pDMapFields <> nil then
      FreeMem(pDMapFields);

    Check(DbiSetFieldMap(SourceTable.Handle, 0, pSFields));
    Check(DbiSetFieldMap(DestTable.Handle, 0, pDFields));    
  end;
end;</PRE>
<!-- SF, Feb 9th, 98 -->


<hr size=2 noshade>
<p>

<A HREF="/devsupport/bde/bdeapiex/index.html">Back to BDE API Reference Page</A>

</TD></TR>

<TR><TD ALIGN="LEFT" VALIGN="TOP" COLSPAN="1"><font size=2>


<HR SIZE="2" NOSHADE>

<FONT SIZE = 2><i><b>DISCLAIMER:</b> You have the right to use this technical information subject to 
the terms of  the No-Nonsense License Statement that you received with the Borland product to which 
this information pertains.</FONT></i></B>


</dl>
</td>

</TR>

<TR>

<!-- THIS IS THE BOTTOM COPYRIGHT & UPDATED MESSAGE -->

<TD ALIGN="CENTER" VALIGN="TOP" COLSPAN="3"><FONT SIZE="2"><A HREF="/copyright.html">Trademarks &amp; Copyright</A> &#169; 1998 Borland International, Inc.

<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM OLD BROWSERS

// THIS WILL WRITE OUT THE LAST MODIFIED DATE
// YOU DO NOT NEED TO CHANGE ANYTHING HERE

function makeArray(arraySize) {
     this.length = arraySize
     return this
}

monthNames = new makeArray(12)
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"

updated = new Date(document.lastModified)
theMonth = monthNames[updated.getMonth() + 1]
theDate = updated.getDate()
theYear = updated.getYear() + 1900

document.write("Last modified on " + theDate +  "-" + theMonth + "-" + theYear + ".")
// END HIDING -->
</SCRIPT></FONT></TD>
</TR>

</TABLE>
</CENTER>

</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -