Accessing the Keytable

Before Dad 1.30 it was only possible to access the keytable on the server via calls to dadGetTabIf and dadWriteTab. As one also want to get and send the keytable on the record level and going towards dad random access file drivers the calls to dadDoConnect, dadOpenPipe and dadOpenFile had to be extended by an additional parameter to specify the keytable for the connection.

This new parameter Keytable must be specified when writing to a file or a pipe and the switch CAC_KEYTABLE is set. Further a keytable to be written together with a record (dadWrite) has to be in the window common block of the dad internal dataflow structure:

    int err;   /* error code */
    int dadh;  /* dad handle for the connection */

    /* open the dad connection - here a pipe */

    dadOpenPipe( &dadh, "dadtest.fifo", "Articles", "ArtKey", 1,
                 CAC_KEYTABLE|CAC_WRITE, &err);

    /* filling of several tables & the keytable */
    ...

    /* setting the keytable for the current record */

    dadFillRecordKey( dadh, &ArtKey, &err);

    /* writing the record to the pipe */

    dadWrite( dadh, &err);

On the readers side it looks simply like

    int err;   /* error code */
    int dadh;  /* dad handle for the connection */

    /* open the dad connection - here a pipe - we don't need CAC_KEYTABLE */

    dadOpenPipe( &dadh, "dadtest.fifo", "Articles", "", 1,
                 CAC_READ, &err);

    /* clear the keytable as new id's will be added */

    CLETAB( ArtKey);

    /* reading a record from the pipe */

    dadRead( dadh, &err);

    /* get the keytable content */

    dadGetRecordKey(dadh, &ArtKey, &err);

    /* Now we can print the new keytable entry after entering it to the TAP*/

    if( BELTAB( ArtKey ) )
      REPTAP(ArtKey);
    else
      INSTAB(ArtKey);

    PRITAB( ArtKey, ID, MINC, MAXC, ALLCOL);

This mechanism works also for server connections. Here you don't need to specify a keytable while opening a connection as the server tells the client about the keytable to use if CAC_KEYTABLE is set.

Be aware that server keytables are something the servers need to control their database with. Therefore the user cannot change access relevant fields change keytable entries of records the user is not connected to or add keytable entries. Access relevant fields are the time informations iStartTime and iEndTime as well as the dataflow name in the cName field.

From the server (we don't have a dadSnap for files, yet) you can also get the complete keytable. See the following example on how to get and modify it (semaphore setting omitted for simplicity):

     /* Open the connection */
     dadOpenDB( &Id, host, "Articles", port,
                 CAC_READ | CAC_WRITE | CAC_KEYTABLE, & err);

     /* error checking omitted for simplicity in the whole example*/

     /* get the whole keytable (no condition specified */

     dadGetTabIf( Id, TID_KEYTAB, 0, &err);

     /* set the physical record number for my connection to 2 */

     dadSetRecordId( Id, 2, &err);

     /* modify the local copy */

     FETTAB( ArtKey, ID, 2);
     /* */
     REPTAB( ArtKey, ID, 2);

     /* use a selector to write the modified row back */

     CRESEL( ArtKey, sel, "SelectorName");
     INSSEL( ArtKey, sel);

     dadWriteTab( Id, ArtKey.artKey, sel, CAF_REPLACE);

     /* attention: in reality don't drop selector to often. Adamo won't
        stand it */

     DROSEL( ArtKey, sel);
How to write records with keytable entries to a server?
     /* Open the connection */
     dadOpenDB( &Id, host, "Articles", port,
                 CAC_READ | CAC_WRITE | CAC_KEYTABLE, & err);

     /* error checking omitted for simplicity in the whole example*/

     /* create a new record on the server */

     dadNew( Id, & err);

     /* ... fill the record with some stuff here ... */

     dadWrite( Id, & err);

     /* get the whole keytable (no condition specified) */

     dadGetTabIf( Id, TID_KEYTAB, 0, &err);

     /* get the physical record number for this  connection */

     dadGetRecordId( Id, &recid, &err);

     /* modify the local copy */

     FETTAB( ArtKey, ID, recid);

     /* ... modify here ... */

     REPTAB( ArtKey, ID, recid);

     /* use a selector to write the modified row back */

     CRESEL( ArtKey, sel, "SelectorName");
     INSSEL( ArtKey, sel);

     dadWriteTab( Id, ArtKey.artKey, sel, CAF_REPLACE);

     /* attention: in reality don't drop selector to often. Adamo won't
        stand it - it is better to reuse them - leave them undropped and
        clear them before each new usage */

     DROSEL( ArtKey, sel);


This page is maintained by Wolfgang Wander.