home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION MEMOPACK (packlist)
- *****************************************************************
-
- * Removes unused memo data from a database DBT file
-
- * Copyright(c) 1991 - James Occhiogrosso
-
- #include "set.ch"
-
- LOCAL counter, old_delete, real_recs, ret_value
-
- PRIVATE temp_file
-
- ret_value = ''
-
- * Get a unique temporary database file name
- temp_file = TEMPFILE('DBF')
-
- * Strip its extension
- temp_file = SUBSTR(temp_file, 1, AT('.', temp_file) - 1)
-
- FOR counter = 1 TO LEN(packlist)
-
- * Make sure all files in passed array exist
- IF .NOT. FILE(packlist[counter] + '.DBF') .OR. .NOT. ;
- FILE(packlist[counter] + '.DBT')
- ret_value = '1 - ' + packlist[counter]
- EXIT
- ENDIF
-
- * Open database and get record count
- USE (packlist[counter])
- real_recs = LASTREC()
-
- * Save deleted setting and set deleted off.
- * (So that deleted records are copied)
- old_delete = SET(_SET_DELETED, .F.)
-
- * Copy to temporary file name and open it
- COPY TO &temp_file
- USE &temp_file
-
- * Restore original deleted setting
- SET(_SET_DELETED, old_delete)
-
- IF LASTREC() = real_recs
- * Copy succeeded if record count is same
- USE
- IF FILE(temp_file + '.DBT')
-
- * Erasing old files
- ERASE (packlist[counter] + '.dbf')
- ERASE (packlist[counter] + '.dbt')
-
- * Make sure they were erased
- IF ( FILE(packlist[counter]+'.DBF') .OR. ;
- FILE(packlist[counter]+'.DBT') )
- * If they are still present, we cannot rename
- ret_value = '2 - ' + packlist[counter]
- EXIT
- ENDIF
-
- * Rename temporary files to passed name
- RENAME (temp_file + '.DBF') TO ;
- (packlist[counter] + '.dbf')
- RENAME (temp_file + '.DBT') TO ;
- (packlist[counter] + '.dbt')
- ELSE
- * Temporary DBT file is missing
- ret_value = '3 - ' + packlist[counter]
- EXIT
- ENDIF
- ELSE
- * Database was copied incorrectly
- ret_value = '4 - ' + packlist[counter]
- EXIT
- ENDIF
- NEXT
- RETURN ret_value
-
-