Welcome Guest | My Membership | Login

Read and Writing Unix/Linux Files from D3

Downloads

Article

Reading and Writing to Unix/Linux files is pretty simple within MultiValue Database application This article talks about SUBROUTINE (Store procedures) that can be used to make your job easier. The routines included in this article have a few limitations that you need to be aware of, though. They will read the complete Unix/Linux Files into memory as a dynamic array. This is not a problem with small files, but if you are working with large file (3MB, 4MB, or 10MB), it can become a problem. If you need to work with large files, then you will need to read the file in chunks, which is another article all together.

Another limitation has to do with binary data or blobs. MultiValue Database are designed to handle business data for storage, processing, reporting, mining, as well as other business tasks. Since binary data is unstructured and is generally stored in the OS File System, not the database, MultiValue SUBROUTINES (stored procedures) don't handle them well. If you want to know how to work with and store binary data within a MultiValue database, the please see the articles relating to Binary/Blob data.

The following program will show you how to use the SUBROUTINEs provided in this article to access Unix/Linux files.

* Example
FILE.NAME = "temp.txt"
CALL IS.READ.OS("/temp",TEMP.ITEM,FILE.NAME,ERROR.ITEM)
IF ERROR.ITEM<1> > 0 THEN CRT "Error Reading ": FILE.NAME
*
CRT TEMP.ITEM
END

This TCL (Console) program will return an output similar to:

:!cat "testing temp.txt" > /temp/temp.txt
:!cat "Line 2 of temp.txt" > /temp/temp.txt
:!cat /temp/temp.txt
Testing temp.txt.
Line 2 of Temp.txt
:EXAMPLE
Testing temp.txt.^Line 2 of Temp.txt
:

Something to Note, the CRLF are changed into AM marks (char 254). This allows you to access the information using standard dynamic array commands, include INSERT, DELETE, REPLACE, and LOCATE.

When you need to write to an OS file, it is just as simple as when reading.

* Example
FILE.NAME = "temp.txt"
CALL IS.READ.OS("/temp",TEMP.ITEM,FILE.NAME,ERROR.ITEM)
IF ERROR.ITEM<1> > 0 THEN CRT "Error Reading ": FILE.NAME
*
CRT TEMP.ITEM
*
TEMP.ITEM<3> = "Line 3 ": TIMEDATE()
CALL IS.WRITE.OS("/temp",TEMP.ITEM.FILE.NAME,ERROR.ITEM)
END

This will add a 3rd line to the /temp/temp.txt file. Using the 'cat' command you can see the results:

:!cat /temp/temp.txt
Testing temp.txt.
Line 2 of Temp.txt
Line 3 15:45:19  08 Jun 2011

The command line above is using Unix/Linux syntax for creating the /temp/temp.txt file, but you can do the similar things using windows. Here is an example using Windows Syntax:

* Example
FILE.NAME = "temp.txt"
CALL IS.READ.OS("c:\temp",TEMP.ITEM,FILE.NAME,ERROR.ITEM)
IF ERROR.ITEM<1> > 0 THEN CRT "Error Reading ": FILE.NAME
*
CRT TEMP.ITEM
END

 

# # #          # # #          # # #

 

Related Articles


Return to top