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 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));
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", (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 v10 OracleSqlUtil v1.0
271  - initial release
272 */
273 
275 namespace OracleSqlUtil {
277  OracleTable get_table(AbstractDatasource nds, string nname, *hash opts);
278 
279 
281  OracleDatabase get_database(AbstractDatasource nds, *hash opts);
282 
283 
286 
287 public:
288  public :
290  bool char_used;
293 
294 public:
295 
296  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, bool is_char = False, bool cu = False, int bs);
297 
298 
300  string getNativeTypeString();
301 
302 
304 
311  list getCreateSql(AbstractTable t);
312 
313 
315 
325  list getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt);
326 
327 
329 
339  string getRenameSql(AbstractTable t, string new_name);
340 
341 
343  bool equalImpl(AbstractColumn c);
344 
345  };
346 
349 
350 public:
351  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, int bs, int n_scale = 0);
352 
353 
354  string getNativeTypeString();
355 
356  };
357 
360 
361 public:
362  public :
364  string native_type;
365 
367  *string tablespace;
368 
369 public:
370 
372  constructor(string n, bool u, hash c, string nt, *string t);
373 
374 
376  string getCreateSql(string table_name, *hash opt);
377 
378 
380  bool equalImpl(AbstractIndex ix);
381 
382 
384  string getRenameSql(string table_name, string new_name);
385 
386  };
387 
390 
391 public:
392  public :
394  bool enabled;
395 
396 public:
397 
398  constructor(string n, Columns c, ForeignConstraintTarget t, bool e);
399 
400 
401  string getCreateSql(string table_name, *hash opt);
402 
403 
404  softlist getRenameSql(string table_name, string new_name);
405 
406 
408  string getDisableSql(string table_name);
409 
410 
412  string getEnableSql(string table_name, *hash opt);
413 
414  };
415 
418 
419 public:
420  public :
422  bool enabled;
423 
424 public:
425 
426  constructor(string n, string n_src, bool e = True);
427 
428 
429  string getCreateSql(string table_name, *hash opt);
430 
431 
432  softlist getRenameSql(string table_name, string new_name);
433 
434 
436  string getDisableSql(string table_name);
437 
438 
440  string getEnableSql(string table_name, *hash opt);
441 
442  };
443 
446 
447 public:
448  private :
450  bool enabled;
451 
453  *string tablespace;
454 
455 public:
456 
457  constructor(string n, hash n_cols, bool e = True, *string ts);
458 
459 
461 
476  OracleColumn memberGate(string k);
477 
478 
479  bool setIndexBase(string ix);
480 
481 
483  clearIndex();
484 
485 
486  string getCreateSql(string table_name, *hash opts);
487 
488 
489  softlist getRenameSql(string table_name, string new_name);
490 
491 
493  string getDisableSql(string table_name);
494 
495 
497  string getEnableSql(string table_name, *hash opt);
498 
499  };
500 
503 
504 public:
505  private :
507  *string tablespace;
508 
509 public:
510 
511  constructor();
512 
513 
514  constructor(string n, *hash c, *string ts);
515 
516 
518 
533  OracleColumn memberGate(string k);
534 
535 
536  bool setIndexBase(string ix);
537 
538 
540  clearIndex();
541 
542 
543  string getCreateSql(string table_name, *hash opts);
544 
545 
546  softlist getRenameSql(string table_name, string new_name);
547 
548 
550 
552  string getDropSql(string table_name);
553 
554 
556  string getDisableSql(string table_name);
557 
558 
560  string getEnableSql(string table_name, *hash opt);
561 
562  };
563 
566 
567 public:
569  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_end);
570 
571 
573  string getCreateSql(*hash opt);
574 
575 
577  string getRenameSql(string new_name);
578 
579  };
580 
583 
584 public:
585  public :
587  bool enabled;
588 
589 public:
590 
591  constructor(string n, string n_src, bool en = True);
592 
593 
594  softlist getCreateSql(string table_name, *hash opt);
595 
596 
598  bool equalImpl(AbstractFunctionBase t);
599 
600 
602  softlist getRenameSql(string table_name, string new_name);
603 
604 
606  softlist getDropSql(string table_name);
607 
608  };
609 
612 
613 public:
615 
619  constructor(string n, string n_type, string n_src);
620 
621 
623  softlist getCreateSql(*hash opt);
624 
625 
627  bool equalImpl(AbstractFunctionBase t);
628 
629 
631  list getRenameSql(string new_name);
632 
633  };
634 
636 class OracleType : public OracleCodeBase {
637 
638 public:
639  constructor(string n_name, string n_src);
640 
641  };
642 
645 
646 public:
648 
651  constructor(string n, string n_src);
652 
653  };
654 
657 
658 public:
660 
663  constructor(string n, string n_src);
664 
665  };
666 
669 
670 public:
671  private :
673  *string body_src;
674 
675 public:
676 
678 
682  constructor(string n, string n_src, *string n_body_src);
683 
684 
686  list getCreateSql(*hash opt);
687 
688 
690  bool equalImpl(AbstractFunctionBase t);
691 
692  };
693 
696 
697 public:
698  public :
700  bool logging;
702  bool use_index;
704  *string tablespace;
705 
706 public:
707 
709 
715  constructor(string n, string n_src, bool n_logging = True, bool n_use_index = True, *string n_tablespace);
716 
717 
719  softlist getCreateSql(*hash opt);
720 
721 
722  bool equalImpl(AbstractFunctionBase t);
723 
724  };
725 
728 
729 public:
730  public :
732  const OracleCreationOptions = AbstractDatabase::CreationOptions + (
733  "compute_statistics": Type::Boolean,
734  );
735 
737  const OracleAlignSchemaOptions = AbstractDatabase::CreationOptions
739  + OracleTable::OracleAlignTableOptions
740  ;
741 
743 
751  const OracleSchemaDescriptionOptions = AbstractDatabase::SchemaDescriptionOptions + (
752  "types": Type::Hash,
753  "type_map": Type::Hash,
754 
755  "packages": Type::Hash,
756  "package_map": Type::Hash,
757 
758  "materialized_views": Type::Hash,
759  "materialized_view_map": Type::Hash,
760 
761  //"synonyms": Type::Hash,
762  //"synonym_map": Type::Hash,
763  );
764 
767  "src": Type::String,
768  "body": Type::String,
769  );
770 
773  "logging": Type::Boolean,
774  "use_index": Type::Boolean,
775  "tablespace": Type::String,
776  "src": Type::String,
777  );
778 
779 public:
780 
781  constructor(AbstractDatasource nds, *hash opts);
782 
783 
784 
785 private:
786  list featuresImpl();
787 public:
788 
789 
790 
791 private:
792  OracleSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
793 public:
794 
795 
796 
797 private:
798  getSchemaName(reference name, reference schema);
799 public:
800 
801 
802 
803 private:
804  *AbstractSequence getSequenceImpl(string name);
805 public:
806 
807 
808 
809 private:
810  OracleFunction makeFunctionImpl(string name, string src, *hash opts);
811 public:
812 
813 
814 
815 private:
816  OracleProcedure makeProcedureImpl(string name, string src, *hash opts);
817 public:
818 
819 
820  OraclePackage makePackage(string name, string src, string body, *hash opts);
821 
822 
823  OraclePackage makePackageFromDescription(string name, hash ph, *hash opts);
824 
825 
826  OracleType makeType(string name, string src, *hash opts);
827 
828 
829  OracleMaterializedView makeMaterializedView(string name, string src, bool logging = True, bool use_index = True, *string tablespace, *hash opts);
830 
831 
832  OracleMaterializedView makeMaterializedViewFromDescription(string name, hash mvh, *hash opts);
833 
834 
835 
836 private:
837  list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
838 public:
839 
840 
841 
842 private:
843  list getAlignSqlImpl(hash schema_hash, *hash opt);
844 public:
845 
846 
847 
848 private:
849  *OracleFunction getFunctionImpl(string name);
850 public:
851 
852 
853 
854 private:
855  *OracleProcedure getProcedureImpl(string name);
856 public:
857 
858 
859  *OraclePackage getPackage(string name);
860 
861 
862  *OracleType getType(string name);
863 
864 
865  *OracleMaterializedView getMaterializedView(string name);
866 
867 
868 
869 private:
870  *string getSource(string type, string name);
871 public:
872 
873 
874 
875 private:
876  checkSource(string type, string name, reference src);
877 public:
878 
879 
881  list listSynonyms();
882 
883 
885  ListIterator synonymIterator();
886 
887 
889  list listTypes();
890 
891 
893  ListIterator typeIterator();
894 
895 
897  list listPackages();
898 
899 
901  ListIterator packageIterator();
902 
903 
906 
907 
909  ListIterator materializedViewIterator();
910 
911 
912 
913 private:
914  list listTablesImpl();
915 public:
916 
917 
918 
919 private:
920  list listFunctionsImpl();
921 public:
922 
923 
924 
925 private:
926  list listProceduresImpl();
927 public:
928 
929 
930 
931 private:
932  list listSequencesImpl();
933 public:
934 
935 
936 
937 private:
938  list listViewsImpl();
939 public:
940 
941 
942 
943 private:
944  list getListIntern(string type);
945 public:
946 
947 
948 
949 private:
950  list getListIntern(list l);
951 public:
952 
953 
954 
955 private:
956  string getCreateSqlImpl(list l);
957 public:
958 
959 
960  static string getCreateSql(list l);
961 
963 
964 private:
965  hash getCreationOptions();
966 public:
967 
968 
970 
971 private:
972  hash getAlignSchemaOptions();
973 public:
974 
975 
977 
978 private:
980 public:
981 
982 
984 
985 private:
986  softint getNextSequenceValueImpl(string name);
987 public:
988 
989 
991 
992 private:
993  bool supportsSequencesImpl();
994 public:
995 
996 
998 
999 private:
1000  bool supportsTypesImpl();
1001 public:
1002 
1003 
1005 
1006 private:
1007  bool supportsPackagesImpl();
1008 public:
1009 
1010  };
1011 
1013 
1016 
1017 public:
1018  public :
1020  const OraTypeMap = (
1021  "number": ("qore": Type::Number, "size": SZ_NUM, "size_range": (1, 38), "scale_range": (-84, 127)),
1022  "varchar2": ("qore": Type::String, "size": SZ_MAND, "size_range": (1, 4000), "is_char": True),
1023  "char": ("qore": Type::String, "size": SZ_MAND, "size_range": (1, 4000), "is_char": True),
1024  "date": ("qore": Type::Date,),
1025  "timestamp": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
1026  "timestamp with time zone": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
1027  "timestamp with local time zone": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 9)),
1028  "timestamp(0)": ("qore": Type::Date,),
1029  "timestamp(1)": ("qore": Type::Date,),
1030  "timestamp(2)": ("qore": Type::Date,),
1031  "timestamp(3)": ("qore": Type::Date,),
1032  "timestamp(4)": ("qore": Type::Date,),
1033  "timestamp(5)": ("qore": Type::Date,),
1034  "timestamp(6)": ("qore": Type::Date,),
1035  "timestamp(7)": ("qore": Type::Date,),
1036  "timestamp(8)": ("qore": Type::Date,),
1037  "timestamp(9)": ("qore": Type::Date,),
1038  "timestamp(0) with time zone": ("qore": Type::Date,),
1039  "timestamp(1) with time zone": ("qore": Type::Date,),
1040  "timestamp(2) with time zone": ("qore": Type::Date,),
1041  "timestamp(3) with time zone": ("qore": Type::Date,),
1042  "timestamp(4) with time zone": ("qore": Type::Date,),
1043  "timestamp(5) with time zone": ("qore": Type::Date,),
1044  "timestamp(6) with time zone": ("qore": Type::Date,),
1045  "timestamp(7) with time zone": ("qore": Type::Date,),
1046  "timestamp(8) with time zone": ("qore": Type::Date,),
1047  "timestamp(9) with time zone": ("qore": Type::Date,),
1048  "timestamp(0) with local time zone": ("qore": Type::Date,),
1049  "timestamp(1) with local time zone": ("qore": Type::Date,),
1050  "timestamp(2) with local time zone": ("qore": Type::Date,),
1051  "timestamp(3) with local time zone": ("qore": Type::Date,),
1052  "timestamp(4) with local time zone": ("qore": Type::Date,),
1053  "timestamp(5) with local time zone": ("qore": Type::Date,),
1054  "timestamp(6) with local time zone": ("qore": Type::Date,),
1055  "timestamp(7) with local time zone": ("qore": Type::Date,),
1056  "timestamp(8) with local time zone": ("qore": Type::Date,),
1057  "timestamp(9) with local time zone": ("qore": Type::Date,),
1058  "interval year(0) to month": ("qore": Type::Date,),
1059  "interval year(1) to month": ("qore": Type::Date,),
1060  "interval year(2) to month": ("qore": Type::Date,),
1061  "interval year(3) to month": ("qore": Type::Date,),
1062  "interval year(4) to month": ("qore": Type::Date,),
1063  "interval year(5) to month": ("qore": Type::Date,),
1064  "interval year(6) to month": ("qore": Type::Date,),
1065  "interval year(7) to month": ("qore": Type::Date,),
1066  "interval year(8) to month": ("qore": Type::Date,),
1067  "interval year(9) to month": ("qore": Type::Date,),
1068  "interval day(0) to second(0)": ("qore": Type::Date,),
1069  "interval day(0) to second(1)": ("qore": Type::Date,),
1070  "interval day(0) to second(2)": ("qore": Type::Date,),
1071  "interval day(0) to second(3)": ("qore": Type::Date,),
1072  "interval day(0) to second(4)": ("qore": Type::Date,),
1073  "interval day(0) to second(5)": ("qore": Type::Date,),
1074  "interval day(0) to second(6)": ("qore": Type::Date,),
1075  "interval day(0) to second(7)": ("qore": Type::Date,),
1076  "interval day(0) to second(8)": ("qore": Type::Date,),
1077  "interval day(0) to second(9)": ("qore": Type::Date,),
1078  "interval day(1) to second(0)": ("qore": Type::Date,),
1079  "interval day(1) to second(1)": ("qore": Type::Date,),
1080  "interval day(1) to second(2)": ("qore": Type::Date,),
1081  "interval day(1) to second(3)": ("qore": Type::Date,),
1082  "interval day(1) to second(4)": ("qore": Type::Date,),
1083  "interval day(1) to second(5)": ("qore": Type::Date,),
1084  "interval day(1) to second(6)": ("qore": Type::Date,),
1085  "interval day(1) to second(7)": ("qore": Type::Date,),
1086  "interval day(1) to second(8)": ("qore": Type::Date,),
1087  "interval day(1) to second(9)": ("qore": Type::Date,),
1088  "interval day(2) to second(0)": ("qore": Type::Date,),
1089  "interval day(2) to second(1)": ("qore": Type::Date,),
1090  "interval day(2) to second(2)": ("qore": Type::Date,),
1091  "interval day(2) to second(3)": ("qore": Type::Date,),
1092  "interval day(2) to second(4)": ("qore": Type::Date,),
1093  "interval day(2) to second(5)": ("qore": Type::Date,),
1094  "interval day(2) to second(6)": ("qore": Type::Date,),
1095  "interval day(2) to second(7)": ("qore": Type::Date,),
1096  "interval day(2) to second(8)": ("qore": Type::Date,),
1097  "interval day(2) to second(9)": ("qore": Type::Date,),
1098  "clob": ("qore": Type::String,),
1099  "blob": ("qore": Type::Binary,),
1100  "long": ("qore": Type::Binary,),
1101  "raw": ("qore": Type::Binary, "size": SZ_MAND, "size_range": (1, 2000)),
1102  "bfile": ("qore": Type::Binary,),
1103  "binary_float": ("qore": Type::Float,),
1104  "binary_double": ("qore": Type::Float,),
1105  "rowid": ("qore": Type::String,),
1106  "urowid": ("qore": Type::String, "size": SZ_OPT, "size_range": (1, 4000)),
1107  );
1108 
1110  const QoreTypeMap = (
1111  "integer": "number",
1112  "float": "number",
1113  "number": "number",
1114  "string": "varchar2",
1115  "date": "timestamp(6)",
1116  "binary": "blob",
1117  SqlUtil::CHAR: "char",
1118  SqlUtil::CLOB: "clob",
1119  SqlUtil::BLOB: "blob",
1120  );
1121 
1122  const OraColumnOpts = (
1123  "character_semantics": Type::Boolean,
1124  );
1125 
1127 
1130  const OraColumnOptions = AbstractTable::ColumnOptions + OraColumnOpts;
1131 
1133 
1136  const OraColumnDescOptions = AbstractTable::ColumnDescOptions + OraColumnOpts;
1137 
1139 
1142  const OracleIndexOptions = AbstractTable::IndexOptions + (
1143  "compute_statistics": Type::Boolean,
1144  );
1145 
1147 
1151  "index": Type::String,
1152  );
1153 
1155  const OracleTableCreationOptions = AbstractTable::TableCreationOptions
1158  ;
1159 
1160  const OracleAlignTableOptions = AbstractTable::AlignTableOptions + OracleTableCreationOptions;
1161 
1163 
1167  const OracleSelectOptions = AbstractTable::SelectOptions + (
1168  "partition": Type::String,
1169  );
1170 
1173  OP_IN: (
1174  "code": string (object t, string cn, any arg, reference args) {
1175  *string argstr = (foldl $1 + "," + $2, (map $1.toString(), arg));
1176 
1177  // in this case this part of the expression will fail
1178  if (!argstr)
1179  return "1 != 1";
1180 
1181  args += argstr;
1182  args += argstr;
1183 
1184  return cn + " in (select regexp_substr(%v,'[^,]+', 1, level) from dual connect by regexp_substr(%v, '[^,]+', 1, level) is not null)";
1185 
1186 public:
1187  ),
1188  );
1189 
1192  COP_OVER: (
1193  "argcolumn": True,
1194  "argoptional": True,
1195  "code": string (*string cve, *string arg) {
1196  string sql = cve + " over (";
1197  if (arg)
1198  sql += sprintf("partition by %s", arg);
1199  sql += ")";
1200  return sql;
1201  },
1202  ),
1203  COP_YEAR: (
1204  "code": string (string arg1, any arg) {
1205  return sprintf("to_char(%s, 'YYYY')", arg1);
1206  }
1207  ),
1208  COP_YEAR_MONTH: (
1209  "code": string (string arg1, any arg) {
1210  return sprintf("to_char(%s, 'YYYY-MM')", arg1);
1211  }
1212  ),
1213  COP_YEAR_DAY: (
1214  "code": string (string arg1, any arg) {
1215  return sprintf("to_char(%s, 'YYYY-MM-DD')", arg1);
1216  }
1217  ),
1218  COP_YEAR_HOUR: (
1219  "code": string (string arg1, any arg) {
1220  return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", arg1);
1221  }
1222  ),
1223  );
1224  }
1225 
1226  private :
1227  // schema name
1228  string schema;
1229 
1230  // tablespace name
1231  *string tablespace;
1232 
1233  // is the table read only?
1234  bool readonly;
1235 
1236  // table comment
1237  *string comment;
1238 
1239  // dblink
1240  *string dblink;
1241 
1242  // Oracle server major version
1243  int ora_major;
1244 
1245 public:
1246 
1247  constructor(AbstractDatasource nds, string nname, *hash opts);
1248 
1249 
1250 
1251 private:
1252  bool checkExistenceImpl();
1253 public:
1254 
1255 
1256 
1257 private:
1258  setTableInfoIntern();
1259 public:
1260 
1261 
1263  string getSqlName();
1264 
1265 
1266 
1267 private:
1268  hash setSchemaTable();
1269 public:
1270 
1271 
1272 
1273 private:
1274  setDblinkSchema();
1275 public:
1276 
1277 
1278 
1279 private:
1280  hash setTable();
1281 public:
1282 
1283 
1284 
1285 private:
1286  string getUserSchema();
1287 public:
1288 
1289 
1290 
1291 private:
1292  string getDBString();
1293 public:
1294 
1295 
1297  string getSchemaName();
1298 
1299 
1301  *string getTablespaceName();
1302 
1303 
1305  *string getComment();
1306 
1307 
1308  bool readOnly();
1309 
1310 
1311 
1312 private:
1313  hash getColumnOptions();
1314 public:
1315 
1316 
1317 
1318 private:
1319  hash getColumnDescOptions();
1320 public:
1321 
1322 
1324 
1325 private:
1326  hash getSelectOptions();
1327 public:
1328 
1329 
1330 
1331 private:
1332  getSelectWhereSqlUnlocked(reference sql, reference args, *hash qh, *hash jch, bool join = False, *hash ch);
1333 public:
1334 
1335 
1336 
1337 private:
1338  doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch);
1339 public:
1340 
1341 
1343 
1344 private:
1345  doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh);
1346 public:
1347 
1348 
1349 
1350 private:
1351  Columns describeImpl();
1352 public:
1353 
1354 
1355 
1356 private:
1357  OraclePrimaryKey getPrimaryKeyImpl();
1358 public:
1359 
1360 
1361 
1362 private:
1363  Indexes getIndexesImpl();
1364 public:
1365 
1366 
1367 
1368 private:
1369  ForeignConstraints getForeignConstraintsImpl(*hash opts);
1370 public:
1371 
1372 
1373 
1374 private:
1375  Constraints getConstraintsImpl();
1376 public:
1377 
1378 
1379 
1380 private:
1381  string getSelectSqlName(*hash qh);
1382 public:
1383 
1384 
1385 
1386 private:
1387  Triggers getTriggersImpl();
1388 public:
1389 
1390 
1391  string getCreateTableSqlImpl(*hash opt);
1392 
1393 
1394 
1395 private:
1396  *list getCreateMiscSqlImpl(*hash opt, bool cache);
1397 public:
1398 
1399 
1400 
1401 private:
1402  string getCreateSqlImpl(list l);
1403 public:
1404 
1405 
1406 
1407 private:
1408  string getRenameSqlImpl(string new_name);
1409 public:
1410 
1411 
1412 
1413 private:
1414  AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
1415 public:
1416 
1417 
1418 
1419 private:
1420  AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
1421 public:
1422 
1423 
1424 
1425 private:
1426  AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
1427 public:
1428 
1429 
1430 
1431 private:
1432  AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
1433 public:
1434 
1435 
1436 
1437 private:
1438  AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
1439 public:
1440 
1441 
1442 
1443 private:
1444  AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
1445 public:
1446 
1447 
1448 
1449 private:
1450  AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
1451 public:
1452 
1453 
1454 
1455 private:
1456  bool tryInsertImpl(string sql, hash row);
1457 public:
1458 
1459 
1460 
1461 private:
1462  *list getAlignSqlImpl(AbstractTable t, *hash opt);
1463 public:
1464 
1465 
1466 
1467 private:
1468  hash getQoreTypeMapImpl();
1469 public:
1470 
1471 
1472 
1473 private:
1474  hash getTypeMapImpl();
1475 public:
1476 
1477 
1478 
1479 private:
1480  hash getIndexOptions();
1481 public:
1482 
1483 
1484 
1485 private:
1486  hash getConstraintOptions();
1487 public:
1488 
1489 
1490 
1491 private:
1492  hash getTableCreationOptions();
1493 public:
1494 
1495 
1496 
1497 private:
1498  hash getAlignTableOptions();
1499 public:
1500 
1501 
1503 
1504 private:
1505  hash getWhereOperatorMap();
1506 public:
1507 
1508 
1510 
1511 private:
1512  hash getColumnOperatorMap();
1513 public:
1514 
1515 
1517 
1518 private:
1519  *string getSqlValueImpl(any v);
1520 public:
1521 
1522 
1523 
1524 private:
1525  bool emptyImpl();
1526 public:
1527 
1528 
1529 
1530 private:
1531  setupTableImpl(hash desc, *hash opt);
1532 public:
1533 
1534 
1536 
1537 private:
1539 public:
1540 
1541 
1543 
1544 private:
1546 public:
1547 
1548 
1550 
1551 private:
1552  bool supportsTablespacesImpl();
1553 public:
1554 
1555 
1557 
1558 private:
1559  copyImpl(AbstractTable old);
1560 public:
1561 
1562  };
1563 };
represents an Oracle unique constraint
Definition: OracleSqlUtil.qm.dox.h:445
const Date
represents an Oracle materialized view
Definition: OracleSqlUtil.qm.dox.h:695
bool supportsPackagesImpl()
returns True if the database supports packages
date date(date dt)
const Hash
const OracleCreationOptions
oracle-specific generic creation options
Definition: OracleSqlUtil.qm.dox.h:732
list listSynonyms()
returns a list of string synonym names in the database
const String
string sprintf(string fmt,...)
const OP_IN
bool supportsSequencesImpl()
returns True if the database supports sequences
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
hash getSchemaDescriptionOptions()
returns driver-specific options to the base abstract class
const DefaultCopMap
ListIterator packageIterator()
returns an iterator listing the string package names in the database
const VARCHAR
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
hash getCreationOptions()
returns driver-specific options to the base abstract class
*string tablespace
the tablespace name of the index (if supported)
Definition: OracleSqlUtil.qm.dox.h:367
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:700
represents an Oracle table
Definition: OracleSqlUtil.qm.dox.h:1015
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:704
const COP_OVER
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
const OracleMaterializedViewDescriptionOptions
oracle-specific materialized view description options
Definition: OracleSqlUtil.qm.dox.h:772
ListIterator materializedViewIterator()
returns an iterator listing the string materialized view names in the database
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
copyImpl(AbstractTable old)
db-specific copy actions
bool enabled
True if the trigger is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:587
const True
const SZ_MAND
const CHAR
const OracleIndexOptions
Oracle-specific index options.
Definition: OracleSqlUtil.qm.dox.h:1142
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:394
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:422
represents an Oracle procedure
Definition: OracleSqlUtil.qm.dox.h:656
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:1172
binary binary()
constructor(string n, string n_src)
creates the object from the arguments passed
const OracleTableCreationOptions
Oracle table creation options.
Definition: OracleSqlUtil.qm.dox.h:1155
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:453
bool enabled
True if the constraint is enabled, False if not
Definition: OracleSqlUtil.qm.dox.h:450
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(...)
bool supportsTypesImpl()
returns True if the database supports named types
const Float
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
ListIterator typeIterator()
returns an iterator listing the string type names in the database
string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
bool exists(...)
bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
hash getColumnOperatorMap()
returns the column operator map for this object
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:1136
bool use_index
Flag if is index used.
Definition: OracleSqlUtil.qm.dox.h:702
const COP_YEAR_MONTH
hash getSelectOptions()
override in subclasses to return driver-specific options
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:727
string type(any arg)
int byte_size
byte size of the column
Definition: OracleSqlUtil.qm.dox.h:292
const CLOB
hash getWhereOperatorMap()
returns the &quot;where&quot; operator map for this object
bool supportsTablespacesImpl()
returns True if the database support tablespaces
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:766
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:1020
string string(softstring str)
const OracleAlignSchemaOptions
oracle-specific schema description / alignment options
Definition: OracleSqlUtil.qm.dox.h:737
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:1150
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:417
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:348
clearIndex()
clears any index base for the constraint
represents an Oracle package
Definition: OracleSqlUtil.qm.dox.h:668
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:285
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:1191
softint getNextSequenceValueImpl(string name)
returns the next value in the given sequence
const OracleSelectOptions
Oracle select options.
Definition: OracleSqlUtil.qm.dox.h:1167
const QoreTypeMap
maps qore type names to an oracle type
Definition: OracleSqlUtil.qm.dox.h:1110
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
*string body_src
package body source
Definition: OracleSqlUtil.qm.dox.h:673
constructor(string n, string n_src)
creates the object from the arguments passed
const COP_YEAR_DAY
*string tablespace
any tablespace for the primary key index
Definition: OracleSqlUtil.qm.dox.h:507
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database
list listPackages()
returns a list of string package names in the database
const Object
represents an Oracle sequence
Definition: OracleSqlUtil.qm.dox.h:565
represents an Oracle trigger
Definition: OracleSqlUtil.qm.dox.h:582
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)
const OracleSchemaDescriptionOptions
oracle-specific schema description keys
Definition: OracleSqlUtil.qm.dox.h:751
*string getSqlValueImpl(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
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:1130
represents an Oracle foreign constraint
Definition: OracleSqlUtil.qm.dox.h:389
represents an Oracle type
Definition: OracleSqlUtil.qm.dox.h:636
represents an Oracle primary key
Definition: OracleSqlUtil.qm.dox.h:502
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 ...
string native_type
the native type of the index (if supported)
Definition: OracleSqlUtil.qm.dox.h:364
string join(string str,...)
const NUMERIC
const Number
represents an Oracle index
Definition: OracleSqlUtil.qm.dox.h:359
hash getAlignSchemaOptions()
returns driver-specific options to the base abstract class
const DefaultOpMap
bool char_used
the column uses character semantics
Definition: OracleSqlUtil.qm.dox.h:290
represents an Oracle function
Definition: OracleSqlUtil.qm.dox.h:644
the base class for Oracle code objects
Definition: OracleSqlUtil.qm.dox.h:611
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database ...