EXPORT ALL 1.0


A global procedure which exports (threaded) a complete database including information about field sizes, formats, etc.

© 1996 Phil Hudson. May be freely used and distributed. Comments and bug reports please to: Released 18 Nov 1996.

Externals required:


Warning:


Revision history:

1.0:
Initial release.
18 Oct 96.

  `TITLE: Procedure: EXPORT ALL
  `CREATED: 23/4/96, 11:27 pm

  `DESCRIPTION: Creates a desktop text file for each structure file in turn.
  `    Writes every field (except invisible boolean fields) of every record
  `    in each file to the corresponding desktop file.

  `PARAMETERS: None

  `RESULTS: None

  `EXTERNALS CALLED: ACI_Pack

  `PROCS CALLED: EXPORT FILE (new process)

  `CALLED BY: CRON (New process)

  `WARNINGS: Does not export pictures, subfiles or hidden booleans

  `Mods:
  `22/10/96: changed name from ExportAll to EXPORT ALL
  `                  changed ExportFld to EXPORT FIELD
  `5/11/96: threaded, created new proc EXPORT FILE

C_LONGINT($i;$numFiles;$procState)
C_STRING(255;<>path)
C_STRING(31;$path)
C_STRING(1;$cr; <>tab; <>apple1; <>ret; <>apple2)
C_BOOLEAN($allDone)

READ ONLY(*)

$numFiles:=Count files
$fileCount:=String($numFiles)

  `Initialise character variables
$cr:=Char(13)
<>ret:=$cr
<>tab:=Char(9)
<>apple1:=Char(16)  `substitute for tabs in text fields (solid apple)
<>apple2:=Char(20)  `substitute for returns in text fields (hollow apple)

  `Store the location of export files
GetDataName (<>path;$path)
If (<>path_<Length(<>path)>_#":")
  <>path:=( <>path+":")
End if 
<>path:=( <>path+"Export:")

ARRAY LONGINT($processes;$numFiles)

For ($i;1;$numFiles)
  
  $processes[Macro error: Can't compile this script because "$" is an illegal character.]
:=New process("EXPORT FILE";16000;String($i))
  
End for 

  `Monitor progress of export processes
