home *** CD-ROM | disk | FTP | other *** search
- /* ==( io/src/ioracle.c )== */
-
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written NA 05-Apr-89 */
- /* Modified VvA 23-May-90 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 23-May-90 VvA - separate cursors for update & reads
- * 15-May-90 VvA - compound key in SELECT ... WHERE ...
- * 13-Mar-90 VvA - allow use of PRO-C passwords if avail
- * 09-Mar-90 VvA - V.2 modifications
- */
-
- /* ORACLE specific I/O calls via IOGEN.C interface & ORACLE OCI calls */
-
-
- # include <stdio.h>
- # include <iodef.h>
- # include <iomsg.h>
- # include <proc.io>
- # include <bench.h>
- # include <iosup.h>
- # include <field.h>
-
-
- /*
- * OACTION_LEN is the size of a string to hold the SQL statement
- * eg. "SELECT * FROM <TABLE> ORDER BY <FIELD>
- * The longest statement will be an Update, and each key specified
- * in the PRO-C Data Definition will increase the length.
- */
- # define OACTION_LEN 4096
- # define OTMPSTR_LEN 80
- # define MINDATE "01-JAN-70"
- # define MAX_ORA_BUFF 75
-
- # define ODEBUG
-
-
- /* Function prototypes */
- # ifdef ANSI
- static int i_addrec(int, char *);
- static int i_close_file(int, char *);
- static int i_commit(int, char *);
- static int i_delrec(int, char *);
- static int i_filename(int, char *);
- static int i_findkey(int, char *);
- static int i_firstkey(int, char *);
- static int i_init_file(int, char *);
- static int i_lastkey(int, char *);
- static int i_lockrec(int, char *);
- static int i_login(int, char *);
- static int i_logoff(int, char *);
- static int i_nextrec(int, char *);
- static int i_open_file(int, char *);
- static int i_prevrec(int, char *);
- static int i_rereadrec(int, char *);
- static int i_rollback(int, char *);
- static int i_selectinx(int, char *);
- static int i_transact(int, char *);
- static int i_unlock_rec(int, char *);
- static int i_updrec(int, char *);
- static int create_file(int);
- static int io_xlate(int, int, char *);
- static int o_findkey(int, char *, int);
- static int o_firstkey(int, char *);
- static int o_nextrec(int, char *);
- # else
- static int i_addrec();
- static int i_close_file();
- static int i_commit();
- static int i_delrec();
- static int i_filename();
- static int i_findkey();
- static int i_firstkey();
- static int i_init_file();
- static int i_lastkey();
- static int i_lockrec();
- static int i_login();
- static int i_logoff();
- static int i_nextrec();
- static int i_open_file();
- static int i_prevrec();
- static int i_rereadrec();
- static int i_rollback();
- static int i_selectinx();
- static int i_transact();
- static int i_unlock_rec();
- static int i_updrec();
- static int create_file();
- static int io_xlate();
- static int o_findkey();
- static int o_firstkey();
- static int o_nextrec();
- # endif
-
-
- # ifdef ANSI
- static char *conv_Odate(char *);
- static char *conv2_Odate(char *);
- static char *order_action(int);
- static char *search_action(int, int, char *);
- static int assign_fields7(int, char *, int);
- static int chk_rowid(int, char *);
- static int create_file7(int);
- static int drop_table7(int);
- static int dtyp7(int );
- static int get_idname7(void);
- static int is_chardate(int, int);
- static int lock_table7(int);
- static int new_table7(int);
- static int unique_fld7(int, struct fldinfx *);
- static int validuid(char *);
- static void add_fields7(int ,char *);
- static void add_keys7(int ,char *);
- static void add_values7(int ,char *);
- static void build_action7(int, int, char *);
- static void close_all7(void );
- static void free_dates7(int );
- static void load_dates7(int );
- static void oraschmeggie(char *);
- static void savenext7(int);
- # else
- static char *conv_Odate();
- static char *conv2_Odate();
- static char *order_action();
- static char *search_action();
- static int assign_fields7();
- static int chk_rowid();
- static int create_file7();
- static int drop_table7();
- static int dtyp7();
- static int get_idname7();
- static int is_chardate();
- static int lock_table7();
- static int new_table7();
- static int unique_fld7();
- static int validuid();
- static void add_fields7();
- static void add_keys7();
- static void add_values7();
- static void build_action7();
- static void close_all7();
- static void free_dates7();
- static void load_dates7();
- static void oraschmeggie();
- static void savenext7();
- # endif
-
- # ifdef ODEBUG
- # ifdef ANSI
- static void get_idx7(int);
- static void dspactn(char *, int, char *);
- static void dspflds(char *, int, char *);
- static void dspbuff(char *, int, char *);
- static void dsp_rowid(int, char *);
- # else
- static void get_idx7();
- static void dspactn();
- static void dspflds();
- static void dspbuff();
- static void dsp_rowid();
- # endif
- # endif
-
-
- /*
- ** DEFINE ROW ID STRUCTURE (for within cursor)
- */
- struct orarowid
- { /* rowid structure */
- struct
- {
- unsigned long tidtrba; /* rba of first blockof table */
- unsigned short tidpid; /* partition id of table */
- unsigned char tidtbl; /* table id of table */
- } ridtid;
- unsigned long ridbrba; /* rba of datablock */
- unsigned short ridsqn; /* sequence number of row in block */
- };
-
- /*
- ** DEFINE THE c VERSION OF THE CURSOR (FOR 32 BIT MACHINES)
- */
- struct oradef
- {
- short orarc; /* return code */
- short oraft; /* function type */
- unsigned long orarpc; /* rows processed count */
- short orapeo; /* parse error offset */
- unsigned char orafc; /* function code */
- unsigned char orafil; /* filler */
- unsigned short oraarc; /* reserved, private */
- unsigned char orawrn; /* warning flags */
- unsigned char oraflg; /* error flags */
- /* *** Operating system dependent *** */
- unsigned int oracn; /* cursor number */
- struct orarowid orarid; /* rowid structure */
- unsigned int oraose; /* os dependent error code */
- unsigned char orachk; /* check byte */
- unsigned char orafill[30]; /* private, reserved fill */
- };
-
-
- /* Oracle SQLMSC library prototypes */
- # ifdef ANSI
- ocan(struct oradef *);
- oclose(struct oradef *);
- ocom(struct oradef *);
- ocof(struct oradef *);
- odefin(struct oradef *, int, char *, int, int, int, short *, char *, int, int, short *, short *);
- oexec(struct oradef *);
- ofetch(struct oradef *);
- ologof(struct oradef *);
- oname(struct oradef *, int, short *, short *, char *, int *);
- oopen(struct oradef *, struct oradef *, char *, int, int, char *, int);
- orlon(struct oradef *, char *, char *, int, char *, int, int);
- orol(struct oradef *);
- osql3(struct oradef *, char *, int);
- # else
- ocan();
- oclose();
- ocom();
- ocof();
- odefin();
- oexec();
- ofetch();
- ologof();
- oname();
- oopen();
- orlon();
- orol();
- osql3();
- # endif
-
-
- /*
- * Info for each file descriptor / cursor
- */
- struct ofd_def
- {
- int inprogress;
- int iostat;
- int direction;
- int do_rowid; /* TRUE if row id values to be saved */
- int lasttype; /* param type last used for assign_field */
- struct oradef scurs; /* cursor for record searches */
- struct oradef ucurs; /* cursor for record updates */
- char *findaction; /* action string for searches */
- char *fieldlist;
- char *fields;
- char *values;
- char *tmpbuf;
- char tmprowid[20]; /* to hold temporary row id */
- char oldrowid[20]; /* to hold retained row id to check */
- char currowid[20]; /* to hold copy of current row id */
- char prvrowid[20]; /* to hold copy of row id of prev rec */
- };
-
- static struct ofd_def ofd[MAX_FILES];
-
-
- /****************************************************************************/
- /* Oracle commands available thru' this interface. */
- /****************************************************************************/
- /*
- * insert into emp(a, b, c) values ('me', 'you', 123)"
- */
- char *Oaddrec = "INSERT INTO %s(%s) VALUES (%s)";
-
- /*
- * update emp set a='him', b='them', c=456 where a='me'
- */
- char *Oupdrec = "UPDATE %s SET %s WHERE ROWID='%s'";
-
- /*
- * delete from emp where a='me'
- */
- char *Odelrec = "DELETE FROM %s WHERE ROWID='%s'";
-
- /*
- * select * from emp where a='him'and b='them' and etc....
- */
- char *multi = "SELECT %s%s FROM %s WHERE %s ORDER BY %s";
-
- char *last = "SELECT NVL(MAX(%s), 0) FROM %s";
- char *dlast = "SELECT NVL(MAX(%s), '%s') FROM %s";
-
- /*
- * Operations
- */
- # define ADD 0
- # define UPD 1
- # define DEL 2
- # define EXA 3
- # define PAR 4
- # define LAS 5
- # define NXT 6
- # define PRV 7
-
- # define FORWARD 1
- # define BACKWARD 0
- # define CURBUFF 1
- # define NXTBUFF 0
-
-
-
- char hst[256]; /* Host definition */
- struct oradef lda; /* lda area */
-
- char uid[31]; /* username/password */
-
- char *action; /* action buffer */
-
- static int logged_on = FALSE;
-
- static short rowid_len;
- static short rowid_err;
- static char delrowid[20];
-
-
- /*
- * Dates Bodge, used for converting Oracle format dates
- * to PRO-C format dates after an INQUIRY.
- * See load_dates7() below.
- */
- struct o_dates
- {
- char d_str[10]; /* Oracle format "DD-MON-YY" ( room for Null ) */
- short d_off; /* Offset in PRO-C buffer */
- struct o_dates *nxt_d;
- };
-
- struct o_dates *d_ptr;
- struct o_dates *d_hdr[MAX_FILES];
- struct o_dates *tmp_ptr;
-
- char uname_mask[] = "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV";
-
- FIELD f_uname = { 2, 2, 1, uid, uname_mask, 0, 30, F_TEXT,
- UNDERLINED, REVVID, CONFIRM_NEEDED | NO_BLANK,
- NULL, text_input, NULL, NULL };
-
-
-
- /*
- *
- * Interface functions
- *
- */
-
-
- /*
- * Sets up File Name extension.
- */
- static int i_filename(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- return(IOGOOD);
- }
-
- /*
- * Initialize and open log file
- */
- static int i_init_file(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- logged_on = TRUE;
- action = alloc(OACTION_LEN); /* Allocate action area */
- tmp_ptr = (struct o_dates *)alloc(sizeof(struct o_dates));
-
- return(IOGOOD);
- }
-
-
- /*
- * File open function
- */
- static int i_open_file(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat, n;
-
- if (!logged_on) /* Don't logoff as not logged on - Nig */
- return(IOERROR);
-
- ofd[fd_sys].inprogress = FALSE; /* no resources active */
- ofd[fd_sys].lasttype = -1;
- ofd[fd_sys].findaction = alloc(OACTION_LEN);
- ofd[fd_sys].values = alloc(OACTION_LEN);
- ofd[fd_sys].fields = alloc(OACTION_LEN);
- ofd[fd_sys].fieldlist = alloc(fd[fd_sys].fld_cnt * (FLDNAME_LEN + 2));
- ofd[fd_sys].tmpbuf = alloc(fd[fd_sys].rec_len);
-
- /*
- * Establish CURSORs for this table
- */
- oopen(&ofd[fd_sys].ucurs, &lda, (char *)0, -1, -1, (char *)0, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Open0A")) != IOGOOD)
- {
- close_all7();
- i_logoff(fd_sys, NULL);
- return (stat);
- }
- oopen(&ofd[fd_sys].scurs, &lda, (char *)0, -1, -1, (char *)0, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Open0B")) != IOGOOD)
- {
- close_all7();
- i_logoff(fd_sys, NULL);
- return (stat);
- }
-
- /*
- * If OUTPUT mode, delete table - supporting logic will create it
- */
- if (fd[fd_sys].openmode & OUTPUT_FLAG)
- drop_table7(fd_sys);
-
- if (new_table7(fd_sys) != IOGOOD)
- {
- if (!(fd[fd_sys].openmode & INPUT_FLAG))
- {
- if (create_file7(fd_sys) != IOGOOD)
- return (IOERROR);
- }
- else
- {
- stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Open1");
- close_all7();
- i_logoff(fd_sys, NULL);
- return (stat);
- }
- }
-
- if (lock_table7(fd_sys) != IOGOOD)
- return (IOERROR);
-
- load_dates7(fd_sys);
-
- ofd[fd_sys].fieldlist[0] = '\0';
- for (n = 0; n < fd[fd_sys].fld_cnt; n++)
- {
- strcat(ofd[fd_sys].fieldlist, fd[fd_sys].flds[n].fldname);
- if (n < fd[fd_sys].fld_cnt - 1)
- strcat(ofd[fd_sys].fieldlist, ",");
- }
-
- return(IOGOOD);
- }
-
-
- /*
- * Lock the table !
- */
- static int lock_table7(fd_sys)
- int fd_sys;
- {
- int stat;
-
- if (fd[fd_sys].openmode & (UPDATE_FLAG | P_SHARED))
- sprintf(action, "LOCK TABLE %s IN SHARE UPDATE MODE NOWAIT", fd[fd_sys].filname);
- else if (fd[fd_sys].openmode & (UPDATE_FLAG | P_EXCLUSIVE))
- sprintf(action, "LOCK TABLE %s IN EXCLUSIVE UPDATE MODE NOWAIT", fd[fd_sys].filname);
- else if (fd[fd_sys].openmode & (INPUT_FLAG | P_SHARED))
- sprintf(action, "LOCK TABLE %s IN SHARE MODE NOWAIT", fd[fd_sys].filname);
- else
- sprintf(action, "LOCK TABLE %s IN EXCLUSIVE MODE NOWAIT", fd[fd_sys].filname);
-
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Lock0");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].ucurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Lock0")) != IOGOOD)
- {
- close_all7();
- i_logoff(fd_sys, NULL);
- return (stat);
- }
-
- return (IOGOOD);
- }
-
-
- /*
- * Tell Oracle to Drop the specified table. ie. Delete it
- */
- static int drop_table7(fd_sys)
- int fd_sys;
- {
- int stat;
-
- sprintf(action, "DROP TABLE %s", fd[fd_sys].filname);
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Drop0");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].ucurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Drop0")) != IOGOOD)
- {
- close_all7();
- i_logoff(fd_sys, NULL);
- return (stat);
- }
- }
-
-
- /*
- * Determine if a Table exists - If not then CREATE it
- */
- static int new_table7(fd_sys)
- int fd_sys;
- {
- /*
- * Bodge up way of checking to see if a table exists
- */
- sprintf(action, "SELECT * FROM %s", fd[fd_sys].filname);
- # ifdef ODEBUG
- dspactn(action, fd_sys, "NEWTAB");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].scurs, action, -1);
-
- #ifdef ODEBUG
- errmsg("new_table fn has error code %d", ofd[fd_sys].scurs.orarc);
- io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "NewTab");
- #endif
-
- if (ofd[fd_sys].scurs.orarc != 0)
- return (IOERROR);
- else
- return (IOGOOD);
- }
-
-
- /*
- * This auxillary routine is called by the OPEN routine in the
- * event that the file is to be created.
- */
- static int create_file7(fd_sys)
- int fd_sys;
- {
- int i, stat;
- char tmp[128];
- struct fldinfx *flds = fd[fd_sys].flds;
-
- /*
- * Build up SQL string to create the table
- */
- sprintf(action, "CREATE TABLE %s ( ", fd[fd_sys].filname);
-
- for (i = 0; i < fd[fd_sys].fld_cnt; i++, flds++)
- {
- switch(flds->fldtype)
- {
- case CHRTYP :
- if (flds->fldlen > 240)
- {
- errmsg("Field Too Long for Oracle to Understand - Adjusting");
- flds->fldlen = 240;
- }
- sprintf(tmp, "%s CHAR(%d)", flds->fldname, flds->fldlen);
- break;
- case MEMTYP :
- sprintf(tmp, "%s LONG", flds->fldname);
- break;
- case INTTYP :
- case LNGTYP :
- sprintf(tmp, "%s NUMBER(%d)", flds->fldname, 1+nummasklen(flds->fldmask));
- break;
- case FLTTYP :
- case DBLTYP :
- sprintf(tmp, "%s NUMBER(%d,%d)", flds->fldname, 1+nummasklen(flds->fldmask), decmasklen(flds->fldmask));
- break;
- case DATTYP :
- if (flds->fldlen == 6)
- sprintf(tmp, "%s DATE", flds->fldname);
- else /* full time date will be stored as a long int */
- sprintf(tmp, "%s NUMBER(10)", flds->fldname);
- break;
- }
-
- strcat(action, tmp);
-
- if (i < fd[fd_sys].fld_cnt-1)
- strcat(action, ", ");
- }
-
- strcat(action, " )");
-
- /*
- * Operation
- */
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Creat0");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].ucurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Create0")) != IOGOOD)
- {
- close_all7();
- i_logoff(fd_sys, NULL);
- return (stat);
- }
-
- for (i = 0, flds = fd[fd_sys].flds; i < fd[fd_sys].fld_cnt; i++, flds++)
- if (unique_fld7(fd_sys, flds))
- {
- sprintf(action, "CREATE UNIQUE INDEX Q%s%sQ ON %s(%s)", fd[fd_sys].filname, flds->fldname, fd[fd_sys].filname, flds->fldname);
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Creat1");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].ucurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Create1")) != IOGOOD)
- {
- close_all7();
- i_logoff(fd_sys, NULL);
- return (stat);
- }
- }
-
- return (IOGOOD);
- }
-
-
- /*
- * Close ALL open tables
- * NOTE: if mixed file managers enabled, this function will have to
- * distinguish between ORACLE and other file types
- */
- static void close_all7()
- {
- int i;
-
- for (i = 0; i < MAX_FILES; i++)
- if (fd[i].active == TRUE)
- i_close_file(i, NULL);
- }
-
-
- /*
- * This routine will close the Table defined by FD_SYS.
- */
- static int i_close_file(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int i;
-
- /*
- * close the table
- */
- oclose(&ofd[fd_sys].ucurs);
- oclose(&ofd[fd_sys].scurs);
- fd[fd_sys].active = FALSE;
-
- free_dates7(fd_sys);
- free(ofd[fd_sys].findaction);
- free(ofd[fd_sys].values);
- free(ofd[fd_sys].fields);
- free(ofd[fd_sys].fieldlist);
- free(ofd[fd_sys].tmpbuf);
-
- /*
- * If a table is still active, then return
- */
- for (i = 0; i < MAX_FILES; i++)
- if (fd[i].active == TRUE)
- return(IOGOOD);
-
- /*
- * Logoff here only if not already logged off
- */
- if (logged_on)
- i_logoff(fd_sys, NULL);
-
- return(IOGOOD);
- }
-
-
- /*
- * Select an index to perform processing on.
- */
- static int i_selectinx(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- return(IOGOOD);
- }
-
-
- /*
- * Retrieve a record according to a key specification.
- */
- static int i_findkey(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int opno;
-
- /*
- * Also need to take the Special Match type into consideration - NIG
- */
- opno = (fd[fd_sys].exact == 1) ? EXA : (fd[fd_sys].exact == 0) ? PAR : 99;
- ofd[fd_sys].direction = FORWARD;
- ofd[fd_sys].do_rowid = TRUE;
- ofd[fd_sys].findaction[0] = '\0';
- return(o_findkey(fd_sys, buffer, opno));
- }
-
- /*
- * Retrieve function allowing direction selection
- */
- static int o_findkey(fd_sys, buffer, opno)
- int fd_sys;
- char *buffer;
- int opno;
- {
- int stat;
-
- if (!ofd[fd_sys].findaction[0])
- build_action7(fd_sys, opno, buffer);
-
- /*
- * If Resources remain allocated by oracle, then we
- * must release them.
- */
- if (ofd[fd_sys].inprogress == TRUE)
- {
- ocan(&ofd[fd_sys].scurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Cancel0")) != IOGOOD)
- return (stat);
- ofd[fd_sys].inprogress = FALSE;
- }
-
- /*
- * Inform Oracle of the Operation
- */
- # ifdef ODEBUG
- dspactn(ofd[fd_sys].findaction, fd_sys, "Find0");
- # endif
- oraschmeggie(ofd[fd_sys].findaction);
- osql3(&ofd[fd_sys].scurs, ofd[fd_sys].findaction, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Find0")) != IOGOOD)
- return (stat);
-
- /*
- * Tell Oracle about the fields in our buffer
- */
- if ((stat = assign_fields7(fd_sys, buffer, CURBUFF)) != IOGOOD)
- return (stat);
-
- /*
- * Perform Op !
- */
- stat = oexec(&ofd[fd_sys].scurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Find1")) != IOGOOD)
- return (stat);
-
- /*
- * Get first record in list.
- */
- zerorec(buffer, fd[fd_sys].rec_len);
- memcpy(ofd[fd_sys].prvrowid, ofd[fd_sys].currowid, 18);
- ofetch(&ofd[fd_sys].scurs);
- if (ofd[fd_sys].do_rowid)
- {
- memcpy(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18);
- #ifdef ODEBUG
- dsp_rowid(fd_sys, "SAVING");
- #endif
- }
- stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Find2");
- ofd[fd_sys].lasttype = -1; /* forces reassignment of field targets */
- if (stat == IOEOF)
- return (IONOKEY);
- else if (stat != IOGOOD)
- return (stat);
-
- /*
- * For each length==6 date field, convert from Oracle format
- * to PRO-C format. ie. DD-MON-YY --> YYMMDD.
- * If the date is Null, then copy Null.
- * (long int date/time fields are treated as longs)
- */
- for (d_ptr = d_hdr[fd_sys]; d_ptr != (struct o_dates *)0; d_ptr = d_ptr->nxt_d)
- {
- if (!*d_ptr->d_str)
- fstrcpy((char *)(buffer + d_ptr->d_off), "", 1);
- else if (is_chardate(fd_sys, d_ptr->d_off))
- memcpy((char *)(buffer + d_ptr->d_off), conv_Odate(d_ptr->d_str), 6);
- }
-
- /*
- * Create list of keys to search on for update/delete
- */
- add_keys7(fd_sys, buffer);
-
- /*
- * Set the inprogress flag to TRUE, as we have retrieved
- * a record, and caused Oracle to allocate resources
- * associated with this search path.
- */
- ofd[fd_sys].inprogress = TRUE;
-
- /*
- * Get the next record now
- */
- savenext7(fd_sys);
-
- return(IOGOOD);
- }
-
-
- /*
- * Find first record in the file
- */
- static int i_firstkey(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- ofd[fd_sys].direction = FORWARD;
- return(o_firstkey(fd_sys, buffer));
- }
-
- /*
- * First record function allowing direction selection
- */
- static int o_firstkey(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int oldexact, stat;
-
- zerorec(buffer, fd[fd_sys].rec_len);
- ofd[fd_sys].do_rowid = (ofd[fd_sys].direction == FORWARD);
- ofd[fd_sys].direction = FORWARD;
- oldexact = fd[fd_sys].exact;
- fd[fd_sys].exact = 0; /* set up search as a PART match */
- ofd[fd_sys].findaction[0] = '\0';
- stat = o_findkey(fd_sys, buffer, PAR);
- fd[fd_sys].exact = oldexact;
-
- return(stat);
- }
-
-
- /*
- * Find last physical record in the file
- */
- static int i_lastkey(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat, ix, opno;
- struct fldinfx *fin;
-
- ofd[fd_sys].direction = BACKWARD;
- build_action7(fd_sys, LAS, buffer);
-
- /*
- * If Resources remain allocated by oracle, then we
- * must release them.
- */
- if (ofd[fd_sys].inprogress == TRUE)
- {
- ocan(&ofd[fd_sys].scurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Cancel4")) != IOGOOD)
- return (stat);
- ofd[fd_sys].inprogress = FALSE;
- }
-
- /*
- * Inform Oracle of the Operation
- */
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Last0");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].scurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last0")) != IOGOOD)
- return (stat);
-
- /*
- * Find this fields info
- */
- ix = fd[fd_sys].keys[fd[fd_sys].cur_key].fldindex[0];
- fin = &fd[fd_sys].flds[ix];
-
- /*
- * Tell Oracle about this field, and only this field.
- * Remember, this is the Only field in the select list,
- * so field number is 1 for this odefin()
- */
- ofd[fd_sys].lasttype = -1; /* ensures redefinition in assign_fields */
-
- if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
- {
- tmp_ptr->d_off = fin->fldstart;
- odefin(&ofd[fd_sys].scurs, 1, tmp_ptr->d_str, 10, dtyp7(fin->fldtype),
- -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
- }
- else
- {
- if (fin->fldtype == DATTYP) /* long int date only */
- odefin(&ofd[fd_sys].scurs, 1, (char *)(buffer + fin->fldstart),
- fin->fldlen, dtyp7(LNGTYP),
- -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
- else
- odefin(&ofd[fd_sys].scurs, 1, (char *)(buffer + fin->fldstart),
- fin->fldlen, dtyp7(fin->fldtype),
- -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
- }
-
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last1")) != IOGOOD)
- return (stat);
-
- /*
- * Perform Op !
- */
- oexec(&ofd[fd_sys].scurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last2")) != IOGOOD)
- return (stat);
-
- /*
- * Get first record in list. (ie, the last record)
- */
- memcpy(ofd[fd_sys].prvrowid, ofd[fd_sys].currowid, 18);
- ofetch(&ofd[fd_sys].scurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Last3")) != IOGOOD)
- return (stat);
-
- /*
- * Convert Oracle date type to PRO-C form, if null, store as null
- */
- if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
- {
- if (!*tmp_ptr->d_str)
- fstrcpy((char *)(buffer + tmp_ptr->d_off), "", 1);
- else if (is_chardate(fd_sys, tmp_ptr->d_off))
- memcpy((char *)(buffer + tmp_ptr->d_off), conv_Odate(tmp_ptr->d_str), 6);
- }
-
- /*
- * De-allocate Oracle Resources
- */
- ocan(&ofd[fd_sys].scurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Cancel5")) != IOGOOD)
- return (stat);
- ofd[fd_sys].inprogress = FALSE;
-
- /*
- * Found last rec okay, now reseek on it to establish rowid
- */
- opno = (fd[fd_sys].exact == 1) ? EXA : (fd[fd_sys].exact == 0) ? PAR : 99;
- ofd[fd_sys].do_rowid = TRUE;
- ofd[fd_sys].findaction[0] = '\0';
- return(o_findkey(fd_sys, buffer, opno));
- }
-
-
- /*
- * This routine will retrieve the NEXT record in the sequence on the
- * currently defined retrieval path.
- * Special handling is performed depending on whether we are just
- * reading or reading/updating.
- * If the latter, then ORACLE's internal search path's are trashed
- * after an update, so using the saved value of the next record we
- * do another partial lookup to set up the search path again.
- */
- static int i_nextrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat;
-
- ofd[fd_sys].direction = FORWARD;
- ofd[fd_sys].do_rowid = FALSE;
-
- stat = o_nextrec(fd_sys, buffer);
-
- if (stat == IOGOOD) /* retain current row id in case PREV done next */
- {
- memcpy(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18);
- #ifdef ODEBUG
- dsp_rowid(fd_sys, "RESETTING");
- #endif
- }
- return(stat);
- }
-
- /*
- * Next function allowing direction selection
- */
- static int o_nextrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int oldexact;
-
- /*
- * Check to see if previous savenext7() call was ok
- */
- if (ofd[fd_sys].iostat != IOGOOD)
- return (ofd[fd_sys].iostat);
-
- bytecpy(buffer, ofd[fd_sys].tmpbuf, fd[fd_sys].rec_len);
- /*
- * Set up key string in case update to be done
- */
- add_keys7(fd_sys, buffer);
- /*
- * Get the next record now
- */
- memcpy(ofd[fd_sys].prvrowid, ofd[fd_sys].currowid, 18);
- memcpy(ofd[fd_sys].currowid, ofd[fd_sys].tmprowid, 18);
- savenext7(fd_sys);
-
- return (IOGOOD);
- }
-
-
- /*
- * Find previous record in the file
- * - if rowid values of "next" rec retrieved by savenext7 match those
- * retained from original fetch, it is the previous record by current
- * ORDER BY criterion
- */
- static int i_prevrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat, opno;
- char prv_rowid[20];
-
- /*
- * Save the Previous row_id for checking !!
- */
- strcpy(prv_rowid, ofd[fd_sys].prvrowid);
-
- opno = (fd[fd_sys].exact == 1) ? EXA : (fd[fd_sys].exact == 0) ? PAR : 99;
-
- errmsg("prev 1");
- if (ofd[fd_sys].direction == BACKWARD) /* lastrec has been used before */
- stat = o_firstkey(fd_sys, buffer);
- else
- stat = o_findkey(fd_sys, buffer, opno);
-
- errmsg("prev 2");
- if (!memcmp(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18))
- return(IOTOF); /* if retained rowid same as current, at TOF */
-
- errmsg("prev 3");
- /*
- * Using the saved previous rowid, look for the required record - NIG
- */
- while (!chk_rowid(fd_sys, prv_rowid) && stat == IOGOOD)
- {
- errmsg("trying the next one");
- stat = o_nextrec(fd_sys, buffer);
- }
-
- if (stat == IOGOOD)
- {
- memcpy(ofd[fd_sys].oldrowid, ofd[fd_sys].currowid, 18);
- #ifdef ODEBUG
- dsp_rowid(fd_sys, "RESETTING");
- #endif
- }
-
- return(stat); /* will be IOEOF if end of file reached */
- }
-
-
- /*
- * Re-read/reposition record pointer function - if required
- */
- static int i_rereadrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- return(IOGOOD);
- }
-
-
- /*
- * Add a new record.
- */
- static int i_addrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat;
-
- build_action7(fd_sys, ADD, buffer);
-
- /*
- * If Resources remain allocated by oracle, then we
- * must release them.
- */
- if (ofd[fd_sys].inprogress == TRUE)
- {
- ocan(&ofd[fd_sys].ucurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Cancel1")) != IOGOOD)
- return (stat);
- ofd[fd_sys].inprogress = FALSE;
- }
-
- /*
- * Inform Oracle of the Operation
- */
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Add0");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].ucurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Add0")) != IOGOOD)
- return (stat);
-
- /*
- * Perform Op !
- */
- oexec(&ofd[fd_sys].ucurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Add1")) != IOGOOD)
- return (stat);
-
- add_keys7(fd_sys, buffer);
-
- return(IOGOOD);
- }
-
-
- /*
- * Update the current record.
- */
- static int i_updrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat, opno;
-
- build_action7(fd_sys, UPD, buffer);
-
- /*
- * If Resources remain allocated by oracle, then we
- * must release them.
- */
- if (ofd[fd_sys].inprogress == TRUE)
- {
- ocan(&ofd[fd_sys].ucurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Cancel2")) != IOGOOD)
- return (stat);
- ofd[fd_sys].inprogress = FALSE;
- }
-
- /*
- * Inform Oracle of the Operation
- */
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Upd0");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].ucurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Update0")) != IOGOOD)
- return (stat);
-
- /*
- * Perform Op !
- */
- oexec(&ofd[fd_sys].ucurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Update1")) != IOGOOD)
- return (stat);
-
- add_keys7(fd_sys, buffer);
-
- return (IOGOOD);
- }
-
-
- /*
- * Save the next record on this search path, so that
- * an updrec() before a nextrec() will not cause
- * ORACLE error -1002 ( fetch out of sequence ).
- * nextrec() knows, according to flags set below,
- * whether or not to do a re-read using the saved next
- * record, or just use the normal next record read.
- *
- * Uses temporary buffer, for next record, so as not
- * to trash our current record.
- */
- static void savenext7(fd_sys)
- int fd_sys;
- {
- int stat;
-
- /*
- * Tell Oracle about the fields in our temp buffer
- */
- if ((stat = assign_fields7(fd_sys, ofd[fd_sys].tmpbuf, NXTBUFF)) != IOGOOD)
- {
- ofd[fd_sys].iostat = stat;
- return;
- }
-
- /*
- * Inform Oracle of the Operation
- */
- # ifdef ODEBUG
- dspactn(ofd[fd_sys].findaction, fd_sys, "SavNxt0");
- # endif
- zerorec(ofd[fd_sys].tmpbuf, fd[fd_sys].rec_len);
- ofetch(&ofd[fd_sys].scurs);
- stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Savenext0");
- if (stat != IOGOOD)
- {
- /*
- * End of File, so set the flag
- */
- ofd[fd_sys].iostat = stat;
- return;
- }
- ofd[fd_sys].iostat = IOGOOD;
-
- /*
- * For each date field, convert from Oracle format
- * to PRO-C format. ie. DD-MON-YY --> YYMMDD.
- */
- for (d_ptr = d_hdr[fd_sys]; d_ptr != (struct o_dates *)0; d_ptr = d_ptr->nxt_d)
- {
- if (!*d_ptr->d_str)
- fstrcpy((char *)(ofd[fd_sys].tmpbuf + d_ptr->d_off), "", 1);
- else if (is_chardate(fd_sys, d_ptr->d_off))
- memcpy((char *)(ofd[fd_sys].tmpbuf + d_ptr->d_off), conv_Odate(d_ptr->d_str), 6);
- }
- }
-
-
- /*
- * Delete the current record.
- */
- static int i_delrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat, opno;
-
- memcpy(delrowid, ofd[fd_sys].currowid, 18);
-
- # ifdef NIGEL
- /*
- * Don't find next because the inquire cursor is still valid
- */
- stat = o_nextrec(fd_sys, buffer); /* have next record ready before delete */
- # endif
-
- build_action7(fd_sys, DEL, buffer);
-
- /*
- * If Resources remain allocated by oracle, then we
- * must release them.
- */
- if (ofd[fd_sys].inprogress == TRUE)
- {
- ocan(&ofd[fd_sys].ucurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Cancel3")) != IOGOOD)
- return (stat);
- ofd[fd_sys].inprogress = FALSE;
- }
-
- /*
- * Inform Oracle of the Operation
- */
- # ifdef ODEBUG
- dspactn(action, fd_sys, "Del0");
- # endif
- oraschmeggie(action);
- osql3(&ofd[fd_sys].ucurs, action, -1);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Delete0")) != IOGOOD)
- return (stat);
-
- /*
- * Perform Op !
- */
- oexec(&ofd[fd_sys].ucurs);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].ucurs.orarc, "Delete1")) != IOGOOD)
- return (stat);
-
- return (IOGOOD);
- }
-
-
- /*
- * Lock Record.
- */
- static int i_lockrec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- return(IOGOOD);
- }
-
-
- /*
- * Unlock Record. Called from Delete/Inquire Mode
- */
- static int i_unlock_rec(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- return(IOGOOD);
- }
-
-
- /*
- * logoff if no tables left open, and reset the first time flag
- */
- static int i_logoff(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- logged_on = FALSE;
-
- free(action);
- free(tmp_ptr);
-
- if (ologof(&lda))
- {
- io_xlate(-1, lda.orarc, "Logoff");
- return (IOERROR);
- }
-
- return (IOGOOD);
- }
-
-
- /*
- * Logon to Oracle
- */
- static int i_login(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat;
-
- while (TRUE)
- {
- if (buffer) /* if a password has been supplied from PRO-C program */
- {
- strcpy(uid, buffer);
- strcat(uid, "/");
- strcat(uid, &buffer[20]); /* offset 20 into buffer has password */
- }
- else if (get_idname7() != IOGOOD)
- return (IOERROR);
-
- if (orlon(&lda, hst, uid, -1, (char *)0, -1, -1))
- {
- if ((stat = io_xlate(fd_sys, lda.orarc, "Logon")) != IOGOOD)
- return (stat);
- }
- ocof(&lda);
- if ((stat = io_xlate(fd_sys, lda.orarc, "No Auto Commit")) != IOGOOD)
- return (stat);
- else
- return (IOGOOD);
- }
- }
-
-
- /*
- * Get username / password from user
- * in the form "uname/passwd".
- *
- * Due to the change in the windowing system, this call
- * to create_w() must be made only after the windowing
- * system has been initialised. (ie. the main call to
- * init_w() / create_w().
- */
- static int get_idname7()
- {
- create_w(1, 1, 3, 32);
- border_w(0, BOLD);
- disp_w(1, 7, REVVID, " username/password ");
-
- do
- {
- input_wx(&f_uname, K_ESC, 0);
- if (ichar == K_ESC)
- {
- delete_w();
- return (IOERROR);
- }
- }
- while(!validuid(uid));
-
- delete_w();
-
- return (IOGOOD);
- }
-
-
- /*
- * Check format of id/pw
- */
- static int validuid(uid)
- char *uid;
- {
- int stat;
-
- if (strchr(uid, '/') == NULL)
- {
- errmsg("Enter Username & Password in format 'Username/Password'");
- return (FALSE);
- }
- else
- {
- stat = warning(-1, "Is the Username & Password Correct ?");
- }
-
- if (stat)
- return (TRUE);
- else
- return (FALSE);
- }
-
-
- /*
- * Create a string containing the required action to
- * pass to Oracle, using the SQL defines above.
- * eg. "SELECT * FROM <TABLE> WHERE <FLD>=<VALUE>
- */
-
- static void build_action7(fd_sys, opno, buffer)
- int fd_sys;
- int opno;
- char *buffer;
- {
- int ix;
- struct fldinfx *fin;
-
- ix = fd[fd_sys].keys[fd[fd_sys].cur_key].fldindex[0];
- fin = &fd[fd_sys].flds[ix];
-
- switch (opno)
- {
- case ADD :
- add_fields7(fd_sys, buffer);
- sprintf(action, Oaddrec, fd[fd_sys].filname, ofd[fd_sys].fieldlist, ofd[fd_sys].values);
- break;
- case UPD :
- add_values7(fd_sys, buffer);
- sprintf(action, Oupdrec, fd[fd_sys].filname, ofd[fd_sys].values, ofd[fd_sys].currowid);
- break;
- case DEL :
- sprintf(action, Odelrec, fd[fd_sys].filname, delrowid);
- break;
- case PAR :
- case EXA :
- case 99 : /* Special - NIG */
- case NXT :
- case PRV :
- 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));
- break;
- case LAS :
- if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
- sprintf(action, dlast, fin->fldname, MINDATE, fd[fd_sys].filname);
- else
- sprintf(action, last, fin->fldname, fd[fd_sys].filname);
- break;
- }
- }
-
-
- /*
- * Build up the search string, be it exact or partial
- */
- static char *search_action(fd_sys, optyp, buffer)
- int fd_sys, optyp;
- char *buffer;
- {
- int n, ix, ck, ofs, nochrval;
- short tmp_i; /* Temp variables */
- long tmp_l;
- float tmp_f;
- double tmp_d;
- char tmps[OTMPSTR_LEN], tmpf[25], tcomp[3];
- static char tmpsrch[MAX_SEGS * (FLDNAME_LEN + MAX_FLDLEN + 7) + 1];
- struct fldinfx *fin;
-
- ck = fd[fd_sys].cur_key;
- if (optyp == EXA || optyp == 99) /* Special Match - NIG */
- strcpy(tcomp, "=");
- else
- strcpy(tcomp, ">=");
- /*
- else if (ofd[fd_sys].direction == FORWARD)
- strcpy(tcomp, ">=");
- else
- strcpy(tcomp, "<=");
- */
-
- zerorec(tmpsrch, MAX_SEGS * (FLDNAME_LEN + MAX_FLDLEN + 7));
-
- for (n = 0; n < fd[fd_sys].keys[ck].segcount; n++)
- {
- ix = fd[fd_sys].keys[ck].fldindex[n];
- fin = &fd[fd_sys].flds[ix];
- nochrval = FALSE;
-
- switch (fin->fldtype)
- {
- case DATTYP :
- if (fin->fldlen == 6)
- {
- sprintf(tmpf, "trunc(%s)", fin->fldname);
- if (!*((char *)buffer + fin->fldstart))
- sprintf(tmps, "'%s'", MINDATE);
- else
- {
- strcpy(tmps, "'");
- sprintf(&tmps[1], "%s", conv2_Odate((char *)buffer + fin->fldstart));
- strcat(tmps, "'");
- }
- break;
- } /* else fall through to LNGTYP - do not put a break here!!! */
- case LNGTYP : /* don't move this - it must follow DATTYP */
- sprintf(tmpf, "nvl(%s,0)", fin->fldname);
- bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmps, "%ld", tmp_l);
- break;
- case CHRTYP :
- ofs = 1;
- if ((fd[fd_sys].keys[ck].segstart[n] == fin->fldstart)
- && (fd[fd_sys].keys[ck].seglen[n] == fin->fldlen))
- strcpy(tmpf, fin->fldname);
- else
- {
- ofs = fd[fd_sys].keys[ck].segstart[n] - fin->fldstart + 1;
- sprintf(tmpf, "SUBSTR(%s,%d,%d)", fin->fldname, ofs, fd[fd_sys].keys[ck].seglen[n]);
- }
- if (!buffer[fin->fldstart] || (buffer[fin->fldstart] == ' '))
- {
- nochrval = TRUE; /* excludes empty char key segments */
- strcpy(tmps, "' '");
- }
- else
- {
- strcpy(tmps, "'");
- fstrcpy(&tmps[1], (char *)buffer + fin->fldstart + ofs - 1, fd[fd_sys].keys[ck].seglen[n]);
- cvt_str(tmps, 2);
- strcat(tmps, "'");
- }
- break;
- case INTTYP :
- sprintf(tmpf, "nvl(%s,0)", fin->fldname);
- bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmps, "%d", tmp_i);
- break;
- case FLTTYP :
- sprintf(tmpf, "nvl(%s,0.0)", fin->fldname);
- bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmps, "%f", tmp_f);
- break;
- case DBLTYP :
- sprintf(tmpf, "nvl(%s,0.0)", fin->fldname);
- bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmps, "%lf", tmp_d);
- break;
- }
-
- if (!nochrval || (n == 0))
- {
- if (n > 0)
- strcat(tmpsrch, " AND ");
- strcat(tmpsrch, tmpf);
- strcat(tmpsrch, tcomp);
- strcat(tmpsrch, tmps);
- }
- if ((optyp == NXT) || (optyp == PRV)) /* no segs used for next/prev */
- return(tmpsrch);
-
- /*
- * Omit the last segment for Match Type 99
- */
- if (optyp == 99 && (n + 1) == (fd[fd_sys].keys[ck].segcount - 1))
- break;
- }
-
- return(tmpsrch);
- }
-
-
- /*
- * Builds a target string for ORDER BY,
- * allowing for compound and substring keys
- */
- static char *order_action(fd_sys)
- int fd_sys;
- {
- int n, ix, scnt, ck, ofs;
- char tstr[50];
- static char ostr[250];
-
- zerorec(ostr, 199);
- ck = fd[fd_sys].cur_key;
- scnt = fd[fd_sys].keys[ck].segcount;
- for (n = 0; n < scnt; n++)
- {
- ix = fd[fd_sys].keys[ck].fldindex[n];
- if ((fd[fd_sys].keys[ck].segstart[n] == fd[fd_sys].flds[ix].fldstart)
- && (fd[fd_sys].keys[ck].seglen[n] == fd[fd_sys].flds[ix].fldlen))
- strcat(ostr, fd[fd_sys].flds[ix].fldname);
- else /* a substring key, use SQL SUBSTR() function */
- {
- ofs = fd[fd_sys].keys[ck].segstart[n] - fd[fd_sys].flds[ix].fldstart + 1;
- sprintf(tstr, "SUBSTR(%s,%d,%d)", fd[fd_sys].flds[ix].fldname,
- ofs, fd[fd_sys].keys[ck].seglen[n]);
- strcat(ostr, tstr);
- }
- /*
- if (ofd[fd_sys].direction == BACKWARD)
- strcat(ostr, " DESC");
- */
- strcat(ostr, ",");
- }
- if (ostr[0])
- ostr[strlen(ostr)-1] ='\0'; /* removes last & unneeded comma */
- return(ostr);
- }
-
-
- /*
- * Tell Oracle about the postions, and types of each
- * field, so that it knows where to put the values
- * after retrieving them.
- */
- static int assign_fields7(fd_sys, buffer, rowidbuf)
- int fd_sys;
- char *buffer;
- int rowidbuf;
- {
- int stat, fcnt;
- struct fldinfx *fin = fd[fd_sys].flds;
-
- if (ofd[fd_sys].lasttype == rowidbuf) /* don't need to do this if same */
- return(IOGOOD);
- ofd[fd_sys].lasttype = rowidbuf;
-
- /*
- * One of these for each field !!!
- *
- * For each date field, tell Oracle to place
- * the value in a special place, for later conversion.
- */
- for (fcnt = 0, d_ptr = d_hdr[fd_sys]; fcnt < fd[fd_sys].fld_cnt; fcnt++, fin++)
- {
- if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
- {
- d_ptr->d_off = fin->fldstart;
- odefin(&ofd[fd_sys].scurs, fcnt+1, d_ptr->d_str, 10, dtyp7(fin->fldtype),
- -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
- d_ptr = d_ptr->nxt_d;
- }
- else
- {
- if (fin->fldtype == DATTYP) /* long int date only */
- odefin(&ofd[fd_sys].scurs, fcnt+1, (char *)(buffer + fin->fldstart),
- fin->fldlen, dtyp7(LNGTYP),
- -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
- else
- odefin(&ofd[fd_sys].scurs, fcnt+1, (char *)(buffer + fin->fldstart),
- fin->fldlen, dtyp7(fin->fldtype),
- -1, (short *)0, (char *)0, -1, -1, (short *)0, (short *)0);
- }
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Assign0")) != IOGOOD)
- return (stat);
- }
-
- /*
- * define ROWID field at the end of the field list
- */
- if (rowidbuf == CURBUFF)
- odefin(&ofd[fd_sys].scurs, fcnt+1, ofd[fd_sys].currowid, 18, 1,
- -1, (short *)0, (char *)0, -1, -1, &rowid_len, &rowid_err);
- else
- odefin(&ofd[fd_sys].scurs, fcnt+1, ofd[fd_sys].tmprowid, 18, 1,
- -1, (short *)0, (char *)0, -1, -1, &rowid_len, &rowid_err);
- if ((stat = io_xlate(fd_sys, ofd[fd_sys].scurs.orarc, "Assign1")) != IOGOOD)
- return(stat);
-
- return (IOGOOD);
- }
-
-
- /*
- * Maps PRO-C data type to Oracle data type:
- * Numbers are straightforward.
- * Chars are space padded to a max length; if they are Null
- * terminated, the last character will be trashed.
- * Dates can be null terminated; the o_dates struct has
- * enough room for the date; this is converted ok with the
- * fmt_ & get_ date routines.
- */
- static int dtyp7(dtype)
- int dtype;
- {
- switch (dtype)
- {
- case DATTYP :
- return (5); /* 5 is NULL terminated ( room in o_dates for Null) */
- case MEMTYP :
- return (1); /* 8 is Oracle LONG type but OCI doesn't like it */
- case CHRTYP :
- return (1); /* 1 is SPACE filled ( no room in PRO-C buffer for Null) */
- case INTTYP :
- case LNGTYP :
- return (3);
- case FLTTYP :
- case DBLTYP :
- return (4);
- }
- }
-
-
- # ifdef ODEBUG
- /*
- * Find out the names associated with the columns
- * in an Oracle Table - debug
- */
- static void get_idx7(fd_sys)
- int fd_sys;
- {
- struct fldinfx *fin = fd[fd_sys].flds;
- int i;
- int len = 10;
- char buff[20], tmp[50];
-
- sprintf(action, "SELECT * FROM %s", fd[fd_sys].filname);
- dspactn(action, fd_sys, "GET_IDX");
- osql3(&ofd[fd_sys].scurs, "SELECT * FROM EMP", -1);
-
- for (i = 0; i < fd[fd_sys].fld_cnt; i++)
- {
- oname(&ofd[fd_sys].scurs, i+1, (short *)0, (short *)0, buff, &len);
- sprintf(tmp, "%d = %.10s\n", i+1, buff);
- dspactn(tmp, fd_sys, "IDXloop");
- }
- }
- # endif
-
- /*
- * Create a string containing values to be inserted into a table
- * insert into emp(a, b, c) values ('me', 'you', 123)"
- *
- * Date fields are converted directly from PRO-C format
- * to Oracle format, by using conv2_Odate() (fmt_date() in V1.3).
- */
- static void add_fields7(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- struct fldinfx *fin = fd[fd_sys].flds;
- static char tmp3[OACTION_LEN+1]; /* value */
- static char tmp2[OACTION_LEN+1];
- int fcnt, j, k, n, p;
- short tmp_i; /* Temp variables */
- long tmp_l;
- float tmp_f;
- double tmp_d;
-
- for (*ofd[fd_sys].values = '\0', fcnt = 0; fcnt < fd[fd_sys].fld_cnt; fcnt++, fin++)
- {
- zerorec(tmp2, OACTION_LEN);
- zerorec(tmp3, OACTION_LEN);
-
- switch(fin->fldtype)
- {
- case DATTYP :
- if (fin->fldlen == 6)
- {
- memcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
- if (strlen(tmp2) < 6)
- sprintf(tmp3, "NULL");
- else
- sprintf(tmp3, "'%s'", conv2_Odate(tmp2));
- break;
- }
- case LNGTYP : /* do not move this - long int date must fall through */
- bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%ld", tmp_l);
- break;
- case MEMTYP :
- zerorec(tmp3, OACTION_LEN);
- p = strlen(buffer + fin->fldstart);
- if (p > fin->fldlen)
- p = fin->fldlen;
- for (j = 0, k = 0; j < p; j+=240)
- {
- n = (j+240 < p) ? 240 : p-j;
- fstrcpy(tmp2, (char *)buffer + fin->fldstart + j, n);
- sprintf(&tmp3[k], "'%s'", tmp2);
- if (j+240 < p)
- {
- strcat(tmp3, "\|\|");
- k = strlen(tmp3);
- }
- }
- break;
- case CHRTYP :
- fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
- sprintf(tmp3, "'%s'", cvt_str(tmp2, 2));
- break;
- case INTTYP :
- bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%d", tmp_i);
- break;
- case FLTTYP :
- bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%f", tmp_f);
- break;
- case DBLTYP :
- bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%lf", tmp_d);
- break;
- }
-
- strcat(ofd[fd_sys].values, tmp3);
-
- if (fcnt < fd[fd_sys].fld_cnt-1)
- strcat(ofd[fd_sys].values, ", ");
- }
- }
-
-
- /*
- * Create search string for all keys set in PRO-C
- */
- static void add_keys7(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- struct fldinfx *fin;
- char tmp3[256]; /* value */
- char tmp2[256];
- int fcnt, ix;
- short tmp_i; /* Temp variables */
- long tmp_l;
- float tmp_f;
- double tmp_d;
-
- /*
- * For every key
- */
- for (*ofd[fd_sys].fields = '\0', fcnt = 0; fcnt < fd[fd_sys].key_cnt; fcnt++)
- {
- ix = fd[fd_sys].keys[fcnt].fldindex[0];
- fin = &fd[fd_sys].flds[ix]; /* field info for key# fcnt */
-
- switch(fin->fldtype)
- {
- case DATTYP :
- if (fin->fldlen == 6)
- {
- fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
- if(!*tmp2)
- sprintf(tmp3, "%s IS NULL", fin->fldname);
- else
- sprintf(tmp3, "trunc(%s)='%s'", fin->fldname, conv2_Odate(tmp2));
- break;
- }
- case LNGTYP : /* do not move this - long int dates must fall through */
- bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "nvl(%s,0)=%ld", fin->fldname, tmp_l);
- break;
- case CHRTYP :
- fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
- if(!*cvt_str(tmp2, 2))
- sprintf(tmp3, "%s IS NULL", fin->fldname);
- else
- sprintf(tmp3, "%s='%s'", fin->fldname, tmp2);
- break;
- case INTTYP :
- bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "nvl(%s,0)=%d", fin->fldname, tmp_i);
- break;
- case FLTTYP :
- bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "nvl(%s,0.0)=%f", fin->fldname, tmp_f);
- break;
- case DBLTYP :
- bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "nvl(%s,0.0)=%lf", fin->fldname, tmp_d);
- break;
- }
-
- strcat(ofd[fd_sys].fields, tmp3);
-
- if (fcnt < fd[fd_sys].key_cnt-1)
- strcat(ofd[fd_sys].fields, " AND ");
- }
- }
-
-
- /*
- * Build string of update values
- */
- static void add_values7(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- struct fldinfx *fin = fd[fd_sys].flds;
- static char tmp3[OACTION_LEN+1]; /* value */
- static char tmp2[OACTION_LEN+1];
- int fcnt, j, k, n, p;
- short tmp_i; /* Temp variables */
- long tmp_l;
- float tmp_f;
- double tmp_d;
-
- for (*ofd[fd_sys].values = '\0', fcnt = 0; fcnt < fd[fd_sys].fld_cnt; fcnt++, fin++)
- {
- zerorec(tmp2, OACTION_LEN);
- zerorec(tmp3, OACTION_LEN);
-
- switch(fin->fldtype)
- {
- case DATTYP :
- if (fin->fldlen == 6)
- {
- fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
- if (strlen(tmp2) < 6)
- sprintf(tmp3, "%s=NULL", fin->fldname);
- else
- sprintf(tmp3, "%s='%s'", fin->fldname, conv2_Odate(tmp2));
- break;
- }
- case LNGTYP : /* do not move this - long int dates must fall through */
- bytecpy((char *)&tmp_l, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%s=%ld", fin->fldname, tmp_l);
- break;
- case MEMTYP :
- zerorec(tmp3, OACTION_LEN);
- p = strlen(buffer + fin->fldstart);
- if (p > fin->fldlen)
- p = fin->fldlen;
- sprintf(tmp3, "%s=", fin->fldname);
- k = strlen(tmp3);
- for (j = 0; j < p; j+=240)
- {
- n = (j+240 < p) ? 240 : p-j;
- fstrcpy(tmp2, (char *)buffer + fin->fldstart + j, n);
- sprintf(&tmp3[k], "'%s'", tmp2);
- if (j+240 < p)
- {
- strcat(tmp3, "\|\|");
- k = strlen(tmp3);
- }
- }
- break;
- case CHRTYP :
- fstrcpy(tmp2, (char *)buffer + fin->fldstart, fin->fldlen);
- sprintf(tmp3, "%s='%s'", fin->fldname, cvt_str(tmp2, 2));
- break;
- case INTTYP :
- bytecpy((char *)&tmp_i, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%s=%d", fin->fldname, tmp_i);
- break;
- case FLTTYP :
- bytecpy((char *)&tmp_f, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%s=%f", fin->fldname, tmp_f);
- break;
- case DBLTYP :
- bytecpy((char *)&tmp_d, (char *)(buffer + fin->fldstart), fin->fldlen);
- sprintf(tmp3, "%s=%lf", fin->fldname, tmp_d);
- break;
- }
-
- strcat(ofd[fd_sys].values, tmp3);
-
- if (fcnt < fd[fd_sys].fld_cnt-1)
- strcat(ofd[fd_sys].values, ", ");
- }
- }
-
-
- /*
- * Check newly retrieved row id against retained values
- * and return TRUE if matching
- */
- static int chk_rowid(fd_sys, prv_rowid)
- int fd_sys;
- char *prv_rowid;
- {
- #ifdef ODEBUG
- dsp_rowid(fd_sys, "CHECKING");
- #endif
- if (!memcmp(ofd[fd_sys].tmprowid, ofd[fd_sys].oldrowid, 18))
- {
- errmsg("chk_row (tmp == old)");
- return(TRUE);
- }
-
- if (!memcmp(ofd[fd_sys].currowid, prv_rowid, 18))
- {
- errmsg("chk_row (cur == prv)");
- return(TRUE);
- }
-
- return (FALSE);
- }
-
-
- #ifdef ODEBUG
- static void dsp_rowid(fd_sys, titl)
- int fd_sys;
- char *titl;
- {
- 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);
- }
- #endif
-
-
- /*
- * Build a linked list of date structures for each Table,
- * to hold the offset and ORACLE representation of each
- * date field in the table, * which will be filled by each
- * ofetch() call.
- * - this will add to the list ONLY for character date types (len 6)
- *
- * Conversions to PRO-C format, will take place after
- * each ofetch() call, by using get_date().
- */
- static void load_dates7(fd_sys)
- int fd_sys;
- {
- struct fldinfx *fin;
- struct o_dates *dp;
- int i;
-
- fin = fd[fd_sys].flds;
-
- /*
- * Scan the fldinfo list, and check every field.
- */
- for (d_ptr = d_hdr[fd_sys] = (struct o_dates *)0, i = 0; i < fd[fd_sys].fld_cnt; i++, fin++)
- if ((fin->fldtype == DATTYP) && (fin->fldlen == 6))
- {
- /*
- * Another date field, so add on to end of list
- */
- dp = macalloc(struct o_dates);
- dp->d_off = fin->fldstart;
- dp->nxt_d = (struct o_dates *)0;
-
- if (d_ptr != (struct o_dates *)0)
- d_ptr->nxt_d = dp;
-
- d_ptr = dp;
-
- if (d_hdr[fd_sys] == (struct o_dates *)0)
- d_hdr[fd_sys] = d_ptr;
- }
- }
-
-
- /*
- * Release Memory, reset pointers associated with o_dates
- */
- static void free_dates7(fd_sys)
- int fd_sys;
- {
- struct o_dates *dp;
-
- /*
- * Scan the date list, and free every entry.
- */
- for (dp = d_hdr[fd_sys]; dp != (struct o_dates *)0; )
- {
- d_ptr = dp->nxt_d;
- free(dp);
- dp = d_ptr;
- }
- d_hdr[fd_sys] = (struct o_dates *)0;
- }
-
-
- static char *conv_Odate(dstr) /* change Oracle date to PRO-C char date */
- char *dstr;
- {
- int ofs;
- char tmp3[4];
- static char tmp[7];
- static char mnths[37] = { "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC" };
- static char mnums[25] = { "010203040506070809101112" };
-
- strncpy(tmp, &dstr[7], 2);
- strncpy(tmp3, &dstr[3], 3); tmp3[3] = '\0';
- ofs = (36 - strlen(strstr(mnths, tmp3)))/3;
- if (ofs != 12)
- {
- strncpy(&tmp[2], &mnums[ofs*2], 2);
- strncpy(&tmp[4], dstr, 2);
- tmp[6] = '\0';
- }
- else
- strcpy(tmp, "");
-
- return(tmp);
- }
-
-
- static char *conv2_Odate(dstr) /* change PRO-C char date to Oracle date */
- char *dstr;
- {
- int ofs;
- char tmp2[3];
- static char tmp[10];
- static char mnths[37] = { "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC" };
-
- if (!dstr[0])
- strcpy(tmp, MINDATE);
- else
- {
- strncpy(tmp, &dstr[4], 2);
- tmp[2] = '-';
- strncpy(tmp2, &dstr[2], 2); tmp2[2] = '\0';
- ofs = atoi(tmp2);
- if (ofs > 12)
- strcpy(tmp, MINDATE);
- else
- {
- strncpy(&tmp[3], &mnths[(ofs-1)*3], 3);
- tmp[6] = '-';
- strncpy(&tmp[7], dstr, 2);
- tmp[9] = '\0';
- }
- }
-
- return(tmp);
- }
-
-
- static int is_chardate(fd_sys, fldoff)
- int fd_sys, fldoff;
- {
- int n;
-
- for (n = 0; n < fd[fd_sys].fld_cnt; n++)
- if (fd[fd_sys].flds[n].fldstart == fldoff)
- return(fd[fd_sys].flds[n].fldlen == 6);
-
- return(FALSE); /* long is shorter in buffer, so a safer default */
- }
-
-
- /*
- * Returns TRUE if field designated as key is unique -
- * but only if it's a simple key, not a compound
- */
- static int unique_fld7(fd_sys, fin)
- int fd_sys;
- struct fldinfx *fin;
- {
- int ix, n;
-
- for (ix = 0; ix < fd[fd_sys].fld_cnt; ix++)
- if (fin->fldstart == fd[fd_sys].flds[ix].fldstart)
- break;
-
- if (ix < fd[fd_sys].fld_cnt)
- for (n = 0; n < fd[fd_sys].key_cnt; n++)
- if ((ix == fd[fd_sys].keys[n].fldindex[0])
- && (fd[fd_sys].keys[n].segcount == 1)
- && (fd[fd_sys].keys[n].keytype == KEY_UNIQUE))
- return(TRUE); /* index of key field into fldinfx matches */
-
- return(FALSE); /* field is not a unique key */
- }
-
-
- /*
- * End (Commit) transaction
- */
- static int i_commit(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat;
-
- ocom(&lda);
- if ((stat = io_xlate(fd_sys, lda.orarc, "Commit")) != IOGOOD)
- return (stat);
-
- return(IOGOOD);
- }
-
- /*
- * Rollback transaction
- */
- static int i_rollback(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- int stat;
-
- orol(&lda);
- if ((stat = io_xlate(fd_sys, lda.orarc, "Rollback")) != IOGOOD)
- return (stat);
-
- return(IOGOOD);
- }
-
- /*
- * Start transaction
- */
- static int i_transact(fd_sys, buffer)
- int fd_sys;
- char *buffer;
- {
- return(IOGOOD);
- }
-
-
- /*
- * This routine translates C-ISAM Error codes into PRO-C error codes.
- * If no PRO-C equivalent, displays the error number.
- */
- static int io_xlate(fd_sys, ernum, rtnname)
- int fd_sys;
- int ernum;
- char *rtnname;
- {
- switch(ernum)
- {
- case 0 :
- case 3 :
- return (IOGOOD);
- case 4 :
- return (IOEOF);
- case -1004 :
- case -1005 :
- case -1017 :
- errmsg("Invalid Username/Password - Aborting");
- return (IONOLOGON);
- case -3121 :
- errmsg("ORACLE has not been loaded !");
- return (IOERROR);
- }
-
- if (fd_sys >= 0)
- errmsg(FileDbgError_sdss, "ORACLE", ernum, fd[fd_sys].filname, rtnname);
- else /* if routines called from generated apps without valid fd_sys */
- errmsg(FileDbgError_sds, "ORACLE", ernum, rtnname);
- return(IOERROR);
- }
-
-
- # ifdef ODEBUG
- static void dspactn(actn, fd_sys, optype)
- int fd_sys;
- char *actn, *optype;
- {
- int i, j, k, l;
- char titl[35];
- errmsg("%s : \n%s", optype, actn);
- return;
-
- strcpy(titl, " Action: ");
- strcat(titl, optype);
- strcat(titl, " ");
- if (fd_sys > -1)
- {
- strcat(titl, fd[fd_sys].filname);
- strcat(titl, " ");
- }
-
- k = strlen(actn);
- create_w(17, 1, 3+k/76, 80);
- border_w(0, BLINK);
- disp_w(1, 5, BOLDUNDER, titl);
-
- for (j = 0, i = 0; i <= k; j++, i+=76)
- for (l = 0; (l < 76) && (l+i <= k); l++)
- poke_w(2+j, 3+l, BOLD, actn[i+l]);
-
- while (inchar() != K_CR)
- ;
- flushscr();
- delete_w();
- }
- # endif
-
-
- # ifdef ODEBUG
- static void dspflds(buffer, fd_sys, optype)
- int fd_sys;
- char *buffer, *optype;
- {
- int j, ofs, flen, tlen;
- short itmp;
- long ltmp;
- float ftmp;
- double dtmp;
- char titl[35];
-
- strcpy(titl, " Fields: ");
- strcat(titl, optype);
- strcat(titl, " ");
- if (fd_sys > -1)
- {
- strcat(titl, fd[fd_sys].filname);
- strcat(titl, " ");
- }
-
- create_w(9, 39, 12, 40);
- border_w(0, BLINK);
- disp_w(1, 3, BOLDUNDER, titl);
-
- for (j = 0; (j < fd[fd_sys].fld_cnt) && (j < 10); j++)
- {
- disp_w(2+j, 2, NORMAL, fd[fd_sys].flds[j].fldname);
- ofs = fd[fd_sys].flds[j].fldstart;
- flen = fd[fd_sys].flds[j].fldlen;
-
- switch(fd[fd_sys].flds[j].fldtype)
- {
- case CHRTYP :
- tlen = (flen < 25) ? flen : 25;
- zerorec(titl, 34);
- strncpy(titl, &buffer[ofs], tlen);
- ndisp_w(2+j, 13, BOLD, tlen, titl);
- break;
- case INTTYP :
- memcpy(&itmp, &buffer[ofs], sizeof(short));
- disp_w(2+j, 13, BOLD, fmt_int(itmp, "zzzz9"));
- break;
- case LNGTYP :
- memcpy(<mp, &buffer[ofs], sizeof(long));
- disp_w(2+j, 13, BOLD, fmt_lng(ltmp, "zzzzzzzzzz9"));
- break;
- case FLTTYP :
- memcpy(&ftmp, &buffer[ofs], sizeof(float));
- dtmp = (double)ftmp;
- disp_w(2+j, 13, BOLD, fmt_dbl(dtmp, "zzzzzzzzz9.99"));
- break;
- case DBLTYP :
- memcpy(&dtmp, &buffer[ofs], sizeof(double));
- disp_w(2+j, 13, BOLD, fmt_dbl(dtmp, "zzzzzzzzz9.99"));
- break;
- default :
- break;
- }
- }
-
- while (inchar() != K_CR)
- ;
- flushscr();
- delete_w();
- }
- # endif
-
-
- # ifdef ODEBUG
- static void dspbuff(buffer, fd_sys, optype)
- int fd_sys;
- char *buffer, *optype;
- {
- int i, j, k, l;
- char titl[35], subtmp[77];
-
- /*
- errmsg("%s : \n%s", optype, buffer);
- return;
- */
- strcpy(titl, " Buffer: ");
- strcat(titl, optype);
- strcat(titl, " ");
- if (fd_sys > -1)
- {
- strcat(titl, fd[fd_sys].filname);
- strcat(titl, " ");
- }
-
- k = fd[fd_sys].rec_len;
- create_w(17, 1, 3+k/76, 80);
- border_w(0, BLINK);
- disp_w(1, 5, BOLDUNDER, titl);
-
- for (j = 0, i = 0; i <= k; j++, i+=76)
- {
- for (l = 0; (l < 76) && (l+i < k); l++)
- subtmp[l] = (isprint(buffer[i+l]) ? buffer[i+l] : (char)254);
- subtmp[l] = '\0';
- disp_w(2+j, 3, BOLD, subtmp);
- }
-
- while (inchar() != K_CR)
- ;
- flushscr();
- delete_w();
- }
- # endif
-
-
- static void oraschmeggie(buf)
- char *buf;
- {
- int cur, new, left, right;
-
- left = 0;
- right = strlen(buf);
-
- while ((new = cur = left + MAX_ORA_BUFF) < right)
- {
- while (cur > left)
- {
- if (buf[cur] == ' ')
- {
- buf[cur] = '\n';
- new = cur;
- break;
- }
- cur--;
- }
- left = new;
- }
- }
-
-
- /*
- * Assign section
- */
-
- void assign_IO_OR(dbnum)
- int dbnum;
- {
- Fntab[dbnum - 1][0] = (int(*)())0; /* Empty */
- Fntab[dbnum - 1][1] = i_init_file;
- Fntab[dbnum - 1][2] = i_open_file;
- Fntab[dbnum - 1][3] = i_close_file;
- Fntab[dbnum - 1][4] = i_addrec;
- Fntab[dbnum - 1][5] = i_delrec;
- Fntab[dbnum - 1][6] = i_findkey;
- Fntab[dbnum - 1][7] = i_firstkey;
- Fntab[dbnum - 1][8] = i_lastkey;
- Fntab[dbnum - 1][9] = i_lockrec;
- Fntab[dbnum - 1][10] = i_nextrec;
- Fntab[dbnum - 1][11] = i_prevrec;
- Fntab[dbnum - 1][12] = i_unlock_rec;
- Fntab[dbnum - 1][13] = i_updrec;
- Fntab[dbnum - 1][14] = i_commit;
- Fntab[dbnum - 1][15] = i_login;
- Fntab[dbnum - 1][16] = i_logoff;
- Fntab[dbnum - 1][17] = i_rollback;
- Fntab[dbnum - 1][18] = i_transact;
- Fntab[dbnum - 1][19] = i_selectinx;
- Fntab[dbnum - 1][20] = i_rereadrec;
- Fntab[dbnum - 1][21] = i_filename;
- }
-
-