1 /* oiface.h */
2 
3 /* This is part of the CLISP Oracle interface from Alma Mater
4    Software.  Copyright (C) 2002 Alma Mater Software, Inc.
5 
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License version 2
8   or (at your option) any later version
9   as published by the Free Software Foundation; see file GNU-GPL.
10 
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15 
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software Foundation,
18   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 */
21 
22 /* Column info returned to external program.  All pointers here point
23    either to corresponding members in (struct column) or to
24    constant/static data. */
25 
26 struct sqlcol {
27   char *        name;           /* Points to column.name */
28   char *        type;           /* Points to result of decode_data_type(column.dtype)) */
29   int           size;           /* Same as column.dsize */
30   int           scale;          /* Same as column.scale */
31   int           precision;      /* Same as column.precision */
32   int           null_ok;        /* Same as column.null_ok */
33 };
34 
35 /* Row info returned to external program.  Pointers here point into
36    corresponding members in (struct column). */
37 
38 struct sqlval {
39   char *        data;           /* Points to column.data */
40   int           is_null;        /* Same as column.indicator -1=NULL 0=exact */
41 };
42 
43 /* Bind parameter input to a SQL statement.  We support named
44    paramters only (no positional parameters) */
45 struct sqlparam {
46   char *            name;           /* Parameter name */
47   struct sqlval     value;          /* Parameter value */
48 };
49 
50 /* Column coming back from a SELECT */
51 struct column {
52   /* Column info extracted from OCIAttrGet(stmt) */
53   char *        name;       /* OCI_ATTR_NAME */
54   ub2           dtype;      /* OCI_ATTR_DATA_TYPE */
55   ub2           dsize;      /* OCI_ATTR_DATA_SIZE */
56   sb1           scale;      /* OCI_ATTR_SCALE */
57   ub1           precision;  /* OCI_ATTR_PRECISION */
58   ub1           null_ok;    /* OCI_ATTR_IS_NULL */
59 
60   /* Fetch info and results */
61   OCIDefine *   def;        /* Returned from OCIDefineByPos() */
62 
63   void *        data;       /* Our malloc'd buffer (of dsize bytes) */
64   sb2           indicator;  /* "Indicator" variable w/ flags for NULL and truncated:
65                                  -2 = data too large, even too large to say size in sb2
66                                  -1 = data is null
67                                  0 = exact data was fetched
68                                  >0 = original size before truncation to "define" variable len */
69   ub2           nfetched;   /* No. of bytes actually fetched */
70   ub2           rcode;      /* Column-level return code */
71 
72   OCILobLocator * lob_locator;  /* Special destination for LobLocator fetch */
73 };
74 
75 /* Database connection, incl. (max of one) current statement, as well
76    as results and status. */
77 struct db_conn {
78 
79   /* Per connection */
80   OCIEnv *          env;            /* Oracle environment handle */
81   OCIError *        err;            /* "" */
82   OCISvcCtx *       svc;            /* "" */
83   int               prefetch_bytes; /* No. of bytes for pre-fetch buffer, or -1 for default */
84   int               long_len;       /* No. of bytes to truncate LONG columns */
85   int               truncate_ok;    /* Flag: allow truncated fetch? */
86   int               auto_commit;    /* Flag: commit after each command? */
87   OCIStmt *         stmt;           /* Oracle statement */
88 
89   char *            user;           /* User ID */
90   char *            schema;         /* Schema */
91   char *            sid;            /* SID logged on to */
92 
93   /* Per executed SQL statement */
94   char *            sql;            /* Malloced SQL query or command */
95   int               is_command;     /* True if SQL is a command (i.e., not a SELECT) */
96   char **           params;         /* Bind parameters for sql command */
97   int               nparam;         /* No. of bind parameters */
98   struct column *   columns;        /* Result column info and current row data (internal version) */
99   struct sqlcol **  sqlcols;        /* Result column info and current row data (external version) */
100   struct sqlval **  currow;         /* Current row data */
101   int               ncol;           /* No. of columns */
102 
103   /* Per fetch */
104   int               rows_affected;  /* No. of rows fetched to present, or rows affected by command */
105   int               eof;            /* Flag: at EOF? */
106 
107   int               success;        /* Set after each operation w/ success */
108   char *            errmsg;         /* Malloc'd error buffer */
109 };
110 
111 /* Exported routines (w/ void *) */
112 
113 /* orafns.c */
114 void *           oracle_connect(char *, char *, char *, char *, int, int, int, int);
115 int              oracle_disconnect(void *);
116 int              oracle_exec_sql(void *, char *, struct sqlparam **, int);
117 
118 int              oracle_ncol(void *);               /* Active SELECT only, may be called any time after exec_sql() */
119 struct sqlcol ** oracle_column_info(void *);        /* "" */
120 int              oracle_fetch_row(void *);          /* "" */
121 int              oracle_eof(void *);                /* Active SELECT only, may be called only after fetch_row() */
122 struct sqlval ** oracle_row_values(void *);         /* "" */
123 
124 int              oracle_rows_affected(void *);      /* For SELECT, no. rows fetched so far; others: no. rows insert/update/delete */
125 
126 int              oracle_success(void *);            /* Check success of last operation.   May be called anytime */
127 
128 int              oracle_commit(void *);                 /* Commit current transaction (auto_commit off) */
129 int              oracle_rollback(void *);               /* Rollback current transaction */
130 int              oracle_set_auto_commit(void *, int);   /* Enable/disable auto-commit */
131 
132 /* oiface.c */
133 char *           oracle_last_error(void *);
134