• 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.0 2010-10-24 21:53 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_auto_commit        BOOLEAN  := FALSE; ")
00439             MT("    v_multiple_consumers BOOLEAN  := FALSE; ")
00440             MT("BEGIN ")
00441             MT("    IF (:multiple_consumers = 1) then ")
00442             MT("        v_multiple_consumers := TRUE; ")
00443             MT("    END IF; ")
00444             MT("    DBMS_AQADM.CREATE_QUEUE_TABLE ")
00445             MT("   (")
00446             MT("       queue_table        => :queue_table, ")
00447             MT("       queue_payload_type => :queue_payload_type, ")
00448             MT("       storage_clause     => :storage_clause, ")
00449             MT("       sort_list          => :sort_list, ")
00450             MT("       multiple_consumers => v_multiple_consumers, ")
00451             MT("       message_grouping   => :message_grouping, ")
00452             MT("       comment            => :comment, ")
00453             MT("       primary_instance   => :primary_instance, ")
00454             MT("       secondary_instance => :secondary_instance, ")
00455             MT("       compatible         => :compatible")
00456             MT("   ); ")
00457             MT("END; ")
00458               );
00459 
00460         res = res && OCI_BindString(st, MT(":queue_table"),  bstr1, 0);
00461         res = res && OCI_BindString(st, MT(":queue_payload_type"), bstr2, 0);
00462         res = res && OCI_BindString(st, MT(":storage_clause"), bstr3, 0);
00463         res = res && OCI_BindString(st, MT(":sort_list"), bstr4, 0);
00464         res = res && OCI_BindInt(st, MT(":multiple_consumers"),  &multiple_consumers);
00465         res = res && OCI_BindUnsignedInt(st, MT(":message_grouping"),  &message_grouping);
00466         res = res && OCI_BindString(st, MT(":comment"), bstr5, 0);
00467         res = res && OCI_BindUnsignedInt(st, MT(":primary_instance"),  &primary_instance);
00468         res = res && OCI_BindUnsignedInt(st, MT(":secondary_instance"),  &secondary_instance);
00469         res = res && OCI_BindString(st, MT(":compatible"), bstr6, 0);
00470 
00471         res = res && OCI_Execute(st);
00472 
00473         OCI_StatementFree(st);
00474     }
00475 
00476     OCI_ReleaseDataString(bstr1);
00477     OCI_ReleaseDataString(bstr2);
00478 
00479     if (storage_clause != NULL)
00480         OCI_ReleaseDataString(bstr3);
00481 
00482     if (sort_list != NULL)
00483         OCI_ReleaseDataString(bstr4);
00484 
00485     if (comment != NULL)
00486         OCI_ReleaseDataString(bstr5);
00487 
00488     if (compatible != NULL)
00489         OCI_ReleaseDataString(bstr6);
00490 
00491     OCI_RESULT(res);
00492 
00493     return res;
00494 }
00495 
00496 /* --------------------------------------------------------------------------------------------- *
00497  * OCI_QueueTableAlter
00498  * --------------------------------------------------------------------------------------------- */
00499 
00500 boolean OCI_API OCI_QueueTableAlter
00501 (
00502     OCI_Connection *con,
00503     const mtext    *queue_table,
00504     const mtext    *comment,
00505     unsigned int    primary_instance,
00506     unsigned int    secondary_instance
00507 )
00508 {
00509     boolean res       = FALSE;
00510     OCI_Statement *st = NULL;
00511     void *bstr1       = NULL, *bstr2 = NULL;
00512     int bsize1        = -1, bsize2 = -1;
00513     dtext *null_str   = DT("");
00514 
00515     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00516     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00517 
00518     bstr1 = OCI_GetMetaFromDataString(queue_table,    &bsize1);
00519     bstr2 = OCI_GetMetaFromDataString(comment,        &bsize2);
00520 
00521     if (bstr2 == NULL)
00522         bstr2 = null_str;
00523 
00524     st = OCI_StatementCreate(con);
00525 
00526     if (st)
00527     {
00528         res = OCI_Prepare
00529               (
00530             st,
00531             MT("BEGIN ")
00532             MT("    DBMS_AQADM.ALTER_QUEUE_TABLE ")
00533             MT("   (")
00534             MT("       queue_table        => :queue_table, ")
00535             MT("       comment            => :comment, ")
00536             MT("       primary_instance   => :primary_instance, ")
00537             MT("       secondary_instance => :secondary_instance ")
00538             MT("   ); ")
00539             MT("END; ")
00540               );
00541 
00542         res = res && OCI_BindString(st, MT(":queue_table"),  bstr1, 0);
00543         res = res && OCI_BindString(st, MT(":comment"), bstr2, 0);
00544         res = res && OCI_BindUnsignedInt(st, MT(":primary_instance"),  &primary_instance);
00545         res = res && OCI_BindUnsignedInt(st, MT(":secondary_instance"),  &secondary_instance);
00546 
00547         res = res && OCI_Execute(st);
00548 
00549         OCI_StatementFree(st);
00550     }
00551 
00552     OCI_ReleaseDataString(bstr1);
00553 
00554     if (comment != NULL)
00555         OCI_ReleaseDataString(bstr2);
00556 
00557     OCI_RESULT(res);
00558 
00559     return res;
00560 }
00561 
00562 /* --------------------------------------------------------------------------------------------- *
00563  * OCI_QueueTableDrop
00564  * --------------------------------------------------------------------------------------------- */
00565 
00566 boolean OCI_API OCI_QueueTableDrop
00567 (
00568     OCI_Connection *con,
00569     const mtext    *queue_table,
00570     boolean         force
00571 )
00572 {
00573     boolean res       = FALSE;
00574     void *bstr1       = NULL;
00575     int bsize1        = -1;
00576     OCI_Statement *st = NULL;
00577 
00578     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00579     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00580 
00581     bstr1 = OCI_GetMetaFromDataString(queue_table, &bsize1);
00582 
00583     st = OCI_StatementCreate(con);
00584 
00585     if (st)
00586     {
00587         res = OCI_Prepare
00588               (
00589             st,
00590             MT("DECLARE ")
00591             MT("    v_force       BOOLEAN  := FALSE; ")
00592             MT("BEGIN ")
00593             MT("    END IF; ")
00594             MT("    IF (:force = 1) then ")
00595             MT("        v_force := TRUE; ")
00596             MT("    END IF; ")
00597             MT("    DBMS_AQADM.DROP_QUEUE_TABLE ")
00598             MT("   (")
00599             MT("       queue_table  => :queue_table, ")
00600             MT("       force        => v_force ")
00601             MT("   ); ")
00602             MT("END; ")
00603               );
00604 
00605         res = res && OCI_BindString(st, MT(":queue_table"), bstr1, 0);
00606         res = res && OCI_BindInt(st, MT(":force"),  &force);
00607 
00608         res = res && OCI_Execute(st);
00609 
00610         OCI_StatementFree(st);
00611     }
00612 
00613     OCI_ReleaseDataString(bstr1);
00614 
00615     OCI_RESULT(res);
00616 
00617     return res;
00618 }
00619 
00620 /* --------------------------------------------------------------------------------------------- *
00621  * OCI_QueueTablePurge
00622  * --------------------------------------------------------------------------------------------- */
00623 
00624 boolean OCI_API OCI_QueueTablePurge
00625 (
00626     OCI_Connection *con,
00627     const mtext    *queue_table,
00628     const mtext    *purge_condition,
00629     boolean         block,
00630     unsigned int    delivery_mode
00631 )
00632 {
00633     boolean res       = FALSE;
00634     OCI_Statement *st = NULL;
00635     void *bstr1       = NULL, *bstr2 = NULL;
00636     int bsize1        = -1, bsize2 = -1;
00637     dtext *null_str   = DT("");
00638 
00639     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00640     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00641 
00642     if (con->ver_num >= OCI_10_1)
00643     {
00644         bstr1 = OCI_GetMetaFromDataString(queue_table,     &bsize1);
00645         bstr2 = OCI_GetMetaFromDataString(purge_condition, &bsize2);
00646 
00647         if (bstr2 == NULL)
00648             bstr2 = null_str;
00649 
00650         st = OCI_StatementCreate(con);
00651 
00652         if (st)
00653         {
00654             res = OCI_Prepare
00655                   (
00656                 st,
00657                 MT("DECLARE ")
00658                 MT("    v_purge_options DBMS_AQADM.AQ$_PURGE_OPTIONS_T; ")
00659                 MT("    v_block         BOOLEAN := FALSE; ")
00660                 MT("BEGIN ")
00661                 MT("    v_purge_options.block         := FALSE; ")
00662                 MT("    v_purge_options.delivery_mode := :delivery_mode; ")
00663                 MT("    IF (:block = 1) then ")
00664                 MT("        v_purge_options.block := TRUE; ")
00665                 MT("    END IF; ")
00666                 MT("    DBMS_AQADM.PURGE_QUEUE_TABLE ")
00667                 MT("    (")
00668                 MT("        queue_table      => :queue_table, ")
00669                 MT("        purge_condition  => :purge_condition, ")
00670                 MT("        purge_options    => v_purge_options ")
00671                 MT("   ); ")
00672                 MT("END; ")
00673                   );
00674 
00675             res = res && OCI_BindString(st, MT(":queue_table"), bstr1, 0);
00676             res = res && OCI_BindString(st, MT(":purge_condition"), bstr2, 0);
00677             res = res && OCI_BindInt(st, MT(":block"),  &block);
00678             res = res && OCI_BindUnsignedInt(st, MT(":delivery_mode"),  &delivery_mode);
00679 
00680             res = res && OCI_Execute(st);
00681 
00682             OCI_StatementFree(st);
00683         }
00684 
00685         OCI_ReleaseDataString(bstr1);
00686 
00687         if (purge_condition != NULL)
00688             OCI_ReleaseDataString(bstr2);
00689     }
00690     else
00691     {
00692         res = TRUE;
00693     }
00694 
00695     OCI_RESULT(res);
00696 
00697     return res;
00698 }
00699 
00700 /* --------------------------------------------------------------------------------------------- *
00701  * OCI_QueueTableMigrate
00702  * --------------------------------------------------------------------------------------------- */
00703 
00704 boolean OCI_API OCI_QueueTableMigrate
00705 (
00706     OCI_Connection *con,
00707     const mtext    *queue_table,
00708     const mtext    *compatible
00709 )
00710 {
00711     boolean res       = FALSE;
00712     OCI_Statement *st = NULL;
00713     void *bstr1       = NULL, *bstr2 = NULL;
00714     int bsize1        = -1, bsize2 = -1;
00715 
00716     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00717     OCI_CHECK_PTR(OCI_IPC_STRING, queue_table, FALSE);
00718     OCI_CHECK_PTR(OCI_IPC_STRING, compatible, FALSE);
00719 
00720     bstr1 = OCI_GetMetaFromDataString(queue_table, &bsize1);
00721     bstr2 = OCI_GetMetaFromDataString(compatible,  &bsize2);
00722 
00723     st = OCI_StatementCreate(con);
00724 
00725     if (st)
00726     {
00727         res = OCI_Prepare
00728               (
00729             st,
00730             MT("BEGIN ")
00731             MT("   DBMS_AQADM.MIGRATE_QUEUE_TABLE")
00732             MT("   (")
00733             MT("       queue_table => :queue_table, ")
00734             MT("       compatible  => :compatible ")
00735             MT("   );")
00736             MT("END;")
00737               );
00738 
00739         res = res && OCI_BindString(st, MT(":queue_table"), bstr1, 0);
00740         res = res && OCI_BindString(st, MT(":compatible"),  bstr2, 0);
00741 
00742         res = res && OCI_Execute(st);
00743 
00744         OCI_StatementFree(st);
00745     }
00746 
00747     OCI_ReleaseDataString(bstr1);
00748     OCI_ReleaseDataString(bstr2);
00749 
00750     OCI_RESULT(res);
00751 
00752     return res;
00753 }

Generated on Sun Oct 24 2010 22:02:55 for OCILIB (C Driver for Oracle) by  doxygen 1.7.1