首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >foxpro光标大小

foxpro光标大小
EN

Stack Overflow用户
提问于 2010-01-22 22:43:33
回答 3查看 7.5K关注 0票数 4

这似乎是一个很简单的问题,但我似乎找不到任何解决方案。我和我的同事正在开发一个利用Foxpro xml转储工具的应用程序。它工作得很好,但我们希望根据一些大小限制将表拆分为多个文件。

这看起来应该是最简单的部分:如何在Foxpro中找到光标的大小?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-01-22 23:02:08

如果您指的是文件大小,则可以通过调用DBF()函数并将光标作为别名,检查返回值扩展名是否为.dbf,然后使用文件函数读取文件大小来查找与光标相关的文件。游标可能在内存中(如果我没记错的话,报告的'filename‘将有一个.tmp扩展名),所以另一种方法是使用RECCOUNT() (获取行数)和AFIELDS() (获取每行的大小)来近似文件大小。(通过在生成查询中包含一个NOFILTER子句,有时可以将内存中的游标强制到磁盘上)

票数 1
EN

Stack Overflow用户

发布于 2010-01-23 11:19:59

RECSIZE()将返回单个行的长度(以字节为单位) --乘以RECCOUNT()提供的大小。已经讨论的所有元素都是准确的。

对于备注字段,如果需要知道它们有多大,可能需要在表结构中为"MemoLength“添加一个新的整型列。然后

将所有memoLength替换为len( alltrim( YourMemoField ))

然后,您可以使用MemoLength来帮助确定细目组,方法是将此列大小与要提取的RECSIZE() *行一起考虑。

此外,您可能希望基于可用作链接的表主键列运行查询,并执行以下操作...

select YourPrimaryKey,len( alltrim( YourMemoField )) as MemoLength from YourTable into cursor SomeHoldingCursor readwrite

。。或者,选择

到表MemSizeTable中

在MemSizeTable上建立索引,您可以使用连接来获取更多信息。这样,它不会扭曲您的原始记录大小,也不会破坏您的原始表结构,但是使用关系,您仍然可以提取所需的元素。

票数 2
EN

Stack Overflow用户

发布于 2010-01-28 23:51:32

这是一个基于示例游标和伪造记录的全功能...关键函数是DumpXML()例程,它需要要转储的文件的别名、要将其限制为最大值的每个文件的大小(以"k“为单位),以及要将XML转储为的文件名前缀。它将自动生成一个排序ex: MyXMLOutput1.xml、MyXMLOutput2.xml、MyXMLOutput3.xml等。我花了大约15分钟。

代码语言:javascript
复制
CREATE CURSOR SomeTest ;
    (   SomeField1      c(10),;
        AnotherField    i,;
        SomeNumber      N(8,2),;
        MemoFld         m,;
        SomeDateTime    t;
    )

INSERT INTO SomeTest VALUES ( "testchar10", 9403, 12345.78, "some memo value string", DATETIME() )


DumpXML( ALIAS(), 300, "MyXML" )


FUNCTION dumpXML
LPARAMETERS cAliasName, nSizeLimit, cNameOfXMLOutput
    IF NOT USED( cAliasName )
        RETURN ""
    ENDIF 

    */ Assume size limit in "k"
    nSizeLimit  = nSizeLimit * 1024

    SELECT ( cAliasName )

    */ Get a copy of the structure without disrupting original
    USE IN SELECT( "MySample" )  && pre-close in case left open from prior cycle
    SELECT * ;
        FROM ( cAliasName ) ;
        WHERE RECNO() = 1;
        INTO CURSOR MySample READWRITE

    SELECT MySample
    */ Populate each field with maximum capacities... typically
    */ critical for your char based fields
    AFIELDS( aActualStru )
    cMemoFields = ""
    lHasMemoFields = .f.
    FOR I = 1 TO FCOUNT()
        cFieldName = FIELD(I)
        DO CASE 
        CASE aActualStru[i,2] = "C"
            replace &cFieldName WITH REPLICATE( "X", aActualStru[i,3] )

        CASE aActualStru[i,2] = "L"
            replace &cFieldName WITH .T.

        CASE aActualStru[i,2] = "D"
            replace &cFieldName WITH DATE()

        CASE aActualStru[i,2] = "T"
            replace &cFieldName WITH DATETIME()

        CASE aActualStru[i,2] = "M"
            */ Default memo as a single character to ensure
            */ closing field name </endoffield> included in XML
            replace &cFieldName WITH "X"

            */ if a MEMO field, add this element to a string 
            */ to be macro'd to detect its size... Each record
            */ can contain MORE than one memo field...
            */ Ex: + LEN( ALLTRIM( MemoFld ))
            lHasMemoFields = .T.
            cMemoFields = cMemoFields + " + len( ALLTRIM( " + cFieldName + " ))"

        CASE aActualStru[i,2] = "I"
            */ Integer, force to just 10 1's
            replace &cFieldName WITH 1111111111


        CASE aActualStru[i,2] = "N"
            */ Actual numeric and not an integer, double or float
            */ Allow for full length plus decimal positions
            NumValue = VAL( REPLICATE( "9", aActualStru[i,3] - aActualStru[i,4] - 1 );
                            + "." + REPLICATE( "9", aActualStru[i,4] ))
            replace &cFieldName WITH NumValue

        ENDCASE     
    ENDFOR 

    */ Strip leading " + " from the string in case multiple fields
    IF lHasMemoFields
        cMemoFields = SUBSTR( cMemoFields, 3 )
    ENDIF 

    cXML = ""
    LOCAL oXML as XMLAdapter

    oXML = CREATEOBJECT( "XMLAdapter" )
    oXML.AddTableSchema( "MySample" )
    oXML.ToXML( "cXML", "", .f. )

    */ Now, determine the size of the per record at its full length -- less memo        
    nSizeOfPerRecord = LEN( STREXTRACT( cXML, "<MySample>", "</MySample>", 1, 4 ))

    */ and the rest of the header per XML dump
    nSizeOfSchema = LEN( cXML ) - nSizeOfPerRecord


    */ Now, back to the production alias to be split
    SELECT( cAliasName )
    nNewSize = 0
    nXMLCycle = 0

    */ if we just started, or finished writing another block
    */ and need to generate a new group of XML dump reset size
    nNewSize = nSizeOfSchema

    */ Always blank out the temp cursor for each batch...
    SELECT MySample
    ZAP 

    SELECT ( cAliasName )
    SCAN 
        IF lHasMemoFields
            nAllMemoSizes = &cMemoFields
        ELSE 
            nAllMemoSizes = 0
        ENDIF 

        IF nNewSize + nSizeOfPerRecord + nAllMemoSizes > nSizeLimit
            */ The upcoming record will have exceeded capacity, finish XML
            */ with all records up to this point
            nXMLCycle = nXMLCycle + 1
            cNewFile = FULLPATH( cNameOfXMLOutput + ALLTRIM( STR( nXMLCycle )) + ".XML" )

            oXML = CREATEOBJECT( "XMLAdapter" )
            oXML.AddTableSchema( "MySample" )
            */ Generate the XML cycle of these qualified records...
            oXML.ToXML( cNewFile, "", .t. )

            */ restart for next pass of data
            nNewSize = nSizeOfSchema

            */ Always blank out the temp cursor for each batch...
            SELECT MySample
            ZAP 
        ENDIF 

        */ Add record to total size...
        nNewSize = nNewSize + nSizeOfPerRecord + nAllMemoSizes

        */ we have a record to be included in segment dump...
        */ scatter from the original table and gather into the temp
        SCATTER MEMO NAME oFromOriginal

        SELECT MySample
        APPEND BLANK
        GATHER MEMO NAME oFromOriginal

        */ back to original table driving the XML Dump process
        SELECT ( cAliasName )

    ENDSCAN 


    */ if the "MyTable" has records not yet flushed from limit, write that too
    IF RECCOUNT( "MySample" ) > 0
        */ The upcoming record will have exceeded capacity, finish XML
        */ with all records up to this point
        nXMLCycle = nXMLCycle + 1
        cNewFile = FULLPATH( cNameOfXMLOutput + ALLTRIM( STR( nXMLCycle )) + ".XML" )

        oXML = CREATEOBJECT( "XMLAdapter" )
        oXML.AddTableSchema( "MySample" )
        */ Generate the XML cycle of these qualified records...
        oXML.ToXML( cNewFile, "", .t. )
    ENDIF 

    */ Done with the "MySample" for cursor to XML analysis...
    USE IN SELECT( "MySample" )

ENDFUNC 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2117963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档