OCILIB (C Driver for Oracle) 3.9.1
D:/Perso/dev/ocilib/ocilib/src/queue.c
00001 /*
00002     +-----------------------------------------------------------------------------------------+
00003     |                                                                                         |
00004     |                               OCILIB - C Driver for Oracle                              |
00005     |                                                                                         |
00006     |                                (C Wrapper for Oracle OCI)                               |
00007     |                                                                                         |
00008     |                              Website : http://www.ocilib.net                            |
00009     |                                                                                         |
00010     |             Copyright (c) 2007-2011 Vincent ROGIER <vince.rogier@ocilib.net>            |
00011     |                                                                                         |
00012     +-----------------------------------------------------------------------------------------+
00013     |                                                                                         |
00014     |             This library is free software; you can redistribute it and/or               |
00015     |             modify it under the terms of the GNU Lesser General Public                  |
00016     |             License as published by the Free Software Foundation; either                |
00017     |             version 2 of the License, or (at your option) any later version.            |
00018     |                                                                                         |
00019     |             This library is distributed in the hope that it will be useful,             |
00020     |             but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00021     |             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           |
00022     |             Lesser General Public License for more details.                             |
00023     |                                                                                         |
00024     |             You should have received a copy of the GNU Lesser General Public            |
00025     |             License along with this library; if not, write to the Free                  |
00026     |             Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.          |
00027     |                                                                                         |
00028     +-----------------------------------------------------------------------------------------+
00029 */
00030 
00031 /* --------------------------------------------------------------------------------------------- *
00032  * $Id: queue.c, v 3.9.1 2011-07-08 00:00 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                            PUBLIC FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_QueueCreate
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 boolean OCI_API OCI_QueueCreate
00046 (
00047     OCI_Connection *con,
00048     const mtext    *queue_name,
00049     const mtext    *queue_table,
00050     unsigned int    queue_type,
00051     unsigned int    max_retries,
00052     unsigned int    retry_delay,
00053     unsigned int    retention_time,
00054     boolean         dependency_tracking,
00055     const mtext    *comment
00056 )
00057 {
00058     boolean res       = FALSE;
00059     OCI_Statement *st = NULL;
00060     void *bstr1       = NULL;
00061     void *bstr2       = NULL;
00062     void *bstr3       = NULL;
00063     int bsize1        = -1;
00064     int bsize2        = -1;
00065     int bsize3        = -1;
00066     dtext *null_str   = DT("");
00067 
00068     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00069     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00070     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00071 
00072     bstr1 = OCI_GetDataFromMetaString(queue_name,  &bsize1);
00073     bstr2 = OCI_GetDataFromMetaString(queue_table, &bsize2);
00074     bstr3 = OCI_GetDataFromMetaString(comment,     &bsize3);
00075 
00076     if (bstr3 == NULL)
00077     {
00078         bstr3 = null_str;
00079     }
00080 
00081     st = OCI_StatementCreate(con);
00082 
00083     if (st)
00084     {
00085         res = OCI_Prepare
00086               (
00087                     st,
00088                     MT("DECLARE ")
00089                     MT("    v_dependency_tracking BOOLEAN  := FALSE; ")
00090                     MT("BEGIN ")
00091                     MT("    IF (:dependency_tracking = 1) then ")
00092                     MT("        v_dependency_tracking := TRUE; ")
00093                     MT("    END IF; ")
00094                     MT("    DBMS_AQADM.CREATE_QUEUE ")
00095                     MT("    (")
00096                     MT("        queue_name           => :queue_name, ")
00097                     MT("        queue_table          => :queue_table, ")
00098                     MT("        queue_type           => :queue_type, ")
00099                     MT("        max_retries          => :max_retries, ")
00100                     MT("        retry_delay          => :retry_delay, ")
00101                     MT("        retention_time       => :retention_time, ")
00102                     MT("        dependency_tracking  => v_dependency_tracking, ")
00103                     MT("        comment              => :comment ")
00104                     MT("    ); ")
00105                     MT("END; ")
00106               );
00107 
00108         res = res && OCI_BindString(st, MT(":queue_name"),  (dtext *) bstr1, 0);
00109         res = res && OCI_BindString(st, MT(":queue_table"), (dtext *) bstr2, 0);
00110         res = res && OCI_BindUnsignedInt(st, MT(":queue_type"),  &queue_type);
00111         res = res && OCI_BindUnsignedInt(st, MT(":max_retries"),  &max_retries);
00112         res = res && OCI_BindUnsignedInt(st, MT(":retry_delay"),  &retry_delay);
00113         res = res && OCI_BindUnsignedInt(st, MT(":retention_time"),  &retention_time);
00114         res = res && OCI_BindInt(st, MT(":dependency_tracking"),  &dependency_tracking);
00115         res = res && OCI_BindString(st, MT(":comment"), (dtext *) bstr3, 0);
00116 
00117         res = res && OCI_Execute(st);
00118 
00119         OCI_StatementFree(st);
00120     }
00121 
00122     OCI_ReleaseDataString(bstr1);
00123     OCI_ReleaseDataString(bstr2);
00124 
00125     if (comment != NULL)
00126     {
00127         OCI_ReleaseDataString(bstr3);
00128     }
00129 
00130     OCI_RESULT(res);
00131 
00132     return res;
00133 }
00134 
00135 /* --------------------------------------------------------------------------------------------- *
00136  * OCI_QueueAlter
00137  * --------------------------------------------------------------------------------------------- */
00138 
00139 boolean OCI_API OCI_QueueAlter
00140 (
00141     OCI_Connection *con,
00142     const mtext    *queue_name,
00143     unsigned int    max_retries,
00144     unsigned int    retry_delay,
00145     unsigned int    retention_time,
00146     const mtext    *comment
00147 )
00148 {
00149     boolean res       = FALSE;
00150     OCI_Statement *st = NULL;
00151     void *bstr1       = NULL;
00152     void *bstr2       = NULL;
00153     int bsize1        = -1;
00154     int bsize2        = -1;
00155     dtext *null_str   = DT("");
00156 
00157     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00158     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00159 
00160     bstr1 = OCI_GetDataFromMetaString(queue_name,  &bsize1);
00161     bstr2 = OCI_GetDataFromMetaString(comment,     &bsize2);
00162 
00163     if (bstr2 == NULL)
00164     {
00165         bstr2 = null_str;
00166     }
00167 
00168     st = OCI_StatementCreate(con);
00169 
00170     if (st)
00171     {
00172         res = OCI_Prepare
00173               (
00174                     st,
00175                     MT("BEGIN ")
00176                     MT("    DBMS_AQADM.ALTER_QUEUE ")
00177                     MT("    (")
00178                     MT("        queue_name           => :queue_name, ")
00179                     MT("        max_retries          => :max_retries, ")
00180                     MT("        retry_delay          => :retry_delay, ")
00181                     MT("        retention_time       => :retention_time, ")
00182                     MT("        comment              => :comment ")
00183                     MT("    ); ")
00184                     MT("END; ")
00185               );
00186 
00187         res = res && OCI_BindString(st, MT(":queue_name"),  (dtext *) bstr1, 0);
00188         res = res && OCI_BindUnsignedInt(st, MT(":max_retries"),  &max_retries);
00189         res = res && OCI_BindUnsignedInt(st, MT(":retry_delay"),  &retry_delay);
00190         res = res && OCI_BindUnsignedInt(st, MT(":retention_time"),  &retention_time);
00191         res = res && OCI_BindString(st, MT(":comment"), (dtext *) bstr2, 0);
00192 
00193         res = res && OCI_Execute(st);
00194 
00195         OCI_StatementFree(st);
00196     }
00197 
00198     OCI_ReleaseDataString(bstr1);
00199 
00200     if (comment != NULL)
00201     {
00202         OCI_ReleaseDataString(bstr2);
00203     }
00204 
00205     OCI_RESULT(res);
00206 
00207     return res;
00208 }
00209 
00210 /* --------------------------------------------------------------------------------------------- *
00211  * OCI_QueueDestroy
00212  * --------------------------------------------------------------------------------------------- */
00213 
00214 boolean OCI_API OCI_QueueDrop
00215 (
00216     OCI_Connection *con,
00217     const mtext    *queue_name
00218 )
00219 {
00220     boolean res       = FALSE;
00221     OCI_Statement *st = NULL;
00222     void *bstr1       = NULL;
00223     int bsize1        = -1;
00224 
00225     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00226     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00227 
00228     bstr1 = OCI_GetDataFromMetaString(queue_name,  &bsize1);
00229 
00230     st = OCI_StatementCreate(con);
00231 
00232     if (st)
00233     {
00234         res = OCI_Prepare
00235               (
00236                     st,
00237                     MT("BEGIN ")
00238                     MT("    DBMS_AQADM.DROP_QUEUE ")
00239                     MT("    (")
00240                     MT("        queue_name  => :queue_name ")
00241                     MT("    ); ")
00242                     MT("END; ")
00243               );
00244 
00245         res = res && OCI_BindString(st, MT(":queue_name"),  (dtext *) bstr1, 0);
00246 
00247         res = res && OCI_Execute(st);
00248 
00249         OCI_StatementFree(st);
00250     }
00251 
00252     OCI_ReleaseDataString(bstr1);
00253 
00254     OCI_RESULT(res);
00255 
00256     return res;
00257 }
00258 
00259 /* --------------------------------------------------------------------------------------------- *
00260  * OCI_QueueStart
00261  * --------------------------------------------------------------------------------------------- */
00262 
00263 boolean OCI_API OCI_QueueStart
00264 (
00265     OCI_Connection *con,
00266     const mtext    *queue_name,
00267     boolean         enqueue,
00268     boolean         dequeue
00269 )
00270 {
00271     boolean res       = FALSE;
00272     OCI_Statement *st = NULL;
00273     void *bstr1       = NULL;
00274     int bsize1        = -1;
00275 
00276     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00277     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00278 
00279     bstr1 = OCI_GetDataFromMetaString(queue_name,  &bsize1);
00280 
00281     st = OCI_StatementCreate(con);
00282 
00283     if (st)
00284     {
00285         res = OCI_Prepare
00286               (
00287                     st,
00288                     MT("DECLARE ")
00289                     MT("    v_enqueue BOOLEAN  := FALSE; ")
00290                     MT("    v_dequeue BOOLEAN  := FALSE; ")
00291                     MT("BEGIN ")
00292                     MT("    IF (:enqueue = 1) then ")
00293                     MT("        v_enqueue := TRUE; ")
00294                     MT("    END IF; ")
00295                     MT("    IF (:dequeue = 1) then ")
00296                     MT("        v_dequeue := TRUE; ")
00297                     MT("    END IF; ")
00298                     MT("    DBMS_AQADM.START_QUEUE ")
00299                     MT("   (")
00300                     MT("       queue_name => :queue_name, ")
00301                     MT("       enqueue    => v_enqueue, ")
00302                     MT("       dequeue    => v_dequeue ")
00303                     MT("   ); ")
00304                     MT("END; ")
00305               );
00306 
00307         res = res && OCI_BindString(st, MT(":queue_name"),  (dtext *) bstr1, 0);
00308         res = res && OCI_BindInt(st, MT(":enqueue"),  &enqueue);
00309         res = res && OCI_BindInt(st, MT(":dequeue"),  &dequeue);
00310 
00311         res = res && OCI_Execute(st);
00312 
00313         OCI_StatementFree(st);
00314     }
00315 
00316     OCI_ReleaseDataString(bstr1);
00317 
00318     OCI_RESULT(res);
00319 
00320     return res;
00321 }
00322 
00323 /* --------------------------------------------------------------------------------------------- *
00324  * OCI_QueueStop
00325  * --------------------------------------------------------------------------------------------- */
00326 
00327 boolean OCI_API OCI_QueueStop
00328 (
00329     OCI_Connection *con,
00330     const mtext    *queue_name,
00331     boolean         enqueue,
00332     boolean         dequeue,
00333     boolean         wait
00334 )
00335 {
00336     boolean res       = FALSE;
00337     OCI_Statement *st = NULL;
00338     void *bstr1       = NULL;
00339     int bsize1        = -1;
00340 
00341     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00342     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00343 
00344     bstr1 = OCI_GetDataFromMetaString(queue_name,  &bsize1);
00345 
00346     st = OCI_StatementCreate(con);
00347 
00348     if (st)
00349     {
00350         res = OCI_Prepare
00351               (
00352                     st,
00353                     MT("DECLARE ")
00354                     MT("    v_enqueue BOOLEAN  := FALSE; ")
00355                     MT("    v_dequeue BOOLEAN  := FALSE; ")
00356                     MT("    v_wait    BOOLEAN  := FALSE; ")
00357                     MT("BEGIN ")
00358                     MT("    IF (:enqueue = 1) then ")
00359                     MT("        v_enqueue := TRUE; ")
00360                     MT("    END IF; ")
00361                     MT("    IF (:dequeue = 1) then ")
00362                     MT("        v_dequeue := TRUE; ")
00363                     MT("    END IF; ")
00364                     MT("    IF (:wait = 1) then ")
00365                     MT("        v_wait := TRUE; ")
00366                     MT("    END IF; ")
00367                     MT("    DBMS_AQADM.STOP_QUEUE ")
00368                     MT("   (")
00369                     MT("       queue_name => :queue_name, ")
00370                     MT("       enqueue    => v_enqueue, ")
00371                     MT("       dequeue    => v_dequeue, ")
00372                     MT("       wait       => v_wait ")
00373                     MT("   ); ")
00374                     MT("END; ")
00375               );
00376 
00377         res = res && OCI_BindString(st, MT(":queue_name"),  (dtext *) bstr1, 0);
00378         res = res && OCI_BindInt(st, MT(":enqueue"),  &enqueue);
00379         res = res && OCI_BindInt(st, MT(":dequeue"),  &dequeue);
00380         res = res && OCI_BindInt(st, MT(":wait"),  &wait);
00381 
00382         res = res && OCI_Execute(st);
00383 
00384         OCI_StatementFree(st);
00385     }
00386 
00387     OCI_ReleaseDataString(bstr1);
00388 
00389     OCI_RESULT(res);
00390 
00391     return res;
00392 }
00393 
00394 /* --------------------------------------------------------------------------------------------- *
00395  * OCI_QueueTableCreate
00396  * --------------------------------------------------------------------------------------------- */
00397 
00398 boolean OCI_API OCI_QueueTableCreate
00399 (
00400     OCI_Connection *con,
00401     const mtext    *queue_table,
00402     const mtext    *queue_payload_type,
00403     const mtext    *storage_clause,
00404     const mtext    *sort_list,
00405     boolean         multiple_consumers,
00406     unsigned int    message_grouping,
00407     const mtext    *comment,
00408     unsigned int    primary_instance,
00409     unsigned int    secondary_instance,
00410     const mtext    *compatible
00411 )
00412 {
00413     boolean res       = FALSE;
00414     OCI_Statement *st = NULL;
00415     void *bstr1       = NULL; 
00416     void *bstr2       = NULL;
00417     void *bstr3       = NULL;
00418     void *bstr4       = NULL;
00419     void *bstr5       = NULL;
00420     void *bstr6       = NULL;
00421     int bsize1        = -1;
00422     int bsize2        = -1;
00423     int bsize3        = -1;
00424     int bsize4        = -1;
00425     int bsize5        = -1;
00426     int bsize6        = -1;
00427     dtext *null_str   = DT("");
00428 
00429     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00430     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00431     OCI_CHECK_PTR(OCI_IPC_STRING, queue_payload_type, FALSE);
00432 
00433     bstr1 = OCI_GetDataFromMetaString(queue_table,        &bsize1);
00434     bstr2 = OCI_GetDataFromMetaString(queue_payload_type, &bsize2);
00435     bstr3 = OCI_GetDataFromMetaString(storage_clause,     &bsize3);
00436     bstr4 = OCI_GetDataFromMetaString(sort_list,          &bsize4);
00437     bstr5 = OCI_GetDataFromMetaString(comment,            &bsize5);
00438     bstr6 = OCI_GetDataFromMetaString(compatible,         &bsize6);
00439 
00440     if (bstr3 == NULL)
00441     {
00442         bstr3 = null_str;
00443     }
00444 
00445     if (bstr4 == NULL)
00446     {
00447         bstr4 = null_str;
00448     }
00449 
00450     if (bstr5 == NULL)
00451     {
00452         bstr5 = null_str;
00453     }
00454 
00455     if (bstr6 == NULL)
00456     {
00457         bstr6 = null_str;
00458     }
00459 
00460     st = OCI_StatementCreate(con);
00461 
00462     if (st)
00463     {
00464         res = OCI_Prepare
00465               (
00466                     st,
00467                     MT("DECLARE ")
00468                     MT("    v_multiple_consumers BOOLEAN  := FALSE; ")
00469                     MT("BEGIN ")
00470                     MT("    IF (:multiple_consumers = 1) then ")
00471                     MT("        v_multiple_consumers := TRUE; ")
00472                     MT("    END IF; ")
00473                     MT("    DBMS_AQADM.CREATE_QUEUE_TABLE ")
00474                     MT("   (")
00475                     MT("       queue_table        => :queue_table, ")
00476                     MT("       queue_payload_type => :queue_payload_type, ")
00477                     MT("       storage_clause     => :storage_clause, ")
00478                     MT("       sort_list          => :sort_list, ")
00479                     MT("       multiple_consumers => v_multiple_consumers, ")
00480                     MT("       message_grouping   => :message_grouping, ")
00481                     MT("       comment            => :comment, ")
00482                     MT("       primary_instance   => :primary_instance, ")
00483                     MT("       secondary_instance => :secondary_instance, ")
00484                     MT("       compatible         => :compatible")
00485                     MT("   ); ")
00486                     MT("END; ")
00487               );
00488 
00489         res = res && OCI_BindString(st, MT(":queue_table"), (dtext *) bstr1, 0);
00490         res = res && OCI_BindString(st, MT(":queue_payload_type"), (dtext *) bstr2, 0);
00491         res = res && OCI_BindString(st, MT(":storage_clause"), (dtext *) bstr3, 0);
00492         res = res && OCI_BindString(st, MT(":sort_list"), (dtext *) bstr4, 0);
00493         res = res && OCI_BindInt(st, MT(":multiple_consumers"),  &multiple_consumers);
00494         res = res && OCI_BindUnsignedInt(st, MT(":message_grouping"),  &message_grouping);
00495         res = res && OCI_BindString(st, MT(":comment"), (dtext *) bstr5, 0);
00496         res = res && OCI_BindUnsignedInt(st, MT(":primary_instance"),  &primary_instance);
00497         res = res && OCI_BindUnsignedInt(st, MT(":secondary_instance"),  &secondary_instance);
00498         res = res && OCI_BindString(st, MT(":compatible"), (dtext *) bstr6, 0);
00499 
00500         res = res && OCI_Execute(st);
00501 
00502         OCI_StatementFree(st);
00503     }
00504 
00505     OCI_ReleaseDataString(bstr1);
00506     OCI_ReleaseDataString(bstr2);
00507 
00508     if (storage_clause != NULL)
00509     {
00510         OCI_ReleaseDataString(bstr3);
00511     }
00512 
00513     if (sort_list != NULL)
00514     {
00515         OCI_ReleaseDataString(bstr4);
00516     }
00517 
00518     if (comment != NULL)
00519     {
00520         OCI_ReleaseDataString(bstr5);
00521     }
00522 
00523     if (compatible != NULL)
00524     {
00525         OCI_ReleaseDataString(bstr6);
00526     }
00527 
00528     OCI_RESULT(res);
00529 
00530     return res;
00531 }
00532 
00533 /* --------------------------------------------------------------------------------------------- *
00534  * OCI_QueueTableAlter
00535  * --------------------------------------------------------------------------------------------- */
00536 
00537 boolean OCI_API OCI_QueueTableAlter
00538 (
00539     OCI_Connection *con,
00540     const mtext    *queue_table,
00541     const mtext    *comment,
00542     unsigned int    primary_instance,
00543     unsigned int    secondary_instance
00544 )
00545 {
00546     boolean res       = FALSE;
00547     OCI_Statement *st = NULL;
00548     void *bstr1       = NULL;
00549     void *bstr2       = NULL;
00550     int bsize1        = -1;
00551     int bsize2        = -1;
00552     dtext *null_str   = DT("");
00553 
00554     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00555     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00556 
00557     bstr1 = OCI_GetDataFromMetaString(queue_table,    &bsize1);
00558     bstr2 = OCI_GetDataFromMetaString(comment,        &bsize2);
00559 
00560     if (bstr2 == NULL)
00561     {
00562         bstr2 = null_str;
00563     }
00564 
00565     st = OCI_StatementCreate(con);
00566 
00567     if (st)
00568     {
00569         res = OCI_Prepare
00570               (
00571                     st,
00572                     MT("BEGIN ")
00573                     MT("    DBMS_AQADM.ALTER_QUEUE_TABLE ")
00574                     MT("   (")
00575                     MT("       queue_table        => :queue_table, ")
00576                     MT("       comment            => :comment, ")
00577                     MT("       primary_instance   => :primary_instance, ")
00578                     MT("       secondary_instance => :secondary_instance ")
00579                     MT("   ); ")
00580                     MT("END; ")
00581               );
00582 
00583         res = res && OCI_BindString(st, MT(":queue_table"), (dtext *)  bstr1, 0);
00584         res = res && OCI_BindString(st, MT(":comment"),  (dtext *) bstr2, 0);
00585         res = res && OCI_BindUnsignedInt(st, MT(":primary_instance"),  &primary_instance);
00586         res = res && OCI_BindUnsignedInt(st, MT(":secondary_instance"),  &secondary_instance);
00587 
00588         res = res && OCI_Execute(st);
00589 
00590         OCI_StatementFree(st);
00591     }
00592 
00593     OCI_ReleaseDataString(bstr1);
00594 
00595     if (comment != NULL)
00596     {
00597         OCI_ReleaseDataString(bstr2);
00598     }
00599 
00600     OCI_RESULT(res);
00601 
00602     return res;
00603 }
00604 
00605 /* --------------------------------------------------------------------------------------------- *
00606  * OCI_QueueTableDrop
00607  * --------------------------------------------------------------------------------------------- */
00608 
00609 boolean OCI_API OCI_QueueTableDrop
00610 (
00611     OCI_Connection *con,
00612     const mtext    *queue_table,
00613     boolean         force
00614 )
00615 {
00616     boolean res       = FALSE;
00617     void *bstr1       = NULL;
00618     int bsize1        = -1;
00619     OCI_Statement *st = NULL;
00620 
00621     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00622     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00623 
00624     bstr1 = OCI_GetDataFromMetaString(queue_table, &bsize1);
00625 
00626     st = OCI_StatementCreate(con);
00627 
00628     if (st)
00629     {
00630         res = OCI_Prepare
00631               (
00632                     st,
00633                     MT("DECLARE ")
00634                     MT("    v_force       BOOLEAN  := FALSE; ")
00635                     MT("BEGIN ")
00636                     MT("    IF (:force = 1) then ")
00637                     MT("        v_force := TRUE; ")
00638                     MT("    END IF; ")
00639                     MT("    DBMS_AQADM.DROP_QUEUE_TABLE ")
00640                     MT("   (")
00641                     MT("       queue_table  => :queue_table, ")
00642                     MT("       force        => v_force ")
00643                     MT("   ); ")
00644                     MT("END; ")
00645               );
00646 
00647         res = res && OCI_BindString(st, MT(":queue_table"),  (dtext *) bstr1, 0);
00648         res = res && OCI_BindInt(st, MT(":force"),  &force);
00649 
00650         res = res && OCI_Execute(st);
00651 
00652         OCI_StatementFree(st);
00653     }
00654 
00655     OCI_ReleaseDataString(bstr1);
00656 
00657     OCI_RESULT(res);
00658 
00659     return res;
00660 }
00661 
00662 /* --------------------------------------------------------------------------------------------- *
00663  * OCI_QueueTablePurge
00664  * --------------------------------------------------------------------------------------------- */
00665 
00666 boolean OCI_API OCI_QueueTablePurge
00667 (
00668     OCI_Connection *con,
00669     const mtext    *queue_table,
00670     const mtext    *purge_condition,
00671     boolean         block,
00672     unsigned int    delivery_mode
00673 )
00674 {
00675     boolean res       = FALSE;
00676     OCI_Statement *st = NULL;
00677     void *bstr1       = NULL; 
00678     void *bstr2       = NULL;
00679     int bsize1        = -1; 
00680     int bsize2        = -1;
00681     dtext *null_str   = DT("");
00682 
00683     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00684     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00685 
00686     if (con->ver_num >= OCI_10_1)
00687     {
00688         bstr1 = OCI_GetDataFromMetaString(queue_table,     &bsize1);
00689         bstr2 = OCI_GetDataFromMetaString(purge_condition, &bsize2);
00690 
00691         if (bstr2 == NULL)
00692         {
00693             bstr2 = null_str;
00694         }
00695 
00696         st = OCI_StatementCreate(con);
00697 
00698         if (st)
00699         {
00700             res = OCI_Prepare
00701                   (
00702                         st,
00703                         MT("DECLARE ")
00704                         MT("    v_purge_options DBMS_AQADM.AQ$_PURGE_OPTIONS_T; ")
00705                         MT("    v_block         BOOLEAN := FALSE; ")
00706                         MT("BEGIN ")
00707                         MT("    v_purge_options.block         := FALSE; ")
00708                         MT("    v_purge_options.delivery_mode := :delivery_mode; ")
00709                         MT("    IF (:block = 1) then ")
00710                         MT("        v_purge_options.block := TRUE; ")
00711                         MT("    END IF; ")
00712                         MT("    DBMS_AQADM.PURGE_QUEUE_TABLE ")
00713                         MT("    (")
00714                         MT("        queue_table      => :queue_table, ")
00715                         MT("        purge_condition  => :purge_condition, ")
00716                         MT("        purge_options    => v_purge_options ")
00717                         MT("   ); ")
00718                         MT("END; ")
00719                   );
00720 
00721             res = res && OCI_BindString(st, MT(":queue_table"), (dtext *) bstr1, 0);
00722             res = res && OCI_BindString(st, MT(":purge_condition"),  (dtext *)  bstr2, 0);
00723             res = res && OCI_BindInt(st, MT(":block"),  &block);
00724             res = res && OCI_BindUnsignedInt(st, MT(":delivery_mode"),  &delivery_mode);
00725 
00726             res = res && OCI_Execute(st);
00727 
00728             OCI_StatementFree(st);
00729         }
00730 
00731         OCI_ReleaseDataString(bstr1);
00732 
00733         if (purge_condition != NULL)
00734         {
00735             OCI_ReleaseDataString(bstr2);
00736         }
00737     }
00738     else
00739     {
00740         res = TRUE;
00741     }
00742 
00743     OCI_RESULT(res);
00744 
00745     return res;
00746 }
00747 
00748 /* --------------------------------------------------------------------------------------------- *
00749  * OCI_QueueTableMigrate
00750  * --------------------------------------------------------------------------------------------- */
00751 
00752 boolean OCI_API OCI_QueueTableMigrate
00753 (
00754     OCI_Connection *con,
00755     const mtext    *queue_table,
00756     const mtext    *compatible
00757 )
00758 {
00759     boolean res       = FALSE;
00760     OCI_Statement *st = NULL;
00761     void *bstr1       = NULL; 
00762     void *bstr2       = NULL;
00763     int bsize1        = -1; 
00764     int bsize2        = -1;
00765 
00766     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00767     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00768     OCI_CHECK_PTR(OCI_IPC_STRING, compatible, FALSE);
00769 
00770     bstr1 = OCI_GetDataFromMetaString(queue_table, &bsize1);
00771     bstr2 = OCI_GetDataFromMetaString(compatible,  &bsize2);
00772 
00773     st = OCI_StatementCreate(con);
00774 
00775     if (st)
00776     {
00777         res = OCI_Prepare
00778               (
00779                     st,
00780                     MT("BEGIN ")
00781                     MT("   DBMS_AQADM.MIGRATE_QUEUE_TABLE")
00782                     MT("   (")
00783                     MT("       queue_table => :queue_table, ")
00784                     MT("       compatible  => :compatible ")
00785                     MT("   );")
00786                     MT("END;")
00787               );
00788 
00789         res = res && OCI_BindString(st, MT(":queue_table"), (dtext *) bstr1, 0);
00790         res = res && OCI_BindString(st, MT(":compatible"),  (dtext *) bstr2, 0);
00791 
00792         res = res && OCI_Execute(st);
00793 
00794         OCI_StatementFree(st);
00795     }
00796 
00797     OCI_ReleaseDataString(bstr1);
00798     OCI_ReleaseDataString(bstr2);
00799 
00800     OCI_RESULT(res);
00801 
00802     return res;
00803 }