🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.vdbase.data.sql
Article #1433

Re: TOO MANY NESTED DO/UDF

#1433
From: Joe Yuzamas
Date: Mon, 22 Dec 1997 00:00
136 lines
4806 bytes
Bowen

Fun you should ask. I did that late Friday. Posted below are two programs.
Program one creates a table of 1500 test records on drive C:. Program two
will read those records and process them just as the production program
does, except it uses a local table instead of a table on the server. The
error occurs at about record 550. You will also note at the bottom of the
outer loop a CLOSE ALL. This is necessary in order to re-capture memory
from the SQL. I have not been able to figure out how to keep SQL (SELECT
command) from eating memory in a loop such as this, except to close the
database. Even here you will notice there is no database specified, but if
you comment out the CLOSE ALL, you will get a out of memory error. Hope
some of these things have been fixed in 7.0, but have not had time to test
yet. Any help will be appreciated.


* Program 1
* Create test table

   CREATE TABLE "AMEND.DBF" ;
      (PRJ_NO		CHAR(8), ;
      AMEND_NO		CHAR(2), ;
      INT_AMOUNT	NUMERIC(14,2), ;
      AMOUNT		NUMERIC(14,2), ;
      INTENT		BOOLEAN)

   CREATE INDEX PRJ_NO ON "AMEND.DBF" (PRJ_NO)
   CREATE INDEX AMEND_NO ON "AMEND.DBF" (AMEND_NO)
   
   USE AMEND IN SELECT()
   SELECT AMEND
   FOR i = 1 TO 500
      cPrjNr = '97-00'+STR(i,3,0,'0')
      FOR j = 1 TO 3
         cAmNr = STR(j,2,0,'0')
         nAmt = 10.0
         lInt = .f.
         APPEND BLANK
         REPLACE PRJ_NO WITH cPrjNr
         REPLACE AMEND_NO WITH cAmNr
         REPLACE AMOUNT WITH nAmt
         REPLACE INTENT WITH lInt
      NEXT
   NEXT
   USE IN AMEND

*
* Program 2
* Program to progate Project Order Database
*
   LOCAL oPrjNr, oAm, oAmt, oIAmt, oInt
   
   oPrjNr = NEW ARRAY()
   FOR i = 1 TO 500
      cPrjNr = '97-00'+STR(i,3,0,'0')
      oPrjNr.Add(1)
      oPrjNr[oPrjNr.Size] = cPrjNr
   NEXT

   FOR i = 1 to oPrjNr.Size
      cPrjNr = oPrjNr[i]
      SELECT PRJ_NO,AMEND_NO,AMOUNT,INT_AMOUNT,INTENT ;
         FROM 'AMEND.DBF' ;
         WHERE PRJ_NO = :cPrjNr
      oAm = NEW ARRAY()
      oAmt = NEW ARRAY()
      oIAmt = NEW ARRAY()
      oInt = NEW ARRAY()
      DO WHILE .NOT. EMPTY(PRJ_NO)
         oAm.Add(1)
         oAmt.Add(1)
         oIAmt.Add(1)
         oInt.Add(1)
         oAm[oAm.Size] = AMEND_NO
         oAmt[oAmt.Size] = AMOUNT
         oIAmt[oIAmt.Size] = INT_AMOUNT
         oInt[oInt.Size] = INTENT
         SKIP
      ENDDO
      FOR j = oAm.Size to 1 step -1
         IF .NOT. oInt[j]
            nTotAmt = 0.0
            FOR k = j to 1 step -1
               IF .NOT. oInt[k]
                  nTotAmt = nTotAmt + oAmt[k]
               ENDIF
            NEXT
            oIAmt[j] = nTotAmt
         ENDIF
      NEXT
      FOR j = 1 TO oAm.Size
         IF .NOT. oInt[j]
            cAM = oAm[j]
            nAmt = oAmt[j]
            nIAmt = oIAmt[j]
            IF nAmt = 0.0 .AND. nIAmt <> 0.0	&& Make up for the fact
               UPDATE 'AMEND.DBF' SET INT_AMOUNT = :nIAmt ; && SQL will not
allow
                  WHERE PRJ_NO = :cPrjNr AND AMEND_NO = :cAM && a zero
update
            ELSEIF nAmt <> 0.0 .AND. nIAmt = 0.0
               UPDATE 'AMEND.DBF' SET AMOUNT = :nAmt ;
                  WHERE PRJ_NO = :cPrjNr AND AMEND_NO = :cAM
            ELSEIF nAmt <> 0.0 .AND. nIAmt <> 0.0
               UPDATE 'AMEND.DBF' SET AMOUNT = :nAmt, INT_AMOUNT = :nIAmt ;
                  WHERE PRJ_NO = :cPrjNr AND AMEND_NO = :cAM
            ENDIF
         ENDIF
      NEXT
      oAm = .f.
      oAmt = .f.
      oIAmt = .f.
      oInt = .f.
      CLOSE ALL		&& Because SQL will eat memory without it
   NEXT
   
 
-- 
Joe  < jyuzamas@wrdiss1.robins.af.mil or jyuzamas@sprynet.com >

Bowen Moursund <teamb@opto-pps.com> wrote in article
<67enmj$dqb7@forums.borland.com>...
> >The code presented was the actual code. The only part missing is the
> tables...
> 
> Well, without the tables the code can't be run <g>. You might include a
> routine that creates and populates the required tables, if you cannot
dupe
> the problem using /SAMPLES tables
> __
> Bowen Moursund (TeamB)
> bowen.NOSPAM@nerds.com
> http://www.mindspring.com/~bowenm/datatech.htm
> 
> 
Technical Details
Message-ID: <01bd0ee3$8a146780$1030f489@jyuzamas.robins.af.mil>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <01bd0afe$ef069980$1030f489@jyuzamas.robins.af.mil> <67bujb$cj78@forums.borland.com> <01bd0c89$7e952b80$1030f489@jyuzamas.robins.af.mil> <67enmj$dqb7@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: ff5a1,249488cfdabe46c3
X-Google-Attributes: gidff5a1,public
From: "Joe Yuzamas" <jyuzamas@wrdiss1.robins.af.mil>
Subject: Re: TOO MANY NESTED DO/UDF
Date: 1997/12/22
Message-ID: <01bd0ee3$8a146780$1030f489@jyuzamas.robins.af.mil>
X-Deja-AN: 309328005
References: <01bd0afe$ef069980$1030f489@jyuzamas.robins.af.mil> <67bujb$cj78@forums.borland.com> <01bd0c89$7e952b80$1030f489@jyuzamas.robins.af.mil> <67enmj$dqb7@forums.borland.com>
Organization: U.S. Air Force
Newsgroups: borland.public.vdbase.data.sql