• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

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-2010 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.8.1 2010-12-13 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, *bstr2 = NULL, *bstr3 = NULL;
00061     int bsize1        = -1, bsize2 = -1, bsize3 = -1;
00062     dtext *null_str   = DT("");
00063 
00064     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00065     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00066     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00067 
00068     bstr1 = OCI_GetMetaFromDataString(queue_name,  &bsize1);
00069     bstr2 = OCI_GetMetaFromDataString(queue_table, &bsize2);
00070     bstr3 = OCI_GetMetaFromDataString(comment,     &bsize3);
00071 
00072     if (bstr3 == NULL)
00073         bstr3 = null_str;
00074 
00075     st = OCI_StatementCreate(con);
00076 
00077     if (st)
00078     {
00079         res = OCI_Prepare
00080               (
00081                 st,
00082                 MT("DECLARE ")
00083                 MT("    v_dependency_tracking BOOLEAN  := FALSE; ")
00084                 MT("BEGIN ")
00085                 MT("    IF (:dependency_tracking = 1) then ")
00086                 MT("        v_dependency_tracking := TRUE; ")
00087                 MT("    END IF; ")
00088                 MT("    DBMS_AQADM.CREATE_QUEUE ")
00089                 MT("    (")
00090                 MT("        queue_name           => :queue_name, ")
00091                 MT("        queue_table          => :queue_table, ")
00092                 MT("        queue_type           => :queue_type, ")
00093                 MT("        max_retries          => :max_retries, ")
00094                 MT("        retry_delay          => :retry_delay, ")
00095                 MT("        retention_time       => :retention_time, ")
00096                 MT("        dependency_tracking  => v_dependency_tracking, ")
00097                 MT("        comment              => :comment ")
00098                 MT("    ); ")
00099                 MT("END; ")
00100               );
00101 
00102         res = res && OCI_BindString(st, MT(":queue_name"),  bstr1, 0);
00103         res = res && OCI_BindString(st, MT(":queue_table"), bstr2, 0);
00104         res = res && OCI_BindUnsignedInt(st, MT(":queue_type"),  &queue_type);
00105         res = res && OCI_BindUnsignedInt(st, MT(":max_retries"),  &max_retries);
00106         res = res && OCI_BindUnsignedInt(st, MT(":retry_delay"),  &retry_delay);
00107         res = res && OCI_BindUnsignedInt(st, MT(":retention_time"),  &retention_time);
00108         res = res && OCI_BindInt(st, MT(":dependency_tracking"),  &dependency_tracking);
00109         res = res && OCI_BindString(st, MT(":comment"), bstr3, 0);
00110 
00111         res = res && OCI_Execute(st);
00112 
00113         OCI_StatementFree(st);
00114     }
00115 
00116     OCI_ReleaseDataString(bstr1);
00117     OCI_ReleaseDataString(bstr2);
00118 
00119     if (comment != NULL)
00120         OCI_ReleaseDataString(bstr3);
00121 
00122     OCI_RESULT(res);
00123 
00124     return res;
00125 }
00126 
00127 /* --------------------------------------------------------------------------------------------- *
00128  * OCI_QueueAlter
00129  * --------------------------------------------------------------------------------------------- */
00130 
00131 boolean OCI_API OCI_QueueAlter
00132 (
00133     OCI_Connection *con,
00134     const mtext    *queue_name,
00135     unsigned int    max_retries,
00136     unsigned int    retry_delay,
00137     unsigned int    retention_time,
00138     const mtext    *comment
00139 )
00140 {
00141     boolean res       = FALSE;
00142     OCI_Statement *st = NULL;
00143     void *bstr1       = NULL, *bstr2 = NULL;
00144     int bsize1        = -1, bsize2 = -1;
00145     dtext *null_str   = DT("");
00146 
00147     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00148     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00149 
00150     bstr1 = OCI_GetMetaFromDataString(queue_name,  &bsize1);
00151     bstr2 = OCI_GetMetaFromDataString(comment,     &bsize2);
00152 
00153     if (bstr2 == NULL)
00154         bstr2 = null_str;
00155 
00156     st = OCI_StatementCreate(con);
00157 
00158     if (st)
00159     {
00160         res = OCI_Prepare
00161               (
00162                 st,
00163                 MT("BEGIN ")
00164                 MT("    DBMS_AQADM.ALTER_QUEUE ")
00165                 MT("    (")
00166                 MT("        queue_name           => :queue_name, ")
00167                 MT("        max_retries          => :max_retries, ")
00168                 MT("        retry_delay          => :retry_delay, ")
00169                 MT("        retention_time       => :retention_time, ")
00170                 MT("        comment              => :comment ")
00171                 MT("    ); ")
00172                 MT("END; ")
00173               );
00174 
00175         res = res && OCI_BindString(st, MT(":queue_name"),  bstr1, 0);
00176         res = res && OCI_BindUnsignedInt(st, MT(":max_retries"),  &max_retries);
00177         res = res && OCI_BindUnsignedInt(st, MT(":retry_delay"),  &retry_delay);
00178         res = res && OCI_BindUnsignedInt(st, MT(":retention_time"),  &retention_time);
00179         res = res && OCI_BindString(st, MT(":comment"), bstr2, 0);
00180 
00181         res = res && OCI_Execute(st);
00182 
00183         OCI_StatementFree(st);
00184     }
00185 
00186     OCI_ReleaseDataString(bstr1);
00187 
00188     if (comment != NULL)
00189         OCI_ReleaseDataString(bstr2);
00190 
00191     OCI_RESULT(res);
00192 
00193     return res;
00194 }
00195 
00196 /* --------------------------------------------------------------------------------------------- *
00197  * OCI_QueueDestroy
00198  * --------------------------------------------------------------------------------------------- */
00199 
00200 boolean OCI_API OCI_QueueDrop
00201 (
00202     OCI_Connection *con,
00203     const mtext    *queue_name
00204 )
00205 {
00206     boolean res       = FALSE;
00207     OCI_Statement *st = NULL;
00208     void *bstr1       = NULL;
00209     int bsize1        = -1;
00210 
00211     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00212     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00213 
00214     bstr1 = OCI_GetMetaFromDataString(queue_name,  &bsize1);
00215 
00216     st = OCI_StatementCreate(con);
00217 
00218     if (st)
00219     {
00220         res = OCI_Prepare
00221               (
00222                 st,
00223                 MT("BEGIN ")
00224                 MT("    DBMS_AQADM.DROP_QUEUE ")
00225                 MT("    (")
00226                 MT("        queue_name  => :queue_name ")
00227                 MT("    ); ")
00228                 MT("END; ")
00229               );
00230 
00231         res = res && OCI_BindString(st, MT(":queue_name"),  bstr1, 0);
00232 
00233         res = res && OCI_Execute(st);
00234 
00235         OCI_StatementFree(st);
00236     }
00237 
00238     OCI_ReleaseDataString(bstr1);
00239 
00240     OCI_RESULT(res);
00241 
00242     return res;
00243 }
00244 
00245 /* --------------------------------------------------------------------------------------------- *
00246  * OCI_QueueStart
00247  * --------------------------------------------------------------------------------------------- */
00248 
00249 boolean OCI_API OCI_QueueStart
00250 (
00251     OCI_Connection *con,
00252     const mtext    *queue_name,
00253     boolean         enqueue,
00254     boolean         dequeue
00255 )
00256 {
00257     boolean res       = FALSE;
00258     OCI_Statement *st = NULL;
00259     void *bstr1       = NULL;
00260     int bsize1        = -1;
00261 
00262     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00263     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00264 
00265     bstr1 = OCI_GetMetaFromDataString(queue_name,  &bsize1);
00266 
00267     st = OCI_StatementCreate(con);
00268 
00269     if (st)
00270     {
00271         res = OCI_Prepare
00272               (
00273             st,
00274             MT("DECLARE ")
00275             MT("    v_enqueue BOOLEAN  := FALSE; ")
00276             MT("    v_dequeue BOOLEAN  := FALSE; ")
00277             MT("BEGIN ")
00278             MT("    IF (:enqueue = 1) then ")
00279             MT("        v_enqueue := TRUE; ")
00280             MT("    END IF; ")
00281             MT("    IF (:dequeue = 1) then ")
00282             MT("        v_dequeue := TRUE; ")
00283             MT("    END IF; ")
00284             MT("    DBMS_AQADM.START_QUEUE ")
00285             MT("   (")
00286             MT("       queue_name => :queue_name, ")
00287             MT("       enqueue    => v_enqueue, ")
00288             MT("       dequeue    => v_dequeue ")
00289             MT("   ); ")
00290             MT("END; ")
00291               );
00292 
00293         res = res && OCI_BindString(st, MT(":queue_name"),  bstr1, 0);
00294         res = res && OCI_BindInt(st, MT(":enqueue"),  &enqueue);
00295         res = res && OCI_BindInt(st, MT(":dequeue"),  &dequeue);
00296 
00297         res = res && OCI_Execute(st);
00298 
00299         OCI_StatementFree(st);
00300     }
00301 
00302     OCI_ReleaseDataString(bstr1);
00303 
00304     OCI_RESULT(res);
00305 
00306     return res;
00307 }
00308 
00309 /* --------------------------------------------------------------------------------------------- *
00310  * OCI_QueueStop
00311  * --------------------------------------------------------------------------------------------- */
00312 
00313 boolean OCI_API OCI_QueueStop
00314 (
00315     OCI_Connection *con,
00316     const mtext    *queue_name,
00317     boolean         enqueue,
00318     boolean         dequeue,
00319     boolean         wait
00320 )
00321 {
00322     boolean res       = FALSE;
00323     OCI_Statement *st = NULL;
00324     void *bstr1       = NULL;
00325     int bsize1        = -1;
00326 
00327     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00328     OCI_CHECK_PTR(OCI_IPC_STRING, queue_name, FALSE);
00329 
00330     bstr1 = OCI_GetMetaFromDataString(queue_name,  &bsize1);
00331 
00332     st = OCI_StatementCreate(con);
00333 
00334     if (st)
00335     {
00336         res = OCI_Prepare
00337               (
00338             st,
00339             MT("DECLARE ")
00340             MT("    v_enqueue BOOLEAN  := FALSE; ")
00341             MT("    v_dequeue BOOLEAN  := FALSE; ")
00342             MT("    v_wait    BOOLEAN  := FALSE; ")
00343             MT("BEGIN ")
00344             MT("    IF (:enqueue = 1) then ")
00345             MT("        v_enqueue := TRUE; ")
00346             MT("    END IF; ")
00347             MT("    IF (:dequeue = 1) then ")
00348             MT("        v_dequeue := TRUE; ")
00349             MT("    END IF; ")
00350             MT("    IF (:wait = 1) then ")
00351             MT("        v_wait := TRUE; ")
00352             MT("    END IF; ")
00353             MT("    DBMS_AQADM.STOP_QUEUE ")
00354             MT("   (")
00355             MT("       queue_name => :queue_name, ")
00356             MT("       enqueue    => v_enqueue, ")
00357             MT("       dequeue    => v_dequeue, ")
00358             MT("       wait       => v_wait ")
00359             MT("   ); ")
00360             MT("END; ")
00361               );
00362 
00363         res = res && OCI_BindString(st, MT(":queue_name"),  bstr1, 0);
00364         res = res && OCI_BindInt(st, MT(":enqueue"),  &enqueue);
00365         res = res && OCI_BindInt(st, MT(":dequeue"),  &dequeue);
00366         res = res && OCI_BindInt(st, MT(":wait"),  &wait);
00367 
00368         res = res && OCI_Execute(st);
00369 
00370         OCI_StatementFree(st);
00371     }
00372 
00373     OCI_ReleaseDataString(bstr1);
00374 
00375     OCI_RESULT(res);
00376 
00377     return res;
00378 }
00379 
00380 /* --------------------------------------------------------------------------------------------- *
00381  * OCI_QueueTableCreate
00382  * --------------------------------------------------------------------------------------------- */
00383 
00384 boolean OCI_API OCI_QueueTableCreate
00385 (
00386     OCI_Connection *con,
00387     const mtext    *queue_table,
00388     const mtext    *queue_payload_type,
00389     const mtext    *storage_clause,
00390     const mtext    *sort_list,
00391     boolean         multiple_consumers,
00392     unsigned int    message_grouping,
00393     const mtext    *comment,
00394     unsigned int    primary_instance,
00395     unsigned int    secondary_instance,
00396     const mtext    *compatible
00397 )
00398 {
00399     boolean res       = FALSE;
00400     OCI_Statement *st = NULL;
00401     void *bstr1       = NULL, *bstr2 = NULL, *bstr3 = NULL;
00402     void *bstr4       = NULL, *bstr5 = NULL, *bstr6 = NULL;
00403     int bsize1        = -1, bsize2 = -1, bsize3 = -1;
00404     int bsize4        = -1, bsize5 = -1, bsize6 = -1;
00405     dtext *null_str   = DT("");
00406 
00407     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00408     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00409     OCI_CHECK_PTR(OCI_IPC_STRING, queue_payload_type, FALSE);
00410 
00411     bstr1 = OCI_GetMetaFromDataString(queue_table,        &bsize1);
00412     bstr2 = OCI_GetMetaFromDataString(queue_payload_type, &bsize2);
00413     bstr3 = OCI_GetMetaFromDataString(storage_clause,     &bsize3);
00414     bstr4 = OCI_GetMetaFromDataString(sort_list,          &bsize4);
00415     bstr5 = OCI_GetMetaFromDataString(comment,            &bsize5);
00416     bstr6 = OCI_GetMetaFromDataString(compatible,         &bsize6);
00417 
00418     if (bstr3 == NULL)
00419         bstr3 = null_str;
00420 
00421     if (bstr4 == NULL)
00422         bstr4 = null_str;
00423 
00424     if (bstr5 == NULL)
00425         bstr5 = null_str;
00426 
00427     if (bstr6 == NULL)
00428         bstr6 = null_str;
00429 
00430     st = OCI_StatementCreate(con);
00431 
00432     if (st)
00433     {
00434         res = OCI_Prepare
00435               (
00436             st,
00437             MT("DECLARE ")
00438             MT("    v_multiple_consumers BOOLEAN  := FALSE; ")
00439             MT("BEGIN ")
00440             MT("    IF (:multiple_consumers = 1) then ")
00441             MT("        v_multiple_consumers := TRUE; ")
00442             MT("    END IF; ")
00443             MT("    DBMS_AQADM.CREATE_QUEUE_TABLE ")
00444             MT("   (")
00445             MT("       queue_table        => :queue_table, ")
00446             MT("       queue_payload_type => :queue_payload_type, ")
00447             MT("       storage_clause     => :storage_clause, ")
00448             MT("       sort_list          => :sort_list, ")
00449             MT("       multiple_consumers => v_multiple_consumers, ")
00450             MT("       message_grouping   => :message_grouping, ")
00451             MT("       comment            => :comment, ")
00452             MT("       primary_instance   => :primary_instance, ")
00453             MT("       secondary_instance => :secondary_instance, ")
00454             MT("       compatible         => :compatible")
00455             MT("   ); ")
00456             MT("END; ")
00457               );
00458 
00459         res = res && OCI_BindString(st, MT(":queue_table"),  bstr1, 0);
00460         res = res && OCI_BindString(st, MT(":queue_payload_type"), bstr2, 0);
00461         res = res && OCI_BindString(st, MT(":storage_clause"), bstr3, 0);
00462         res = res && OCI_BindString(st, MT(":sort_list"), bstr4, 0);
00463         res = res && OCI_BindInt(st, MT(":multiple_consumers"),  &multiple_consumers);
00464         res = res && OCI_BindUnsignedInt(st, MT(":message_grouping"),  &message_grouping);
00465         res = res && OCI_BindString(st, MT(":comment"), bstr5, 0);
00466         res = res && OCI_BindUnsignedInt(st, MT(":primary_instance"),  &primary_instance);
00467         res = res && OCI_BindUnsignedInt(st, MT(":secondary_instance"),  &secondary_instance);
00468         res = res && OCI_BindString(st, MT(":compatible"), bstr6, 0);
00469 
00470         res = res && OCI_Execute(st);
00471 
00472         OCI_StatementFree(st);
00473     }
00474 
00475     OCI_ReleaseDataString(bstr1);
00476     OCI_ReleaseDataString(bstr2);
00477 
00478     if (storage_clause != NULL)
00479         OCI_ReleaseDataString(bstr3);
00480 
00481     if (sort_list != NULL)
00482         OCI_ReleaseDataString(bstr4);
00483 
00484     if (comment != NULL)
00485         OCI_ReleaseDataString(bstr5);
00486 
00487     if (compatible != NULL)
00488         OCI_ReleaseDataString(bstr6);
00489 
00490     OCI_RESULT(res);
00491 
00492     return res;
00493 }
00494 
00495 /* --------------------------------------------------------------------------------------------- *
00496  * OCI_QueueTableAlter
00497  * --------------------------------------------------------------------------------------------- */
00498 
00499 boolean OCI_API OCI_QueueTableAlter
00500 (
00501     OCI_Connection *con,
00502     const mtext    *queue_table,
00503     const mtext    *comment,
00504     unsigned int    primary_instance,
00505     unsigned int    secondary_instance
00506 )
00507 {
00508     boolean res       = FALSE;
00509     OCI_Statement *st = NULL;
00510     void *bstr1       = NULL, *bstr2 = NULL;
00511     int bsize1        = -1, bsize2 = -1;
00512     dtext *null_str   = DT("");
00513 
00514     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00515     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00516 
00517     bstr1 = OCI_GetMetaFromDataString(queue_table,    &bsize1);
00518     bstr2 = OCI_GetMetaFromDataString(comment,        &bsize2);
00519 
00520     if (bstr2 == NULL)
00521         bstr2 = null_str;
00522 
00523     st = OCI_StatementCreate(con);
00524 
00525     if (st)
00526     {
00527         res = OCI_Prepare
00528               (
00529             st,
00530             MT("BEGIN ")
00531             MT("    DBMS_AQADM.ALTER_QUEUE_TABLE ")
00532             MT("   (")
00533             MT("       queue_table        => :queue_table, ")
00534             MT("       comment            => :comment, ")
00535             MT("       primary_instance   => :primary_instance, ")
00536             MT("       secondary_instance => :secondary_instance ")
00537             MT("   ); ")
00538             MT("END; ")
00539               );
00540 
00541         res = res && OCI_BindString(st, MT(":queue_table"),  bstr1, 0);
00542         res = res && OCI_BindString(st, MT(":comment"), bstr2, 0);
00543         res = res && OCI_BindUnsignedInt(st, MT(":primary_instance"),  &primary_instance);
00544         res = res && OCI_BindUnsignedInt(st, MT(":secondary_instance"),  &secondary_instance);
00545 
00546         res = res && OCI_Execute(st);
00547 
00548         OCI_StatementFree(st);
00549     }
00550 
00551     OCI_ReleaseDataString(bstr1);
00552 
00553     if (comment != NULL)
00554         OCI_ReleaseDataString(bstr2);
00555 
00556     OCI_RESULT(res);
00557 
00558     return res;
00559 }
00560 
00561 /* --------------------------------------------------------------------------------------------- *
00562  * OCI_QueueTableDrop
00563  * --------------------------------------------------------------------------------------------- */
00564 
00565 boolean OCI_API OCI_QueueTableDrop
00566 (
00567     OCI_Connection *con,
00568     const mtext    *queue_table,
00569     boolean         force
00570 )
00571 {
00572     boolean res       = FALSE;
00573     void *bstr1       = NULL;
00574     int bsize1        = -1;
00575     OCI_Statement *st = NULL;
00576 
00577     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00578     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00579 
00580     bstr1 = OCI_GetMetaFromDataString(queue_table, &bsize1);
00581 
00582     st = OCI_StatementCreate(con);
00583 
00584     if (st)
00585     {
00586         res = OCI_Prepare
00587               (
00588             st,
00589             MT("DECLARE ")
00590             MT("    v_force       BOOLEAN  := FALSE; ")
00591             MT("BEGIN ")
00592             MT("    IF (:force = 1) then ")
00593             MT("        v_force := TRUE; ")
00594             MT("    END IF; ")
00595             MT("    DBMS_AQADM.DROP_QUEUE_TABLE ")
00596             MT("   (")
00597             MT("       queue_table  => :queue_table, ")
00598             MT("       force        => v_force ")
00599             MT("   ); ")
00600             MT("END; ")
00601               );
00602 
00603         res = res && OCI_BindString(st, MT(":queue_table"), bstr1, 0);
00604         res = res && OCI_BindInt(st, MT(":force"),  &force);
00605 
00606         res = res && OCI_Execute(st);
00607 
00608         OCI_StatementFree(st);
00609     }
00610 
00611     OCI_ReleaseDataString(bstr1);
00612 
00613     OCI_RESULT(res);
00614 
00615     return res;
00616 }
00617 
00618 /* --------------------------------------------------------------------------------------------- *
00619  * OCI_QueueTablePurge
00620  * --------------------------------------------------------------------------------------------- */
00621 
00622 boolean OCI_API OCI_QueueTablePurge
00623 (
00624     OCI_Connection *con,
00625     const mtext    *queue_table,
00626     const mtext    *purge_condition,
00627     boolean         block,
00628     unsigned int    delivery_mode
00629 )
00630 {
00631     boolean res       = FALSE;
00632     OCI_Statement *st = NULL;
00633     void *bstr1       = NULL, *bstr2 = NULL;
00634     int bsize1        = -1, bsize2 = -1;
00635     dtext *null_str   = DT("");
00636 
00637     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00638     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00639 
00640     if (con->ver_num >= OCI_10_1)
00641     {
00642         bstr1 = OCI_GetMetaFromDataString(queue_table,     &bsize1);
00643         bstr2 = OCI_GetMetaFromDataString(purge_condition, &bsize2);
00644 
00645         if (bstr2 == NULL)
00646             bstr2 = null_str;
00647 
00648         st = OCI_StatementCreate(con);
00649 
00650         if (st)
00651         {
00652             res = OCI_Prepare
00653                   (
00654                 st,
00655                 MT("DECLARE ")
00656                 MT("    v_purge_options DBMS_AQADM.AQ$_PURGE_OPTIONS_T; ")
00657                 MT("    v_block         BOOLEAN := FALSE; ")
00658                 MT("BEGIN ")
00659                 MT("    v_purge_options.block         := FALSE; ")
00660                 MT("    v_purge_options.delivery_mode := :delivery_mode; ")
00661                 MT("    IF (:block = 1) then ")
00662                 MT("        v_purge_options.block := TRUE; ")
00663                 MT("    END IF; ")
00664                 MT("    DBMS_AQADM.PURGE_QUEUE_TABLE ")
00665                 MT("    (")
00666                 MT("        queue_table      => :queue_table, ")
00667                 MT("        purge_condition  => :purge_condition, ")
00668                 MT("        purge_options    => v_purge_options ")
00669                 MT("   ); ")
00670                 MT("END; ")
00671                   );
00672 
00673             res = res && OCI_BindString(st, MT(":queue_table"), bstr1, 0);
00674             res = res && OCI_BindString(st, MT(":purge_condition"), bstr2, 0);
00675             res = res && OCI_BindInt(st, MT(":block"),  &block);
00676             res = res && OCI_BindUnsignedInt(st, MT(":delivery_mode"),  &delivery_mode);
00677 
00678             res = res && OCI_Execute(st);
00679 
00680             OCI_StatementFree(st);
00681         }
00682 
00683         OCI_ReleaseDataString(bstr1);
00684 
00685         if (purge_condition != NULL)
00686             OCI_ReleaseDataString(bstr2);
00687     }
00688     else
00689     {
00690         res = TRUE;
00691     }
00692 
00693     OCI_RESULT(res);
00694 
00695     return res;
00696 }
00697 
00698 /* --------------------------------------------------------------------------------------------- *
00699  * OCI_QueueTableMigrate
00700  * --------------------------------------------------------------------------------------------- */
00701 
00702 boolean OCI_API OCI_QueueTableMigrate
00703 (
00704     OCI_Connection *con,
00705     const mtext    *queue_table,
00706     const mtext    *compatible
00707 )
00708 {
00709     boolean res       = FALSE;
00710     OCI_Statement *st = NULL;
00711     void *bstr1       = NULL, *bstr2 = NULL;
00712     int bsize1        = -1, bsize2 = -1;
00713 
00714     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00715     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00716     OCI_CHECK_PTR(OCI_IPC_STRING, compatible, FALSE);
00717 
00718     bstr1 = OCI_GetMetaFromDataString(queue_table, &bsize1);
00719     bstr2 = OCI_GetMetaFromDataString(compatible,  &bsize2);
00720 
00721     st = OCI_StatementCreate(con);
00722 
00723     if (st)
00724     {
00725         res = OCI_Prepare
00726               (
00727             st,
00728             MT("BEGIN ")
00729             MT("   DBMS_AQADM.MIGRATE_QUEUE_TABLE")
00730             MT("   (")
00731             MT("       queue_table => :queue_table, ")
00732             MT("       compatible  => :compatible ")
00733             MT("   );")
00734             MT("END;")
00735               );
00736 
00737         res = res && OCI_BindString(st, MT(":queue_table"), bstr1, 0);
00738         res = res && OCI_BindString(st, MT(":compatible"),  bstr2, 0);
00739 
00740         res = res && OCI_Execute(st);
00741 
00742         OCI_StatementFree(st);
00743     }
00744 
00745     OCI_ReleaseDataString(bstr1);
00746     OCI_ReleaseDataString(bstr2);
00747 
00748     OCI_RESULT(res);
00749 
00750     return res;
00751 }

Generated on Mon Dec 13 2010 22:32:02 for OCILIB (C Driver for Oracle) by  doxygen 1.7.2