2 // ociglue.cs - provides glue between
3 // managed C#/.NET System.Data.OracleClient.dll and
4 // unmanaged native c library oci.dll
5 // to be used in Mono System.Data.OracleClient as
6 // the Oracle 8i data provider.
8 // Part of managed C#/.NET library System.Data.OracleClient.dll
10 // Part of the Mono class libraries at
11 // mcs/class/System.Data.OracleClient/System.Data.OracleClient.OCI
13 // Assembly: System.Data.OracleClient.dll
14 // Namespace: System.Data.OracleClient
17 // Daniel Morgan <danmorg@sc.rr.com>
19 // Copyright (C) Daniel Morgan, 2002
23 using System.Runtime.InteropServices;
25 namespace System.Data.OracleClient.OCI {
26 internal sealed class OciGlue {
28 // TODO: need to clean up, dispose, close, etc...
30 // connection parameters
35 private UInt32 ociGlueConnectionHandle = 0;
37 // http://download-west.oracle.com/docs/cd/A87861_01/NT817EE/index.htm
38 // from oracle/ora81/oci/include/oci.h
40 // Currently, these are not being used, nor are the
41 // OCI_* constants nor the DllImports for oci.dll
42 IntPtr myenvhp = IntPtr.Zero; // OCIEnv - the environment handle
43 IntPtr mysrvhp = IntPtr.Zero; // OCIServer - the server handle
44 IntPtr myerrhp = IntPtr.Zero; // OCIError - the error handle
45 IntPtr myusrhp = IntPtr.Zero; // OCISession- user session handle
46 IntPtr mysvchp = IntPtr.Zero; // OCISvcCtx- the service handle
48 public const UInt32 OCI_DEFAULT = (UInt32) 0x00;
50 public const UInt32 OCI_THREADED = (UInt32) 0x01;
51 public const UInt32 OCI_OBJECT = (UInt32) 0x02;
52 public const UInt32 OCI_EVENTS = (UInt32) 0x04;
53 public const UInt32 OCI_RESERVED1 = (UInt32) 0x08;
54 public const UInt32 OCI_SHARED = (UInt32) 0x10;
55 public const UInt32 OCI_RESERVED2 = (UInt32) 0x20;
57 public const UInt32 OCI_NO_UCB = (UInt32) 0x40;
58 public const UInt32 OCI_NO_MUTEX = (UInt32) 0x80;
60 public const UInt32 OCI_SHARED_EXT = (UInt32) 0x100;
61 public const UInt32 OCI_CACHE = (UInt32) 0x200;
62 public const UInt32 OCI_NO_CACHE = (UInt32) 0x400;
64 public const UInt32 OCI_HTYPE_FIRST = 1;
65 public const UInt32 OCI_HTYPE_ENV = 1;
66 public const UInt32 OCI_HTYPE_ERROR = 2;
67 public const UInt32 OCI_HTYPE_SVCCTX = 3;
68 public const UInt32 OCI_HTYPE_STMT = 4;
69 public const UInt32 OCI_HTYPE_BIND = 5;
70 public const UInt32 OCI_HTYPE_DEFINE = 6;
71 public const UInt32 OCI_HTYPE_DESCRIBE = 7;
72 public const UInt32 OCI_HTYPE_SERVER = 8;
73 public const UInt32 OCI_HTYPE_SESSION = 9;
74 public const UInt32 OCI_HTYPE_TRANS =10;
75 public const UInt32 OCI_HTYPE_COMPLEXOBJECT =11;
76 public const UInt32 OCI_HTYPE_SECURITY =12;
77 public const UInt32 OCI_HTYPE_SUBSCRIPTION =13;
78 public const UInt32 OCI_HTYPE_DIRPATH_CTX =14;
79 public const UInt32 OCI_HTYPE_DIRPATH_COLUMN_ARRAY =15;
80 public const UInt32 OCI_HTYPE_DIRPATH_STREAM =16;
81 public const UInt32 OCI_HTYPE_PROC =17;
82 public const UInt32 OCI_HTYPE_LAST =17;
84 public const UInt32 OCI_ATTR_FNCODE =1;
85 public const UInt32 OCI_ATTR_OBJECT =2;
86 public const UInt32 OCI_ATTR_NONBLOCKING_MODE =3;
87 public const UInt32 OCI_ATTR_SQLCODE =4;
88 public const UInt32 OCI_ATTR_ENV =5;
89 public const UInt32 OCI_ATTR_SERVER =6;
90 public const UInt32 OCI_ATTR_SESSION =7;
91 public const UInt32 OCI_ATTR_TRANS =8;
92 public const UInt32 OCI_ATTR_ROW_COUNT = 9;
93 public const UInt32 OCI_ATTR_SQLFNCODE =10;
94 public const UInt32 OCI_ATTR_PREFETCH_ROWS = 11;
95 public const UInt32 OCI_ATTR_NESTED_PREFETCH_ROWS =12;
96 public const UInt32 OCI_ATTR_PREFETCH_MEMORY =13;
97 public const UInt32 OCI_ATTR_NESTED_PREFETCH_MEMORY =14;
98 public const UInt32 OCI_ATTR_CHAR_COUNT =15;
100 public const UInt32 OCI_ATTR_PDSCL =16;
101 public const UInt32 OCI_ATTR_FSPRECISION =OCI_ATTR_PDSCL;
103 public const UInt32 OCI_ATTR_PDPRC =17;
104 public const UInt32 OCI_ATTR_LFPRECISION =OCI_ATTR_PDPRC;
106 public const UInt32 OCI_ATTR_PARAM_COUNT =18;
107 public const UInt32 OCI_ATTR_ROWID =19;
108 public const UInt32 OCI_ATTR_CHARSET =20;
109 public const UInt32 OCI_ATTR_NCHAR =21;
110 public const UInt32 OCI_ATTR_USERNAME =22;
111 public const UInt32 OCI_ATTR_PASSWORD =23;
112 public const UInt32 OCI_ATTR_STMT_TYPE = 24;
113 public const UInt32 OCI_ATTR_INTERNAL_NAME = 25;
114 public const UInt32 OCI_ATTR_EXTERNAL_NAME = 26;
115 public const UInt32 OCI_ATTR_XID = 27;
116 public const UInt32 OCI_ATTR_TRANS_LOCK =28;
117 public const UInt32 OCI_ATTR_TRANS_NAME= 29;
118 public const UInt32 OCI_ATTR_HEAPALLOC =30;
119 public const UInt32 OCI_ATTR_CHARSET_ID =31;
120 public const UInt32 OCI_ATTR_CHARSET_FORM =32;
121 public const UInt32 OCI_ATTR_MAXDATA_SIZE =33;
122 public const UInt32 OCI_ATTR_CACHE_OPT_SIZE =34;
123 public const UInt32 OCI_ATTR_CACHE_MAX_SIZE =35;
124 public const UInt32 OCI_ATTR_PINOPTION =36;
125 public const UInt32 OCI_ATTR_ALLOC_DURATION =37;
127 public const UInt32 OCI_ATTR_PIN_DURATION =38;
128 public const UInt32 OCI_ATTR_FDO =39;
129 public const UInt32 OCI_ATTR_POSTPROCESSING_CALLBACK =40;
131 public const UInt32 OCI_ATTR_POSTPROCESSING_CONTEXT =41;
133 public const UInt32 OCI_ATTR_ROWS_RETURNED =42;
135 public const UInt32 OCI_ATTR_FOCBK =43;
136 public const UInt32 OCI_ATTR_IN_V8_MODE =44;
137 public const UInt32 OCI_ATTR_LOBEMPTY =45;
138 public const UInt32 OCI_ATTR_SESSLANG =46;
140 public const UInt32 OCI_ATTR_VISIBILITY = 47;
141 public const UInt32 OCI_ATTR_RELATIVE_MSGID = 48;
142 public const UInt32 OCI_ATTR_SEQUENCE_DEVIATION= 49;
144 public const UInt32 OCI_ATTR_CONSUMER_NAME = 50;
145 public const UInt32 OCI_ATTR_DEQ_MODE =51;
146 public const UInt32 OCI_ATTR_NAVIGATION = 52;
147 public const UInt32 OCI_ATTR_WAIT = 53;
148 public const UInt32 OCI_ATTR_DEQ_MSGID =54;
150 public const UInt32 OCI_ATTR_PRIORITY =55;
151 public const UInt32 OCI_ATTR_DELAY = 56;
152 public const UInt32 OCI_ATTR_EXPIRATION = 57;
153 public const UInt32 OCI_ATTR_CORRELATION = 58;
154 public const UInt32 OCI_ATTR_ATTEMPTS =59;
155 public const UInt32 OCI_ATTR_RECIPIENT_LIST = 60;
156 public const UInt32 OCI_ATTR_EXCEPTION_QUEUE =61;
157 public const UInt32 OCI_ATTR_ENQ_TIME =62;
158 public const UInt32 OCI_ATTR_MSG_STATE =63;
160 public const UInt32 OCI_ATTR_AGENT_NAME = 64;
161 public const UInt32 OCI_ATTR_AGENT_ADDRESS = 65;
162 public const UInt32 OCI_ATTR_AGENT_PROTOCOL = 66;
164 public const UInt32 OCI_ATTR_SENDER_ID =68;
165 public const UInt32 OCI_ATTR_ORIGINAL_MSGID = 69;
167 public const UInt32 OCI_ATTR_QUEUE_NAME = 70;
168 public const UInt32 OCI_ATTR_NFY_MSGID = 71;
169 public const UInt32 OCI_ATTR_MSG_PROP = 72;
171 public const UInt32 OCI_ATTR_NUM_DML_ERRORS = 73;
172 public const UInt32 OCI_ATTR_DML_ROW_OFFSET = 74;
174 public const UInt32 OCI_ATTR_DATEFORMAT = 75;
175 public const UInt32 OCI_ATTR_BUF_ADDR = 76;
176 public const UInt32 OCI_ATTR_BUF_SIZE = 77;
177 public const UInt32 OCI_ATTR_DIRPATH_MODE = 78;
178 public const UInt32 OCI_ATTR_DIRPATH_NOLOG = 79;
179 public const UInt32 OCI_ATTR_DIRPATH_PARALLEL = 80;
180 public const UInt32 OCI_ATTR_NUM_ROWS = 81;
182 public const UInt32 OCI_ATTR_COL_COUNT = 82;
184 public const UInt32 OCI_ATTR_STREAM_OFFSET = 83;
185 public const UInt32 OCI_ATTR_SHARED_HEAPALLOC = 84;
187 public const UInt32 OCI_ATTR_SERVER_GROUP = 85;
189 public const UInt32 OCI_ATTR_MIGSESSION = 86;
191 public const UInt32 OCI_ATTR_NOCACHE = 87;
193 public const UInt32 OCI_ATTR_MEMPOOL_SIZE = 88;
194 public const UInt32 OCI_ATTR_MEMPOOL_INSTNAME = 89;
195 public const UInt32 OCI_ATTR_MEMPOOL_APPNAME = 90;
196 public const UInt32 OCI_ATTR_MEMPOOL_HOMENAME = 91;
197 public const UInt32 OCI_ATTR_MEMPOOL_MODEL = 92;
198 public const UInt32 OCI_ATTR_MODES = 93;
200 public const UInt32 OCI_ATTR_SUBSCR_NAME = 94;
201 public const UInt32 OCI_ATTR_SUBSCR_CALLBACK = 95;
202 public const UInt32 OCI_ATTR_SUBSCR_CTX = 96;
203 public const UInt32 OCI_ATTR_SUBSCR_PAYLOAD = 97;
204 public const UInt32 OCI_ATTR_SUBSCR_NAMESPACE = 98;
206 public const UInt32 OCI_ATTR_PROXY_CREDENTIALS = 99;
207 public const UInt32 OCI_ATTR_INITIAL_CLIENT_ROLES = 100;
209 public const UInt32 OCI_ATTR_UNK = 101;
210 public const UInt32 OCI_ATTR_NUM_COLS = 102;
211 public const UInt32 OCI_ATTR_LIST_COLUMNS = 103;
212 public const UInt32 OCI_ATTR_RDBA = 104;
213 public const UInt32 OCI_ATTR_CLUSTERED = 105;
214 public const UInt32 OCI_ATTR_PARTITIONED = 106;
215 public const UInt32 OCI_ATTR_INDEX_ONLY = 107;
216 public const UInt32 OCI_ATTR_LIST_ARGUMENTS = 108;
217 public const UInt32 OCI_ATTR_LIST_SUBPROGRAMS =109;
218 public const UInt32 OCI_ATTR_REF_TDO = 110;
219 public const UInt32 OCI_ATTR_LINK = 111;
220 public const UInt32 OCI_ATTR_MIN = 112;
221 public const UInt32 OCI_ATTR_MAX = 113;
222 public const UInt32 OCI_ATTR_INCR = 114;
223 public const UInt32 OCI_ATTR_CACHE = 115;
224 public const UInt32 OCI_ATTR_ORDER = 116;
225 public const UInt32 OCI_ATTR_HW_MARK = 117;
226 public const UInt32 OCI_ATTR_TYPE_SCHEMA = 118;
227 public const UInt32 OCI_ATTR_TIMESTAMP = 119;
228 public const UInt32 OCI_ATTR_NUM_ATTRS = 120;
229 public const UInt32 OCI_ATTR_NUM_PARAMS = 121;
230 public const UInt32 OCI_ATTR_OBJID = 122;
231 public const UInt32 OCI_ATTR_PTYPE = 123;
232 public const UInt32 OCI_ATTR_PARAM = 124;
233 public const UInt32 OCI_ATTR_OVERLOAD_ID = 125;
234 public const UInt32 OCI_ATTR_TABLESPACE = 126;
235 public const UInt32 OCI_ATTR_TDO = 127;
236 public const UInt32 OCI_ATTR_LTYPE = 128;
237 public const UInt32 OCI_ATTR_PARSE_ERROR_OFFSET =129;
238 public const UInt32 OCI_ATTR_IS_TEMPORARY = 130;
239 public const UInt32 OCI_ATTR_IS_TYPED = 131;
240 public const UInt32 OCI_ATTR_DURATION = 132;
241 public const UInt32 OCI_ATTR_IS_INVOKER_RIGHTS= 133;
242 public const UInt32 OCI_ATTR_OBJ_NAME = 134;
243 public const UInt32 OCI_ATTR_OBJ_SCHEMA = 135;
244 public const UInt32 OCI_ATTR_OBJ_ID = 136;
246 public const UInt32 OCI_ATTR_DIRPATH_SORTED_INDEX = 137;
248 public const UInt32 OCI_ATTR_DIRPATH_INDEX_MAINT_METHOD= 138;
250 public const UInt32 OCI_ATTR_DIRPATH_FILE =139;
251 public const UInt32 OCI_ATTR_DIRPATH_STORAGE_INITIAL =140;
252 public const UInt32 OCI_ATTR_DIRPATH_STORAGE_NEXT =141;
254 public const UInt32 OCI_ATTR_TRANS_TIMEOUT = 142;
255 public const UInt32 OCI_ATTR_SERVER_STATUS = 143;
256 public const UInt32 OCI_ATTR_STATEMENT = 144;
258 public const UInt32 OCI_ATTR_NO_CACHE = 145;
259 public const UInt32 OCI_ATTR_RESERVED_1 = 146;
260 public const UInt32 OCI_ATTR_SERVER_BUSY = 147;
262 public const UInt32 OCI_UCS2ID = 1000;
264 public const UInt32 OCI_SERVER_NOT_CONNECTED = 0x0;
265 public const UInt32 OCI_SERVER_NORMAL = 0x1;
267 public const UInt32 OCI_SUBSCR_NAMESPACE_ANONYMOUS = 0;
268 public const UInt32 OCI_SUBSCR_NAMESPACE_AQ = 1;
269 public const UInt32 OCI_SUBSCR_NAMESPACE_MAX = 2;
271 public const UInt32 OCI_CRED_RDBMS = 1;
272 public const UInt32 OCI_CRED_EXT = 2;
273 public const UInt32 OCI_CRED_PROXY = 3;
275 public const Int32 OCI_SUCCESS = 0;
276 public const Int32 OCI_SUCCESS_WITH_INFO = 1;
277 public const Int32 OCI_RESERVED_FOR_INT_USE = 200;
278 public const Int32 OCI_NO_DATA = 100;
279 public const Int32 OCI_ERROR = -1;
280 public const Int32 OCI_INVALID_HANDLE = -2;
281 public const Int32 OCI_NEED_DATA = 99;
282 public const Int32 OCI_STILL_EXECUTING = -3123;
283 public const Int32 OCI_CONTINUE = -24200;
285 // from oci/include/ociap.h
287 //------ Platform Invoke to native c library oci.dll ----------
289 [DllImport("oci.dll")]
290 public static extern Int32 OCIEnvCreate (
291 out IntPtr envhpp, UInt32 mode, IntPtr ctxp,
292 ref IntPtr malocfp, ref IntPtr ralocfp, ref IntPtr mfreefp,
293 uint xtramemsz, out IntPtr usrmempp);
294 //sword OCIEnvCreate (
295 // OCIEnv **envhpp, ub4 mode, CONST dvoid *ctxp,
296 // CONST dvoid *(*malocfp) (dvoid *ctxp, size_t size),
297 // CONST dvoid *(*ralocfp) (dvoid *ctxp, dvoid *memptr, size_t newsize),
298 // CONST void (*mfreefp) (dvoid *ctxp, dvoid *memptr)),
299 // size_t xtramemsz, dvoid **usrmempp);
300 // [OUT],[IN],[IN],[IN],[IN],[IN],[IN],[OUT]
302 [DllImport("oci.dll")]
303 public static extern Int32 OCIHandleAlloc (
304 IntPtr parenth, ref IntPtr hndlpp, UInt32 type,
305 int xtramem_sz, ref IntPtr usrmempp);
306 //sword OCIHandleAlloc(
307 // CONST dvoid *parenth, dvoid **hndlpp, ub4 type,
308 // size_t xtramem_sz, dvoid **usrmempp );
309 // [IN],OUT],[OUT],[IN],[OUT]
311 [DllImport("oci.dll")]
312 public static extern Int32 OCIServerAttach (
313 ref IntPtr srvhp, ref IntPtr errhp, string dblink,
314 Int32 dblink_len, UInt32 mode);
315 //sword OCIServerAttach (
316 // OCIServer *srvhp, OCIError *errhp, CONST text *dblink,
317 // sb4 dblink_len, ub4 mode);
318 // [IN/OUT],[IN/OUT],[IN],[IN],[IN]
320 [DllImport("oci.dll")]
321 public static extern Int32 OCIAttrSet (
322 ref IntPtr trgthndlp, UInt32 trghndltyp, IntPtr attributep,
323 UInt32 size, UInt32 attrtype,
326 // dvoid *trgthndlp, ub4 trghndltyp, dvoid *attributep,
327 // ub4 size, ub4 attrtype, OCIError *errhp );
328 // [IN/OUT], [IN/OUT], [IN], [IN], [IN], [IN/OUT]
330 [DllImport("oci.dll")]
331 public static extern Int32 OCISessionBegin (
332 IntPtr svchp, ref IntPtr errhp, ref IntPtr usrhp,
333 UInt32 credt, UInt32 mode);
334 //sword OCISessionBegin (
335 // OCISvcCtx *svchp, OCIError *errhp,
336 // OCISession *usrhp, ub4 credt, ub4 mode );
337 // [IN],[IN],[IN/OUT],[IN],[IN]
339 [DllImport("oci.dll")]
340 public static extern UInt32 OCIErrorGet (
341 ref IntPtr hndlp, UInt32 recordno, ref IntPtr sqlstate,
342 out Int32 errcodep, out string bufp, UInt32 bufsiz,
345 // dvoid *hndlp, ub4 recordno, text *sqlstate,
346 // sb4 *errcodep, text *bufp, ub4 bufsiz,
348 // [IN],[IN],[OUT],[OUT],[OUT],[IN],[IN]
350 //------ Platform Invoke to native c library System.Data.OracleClient.ociglue.dll ----------
351 // System.Data.OracleClient.ociglue.dll is the glue between C# and oci.dll
353 [DllImport("System.Data.OracleClient.ociglue.dll")]
354 public static extern IntPtr OciGlue_OCIEnvCreate(ref Int32 status);
355 // void *OciGlue_OCIEnvCreate(sword *status);
357 [DllImport("System.Data.OracleClient.ociglue.dll")]
358 public static extern IntPtr OciGlue_OCIHandleAlloc(ref Int32 status,
359 IntPtr parenth, UInt32 type);
360 // dvoid *OciGlue_OCIHandleAlloc(sword *status,
361 // CONST dvoid *parenth, ub4 type);
363 [DllImport("System.Data.OracleClient.ociglue.dll")]
364 public static extern void OciGlue_OCIServerAttach(ref Int32 status,
366 IntPtr errhp, string dblink, UInt32 mode);
367 // void OciGlue_OCIServerAttach(sword *status, dvoid *srvhp,
368 // dvoid *errhp, char *dblink, ub4 mode);
370 [DllImport("System.Data.OracleClient.ociglue.dll")]
371 public static extern void OciGlue_OCIAttrSet(ref Int32 status,
372 IntPtr trgthndlp, UInt32 trghndltyp,
373 IntPtr attributep, UInt32 size, UInt32 attrtype,
375 //void OciGlue_OCIAttrSet(sword *status,
376 // dvoid *trgthndlp, ub4 trghndltyp,
377 // dvoid *attributep, ub4 size, ub4 attrtype,
380 [DllImport("System.Data.OracleClient.ociglue.dll")]
381 public static extern IntPtr OciGlue_OCISessionBegin(ref Int32 status,
382 IntPtr svchp, IntPtr errhp, IntPtr usrhp,
383 UInt32 credt, UInt32 mode);
384 // void OciGlue_OCISessionBegin(sword *status,
385 // dvoid *svchp, dvoid *errhp, dvoid *usrhp,
386 // ub4 credt, ub4 mode )
388 [DllImport("System.Data.OracleClient.ociglue.dll")]
389 public static extern Int32 OciGlue_Connect (
390 out UInt32 ociGlueConnectionHandle,
392 string username, string password);
393 //sword OciGlue_Connect (
394 // uint4 oci_glue_handle,
396 // char *username, char *password);
398 [DllImport("System.Data.OracleClient.ociglue.dll")]
399 public static extern Int32 OciGlue_Disconnect (UInt32 connection_handle);
400 // sword OciGlue_Disconnect (ub4 connection_handle);
402 [DllImport("System.Data.OracleClient.ociglue.dll")]
403 public static extern Int32 OciGlue_PrepareAndExecuteNonQuerySimple (
404 UInt32 ociGlueConnectionHandle,
405 string sqlstmt, out int found);
406 //sword OciGlue_PrepareAndExecuteNonQuerySimple (
407 // guint4 oci_glue_handle,
408 // char *sqlstmt, int *found);
410 [DllImport("System.Data.OracleClient.ociglue.dll")]
411 public static extern UInt32 OciGlue_ConnectionCount();
412 //guint OciGlue_ConnectionCount();
414 [DllImport("System.Data.OracleClient.ociglue.dll")]
415 public static extern IntPtr OciGlue_CheckError (Int32 status, UInt32 connection_handle);
416 // CONST text *OciGlue_CheckError (sword status, ub4 connection_handle);
418 [DllImport("System.Data.OracleClient.ociglue.dll")]
419 public static extern void Free (IntPtr obj);
420 // void Free (void *obj);
422 // --------- Methods --------------------------------
424 public string OciGlueCheckError(Int32 status) {
425 IntPtr intptrMsg = IntPtr.Zero;
429 intptrMsg = OciGlue_CheckError(status, ociGlueConnectionHandle);
430 strMsg = Marshal.PtrToStringAnsi(intptrMsg);
432 msg = String.Copy(strMsg);
440 public static void IsObjectNull(string usedfor, string name, object obj) {
446 exists = "is not null";
448 IntPtr intptr = (IntPtr) obj;
449 if(intptr == IntPtr.Zero)
450 exists = exists + " - IntPtr is IntPtr.Zero";
452 exists = exists + " - IntPtr is not IntPtr.Zero";
456 "UsedFor: " + usedfor +
457 " Object name: " + name +
458 " exists: " + exists;
461 public Int32 OciGlueConnect(OracleConnectionInfo conInfo) {
465 database = conInfo.Database;
466 username = conInfo.Username;
467 password = conInfo.Password;
469 Console.WriteLine("OciGlue_Connect");
470 status = OciGlue.OciGlue_Connect (out ociGlueConnectionHandle,
471 database, username, password);
472 Console.WriteLine(" Handle: " + ociGlueConnectionHandle);
481 public Int32 OciGlueDisconnect() {
486 Console.WriteLine("OciGlue_Disconnect");
487 Console.WriteLine(" Handle: " + ociGlueConnectionHandle);
488 status = OciGlue.OciGlue_Disconnect (ociGlueConnectionHandle);
489 ociGlueConnectionHandle = 0;
492 msg = CheckStatus(status);
493 throw new Exception(msg);
501 public Int32 PrepareAndExecuteNonQuerySimple(string sql)
506 Console.WriteLine("PrepareAndExecuteNonQuerySimple");
507 status = OciGlue_PrepareAndExecuteNonQuerySimple (
508 ociGlueConnectionHandle, sql, out found);
510 Console.WriteLine(" Handle: " + ociGlueConnectionHandle +
511 " Found: " + found.ToString());
517 // currently not used
518 public void Connect()
521 IntPtr nothing = IntPtr.Zero;
522 // initialize the mode to be the threaded and object environment
524 // OCI_THREADED|OCI_OBJECT
526 // OCI_THREADED|OCI_OBJECT|OCI_NO_UCB
527 //status = OCIEnvCreate(out myenvhp, OCI_DEFAULT|OCI_NO_UCB,
529 // ref nothing, ref nothing, ref nothing, 0,
531 myenvhp = OciGlue_OCIEnvCreate(ref status);
532 IsObjectNull("Result from OCIEnvCreate for initialize the mode for environment","myenvhp",myenvhp);
535 // allocate a server handle
537 //status = OCIHandleAlloc (myenvhp, ref mysrvhp,
538 // OCI_HTYPE_SERVER, 0, ref nothing);
539 mysrvhp = OciGlue_OCIHandleAlloc(ref status,
540 myenvhp, OCI_HTYPE_SERVER);
541 IsObjectNull("Result from OCIHandleAlloc for server handle","mysrvhp",mysrvhp);
544 // allocate an error handle
546 //status = OCIHandleAlloc (myenvhp, ref myerrhp,
547 // OCI_HTYPE_ERROR, 0, ref nothing);
548 myerrhp = OciGlue_OCIHandleAlloc(ref status,
549 myenvhp, OCI_HTYPE_ERROR);
550 IsObjectNull("Result from OCIHandleAlloc for error handle","myerrhp",myerrhp);
553 // create a server context
555 string dblink = "DANSDB";
556 //mysrvhp = OciGlueMallocType (OciGlueType_OCIServer);
557 //status = OCIServerAttach (ref mysrvhp, ref myerrhp, dblink,
558 // dblink.Length, OCI_DEFAULT);
559 OciGlue_OCIServerAttach(ref status,
560 mysrvhp, myerrhp, dblink, OCI_DEFAULT);
561 IsObjectNull("Result from OCIServerAttach for server context","mysrvhp",mysrvhp);
564 // allocate a service handle
566 //status = OCIHandleAlloc (myenvhp, ref mysvchp,
567 // OCI_HTYPE_SVCCTX, 0, ref nothing);
568 mysvchp = OciGlue_OCIHandleAlloc(ref status,
569 myenvhp, OCI_HTYPE_SVCCTX);
570 IsObjectNull("Result from OCIHandleAlloc for service handle","myenvhp",mysvchp);
574 // set the server attribute in the service context handle
577 //status = OCIAttrSet (
578 // ref mysvchp, OCI_HTYPE_SVCCTX,
579 // mysrvhp, 0, OCI_ATTR_SERVER, ref myerrhp);
580 OciGlue_OCIAttrSet(ref status,
581 mysvchp, OCI_HTYPE_SVCCTX,
582 mysrvhp, (UInt32) 0, OCI_ATTR_SERVER, myerrhp);
584 IsObjectNull("Result from OCIAttrSet for server attribute","mysvchp",mysvchp);
585 Console.WriteLine("status is: " + status.ToString());
588 // allocate a user session handle
589 Console.WriteLine(" blah ");
591 //status = OCIHandleAlloc (myenvhp, ref myusrhp,
592 // OCI_HTYPE_SESSION, 0, ref nothing);
593 myusrhp = OciGlue_OCIHandleAlloc(ref status,
594 myenvhp, OCI_HTYPE_SESSION);
595 IsObjectNull("Result from OCIHandleAlloc for user session","myusrhp",myusrhp);
598 // set username attribute in user session handle
600 string username = "scott";
601 IntPtr intptrUsername = Marshal.StringToHGlobalAnsi( username );
602 //status = OCIAttrSet (
603 // ref myusrhp, OCI_HTYPE_SESSION,
604 // intptrUsername, (UInt32) username.Length,
605 // OCI_ATTR_USERNAME, ref myerrhp);
606 OciGlue_OCIAttrSet(ref status,
607 myusrhp, OCI_HTYPE_SESSION,
608 intptrUsername, (UInt32) username.Length,
609 OCI_ATTR_USERNAME, myerrhp);
610 IsObjectNull("Result from OCIAttrSet for username","myusrhp",myusrhp);
613 // set password attribute in user session handle
615 string password = "tiger";
616 IntPtr intptrPassword = Marshal.StringToHGlobalAnsi( password );
617 //status = OCIAttrSet (ref myusrhp,
618 // OCI_HTYPE_SESSION,
619 // intptrPassword, (UInt32) password.Length,
620 // OCI_ATTR_PASSWORD, ref myerrhp);
621 OciGlue_OCIAttrSet(ref status,
624 intptrPassword, (UInt32) password.Length,
625 OCI_ATTR_PASSWORD, myerrhp);
626 IsObjectNull("Result from OCIAttrSet for password","myusrhp",myusrhp);
631 //status = OCISessionBegin (mysvchp, ref myerrhp, ref myusrhp,
632 // OCI_CRED_RDBMS, OCI_DEFAULT);
633 OciGlue_OCISessionBegin(ref status,
634 mysvchp, myerrhp, myusrhp,
635 OCI_CRED_RDBMS, OCI_DEFAULT);
636 IsObjectNull("Result from OCISessionBegin","myusrhp",myusrhp);
639 // FIXME: check for errors to make sure
640 // authentication was successful
642 // set the user session attribute in the service context handle
644 //status = OCIAttrSet (ref mysvchp,
646 // myusrhp, 0, OCI_ATTR_SESSION, ref myerrhp);
647 OciGlue_OCIAttrSet(ref status,
650 myusrhp, 0, OCI_ATTR_SESSION, myerrhp);
651 IsObjectNull("Result from OCIAttrSet for user session attribute in service context handle","myusrhp",myusrhp);
655 // FIXME: check for errors after each call
657 // FIXME: need to properly free resources, such as,
658 // intptrUsername, intptrPassword, etc...
661 Console.WriteLine("Waiting... Press Enter to continue.");
662 string s = Console.ReadLine();
664 Console.WriteLine("Exiting...");
667 public string CheckStatus(Int32 status) {
668 return CheckError(status);
671 // OCIError errhp, Int32 status
672 public string CheckError(Int32 status) {
680 case OCI_SUCCESS_WITH_INFO:
681 msg = "Error - OCI_SUCCESS_WITH_INFO";
684 msg = "Error - OCI_NEED_DATA";
687 msg = "Error - OCI_NODATA";
690 if(ociGlueConnectionHandle != 0) {
691 string errmsg = OciGlueCheckError(status);
692 //OCIErrorGet(ref errhp, 1, ref nullString, out errcode,
693 // out errbuf, (UInt32) errbuf.Length, OCI_HTYPE_ERROR);
694 msg = "OCI Error - errcode: " + errcode.ToString() + " errbuf: " + errmsg;
699 case OCI_INVALID_HANDLE:
700 msg = "Error - OCI_INVALID_HANDLE";
702 case OCI_STILL_EXECUTING:
703 msg = "Error - OCI_STILL_EXECUTE";
706 msg = "Error - OCI_CONTINUE";