                Frequently Asked Questions about DBS
                ------------------------------------



Q: What is DBS?

A: The Psion Database Server...

   DBS is a Database server that runs on Psion machines and
   allows you to access dBase III and IV format files and
   Psion DBF files from both C and OPL programs.

   DBS is the replacement for ISAM.  ISAM is a set of
   routines that provided DBF file manipulation and indexing
   support.

Q: What Psion machines does DBS run on?

A: DBS runs on the Series 3, Series 3a, HC range and
   Workabout.

Q: Why does DBS support dBase format files?

A: dBase support was added to give better compatibility with
   other database systems...

   Although the dBase file format is not ideal for handheld
   machines, DBS supports it so that data can be used
   directly from PC based applications without having to be
   first translated into Psion DBF format.

Q: Where are the DBS files found on the Psion machine?

A: All DBS files go in a \DBS directory in the root of one of
   the devices on the machine.

   The client APIs look for the DBS files in the \DBS
   directory on each device on the machine when they try to
   connect to the DBS server.  There are C and OPL example
   routines included within the release (CHECKVER.C and
   CHECKVER.OPL) which will check for any existing version of
   the server and inform the caller whether or not a new
   version needs installing.

Q: Does DBS have any advantages over using ISAM apart from
   the dBase compatibility

A: Yes, but it also has some omissions...

   DBS is a database server (a separate process on the
   Psion), with full multi-client support, including
   simultaneous access to the same data and index files,
   which ISAM does not provide.  DBS has extended the
   original ISAM functionality by adding:

       database level support
       index tracking
       multiple record buffers on the same table, with record-
        locking during editing
       DynaViews, which give a filtered and/or sorted view of
        records in a table.
       Extra field flags
       Three new field types:
            Date, Logical and LongBinary (LongBinary not currently
            supported by Psion DBF)

   DBS also uses some text based expressions to specify
   filters and sorting.

   DBS cannot read index files written by ISAM.

Q: Is DBS faster or slower than ISAM?

A: That depends...

   Because DBS is a separate process, each function call has
   the overhead of an inter-process message, but DBS is
   mostly faster (particularly at indexing) than ISAM.
   However, field data access is slower using DBS than ISAM.

   dBase uses a text based fixed-width format for all its
   field types, this makes the data access slower than DBF
   field access.  Because of other overheads, this is most
   noticeable when indexing a table, when using dBase format
   files can be 2-3 times slower than using the Psion DBF
   format files.

Q: Are the "logical" and "date" types new fieldtypes or are
   they just converted to bytes and longs?

A: Yes they are converted...

   Date is passed as a P_DAYSEC structure. dBase only stores
   the date part of this, Psion DBF stores the whole of it.

   Logical is passed as a WORD, zero is taken as False, any
   other value as True.

Q: How much of the Psion resources does DBS use?

A: Psion/dBase comparisons

   dBase data files tend to be 2-3 times bigger than an
   equivalent Psion DBF data file.  dBase indexes can also be
   up to 2 times larger than Psion ones (depends very much on
   the sorting key).

A: Runtime memory requirements

   DBS requires at least four files totalling 36K on the
   Psion computer (for just Psion DBF support), and uses most
   of that when running. Adding dBase requires an extra 19K.
   In comparison the original ISAM is only 12K.

   However, using DBS means there is almost no overhead in
   the client's data segment, as the index cache and record
   buffers are all stored in the server's data space.

A: Server memory usage

   A small amount of memory is used for the connection and
   database objects.

   Opening tables builds the table definition in the server's
   space, so this can be significant for tables with large
   numbers of fields, but is generally fairly small.

   Record Views have their own record buffer, the size of
   which depends on the record size in the table.

   DynaViews also maintain an array of record keys, which can
   contain from 0 to 128K entries, each record in the set
   requires 4 bytes, arrays over a certain size are stored in
   far memory. A Clone of a DynaView uses the same key array,
   but has it's own record buffer.

   Creating a sorted DynaView requires enough disk space for
   a temporary index to be created, this index is deleted
   before the Create function returns.

   Indexing uses a cache in the server's data space (as did
   ISAM v1), but this is freed when no indexes are open.

A: Psion DBF data file sizes

   DBF table files have no change in size under DBS.

   DBS explicitly sets the ISAM_FLAG_MINIMIZE flag for all
   indexes as this has a small speed disadvantage for smaller
   indexes and a significant advantage for large ones (as the
   index is smaller), apart from the size advantage.
   This affects the index size calculation:

       Worst case is still 50% usage
        => 2*(no_records)*(length of key+6)
       but on average the index will be 75-90% full
        => ~1.25*(no of records)*(length of key+6)

Q: How compatible is DBS with reading older DBF files

