Qore OracleSqlUtil Module Reference  1.0
 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.8 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
39  * 2013-10-04 v1.0: David Nichols <david@qore.org>
40  + the initial version of the OracleSqlUtil module
41 */
42  a.*, rownum rnum from (select * from schema.table where type = %v order by type) a where rownum <= %v) where rnum > %v", ("user", 300, 200));
72  @endcode
73  note that the following simpler SQL is generated for Oracle 12c+ servers:
74  @code
75 $ds.vselectRows("select * from schema.table where type = %v order by type offset %v rows fetch next %v rows only", ("user", 200, 100));
76  @endcode
77 
78  @subsection ora_in_operator IN Operator on Oracle
79 
80  In order to avoid dynamic SQL and better manage the server's shared pool (in particular, the number of parsed statements), the %OracleSqlUtil
81  module uses bind by value with the SQL \c IN operator.
82 
83  For example, the following query:
84  @code
85 my *hash $q = $table.select(("where": ("col1": op_in(1, 2, 3, 4))));
86  @endcode
87 
88  Results in the equivalent of the following SQL:
89  @code
90 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");
91  @endcode
92 
93  @subsection ora_partitioning_select Partition Support in Selects
94 
95  It's possible to select from a particular partition of a table with %OracleSqlUtil;
96  @ref OracleSqlUtil::OracleTable::OracleSelectOptions "OracleSelectOptions" defines the \c "partition" key which can be added to a
97  @ref select_option_hash "select option hash" to specify the partition to select from as in the following example:
98  @code
99 my *list $rows = $table.selectRows(("created": op_gt(2012-05-01), "partition": "p1"));
100  @endcode
101  Which generates an SQL command like the following:
102  @code
103 my *list $rows = $ds.vselectRows("select * from schema.table partition(p1) where created > %v", (2012-05-01));
104  @endcode
105 
106  @subsection ora_partitioning_join Partition Support in Joins
107 
108  It's possible to perform a join on a particular partition of a table with %OracleSqlUtil; the join option \c "partition" is
109  supported to specify the partition to join on as in the following example:
110  @code
111 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid"), NOTHING, ("partition": "p2"))));
112  @endcode
113  Which generates an SQL command like the following:
114  @code
115 my *list $rows = $ds.vselectRows("select * from schema.table inner join schema.table2 partition(p2) t2 on (schema.table.id = t2.altid)");
116  @endcode
117 
118  @section ora_schema_management Schema Management on Oracle
119 
120  Note that when getting an object description from an Oracle database, if the object cannot be found in the connection schema, then
121  if a synonym of the same type exists and the target object is accessible, then the target object is read automatically and the owning
122  schema name is also set to the actual owner of the object.
123 
124  @subsection ora_type_mapping Type Mapping
125 
126  Column types are mapped from %Qore types as follows:
127 
128  <b>Oracle Column Type Mappings</b>
129  @htmlonly <style><!-- td.qore { background-color: #5b9409; color: white; } --></style> @endhtmlonly
130  <table>
131  <tr>
132  <td class="qore"><b>Generic Type Name</b></td>
133  <td class="qore"><b>Oracle Type Used</b></td>
134  </tr>
135  <tr>
136  <td>\c float</td>
137  <td>\c number</td>
138  </tr>
139  <tr>
140  <td>\c integer</td>
141  <td>\c number</td>
142  </tr>
143  <tr>
144  <td>\c number</td>
145  <td>\c number</td>
146  </tr>
147  <tr>
148  <td>\c string</td>
149  <td>\c varchar2</td>
150  </tr>
151  <tr>
152  <td>\c date</td>
153  <td>\c timestamp(6)</td>
154  </tr>
155  <tr>
156  <td>\c binary</td>
157  <td>\c blob</td>
158  </tr>
159  <tr>
160  <td>@ref SqlUtil::BLOB</td>
161  <td>\c blob</td>
162  </tr>
163  <tr>
164  <td>@ref SqlUtil::CHAR</td>
165  <td>\c char</td>
166  </tr>
167  <tr>
168  <td>@ref SqlUtil::CLOB</td>
169  <td>\c clob</td>
170  </tr>
171  <tr>
172  <td>@ref SqlUtil::NUMERIC</td>
173  <td>\c number</td>
174  </tr>
175  <tr>
176  <td>@ref SqlUtil::VARCHAR</td>
177  <td>\c varchar2</td>
178  </tr>
179  </table>
180 
181  To use other types, use the \c "native_type" @ref SqlUtil::AbstractTable::ColumnDescOptions "column description option" with the
182  native Oracle type name instead (under the \c "driver" and \c "oracle" keys for schemas supporting multiple databases).
183 
184  @subsection ora_other_objects Additional Object Types Supported
185 
186  The following additional schema objects can be managed with %OracleSqlUtil:
187  - @ref ora_materialized_views "materialized views"
188  - @ref ora_packages "packages"
189  - @ref ora_types "types"
190 
191  @subsection ora_materialized_views Materialized Views
192 
193  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.
194 
195  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
196  following keys:
197  - \c "logging": (@ref bool_type "bool") if the materialized view should be logged
198  - \c "use_index": (@ref bool_type "bool") if the materialized view should be indexed
199  - \c "src": (@ref bool_type "bool") the source of the materialized view
200 
201  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:
202 
203  @code
204 my hash $schema = (
205  "driver": (
206  "oracle": (
207  "materialized_views": (
208  "example_mv": (
209  "logging": False,
210  "use_index": False,
211  "src": "select type, count(1) total_count from table group by type",
212  ),
213  ),
214  ),
215  ),
216 );
217  @endcode
218 
219  @subsection ora_packages Packages
220 
221  The @ref schema_desc_hash takes an optional key, \c "packages" that allows packages in Oracle schemas to be managed along with other objects.
222 
223  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
224  following key:
225  - \c "src": (@ref bool_type "bool") the source of the package
226 
227  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:
228 
229  @code
230 my hash $schema = (
231  "driver": (
232  "oracle": (
233  "packages": (
234  "example_pkg": (
235  "src": "types as
236 type cursorType is ref cursor;
237 MYSTATCOMPLETE constant order_status.orderstatus%type := 'C';
238 MYSTATERROR constant order_status.orderstatus%type := 'E';
239 ",
240  ),
241  ),
242  ),
243  ),
244 );
245  @endcode
246 
247  @subsection ora_types Types
248 
249  The @ref schema_desc_hash takes an optional key, \c "types" that allows types in Oracle schemas to be managed along with other objects.
250 
251  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.
252 
253  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:
254 
255  @code
256 my hash $schema = (
257  "driver": (
258  "oracle": (
259  "types": (
260  "num_array": "table of number",
261  "str_array": "table of varchar2(240)",
262  ),
263  ),
264  ),
265 );
266  @endcode
267 
268  @see OracleSqlUtil::OracleDatabase::OracleSchemaDescriptionOptions for a list of Oracle-specific schema description hash keys.
269 
270  @section ora_relnotes Release Notes
271 
272  @subsection v10 OracleSqlUtil v1.0
273  - initial release
274 */
275 
277 namespace OracleSqlUtil {
279  OracleTable get_table(AbstractDatasource nds, string nname, *hash opts);
280 
281 
283  OracleDatabase get_database(AbstractDatasource nds, *hash opts);
284 
285 
288 
289 public:
290  public :
292  bool char_used;
295 
296 public:
297 
298  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, bool is_char = False, bool cu = False, int bs);
299 
300 
302  string getNativeTypeString();
303 
304 
306 
313  list getCreateSql(AbstractTable t);
314 
315 
317 
327  list getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt);
328 
329 
331 
341  string getRenameSql(AbstractTable t, string new_name);
342 
343 
345  bool equalImpl(AbstractColumn c);
346 
347  };
348 
351 
352 public:
353  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, int bs, int n_scale = 0);
354 
355 
356  string getNativeTypeString();
357 
358  };
359 
362 
363 public:
364  public :
366  string native_type;
367 
369  *string tablespace;
370 
371 public:
372 
374  constructor(string n, bool u, hash c, string nt, *string t);
375 
376 
378  string getCreateSql(string table_name, *hash opt);
379 
380 
382  bool equalImpl(AbstractIndex ix);
383 
384 
386  string getRenameSql(string table_name, string new_name);
387 
388  };
389 
392 
393 public:
394  public :
396  bool enabled;
397 
398 public:
399 
400  constructor(string n, Columns c, ForeignConstraintTarget t, bool e);
401 
402 
403  string getCreateSql(string table_name, *hash opt);
404 
405 
406  softlist getRenameSql(string table_name, string new_name);
407 
408 
410  string getDisableSql(string table_name);
411 
412 
414  string getEnableSql(string table_name, *hash opt);
415 
416  };
417 
420 
421 public:
422  public :
424  bool enabled;
425 
426 public:
427 
428  constructor(string n, string n_src, bool e = True);
429 
430 
431  string getCreateSql(string table_name, *hash opt);
432 
433 
434  softlist getRenameSql(string table_name, string new_name);
435 
436 
438  string getDisableSql(string table_name);
439 
440 
442  string getEnableSql(string table_name, *hash opt);
443 
444  };
445 
448 
449 public:
450  private :
452  bool enabled;
453 
455  *string tablespace;
456 
457 public:
458 
459  constructor(string n, hash n_cols, bool e = True, *string ts);
460 
461 
463 
478  OracleColumn memberGate(string k);
479 
480 
481  bool setIndexBase(string ix);
482 
483 
485  clearIndex();
486 
487 
488  string getCreateSql(string table_name, *hash opts);
489 
490 
491  softlist getRenameSql(string table_name, string new_name);
492 
493 
495  string getDisableSql(string table_name);
496 
497 
499  string getEnableSql(string table_name, *hash opt);
500 
501  };
502 
505 
506 public:
507  private :
509  *string tablespace;
510 
511 public:
512 
513  constructor();
514 
515 
516  constructor(string n, *hash c, *string ts);
517 
518 
520 
535  OracleColumn memberGate(string k);
536 
537 
538  bool setIndexBase(string ix);
539 
540 
542  clearIndex();
543 
544 
545  string getCreateSql(string table_name, *hash opts);
546 
547 
548  softlist getRenameSql(string table_name, string new_name);
549 
550 
552 
554  string getDropSql(string table_name);
555 
556 
558  string getDisableSql(string table_name);
559 
560 
562  string getEnableSql(string table_name, *hash opt);
563 
564  };
565 
568 
569 public:
571  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_end);
572 
573 
575  string getCreateSql(*hash opt);
576 
577 
579  string getRenameSql(string new_name);
580 
581  };
582 
585 
586 public:
587 
588  public :
590  *string type_text;
592  *string oid_text;
596  *string view_type;
598  *string superview_name;
601 
602 public:
603 
605  constructor(string n_name, string n_src, *string n_schema, *string n_type_text,
606  *string n_oid_text, *string n_view_type_owner,
607  *string n_view_type, *string n_superview_name,
608  bool n_updatable, bool n_container_data)
609 ;
610 
611 
613  string getCreateSql(*hash opt);
614 
615 
617  softlist getRenameSql(string new_name);
618 
619  };
620 
623 
624 public:
625  public :
627  bool enabled;
628 
629 public:
630 
631  constructor(string n, string n_src, bool en = True);
632 
633 
634  softlist getCreateSql(string table_name, *hash opt);
635 
636 
638  bool equalImpl(AbstractFunctionBase t);
639 
640 
642  softlist getRenameSql(string table_name, string new_name);
643 
644 
646  softlist getDropSql(string table_name);
647 
648  };
649 
652 
653 public:
655 
659  constructor(string n, string n_type, string n_src);
660 
661 
663  softlist getCreateSql(*hash opt);
664 
665 
667  bool equalImpl(AbstractFunctionBase t);
668 
669 
671  list getRenameSql(string new_name);
672 
673  };
674 
676 class OracleType : public OracleCodeBase {
677 
678 public:
679  constructor(string n_name, string n_src);
680 
681  };
682 
685 
686 public:
688 
691  constructor(string n, string n_src);
692 
693  };
694 
697 
698 public:
700 
703  constructor(string n, string n_src);
704 
705  };
706 
709 
710 public:
711  private :
713  *string body_src;
714 
715 public:
716 
718 
722  constructor(string n, string n_src, *string n_body_src);
723 
724 
726  list getCreateSql(*hash opt);
727 
728 
730  bool equalImpl(AbstractFunctionBase t);
731 
732  };
733 
736 
737 public:
738  public :
740  bool logging;
742  bool use_index;
744  *string tablespace;
745 
746 public:
747 
749 
755  constructor(string n, string n_src, bool n_logging = True, bool n_use_index = True, *string n_tablespace);
756 
757 
759  softlist getCreateSql(*hash opt);
760 
761 
762  bool equalImpl(AbstractFunctionBase t);
763 
764  };
765 
768 
769 public:
770  public :
772  const OracleCreationOptions = AbstractDatabase::CreationOptions + (
773  "compute_statistics": Type::Boolean,
774  );
775 
777  const OracleAlignSchemaOptions = AbstractDatabase::CreationOptions
779  + OracleTable::OracleAlignTableOptions
780  ;
781 
783 
791  const OracleSchemaDescriptionOptions = AbstractDatabase::SchemaDescriptionOptions + (
792  "types": Type::Hash,
793  "type_map": Type::Hash,
794 
795  "packages": Type::Hash,
796  "package_map": Type::Hash,
797 
798  "materialized_views": Type::Hash,
799  "materialized_view_map": Type::Hash,
800 
801  //"synonyms": Type::Hash,
802  //"synonym_map": Type::Hash,
803  );
804 
807  "src": Type::String,
808  "body": Type::String,
809  );
810 
813  "logging": Type::Boolean,
814  "use_index": Type::Boolean,
815  "tablespace": Type::String,
816  "src": Type::String,
817  );
818 
819 public:
820 
821  constructor(AbstractDatasource nds, *hash opts);
822 
823 
824  private list featuresImpl();
825 
826 
827  private OracleSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
828 
829 
830  private getSchemaName(reference name, reference schema);
831 
832 
833  private *AbstractSequence getSequenceImpl(string name);
834 
835 
836  private *AbstractView getViewImpl(string name);
837 
838 
839  private OracleFunction makeFunctionImpl(string name, string src, *hash opts);
840 
841 
842  private OracleProcedure makeProcedureImpl(string name, string src, *hash opts);
843 
844 
845  OraclePackage makePackage(string name, string src, string body, *hash opts);
846 
847 
848  OraclePackage makePackageFromDescription(string name, hash ph, *hash opts);
849 
850 
851  OracleType makeType(string name, string src, *hash opts);
852 
853 
854  OracleMaterializedView makeMaterializedView(string name, string src, bool logging = True, bool use_index = True, *string tablespace, *hash opts);
855 
856 
857  OracleMaterializedView makeMaterializedViewFromDescription(string name, hash mvh, *hash opts);
858 
859 
860  private list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
861 
862 
863  private list getAlignSqlImpl(hash schema_hash, *hash opt);
864 
865 
866  private *OracleFunction getFunctionImpl(string name);
867 
868 
869  private *OracleProcedure getProcedureImpl(string name);
870 
871 
872  *OraclePackage getPackage(string name);
873 
874 
875  *OracleType getType(string name);
876 
877 
878  *OracleMaterializedView getMaterializedView(string name);
879 
880 
881  private *string getSource(string type, string name);
882 
883 
884  private checkSource(string type, string name, reference src);
885 
886 
888  list listSynonyms();
889 
890 
892  ListIterator synonymIterator();
893 
894 
896  list listTypes();
897 
898 
900  ListIterator typeIterator();
901 
902 
904  list listPackages();
905 
906 
908  ListIterator packageIterator();
909 
910 
913 
914 
916  ListIterator materializedViewIterator();
917 
918 
919  private list listTablesImpl();
920 
921 
922  private list listFunctionsImpl();
923 
924 
925  private list listProceduresImpl();
926 
927 
928  private list listSequencesImpl();
929 
930 
931  private list listViewsImpl();
932 
933 
934  private list getListIntern(string type);
935 
936 
937  private list getListIntern(list l);
938 
939 
940  private string getCreateSqlImpl(list l);
941 
942 
943  static string getCreateSql(list l);
944 
946  private hash getCreationOptions();
947 
948 
950  private hash getAlignSchemaOptions();
951 
952 
954  private hash getSchemaDescriptionOptions();
955 
956 
958  private softint getNextSequenceValueImpl(string name);
959 
960 
962  private bool supportsSequencesImpl();
963 
964 
966  private bool supportsTypesImpl();
967 
968 
970  private bool supportsPackagesImpl();
971 
972  };
973 
975 
978 
979 public:
980  public :
982  const OraTypeMap = (
983  "number": ("qore": Type::Number, "size": SZ_NUM, "size_range": (1, 38), "scale_range": (-84, 127)),
984  "varchar2": ("qore": Type::String, "size": SZ_MAND, "size_range": (1, 4000), "is_char": True),
985  "char": ("qore": Type::String, "size": SZ_MAND, "size_range": (1, 4000), "is_char": True),
986  "date": ("qore": Type::Date,),
987  "timestamp": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
988  "timestamp with time zone": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
989  "timestamp with local time zone": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
990  "timestamp(0)": ("qore": Type::Date,),
991  "timestamp(1)": ("qore": Type::Date,),
992  "timestamp(2)": ("qore": Type::Date,),
993  "timestamp(3)": ("qore": Type::Date,),
994  "timestamp(4)": ("qore": Type::Date,),
995  "timestamp(5)": ("qore": Type::Date,),
996  "timestamp(6)": ("qore": Type::Date,),
997  "timestamp(7)": ("qore": Type::Date,),
998  "timestamp(8)": ("qore": Type::Date,),
999  "timestamp(9)": ("qore": Type::Date,),
1000  "timestamp(0) with time zone": ("qore": Type::Date,),
1001  "timestamp(1) with time zone": ("qore": Type::Date,),
1002  "timestamp(2) with time zone": ("qore": Type::Date,),
1003  "timestamp(3) with time zone": ("qore": Type::Date,),
1004  "timestamp(4) with time zone": ("qore": Type::Date,),
1005  "timestamp(5) with time zone": ("qore": Type::Date,),
1006  "timestamp(6) with time zone": ("qore": Type::Date,),
1007  "timestamp(7) with time zone": ("qore": Type::Date,),
1008  "timestamp(8) with time zone": ("qore": Type::Date,),
1009  "timestamp(9) with time zone": ("qore": Type::Date,),
1010  "timestamp(0) with local time zone": ("qore": Type::Date,),
1011  "timestamp(1) with local time zone": ("qore": Type::Date,),
1012  "timestamp(2) with local time zone": ("qore": Type::Date,),
1013  "timestamp(3) with local time zone": ("qore": Type::Date,),
1014  "timestamp(4) with local time zone": ("qore": Type::Date,),
1015  "timestamp(5) with local time zone": ("qore": Type::Date,),
1016  "timestamp(6) with local time zone": ("qore": Type::Date,),
1017  "timestamp(7) with local time zone": ("qore": Type::Date,),
1018  "timestamp(8) with local time zone": ("qore": Type::Date,),
1019  "timestamp(9) with local time zone": ("qore": Type::Date,),
1020  "interval year(0) to month": ("qore": Type::Date,),
1021  "interval year(1) to month": ("qore": Type::Date,),
1022  "interval year(2) to month": ("qore": Type::Date,),
1023  "interval year(3) to month": ("qore": Type::Date,),
1024  "interval year(4) to month": ("qore": Type::Date,),
1025  "interval year(5) to month": ("qore": Type::Date,),
1026  "interval year(6) to month": ("qore": Type::Date,),
1027  "interval year(7) to month": ("qore": Type::Date,),
1028  "interval year(8) to month": ("qore": Type::Date,),
1029  "interval year(9) to month": ("qore": Type::Date,),
1030  "interval day(0) to second(0)": ("qore": Type::Date,),
1031  "interval day(0) to second(1)": ("qore": Type::Date,),
1032  "interval day(0) to second(2)": ("qore": Type::Date,),
1033  "interval day(0) to second(3)": ("qore": Type::Date,),
1034  "interval day(0) to second(4)": ("qore": Type::Date,),
1035  "interval day(0) to second(5)": ("qore": Type::Date,),
1036  "interval day(0) to second(6)": ("qore": Type::Date,),
1037  "interval day(0) to second(7)": ("qore": Type::Date,),
1038  "interval day(0) to second(8)": ("qore": Type::Date,),
1039  "interval day(0) to second(9)": ("qore": Type::Date,),
1040  "interval day(1) to second(0)": ("qore": Type::Date,),
1041  "interval day(1) to second(1)": ("qore": Type::Date,),
1042  "interval day(1) to second(2)": ("qore": Type::Date,),
1043  "interval day(1) to second(3)": ("qore": Type::Date,),
1044  "interval day(1) to second(4)": ("qore": Type::Date,),
1045  "interval day(1) to second(5)": ("qore": Type::Date,),
1046  "interval day(1) to second(6)": ("qore": Type::Date,),
1047  "interval day(1) to second(7)": ("qore": Type::Date,),
1048  "interval day(1) to second(8)": ("qore": Type::Date,),
1049  "interval day(1) to second(9)": ("qore": Type::Date,),
1050  "interval day(2) to second(0)": ("qore": Type::Date,),
1051  "interval day(2) to second(1)": ("qore": Type::Date,),
1052  "interval day(2) to second(2)": ("qore": Type::Date,),
1053  "interval day(2) to second(3)": ("qore": Type::Date,),
1054  "interval day(2) to second(4)": ("qore": Type::Date,),
1055  "interval day(2) to second(5)": ("qore": Type::Date,),
1056  "interval day(2) to second(6)": ("qore": Type::Date,),
1057  "interval day(2) to second(7)": ("qore": Type::Date,),
1058  "interval day(2) to second(8)": ("qore": Type::Date,),
1059  "interval day(2) to second(9)": ("qore": Type::Date,),
1060  "clob": ("qore": Type::String,),
1061  "blob": ("qore": Type::Binary,),
1062  "long": ("qore": Type::Binary,),
1063  "raw": ("qore": Type::Binary, "size": SZ_MAND, "size_range": (1, 2000)),
1064  "bfile": ("qore": Type::Binary,),
1065  "binary_float": ("qore": Type::Float,),
1066  "binary_double": ("qore": Type::Float,),
1067  "rowid": ("qore": Type::String,),
1068  "urowid": ("qore": Type::String, "size": SZ_OPT, "size_range": (1, 4000)),
1069  );
1070 
1072  const QoreTypeMap = (
1073  "integer": "number",
1074  "float": "number",
1075  "number": "number",
1076  "string": "varchar2",
1077  "date": "timestamp(6)",
1078  "binary": "blob",
1079  SqlUtil::CHAR: "char",
1080  SqlUtil::CLOB: "clob",
1081  SqlUtil::BLOB: "blob",
1082  );
1083 
1084  const OraColumnOpts = (
1085  "character_semantics": Type::Boolean,
1086  );
1087 
1089 
1092  const OraColumnOptions = AbstractTable::ColumnOptions + OraColumnOpts;
1093 
1095 
1098  const OraColumnDescOptions = AbstractTable::ColumnDescOptions + OraColumnOpts;
1099 
1101 
1104  const OracleIndexOptions = AbstractTable::IndexOptions + (
1105  "compute_statistics": Type::Boolean,
1106  );
1107 
1109 
1113  "index": Type::String,
1114  );
1115 
1117  const OracleTableCreationOptions = AbstractTable::TableCreationOptions
1120  ;
1121 
1122  const OracleAlignTableOptions = AbstractTable::AlignTableOptions + OracleTableCreationOptions;
1123 
1125 
1129  const OracleSelectOptions = AbstractTable::SelectOptions + (
1130  "partition": Type::String,
1131  );
1132 
1135  OP_IN: (
1136  "code": string (object t, string cn, any arg, reference args) {
1137  *string argstr = (foldl $1 + "," + $2, (map $1.toString(), arg));
1138 
1139  // in this case this part of the expression will fail
1140  if (!argstr)
1141  return "1 != 1";
1142 
1143  args += argstr;
1144  args += argstr;
1145 
1146  return cn + " in (select regexp_substr(%v,'[^,]+', 1, level) from dual connect by regexp_substr(%v, '[^,]+', 1, level) is not null)";
1147  },
1148  ),
1149  );
1150 
1153  COP_OVER: (
1154  "argcolumn": True,
1155  "argoptional": True,
1156  "code": string (*string cve, *string arg) {
1157  string sql = cve + " over (";
1158  if (arg)
1159  sql += sprintf("partition by %s", arg);
1160  sql += ")";
1161  return sql;
1162  },
1163  ),
1164  COP_YEAR: (
1165  "code": string (string arg1, any arg) {
1166  return sprintf("to_char(%s, 'YYYY')", arg1);
1167  }
1168  ),
1169  COP_YEAR_MONTH: (
1170  "code": string (string arg1, any arg) {
1171  return sprintf("to_char(%s, 'YYYY-MM')", arg1);
1172  }
1173  ),
1174  COP_YEAR_DAY: (
1175  "code": string (string arg1, any arg) {
1176  return sprintf("to_char(%s, 'YYYY-MM-DD')", arg1);
1177  }
1178  ),
1179  COP_YEAR_HOUR: (
1180  "code": string (string arg1, any arg) {
1181  return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", arg1);
1182  }
1183  ),
1184  );
1185 
1186 public:
1187 
1188  private :
1189  // schema name
1190  string schema;
1191 
1192  // tablespace name
1193  *string tablespace;
1194 
1195  // is the table read only?
1196  bool readonly;
1197 
1198  // table comment
1199  *string comment;
1200 
1201  // dblink
1202  *string dblink;
1203 
1204  // Oracle server major version
1205  int ora_major;
1206 
1207 public:
1208 
1209  constructor(AbstractDatasource nds, string nname, *hash opts);
1210 
1211 
1212  private bool checkExistenceImpl();
1213 
1214 
1215  private setTableInfoIntern();
1216 
1217 
1219  string getSqlName();
1220 
1221 
1222  private hash setSchemaTable();
1223 
1224 
1225  private setDblinkSchema();
1226 
1227 
1228  private hash setTable();
1229 
1230 
1231  private string getUserSchema();
1232 
1233 
1234  private string getDBString();
1235 
1236 
1238  string getSchemaName();
1239 
1240 
1242  *string getTablespaceName();
1243 
1244 
1246  *string getComment();
1247 
1248 
1249  bool readOnly();
1250 
1251 
1252  private hash getColumnOptions();
1253 
1254 
1255  private hash getColumnDescOptions();
1256 
1257 
1259  private hash getSelectOptions();
1260 
1261 
1262  private getSelectWhereSqlUnlocked(reference sql, reference args, *hash qh, *hash jch, bool join = False, *hash ch);
1263 
1264 
1265  private doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch);
1266 
1267 
1269  private doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh);
1270 
1271 
1272  private Columns describeImpl();
1273 
1274 
1275  private OraclePrimaryKey getPrimaryKeyImpl();
1276 
1277 
1278  private Indexes getIndexesImpl();
1279 
1280 
1281  private ForeignConstraints getForeignConstraintsImpl(*hash opts);
1282 
1283 
1284  private Constraints getConstraintsImpl();
1285 
1286 
1287  private string getSelectSqlName(*hash qh);
1288 
1289 
1290  private Triggers getTriggersImpl();
1291 
1292 
1293  string getCreateTableSqlImpl(*hash opt);
1294 
1295 
1296  private *list getCreateMiscSqlImpl(*hash opt, bool cache);
1297 
1298 
1299  private string getCreateSqlImpl(list l);
1300 
1301 
1302  private string getRenameSqlImpl(string new_name);
1303 
1304 
1305  private AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
1306 
1307 
1308  private AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
1309 
1310 
1311  private AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
1312 
1313 
1314  private AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
1315 
1316 
1317  private AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
1318 
1319 
1320  private AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
1321 
1322 
1323  private AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
1324 
1325 
1326  private bool tryInsertImpl(string sql, hash row);
1327 
1328 
1329  private *list getAlignSqlImpl(AbstractTable t, *hash opt);
1330 
1331 
1332  private hash getQoreTypeMapImpl();
1333 
1334 
1335  private hash getTypeMapImpl();
1336 
1337 
1338  private hash getIndexOptions();
1339 
1340 
1341  private hash getConstraintOptions();
1342 
1343 
1344  private hash getTableCreationOptions();
1345 
1346 
1347  private hash getAlignTableOptions();
1348 
1349 
1351  private hash getWhereOperatorMap();
1352 
1353 
1355  private hash getColumnOperatorMap();
1356 
1357 
1359  private *string getSqlValueImpl(any v);
1360 
1361 
1362  private bool emptyImpl();
1363 
1364 
1365  private setupTableImpl(hash desc, *hash opt);
1366 
1367 
1369  private bool constraintsLinkedToIndexesImpl();
1370 
1371 
1373  private bool uniqueIndexCreatesConstraintImpl();
1374 
1375 
1377  private bool supportsTablespacesImpl();
1378 
1379 
1381  private copyImpl(AbstractTable old);
1382 
1383  };
1384 };
represents an Oracle unique constraint
Definition: OracleSqlUtil.qm.dox.h:447
private hash getSelectOptions()
override in subclasses to return driver-specific options
const Date
represents an Oracle materialized view
Definition: OracleSqlUtil.qm.dox.h:735
date date(date dt)
const Hash
const OracleCreationOptions
oracle-specific generic creation options
Definition: OracleSqlUtil.qm.dox.h:772
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
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:369
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:740
*string view_type_owner
Owner of the type of the view if the view is a typed view.
Definition: OracleSqlUtil.qm.dox.h:594
represents an Oracle table
Definition: OracleSqlUtil.qm.dox.h:977
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:744
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:812
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
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:598
bool enabled
True if the trigger is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:627
const True
const SZ_MAND
const CHAR
const OracleIndexOptions
Oracle-specific index options.
Definition: OracleSqlUtil.qm.dox.h:1104
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:396
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:424
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:696
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:1134
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:1117
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:455
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:452
represents an Oracle view
Definition: OracleSqlUtil.qm.dox.h:584
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
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
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:592
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:1098
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:742
const COP_YEAR_MONTH
private hash getWhereOperatorMap()
returns the &quot;where&quot; 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:767
string type(any arg)
int byte_size
byte size of the column
Definition: OracleSqlUtil.qm.dox.h:294
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:806
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:982
string string(softstring str)
const OracleAlignSchemaOptions
oracle-specific schema description / alignment options
Definition: OracleSqlUtil.qm.dox.h:777
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:1112
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
string getSchemaName()
returns the schema name
represents an Oracle check constraint
Definition: OracleSqlUtil.qm.dox.h:419
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:350
clearIndex()
clears any index base for the constraint
represents an Oracle package
Definition: OracleSqlUtil.qm.dox.h:708
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:287
*string type_text
Type clause of the typed view.
Definition: OracleSqlUtil.qm.dox.h:590
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:1152
private hash getColumnOperatorMap()
returns the column operator map for this object
const OracleSelectOptions
Oracle select options.
Definition: OracleSqlUtil.qm.dox.h:1129
const QoreTypeMap
maps qore type names to an oracle type
Definition: OracleSqlUtil.qm.dox.h:1072
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
*string body_src
package body source
Definition: OracleSqlUtil.qm.dox.h:713
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:509
*string view_type
Type of the view if the view is a typed view.
Definition: OracleSqlUtil.qm.dox.h:596
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:567
represents an Oracle trigger
Definition: OracleSqlUtil.qm.dox.h:622
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:600
const OracleSchemaDescriptionOptions
oracle-specific schema description keys
Definition: OracleSqlUtil.qm.dox.h:791
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:1092
represents an Oracle foreign constraint
Definition: OracleSqlUtil.qm.dox.h:391
represents an Oracle type
Definition: OracleSqlUtil.qm.dox.h:676
represents an Oracle primary key
Definition: OracleSqlUtil.qm.dox.h:504
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 &quot;limit&quot; argument, but no &quot;orderby&quot; or &quot;offset&quot; arguments
string native_type
the native type of the index (if supported)
Definition: OracleSqlUtil.qm.dox.h:366
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:361
const DefaultOpMap
bool char_used
the column uses character semantics
Definition: OracleSqlUtil.qm.dox.h:292
represents an Oracle function
Definition: OracleSqlUtil.qm.dox.h:684
the base class for Oracle code objects
Definition: OracleSqlUtil.qm.dox.h:651
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database ...