00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ocilib_internal.h"
00036
00037
00038
00039
00040
00041 static mtext * OCILib_TypeNames[] =
00042 {
00043 MT("generic pointer"),
00044 MT("short pointer"),
00045 MT("int pointer"),
00046 MT("big_int pointer"),
00047 MT("double pointer"),
00048 MT("string pointer"),
00049 MT("function callback"),
00050
00051 MT("Error handle"),
00052 MT("Schema handle"),
00053 MT("Connection handle"),
00054 MT("Connection pool handle"),
00055 MT("Transaction handle"),
00056 MT("Statement handle"),
00057 MT("Resultset handle"),
00058 MT("Column handle"),
00059 MT("Date handle"),
00060 MT("Timestamp handle"),
00061 MT("Interval handle"),
00062 MT("Lob handle"),
00063 MT("File handle"),
00064 MT("Long handle"),
00065 MT("Object handle"),
00066 MT("Collection handle"),
00067 MT("Collection iterator handle"),
00068 MT("Collection element handle"),
00069 MT("Hash Table handle"),
00070 MT("Thread handle"),
00071 MT("Mutex handle"),
00072 MT("Bind handle"),
00073 MT("Ref handle"),
00074 MT("Direct Path handle"),
00075
00076 MT("Internal list handle"),
00077 MT("Internal list item handle"),
00078 MT("Internal array of bind handles"),
00079 MT("Internal define handle"),
00080 MT("Internal array of define handles"),
00081 MT("Internal hash entry handle"),
00082 MT("Internal array of hash entry handles"),
00083 MT("Internal hash value handle"),
00084 MT("Internal thread key handle"),
00085 MT("Internal Oracle date handle"),
00086 MT("Internal C tm structure"),
00087 MT("Internal array of resultset handles"),
00088 MT("Internal array of PL/SQL sizes integers"),
00089 MT("Internal array of PL/SQL return codes integers"),
00090 MT("Internal server output handle"),
00091 MT("Internal array of indicator integers"),
00092 MT("Internal array of buffer length integers"),
00093 MT("Internal array of data buffers"),
00094 MT("Internal Long handle data buffer"),
00095 MT("Internal trace info structure"),
00096 MT("Internal array of direct path columns"),
00097 MT("Internal array of batch error objects")
00098 };
00099
00100
00101 #if defined(OCI_CHARSET_UNICODE) && !defined(_MSC_VER)
00102
00103 static mtext * OCILib_ErrorMsg[] =
00104 {
00105 MT("No error"),
00106 MT("OCILIB has not been initialized"),
00107 MT("Cannot load OCI shared library (%ls)"),
00108 MT("Cannot load OCI symbols from shared library"),
00109 MT("OCILIB has not been initialized in multithreaded mode"),
00110 MT("Memory allocation failure (type %ls, size : %d)"),
00111 MT("Feature not available (%ls) "),
00112 MT("A null %ls has been provided"),
00113 MT("Oracle datatype (sqlcode %d) not supported for this operation "),
00114 MT("Unknown identifier %c while parsing SQL"),
00115 MT("Unknown argument %d while retrieving data"),
00116 MT("Index %d out of bounds"),
00117 MT("Found %d unfreed %ls"),
00118 MT("Maximum number of binds (%d) already reached"),
00119 MT("Object attribute '%ls' not found"),
00120 MT("The integer parameter value must be at least %d"),
00121 MT("Elements are not compatible"),
00122 MT("Unable to perform this operation on a %ls statement"),
00123 MT("The statement is not scrollable"),
00124 MT("Name or position '%ls' already binded to the statement"),
00125 MT("Invalid new size for bind arrays (initial %d, current %d, new %d)"),
00126 MT("Column '%ls' not find in table '%ls'"),
00127 MT("Unable to perform this operation on a %ls direct path process"),
00128 MT("Cannot create OCI environment")
00129 };
00130
00131 #else
00132
00133 static mtext * OCILib_ErrorMsg[] =
00134 {
00135 MT("No error"),
00136 MT("OCILIB has not been initialized"),
00137 MT("Cannot load OCI shared library (%s)"),
00138 MT("Cannot load OCI symbols from shared library"),
00139 MT("OCILIB has not been initialized in multithreaded mode"),
00140 MT("Memory allocation failure (type %s, size : %d)"),
00141 MT("Feature not available (%s) "),
00142 MT("A null %s has been provided"),
00143 MT("Oracle datatype (sqlcode %d) not supported for this operation "),
00144 MT("Unknown identifier %c while parsing SQL : "),
00145 MT("Unknown argument %d while retrieving data"),
00146 MT("Index %d out of bounds"),
00147 MT("Found %d unfreed %s"),
00148 MT("Maximum number of binds (%d) already reached"),
00149 MT("Object attribute '%s' not found"),
00150 MT("The integer parameter value must be at least %d"),
00151 MT("Elements are not compatible"),
00152 MT("Unable to perform this operation on a %s statement"),
00153 MT("The statement is not scrollable"),
00154 MT("Name or position '%s' already binded to the statement"),
00155 MT("Invalid new size for bind arrays (initial %d, current %d, new %d)"),
00156 MT("Column '%s' not find in table '%s'"),
00157 MT("Unable to perform this operation on a %s direct path process"),
00158 MT("Cannot create OCI environment")
00159 };
00160
00161 #endif
00162
00163 static mtext * OCILib_OraFeatures[] =
00164 {
00165 MT("Oracle 9i support for Unicode data"),
00166 MT("Oracle 9i Timestamps and Intervals"),
00167 MT("Oracle 9i Direct path date caching"),
00168 MT("Oracle 10g LOBs size extensions")
00169 MT("Oracle 11g remote database startup/shutdown")
00170 };
00171
00172 static mtext * OCILib_StmtStates[] =
00173 {
00174 MT("closed"),
00175 MT("prepared"),
00176 MT("executed")
00177 };
00178
00179 static mtext * OCILib_DirPathStates[] =
00180 {
00181 MT("non prepared"),
00182 MT("prepared"),
00183 MT("converted"),
00184 MT("terminated")
00185 };
00186
00187
00188 static mtext * OCILib_HandleNames[] =
00189 {
00190 MT("OCI handle"),
00191 MT("OCI descriptors"),
00192 MT("OCI Object handles")
00193 };
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 OCI_Error * OCI_ExceptionGetError(void)
00204 {
00205 OCI_Error *err = OCI_ErrorGet(TRUE);
00206
00207 if (err != NULL)
00208 {
00209 OCI_ErrorReset(err);
00210
00211 err->active = TRUE;
00212 }
00213
00214 return err;
00215 }
00216
00217
00218
00219
00220
00221 void OCI_ExceptionRaise(OCI_Error *err)
00222 {
00223 if (err != NULL)
00224 {
00225 if (OCILib.error_handler != NULL)
00226 OCILib.error_handler(err);
00227
00228 err->active = FALSE;
00229 }
00230 }
00231
00232
00233
00234
00235
00236 void OCI_ExceptionOCI(OCIError *p_err, OCI_Connection *con, OCI_Statement *stmt)
00237 {
00238 OCI_Error *err = OCI_ExceptionGetError();
00239
00240 if (err != NULL)
00241 {
00242 int osize = -1;
00243 void *ostr = NULL;
00244
00245 err->type = OCI_ERR_ORACLE;
00246 err->con = con;
00247 err->stmt = stmt;
00248
00249
00250
00251 osize = msizeof(err->str) - 1;
00252
00253 ostr = OCI_GetInputMetaString(err->str, &osize);
00254
00255 OCIErrorGet((dvoid *) p_err, (ub4) 1, (OraText *) NULL, &err->ocode,
00256 (OraText *) ostr, (ub4) osize, (ub4) OCI_HTYPE_ERROR);
00257
00258
00259 OCI_GetOutputMetaString(ostr, err->str, &osize);
00260 OCI_ReleaseMetaString(ostr);
00261 }
00262
00263 OCI_ExceptionRaise(err);
00264 }
00265
00266
00267
00268
00269
00270 void OCI_ExceptionNotInitialized(void)
00271 {
00272 OCI_Error *err = OCI_ExceptionGetError();
00273
00274 if (err != NULL)
00275 {
00276 err->type = OCI_ERR_OCILIB;
00277 err->icode = OCI_ERR_NOT_INITIALIZED;
00278
00279 mtsncat(err->str, OCILib_ErrorMsg[OCI_ERR_NOT_INITIALIZED],
00280 msizeof(err->str) - 1);
00281 }
00282
00283 OCI_ExceptionRaise(err);
00284 }
00285
00286
00287
00288
00289
00290 void OCI_ExceptionLoadingSharedLib(void)
00291 {
00292 #ifdef OCI_IMPORT_RUNTIME
00293
00294 OCI_Error *err = OCI_ExceptionGetError();
00295
00296 if (err != NULL)
00297 {
00298 err->type = OCI_ERR_OCILIB;
00299 err->icode = OCI_ERR_LOADING_SHARED_LIB;
00300
00301 mtsprintf(err->str, msizeof(err->str) - 1,
00302 OCILib_ErrorMsg[OCI_ERR_LOADING_SHARED_LIB],
00303 OCI_DL_META_NAME);
00304 }
00305
00306 OCI_ExceptionRaise(err);
00307
00308 #endif
00309 }
00310
00311
00312
00313
00314
00315 void OCI_ExceptionLoadingSymbols(void)
00316 {
00317 OCI_Error *err = OCI_ExceptionGetError();
00318
00319 if (err != NULL)
00320 {
00321 err->type = OCI_ERR_OCILIB;
00322 err->icode = OCI_ERR_LOADING_SYMBOLS;
00323
00324 mtsncat(err->str, OCILib_ErrorMsg[OCI_ERR_LOADING_SYMBOLS],
00325 msizeof(err->str) - 1);
00326 }
00327
00328 OCI_ExceptionRaise(err);}
00329
00330
00331
00332
00333
00334 void OCI_ExceptionNotMultithreaded(void)
00335 {
00336 OCI_Error *err = OCI_ExceptionGetError();
00337
00338 if (err != NULL)
00339 {
00340 err->type = OCI_ERR_OCILIB;
00341 err->icode = OCI_ERR_MULTITHREADED;
00342
00343 mtsncat(err->str, OCILib_ErrorMsg[OCI_ERR_MULTITHREADED],
00344 msizeof(err->str) - 1);
00345 }
00346
00347 OCI_ExceptionRaise(err);
00348 }
00349
00350
00351
00352
00353
00354 void OCI_ExceptionNullPointer(int type)
00355 {
00356 OCI_Error *err = OCI_ExceptionGetError();
00357
00358 if (err != NULL)
00359 {
00360 err->type = OCI_ERR_OCILIB;
00361 err->icode = OCI_ERR_NULL_POINTER;
00362
00363 mtsprintf(err->str, msizeof(err->str) - 1,
00364 OCILib_ErrorMsg[OCI_ERR_NULL_POINTER],
00365 OCILib_TypeNames[type-1]);
00366 }
00367
00368 OCI_ExceptionRaise(err);
00369 }
00370
00371
00372
00373
00374
00375 void OCI_ExceptionMemory(int type, size_t nb_bytes, OCI_Connection *con,
00376 OCI_Statement *stmt)
00377 {
00378 OCI_Error *err = OCI_ExceptionGetError();
00379
00380 if (err != NULL)
00381 {
00382 err->type = OCI_ERR_OCILIB;
00383 err->icode = OCI_ERR_MEMORY;
00384 err->con = con;
00385 err->stmt = stmt;
00386
00387 mtsprintf(err->str,
00388 msizeof(err->str) - 1,
00389 OCILib_ErrorMsg[OCI_ERR_MEMORY],
00390 OCILib_TypeNames[type-1],
00391 nb_bytes);
00392 }
00393
00394 OCI_ExceptionRaise(err);
00395 }
00396
00397
00398
00399
00400
00401 void OCI_ExceptionNotAvailable(OCI_Connection *con, int feature)
00402 {
00403 OCI_Error *err = OCI_ExceptionGetError();
00404
00405 if (err != NULL)
00406 {
00407 err->type = OCI_ERR_OCILIB;
00408 err->icode = OCI_ERR_NOT_AVAILABLE;
00409 err->con = con;
00410
00411 mtsprintf(err->str,
00412 msizeof(err->str) - 1,
00413 OCILib_ErrorMsg[OCI_ERR_NOT_AVAILABLE],
00414 OCILib_OraFeatures[feature-1]);
00415 }
00416
00417 OCI_ExceptionRaise(err);
00418 }
00419
00420
00421
00422
00423
00424 void OCI_ExceptionDatatypeNotSupported(OCI_Connection *con, OCI_Statement *stmt,
00425 int code)
00426 {
00427 OCI_Error *err = OCI_ExceptionGetError();
00428
00429 if (err != NULL)
00430 {
00431 err->type = OCI_ERR_OCILIB;
00432 err->icode = OCI_ERR_DATATYPE_NOT_SUPPORTED;
00433 err->con = con;
00434 err->stmt = stmt;
00435
00436 mtsprintf(err->str,
00437 msizeof(err->str) - 1,
00438 OCILib_ErrorMsg[OCI_ERR_DATATYPE_NOT_SUPPORTED],
00439 code);
00440 }
00441
00442 OCI_ExceptionRaise(err);
00443 }
00444
00445
00446
00447
00448
00449 void OCI_ExceptionParsingToken(OCI_Connection *con, OCI_Statement *stmt, mtext token)
00450 {
00451 OCI_Error *err = OCI_ExceptionGetError();
00452
00453 if (err != NULL)
00454 {
00455 err->type = OCI_ERR_OCILIB;
00456 err->icode = OCI_ERR_PARSE_TOKEN;
00457 err->con = con;
00458 err->stmt = stmt;
00459
00460 mtsprintf(err->str,
00461 msizeof(err->str) - 1,
00462 OCILib_ErrorMsg[OCI_ERR_PARSE_TOKEN],
00463 token);
00464 }
00465
00466 OCI_ExceptionRaise(err);
00467 }
00468
00469
00470
00471
00472
00473 void OCI_ExceptionMappingArgument(OCI_Connection *con, OCI_Statement *stmt,
00474 int arg)
00475 {
00476 OCI_Error *err = OCI_ExceptionGetError();
00477
00478 if (err != NULL)
00479 {
00480 err->type = OCI_ERR_OCILIB;
00481 err->icode = OCI_ERR_MAP_ARGUMENT;
00482 err->con = con;
00483 err->stmt = stmt;
00484
00485 mtsprintf(err->str,
00486 msizeof(err->str) - 1,
00487 OCILib_ErrorMsg[OCI_ERR_MAP_ARGUMENT],
00488 arg);
00489 }
00490
00491 OCI_ExceptionRaise(err);
00492 }
00493
00494
00495
00496
00497
00498 void OCI_ExceptionOutOfBounds(OCI_Connection *con, int value)
00499 {
00500 OCI_Error *err = OCI_ExceptionGetError();
00501
00502 if (err != NULL)
00503 {
00504 err->type = OCI_ERR_OCILIB;
00505 err->icode = OCI_ERR_OUT_OF_BOUNDS;
00506 err->con = con;
00507
00508 mtsprintf(err->str,
00509 msizeof(err->str) - 1,
00510 OCILib_ErrorMsg[OCI_ERR_OUT_OF_BOUNDS],
00511 value);
00512 }
00513
00514 OCI_ExceptionRaise(err);
00515 }
00516
00517
00518
00519
00520
00521 void OCI_ExceptionUnfreedData(int type_elem, int nb_elem)
00522 {
00523 OCI_Error *err = OCI_ExceptionGetError();
00524
00525 if (err != NULL)
00526 {
00527 err->type = OCI_ERR_OCILIB;
00528 err->icode = OCI_ERR_UNFREED_DATA;
00529
00530 mtsprintf(err->str,
00531 msizeof(err->str) - 1,
00532 OCILib_ErrorMsg[OCI_ERR_UNFREED_DATA],
00533 nb_elem, OCILib_HandleNames[type_elem-1]);
00534 }
00535
00536 OCI_ExceptionRaise(err);
00537 }
00538
00539
00540
00541
00542
00543 void OCI_ExceptionMaxBind(OCI_Statement *stmt)
00544 {
00545 OCI_Error *err = OCI_ExceptionGetError();
00546
00547 if (err != NULL)
00548 {
00549 err->type = OCI_ERR_OCILIB;
00550 err->icode = OCI_ERR_MAX_BIND;
00551 err->stmt = stmt;
00552
00553 if (stmt != NULL)
00554 err->con = stmt->con;
00555
00556
00557 mtsprintf(err->str,
00558 msizeof(err->str) - 1,
00559 OCILib_ErrorMsg[OCI_ERR_MAX_BIND],
00560 OCI_BIND_MAX);
00561 }
00562
00563 OCI_ExceptionRaise(err);
00564 }
00565
00566
00567
00568
00569
00570 void OCI_ExceptionAttributeNotFound(OCI_Connection *con, const mtext *attr)
00571 {
00572 OCI_Error *err = OCI_ExceptionGetError();
00573
00574 if (err != NULL)
00575 {
00576 err->type = OCI_ERR_OCILIB;
00577 err->icode = OCI_ERR_ATTR_NOT_FOUND;
00578 err->con = con;
00579
00580 mtsprintf(err->str,
00581 msizeof(err->str) - 1,
00582 OCILib_ErrorMsg[OCI_ERR_ATTR_NOT_FOUND],
00583 attr);
00584 }
00585
00586 OCI_ExceptionRaise(err);
00587 }
00588
00589
00590
00591
00592
00593 void OCI_ExceptionMinimumValue(OCI_Connection *con, OCI_Statement *stmt, int min)
00594 {
00595 OCI_Error *err = OCI_ExceptionGetError();
00596
00597 if (err != NULL)
00598 {
00599 err->type = OCI_ERR_OCILIB;
00600 err->icode = OCI_ERR_MIN_VALUE;
00601 err->con = con;
00602 err->stmt = stmt;
00603 mtsprintf(err->str, msizeof(err->str) - 1,
00604 OCILib_ErrorMsg[OCI_ERR_MIN_VALUE], min);
00605 }
00606
00607 OCI_ExceptionRaise(err);
00608 }
00609
00610
00611
00612
00613
00614 void OCI_ExceptionTypeNotCompatible(OCI_Connection *con)
00615 {
00616 OCI_Error *err = OCI_ExceptionGetError();
00617
00618 if (err != NULL)
00619 {
00620 err->type = OCI_ERR_OCILIB;
00621 err->icode = OCI_ERR_NOT_COMPATIBLE;
00622 err->con = con;
00623
00624 mtsncat(err->str, OCILib_ErrorMsg[OCI_ERR_NOT_COMPATIBLE],
00625 msizeof(err->str) - 1);
00626 }
00627
00628 OCI_ExceptionRaise(err);
00629 }
00630
00631
00632
00633
00634
00635 void OCI_ExceptionStatementState(OCI_Statement *stmt, int state)
00636 {
00637 OCI_Error *err = OCI_ExceptionGetError();
00638
00639 if (err != NULL)
00640 {
00641 err->type = OCI_ERR_OCILIB;
00642 err->icode = OCI_ERR_STMT_STATE;
00643 err->stmt = stmt;
00644
00645 if (stmt != NULL)
00646 err->con = stmt->con;
00647
00648 mtsprintf(err->str,
00649 msizeof(err->str) - 1,
00650 OCILib_ErrorMsg[OCI_ERR_STMT_STATE],
00651 OCILib_StmtStates[state-1]);
00652 }
00653
00654 OCI_ExceptionRaise(err);
00655 }
00656
00657
00658
00659
00660
00661 void OCI_ExceptionStatementNotScrollable(OCI_Statement *stmt)
00662 {
00663 OCI_Error *err = OCI_ExceptionGetError();
00664
00665 if (err != NULL)
00666 {
00667 err->type = OCI_ERR_OCILIB;
00668 err->icode = OCI_ERR_STMT_NOT_SCROLLABLE;
00669 err->stmt = stmt;
00670
00671 if (stmt != NULL)
00672 err->con = stmt->con;
00673
00674 mtsncat(err->str, OCILib_ErrorMsg[OCI_ERR_STMT_NOT_SCROLLABLE],
00675 msizeof(err->str) - 1);
00676
00677 }
00678
00679 OCI_ExceptionRaise(err);
00680 }
00681
00682
00683
00684
00685
00686 void OCI_ExceptionBindAlreadyUsed(OCI_Statement *stmt, const mtext * bind)
00687 {
00688 OCI_Error *err = OCI_ExceptionGetError();
00689
00690 if (err != NULL)
00691 {
00692 err->type = OCI_ERR_OCILIB;
00693 err->icode = OCI_ERR_BIND_ALREADY_USED;
00694 err->stmt = stmt;
00695
00696 if (stmt != NULL)
00697 err->con = stmt->con;
00698
00699 mtsprintf(err->str,
00700 msizeof(err->str) - 1,
00701 OCILib_ErrorMsg[OCI_ERR_BIND_ALREADY_USED],
00702 bind);
00703 }
00704
00705 OCI_ExceptionRaise(err);
00706 }
00707
00708
00709
00710
00711
00712 void OCI_ExceptionBindArraySize(OCI_Statement *stmt, unsigned int maxsize,
00713 unsigned int cursize, unsigned int newsize)
00714 {
00715 OCI_Error *err = OCI_ExceptionGetError();
00716
00717 if (err != NULL)
00718 {
00719 err->type = OCI_ERR_OCILIB;
00720 err->icode = OCI_ERR_BIND_ARRAY_SIZE;
00721 err->stmt = stmt;
00722
00723 if (stmt != NULL)
00724 err->con = stmt->con;
00725
00726 mtsprintf(err->str,
00727 msizeof(err->str) - 1,
00728 OCILib_ErrorMsg[OCI_ERR_BIND_ARRAY_SIZE],
00729 maxsize, cursize, newsize);
00730 }
00731
00732 OCI_ExceptionRaise(err);
00733 }
00734
00735
00736
00737
00738
00739 void OCI_ExceptionDirPathColNotFound(OCI_DirPath *dp, const mtext * column,
00740 const mtext *table)
00741 {
00742 OCI_Error *err = OCI_ExceptionGetError();
00743
00744 if (err != NULL)
00745 {
00746 err->type = OCI_ERR_OCILIB;
00747 err->icode = OCI_ERR_DIRPATH_STATE;
00748 err->stmt = NULL;
00749
00750 if (dp != NULL)
00751 dp->con = dp->con;
00752
00753 mtsprintf(err->str,
00754 msizeof(err->str) - 1,
00755 OCILib_ErrorMsg[OCI_ERR_COLUMN_NOT_FOUND],
00756 column,
00757 table);
00758 }
00759
00760 OCI_ExceptionRaise(err);
00761 }
00762
00763
00764
00765
00766
00767 void OCI_ExceptionDirPathState(OCI_DirPath *dp, int state)
00768 {
00769 OCI_Error *err = OCI_ExceptionGetError();
00770
00771 if (err != NULL)
00772 {
00773 err->type = OCI_ERR_OCILIB;
00774 err->icode = OCI_ERR_DIRPATH_STATE;
00775 err->stmt = NULL;
00776
00777 if (dp != NULL)
00778 dp->con = dp->con;
00779
00780 mtsprintf(err->str,
00781 msizeof(err->str) - 1,
00782 OCILib_ErrorMsg[OCI_ERR_DIRPATH_STATE],
00783 OCILib_DirPathStates[state-1]);
00784 }
00785
00786 OCI_ExceptionRaise(err);
00787 }
00788
00789
00790
00791
00792
00793 void OCI_ExceptionOCIEnvironment(void)
00794 {
00795 OCI_Error *err = OCI_ExceptionGetError();
00796
00797 if (err != NULL)
00798 {
00799 err->type = OCI_ERR_OCILIB;
00800 err->icode = OCI_ERR_CREATE_OCI_ENVIRONMENT;
00801
00802 mtsncat(err->str, OCILib_ErrorMsg[OCI_ERR_CREATE_OCI_ENVIRONMENT],
00803 msizeof(err->str) - 1);
00804 }
00805
00806 OCI_ExceptionRaise(err);
00807 }
00808