A: Fairly compatible...

   Currently DBS does not support LongBinary in Psion DBF
   files.

   Any DBF file created using OPL or the Data app can be read
   by DBS.  Labels from Data are read as Field names by DBS.
   OPL has a limit of 32 fields when creating a table, but is
   able to open existing tables with more fields without any
   problems.

   ISAM indexes cannot be read by DBS, nor the other way
   round.

   DBF files created by DBS:

   As long as all the fields are String fields and the field
   flags are not used, the Data app can read the file, and
   will correctly find the labels.

   Restricted to String, Int16, Int32 and Double fields with
   no field flags, OPL and ISAM can read the file. Field
   names are ignored.

   Using Date, Logical, LongBinary, Int8, Uint8, Uint16 or
   Uint32 field types, or either the NoUpdate or NotNull
   field flags will make the file unreadable to Data, OPL and
   ISAM.

   The low level PLIB DBF file functions should be able to
   read files produced by DBS fine, as it is up to the
   programmer to interpret the FIR and the other records
   themselves. The header file type is as for OPL data files.

Q: Does PsiWin support conversions of any of the DBS files

A: Not currently...

   The PsiWin DBF converter can only handle a 32 string field
   DBF file, i.e. one generated by the Data app, or if you're
   very specific with OPL or ISAM.  PsiWin does not recognise
   any of the index files produced by either DBS or ISAM.

Q: How do you pass a table definition with more than one field
   into DbsTableCreate()?

A: By adding extra elements to the DBS_TABLEDEF structure:

   The DBS_TABLEDEF structure defined uses a C-coding practice
   which allows the number of real DBS_FIELDDEF*'s passed to
   be determined by the code which calls DbsTableCreate. If the
   structure was defined for the largest possible table (about
   4000 fields) it would usually waste a vast amount of data
   space, so it is defined for just one.
   
   Usually you would define your own structure which contains
   DBS_TABLEDEF for your actual definition, or you would use a
   DBS_TABLEDEF*, ensuring that there is enough space for the
   full definition at that location. Here are two examples which
   show these two methods:

   1) Staticly allocated definition:

   #define FIELD_COUNT 10
   
   /* Define a structure for a table definition with FIELD_COUNT  *
    * fields. The DBS_TABLEDEF is the head of the structure, and  *
    * the remaining DBS_FIELDDEF*'s follow immediately            */

   typedef struct
        {
        DBS_TABLEDEF def;
        DBS_FIELDDEF *f[FIELD_COUNT-1];
        } MY_TABLEDEF;

   DBS_DBASE DataBase;
   DBS_TABLE Table;
   DBS_FIELDDEF Field[FIELD_COUNT];
   MY_TABLEDEF TableDef;

   int CreateTable()
       {
       int ii;

   /* Setup field definitions */
       .....

       TableDef.def.count=FIELD_COUNT;
       for (ii=0;ii<FIELD_COUNT;++ii)
           TableDef.def.field[i]=&Field[ii];
       return DbsTableCreate(DataBase,&Table,"Example",
                              0,&TableDef.def);
       }


   2) Dynamic definition

   DBS_DBASE DataBase;
   DBS_TABLE Table;

   int CreateTable(int count,DBS_FIELDDEF fields[])

   /* count is the number of fields                         *
    * assume that the field definitions have been set up    *
    * and are passed in as an array in fields               */

       {
       int ii,err;
       DBS_TABLEDEF *pDef;

   /* allocate enough space for count fields in the
      table definition */

       pDef=p_alloc(sizeof(DBS_TABLEDEF) +
                     (count-1)*sizeof(DBS_FIELDDEF*));
       if (!pDef)
           return E_GEN_NOMEMORY;
       pDef->count=count;
       for (ii=0;ii<count;++ii)
           pDef->field[i]=&fields[ii];
       err=DbsTableCreate(DataBase,&Table,"Example2",0,pDef);
   
   /* we are finished with the definition */
       p_free(pDef);	
       return err;
       }


Q: I can't seem to get DbsTblViewSeek() to find a String field on
   an index.

A: The string data has to be passed with a leading byte count:

   The data for the Seek function requires data for a String field
   as a leading byte counted string, not as a (normal) zero-terminated
   string. In the LBC string, the first byte of data is expected to
   be the length of the string, not including the byte count itself.
   No terminating character is required.

   e.g. an LBC version of the string "fred" could be defined:
   
   char LBC_fred[] = {4,'f','r','e','d'};

   And a simple function to seek using an original zero-terminated
   string could be written as:

   int SeekForZTS(DBS_VIEW *tView,TEXT *str)
       {
       DBS_SEEKDATA seek;
       char buffer[64];
       int len;

       len=p_slen(str);
       buffer[0]=len;
       p_bcpy(&buffer[1],str,len);
       seek.keycount=1;
       seek.seekdata[0]=&buffer[0];
       return DbsTblViewSeek(tView,DBS_COMP_GREATEQ,&seekdata);
       }


[ DBS_FAQ.TXT    Version 1.10    March 1996 ]

