Qore OracleSqlUtil Module Reference  1.1
 All Classes Namespaces Functions Variables Groups Pages
OracleSqlUtil.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file OracleSqlUtil.qm Qore user module for working with Oracle SQL data
3 
4 /* OracleSqlUtil.qm Copyright 2013 - 2014 Qore Technologies, sro
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // this module requires Qore 0.8.11 or better
26 
27 // requires the SqlUtil module
28 
29 // requires the Util module
30 
31 // don't use "$" signs for variables and class members, assume local variable scope
32 
33 // require type definitions everywhere
34 
35 // enable all warnings
36 
37 
38 /* Version History: see docs below
39 */
40  a.*, rownum rnum from (select * from schema.table where type = %v order by type) a where rownum <= %v) where rnum > %v", ("user", 300, 200));
70  @endcode
71  note that the following simpler SQL is generated for Oracle 12c+ servers:
72  @code
73 $ds.vselectRows("select * from schema.table where type = %v order by type offset %v rows fetch next %v rows only", ("user", 200, 100));
74  @endcode
75 
76  @subsection ora_in_operator IN Operator on Oracle
77 
78  In order to avoid dynamic SQL and better manage the server's shared pool (in particular, the number of parsed statements), the %OracleSqlUtil
79  module uses bind by value with the SQL \c IN operator.
80 
81  For example, the following query:
82  @code
83 my *hash $q = $table.select(("where": ("col1": op_in(1, 2, 3, 4))));
84  @endcode
85 
86  Results in the equivalent of the following SQL:
87  @code
88 my *hash $q = $ds.select("select * from schema.table where col1 in (select regexp_substr(%v,'[^,]+', 1, level) from dual connect by regexp_substr(%v, '[^,]+', 1, level) is not null)", "1,2,3,4", "1,2,3,4");
89  @endcode
90 
91  @subsection ora_partitioning_select Partition Support in Selects
92 
93  It's possible to select from a particular partition of a table with %OracleSqlUtil;
94  @ref OracleSqlUtil::OracleTable::OracleSelectOptions "OracleSelectOptions" defines the \c "partition" key which can be added to a
95  @ref select_option_hash "select option hash" to specify the partition to select from as in the following example:
96  @code
97 my *list $rows = $table.selectRows(("created": op_gt(2012-05-01), "partition": "p1"));
98  @endcode
99  Which generates an SQL command like the following:
100  @code
101 my *list $rows = $ds.vselectRows("select * from schema.table partition(p1) where created > %v", (2012-05-01));
102  @endcode
103 
104  @subsection ora_partitioning_join Partition Support in Joins
105 
106  It's possible to perform a join on a particular partition of a table with %OracleSqlUtil; the join option \c "partition" is
107  supported to specify the partition to join on as in the following example:
108  @code
109 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid"), NOTHING, ("partition": "p2"))));
110  @endcode
111  Which generates an SQL command like the following:
112  @code
113 my *list $rows = $ds.vselectRows("select * from schema.table inner join schema.table2 partition(p2) t2 on (schema.table.id = t2.altid)");
114  @endcode
115 
116  @section ora_schema_management Schema Management on Oracle
117 
118  Note that when getting an object description from an Oracle database, if the object cannot be found in the connection schema, then
119  if a synonym of the same type exists and the target object is accessible, then the target object is read automatically and the owning
120  schema name is also set to the actual owner of the object.
121 
122  @subsection ora_type_mapping Type Mapping
123 
124  Column types are mapped from %Qore types as follows:
125 
126  <b>Oracle Column Type Mappings</b>
127  @htmlonly <style><!-- td.qore { background-color: #5b9409; color: white; } --></style> @endhtmlonly
128  <table>
129  <tr>
130  <td class="qore"><b>Generic Type Name</b></td>
131  <td class="qore"><b>Oracle Type Used</b></td>
132  </tr>
133  <tr>
134  <td>\c float</td>
135  <td>\c number</td>
136  </tr>
137  <tr>
138  <td>\c integer</td>
139  <td>\c number</td>
140  </tr>
141  <tr>
142  <td>\c number</td>
143  <td>\c number</td>
144  </tr>
145  <tr>
146  <td>\c string</td>
147  <td>\c varchar2</td>
148  </tr>
149  <tr>
150  <td>\c date</td>
151  <td>\c timestamp(6)</td>
152  </tr>
153  <tr>
154  <td>\c binary</td>
155  <td>\c blob</td>
156  </tr>
157  <tr>
158  <td>@ref SqlUtil::BLOB</td>
159  <td>\c blob</td>
160  </tr>
161  <tr>
162  <td>@ref SqlUtil::CHAR</td>
163  <td>\c char</td>
164  </tr>
165  <tr>
166  <td>@ref SqlUtil::CLOB</td>
167  <td>\c clob</td>
168  </tr>
169  <tr>
170  <td>@ref SqlUtil::NUMERIC</td>
171  <td>\c number</td>
172  </tr>
173  <tr>
174  <td>@ref SqlUtil::VARCHAR</td>
175  <td>\c varchar2</td>
176  </tr>
177  </table>
178 
179  To use other types, use the \c "native_type" @ref SqlUtil::AbstractTable::ColumnDescOptions "column description option" with the
180  native Oracle type name instead (under the \c "driver" and \c "oracle" keys for schemas supporting multiple databases).
181 
182  @subsection ora_other_objects Additional Object Types Supported
183 
184  The following additional schema objects can be managed with %OracleSqlUtil:
185  - @ref ora_materialized_views "materialized views"
186  - @ref ora_packages "packages"
187  - @ref ora_types "types"
188 
189  @subsection ora_materialized_views Materialized Views
190 
191  The @ref schema_desc_hash takes an optional key, \c "materialized_views" that allows materialized views in Oracle schemas to be managed along with other objects.
192 
193  The \c "materialized_views" should be assigned to a hash, each key name is the name of the materialized view, and the values are hashes with the
194  following keys:
195  - \c "logging": (@ref bool_type "bool") if the materialized view should be logged
196  - \c "use_index": (@ref bool_type "bool") if the materialized view should be indexed
197  - \c "src": (@ref bool_type "bool") the source of the materialized view
198 
199  The \c "materialized_views" key can go in the top level of the @ref schema_desc_hash for Oracle-only schemas, or, for schemas targeting multiple database types, under the \c "driver" and \c "oracle" keys as in the following example:
200 
201  @code
202 my hash $schema = (
203  "driver": (
204  "oracle": (
205  "materialized_views": (
206  "example_mv": (
207  "logging": False,
208  "use_index": False,
209  "src": "select type, count(1) total_count from table group by type",
210  ),
211  ),
212  ),
213  ),
214 );
215  @endcode
216 
217  @subsection ora_packages Packages
218 
219  The @ref schema_desc_hash takes an optional key, \c "packages" that allows packages in Oracle schemas to be managed along with other objects.
220 
221  The \c "packages" should be assigned to a hash, each key name is the name of the package, and the values are hashes with the
222  following key:
223  - \c "src": (@ref bool_type "bool") the source of the package
224 
225  The \c "packages" key can go in the top level of the @ref schema_desc_hash for Oracle-only schemas, or, for schemas targeting multiple database types, under the \c "driver" and \c "oracle" keys as in the following example:
226 
227  @code
228 my hash $schema = (
229  "driver": (
230  "oracle": (
231  "packages": (
232  "example_pkg": (
233  "src": "types as
234 type cursorType is ref cursor;
235 MYSTATCOMPLETE constant order_status.orderstatus%type := 'C';
236 MYSTATERROR constant order_status.orderstatus%type := 'E';
237 ",
238  ),
239  ),
240  ),
241  ),
242 );
243  @endcode
244 
245  @subsection ora_types Types
246 
247  The @ref schema_desc_hash takes an optional key, \c "types" that allows types in Oracle schemas to be managed along with other objects.
248 
249  The \c "types" should be assigned to a hash, each key name is the name of the type, and the values are strings giving the type definition.
250 
251  The \c "types" key can go in the top level of the @ref schema_desc_hash for Oracle-only schemas, or, for schemas targeting multiple database types, under the \c "driver" and \c "oracle" keys as in the following example:
252 
253  @code
254 my hash $schema = (
255  "driver": (
256  "oracle": (
257  "types": (
258  "num_array": "table of number",
259  "str_array": "table of varchar2(240)",
260  ),
261  ),
262  ),
263 );
264  @endcode
265 
266  @see OracleSqlUtil::OracleDatabase::OracleSchemaDescriptionOptions for a list of Oracle-specific schema description hash keys.
267 
268  @section ora_relnotes Release Notes
269 
270  @subsection v11 OracleSqlUtil v1.1
271  - fixed selects with "limit" but no "offset"
272  - convert date/time values to timestamps with microseconds resolution instead of dates with second resolution when dynamically inserting values as strings in SQL (binding by value not affected)
273  - fixed schema information classes when the "string-numbers" driver option is enabled
274 
275  @subsection v10 OracleSqlUtil v1.0
276  - initial release
277 */
278 
280 namespace OracleSqlUtil {
282  OracleTable get_table(AbstractDatasource nds, string nname, *hash opts);
283 
284 
286  OracleDatabase get_database(AbstractDatasource nds, *hash opts);
287 
288 
291 
292 public:
293  public :
295  bool char_used;
298 
299 public:
300 
301  constructor(string n, string nt, *string qt, softint sz, bool nul, *string dv, *string cm, bool is_char = False, bool cu = False, softint bs);
302 
303 
305  string getNativeTypeString();
306 
307 
309 
316  list getAddColumnSql(AbstractTable t);
317 
318 
320 
330  list getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt);
331 
332 
334 
344  string getRenameSql(AbstractTable t, string new_name);
345 
346 
348  bool equalImpl(AbstractColumn c);
349 
350  };
351 
354 
355 public:
356  constructor(string n, string nt, *string qt, softint sz, bool nul, *string dv, *string cm, softint bs, softint n_scale = 0);
357 
358 
359  string getNativeTypeString();
360 
361  };
362 
365 
366 public:
367  public :
369  string native_type;
370 
372  *string tablespace;
373 
374 public:
375 
377  constructor(string n, bool u, hash c, string nt, *string t);
378 
379 
381  string getCreateSql(string table_name, *hash opt);
382 
383 
385  bool equalImpl(AbstractIndex ix);
386 
387 
389  string getRenameSql(string table_name, string new_name);
390 
391  };
392 
395 
396 public:
397  public :
399  bool enabled;
400 
401 public:
402 
403  constructor(string n, Columns c, ForeignConstraintTarget t, bool e);
404 
405 
406  string getCreateSql(string table_name, *hash opt);
407 
408 
409  softlist getRenameSql(string table_name, string new_name);
410 
411 
413  string getDisableSql(string table_name);
414 
415 
417  string getEnableSql(string table_name, *hash opt);
418 
419  };
420 
423 
424 public:
425  public :
427  bool enabled;
428 
429 public:
430 
431  constructor(string n, string n_src, bool e = True);
432 
433 
434  string getCreateSql(string table_name, *hash opt);
435 
436 
437  softlist getRenameSql(string table_name, string new_name);
438 
439 
441  string getDisableSql(string table_name);
442 
443 
445  string getEnableSql(string table_name, *hash opt);
446 
447  };
448 
451 
452 public:
453  private :
455  bool enabled;
456 
458  *string tablespace;
459 
460 public:
461 
462  constructor(string n, hash n_cols, bool e = True, *string ts);
463 
464 
466 
481  OracleColumn memberGate(string k);
482 
483 
484  bool setIndexBase(string ix);
485 
486 
488  clearIndex();
489 
490 
491  string getCreateSql(string table_name, *hash opts);
492 
493 
494  softlist getRenameSql(string table_name, string new_name);
495 
496 
498  string getDisableSql(string table_name);
499 
500 
502  string getEnableSql(string table_name, *hash opt);
503 
504  };
505 
508 
509 public:
510  private :
512  *string tablespace;
513 
514 public:
515 
516  constructor();
517 
518 
519  constructor(string n, *hash c, *string ts);
520 
521 
523 
538  OracleColumn memberGate(string k);
539 
540 
541  bool setIndexBase(string ix);
542 
543 
545  clearIndex();
546 
547 
548  string getCreateSql(string table_name, *hash opts);
549 
550 
551  softlist getRenameSql(string table_name, string new_name);
552 
553 
555 
557  string getDropSql(string table_name);
558 
559 
561  string getDisableSql(string table_name);
562 
563 
565  string getEnableSql(string table_name, *hash opt);
566 
567  };
568 
571 
572 public:
574  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_end);
575 
576 
578  string getCreateSql(*hash opt);
579 
580 
582  string getRenameSql(string new_name);
583 
584  };
585 
588 
589 public:
590 
591  public :
593  *string type_text;
595  *string oid_text;
599  *string view_type;
601  *string superview_name;
604 
605 public:
606 
608  constructor(string n_name, string n_src, *string n_schema, *string n_type_text,
609  *string n_oid_text, *string n_view_type_owner,
610  *string n_view_type, *string n_superview_name,
611  bool n_updatable, bool n_container_data)
612 ;
613 
614 
616  string getCreateSql(*hash opt);
617 
618 
620  softlist getRenameSql(string new_name);
621 
622  };
623 
626 
627 public:
628  public :
630  bool enabled;
631 
632 public:
633 
634  constructor(string n, string n_src, bool en = True);
635 
636 
637  softlist getCreateSql(string table_name, *hash opt);
638 
639 
641  bool equalImpl(AbstractFunctionBase t);
642 
643 
645  softlist getRenameSql(string table_name, string new_name);
646 
647 
649  softlist getDropSql(string table_name);
650 
651  };
652 
655 
656 public:
658 
662  constructor(string n, string n_type, string n_src);
663 
664 
666  softlist getCreateSql(*hash opt);
667 
668 
670  bool equalImpl(AbstractFunctionBase t);
671 
672 
674  list getRenameSql(string new_name);
675 
676  };
677 
679 class OracleType : public OracleCodeBase {
680 
681 public:
682  constructor(string n_name, string n_src);
683 
684  };
685 
688 
689 public:
691 
694  constructor(string n, string n_src);
695 
696  };
697 
700 
701 public:
703 
706  constructor(string n, string n_src);
707 
708  };
709 
712 
713 public:
714  private :
716  *string body_src;
717 
718 public:
719 
721 
725  constructor(string n, string n_src, *string n_body_src);
726 
727 
729  list getCreateSql(*hash opt);
730 
731 
733  bool equalImpl(AbstractFunctionBase t);
734 
735  };
736 
739 
740 public:
741  public :
743  bool logging;
745  bool use_index;
747  *string tablespace;
748 
749 public:
750 
752 
758  constructor(string n, string n_src, bool n_logging = True, bool n_use_index = True, *string n_tablespace);
759 
760 
762  softlist getCreateSql(*hash opt);
763 
764 
765  bool equalImpl(AbstractFunctionBase t);
766 
767  };
768 
771 
772 public:
773  public :
775  const OracleCreationOptions = AbstractDatabase::CreationOptions + (
776  "compute_statistics": Type::Boolean,
777  );
778 
780  const OracleAlignSchemaOptions = AbstractDatabase::CreationOptions
782  + OracleTable::OracleAlignTableOptions
783  ;
784 
786 
794  const OracleSchemaDescriptionOptions = AbstractDatabase::SchemaDescriptionOptions + (
795  "types": Type::Hash,
796  "type_map": Type::Hash,
797 
798  "packages": Type::Hash,
799  "package_map": Type::Hash,
800 
801  "materialized_views": Type::Hash,
802  "materialized_view_map": Type::Hash,
803 
804  //"synonyms": Type::Hash,
805  //"synonym_map": Type::Hash,
806  );
807 
810  "src": Type::String,
811  "body": Type::String,
812  );
813 
816  "logging": Type::Boolean,
817  "use_index": Type::Boolean,
818  "tablespace": Type::String,
819  "src": Type::String,
820  );
821 
822 public:
823 
825  constructor(AbstractDatasource nds, *hash opts);
826 
827 
828  private list featuresImpl();
829 
830 
831  private OracleSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
832 
833 
834  private getSchemaName(reference name, reference schema);
835 
836 
837  private *AbstractSequence getSequenceImpl(string name);
838 
839 
840  private *AbstractView getViewImpl(string name);
841 
842 
843  private OracleFunction makeFunctionImpl(string name, string src, *hash opts);
844 
845 
846  private OracleProcedure makeProcedureImpl(string name, string src, *hash opts);
847 
848 
849  private OraclePackage makePackage(string name, string src, string body, *hash opts);
850 
851 
852  private OraclePackage makePackageFromDescription(string name, hash ph, *hash opts);
853 
854 
855  private OracleType makeType(string name, string src, *hash opts);
856 
857 
858  private OracleMaterializedView makeMaterializedView(string name, string src, bool logging = True, bool use_index = True, *string tablespace, *hash opts);
859 
860 
861  private OracleMaterializedView makeMaterializedViewFromDescription(string name, hash mvh, *hash opts);
862 
863 
864  private list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
865 
866 
867  private list getAlignSqlImpl(hash schema_hash, *hash opt);
868 
869 
870  private *OracleFunction getFunctionImpl(string name);
871 
872 
873  private *OracleProcedure getProcedureImpl(string name);
874 
875 
877  *OraclePackage getPackage(string name);
878 
879 
881  *OracleType getType(string name);
882 
883 
886 
887 
888  private *string getSource(string type, string name);
889 
890 
891  private checkSource(string type, string name, reference src);
892 
893 
895  list listSynonyms();
896 
897 
899  ListIterator synonymIterator();
900 
901 
903  list listTypes();
904 
905 
907  ListIterator typeIterator();
908 
909 
911  list listPackages();
912 
913 
915  ListIterator packageIterator();
916 
917 
920 
921 
923  ListIterator materializedViewIterator();
924 
925 
926  private list listTablesImpl();
927 
928 
929  private list listFunctionsImpl();
930 
931 
932  private list listProceduresImpl();
933 
934 
935  private list listSequencesImpl();
936 
937 
938  private list listViewsImpl();
939 
940 
941  private list getListIntern(string type);
942 
943 
944  private list getListIntern(list l);
945 
946 
947  private string getCreateSqlImpl(list l);
948 
949 
950  static string getCreateSql(list l);
951 
953  private hash getCreationOptions();
954 
955 
957  private hash getAlignSchemaOptions();
958 
959 
961  private hash getSchemaDescriptionOptions();
962 
963 
965  private softint getNextSequenceValueImpl(string name);
966 
967 
969  private bool supportsSequencesImpl();
970 
971 
973  private bool supportsTypesImpl();
974 
975 
977  private bool supportsPackagesImpl();
978 
979  };
980 
982 
985 
986 public:
987  public :
989  const OraTypeMap = (
990  "number": ("qore": Type::Number, "size": SZ_NUM, "size_range": (1, 38), "scale_range": (-84, 127)),
991  "varchar2": ("qore": Type::String, "size": SZ_MAND, "size_range": (1, 4000), "is_char": True),
992  "char": ("qore": Type::String, "size": SZ_MAND, "size_range": (1, 4000), "is_char": True),
993  "date": ("qore": Type::Date,),
994  "timestamp": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
995  "timestamp with time zone": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
996  "timestamp with local time zone": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
997  "timestamp(0)": ("qore": Type::Date,),
998  "timestamp(1)": ("qore": Type::Date,),
999  "timestamp(2)": ("qore": Type::Date,),
1000  "timestamp(3)": ("qore": Type::Date,),
1001  "timestamp(4)": ("qore": Type::Date,),
1002  "timestamp(5)": ("qore": Type::Date,),
1003  "timestamp(6)": ("qore": Type::Date,),
1004  "timestamp(7)": ("qore": Type::Date,),
1005  "timestamp(8)": ("qore": Type::Date,),
1006  "timestamp(9)": ("qore": Type::Date,),
1007  "timestamp(0) with time zone": ("qore": Type::Date,),
1008  "timestamp(1) with time zone": ("qore": Type::Date,),
1009  "timestamp(2) with time zone": ("qore": Type::Date,),
1010  "timestamp(3) with time zone": ("qore": Type::Date,),
1011  "timestamp(4) with time zone": ("qore": Type::Date,),
1012  "timestamp(5) with time zone": ("qore": Type::Date,),
1013  "timestamp(6) with time zone": ("qore": Type::Date,),
1014  "timestamp(7) with time zone": ("qore": Type::Date,),
1015  "timestamp(8) with time zone": ("qore": Type::Date,),
1016  "timestamp(9) with time zone": ("qore": Type::Date,),
1017  "timestamp(0) with local time zone": ("qore": Type::Date,),
1018  "timestamp(1) with local time zone": ("qore": Type::Date,),
1019  "timestamp(2) with local time zone": ("qore": Type::Date,),
1020  "timestamp(3) with local time zone": ("qore": Type::Date,),
1021  "timestamp(4) with local time zone": ("qore": Type::Date,),
1022  "timestamp(5) with local time zone": ("qore": Type::Date,),
1023  "timestamp(6) with local time zone": ("qore": Type::Date,),
1024  "timestamp(7) with local time zone": ("qore": Type::Date,),
1025  "timestamp(8) with local time zone": ("qore": Type::Date,),
1026  "timestamp(9) with local time zone": ("qore": Type::Date,),
1027  "interval year(0) to month": ("qore": Type::Date,),
1028  "interval year(1) to month": ("qore": Type::Date,),
1029  "interval year(2) to month": ("qore": Type::Date,),
1030  "interval year(3) to month": ("qore": Type::Date,),
1031  "interval year(4) to month": ("qore": Type::Date,),
1032  "interval year(5) to month": ("qore": Type::Date,),
1033  "interval year(6) to month": ("qore": Type::Date,),
1034  "interval year(7) to month": ("qore": Type::Date,),
1035  "interval year(8) to month": ("qore": Type::Date,),
1036  "interval year(9) to month": ("qore": Type::Date,),
1037  "interval day(0) to second(0)": ("qore": Type::Date,),
1038  "interval day(0) to second(1)": ("qore": Type::Date,),
1039  "interval day(0) to second(2)": ("qore": Type::Date,),
1040  "interval day(0) to second(3)": ("qore": Type::Date,),
1041  "interval day(0) to second(4)": ("qore": Type::Date,),
1042  "interval day(0) to second(5)": ("qore": Type::Date,),
1043  "interval day(0) to second(6)": ("qore": Type::Date,),
1044  "interval day(0) to second(7)": ("qore": Type::Date,),
1045  "interval day(0) to second(8)": ("qore": Type::Date,),
1046  "interval day(0) to second(9)": ("qore": Type::Date,),
1047  "interval day(1) to second(0)": ("qore": Type::Date,),
1048  "interval day(1) to second(1)": ("qore": Type::Date,),
1049  "interval day(1) to second(2)": ("qore": Type::Date,),
1050  "interval day(1) to second(3)": ("qore": Type::Date,),
1051  "interval day(1) to second(4)": ("qore": Type::Date,),
1052  "interval day(1) to second(5)": ("qore": Type::Date,),
1053  "interval day(1) to second(6)": ("qore": Type::Date,),
1054  "interval day(1) to second(7)": ("qore": Type::Date,),
1055  "interval day(1) to second(8)": ("qore": Type::Date,),
1056  "interval day(1) to second(9)": ("qore": Type::Date,),
1057  "interval day(2) to second(0)": ("qore": Type::Date,),
1058  "interval day(2) to second(1)": ("qore": Type::Date,),
1059  "interval day(2) to second(2)": ("qore": Type::Date,),
1060  "interval day(2) to second(3)": ("qore": Type::Date,),
1061  "interval day(2) to second(4)": ("qore": Type::Date,),
1062  "interval day(2) to second(5)": ("qore": Type::Date,),
1063  "interval day(2) to second(6)": ("qore": Type::Date,),
1064  "interval day(2) to second(7)": ("qore": Type::Date,),
1065  "interval day(2) to second(8)": ("qore": Type::Date,),
1066  "interval day(2) to second(9)": ("qore": Type::Date,),
1067  "clob": ("qore": Type::String,),
1068  "blob": ("qore": Type::Binary,),
1069  "long": ("qore": Type::Binary,),
1070  "raw": ("qore": Type::Binary, "size": SZ_MAND, "size_range": (1, 2000)),
1071  "bfile": ("qore": Type::Binary,),
1072  "binary_float": ("qore": Type::Float,),
1073  "binary_double": ("qore": Type::Float,),
1074  "rowid": ("qore": Type::String,),
1075  "urowid": ("qore": Type::String, "size": SZ_OPT, "size_range": (1, 4000)),
1076  );
1077 
1079  const QoreTypeMap = (
1080  "integer": "number",
1081  "float": "number",
1082  "number": "number",
1083  "string": "varchar2",
1084  "date": "timestamp(6)",
1085  "binary": "blob",
1086  SqlUtil::CHAR: "char",
1087  SqlUtil::CLOB: "clob",
1088  SqlUtil::BLOB: "blob",
1089  );
1090 
1091  const OraColumnOpts = (
1092  "character_semantics": Type::Boolean,
1093  );
1094 
1096 
1099  const OraColumnOptions = AbstractTable::ColumnOptions + OraColumnOpts;
1100 
1102 
1105  const OraColumnDescOptions = AbstractTable::ColumnDescOptions + OraColumnOpts;
1106 
1108 
1111  const OracleIndexOptions = AbstractTable::IndexOptions + (
1112  "compute_statistics": Type::Boolean,
1113  );
1114 
1116 
1120  "index": Type::String,
1121  );
1122 
1124  const OracleTableCreationOptions = AbstractTable::TableCreationOptions
1127  ;
1128 
1129  const OracleAlignTableOptions = AbstractTable::AlignTableOptions + OracleTableCreationOptions;
1130 
1132 
1136  const OracleSelectOptions = AbstractTable::SelectOptions + (
1137  "partition": Type::String,
1138  );
1139 
1142  OP_IN: (
1143  "code": string (object t, string cn, any arg, reference args) {
1144  *string argstr = (foldl $1 + "," + $2, (map $1.toString(), arg));
1145 
1146  // in this case this part of the expression will fail
1147  if (!argstr)
1148  return "1 != 1";
1149 
1150  args += argstr;
1151  args += argstr;
1152 
1153  return cn + " in (select regexp_substr(%v,'[^,]+', 1, level) from dual connect by regexp_substr(%v, '[^,]+', 1, level) is not null)";
1154  },
1155  ),
1156  );
1157 
1160  COP_OVER: (
1161  "argcolumn": True,
1162  "argoptional": True,
1163  "code": string (*string cve, *string arg) {
1164  string sql = cve + " over (";
1165  if (arg)
1166  sql += sprintf("partition by %s", arg);
1167  sql += ")";
1168  return sql;
1169  },
1170  ),
1171  COP_YEAR: (
1172  "code": string (string arg1, any arg) {
1173  return sprintf("to_char(%s, 'YYYY')", arg1);
1174  }
1175  ),
1176  COP_YEAR_MONTH: (
1177  "code": string (string arg1, any arg) {
1178  return sprintf("to_char(%s, 'YYYY-MM')", arg1);
1179  }
1180  ),
1181  COP_YEAR_DAY: (
1182  "code": string (string arg1, any arg) {
1183  return sprintf("to_char(%s, 'YYYY-MM-DD')", arg1);
1184  }
1185  ),
1186  COP_YEAR_HOUR: (
1187  "code": string (string arg1, any arg) {
1188  return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", arg1);
1189  }
1190  ),
1191  COP_SEQ: (
1192  "code": string (string arg1, any arg) {
1193  return sprintf("%s.nextval", arg);
1194  }
1195  ),
1196  );
1197 
1200  IOP_SEQ: (
1201  "arg": Type::String,
1202  "immediate": True,
1203  "code": string (string cve, string arg) {
1204  return sprintf("%s.nextval", arg);
1205  },
1206  ),
1207  );
1208 
1209 public:
1210 
1211  private :
1212  // schema name
1213  string schema;
1214 
1215  // tablespace name
1216  *string tablespace;
1217 
1218  // is the table read only?
1219  bool readonly;
1220 
1221  // table comment
1222  *string comment;
1223 
1224  // dblink
1225  *string dblink;
1226 
1227  // Oracle server major version
1228  int ora_major;
1229 
1230 public:
1231 
1232  constructor(AbstractDatasource nds, string nname, *hash opts);
1233 
1234 
1235  private bool checkExistenceImpl();
1236 
1237 
1238  private setTableInfoIntern();
1239 
1240 
1242  string getSqlName();
1243 
1244 
1245  private hash setSchemaTable();
1246 
1247 
1248  private setDblinkSchema();
1249 
1250 
1251  private hash setTable();
1252 
1253 
1254  private string getUserSchema();
1255 
1256 
1257  private string getDBString();
1258 
1259 
1261  string getSchemaName();
1262 
1263 
1265  *string getTablespaceName();
1266 
1267 
1269  *string getComment();
1270 
1271 
1272  bool readOnly();
1273 
1274 
1275  private hash getColumnOptions();
1276 
1277 
1278  private hash getColumnDescOptions();
1279 
1280 
1282  private hash getSelectOptions();
1283 
1284 
1285  private getSelectWhereSqlUnlocked(reference sql, reference args, *hash qh, *hash jch, bool join = False, *hash ch);
1286 
1287 
1288  private doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch);
1289 
1290 
1292  private doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh);
1293 
1294 
1295  private Columns describeImpl();
1296 
1297 
1298  private OraclePrimaryKey getPrimaryKeyImpl();
1299 
1300 
1301  private Indexes getIndexesImpl();
1302 
1303 
1304  private ForeignConstraints getForeignConstraintsImpl(*hash opts);
1305 
1306 
1307  private Constraints getConstraintsImpl();
1308 
1309 
1310  private string getSelectSqlName(*hash qh);
1311 
1312 
1313  private Triggers getTriggersImpl();
1314 
1315 
1316  string getCreateTableSqlImpl(*hash opt);
1317 
1318 
1319  private *list getCreateMiscSqlImpl(*hash opt, bool cache);
1320 
1321 
1322  private string getCreateSqlImpl(list l);
1323 
1324 
1325  private string getRenameSqlImpl(string new_name);
1326 
1327 
1328  private AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
1329 
1330 
1331  private AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
1332 
1333 
1334  private AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
1335 
1336 
1337  private AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
1338 
1339 
1340  private AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
1341 
1342 
1343  private AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
1344 
1345 
1346  private AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
1347 
1348 
1349  private bool tryInsertImpl(string sql, hash row);
1350 
1351 
1352  private *list getAlignSqlImpl(AbstractTable t, *hash opt);
1353 
1354 
1355  private hash getQoreTypeMapImpl();
1356 
1357 
1358  private hash getTypeMapImpl();
1359 
1360 
1361  private hash getIndexOptions();
1362 
1363 
1364  private hash getConstraintOptions();
1365 
1366 
1367  private hash getTableCreationOptions();
1368 
1369 
1370  private hash getAlignTableOptions();
1371 
1372 
1374  private hash getWhereOperatorMap();
1375 
1376 
1378  private hash getColumnOperatorMap();
1379 
1380 
1382  private hash getInsertOperatorMap();
1383 
1384 
1386  private *string getSqlValueImpl(any v);
1387 
1388 
1389  private bool emptyImpl();
1390 
1391 
1392  private setupTableImpl(hash desc, *hash opt);
1393 
1394 
1396  private bool constraintsLinkedToIndexesImpl();
1397 
1398 
1400  private bool uniqueIndexCreatesConstraintImpl();
1401 
1402 
1404  private bool supportsTablespacesImpl();
1405 
1406 
1408  private copyImpl(AbstractTable old);
1409 
1410  };
1411 };
represents an Oracle unique constraint
Definition: OracleSqlUtil.qm.dox.h:450
private hash getSelectOptions()
override in subclasses to return driver-specific options
const Date
represents an Oracle materialized view
Definition: OracleSqlUtil.qm.dox.h:738
date date(date dt)
const COP_SEQ
const Hash
const OracleCreationOptions
oracle-specific generic creation options
Definition: OracleSqlUtil.qm.dox.h:775
list listSynonyms()
returns a list of string synonym names in the database
private hash getAlignSchemaOptions()
returns driver-specific options to the base abstract class
const String
const DefaultIopMap
string sprintf(string fmt,...)
const OP_IN
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
const DefaultCopMap
ListIterator packageIterator()
returns an iterator listing the string package names in the database
const VARCHAR
*string tablespace
the tablespace name of the index (if supported)
Definition: OracleSqlUtil.qm.dox.h:372
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database ...
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from the database
bool logging
Flag if is loggign mode used.
Definition: OracleSqlUtil.qm.dox.h:743
*string view_type_owner
Owner of the type of the view if the view is a typed view.
Definition: OracleSqlUtil.qm.dox.h:597
represents an Oracle table
Definition: OracleSqlUtil.qm.dox.h:984
private hash getInsertOperatorMap()
returns the insert operator map for this object
private bool supportsSequencesImpl()
returns True if the database supports sequences
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database ...
ListIterator synonymIterator()
returns an iterator listing the string synonym names in the database
list getCreateSql(*hash opt)
returns a string that can be used to create the package in the database
*string tablespace
Name of the potential tablespace.
Definition: OracleSqlUtil.qm.dox.h:747
const COP_OVER
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
private bool supportsPackagesImpl()
returns True if the database supports packages
const OracleMaterializedViewDescriptionOptions
oracle-specific materialized view description options
Definition: OracleSqlUtil.qm.dox.h:815
ListIterator materializedViewIterator()
returns an iterator listing the string materialized view names in the database
private bool supportsTypesImpl()
returns True if the database supports named types
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database ...
list getRenameSql(string new_name)
returns a string that can be used to rename the object in the database
*OracleType getType(string name)
returns an OracleType object for the package name given or NOTHING if the object does not exist or is...
string getCreateSql(*hash opt)
returns a string that can be used to create the sequence in the database
*string superview_name
Name of the superview.
Definition: OracleSqlUtil.qm.dox.h:601
bool enabled
True if the trigger is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:630
const True
const SZ_MAND
const CHAR
const OracleIndexOptions
Oracle-specific index options.
Definition: OracleSqlUtil.qm.dox.h:1111
private hash getCreationOptions()
returns driver-specific options to the base abstract class
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:399
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:427
constructor(string n_name, string n_src, *string n_schema, *string n_type_text, *string n_oid_text, *string n_view_type_owner, *string n_view_type, *string n_superview_name, bool n_updatable, bool n_container_data)
creates the object from the arguments
represents an Oracle procedure
Definition: OracleSqlUtil.qm.dox.h:699
number number(softnumber n)
const COP_YEAR_HOUR
OracleColumn memberGate(string k)
returns the OracleColumn value of the given key if it exists, otherwise throws a KEY-ERROR exception ...
const OracleOpMap
where operator specializations for Oracle
Definition: OracleSqlUtil.qm.dox.h:1141
binary binary()
private bool supportsTablespacesImpl()
returns True if the database support tablespaces
constructor(string n, string n_src)
creates the object from the arguments passed
const OracleTableCreationOptions
Oracle table creation options.
Definition: OracleSqlUtil.qm.dox.h:1124
bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
list listTypes()
returns a list of string type names in the database
const False
*string tablespace
any tablespace for the unique key index
Definition: OracleSqlUtil.qm.dox.h:458
constructor(AbstractDatasource nds, *hash opts)
creates the object from the arguments given
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:455
represents an Oracle view
Definition: OracleSqlUtil.qm.dox.h:587
constructor(string n, string n_src, *string n_body_src)
creates the object from the arguments passed
list listMaterializedViews()
returns a list of string materialized view names in the database
list list(...)
const Float
private hash getSchemaDescriptionOptions()
returns driver-specific options to the base abstract class
const Boolean
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database
constructor(string n_name, number n_start=1, number n_increment=1, *softnumber n_end)
creates the object from the arguments
const SZ_NUM
date microseconds(softint us)
const Binary
softlist getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the trigger in the database
softlist getRenameSql(string new_name)
returns a string that can be used to rename the view in the database
*OraclePackage getPackage(string name)
returns an OraclePackage object for the package name given or NOTHING if the object does not exist or...
ListIterator typeIterator()
returns an iterator listing the string type names in the database
*string oid_text
WITH OID clause of the typed view.
Definition: OracleSqlUtil.qm.dox.h:595
string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
bool exists(...)
string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database
const OraColumnDescOptions
Oracle-specific column options.
Definition: OracleSqlUtil.qm.dox.h:1105
private bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
bool use_index
Flag if is index used.
Definition: OracleSqlUtil.qm.dox.h:745
const COP_YEAR_MONTH
private hash getWhereOperatorMap()
returns the "where" operator map for this object
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
constructor(string n, bool u, hash c, string nt, *string t)
creates the object from the arguments
const BLOB
the Oracle specialization for SqlUtil::AbstractDatabase
Definition: OracleSqlUtil.qm.dox.h:770
string type(any arg)
int byte_size
byte size of the column
Definition: OracleSqlUtil.qm.dox.h:297
const CLOB
string getNativeTypeString()
returns the string describing the native type that can be used in SQL (for example to add the colunn ...
bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
const OraclePackageDescriptionOptions
oracle-specific package description options
Definition: OracleSqlUtil.qm.dox.h:809
const NOTHING
string getRenameSql(string new_name)
returns a string that can be used to rename the sequence in the database
const OraTypeMap
maps oracle type names to type descriptions
Definition: OracleSqlUtil.qm.dox.h:989
string string(softstring str)
const OracleAlignSchemaOptions
oracle-specific schema description / alignment options
Definition: OracleSqlUtil.qm.dox.h:780
string getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
const OracleConstraintOptions
Oracle-specific constraint options.
Definition: OracleSqlUtil.qm.dox.h:1119
OracleColumn memberGate(string k)
returns the OracleColumn value of the given key if it exists, otherwise throws a KEY-ERROR exception ...
softlist getCreateSql(*hash opt)
returns a string that can be used to create the object in the database
*string getComment()
returns any table comment or NOTHING if none is known
const OracleIopMap
a hash of default value operator descriptions for Oracle
Definition: OracleSqlUtil.qm.dox.h:1199
string getSchemaName()
returns the schema name
represents an Oracle check constraint
Definition: OracleSqlUtil.qm.dox.h:422
string getSqlName()
returns the schema and table naem in dot notation
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database
constructor(string n, string n_src, bool n_logging=True, bool n_use_index=True, *string n_tablespace)
creates the object from the arguments passed
represents an Oracle number column
Definition: OracleSqlUtil.qm.dox.h:353
clearIndex()
clears any index base for the constraint
represents an Oracle package
Definition: OracleSqlUtil.qm.dox.h:711
const COP_YEAR
list getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
represents an Oracle column
Definition: OracleSqlUtil.qm.dox.h:290
*string type_text
Type clause of the typed view.
Definition: OracleSqlUtil.qm.dox.h:593
OracleDatabase get_database(AbstractDatasource nds, *hash opts)
returns an OracleDatabase object corresponding to the arguments
softlist getCreateSql(*hash opt)
returns a string that can be used to create the object in the database
const OracleCopMap
column operator specializations for Oracle
Definition: OracleSqlUtil.qm.dox.h:1159
list getAddColumnSql(AbstractTable t)
returns a list of sql strings that can be used to add the column to an existing table ...
private hash getColumnOperatorMap()
returns the column operator map for this object
const OracleSelectOptions
Oracle select options.
Definition: OracleSqlUtil.qm.dox.h:1136
const QoreTypeMap
maps qore type names to an oracle type
Definition: OracleSqlUtil.qm.dox.h:1079
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
*string body_src
package body source
Definition: OracleSqlUtil.qm.dox.h:716
*OracleMaterializedView getMaterializedView(string name)
returns an OracleMaterializedView object for the package name given or NOTHING if the object does not...
private *string getSqlValueImpl(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
constructor(string n, string n_src)
creates the object from the arguments passed
const COP_YEAR_DAY
private bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
*string tablespace
any tablespace for the primary key index
Definition: OracleSqlUtil.qm.dox.h:512
*string view_type
Type of the view if the view is a typed view.
Definition: OracleSqlUtil.qm.dox.h:599
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database
private copyImpl(AbstractTable old)
db-specific copy actions
list listPackages()
returns a list of string package names in the database
const Object
represents an Oracle sequence
Definition: OracleSqlUtil.qm.dox.h:570
represents an Oracle trigger
Definition: OracleSqlUtil.qm.dox.h:625
softlist getDropSql(string table_name)
returns a string that can be used to drop the trigger from the database
OracleTable get_table(AbstractDatasource nds, string nname, *hash opts)
returns an OracleTable object corresponding to the arguments
hash hash(object obj)
bool container_data
Indicates whether the view contains container-specific data.
Definition: OracleSqlUtil.qm.dox.h:603
const OracleSchemaDescriptionOptions
oracle-specific schema description keys
Definition: OracleSqlUtil.qm.dox.h:794
const SZ_OPT
string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
const OraColumnOptions
Oracle-specific column options.
Definition: OracleSqlUtil.qm.dox.h:1099
const IOP_SEQ
represents an Oracle foreign constraint
Definition: OracleSqlUtil.qm.dox.h:394
represents an Oracle type
Definition: OracleSqlUtil.qm.dox.h:679
represents an Oracle primary key
Definition: OracleSqlUtil.qm.dox.h:507
clearIndex()
clears any index base for the constraint
*string getTablespaceName()
returns the data tablespace name for the table if any or NOTHING if none is known ...
private doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh)
processes a string for use in SQL select statements when there is a "limit" argument, but no "orderby" or "offset" arguments
string native_type
the native type of the index (if supported)
Definition: OracleSqlUtil.qm.dox.h:369
string join(string str,...)
const NUMERIC
const Number
private softint getNextSequenceValueImpl(string name)
returns the next value in the given sequence
represents an Oracle index
Definition: OracleSqlUtil.qm.dox.h:364
const DefaultOpMap
bool char_used
the column uses character semantics
Definition: OracleSqlUtil.qm.dox.h:295
represents an Oracle function
Definition: OracleSqlUtil.qm.dox.h:687
the base class for Oracle code objects
Definition: OracleSqlUtil.qm.dox.h:654
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database ...