Deutsch English
Home
About tdbengine
Newsletter
Download
Helpware
Forum
Chat
Documentation
Installation
Configuration
First Steps
Runtime Switches
Text files
System functions
Database functions
Index functions
Full-text Indexing
Memos and BLOBs
Semaphore concept
Error codes
Hints for PHP developers
Basic Course
Function reference
HOWTO...?
Projects
Links
Benchmarks
Bug Reporting
Support request
 
Home    Overview    Search    Impressum    Contact    Members
Memo and BLOB Functions
Both memos and BLOBs are stored in its own physical files. In the related table only a pointer is put to the corresponding entry in the specified memo or BLOB file. A memo field stores a however large text, a BLOB field (BLOB = Binary Large OBject) - any binary data.

Filling memos
Memo fields are set by reading in a text file (external or internal).

ReadMemo(db,'MemoField',Path_to_TextFile)

With the help of an optional parameter it can be determined, if an existing memo is replaced or supplemented with the text file by the call of the function:

ReadMemo(db,'MemoField',Path_to_TextFile,0)

Text is attached to existing memo

ReadMemo(db,'MemoField', Path_to_TextFile,1)

Text replaces existing memo

The default value for the insert mode is 0.

A next parameter determines, if the external text is represented in ANSI or in ASCII character set:

0 (default value) ANSI character set
1 ASCII character set

Example:

ReadMemo(db,'MemoField',Path_to_TextFile,1,1)

The external text file is represented in ASCII character set and replaces the previous memo

ReadMemo(db,'MemoField',Path_to_TextFile,0,1)

The external text file is represented in ASCII character set and is attached to the previous memo

Important note :

The function operates always with the actual (also lastly read or written) record. A complete operation is always performed including also the write-back of the current record. Therefore a final WriteRec() is not necessary.

Example:

ReadRec(db,10000)
ReadMemo(db,'Note,'texts/new text.txt',1)
// none of writerec!

ReadMemo() returns 0, if everything is alright, otherwise the error code is generated.

Determing the size of a memo
The current size (in bytes) of a memo is determined by the function MemoLen():

MemoLen(dn,'MemoField') -> The number of all characters of the related text.

Filling memos from HTML form
Memos are normally entered in HTML forms through a TEXTAREA tag. The textarea must have a name, which begins with "text:"

<textarea name="text:Note" ...

The form with the Textarea must use the method "POST". Then a ramtext is automatically created by the execution of the corresponding program, which contains the contents of the textarea in ASCII character set. So if you wish to insert the textareas content into a memo, the following call is necessary:

ReadMemo(db,'Memo field','ramtext:text:Note',1,1)

Reading out a memo field
The function CopyMemo() is available as the analogue of ReadMemo(), by which the contents of a memo field is transferred to a (internal or external) text file.

CopyMemo(db,'MemoField',Path_to_TextFile)

There is also a next parameter, which determines the character set of the text file:

0 (predetermined value) -> ANSI character set
1 -> ASCII character set

As ReadMemo() does, CopyMemo() also operates with the current record.

Memos in templates
The function Subst() offers a highly convenient possibility for embedding memos in templates:

Subst(target,db,'MemoField',1)

.embeds the contents of the memo field as the target, and in doing so already a correct character conversion according to HTML is performed. This method is applied if the target defines the contents of a textarea, which also will be used to edit the memo.

Outside of textareas:

Subst(target,db,'MemoField',5)

. is chosen, then hard line breaks within the memo are replaced with '<br>'  thereby.

Advise : If you apply specific display tags (for example, <b>..</b>), you can also make effective them after HTML conversion:

WHILE subst('<b>','<b>') DO END
WHILE subst('</b>','<b>') DO END

Searching in memos
The searching can be carried out in memos by a sequential search with the operators HAS or LIKE as in string fields. Memo fields can be also put in a full-text index, what enables a very quick search.

Inserting BLOBs
As memos, so BLOBs are placed in its own file. In the table itself a pointer is set at the beginning. Notwithstanding two types of implementation are distinguished by BLOBs:

  • An external file is completely copied to the BLOB file (embedded)
  • A reference to the external file is stored only (link)

There is an function of its own for each case:

EmbedBlob(db,'BlobField',Path_to_File)

stores the whole file in the BLB file

LinkBlob(db,'BlobField', Path_to_File)

stores Path_to_File in the BLB file only

In both cases a type identifier for the external file can be transferred as optional parameter. Following type identifiers are predefined and must not be used for other file types:

1 : BMP or DIB
2 : PXC
3 : WAV
4 : WMF
5 : GIF
6 : JPG or JPEG

Example:

EmbedBLOB(db,'Picture','/pics/maria.jpg',6)

The function result of both functions is 0, if the operation was successful, otherwise the error code is returned.

If LinkBlob() is called without a file name, the function gives the actual stored path (reference).

Linked BLOBs are relatively uninteresting with the tdbengine, because a normal STRING field would be enough as a reference to an external file and the expenses are too high for an extra file. Furthermore the tdbengine does not notice when a reference indicates to empty place, while the related file was deleted, renamed or replaced in an other directory.

But embedded BLOBs are another matter, while a complete copy is available here, therefore the source file is not required any further.

Reading out BLOBs
The function CopyBlob() is available as the analogue of EmbedBlob:

CopyBlob(db,'BlobField',Path_to_File)

copies the contents of the BLOB field in an external file

There is available a special form of this function call, when the BLOB is copied in the file 'con':

CopyBLOB(db,'BlobField','con')

In this case the BLOB is given to the standard output (so directly to the CGI-client).

Two functions specify size and type identifier of the BLOBs:

BlobSize(db,'BlobField)

Size of the stored BLOBs in bytes

BlobType(db,'BlobField')

Type identifier of the BLOBs

Example:

VAR t : REAL
  ...
  IF t:=BLOBType(db,'Bild')=5
  THEN CGIWriteLn('content-type: image/gif')
  ELSIF t=6
  THEN CGIWriteLn('content-type: image/jpeg')
  ELSE
    // Error processing
  END
  CGIWriteLn('')
  CGICloseBuffer
  CopyBLOB(db,'Bild','con')
  ...

Tips - Tips - Tips
You should bind a value to neither memos nor BLOBs with SetField().

You can delete a BLOB field with SetField(db,'BlobField',''). Thereby the linked file is maintained the BLOB file, the reference is deleted only.

You must take care that none of further direct assignments are given to memo or BLOB fields except for this 0-assignment. Otherwise the whole management can be confused that the table is not more applicable.

A trap in the above said sense is contained in following program sample:

ReadRec(db,x); WriteRec(db,FileSize(x)+1)

A copy of the data block is put here, thereby the memo and BLOB references are also copied (what quickly leads to the catastrophe).

It would be correct as follows:

ReadRec(db,x); SetRecord(db,db); WriteRec(db,FileSize(x)+1)

Unfortunately it works in version 6.2.5 (and higher) of the tdbengine only.

If you have the feeling that something is wrong by memos or BLOBs (because, for example, the modifications in one memo field are also appeared unexpectedly in another), please restructure the table with the ddk. New memo or BLOB files are created thereby.



tdbengine Anwendungen im Web:

Open-Source Web CMS


Open-Source Bug-Tracking


Free wiki hosting

Open-Source Wiki-System

Kostenloses Foren-Hosting

Dišt mit tdbengine 8-)

tdbengine chat
irc.tdbengine.org
#tdbengine

   Copyright © 2003-2004 tdb Software Service GmbH
   Alle rechte vorbehalten. / All rights reserved
   Last changed: 06.05.2004


ranking-charts.de

Programmers Heaven - Where programmers go!