Repeat 
  
  DELAY PROCESS(Current process;3600)  `wait a minute
  $allDone:=True
  
  For ($i;1;$numFiles)
    
    $procState:=Process state($processes[Macro error: Can't compile this script because "$" is an illegal character.]
)
    
    If (($procState#-1) & ($procState#-100))  `at least one export process is still running
      
      $allDone:=False
      $i:=($numFiles+1)  `exit loop
      
    End if 
    
  End for 
  
Until ($allDone=True)




  `Procedure: EXPORT FILE
  `CREATED BY:PDH,5/11/96,8:25 am
  `DESC: Thread for exporting all data in a file
  `PARAMS: (file number passed as name of process)
  `RESULTS: none
  `PROCS CALLED: EXPORT FIELD, IntToHexStr, EXPORT ERROR (ON ERR CALL)
  `EXTERNALS CALLED: ACI_Pack
  `GLOBALS:
  `FILES:
  `LAYOUTS:
  `OBJECTS:
  `CALLED BY:
  `SIDE EFFECTS:
  `LIMITS: Length(<>path) must be <= 255
  `WARNINGS: Does not export hidden Boolean fields (always unused dummy fields in
  `                  my systems).
  `Date    Programmer    Mod
  `---------------------------
  `1/11/96: PDH: created


C_LONGINT($numRecs;$bar;$k;$i;$j;$numFlds)
C_INTEGER($attrib;$typ;$relFile;$relFld;$procState;$procTime)
C_INTEGER($fldNum;$visFldCnt;$aSz;$len)
C_POINTER($filePtr;$fldPtr)
C_STRING(20;$fileName;$fldNam;$choiceLst;$processName)
C_BOOLEAN($lastFld)
C_STRING(255; <>path)
C_STRING(1;$colon)

PROCESS ATTRIBUTES(Current process;$processName;$procState;$procTime)  `get the process name
$i:=Num($processName)  `file number passed as process name

READ ONLY(*)  `no data modification in this process

$numFlds:=Count fields($i)  `how many fields per record in this file?


  `For each field, record the following info:

  `1. Field pointer
ARRAY POINTER($aFldPtr;$numFlds)
  `2. Field type
ARRAY INTEGER($aFldTyp;$numFlds)
  `3. Field size
ARRAY INTEGER($aFldLen;$numFlds)
  `4. Attributes (16 bit field)
ARRAY INTEGER($aFldAttrib;$numFlds)
  `5. Number of related file
ARRAY INTEGER($aRelFile;$numFlds)
  `6. Number of related field
ARRAY INTEGER($aRelFld;$numFlds)
  `7. Field name
ARRAY STRING(16;$aFldName;$numFlds)


  `From the full set of fields, select only those which are not
  `  invisible boolean fields (my standard for redundant fields)
  `  by storing an index into the full set for each required field.
  `IOW, Size of array($aVisFlds) must always be <= Size of array($aFldPtr)
ARRAY INTEGER($aVisFlds;0)

For ($j;1;$numFlds)
  
  $fldPtr:=Field($i;$j)
  
  FIELD ATTRIBUTES($fldPtr;$typ;$len)  `get type and size (if applicable) of each field
  
  $bar:=GetFieldInfos ($i;$j;$relFile;$relFld;$attrib;$choiceLst)  `other field info
  
  If (($typ#6) | (bitAND ($attrib;256)=0))  `no invisible boolean fields wanted (leave blank elements in arrays)
    
    $aFldPtr[Macro error: Can't compile this script because "$" is an illegal character.]
:=$fldPtr  `store a pointer to this field
    $aFldTyp[Macro error: Can't compile this script because "$" is an illegal character.]
:=$typ  `...its type...
    $aFldLen[Macro error: Can't compile this script because "$" is an illegal character.]
:=$len  `... its length...
    
    $fldNam:=Fieldname($fldPtr)
    $aFldName[Macro error: Can't compile this script because "$" is an illegal character.]
:=$fldNam  `...its name...
    
    $aRelFile[Macro error: Can't compile this script because "$" is an illegal character.]
:=$relFile
    $aRelFld[Macro error: Can't compile this script because "$" is an illegal character.]
:=$relFld
    $aFldAttrib[Macro error: Can't compile this script because "$" is an illegal character.]
:=$attrib  `...and its attributes.
    
      `Grow the array of exportable field indexes
    $aSz:=(Size of array($aVisFlds)+1)
    INSERT ELEMENT($aVisFlds;$aSz)
    $aVisFlds[Macro error: Can't compile this script because "$" is an illegal character.]
:=$j
    
  End if 
  
End for 

$visFldCnt:=Size of array($aVisFlds)

If ($visFldCnt>0)  `file contains data we need to export
  
    `Build the name for the disk export file
  $fileName:=String($i)
  $fileName:=(((3-Length($fileName))*"0")+$fileName)
  $fileName:=($fileName+Filename($i))
  
    `Open export file for writing
  vDoc:=Create document(<>path+$fileName;"TEXT")
  ON ERR CALL("EXPORT ERROR")
  
  If (OK=1)
    
    $colon:=Char(58)  `":"
    
      `Write descriptive header record
    For ($j;1;$visFldCnt)
      
      $fldNum:=$aVisFlds[Macro error: Can't compile this script because "$" is an illegal character.]

      
      $fldNam:=$aFldName[Macro error: Can't compile this script because "$" is an illegal character.]

      $attrib:=$aFldAttrib[Macro error: Can't compile this script because "$" is an illegal character.]

      $relFile:=$aRelFile[Macro error: Can't compile this script because "$" is an illegal character.]

      $relFld:=$aRelFld[Macro error: Can't compile this script because "$" is an illegal character.]

      $typ:=$aFldTyp[Macro error: Can't compile this script because "$" is an illegal character.]

      $len:=$aFldLen[Macro error: Can't compile this script because "$" is an illegal character.]

      
      $lastFld:=($j=$visFldCnt)
      
      SEND PACKET(vDoc;String($fldNum)+$colon+$fldNam+$colon+String($typ)+$colon+String($len)+$colon)
      SEND PACKET(vDoc;String($relFile)+$colon+String($relFld)+$colon+Int to hex str ($attrib))
      SEND PACKET(vDoc;Char(9+(Num($lastFld)*4)))
      
    End for 
    
      `Export all records in file
    $filePtr:=File($i)
    
    ALL RECORDS($filePtr>>)
    $numRecs:=Records in selection($filePtr>>)
    
    For ($k;1;$numRecs)
      
      GOTO SELECTED RECORD($filePtr>>;$k)
      
      For ($j;1;$visFldCnt)
        
        $fldNum:=$aVisFlds[Macro error: Can't compile this script because "$" is an illegal character.]

        
        $fldPtr:=$aFldPtr[Macro error: Can't compile this script because "$" is an illegal character.]

        $fldTyp:=$aFldTyp[Macro error: Can't compile this script because "$" is an illegal character.]

        
        $lastFld:=($j=$visFldCnt)
        
        EXPORT FIELD ($fldPtr;$fldTyp;$lastFld)
        
      End for 
      
    End for 
    
      `close export file
    CLOSE DOCUMENT(vDoc)
    ON ERR CALL("")
    
  End if 
  
End if 



  `TITLE: Procedure: ExportFld(pointer;int;boolean)
  `CREATED BY: Phil Hudson
  `CREATED: 19/8/96, 3:41 pm

  `DESCRIPTION: Writes a single field to a desktop text file followed by a
  `    delimiter (tab, or, if end of record, return).

  `PARAMETERS: $1: pointer to field
  `    $2: integer representing field type as per ACI_Pack GetFieldInfos
  `    $3: boolean indicating whether end of record (true) or not

  `RESULTS: None

  `PROCS CALLED: None

  `EXTERNALS CALLED: None
  `GLOBALS: vDoc
  `FIELDS: $1>>
  `CALLED BY: EXPORT FILE

  `SIDE EFFECTS: 

  `WARNINGS: A document must have been opened/created and its 
  `                 reference stored in vDoc

  `Mods:
  `22/10/96: Changed name from ExportFld to EXPORT FIELD
  `5/11/96: Replaced calls to Char(9) etc. with global chars

C_POINTER($1)  `field pointer
C_INTEGER($2)  `field type
C_BOOLEAN($3)  `last field in record?
C_STRING(1; <>tab; <>apple1; <>ret; <>apple2)

Case of 
    
  : (($2=0) | ($2=2))  `alpha or text
    SEND PACKET(vDoc;Replace string(Replace string($1»;<>tab; <>apple1); <>ret; <>apple2))
    
  : (($2=1) | ($2=4) | ($2=8) | ($2=9) | ($2=11))  `real, date, int, long, time
    SEND PACKET(vDoc;String($1>>))
    
  : ($2=6)  `boolean
    SEND PACKET(vDoc;String(Num($1>>);"True;;False"))
    
End case 

SEND PACKET(vDoc;Char(9+(Num($3)*4)))



  `Procedure: EXPORT ERROR
  `CREATED BY:PDH,18/10/96,10:43 am
  `DESC:
  `PARAMS:
  `RESULTS:
  `PROCS CALLED:
  `EXTERNALS CALLED:
  `GLOBALS:
  `FILES:
  `LAYOUTS:
  `OBJECTS:
  `CALLED BY:
  `SIDE EFFECTS:
  `LIMITS:
  `WARNINGS:
  `Date    Programmer    Mod
  `---------------------------
CLOSE DOCUMENT(vDoc)
ABORT



Top of page
Cool IT in Africa Site design by Phil Hudson. Comments? Email phil.hudson@iname.com.
Top of page