Qore SqlUtil Module Reference  1.6
AbstractDatabase.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
25 // minimum required Qore version
26 // assume local scope for variables, do not use "$" signs
27 // require type definitions everywhere
29 // enable all warnings
30 
32 namespace SqlUtil {
35 
36 public:
38 
41  const DatabaseOptions = (
42  "native_case": Type::Boolean,
43  );
44 
46 
49  const CacheOptions = (
50  "table_cache": "Tables",
51  );
52 
54 
59  const CallbackOptions = (
60  "info_callback": "code",
61  "sql_callback": "code",
62  "sql_callback_executed": Type::Boolean,
63  );
64 
73  const AC_Unchanged = 0;
75 
77  const AC_Create = 1;
78 
80  const AC_Drop = 2;
81 
83  const AC_Rename = 3;
84 
86  const AC_Modify = 4;
87 
89  const AC_Truncate = 5;
90 
92  const AC_Add = 6;
93 
95  const AC_Recreate = 7;
96 
98  const AC_Insert = 8;
99 
101  const AC_Update = 9;
102 
104  const AC_Delete = 10;
105 
107  const AC_NotFound = 11;
109 
111  const ActionMap = (
112  AC_Unchanged: "unchanged",
113  AC_Create: "create",
114  AC_Drop: "drop",
115  AC_Rename: "rename",
116  AC_Modify: "modify",
117  AC_Truncate: "truncate",
118  AC_Add: "add",
119  AC_Recreate: "recreate",
120  AC_Insert: "insert",
121  AC_Update: "update",
122  AC_Delete: "delete",
123  AC_NotFound: "not found",
124  );
125 
127  const ActionDescMap = (
128  "unchanged": AC_Unchanged,
129  "create": AC_Create,
130  "drop": AC_Drop,
131  "rename": AC_Rename,
132  "modify": AC_Modify,
133  "truncate": AC_Truncate,
134  "add": AC_Add,
135  "recreate": AC_Recreate,
136  "insert": AC_Insert,
137  "update": AC_Update,
138  "delete": AC_Delete,
139  "not found": AC_NotFound,
140  );
141 
143  const ActionLetterMap = (
144  AC_Unchanged: ".",
145  AC_Create: "C",
146  AC_Drop: "D",
147  AC_Rename: "N",
148  AC_Modify: "M",
149  AC_Truncate: "T",
150  AC_Add: "A",
151  AC_Recreate: "R",
152  AC_Insert: "I",
153  AC_Update: "U",
154  AC_Delete: "X",
155  AC_NotFound: ".",
156  );
157 
159 
166  "replace": Type::Boolean,
167  "table_cache": "Tables",
168  "data_tablespace": Type::String,
169  "index_tablespace": Type::String,
170  );
171 
173 
177  "force": Type::Boolean,
178  );
179 
181 
185  "force": Type::Boolean,
186  );
187 
189 
202  "tables": Type::Hash,
203  "table_map": Type::Hash,
204 
205  "sequences": Type::Hash,
206  "sequence_map": Type::Hash,
207 
208  "functions": Type::Hash,
209  "function_map": Type::Hash,
210 
211  "procedures": Type::Hash,
212  "procedure_map": Type::Hash,
213 
214  //"views": Type::Hash,
215  //"view_map": Type::Hash,
216  );
217 
219 
225  "start": Type::Int,
226  "increment": Type::Int,
227  "end": Type::Int,
228  );
229 
232  "tables" : "softstringlist",
233  );
234 
237  "tables" : "softstringlist",
238  );
239 
240 protected:
243 
244  // AbstractDatabase::getPhysicalSize() return in a case of no data
245  const GET_PHYSICAL_DB_SIZE_NOVAL = -1;
246 
247 public:
248 
250 
255 protected:
256  constructor(AbstractDatasource nds, *hash nopts) ;
257 public:
258 
259 
261  list features();
262 
263 
264  static doOkCallback(*hash<auto> opt, int ac, string type, string name, *string table, *string info);
265 
266 protected:
267  static runInfoCallback(code info_callback, int ac, string type, string name, *string table, *string new_name, *string info);
268 public:
269 
270 
271  static *string doCallback(*hash<auto> opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
272 
273  static list doCallback(*hash<auto> opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
274 
276 
287  auto tryExec(string sql);
288 
289 
291 
301  auto tryExecArgs(string sql, *softlist<auto> args);
302 
303 
305 
316  auto tryExecRaw(string sql);
317 
318 
320 
334  list<auto> getAlignSql(hash schema_hash, *hash<auto> opt, *Tables table_cache);
335 
336 
338 
351  list<auto> getDropSchemaSql(hash schema_hash, *hash<auto> opt);
352 
353 
354 protected:
355  list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash<auto> opt, string make_arg_type);
356 public:
357 
358 
359 protected:
360  list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash<auto> opt, string make_arg_type);
361 public:
362 
363 
365 
379  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash<auto> opts);
380 
381 
382  AbstractSequence makeSequenceFromDescription(string name, *hash<auto> sh, *hash<auto> opts);
383 
384 
386 
399  AbstractTable makeTable(string name, hash<auto> desc, *hash<auto> opts);
400 
401 
403 
414  AbstractFunction makeFunction(string name, string src, *hash<auto> opts);
415 
416 
418 
429  AbstractFunction makeProcedure(string name, string src, *hash<auto> opt);
430 
431 
433 
445  bool dropFunctionIfExists(string name, *hash<auto> opt);
446 
447 
449 
461  bool dropProcedureIfExists(string name, *hash<auto> opt);
462 
463 
465 
477  bool dropSequenceIfExists(string name, *hash<auto> opt);
478 
479 
481 
493  bool dropViewIfExists(string name, *hash<auto> opt);
494 
495 
497 
509  bool dropTableIfExists(string name, *hash<auto> opt);
510 
511 
513 
525  *string getDropFunctionSqlIfExists(string name, *hash<auto> opt);
526 
527 
529 
541  *string getDropProcedureSqlIfExists(string name, *hash<auto> opt);
542 
543 
545 
557  *string getDropSequenceSqlIfExists(string name, *hash<auto> opt);
558 
559 
561 
573  *list<auto> getDropTableSqlIfExists(string name, *hash<auto> opt);
574 
575 
576  doDropSql(*softlist l, string type, string name, *hash<auto> opt);
577 
578 
579  bool doDrop(*softlist l, string type, string name, *hash<auto> opt);
580 
581 
583 
595  list<auto> getAlignFunctionSql(AbstractFunction f, *hash<auto> opt);
596 
597 
599 
611  list<auto> getAlignProcedureSql(AbstractFunction f, *hash<auto> opt);
612 
613 
615 
624  *AbstractTable getTable(string name);
625 
626 
628 
637  *AbstractSequence getSequence(string name);
638 
639 
641 
652  *AbstractFunction getFunction(string name);
653 
654 
656 
667  *AbstractFunction getProcedure(string name);
668 
669 
671 
680  *AbstractView getView(string name);
681 
682 
684 
693  int getNextSequenceValue(string name);
694 
695 
697 
706  int getCurrentSequenceValue(string name);
707 
708 
710 
719  string getSqlFromList(list l);
720 
721 
723  bool supportsSequences();
724 
725 
727  bool supportsTypes();
728 
729 
731  bool supportsPackages();
732 
733 
735  list<string> listTables();
736 
737 
740 
741 
743  list<string> listFunctions();
744 
745 
748 
749 
751  list<string> listProcedures();
752 
753 
756 
757 
759  list<string> listSequences();
760 
761 
764 
765 
767  list<string> listViews();
768 
769 
772 
773 
775 
785  bool rebuildIndex(string name, *hash<auto> options);
786 
787 
789 
797  bool rebuildIndex(AbstractIndex index, *hash<auto> options);
798 
799 
801 
808  computeStatistics(*hash<auto> options);
809 
810 
812 
819  reclaimSpace(*hash<auto> options);
820 
821 
823 
832  int getPhysicalSize();
833 
834 
835 protected:
836  validateOptionsIntern(string err, hash<auto> ropt, reference<hash> opt);
837 public:
838 
839 
840 protected:
841  validateOptionsIntern(string err, hash<auto> ropt, reference<hash> opt, string tag);
842 public:
843 
844 
845  static AbstractDatabase getDatabase(AbstractDatasource nds, *hash<auto> opts);
846 
847  static AbstractDatabase getDatabase(string dsstr, *hash<auto> opts);
848 
849  static AbstractDatabase getDatabase(hash<auto> dsh, *hash<auto> opts);
850 
851  static checkDriverOptions(reference<hash> h, string drv);
852 
854 protected:
855  hash<auto> getDatabaseOptions();
856 public:
857 
858 
860 protected:
861  hash<auto> getCallbackOptions();
862 public:
863 
864 
866 protected:
867  hash<auto> getCreationOptions();
868 public:
869 
870 
872 protected:
873  hash<auto> getCacheOptions();
874 public:
875 
876 
878 protected:
879  hash<auto> getAlignSchemaOptions();
880 public:
881 
882 
884 protected:
885  hash<auto> getDropSchemaOptions();
886 public:
887 
888 
890 protected:
891  hash<auto> getSchemaDescriptionOptions();
892 public:
893 
894 
896 protected:
897  hash<auto> getSequenceDescriptionOptions();
898 public:
899 
900 
902 protected:
903  hash<auto> getRebuildIndexOptions();
904 public:
905 
906 
908 protected:
909  hash<auto> getComputeStatisticsOptions();
910 public:
911 
912 
914 protected:
915  hash<auto> getReclaimSpaceOptions();
916 public:
917 
918 
920 protected:
921  auto tryExecArgsImpl(string sql, *softlist<auto> args);
922 public:
923 
924 
926 protected:
927  auto tryExecRawImpl(string sql);
928 public:
929 
930 
931 protected:
932  abstract string getCreateSqlImpl(list l);
933 public:
934 protected:
935  abstract list<auto> getAlignSqlImpl(hash schema_hash, *hash<auto> opt);
936 public:
937 protected:
938  abstract list<auto> getDropSchemaSqlImpl(hash schema_hash, *hash<auto> opt);
939 public:
940 
941 protected:
942  abstract *AbstractSequence getSequenceImpl(string name);
943 public:
944 protected:
945  abstract *AbstractFunction getFunctionImpl(string name);
946 public:
947 protected:
948  abstract *AbstractFunction getProcedureImpl(string name);
949 public:
950 protected:
951  abstract *AbstractView getViewImpl(string name);
952 public:
953 
954 protected:
955  abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash<auto> opts);
956 public:
957 protected:
958  abstract AbstractFunction makeFunctionImpl(string name, string src, *hash<auto> opts);
959 public:
960 protected:
961  abstract AbstractFunction makeProcedureImpl(string name, string src, *hash<auto> opts);
962 public:
963 
964 protected:
965  abstract list<string> featuresImpl();
966 public:
967 protected:
968  abstract list<string> listTablesImpl();
969 public:
970 protected:
971  abstract list<string> listFunctionsImpl();
972 public:
973 protected:
974  abstract list<string> listProceduresImpl();
975 public:
976 protected:
977  abstract list<string> listSequencesImpl();
978 public:
979 protected:
980  abstract list<string> listViewsImpl();
981 public:
982 
984 protected:
985  abstract int getNextSequenceValueImpl(string name);
986 public:
988 protected:
989  abstract int getCurrentSequenceValueImpl(string name);
990 public:
991 
993 protected:
994  abstract bool supportsSequencesImpl();
995 public:
996 protected:
997  abstract bool supportsPackagesImpl();
998 public:
999 protected:
1000  abstract bool supportsTypesImpl();
1001 public:
1002 
1003 protected:
1004  abstract bool rebuildIndexImpl(string name, *hash<auto> options);
1005 public:
1006 protected:
1007  abstract computeStatisticsImpl(*hash<auto> options);
1008 public:
1009 protected:
1010  abstract reclaimSpaceImpl(*hash<auto> options);
1011 public:
1012 protected:
1013  abstract int getPhysicalSizeImpl();
1014 public:
1015 };
1016 };
const ActionMap
maps from action codes to action descriptions
Definition: AbstractDatabase.qc.dox.h:111
AbstractFunction makeFunction(string name, string src, *hash< auto > opts)
creates a database-specific AbstractFunction object corresponding to the arguments
auto tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost
const Hash
hash< auto > getComputeStatisticsOptions()
override in subclasses to return driver-specific options
const String
hash< auto > getDatabaseOptions()
override in subclasses to return driver-specific options
const AC_Unchanged
used when an existing object matches the template and no changes are made
Definition: AbstractDatabase.qc.dox.h:74
the base abstract class for the table implementation
Definition: AbstractTable.qc.dox.h:36
bool rebuildIndex(string name, *hash< auto > options)
Rebuild an index in the DB.
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:5374
hash< auto > getRebuildIndexOptions()
override in subclasses to return driver-specific options
*hash< auto > opts
option hash
Definition: AbstractSqlUtilBase.qc.dox.h:41
const DropSchemaOptions
default generic drop schema options
Definition: AbstractDatabase.qc.dox.h:184
reclaimSpace(*hash< auto > options)
Reclaim taken but unused space in the DB.
const SchemaDescriptionOptions
default generic schema description keys
Definition: AbstractDatabase.qc.dox.h:201
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view cannot be found
bool dropSequenceIfExists(string name, *hash< auto > opt)
drops the given sequence if it exists; returns True if the sequence was dropped, False if not
const DatabaseOptions
database options
Definition: AbstractDatabase.qc.dox.h:41
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:5817
constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
list< auto > getAlignProcedureSql(AbstractFunction f, *hash< auto > opt)
returns a list of SQL strings that can be used to update a stored procedure in the database to the st...
computeStatistics(*hash< auto > options)
Compute database statistics.
hash< auto > getCallbackOptions()
override in subclasses to return driver-specific options
const AC_Create
used when a new object is created
Definition: AbstractDatabase.qc.dox.h:77
base class for sequences
Definition: SqlUtil.qm.dox.h:6204
*string getDropSequenceSqlIfExists(string name, *hash< auto > opt)
returns the SQL require to drop the given sequence if it exists or NOTHING if the named sequence does...
int getPhysicalSize()
Get the current database physical size in bytes.
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
number number(softnumber n)
list< auto > getAlignFunctionSql(AbstractFunction f, *hash< auto > opt)
returns a list of SQL strings that can be used to update a function in the database to the function d...
auto tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
base class for abstract SqlUtil classes
Definition: AbstractSqlUtilBase.qc.dox.h:34
const CacheOptions
generic cache options
Definition: AbstractDatabase.qc.dox.h:49
const AC_Modify
used when an object is modified in place
Definition: AbstractDatabase.qc.dox.h:86
AbstractSequence makeSequence(string name, number start=1, number increment=1, *softnumber end, *hash< auto > opts)
creates a database-specific AbstractSequence object corresponding to the arguments
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
const False
const AC_Drop
used when an object is dropped
Definition: AbstractDatabase.qc.dox.h:80
Qore AbstractDatabase class definition.
Definition: AbstractDatabase.qc.dox.h:32
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
const ActionLetterMap
maps from action codes to action letter codes
Definition: AbstractDatabase.qc.dox.h:143
hash< auto > getSchemaDescriptionOptions()
override in subclasses to return driver-specific options
bool supportsPackages()
returns True if the database supports packages
int index(softstring str, softstring substr, softint pos=0)
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
const Boolean
hash< auto > getCreationOptions()
override in subclasses to return driver-specific options
const AC_Rename
used when an object is renamed
Definition: AbstractDatabase.qc.dox.h:83
list< auto > list(...)
list< string > listTables()
returns a list of string table names in the database
bool dropViewIfExists(string name, *hash< auto > opt)
drops the given view if it exists; returns True if the view was dropped, False if not
const CreationOptions
default generic creation options
Definition: AbstractDatabase.qc.dox.h:165
const AC_Insert
used when data is inserted in a table
Definition: AbstractDatabase.qc.dox.h:98
hash< auto > getAlignSchemaOptions()
override in subclasses to return driver-specific options
hash< auto > getSequenceDescriptionOptions()
override in subclasses to return driver-specific options
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
abstract bool supportsSequencesImpl()
returns True if the database supports sequences
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
bool supportsTypes()
returns True if the database supports named types
list< auto > getDropSchemaSql(hash schema_hash, *hash< auto > opt)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
list< auto > getAlignSql(hash schema_hash, *hash< auto > opt, *Tables table_cache)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
auto tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost
base class for functions
Definition: SqlUtil.qm.dox.h:6321
const AC_Recreate
used when an object is recreated (usually dropped and recreated in place)
Definition: AbstractDatabase.qc.dox.h:95
string type(auto arg)
base class for views
Definition: SqlUtil.qm.dox.h:6240
bool native_case
native case option
Definition: AbstractDatabase.qc.dox.h:242
hash< auto > hash(object obj)
AbstractTable makeTable(string name, hash< auto > desc, *hash< auto > opts)
creates a database-specific AbstractTable object corresponding to the arguments
hash< auto > getDropSchemaOptions()
override in subclasses to return driver-specific options
const Int
const SequenceDescriptionOptions
default generic sequence description keys
Definition: AbstractDatabase.qc.dox.h:224
hash< auto > getReclaimSpaceOptions()
override in subclasses to return driver-specific options
list< string > listSequences()
returns a list of string sequence names in the database
list< string > listProcedures()
returns a list of string procedure names in the database
bool dropFunctionIfExists(string name, *hash< auto > opt)
drops the given function if it exists; returns True if the function was dropped, False if not
const AlignSchemaOptions
default generic schema description / alignment options
Definition: AbstractDatabase.qc.dox.h:176
int getNextSequenceValue(string name)
returns the next value in the given sequence
const AC_Truncate
used when a table is truncated
Definition: AbstractDatabase.qc.dox.h:89
transient Mutex l()
mutex for atomic actions
list< string > listViews()
returns a list of string view names in the database
auto tryExecArgsImpl(string sql, *softlist< auto > args)
tries to execute a command so that if an error occurs the current transaction status is not lost
*string getDropProcedureSqlIfExists(string name, *hash< auto > opt)
returns the SQL require to drop the given procedure if it exists or NOTHING if the named procedure do...
hash< auto > getCacheOptions()
override in subclasses to return driver-specific options
list features()
See DB Features Constants.
*string getDropFunctionSqlIfExists(string name, *hash< auto > opt)
returns the SQL require to drop the given function if it exists or NOTHING if the named function does...
list< string > listFunctions()
returns a list of string function names in the database
const CallbackOptions
generic callback options
Definition: AbstractDatabase.qc.dox.h:59
const ActionDescMap
maps from action descriptions to action codes
Definition: AbstractDatabase.qc.dox.h:127
*list< auto > getDropTableSqlIfExists(string name, *hash< auto > opt)
returns the SQL require to drop the given table if it exists or NOTHING if the named table does not e...
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
int getCurrentSequenceValue(string name)
returns the last value issued for the given sequence in the current session
bool dropProcedureIfExists(string name, *hash< auto > opt)
drops the given procedure if it exists; returns True if the procedure was dropped,...
const AC_Delete
used when data is deleted in a table
Definition: AbstractDatabase.qc.dox.h:104
const ComputeStatisticsOptions
Options for computeStatistics()
Definition: AbstractDatabase.qc.dox.h:231
const AC_Update
used when data is updated in a table
Definition: AbstractDatabase.qc.dox.h:101
const AC_NotFound
used when dropping object but the object is not present
Definition: AbstractDatabase.qc.dox.h:107
abstract int getCurrentSequenceValueImpl(string name)
returns the last value issued for the given sequence in the current session
AbstractFunction makeProcedure(string name, string src, *hash< auto > opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
the base abstract class for the database implementation
Definition: AbstractDatabase.qc.dox.h:34
bool dropTableIfExists(string name, *hash< auto > opt)
drops the given table if it exists; returns True if the table was dropped, False if not
const AC_Add
used when an element is added to an existing object
Definition: AbstractDatabase.qc.dox.h:92
auto tryExecArgs(string sql, *softlist< auto > args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found
abstract int getNextSequenceValueImpl(string name)
returns the next value in the given sequence
bool supportsSequences()
returns True if the database supports sequences
const ReclaimSpaceOptions
Options for reclaimSpace()
Definition: AbstractDatabase.qc.dox.h:236