OTL 4.0, OTL template, dynamic, and STL vector based containers for PL/SQL tables (OCIx)

OTL template, dynamic, and STL vector based containers for PL/SQL tables (OCIx)

In OTL 3.x, a set of new template, dynamically allocated, and STL vector based data containers were introduced to support PL/SQL tables as parameters via otl_streams:

Numeric PL/SQL tables

   template class otl_int_tab<int max_tab_size>;
   template class otl_double_tab<int max_tab_size>;
   template class otl_float_tab<int max_tab_size>;
   template class otl_unsgined_tab<int max_tab_size>;
   template class otl_short_tab<int max_tab_size>;
   template class otl_long_int_tab<int max_tab_size>;
   class otl_dynamic_int_tab(int max_tab_size=1);
   class otl_dynamic_double_tab(int max_tab_size=1);
   class otl_dynamic_float_tab(int max_tab_size=1);
   class otl_dynamic_unsgined_tab(int max_tab_size=1);
   class otl_dynamic_short_tab(int max_tab_size=1);
   class otl_dynamic_long_int_tab(int max_tab_size=1);
   class otl_int_vec;
   class otl_double_vec;
   class otl_float_vec;
   class otl_unsgined_vec;
   class otl_short_vec;
   class otl_long_int_vec;
Date & time PL/SQL tables
    template class otl_datetime_tab<int max_tab_size>;
    class otl_dynamic_datetime_tab(int max_tab_size=1);
    class otl_datetime_vec;
C-string (null terminated) PL/SQL tables
    template class otl_cstr_tab<int max_tab_size, int max_str_size>;
    template class otl_dynamic_cstr_tab<int max_str_size>(int max_tab_size=1);
STL string (std::string), STL vector based PL/SQL tables
  class otl_string_vec;


max_tab_size defines the PL/SQL table maximum size.
max_str_size defines the string maximum size, in case of the otl_cstr_tab template class and the otl_dynamic_cstr_tab class.

The difference between the template and dynamic containers is that the max_tab_size is a template parameter in the template containers and a constructor parameter in the dynamic containers. Therefore, the template containers define the table size statically, at compile time, and the dynamic containers define the table size dynamically, at runtime.

STL vector based data containers do not have any restrictions on the container size, nor they have any initial size requirements. Everything is controlled by the STL vector memory allocator.
 

Each PL/SQL table template, dynamic, and STL vector based class has the following data member:

Numerics, Date & times:

   T v[max_tab_size]; // template container

   T* v=new T[max_tab_size]; // dynamic container

   std::vector<T> v; // vector based container
Strings
   typedef unsigned char T[max_str_size]; // both template and dynamic containers

   T v[max_tab_size]; // template container

   T* v=new T[max_tab_size]; // dynamic container
   std::vector<std::string> v; // string vector container

and member functions: 

int is_null(int ndx=0) Check if the Nth element of the PL/SQL table is NULL
void set_null(ind ndx=0) Set if the Nth element of the PL/SQL table to NULL
void set_non_null(int ndx=0) If the Nth element of the PL/SQL table was set to a value, then this functions needs to be called to set the null flag to NOT NULL
int len() This function returns the dynamic length of the PL/SQL table . It is needed if PL/SQL tables are OUT or IN OUT parameters in stored procedures.
void set_len(int new_len) Set the dynamic length of the PL/SQL table. It is needed if PL/SQL tables are IN parameters in stored procedures. Important: this function needs to be called first, to set the size of the vector based container, and only after that to assign values to the elements of the container.

Also, see examples 49, 50, 51, 52 (template containers), examples 68, 69, 70, 71 (dynamic containers), and examples 85, 86, 87, 88 (vector based containers)

When #define OTL_UNICODE is enabled, character/string PL/SQL table containers will be populated with NULL terminated Unicode character strings, even though the string buffer size was specified in bytes. Therefore, the size of buffer needs to be calculated accordingly: 2 bytes per Unicode character + 2 bytes for a possible surrogate character that can be added for each Unicode character + 2-byte NULL terminator and the end of the string. In order to access the Unicode character array/string the char[] buffer needs to be type cast to "unsigned short*". See code samples for more detail.


Prev NextContentsGo Home

Copyright © 1996-2017, Sergei Kuchin, email: skuchin@gmail.com, Last Updated:

Permission to use, copy, modify and redistribute this document for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.