home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / BENCH / IORACLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  59.4 KB  |  2,474 lines

  1. /* ==( io/src/ioracle.c )== */
  2.  
  3. /* ----------------------------------------------- */
  4. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  5. /* Modification to this source is not supported    */
  6. /* by Vestronix Inc.                               */
  7. /*            All Rights Reserved                  */
  8. /* ----------------------------------------------- */
  9. /* Written   NA   05-Apr-89                        */
  10. /* Modified  VvA  23-May-90  See comments below    */
  11. /* ----------------------------------------------- */
  12. /* %W%  (%H% %T%) */
  13.  
  14. /*
  15.  *  Modifications
  16.  *
  17.  *  23-May-90  VvA - separate cursors for update & reads
  18.  *  15-May-90  VvA - compound key in SELECT ... WHERE ...
  19.  *  13-Mar-90  VvA - allow use of PRO-C passwords if avail
  20.  *  09-Mar-90  VvA - V.2 modifications
  21. */
  22.  
  23. /*  ORACLE specific I/O calls via IOGEN.C interface & ORACLE OCI calls */
  24.  
  25.  
  26. # include <stdio.h>
  27. # include <iodef.h>
  28. # include <iomsg.h>
  29. # include <proc.io>
  30. # include <bench.h>
  31. # include <iosup.h>
  32. # include <field.h>
  33.  
  34.  
  35. /*
  36.  * OACTION_LEN is the size of a string to hold the SQL statement
  37.  * eg. "SELECT * FROM <TABLE> ORDER BY <FIELD>
  38.  * The longest statement will be an Update, and each key specified
  39.  * in the PRO-C Data Definition will increase the length.
  40. */
  41. # define      OACTION_LEN       4096
  42. # define      OTMPSTR_LEN       80
  43. # define      MINDATE           "01-JAN-70"
  44. # define      MAX_ORA_BUFF      75 
  45.  
  46. # define      ODEBUG
  47.  
  48.  
  49. /* Function prototypes */
  50. # ifdef ANSI
  51. static int i_addrec(int, char *);
  52. static int i_close_file(int, char *);
  53. static int i_commit(int, char *);
  54. static int i_delrec(int, char *);
  55. static int i_filename(int, char *);
  56. static int i_findkey(int, char *);
  57. static int i_firstkey(int, char *);
  58. static int i_init_file(int, char *);
  59. static int i_lastkey(int, char *);
  60. static int i_lockrec(int, char *);
  61. static int i_login(int, char *);
  62. static int i_logoff(int, char *);
  63. static int i_nextrec(int, char *);
  64. static int i_open_file(int, char *);
  65. static int i_prevrec(int, char *);
  66. static int i_rereadrec(int, char *);
  67. static int i_rollback(int, char *);
  68. static int i_selectinx(int, char *);
  69. static int i_transact(int, char *);
  70. static int i_unlock_rec(int, char *);
  71. static int i_updrec(int, char *);
  72. static int create_file(int);
  73. static int io_xlate(int, int, char *);
  74. static int o_findkey(int, char *, int);
  75. static int o_firstkey(int, char *);
  76. static int o_nextrec(int, char *);
  77. # else
  78. static int i_addrec();
  79. static int i_close_file();
  80. static int i_commit();
  81. static int i_delrec();
  82. static int i_filename();
  83. static int i_findkey();
  84. static int i_firstkey();
  85. static int i_init_file();
  86. static int i_lastkey();
  87. static int i_lockrec();
  88. static int i_login();
  89. static int i_logoff();
  90. static int i_nextrec();
  91. static int i_open_file();
  92. static int i_prevrec();
  93. static int i_rereadrec();
  94. static int i_rollback();
  95. static int i_selectinx();
  96. static int i_transact();
  97. static int i_unlock_rec();
  98. static int i_updrec();
  99. static int create_file();
  100. static int io_xlate();
  101. static int o_findkey();
  102. static int o_firstkey();
  103. static int o_nextrec();
  104. # endif
  105.  
  106.  
  107. # ifdef ANSI
  108. static char *conv_Odate(char *);
  109. static char *conv2_Odate(char *);
  110. static char *order_action(int);
  111. static char *search_action(int, int, char *);
  112. static int assign_fields7(int, char *, int);
  113. static int chk_rowid(int, char *);
  114. static int create_file7(int);
  115. static int drop_table7(int);
  116. static int dtyp7(int );
  117. static int get_idname7(void);
  118. static int is_chardate(int, int);
  119. static int lock_table7(int);
  120. static int new_table7(int);
  121. static int unique_fld7(int, struct fldinfx *);
  122. static int validuid(char *);
  123. static void add_fields7(int ,char *);
  124. static void add_keys7(int ,char *);
  125. static void add_values7(int ,char *);
  126. static void build_action7(int, int, char *);
  127. static void close_all7(void );
  128. static void free_dates7(int );
  129. static void load_dates7(int );
  130. static void oraschmeggie(char *);
  131. static void savenext7(int);
  132. # else
  133. static char *conv_Odate();
  134. static char *conv2_Odate();
  135. static char *order_action();
  136. static char *search_action();
  137. static int assign_fields7();
  138. static int chk_rowid();
  139. static int create_file7();
  140. static int drop_table7();
  141. static int dtyp7();
  142. static int get_idname7();
  143. static int is_chardate();
  144. static int lock_table7();
  145. static int new_table7();
  146. static int unique_fld7();
  147. static int validuid();
  148. static void add_fields7();
  149. static void add_keys7();
  150. static void add_values7();
  151. static void build_action7();
  152. static void close_all7();
  153. static void free_dates7();
  154. static void load_dates7();
  155. static void oraschmeggie();
  156. static void savenext7();
  157. # endif
  158.  
  159. # ifdef ODEBUG
  160. # ifdef ANSI
  161. static void get_idx7(int);
  162. static void dspactn(char *, int, char *);
  163. static void dspflds(char *, int, char *);
  164. static void dspbuff(char *, int, char *);
  165. static void dsp_rowid(int, char *);
  166. # else
  167. static void get_idx7();
  168. static void dspactn();
  169. static void dspflds();
  170. static void dspbuff();
  171. static void dsp_rowid();
  172. # endif
  173. # endif
  174.  
  175.  
  176. /*
  177. **  DEFINE ROW ID STRUCTURE (for within cursor)
  178. */
  179. struct orarowid 
  180. {                                            /* rowid structure */
  181.     struct 
  182.     {
  183.         unsigned long    tidtrba;        /* rba of first blockof table */
  184.         unsigned short    tidpid;        /* partition id of table */
  185.         unsigned char    tidtbl;        /* table id of table */
  186.     } ridtid;
  187.     unsigned long   ridbrba;        /* rba of datablock */
  188.     unsigned short  ridsqn;            /* sequence number of row in block */
  189. };
  190.  
  191. /*
  192. ** DEFINE THE c VERSION OF THE CURSOR (FOR 32 BIT MACHINES)
  193. */
  194. struct oradef
  195. {
  196.     short      orarc;                            /* return code */
  197.     short      oraft;                            /* function type */
  198.     unsigned long  orarpc;                /* rows processed count */
  199.     short      orapeo;                        /* parse error offset */
  200.     unsigned char  orafc;                /* function code */
  201.     unsigned char  orafil;                /* filler  */
  202.     unsigned short oraarc;                /* reserved, private */
  203.     unsigned char  orawrn;                /* warning flags */
  204.     unsigned char  oraflg;                /* error flags */
  205.     /*             *** Operating system dependent ***          */
  206.     unsigned int   oracn;                /* cursor number */
  207.     struct orarowid orarid;             /* rowid structure */
  208.     unsigned int   oraose;                /* os dependent error code */
  209.     unsigned char  orachk;                /* check byte */
  210.     unsigned char  orafill[30];        /* private, reserved fill */
  211. };
  212.  
  213.  
  214. /* Oracle SQLMSC library prototypes */
  215. # ifdef ANSI
  216. ocan(struct oradef *); 
  217. oclose(struct oradef *);
  218. ocom(struct oradef *);
  219. ocof(struct oradef *);
  220. odefin(struct oradef *, int, char *, int, int, int, short *, char *, int, int, short *, short *);
  221. oexec(struct oradef *);
  222. ofetch(struct oradef *);
  223. ologof(struct oradef *);
  224. oname(struct oradef *, int, short *, short *, char *, int *);
  225. oopen(struct oradef *, struct oradef *, char *, int, int, char *, int);
  226. orlon(struct oradef *, char *, char *, int, char *, int, int);
  227. orol(struct oradef *);
  228. osql3(struct oradef *, char *, int); 
  229. # else
  230. ocan(); 
  231. oclose();
  232. ocom();
  233. ocof();
  234. odefin();
  235. oexec();
  236. ofetch();
  237. ologof();
  238. oname();
  239. oopen();
  240. orlon();
  241. orol();
  242. osql3(); 
  243. # endif
  244.  
  245.  
  246. /*
  247.  * Info for each file descriptor / cursor
  248. */
  249. struct ofd_def
  250. {
  251.     int    inprogress;
  252.     int    iostat;
  253.     int    direction;
  254.     int    do_rowid;              /* TRUE if row id values to be saved */
  255.     int    lasttype;              /* param type last used for assign_field */ 
  256.     struct oradef scurs;                /* cursor for record searches */
  257.     struct oradef ucurs;          /* cursor for record updates */
  258.    char   *findaction;           /* action string for searches */
  259.     char   *fieldlist;
  260.     char   *fields;
  261.     char   *values;
  262.     char   *tmpbuf;
  263.     char   tmprowid[20];          /* to hold temporary row id */
  264.     char   oldrowid[20];          /* to hold retained row id to check */
  265.     char   currowid[20];          /* to hold copy of current row id */
  266.    char   prvrowid[20];          /* to hold copy of row id of prev rec */
  267. };
  268.  
  269. static struct ofd_def ofd[MAX_FILES];
  270.  
  271.  
  272. /****************************************************************************/
  273. /*             Oracle commands available thru' this interface.              */
  274. /****************************************************************************/
  275. /*
  276.  * insert into emp(a, b, c) values ('me', 'you', 123)"
  277. */
  278. char *Oaddrec    = "INSERT INTO %s(%s) VALUES (%s)";
  279.  
  280. /*
  281.  * update emp set a='him', b='them', c=456 where a='me'
  282. */
  283. char *Oupdrec    = "UPDATE %s SET %s WHERE ROWID='%s'";
  284.  
  285. /*
  286.  * delete from emp where a='me'
  287. */
  288. char *Odelrec    = "DELETE FROM %s WHERE ROWID='%s'";
  289.  
  290. /*
  291.  * select * from emp where a='him'and b='them' and etc....
  292. */
  293. char *multi     = "SELECT %s%s FROM %s WHERE %s ORDER BY %s";
  294.  
  295. char *last      = "SELECT NVL(MAX(%s), 0) FROM %s";
  296. char *dlast     = "SELECT NVL(MAX(%s), '%s') FROM %s";
  297.  
  298. /*
  299.  * Operations
  300. */
  301. # define      ADD      0
  302. # define      UPD      1
  303. # define      DEL      2
  304. # define      EXA      3
  305. # define      PAR      4
  306. # define      LAS      5
  307. # define      NXT      6
  308. # define      PRV      7
  309.  
  310. # define    FORWARD    1
  311. # define    BACKWARD   0
  312. # define    CURBUFF    1
  313. # define    NXTBUFF    0
  314.  
  315.  
  316.  
  317. char   hst[256];                            /* Host definition */
  318. struct oradef lda;                        /* lda area */
  319.  
  320. char uid[31];                                /* username/password */
  321.  
  322. char *action;                                /* action buffer */
  323.  
  324. static int logged_on = FALSE;
  325.  
  326. static short rowid_len;
  327. static short rowid_err;
  328. static char delrowid[20];
  329.  
  330.  
  331. /*
  332.  * Dates Bodge, used for converting Oracle format dates
  333.  * to PRO-C format dates after an INQUIRY. 
  334.  * See load_dates7() below.
  335. */
  336. struct o_dates
  337. {
  338.     char d_str[10];            /* Oracle format "DD-MON-YY" ( room for Null ) */
  339.     short d_off;                /* Offset in PRO-C buffer */
  340.     struct o_dates *nxt_d;
  341. };
  342.  
  343. struct o_dates *d_ptr;
  344. struct o_dates *d_hdr[MAX_FILES];
  345. struct o_dates *tmp_ptr;
  346.  
  347. char uname_mask[] = "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV";
  348.  
  349. FIELD f_uname = { 2, 2, 1, uid, uname_mask, 0, 30, F_TEXT,
  350.                           UNDERLINED, REVVID, CONFIRM_NEEDED | NO_BLANK,
  351.                           NULL, text_input, NULL, NULL };
  352.  
  353.  
  354.  
  355. /*
  356.  *
  357.  * Interface functions
  358.  *
  359.  */
  360.  
  361.  
  362. /*
  363.  *  Sets up File Name extension.
  364. */
  365. static int i_filename(fd_sys, buffer)
  366. int fd_sys;
  367. char *buffer;
  368. {
  369.     return(IOGOOD);
  370. }
  371.  
  372. /*
  373.  *  Initialize and open log file
  374. */
  375. static int i_init_file(fd_sys, buffer)
  376. int fd_sys;
  377. char *buffer;
  378. {
  379.     logged_on = TRUE;
  380.     action = alloc(OACTION_LEN);            /* Allocate action area */
  381.    tmp_ptr = (struct o_dates *)alloc(sizeof(struct o_dates));
  382.  
  383.     return(IOGOOD);
  384. }
  385.  
  386.  
  387. /*
  388.  *  File open function
  389. */
  390. static int i_open_file(fd_sys, buffer)
  391. int fd_sys;
  392. char *buffer;
  393. {
  394.     int stat, n;
  395.  
  396.     if (!logged_on)          /* Don't logoff as not logged on - Nig */
  397.         return(IOERROR);
  398.  
  399.     ofd[fd_sys].inprogress = FALSE;                      /* no resources active */
  400.    ofd[fd_sys].lasttype = -1;
  401.    ofd[fd_sys].findaction = alloc(OACTION_LEN);
  402.     ofd[fd_sys].values = alloc(OACTION_LEN);
  403.     ofd[fd_sys].fields = alloc(OACTION_LEN);
  404.    ofd[fd_sys].fieldlist = alloc(fd[fd_sys].fld_cnt * (FLDNAME_LEN + 2));
  405.     ofd[fd_sys].tmpbuf = alloc(fd[fd_sys].rec_len);
  406.  
  407.     /*
  408.      * Establish CURSORs for this table
  409.     */
  410.     oopen(&ofd[fd_sys].ucurs, &lda, (char *)0, -1, -1, (char *)0, -1);
  411.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Open0A")) != IOGOOD)
  412.     {
  413.         close_all7();
  414.         i_logoff(fd_sys, NULL);
  415.         return (stat);
  416.     }
  417.     oopen(&ofd[fd_sys].scurs, &lda, (char *)0, -1, -1, (char *)0, -1);
  418.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Open0B")) != IOGOOD)
  419.     {
  420.         close_all7();
  421.         i_logoff(fd_sys, NULL);
  422.         return (stat);
  423.    }
  424.  
  425.     /*
  426.     * If OUTPUT mode, delete table - supporting logic will create it
  427.     */
  428.     if (fd[fd_sys].openmode & OUTPUT_FLAG)
  429.         drop_table7(fd_sys);
  430.  
  431.     if (new_table7(fd_sys) != IOGOOD)
  432.     {
  433.         if (!(fd[fd_sys].openmode & INPUT_FLAG))
  434.         {
  435.             if (create_file7(fd_sys) != IOGOOD)
  436.                 return (IOERROR);
  437.         }
  438.         else
  439.         {
  440.             stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Open1");
  441.             close_all7();
  442.             i_logoff(fd_sys, NULL);
  443.             return (stat);
  444.         }
  445.     }
  446.  
  447.     if (lock_table7(fd_sys) != IOGOOD)
  448.         return (IOERROR);
  449.  
  450.     load_dates7(fd_sys);
  451.  
  452.    ofd[fd_sys].fieldlist[0] = '\0';
  453.    for (n = 0; n < fd[fd_sys].fld_cnt; n++)
  454.    {
  455.       strcat(ofd[fd_sys].fieldlist, fd[fd_sys].flds[n].fldname);
  456.       if (n < fd[fd_sys].fld_cnt - 1)
  457.          strcat(ofd[fd_sys].fieldlist, ",");
  458.    }
  459.  
  460.     return(IOGOOD);
  461. }
  462.  
  463.  
  464. /*
  465.  * Lock the table !
  466. */
  467. static int lock_table7(fd_sys)
  468. int fd_sys;
  469. {
  470.     int stat;
  471.  
  472.     if (fd[fd_sys].openmode & (UPDATE_FLAG | P_SHARED))
  473.         sprintf(action, "LOCK TABLE %s IN SHARE UPDATE MODE NOWAIT", fd[fd_sys].filname);
  474.     else if (fd[fd_sys].openmode & (UPDATE_FLAG | P_EXCLUSIVE))
  475.         sprintf(action, "LOCK TABLE %s IN EXCLUSIVE UPDATE MODE NOWAIT", fd[fd_sys].filname);
  476.     else if (fd[fd_sys].openmode & (INPUT_FLAG | P_SHARED))
  477.         sprintf(action, "LOCK TABLE %s IN SHARE MODE NOWAIT", fd[fd_sys].filname);
  478.     else
  479.         sprintf(action, "LOCK TABLE %s IN EXCLUSIVE MODE NOWAIT", fd[fd_sys].filname);
  480.  
  481. # ifdef ODEBUG
  482.     dspactn(action, fd_sys, "Lock0");
  483. # endif
  484.     oraschmeggie(action);
  485.     osql3(&ofd[fd_sys].ucurs, action, -1); 
  486.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Lock0")) != IOGOOD)
  487.     {
  488.         close_all7();
  489.         i_logoff(fd_sys, NULL);
  490.         return (stat);
  491.     }
  492.  
  493.     return (IOGOOD);
  494. }
  495.  
  496.  
  497. /*
  498.  * Tell Oracle to Drop the specified table. ie. Delete it
  499. */
  500. static int drop_table7(fd_sys)
  501. int fd_sys;
  502. {
  503.     int stat;
  504.  
  505.     sprintf(action, "DROP TABLE %s", fd[fd_sys].filname);
  506. # ifdef ODEBUG
  507.     dspactn(action, fd_sys, "Drop0");
  508. # endif
  509.     oraschmeggie(action);
  510.     osql3(&ofd[fd_sys].ucurs, action, -1); 
  511.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Drop0")) != IOGOOD)
  512.     {
  513.         close_all7();
  514.         i_logoff(fd_sys, NULL);
  515.         return (stat);
  516.     }
  517. }
  518.  
  519.  
  520. /*
  521.  * Determine if a Table exists - If not then CREATE it
  522. */
  523. static int new_table7(fd_sys)
  524. int fd_sys;
  525. {
  526.     /*
  527.      * Bodge up way of checking to see if a table exists
  528.     */
  529.     sprintf(action, "SELECT * FROM %s", fd[fd_sys].filname);
  530. # ifdef ODEBUG
  531.     dspactn(action, fd_sys, "NEWTAB");
  532. # endif
  533.     oraschmeggie(action);
  534.     osql3(&ofd[fd_sys].scurs, action, -1);
  535.  
  536. #ifdef ODEBUG
  537.    errmsg("new_table fn has error code %d", ofd[fd_sys].scurs.orarc);
  538.    io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "NewTab");
  539. #endif
  540.  
  541.     if (ofd[fd_sys].scurs.orarc != 0)
  542.         return (IOERROR);
  543.     else
  544.         return (IOGOOD);
  545. }
  546.  
  547.  
  548. /*
  549.  * This auxillary routine is called by the OPEN routine in the 
  550.  * event that the file is to be created.
  551. */
  552. static int create_file7(fd_sys)
  553. int fd_sys;
  554. {
  555.     int i, stat;
  556.     char tmp[128];
  557.     struct fldinfx *flds = fd[fd_sys].flds;
  558.  
  559.     /*
  560.      * Build up SQL string to create the table
  561.     */
  562.     sprintf(action, "CREATE TABLE %s ( ", fd[fd_sys].filname);
  563.  
  564.     for (i = 0;  i < fd[fd_sys].fld_cnt;  i++, flds++)
  565.     {
  566.         switch(flds->fldtype) 
  567.         {
  568.         case CHRTYP :
  569.             if (flds->fldlen > 240)
  570.             {
  571.                 errmsg("Field Too Long for Oracle to Understand - Adjusting");
  572.                 flds->fldlen = 240;
  573.             }
  574.             sprintf(tmp, "%s CHAR(%d)", flds->fldname, flds->fldlen);
  575.             break;
  576.         case MEMTYP :
  577.             sprintf(tmp, "%s LONG", flds->fldname);
  578.             break;
  579.         case INTTYP :
  580.         case LNGTYP :
  581.             sprintf(tmp, "%s NUMBER(%d)", flds->fldname, 1+nummasklen(flds->fldmask));
  582.             break;
  583.         case FLTTYP :
  584.         case DBLTYP :
  585.             sprintf(tmp, "%s NUMBER(%d,%d)", flds->fldname, 1+nummasklen(flds->fldmask), decmasklen(flds->fldmask));
  586.             break;
  587.         case DATTYP :
  588.             if (flds->fldlen == 6)
  589.                 sprintf(tmp, "%s DATE", flds->fldname);
  590.             else           /* full time date will be stored as a long int */
  591.                 sprintf(tmp, "%s NUMBER(10)", flds->fldname);
  592.             break;
  593.         }
  594.  
  595.         strcat(action, tmp);
  596.  
  597.         if (i < fd[fd_sys].fld_cnt-1)
  598.             strcat(action, ", ");
  599.     }
  600.  
  601.     strcat(action, " )");
  602.  
  603.     /* 
  604.      * Operation 
  605.     */
  606. # ifdef ODEBUG
  607.     dspactn(action, fd_sys, "Creat0");
  608. # endif
  609.     oraschmeggie(action);
  610.     osql3(&ofd[fd_sys].ucurs, action, -1); 
  611.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Create0")) != IOGOOD)
  612.     {
  613.         close_all7();
  614.         i_logoff(fd_sys, NULL);
  615.         return (stat);
  616.     }
  617.  
  618.     for (i = 0, flds = fd[fd_sys].flds;  i < fd[fd_sys].fld_cnt;  i++, flds++)
  619.         if (unique_fld7(fd_sys, flds))
  620.         {
  621.             sprintf(action, "CREATE UNIQUE INDEX Q%s%sQ ON %s(%s)", fd[fd_sys].filname, flds->fldname, fd[fd_sys].filname, flds->fldname);
  622. # ifdef ODEBUG
  623.     dspactn(action, fd_sys, "Creat1");
  624. # endif
  625.             oraschmeggie(action);
  626.             osql3(&ofd[fd_sys].ucurs, action, -1); 
  627.             if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Create1")) != IOGOOD)
  628.             {
  629.                 close_all7();
  630.                 i_logoff(fd_sys, NULL);
  631.                 return (stat);
  632.             }
  633.         }
  634.  
  635.     return (IOGOOD);
  636. }
  637.  
  638.  
  639. /*
  640.  * Close ALL open tables
  641.  * NOTE: if mixed file managers enabled, this function will have to
  642.  *   distinguish between ORACLE and other file types
  643. */
  644. static void close_all7()
  645. {
  646.     int i;
  647.  
  648.     for (i = 0; i < MAX_FILES; i++)
  649.         if (fd[i].active == TRUE)
  650.             i_close_file(i, NULL);
  651. }
  652.  
  653.  
  654. /*
  655.  * This routine will close the Table defined by FD_SYS.
  656. */
  657. static int i_close_file(fd_sys, buffer)
  658. int fd_sys;
  659. char *buffer;
  660. {
  661.     int i;
  662.  
  663. /*
  664.  * close the table
  665. */
  666.     oclose(&ofd[fd_sys].ucurs);
  667.    oclose(&ofd[fd_sys].scurs);
  668.     fd[fd_sys].active = FALSE;
  669.  
  670.     free_dates7(fd_sys);
  671.    free(ofd[fd_sys].findaction);
  672.     free(ofd[fd_sys].values);
  673.     free(ofd[fd_sys].fields);
  674.    free(ofd[fd_sys].fieldlist);
  675.     free(ofd[fd_sys].tmpbuf);
  676.  
  677. /*
  678.  * If a table is still active, then return
  679. */
  680.     for (i = 0; i < MAX_FILES; i++)
  681.         if (fd[i].active == TRUE)
  682.             return(IOGOOD);
  683.  
  684.     /*
  685.      * Logoff here only if not already logged off
  686.     */
  687.     if (logged_on)
  688.         i_logoff(fd_sys, NULL);
  689.  
  690.     return(IOGOOD);
  691. }
  692.  
  693.  
  694. /*
  695.  * Select an index to perform processing on.
  696. */
  697. static int i_selectinx(fd_sys, buffer)
  698. int fd_sys;
  699. char *buffer;
  700. {
  701.     return(IOGOOD);
  702. }
  703.  
  704.  
  705. /*
  706.  * Retrieve a record according to a key specification.
  707. */
  708. static int i_findkey(fd_sys, buffer)
  709. int fd_sys;
  710. char *buffer;
  711. {
  712.    int opno;
  713.  
  714.     /*
  715.      * Also need to take the Special Match type into consideration - NIG
  716.     */
  717.    opno = (fd[fd_sys].exact == 1) ? EXA : (fd[fd_sys].exact == 0) ? PAR : 99;
  718.    ofd[fd_sys].direction = FORWARD;
  719.    ofd[fd_sys].do_rowid = TRUE;
  720.    ofd[fd_sys].findaction[0] = '\0';
  721.    return(o_findkey(fd_sys, buffer, opno));
  722. }
  723.  
  724. /*
  725.  * Retrieve function allowing direction selection
  726. */
  727. static int o_findkey(fd_sys, buffer, opno)
  728. int fd_sys;
  729. char *buffer;
  730. int opno;
  731. {
  732.     int stat;
  733.  
  734.    if (!ofd[fd_sys].findaction[0])
  735.        build_action7(fd_sys, opno, buffer);
  736.  
  737.     /*
  738.      * If Resources remain allocated by oracle, then we
  739.      * must release them.
  740.     */
  741.     if (ofd[fd_sys].inprogress == TRUE)
  742.     {
  743.         ocan(&ofd[fd_sys].scurs); 
  744.         if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Cancel0")) != IOGOOD)
  745.             return (stat);
  746.         ofd[fd_sys].inprogress = FALSE;
  747.     }
  748.  
  749.     /* 
  750.      * Inform Oracle of the Operation 
  751.     */
  752. # ifdef ODEBUG
  753.     dspactn(ofd[fd_sys].findaction, fd_sys, "Find0");
  754. # endif
  755.     oraschmeggie(ofd[fd_sys].findaction);
  756.     osql3(&ofd[fd_sys].scurs, ofd[fd_sys].findaction, -1); 
  757.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Find0")) != IOGOOD)
  758.         return (stat);
  759.  
  760.     /*
  761.      * Tell Oracle about the fields in our buffer
  762.     */
  763.     if ((stat = assign_fields7(fd_sys, buffer, CURBUFF)) != IOGOOD)
  764.         return (stat);
  765.  
  766.     /*
  767.      * Perform Op !
  768.     */
  769.     stat = oexec(&ofd[fd_sys].scurs);
  770.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Find1")) != IOGOOD)
  771.         return (stat);
  772.  
  773.     /*
  774.      * Get first record in list.
  775.     */
  776.     zerorec(buffer, fd[fd_sys].rec_len);
  777.    memcpy(ofd[fd_sys].prvrowid, ofd[fd_sys].currowid, 18);
  778.     ofetch(&ofd[fd_sys].scurs);
  779.    if (ofd[fd_sys].do_rowid)
  780.    {
  781.       memcpy(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18);
  782. #ifdef ODEBUG
  783.       dsp_rowid(fd_sys, "SAVING");
  784. #endif
  785.    }
  786.     stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Find2");
  787.    ofd[fd_sys].lasttype = -1;        /* forces reassignment of field targets */
  788.     if (stat == IOEOF)
  789.         return (IONOKEY);
  790.     else if (stat != IOGOOD)
  791.         return (stat);
  792.  
  793.     /*
  794.      * For each length==6 date field, convert from Oracle format
  795.      * to PRO-C format. ie. DD-MON-YY --> YYMMDD.
  796.      * If the date is Null, then copy Null.
  797.      * (long int date/time fields are treated as longs)
  798.     */
  799.     for (d_ptr = d_hdr[fd_sys];  d_ptr != (struct o_dates *)0;  d_ptr = d_ptr->nxt_d)
  800.     {
  801.         if (!*d_ptr->d_str)
  802.             fstrcpy((char *)(buffer + d_ptr->d_off), "", 1);
  803.         else if (is_chardate(fd_sys, d_ptr->d_off))
  804.             memcpy((char *)(buffer + d_ptr->d_off), conv_Odate(d_ptr->d_str),  6);
  805.     }
  806.  
  807.     /*
  808.      * Create list of keys to search on for update/delete
  809.     */
  810.     add_keys7(fd_sys, buffer);
  811.  
  812.     /*
  813.      * Set the inprogress flag to TRUE, as we have retrieved
  814.      * a record, and caused Oracle to allocate resources
  815.      * associated with this search path.
  816.     */
  817.     ofd[fd_sys].inprogress = TRUE;
  818.  
  819.     /*
  820.      * Get the next record now
  821.     */
  822.     savenext7(fd_sys);
  823.  
  824.     return(IOGOOD);
  825. }
  826.  
  827.  
  828. /*
  829.  *  Find first record in the file
  830. */
  831. static int i_firstkey(fd_sys, buffer)
  832. int fd_sys;
  833. char *buffer;
  834. {
  835.     ofd[fd_sys].direction = FORWARD;
  836.     return(o_firstkey(fd_sys, buffer));
  837. }
  838.  
  839. /*
  840.  * First record function allowing direction selection
  841. */
  842. static int o_firstkey(fd_sys, buffer)
  843. int fd_sys;
  844. char *buffer;
  845. {
  846.     int oldexact, stat;
  847.  
  848.     zerorec(buffer, fd[fd_sys].rec_len);
  849.    ofd[fd_sys].do_rowid = (ofd[fd_sys].direction == FORWARD); 
  850.    ofd[fd_sys].direction = FORWARD;
  851.     oldexact = fd[fd_sys].exact;
  852.     fd[fd_sys].exact = 0;                   /* set up search as a PART match */
  853.    ofd[fd_sys].findaction[0] = '\0';
  854.     stat = o_findkey(fd_sys, buffer, PAR);
  855.     fd[fd_sys].exact = oldexact;
  856.  
  857.     return(stat);
  858. }
  859.  
  860.  
  861. /*
  862.  *  Find last physical record in the file
  863. */
  864. static int i_lastkey(fd_sys, buffer)
  865. int fd_sys;
  866. char *buffer;
  867. {
  868.     int stat, ix, opno;
  869.     struct fldinfx *fin;
  870.  
  871.    ofd[fd_sys].direction = BACKWARD;
  872.     build_action7(fd_sys, LAS, buffer);
  873.  
  874.     /*
  875.      * If Resources remain allocated by oracle, then we
  876.      * must release them.
  877.     */
  878.     if (ofd[fd_sys].inprogress == TRUE)
  879.     {
  880.         ocan(&ofd[fd_sys].scurs); 
  881.         if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Cancel4")) != IOGOOD)
  882.             return (stat);
  883.         ofd[fd_sys].inprogress = FALSE;
  884.     }
  885.  
  886.     /* 
  887.      * Inform Oracle of the Operation 
  888.     */
  889. # ifdef ODEBUG
  890.     dspactn(action, fd_sys, "Last0");
  891. # endif
  892.     oraschmeggie(action);
  893.     osql3(&ofd[fd_sys].scurs, action, -1); 
  894.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last0")) != IOGOOD)
  895.         return (stat);
  896.  
  897.     /*
  898.      * Find this fields info
  899.     */
  900.     ix = fd[fd_sys].keys[fd[fd_sys].cur_key].fldindex[0];
  901.     fin = &fd[fd_sys].flds[ix];
  902.  
  903.     /*
  904.      * Tell Oracle about this field, and only this field.
  905.      * Remember, this is the Only field in the select list,
  906.      * so field number is 1 for this odefin()
  907.     */
  908.    ofd[fd_sys].lasttype = -1;       /* ensures redefinition in assign_fields */
  909.  
  910.     if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
  911.     {
  912.         tmp_ptr->d_off = fin->fldstart;
  913.         odefin(&ofd[fd_sys].scurs, 1, tmp_ptr->d_str, 10, dtyp7(fin->fldtype),
  914.             -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
  915.     }
  916.     else
  917.     {
  918.         if (fin->fldtype == DATTYP)                   /* long int date only */
  919.             odefin(&ofd[fd_sys].scurs, 1, (char *)(buffer + fin->fldstart),
  920.                 fin->fldlen, dtyp7(LNGTYP),
  921.                 -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
  922.         else
  923.             odefin(&ofd[fd_sys].scurs, 1, (char *)(buffer + fin->fldstart),
  924.                 fin->fldlen, dtyp7(fin->fldtype),
  925.                 -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
  926.     }
  927.  
  928.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last1")) != IOGOOD)
  929.         return (stat);
  930.  
  931.     /*
  932.      * Perform Op !
  933.     */
  934.     oexec(&ofd[fd_sys].scurs);
  935.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last2")) != IOGOOD)
  936.         return (stat);
  937.  
  938.     /*
  939.      * Get first record in list. (ie, the last record)
  940.     */
  941.    memcpy(ofd[fd_sys].prvrowid, ofd[fd_sys].currowid, 18);
  942.     ofetch(&ofd[fd_sys].scurs);
  943.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last3")) != IOGOOD)
  944.         return (stat);
  945.  
  946.     /*
  947.     * Convert Oracle date type to PRO-C form, if null, store as null
  948.     */
  949.     if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
  950.    {
  951.         if (!*tmp_ptr->d_str)
  952.             fstrcpy((char *)(buffer + tmp_ptr->d_off), "", 1);
  953.         else if (is_chardate(fd_sys, tmp_ptr->d_off))
  954.             memcpy((char *)(buffer + tmp_ptr->d_off), conv_Odate(tmp_ptr->d_str),  6);
  955.     }
  956.  
  957.     /*
  958.      * De-allocate Oracle Resources
  959.     */
  960.     ocan(&ofd[fd_sys].scurs); 
  961.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Cancel5")) != IOGOOD)
  962.         return (stat);
  963.     ofd[fd_sys].inprogress = FALSE;
  964.  
  965.    /*
  966.     * Found last rec okay, now reseek on it to establish rowid
  967.    */
  968.    opno = (fd[fd_sys].exact == 1) ? EXA : (fd[fd_sys].exact == 0) ? PAR : 99;
  969.    ofd[fd_sys].do_rowid = TRUE;
  970.    ofd[fd_sys].findaction[0] = '\0';
  971.    return(o_findkey(fd_sys, buffer, opno));
  972. }
  973.  
  974.  
  975. /*
  976.  * This routine will retrieve the NEXT record in the sequence on the
  977.  * currently defined retrieval path.
  978.  * Special handling is performed depending on whether we are just
  979.  * reading or reading/updating.
  980.  * If the latter, then ORACLE's internal search path's are trashed
  981.  * after an update, so using the saved value of the next record we
  982.  * do another partial lookup to set up the search path again.
  983. */
  984. static int i_nextrec(fd_sys, buffer)
  985. int fd_sys;
  986. char *buffer;
  987. {
  988.     int stat;
  989.  
  990.    ofd[fd_sys].direction = FORWARD;
  991.    ofd[fd_sys].do_rowid = FALSE;
  992.  
  993.    stat = o_nextrec(fd_sys, buffer);
  994.  
  995.    if (stat == IOGOOD)      /* retain current row id in case PREV done next */
  996.    {
  997.       memcpy(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18);
  998. #ifdef ODEBUG
  999.       dsp_rowid(fd_sys, "RESETTING");
  1000. #endif
  1001.    }
  1002.    return(stat);
  1003. }
  1004.  
  1005. /*
  1006.  * Next function allowing direction selection
  1007. */
  1008. static int o_nextrec(fd_sys, buffer)
  1009. int fd_sys;
  1010. char *buffer;
  1011. {
  1012.     int oldexact;
  1013.  
  1014.     /*
  1015.      * Check to see if previous savenext7() call was ok
  1016.     */
  1017.     if (ofd[fd_sys].iostat != IOGOOD)
  1018.         return (ofd[fd_sys].iostat);
  1019.  
  1020.         bytecpy(buffer, ofd[fd_sys].tmpbuf, fd[fd_sys].rec_len);
  1021.         /*
  1022.          * Set up key string in case update to be done
  1023.         */
  1024.         add_keys7(fd_sys, buffer);
  1025.         /*
  1026.           * Get the next record now
  1027.         */
  1028.       memcpy(ofd[fd_sys].prvrowid, ofd[fd_sys].currowid, 18);
  1029.       memcpy(ofd[fd_sys].currowid, ofd[fd_sys].tmprowid, 18);
  1030.         savenext7(fd_sys);
  1031.  
  1032.     return (IOGOOD);
  1033. }
  1034.  
  1035.  
  1036. /*
  1037.  *  Find previous record in the file
  1038.  *  - if rowid values of "next" rec retrieved by savenext7 match those
  1039.  *    retained from original fetch, it is the previous record by current
  1040.  *    ORDER BY criterion
  1041. */
  1042. static int i_prevrec(fd_sys, buffer)
  1043. int fd_sys;
  1044. char *buffer;
  1045. {
  1046.    int stat, opno;
  1047.     char prv_rowid[20];
  1048.  
  1049.     /*
  1050.      * Save the Previous row_id for checking !!
  1051.     */
  1052.     strcpy(prv_rowid, ofd[fd_sys].prvrowid);
  1053.  
  1054.       opno = (fd[fd_sys].exact == 1) ? EXA : (fd[fd_sys].exact == 0) ? PAR : 99;
  1055.  
  1056. errmsg("prev 1");
  1057.    if (ofd[fd_sys].direction == BACKWARD)   /* lastrec has been used before */
  1058.       stat = o_firstkey(fd_sys, buffer);
  1059.    else
  1060.       stat = o_findkey(fd_sys, buffer, opno);
  1061.  
  1062. errmsg("prev 2");
  1063.    if (!memcmp(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18))
  1064.       return(IOTOF);            /* if retained rowid same as current, at TOF */
  1065.  
  1066. errmsg("prev 3");
  1067.     /*
  1068.      * Using the saved previous rowid, look for the required record - NIG
  1069.     */
  1070.    while (!chk_rowid(fd_sys, prv_rowid) && stat == IOGOOD)
  1071.     {
  1072. errmsg("trying the next one");
  1073.       stat = o_nextrec(fd_sys, buffer);
  1074.     }
  1075.  
  1076.    if (stat == IOGOOD)
  1077.    {
  1078.       memcpy(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18);
  1079. #ifdef ODEBUG
  1080.       dsp_rowid(fd_sys, "RESETTING");
  1081. #endif
  1082.    }
  1083.  
  1084.    return(stat);                   /* will be IOEOF if end of file reached */
  1085. }
  1086.  
  1087.  
  1088. /*
  1089.  *  Re-read/reposition record pointer function - if required
  1090. */
  1091. static int i_rereadrec(fd_sys, buffer)
  1092. int fd_sys;
  1093. char *buffer;
  1094. {
  1095.     return(IOGOOD);
  1096. }
  1097.  
  1098.  
  1099. /*
  1100.  *  Add a new record.
  1101. */
  1102. static int i_addrec(fd_sys, buffer)
  1103. int fd_sys;
  1104. char *buffer;
  1105. {
  1106.     int stat;
  1107.  
  1108.     build_action7(fd_sys, ADD, buffer);
  1109.  
  1110.     /*
  1111.      * If Resources remain allocated by oracle, then we
  1112.      * must release them.
  1113.     */
  1114.     if (ofd[fd_sys].inprogress == TRUE)
  1115.     {
  1116.         ocan(&ofd[fd_sys].ucurs); 
  1117.         if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Cancel1")) != IOGOOD)
  1118.             return (stat);
  1119.         ofd[fd_sys].inprogress = FALSE;
  1120.     }
  1121.  
  1122.     /* 
  1123.      * Inform Oracle of the Operation 
  1124.     */
  1125. # ifdef ODEBUG
  1126.     dspactn(action, fd_sys, "Add0");
  1127. # endif
  1128.     oraschmeggie(action);
  1129.     osql3(&ofd[fd_sys].ucurs, action, -1); 
  1130.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Add0")) != IOGOOD)
  1131.         return (stat);
  1132.  
  1133.     /*
  1134.      * Perform Op !
  1135.     */
  1136.     oexec(&ofd[fd_sys].ucurs);
  1137.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Add1")) != IOGOOD)
  1138.         return (stat);
  1139.  
  1140.     add_keys7(fd_sys, buffer);
  1141.  
  1142.     return(IOGOOD);       
  1143. }
  1144.  
  1145.  
  1146. /*
  1147.  *  Update the current record.
  1148. */
  1149. static int i_updrec(fd_sys, buffer)
  1150. int fd_sys;
  1151. char *buffer;
  1152. {
  1153.     int stat, opno;
  1154.  
  1155.     build_action7(fd_sys, UPD, buffer);
  1156.  
  1157.     /*
  1158.      * If Resources remain allocated by oracle, then we
  1159.      * must release them.
  1160.     */
  1161.     if (ofd[fd_sys].inprogress == TRUE)
  1162.     {
  1163.         ocan(&ofd[fd_sys].ucurs); 
  1164.         if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Cancel2")) != IOGOOD)
  1165.             return (stat);
  1166.         ofd[fd_sys].inprogress = FALSE;
  1167.     }
  1168.  
  1169.     /* 
  1170.      * Inform Oracle of the Operation 
  1171.     */
  1172. # ifdef ODEBUG
  1173.     dspactn(action, fd_sys, "Upd0");
  1174. # endif
  1175.     oraschmeggie(action);
  1176.     osql3(&ofd[fd_sys].ucurs, action, -1); 
  1177.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Update0")) != IOGOOD)
  1178.         return (stat);
  1179.  
  1180.     /*
  1181.      * Perform Op !
  1182.     */
  1183.     oexec(&ofd[fd_sys].ucurs);
  1184.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Update1")) != IOGOOD)
  1185.         return (stat);
  1186.  
  1187.     add_keys7(fd_sys, buffer);
  1188.  
  1189.     return (IOGOOD);
  1190. }
  1191.  
  1192.  
  1193. /*
  1194.  * Save the next record on this search path, so that
  1195.  * an updrec() before a nextrec() will not cause 
  1196.  * ORACLE error -1002 ( fetch out of sequence ).
  1197.  * nextrec() knows, according to flags set below,
  1198.  * whether or not to do a re-read using the saved next
  1199.  * record, or just use the normal next record read.
  1200.  *
  1201.  * Uses temporary buffer, for next record, so as not
  1202.  * to trash our current record.
  1203. */
  1204. static void savenext7(fd_sys)
  1205. int fd_sys;
  1206. {
  1207.     int stat;
  1208.  
  1209.     /*
  1210.      * Tell Oracle about the fields in our temp buffer
  1211.     */
  1212.     if ((stat = assign_fields7(fd_sys, ofd[fd_sys].tmpbuf, NXTBUFF)) != IOGOOD)
  1213.     {
  1214.         ofd[fd_sys].iostat = stat;
  1215.         return;
  1216.     }
  1217.  
  1218.     /* 
  1219.      * Inform Oracle of the Operation 
  1220.     */
  1221. # ifdef ODEBUG
  1222.     dspactn(ofd[fd_sys].findaction, fd_sys, "SavNxt0");
  1223. # endif
  1224.     zerorec(ofd[fd_sys].tmpbuf, fd[fd_sys].rec_len);
  1225.     ofetch(&ofd[fd_sys].scurs);
  1226.     stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Savenext0");
  1227.     if (stat != IOGOOD)
  1228.     {
  1229.         /*
  1230.          * End of File, so set the flag
  1231.         */
  1232.         ofd[fd_sys].iostat = stat;
  1233.         return;
  1234.     }
  1235.     ofd[fd_sys].iostat = IOGOOD;
  1236.  
  1237.     /*
  1238.      * For each date field, convert from Oracle format
  1239.      * to PRO-C format. ie. DD-MON-YY --> YYMMDD.
  1240.     */
  1241.     for (d_ptr = d_hdr[fd_sys];  d_ptr != (struct o_dates *)0;  d_ptr = d_ptr->nxt_d)
  1242.     {
  1243.         if (!*d_ptr->d_str)
  1244.             fstrcpy((char *)(ofd[fd_sys].tmpbuf + d_ptr->d_off), "", 1);
  1245.         else if (is_chardate(fd_sys, d_ptr->d_off))
  1246.             memcpy((char *)(ofd[fd_sys].tmpbuf + d_ptr->d_off), conv_Odate(d_ptr->d_str), 6);
  1247.     }
  1248. }
  1249.  
  1250.  
  1251. /*
  1252.  *  Delete the current record.
  1253. */
  1254. static int i_delrec(fd_sys, buffer)
  1255. int fd_sys;
  1256. char *buffer;
  1257. {
  1258.     int stat, opno;
  1259.  
  1260.    memcpy(delrowid, ofd[fd_sys].currowid, 18);
  1261.  
  1262. # ifdef NIGEL
  1263.     /*
  1264.      * Don't find next because the inquire cursor is still valid
  1265.     */
  1266.    stat = o_nextrec(fd_sys, buffer); /* have next record ready before delete */
  1267. # endif
  1268.  
  1269.     build_action7(fd_sys, DEL, buffer);
  1270.  
  1271.     /*
  1272.      * If Resources remain allocated by oracle, then we
  1273.      * must release them.
  1274.     */
  1275.     if (ofd[fd_sys].inprogress == TRUE)
  1276.     {
  1277.         ocan(&ofd[fd_sys].ucurs); 
  1278.         if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Cancel3")) != IOGOOD)
  1279.             return (stat);
  1280.         ofd[fd_sys].inprogress = FALSE;
  1281.     }
  1282.  
  1283.     /* 
  1284.      * Inform Oracle of the Operation 
  1285.     */
  1286. # ifdef ODEBUG
  1287.     dspactn(action, fd_sys, "Del0");
  1288. # endif
  1289.     oraschmeggie(action);
  1290.     osql3(&ofd[fd_sys].ucurs, action, -1); 
  1291.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Delete0")) != IOGOOD)
  1292.         return (stat);
  1293.  
  1294.     /*
  1295.      * Perform Op !
  1296.     */
  1297.     oexec(&ofd[fd_sys].ucurs);
  1298.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Delete1")) != IOGOOD)
  1299.         return (stat);
  1300.  
  1301.     return (IOGOOD);
  1302. }
  1303.  
  1304.  
  1305. /*
  1306.  * Lock Record. 
  1307. */
  1308. static int i_lockrec(fd_sys, buffer)
  1309. int fd_sys;
  1310. char *buffer;
  1311. {
  1312.    return(IOGOOD);
  1313. }
  1314.  
  1315.  
  1316. /*
  1317.  *  Unlock Record. Called from Delete/Inquire Mode
  1318. */
  1319. static int i_unlock_rec(fd_sys, buffer)
  1320. int fd_sys;
  1321. char *buffer;
  1322. {
  1323.     return(IOGOOD);
  1324. }
  1325.  
  1326.  
  1327. /*
  1328.  * logoff if no tables left open, and reset the first time flag
  1329. */
  1330. static int i_logoff(fd_sys, buffer)
  1331. int fd_sys;
  1332. char *buffer;
  1333. {
  1334.     logged_on = FALSE;
  1335.  
  1336.     free(action);
  1337.    free(tmp_ptr);
  1338.  
  1339.     if (ologof(&lda))
  1340.     {
  1341.         io_xlate(-1, lda.orarc, "Logoff");
  1342.         return (IOERROR);
  1343.     }
  1344.  
  1345.     return (IOGOOD);
  1346. }
  1347.  
  1348.  
  1349. /*
  1350.  * Logon to Oracle
  1351. */
  1352. static int i_login(fd_sys, buffer)
  1353. int fd_sys;
  1354. char *buffer;
  1355. {
  1356.     int stat;
  1357.  
  1358.     while (TRUE)
  1359.     {
  1360.         if (buffer)     /* if a password has been supplied from PRO-C program */
  1361.         {
  1362.             strcpy(uid, buffer);
  1363.             strcat(uid, "/");
  1364.             strcat(uid, &buffer[20]);    /* offset 20 into buffer has password */
  1365.          }
  1366.         else if (get_idname7() != IOGOOD)
  1367.             return (IOERROR);
  1368.  
  1369.         if (orlon(&lda, hst, uid, -1, (char *)0, -1, -1))
  1370.         {
  1371.             if ((stat = io_xlate(fd_sys, lda.orarc, "Logon")) != IOGOOD)
  1372.                 return (stat);
  1373.         }
  1374.         ocof(&lda);
  1375.         if ((stat = io_xlate(fd_sys, lda.orarc, "No Auto Commit")) != IOGOOD)
  1376.             return (stat);
  1377.         else
  1378.             return (IOGOOD);
  1379.     }
  1380. }
  1381.  
  1382.  
  1383. /*
  1384.  * Get username / password from user 
  1385.  * in the form "uname/passwd".
  1386.  *
  1387.  * Due to the change in the windowing system, this call
  1388.  * to create_w() must be made only after the windowing
  1389.  * system has been initialised. (ie. the main call to
  1390.  * init_w() / create_w().
  1391. */
  1392. static int get_idname7()
  1393. {
  1394.     create_w(1, 1, 3, 32);
  1395.     border_w(0, BOLD);
  1396.     disp_w(1, 7, REVVID, " username/password ");
  1397.  
  1398.     do
  1399.     {
  1400.         input_wx(&f_uname, K_ESC, 0);
  1401.         if (ichar == K_ESC)
  1402.         {
  1403.             delete_w();
  1404.             return (IOERROR);
  1405.         }
  1406.     }
  1407.     while(!validuid(uid));
  1408.  
  1409.     delete_w();
  1410.  
  1411.     return (IOGOOD);
  1412. }
  1413.  
  1414.  
  1415. /*
  1416.  * Check format of id/pw
  1417. */
  1418. static int validuid(uid)
  1419. char *uid;
  1420. {
  1421.     int stat;
  1422.  
  1423.     if (strchr(uid, '/') == NULL)
  1424.     {
  1425.         errmsg("Enter Username & Password in format 'Username/Password'");
  1426.         return (FALSE);
  1427.     }
  1428.     else 
  1429.     {
  1430.         stat = warning(-1, "Is the Username & Password Correct ?");
  1431.     }
  1432.     
  1433.     if (stat)
  1434.         return (TRUE);
  1435.     else
  1436.         return (FALSE);
  1437. }
  1438.  
  1439.  
  1440. /*
  1441.  * Create a string containing the required action to
  1442.  * pass to Oracle, using the SQL defines above.
  1443.  * eg. "SELECT * FROM <TABLE> WHERE <FLD>=<VALUE>
  1444. */
  1445.  
  1446. static void build_action7(fd_sys, opno, buffer)
  1447. int fd_sys;
  1448. int opno;
  1449. char *buffer;
  1450. {
  1451.     int ix;
  1452.     struct fldinfx *fin;
  1453.  
  1454.     ix = fd[fd_sys].keys[fd[fd_sys].cur_key].fldindex[0];
  1455.     fin = &fd[fd_sys].flds[ix];
  1456.  
  1457.     switch (opno)
  1458.     {
  1459.     case ADD :
  1460.         add_fields7(fd_sys, buffer);
  1461.         sprintf(action, Oaddrec, fd[fd_sys].filname, ofd[fd_sys].fieldlist, ofd[fd_sys].values);
  1462.         break;
  1463.     case UPD :
  1464.         add_values7(fd_sys, buffer);
  1465.         sprintf(action, Oupdrec, fd[fd_sys].filname, ofd[fd_sys].values, ofd[fd_sys].currowid);
  1466.         break;
  1467.     case DEL :
  1468.         sprintf(action, Odelrec, fd[fd_sys].filname, delrowid);
  1469.         break;
  1470.     case PAR :
  1471.    case EXA :
  1472.    case  99 :  /* Special - NIG */
  1473.    case NXT :
  1474.    case PRV :
  1475.       sprintf(ofd[fd_sys].findaction, multi, ofd[fd_sys].fieldlist, ",ROWID", fd[fd_sys].filname, search_action(fd_sys, opno, buffer), order_action(fd_sys));
  1476.         break;
  1477.     case LAS :
  1478.       if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
  1479.            sprintf(action, dlast, fin->fldname, MINDATE, fd[fd_sys].filname);
  1480.       else
  1481.            sprintf(action, last, fin->fldname, fd[fd_sys].filname);
  1482.         break;
  1483.     }
  1484. }
  1485.  
  1486.  
  1487. /*
  1488.  * Build up the search string, be it exact or partial
  1489. */
  1490. static char *search_action(fd_sys, optyp, buffer)
  1491. int fd_sys, optyp;
  1492. char *buffer;
  1493. {
  1494.     int n, ix, ck, ofs, nochrval;
  1495.     short tmp_i;            /* Temp variables */
  1496.     long tmp_l;
  1497.     float tmp_f;
  1498.     double tmp_d;
  1499.     char tmps[OTMPSTR_LEN], tmpf[25], tcomp[3];
  1500.    static char tmpsrch[MAX_SEGS * (FLDNAME_LEN + MAX_FLDLEN + 7) + 1];
  1501.     struct fldinfx *fin;
  1502.  
  1503.    ck = fd[fd_sys].cur_key;
  1504.    if (optyp == EXA || optyp == 99)  /* Special Match - NIG */
  1505.       strcpy(tcomp, "=");
  1506.    else
  1507.       strcpy(tcomp, ">=");
  1508. /*
  1509.    else if (ofd[fd_sys].direction == FORWARD)
  1510.       strcpy(tcomp, ">=");
  1511.    else
  1512.       strcpy(tcomp, "<=");
  1513. */
  1514.  
  1515.    zerorec(tmpsrch, MAX_SEGS * (FLDNAME_LEN + MAX_FLDLEN + 7));
  1516.  
  1517.    for (n = 0; n < fd[fd_sys].keys[ck].segcount; n++)
  1518.    {
  1519.        ix = fd[fd_sys].keys[ck].fldindex[n];
  1520.        fin = &fd[fd_sys].flds[ix];
  1521.       nochrval = FALSE;
  1522.  
  1523.        switch (fin->fldtype)
  1524.        {
  1525.         case DATTYP :
  1526.             if (fin->fldlen == 6)
  1527.             {
  1528.             sprintf(tmpf, "trunc(%s)", fin->fldname);
  1529.                 if (!*((char *)buffer + fin->fldstart))
  1530.                sprintf(tmps, "'%s'", MINDATE);
  1531.                 else
  1532.             {
  1533.                strcpy(tmps, "'");
  1534.                    sprintf(&tmps[1], "%s", conv2_Odate((char *)buffer + fin->fldstart));
  1535.                strcat(tmps, "'");
  1536.             }
  1537.                 break;
  1538.             }        /* else fall through to LNGTYP - do not put a break here!!! */
  1539.         case LNGTYP :                /* don't move this - it must follow DATTYP */
  1540.          sprintf(tmpf, "nvl(%s,0)", fin->fldname);
  1541.             bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
  1542.             sprintf(tmps, "%ld", tmp_l);
  1543.             break;
  1544.         case CHRTYP :
  1545.          ofs = 1;
  1546.            if ((fd[fd_sys].keys[ck].segstart[n] == fin->fldstart)
  1547.               && (fd[fd_sys].keys[ck].seglen[n] == fin->fldlen))
  1548.             strcpy(tmpf, fin->fldname);
  1549.          else
  1550.          {
  1551.                ofs = fd[fd_sys].keys[ck].segstart[n] - fin->fldstart + 1;
  1552.                 sprintf(tmpf, "SUBSTR(%s,%d,%d)", fin->fldname, ofs, fd[fd_sys].keys[ck].seglen[n]);
  1553.          }
  1554.          if (!buffer[fin->fldstart] || (buffer[fin->fldstart] == ' '))
  1555.          {
  1556.             nochrval = TRUE;             /* excludes empty char key segments */ 
  1557.                 strcpy(tmps, "' '");
  1558.          }
  1559.             else
  1560.             {
  1561.             strcpy(tmps, "'");
  1562.                 fstrcpy(&tmps[1], (char *)buffer + fin->fldstart + ofs - 1, fd[fd_sys].keys[ck].seglen[n]);
  1563.                 cvt_str(tmps, 2);
  1564.             strcat(tmps, "'");
  1565.             }
  1566.             break;
  1567.         case INTTYP :
  1568.          sprintf(tmpf, "nvl(%s,0)", fin->fldname);
  1569.             bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
  1570.             sprintf(tmps, "%d", tmp_i);
  1571.             break;
  1572.         case FLTTYP :
  1573.          sprintf(tmpf, "nvl(%s,0.0)", fin->fldname);
  1574.             bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
  1575.             sprintf(tmps, "%f", tmp_f);
  1576.             break;
  1577.         case DBLTYP :
  1578.          sprintf(tmpf, "nvl(%s,0.0)", fin->fldname);
  1579.             bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
  1580.             sprintf(tmps, "%lf", tmp_d);
  1581.             break;
  1582.        }
  1583.  
  1584.         if (!nochrval || (n == 0))
  1585.         {
  1586.             if (n > 0)
  1587.                 strcat(tmpsrch, " AND ");
  1588.             strcat(tmpsrch, tmpf);
  1589.             strcat(tmpsrch, tcomp);
  1590.             strcat(tmpsrch, tmps);
  1591.         }
  1592.         if ((optyp == NXT) || (optyp == PRV))   /* no segs used for next/prev */
  1593.             return(tmpsrch);
  1594.  
  1595.         /*
  1596.          * Omit the last segment for Match Type 99
  1597.         */
  1598.         if (optyp == 99 && (n + 1) == (fd[fd_sys].keys[ck].segcount - 1))
  1599.             break;
  1600.    }
  1601.  
  1602.    return(tmpsrch);
  1603. }
  1604.  
  1605.  
  1606. /*
  1607.  *  Builds a target string for ORDER BY, 
  1608.  *  allowing for compound and substring keys
  1609. */
  1610. static char *order_action(fd_sys)
  1611. int fd_sys;
  1612. {
  1613.     int n, ix, scnt, ck, ofs;
  1614.     char tstr[50];
  1615.     static char ostr[250];
  1616.  
  1617.     zerorec(ostr, 199);
  1618.     ck = fd[fd_sys].cur_key;
  1619.     scnt = fd[fd_sys].keys[ck].segcount;
  1620.     for (n = 0; n < scnt; n++)
  1621.     {
  1622.         ix = fd[fd_sys].keys[ck].fldindex[n];
  1623.         if ((fd[fd_sys].keys[ck].segstart[n] == fd[fd_sys].flds[ix].fldstart)
  1624.           && (fd[fd_sys].keys[ck].seglen[n] == fd[fd_sys].flds[ix].fldlen))
  1625.             strcat(ostr, fd[fd_sys].flds[ix].fldname);
  1626.         else                    /* a substring key, use SQL SUBSTR() function */
  1627.         {
  1628.             ofs = fd[fd_sys].keys[ck].segstart[n] - fd[fd_sys].flds[ix].fldstart + 1;
  1629.             sprintf(tstr, "SUBSTR(%s,%d,%d)", fd[fd_sys].flds[ix].fldname, 
  1630.                     ofs, fd[fd_sys].keys[ck].seglen[n]);
  1631.             strcat(ostr, tstr);
  1632.         }
  1633. /*
  1634.       if (ofd[fd_sys].direction == BACKWARD)
  1635.          strcat(ostr, " DESC");
  1636. */
  1637.         strcat(ostr, ",");
  1638.     }
  1639.     if (ostr[0])
  1640.         ostr[strlen(ostr)-1] ='\0';          /* removes last & unneeded comma */
  1641.     return(ostr);
  1642. }
  1643.  
  1644.  
  1645. /*
  1646.  * Tell Oracle about the postions, and types of each
  1647.  * field, so that it knows where to put the values
  1648.  * after retrieving them.
  1649. */
  1650. static int assign_fields7(fd_sys, buffer, rowidbuf)
  1651. int fd_sys;
  1652. char *buffer;
  1653. int rowidbuf;
  1654. {
  1655.     int stat, fcnt;
  1656.     struct fldinfx *fin = fd[fd_sys].flds;
  1657.  
  1658.    if (ofd[fd_sys].lasttype == rowidbuf)    /* don't need to do this if same */
  1659.       return(IOGOOD);
  1660.    ofd[fd_sys].lasttype = rowidbuf;
  1661.  
  1662.     /*
  1663.      * One of these for each field !!!
  1664.      *
  1665.      * For each date field, tell Oracle to place
  1666.      * the value in a special place, for later conversion.
  1667.     */
  1668.     for (fcnt = 0, d_ptr = d_hdr[fd_sys]; fcnt < fd[fd_sys].fld_cnt; fcnt++, fin++)
  1669.     {
  1670.         if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
  1671.         {
  1672.             d_ptr->d_off = fin->fldstart;
  1673.             odefin(&ofd[fd_sys].scurs, fcnt+1, d_ptr->d_str, 10, dtyp7(fin->fldtype),
  1674.                 -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
  1675.             d_ptr = d_ptr->nxt_d;
  1676.         }
  1677.         else
  1678.         {
  1679.             if (fin->fldtype == DATTYP)                   /* long int date only */
  1680.                 odefin(&ofd[fd_sys].scurs, fcnt+1, (char *)(buffer + fin->fldstart),
  1681.                fin->fldlen, dtyp7(LNGTYP),
  1682.                    -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
  1683.             else
  1684.                 odefin(&ofd[fd_sys].scurs, fcnt+1, (char *)(buffer + fin->fldstart),
  1685.                fin->fldlen, dtyp7(fin->fldtype),
  1686.                    -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
  1687.         }
  1688.         if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Assign0")) != IOGOOD)
  1689.             return (stat);
  1690.     }
  1691.  
  1692. /*
  1693.  * define ROWID field at the end of the field list
  1694. */
  1695.    if (rowidbuf == CURBUFF)
  1696.       odefin(&ofd[fd_sys].scurs, fcnt+1, ofd[fd_sys].currowid, 18, 1,
  1697.             -1, (short *)0, (char *)0, -1, -1, &rowid_len, &rowid_err);
  1698.    else
  1699.       odefin(&ofd[fd_sys].scurs, fcnt+1, ofd[fd_sys].tmprowid, 18, 1,
  1700.             -1, (short *)0, (char *)0, -1, -1, &rowid_len, &rowid_err);
  1701.     if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Assign1")) != IOGOOD)
  1702.       return(stat);
  1703.  
  1704.     return (IOGOOD);
  1705. }
  1706.  
  1707.  
  1708. /*
  1709.  * Maps PRO-C data type to Oracle data type:
  1710.  * Numbers are straightforward.
  1711.  * Chars are space padded to a max length; if they are Null
  1712.  * terminated, the last character will be trashed.
  1713.  * Dates can be null terminated; the o_dates struct has
  1714.  * enough room for the date; this is converted ok with the
  1715.  * fmt_ & get_ date routines.
  1716. */
  1717. static int dtyp7(dtype)
  1718. int dtype;
  1719. {
  1720.     switch (dtype)
  1721.     {
  1722.     case  DATTYP :
  1723.         return (5);   /* 5 is NULL terminated ( room in o_dates for Null) */
  1724.     case  MEMTYP :
  1725.         return (1);   /* 8 is Oracle LONG type but OCI doesn't like it */
  1726.     case  CHRTYP :
  1727.         return (1);   /* 1 is SPACE filled ( no room in PRO-C buffer for Null) */
  1728.     case  INTTYP :
  1729.     case  LNGTYP :
  1730.         return (3);
  1731.     case  FLTTYP :
  1732.     case  DBLTYP :
  1733.         return (4);
  1734.     }
  1735. }
  1736.  
  1737.  
  1738. # ifdef ODEBUG
  1739. /*
  1740.  * Find out the names associated with the columns 
  1741.  * in an Oracle Table - debug
  1742. */
  1743. static void get_idx7(fd_sys)
  1744. int fd_sys;
  1745. {
  1746.     struct fldinfx *fin = fd[fd_sys].flds;
  1747.     int i;
  1748.     int len = 10;
  1749.     char buff[20], tmp[50];
  1750.  
  1751.     sprintf(action, "SELECT * FROM %s", fd[fd_sys].filname);
  1752.     dspactn(action, fd_sys, "GET_IDX");
  1753.     osql3(&ofd[fd_sys].scurs, "SELECT * FROM EMP", -1); 
  1754.  
  1755.     for (i = 0;  i < fd[fd_sys].fld_cnt;  i++)
  1756.     {
  1757.         oname(&ofd[fd_sys].scurs, i+1, (short *)0, (short *)0, buff, &len);
  1758.         sprintf(tmp, "%d = %.10s\n", i+1, buff);
  1759.         dspactn(tmp, fd_sys, "IDXloop");
  1760.     }
  1761. }
  1762. # endif
  1763.  
  1764. /*
  1765.  * Create a string containing values to be inserted into a table
  1766.  * insert into emp(a, b, c) values ('me', 'you', 123)"
  1767.  *
  1768.  * Date fields are converted directly from PRO-C format
  1769.  * to Oracle format, by using conv2_Odate() (fmt_date() in V1.3).
  1770. */
  1771. static void add_fields7(fd_sys, buffer)
  1772. int fd_sys;
  1773. char *buffer;
  1774. {
  1775.     struct fldinfx *fin = fd[fd_sys].flds;
  1776.     static char tmp3[OACTION_LEN+1];    /* value */
  1777.     static char tmp2[OACTION_LEN+1];
  1778.     int fcnt, j, k, n, p;
  1779.     short tmp_i;            /* Temp variables */
  1780.     long tmp_l;
  1781.     float tmp_f;
  1782.     double tmp_d;
  1783.  
  1784.     for (*ofd[fd_sys].values = '\0', fcnt = 0;  fcnt < fd[fd_sys].fld_cnt;  fcnt++, fin++)
  1785.     {
  1786.         zerorec(tmp2, OACTION_LEN);
  1787.         zerorec(tmp3, OACTION_LEN);
  1788.  
  1789.         switch(fin->fldtype)
  1790.         {
  1791.         case DATTYP :
  1792.             if (fin->fldlen == 6)
  1793.             {
  1794.                 memcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
  1795.                 if (strlen(tmp2) < 6)
  1796.                     sprintf(tmp3, "NULL");
  1797.                 else
  1798.                     sprintf(tmp3, "'%s'", conv2_Odate(tmp2));
  1799.                 break;
  1800.             }
  1801.         case LNGTYP :   /* do not move this - long int date must fall through */
  1802.             bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
  1803.             sprintf(tmp3, "%ld", tmp_l);
  1804.             break;
  1805.         case MEMTYP :
  1806.             zerorec(tmp3, OACTION_LEN);
  1807.             p = strlen(buffer + fin->fldstart);
  1808.             if (p > fin->fldlen)
  1809.                 p = fin->fldlen; 
  1810.             for (j = 0, k = 0; j < p; j+=240)
  1811.             {
  1812.                 n = (j+240 < p) ? 240 : p-j;
  1813.                 fstrcpy(tmp2, (char *)buffer + fin->fldstart + j, n);
  1814.                 sprintf(&tmp3[k], "'%s'", tmp2);
  1815.                 if (j+240 < p)
  1816.                 {
  1817.                     strcat(tmp3, "\|\|");
  1818.                     k = strlen(tmp3);
  1819.                 }
  1820.             }
  1821.             break;
  1822.         case CHRTYP :
  1823.             fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
  1824.             sprintf(tmp3, "'%s'", cvt_str(tmp2, 2));
  1825.             break;
  1826.         case INTTYP :
  1827.             bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
  1828.             sprintf(tmp3, "%d", tmp_i);
  1829.             break;
  1830.         case FLTTYP :
  1831.             bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
  1832.             sprintf(tmp3, "%f", tmp_f);
  1833.             break;
  1834.         case DBLTYP :
  1835.             bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
  1836.             sprintf(tmp3, "%lf", tmp_d);
  1837.             break;
  1838.         }
  1839.  
  1840.         strcat(ofd[fd_sys].values, tmp3);
  1841.  
  1842.         if (fcnt < fd[fd_sys].fld_cnt-1)
  1843.             strcat(ofd[fd_sys].values, ", ");
  1844.     }
  1845. }
  1846.  
  1847.  
  1848. /*
  1849.  * Create search string for all keys set in PRO-C
  1850. */
  1851. static void add_keys7(fd_sys, buffer)
  1852. int fd_sys;
  1853. char *buffer;
  1854. {
  1855.     struct fldinfx *fin;
  1856.     char tmp3[256];    /* value */
  1857.     char tmp2[256];
  1858.     int fcnt, ix;
  1859.     short tmp_i;            /* Temp variables */
  1860.     long tmp_l;
  1861.     float tmp_f;
  1862.     double tmp_d;
  1863.  
  1864.     /*
  1865.      * For every key
  1866.     */
  1867.     for (*ofd[fd_sys].fields = '\0', fcnt = 0;  fcnt < fd[fd_sys].key_cnt;  fcnt++)
  1868.     {
  1869.         ix = fd[fd_sys].keys[fcnt].fldindex[0];
  1870.         fin = &fd[fd_sys].flds[ix];               /* field info for key# fcnt */
  1871.  
  1872.         switch(fin->fldtype)
  1873.         {
  1874.         case DATTYP :
  1875.             if (fin->fldlen == 6)
  1876.             {
  1877.                 fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
  1878.                 if(!*tmp2)
  1879.                     sprintf(tmp3, "%s IS NULL", fin->fldname);
  1880.                 else
  1881.                     sprintf(tmp3, "trunc(%s)='%s'", fin->fldname, conv2_Odate(tmp2));
  1882.                 break;
  1883.             }
  1884.         case LNGTYP :   /* do not move this - long int dates must fall through */
  1885.             bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
  1886.             sprintf(tmp3, "nvl(%s,0)=%ld", fin->fldname, tmp_l);
  1887.             break;
  1888.         case CHRTYP :
  1889.             fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
  1890.             if(!*cvt_str(tmp2, 2))
  1891.                 sprintf(tmp3, "%s IS NULL", fin->fldname);
  1892.             else
  1893.                 sprintf(tmp3, "%s='%s'", fin->fldname, tmp2);
  1894.             break;
  1895.         case INTTYP :
  1896.             bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
  1897.             sprintf(tmp3, "nvl(%s,0)=%d", fin->fldname, tmp_i);
  1898.             break;
  1899.         case FLTTYP :
  1900.             bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
  1901.             sprintf(tmp3, "nvl(%s,0.0)=%f", fin->fldname, tmp_f);
  1902.             break;
  1903.         case DBLTYP :
  1904.             bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
  1905.             sprintf(tmp3, "nvl(%s,0.0)=%lf", fin->fldname, tmp_d);
  1906.             break;
  1907.         }
  1908.  
  1909.         strcat(ofd[fd_sys].fields, tmp3);
  1910.  
  1911.         if (fcnt < fd[fd_sys].key_cnt-1)
  1912.             strcat(ofd[fd_sys].fields, " AND ");
  1913.     }
  1914. }
  1915.  
  1916.  
  1917. /*
  1918.  * Build string of update values
  1919. */
  1920. static void add_values7(fd_sys, buffer)
  1921. int fd_sys;
  1922. char *buffer;
  1923. {
  1924.     struct fldinfx *fin = fd[fd_sys].flds;
  1925.     static char tmp3[OACTION_LEN+1];    /* value */
  1926.     static char tmp2[OACTION_LEN+1];
  1927.     int fcnt, j, k, n, p;
  1928.     short tmp_i;            /* Temp variables */
  1929.     long tmp_l;
  1930.     float tmp_f;
  1931.     double tmp_d;
  1932.  
  1933.     for (*ofd[fd_sys].values = '\0', fcnt = 0;  fcnt < fd[fd_sys].fld_cnt;  fcnt++, fin++)
  1934.     {
  1935.         zerorec(tmp2, OACTION_LEN);
  1936.         zerorec(tmp3, OACTION_LEN);
  1937.  
  1938.         switch(fin->fldtype)
  1939.         {
  1940.         case DATTYP :
  1941.             if (fin->fldlen == 6)
  1942.             {
  1943.                 fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
  1944.                 if (strlen(tmp2) < 6)
  1945.                     sprintf(tmp3, "%s=NULL", fin->fldname);
  1946.                 else
  1947.                     sprintf(tmp3, "%s='%s'", fin->fldname, conv2_Odate(tmp2));
  1948.                 break;
  1949.             }
  1950.         case LNGTYP :   /* do not move this - long int dates must fall through */
  1951.             bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
  1952.             sprintf(tmp3, "%s=%ld", fin->fldname, tmp_l);
  1953.             break;
  1954.         case MEMTYP :
  1955.             zerorec(tmp3, OACTION_LEN);
  1956.             p = strlen(buffer + fin->fldstart);
  1957.             if (p > fin->fldlen)
  1958.                 p = fin->fldlen; 
  1959.             sprintf(tmp3, "%s=", fin->fldname);
  1960.             k = strlen(tmp3);
  1961.             for (j = 0; j < p; j+=240)
  1962.             {
  1963.                 n = (j+240 < p) ? 240 : p-j;
  1964.                 fstrcpy(tmp2, (char *)buffer + fin->fldstart + j, n);
  1965.                 sprintf(&tmp3[k], "'%s'", tmp2);
  1966.                 if (j+240 < p)
  1967.                 {
  1968.                     strcat(tmp3, "\|\|");
  1969.                     k = strlen(tmp3);
  1970.                 }
  1971.             }
  1972.             break;
  1973.         case CHRTYP :
  1974.             fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
  1975.             sprintf(tmp3, "%s='%s'", fin->fldname, cvt_str(tmp2, 2));
  1976.             break;
  1977.         case INTTYP :
  1978.             bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
  1979.             sprintf(tmp3, "%s=%d", fin->fldname, tmp_i);
  1980.             break;
  1981.         case FLTTYP :
  1982.             bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
  1983.             sprintf(tmp3, "%s=%f", fin->fldname, tmp_f);
  1984.             break;
  1985.         case DBLTYP :
  1986.             bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
  1987.             sprintf(tmp3, "%s=%lf", fin->fldname, tmp_d);
  1988.             break;
  1989.         }
  1990.  
  1991.         strcat(ofd[fd_sys].values, tmp3);
  1992.  
  1993.         if (fcnt < fd[fd_sys].fld_cnt-1)
  1994.             strcat(ofd[fd_sys].values, ", ");
  1995.     }
  1996. }
  1997.  
  1998.  
  1999. /*
  2000.  * Check newly retrieved row id against retained values
  2001.  * and return TRUE if matching
  2002. */
  2003. static int chk_rowid(fd_sys, prv_rowid)
  2004. int fd_sys;
  2005. char *prv_rowid;
  2006. {
  2007. #ifdef ODEBUG
  2008.    dsp_rowid(fd_sys, "CHECKING");
  2009. #endif
  2010.    if (!memcmp(ofd[fd_sys].tmprowid, ofd[fd_sys].oldrowid, 18))
  2011.     {
  2012. errmsg("chk_row (tmp == old)");
  2013.       return(TRUE);
  2014.     }
  2015.  
  2016.     if (!memcmp(ofd[fd_sys].currowid, prv_rowid, 18))
  2017.     {
  2018. errmsg("chk_row (cur == prv)");
  2019.       return(TRUE);
  2020.     }
  2021.  
  2022.     return (FALSE);
  2023. }
  2024.  
  2025.  
  2026. #ifdef ODEBUG
  2027. static void dsp_rowid(fd_sys, titl)
  2028. int fd_sys;
  2029. char *titl;
  2030. {
  2031.    errmsg("%s - %s \n length: %d \n error: %d \n Retained rowid: >%s< \n Current rowid:  >%s< \n Next Rec rowid: >%s< \n Prev Rec rowid: >%s<", fd[fd_sys].filname, titl, rowid_len, rowid_err, ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, ofd[fd_sys].tmprowid, ofd[fd_sys].prvrowid);
  2032. }
  2033. #endif
  2034.  
  2035.  
  2036. /*
  2037.  * Build a linked list of date structures for each Table, 
  2038.  * to hold the offset and ORACLE representation of each 
  2039.  * date field in the table, * which will be filled by each 
  2040.  * ofetch() call.
  2041.  * - this will add to the list ONLY for character date types (len 6)
  2042.  *
  2043.  * Conversions to PRO-C format, will take place after 
  2044.  * each ofetch() call, by using get_date().
  2045. */
  2046. static void load_dates7(fd_sys)
  2047. int fd_sys;
  2048. {
  2049.     struct fldinfx *fin;
  2050.     struct o_dates *dp;
  2051.     int i;
  2052.  
  2053.     fin = fd[fd_sys].flds;
  2054.  
  2055.     /*
  2056.      * Scan the fldinfo list, and check every field.
  2057.     */
  2058.     for (d_ptr = d_hdr[fd_sys] = (struct o_dates *)0, i = 0;  i < fd[fd_sys].fld_cnt;  i++, fin++)
  2059.         if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
  2060.         {
  2061.             /*
  2062.              * Another date field, so add on to end of list
  2063.             */
  2064.             dp = macalloc(struct o_dates);
  2065.             dp->d_off = fin->fldstart;
  2066.             dp->nxt_d = (struct o_dates *)0;
  2067.  
  2068.             if (d_ptr != (struct o_dates *)0)
  2069.                 d_ptr->nxt_d = dp;
  2070.  
  2071.             d_ptr = dp;
  2072.  
  2073.             if (d_hdr[fd_sys] == (struct o_dates *)0)
  2074.                 d_hdr[fd_sys] = d_ptr;
  2075.         }
  2076. }
  2077.  
  2078.  
  2079. /*
  2080.  * Release Memory, reset pointers associated with o_dates
  2081. */
  2082. static void free_dates7(fd_sys)
  2083. int fd_sys;
  2084. {
  2085.     struct o_dates *dp;
  2086.  
  2087.     /*
  2088.      * Scan the date list, and free every entry.
  2089.     */
  2090.     for (dp = d_hdr[fd_sys];  dp != (struct o_dates *)0;  )
  2091.     {
  2092.         d_ptr = dp->nxt_d;
  2093.         free(dp);
  2094.         dp = d_ptr;
  2095.     }
  2096.     d_hdr[fd_sys] = (struct o_dates *)0;
  2097. }
  2098.  
  2099.  
  2100. static char *conv_Odate(dstr)      /* change Oracle date to PRO-C char date */
  2101. char *dstr;
  2102. {
  2103.     int ofs;
  2104.     char tmp3[4];
  2105.     static char tmp[7];
  2106.     static char mnths[37] = { "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC" };
  2107.     static char mnums[25] = { "010203040506070809101112" };
  2108.  
  2109.     strncpy(tmp, &dstr[7], 2);
  2110.     strncpy(tmp3, &dstr[3], 3); tmp3[3] = '\0';
  2111.     ofs = (36 - strlen(strstr(mnths, tmp3)))/3;
  2112.     if (ofs != 12)
  2113.     {
  2114.         strncpy(&tmp[2], &mnums[ofs*2], 2);
  2115.         strncpy(&tmp[4], dstr, 2);
  2116.         tmp[6] = '\0';
  2117.     }
  2118.     else
  2119.         strcpy(tmp, "");
  2120.  
  2121.     return(tmp);
  2122. }
  2123.  
  2124.  
  2125. static char *conv2_Odate(dstr)     /* change PRO-C char date to Oracle date */
  2126. char *dstr;
  2127. {
  2128.     int ofs;
  2129.     char tmp2[3];
  2130.     static char tmp[10];
  2131.     static char mnths[37] = { "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC" };
  2132.  
  2133.     if (!dstr[0])
  2134.         strcpy(tmp, MINDATE);
  2135.     else
  2136.     {
  2137.         strncpy(tmp, &dstr[4], 2);
  2138.         tmp[2] = '-';
  2139.         strncpy(tmp2, &dstr[2], 2); tmp2[2] = '\0';
  2140.         ofs = atoi(tmp2);
  2141.         if (ofs > 12)
  2142.             strcpy(tmp, MINDATE);
  2143.         else
  2144.         {
  2145.             strncpy(&tmp[3], &mnths[(ofs-1)*3], 3);
  2146.             tmp[6] = '-';
  2147.             strncpy(&tmp[7], dstr, 2);
  2148.             tmp[9] = '\0';
  2149.         }
  2150.     }
  2151.  
  2152.     return(tmp);
  2153. }
  2154.  
  2155.  
  2156. static int is_chardate(fd_sys, fldoff)
  2157. int fd_sys, fldoff;
  2158. {
  2159.     int n;
  2160.  
  2161.     for (n = 0; n < fd[fd_sys].fld_cnt; n++)
  2162.         if (fd[fd_sys].flds[n].fldstart == fldoff)
  2163.             return(fd[fd_sys].flds[n].fldlen == 6);
  2164.  
  2165.     return(FALSE);          /* long is shorter in buffer, so a safer default */
  2166. }
  2167.  
  2168.  
  2169. /*
  2170.  * Returns TRUE if field designated as key is unique -
  2171.  * but only if it's a simple key, not a compound
  2172. */
  2173. static int unique_fld7(fd_sys, fin)
  2174. int fd_sys;
  2175. struct fldinfx *fin;
  2176. {
  2177.     int ix, n;
  2178.  
  2179.     for (ix = 0; ix < fd[fd_sys].fld_cnt; ix++)
  2180.         if (fin->fldstart == fd[fd_sys].flds[ix].fldstart)
  2181.             break;
  2182.  
  2183.     if (ix < fd[fd_sys].fld_cnt)
  2184.         for (n = 0; n < fd[fd_sys].key_cnt; n++)
  2185.             if ((ix == fd[fd_sys].keys[n].fldindex[0])
  2186.                     && (fd[fd_sys].keys[n].segcount == 1)
  2187.                     && (fd[fd_sys].keys[n].keytype == KEY_UNIQUE))
  2188.                 return(TRUE);        /* index of key field into fldinfx matches */
  2189.  
  2190.     return(FALSE);                              /* field is not a unique key */
  2191. }
  2192.  
  2193.  
  2194. /*
  2195.  *  End (Commit) transaction
  2196. */
  2197. static int i_commit(fd_sys, buffer)
  2198. int fd_sys;
  2199. char *buffer;
  2200. {
  2201.     int stat;
  2202.  
  2203.     ocom(&lda);
  2204.     if ((stat = io_xlate(fd_sys, lda.orarc, "Commit")) != IOGOOD)
  2205.         return (stat);
  2206.  
  2207.    return(IOGOOD);
  2208. }
  2209.  
  2210. /*
  2211.  *  Rollback transaction
  2212. */
  2213. static int i_rollback(fd_sys, buffer)
  2214. int fd_sys;
  2215. char *buffer;
  2216. {
  2217.     int stat;
  2218.  
  2219.     orol(&lda);
  2220.     if ((stat = io_xlate(fd_sys, lda.orarc, "Rollback")) != IOGOOD)
  2221.         return (stat);
  2222.  
  2223.    return(IOGOOD);
  2224. }
  2225.  
  2226. /*
  2227.  *  Start transaction
  2228. */
  2229. static int i_transact(fd_sys, buffer)
  2230. int fd_sys;
  2231. char *buffer;
  2232. {
  2233.    return(IOGOOD);
  2234. }
  2235.  
  2236.  
  2237. /*
  2238.  *  This routine translates C-ISAM Error codes into PRO-C error codes.
  2239.  *  If no PRO-C equivalent, displays the error number.
  2240. */
  2241. static int io_xlate(fd_sys, ernum, rtnname)
  2242. int fd_sys;
  2243. int ernum;
  2244. char *rtnname;
  2245. {
  2246.     switch(ernum)
  2247.     {
  2248.         case 0 :
  2249.         case 3 :
  2250.             return (IOGOOD);
  2251.         case 4 :
  2252.             return (IOEOF);
  2253.         case -1004 :
  2254.         case -1005 :
  2255.         case -1017 :
  2256.             errmsg("Invalid Username/Password - Aborting");
  2257.             return (IONOLOGON);
  2258.         case -3121 :
  2259.             errmsg("ORACLE has not been loaded !");
  2260.             return (IOERROR);
  2261.    }
  2262.  
  2263.    if (fd_sys >= 0)
  2264.       errmsg(FileDbgError_sdss, "ORACLE", ernum, fd[fd_sys].filname, rtnname);
  2265.    else      /* if routines called from generated apps without valid fd_sys */
  2266.       errmsg(FileDbgError_sds, "ORACLE", ernum, rtnname);
  2267.    return(IOERROR);
  2268. }
  2269.  
  2270.  
  2271. # ifdef ODEBUG
  2272. static void dspactn(actn, fd_sys, optype)
  2273. int fd_sys;
  2274. char *actn, *optype;
  2275. {
  2276.    int i, j, k, l;
  2277.    char titl[35];
  2278.     errmsg("%s : \n%s", optype, actn);
  2279.     return;
  2280.  
  2281.    strcpy(titl, " Action: ");
  2282.    strcat(titl, optype);
  2283.    strcat(titl, " ");
  2284.    if (fd_sys > -1)
  2285.    {
  2286.       strcat(titl, fd[fd_sys].filname);
  2287.       strcat(titl, " ");
  2288.    }
  2289.  
  2290.    k = strlen(actn);
  2291.    create_w(17, 1, 3+k/76, 80);
  2292.    border_w(0, BLINK);
  2293.    disp_w(1, 5, BOLDUNDER, titl);
  2294.  
  2295.    for (j = 0, i = 0; i <= k; j++, i+=76)
  2296.       for (l = 0; (l < 76) && (l+i <= k); l++)
  2297.          poke_w(2+j, 3+l, BOLD, actn[i+l]);
  2298.  
  2299.    while (inchar() != K_CR)
  2300.       ;
  2301.    flushscr();
  2302.    delete_w();
  2303. }
  2304. # endif
  2305.  
  2306.  
  2307. # ifdef ODEBUG
  2308. static void dspflds(buffer, fd_sys, optype)
  2309. int fd_sys;
  2310. char *buffer, *optype;
  2311. {
  2312.    int j, ofs, flen, tlen;
  2313.     short itmp;
  2314.    long ltmp;
  2315.    float ftmp;
  2316.    double dtmp;
  2317.    char titl[35];
  2318.  
  2319.    strcpy(titl, " Fields: ");
  2320.    strcat(titl, optype);
  2321.    strcat(titl, " ");
  2322.    if (fd_sys > -1)
  2323.    {
  2324.       strcat(titl, fd[fd_sys].filname);
  2325.       strcat(titl, " ");
  2326.    }
  2327.  
  2328.    create_w(9, 39, 12, 40);
  2329.    border_w(0, BLINK);
  2330.    disp_w(1, 3, BOLDUNDER, titl);
  2331.  
  2332.    for (j = 0; (j < fd[fd_sys].fld_cnt) && (j < 10); j++)
  2333.    {
  2334.       disp_w(2+j, 2, NORMAL, fd[fd_sys].flds[j].fldname);
  2335.       ofs = fd[fd_sys].flds[j].fldstart;
  2336.       flen = fd[fd_sys].flds[j].fldlen;
  2337.  
  2338.       switch(fd[fd_sys].flds[j].fldtype)
  2339.       {
  2340.          case CHRTYP :
  2341.             tlen = (flen < 25) ? flen : 25;
  2342.             zerorec(titl, 34);
  2343.             strncpy(titl, &buffer[ofs], tlen);
  2344.             ndisp_w(2+j, 13, BOLD, tlen, titl);
  2345.             break;
  2346.          case INTTYP :
  2347.             memcpy(&itmp, &buffer[ofs], sizeof(short));
  2348.             disp_w(2+j, 13, BOLD, fmt_int(itmp, "zzzz9"));
  2349.             break;
  2350.          case LNGTYP : 
  2351.             memcpy(<mp, &buffer[ofs], sizeof(long));
  2352.             disp_w(2+j, 13, BOLD, fmt_lng(ltmp, "zzzzzzzzzz9"));
  2353.             break;
  2354.          case FLTTYP :
  2355.             memcpy(&ftmp, &buffer[ofs], sizeof(float));
  2356.             dtmp = (double)ftmp;
  2357.             disp_w(2+j, 13, BOLD, fmt_dbl(dtmp, "zzzzzzzzz9.99"));
  2358.             break;
  2359.          case DBLTYP :
  2360.             memcpy(&dtmp, &buffer[ofs], sizeof(double));
  2361.             disp_w(2+j, 13, BOLD, fmt_dbl(dtmp, "zzzzzzzzz9.99"));
  2362.             break;
  2363.          default :
  2364.             break;
  2365.       }
  2366.    }
  2367.  
  2368.    while (inchar() != K_CR)
  2369.       ;
  2370.    flushscr();
  2371.    delete_w();
  2372. }
  2373. # endif
  2374.  
  2375.  
  2376. # ifdef ODEBUG
  2377. static void dspbuff(buffer, fd_sys, optype)
  2378. int fd_sys;
  2379. char *buffer, *optype;
  2380. {
  2381.    int i, j, k, l;
  2382.    char titl[35], subtmp[77];
  2383.  
  2384. /*
  2385.     errmsg("%s : \n%s", optype, buffer);
  2386.     return;
  2387. */
  2388.    strcpy(titl, " Buffer: ");
  2389.    strcat(titl, optype);
  2390.    strcat(titl, " ");
  2391.    if (fd_sys > -1)
  2392.    {
  2393.       strcat(titl, fd[fd_sys].filname);
  2394.       strcat(titl, " ");
  2395.    }
  2396.  
  2397.    k = fd[fd_sys].rec_len;
  2398.    create_w(17, 1, 3+k/76, 80);
  2399.    border_w(0, BLINK);
  2400.    disp_w(1, 5, BOLDUNDER, titl);
  2401.  
  2402.    for (j = 0, i = 0; i <= k; j++, i+=76)
  2403.    {
  2404.       for (l = 0; (l < 76) && (l+i < k); l++)
  2405.          subtmp[l] = (isprint(buffer[i+l]) ? buffer[i+l] : (char)254);
  2406.       subtmp[l] = '\0';
  2407.       disp_w(2+j, 3, BOLD, subtmp);
  2408.    }
  2409.  
  2410.    while (inchar() != K_CR)
  2411.       ;
  2412.    flushscr();
  2413.    delete_w();
  2414. }
  2415. # endif
  2416.  
  2417.  
  2418. static void oraschmeggie(buf)
  2419. char *buf;
  2420. {
  2421.    int cur, new, left, right;
  2422.  
  2423.    left = 0;
  2424.    right = strlen(buf);
  2425.  
  2426.    while ((new = cur = left + MAX_ORA_BUFF) < right)
  2427.    {
  2428.       while (cur > left)
  2429.       {
  2430.      if (buf[cur] == ' ')
  2431.      {
  2432.         buf[cur] = '\n';
  2433.         new = cur;
  2434.         break;
  2435.      }
  2436.      cur--;
  2437.       }
  2438.       left = new;
  2439.    }
  2440. }
  2441.  
  2442.  
  2443. /*
  2444.  * Assign section
  2445. */
  2446.  
  2447. void assign_IO_OR(dbnum)
  2448. int dbnum;
  2449. {
  2450.    Fntab[dbnum - 1][0]  = (int(*)())0; /* Empty */
  2451.    Fntab[dbnum - 1][1]  = i_init_file;
  2452.    Fntab[dbnum - 1][2]  = i_open_file;
  2453.    Fntab[dbnum - 1][3]  = i_close_file;
  2454.    Fntab[dbnum - 1][4]  = i_addrec;
  2455.    Fntab[dbnum - 1][5]  = i_delrec;
  2456.    Fntab[dbnum - 1][6]  = i_findkey;
  2457.    Fntab[dbnum - 1][7]  = i_firstkey;
  2458.    Fntab[dbnum - 1][8]  = i_lastkey;
  2459.    Fntab[dbnum - 1][9]  = i_lockrec;
  2460.    Fntab[dbnum - 1][10] = i_nextrec;
  2461.    Fntab[dbnum - 1][11] = i_prevrec;
  2462.    Fntab[dbnum - 1][12] = i_unlock_rec;
  2463.    Fntab[dbnum - 1][13] = i_updrec;
  2464.    Fntab[dbnum - 1][14] = i_commit;
  2465.    Fntab[dbnum - 1][15] = i_login;
  2466.    Fntab[dbnum - 1][16] = i_logoff;
  2467.    Fntab[dbnum - 1][17] = i_rollback;
  2468.    Fntab[dbnum - 1][18] = i_transact;
  2469.    Fntab[dbnum - 1][19] = i_selectinx;
  2470.    Fntab[dbnum - 1][20] = i_rereadrec;
  2471.    Fntab[dbnum - 1][21] = i_filename;
  2472. }
  2473.  
  2474.