Qore SqlUtil Module Reference  1.8.1
AbstractDatabase.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
26 namespace SqlUtil {
29 
30 public:
32 
35  const DatabaseOptions = ...;
36 
37 
39 
42  const CacheOptions = ...;
43 
44 
46 
51  const CallbackOptions = ...;
52 
53 
63  const AC_Unchanged = 0;
64 
66  const AC_Create = 1;
67 
69  const AC_Drop = 2;
70 
72  const AC_Rename = 3;
73 
75  const AC_Modify = 4;
76 
78  const AC_Truncate = 5;
79 
81  const AC_Add = 6;
82 
84  const AC_Recreate = 7;
85 
87  const AC_Insert = 8;
88 
90  const AC_Update = 9;
91 
93  const AC_Delete = 10;
94 
96  const AC_NotFound = 11;
98 
100  const ActionMap = ...;
101 
102 
104  const ActionDescMap = ...;
105 
106 
108  const ActionLetterMap = ...;
109 
110 
112 
118  const CreationOptions = ...;
119 
120 
122 
125  const AlignSchemaOptions = ...;
126 
127 
129 
132  const DropSchemaOptions = ...;
133 
134 
136 
149 
150 
152 
158 
159 
162 
163 
165  const ReclaimSpaceOptions = ...;
166 
167 
168 protected:
171 
172  // AbstractDatabase::getPhysicalSize() return in a case of no data
173  const GET_PHYSICAL_DB_SIZE_NOVAL = -1;
174 
175 public:
176 
178 
183 protected:
184  constructor(AbstractDatasource nds, *hash nopts) ;
185 public:
186 
187 
190 
191 
192  static doOkCallback(*hash<auto> opt, int ac, string type, string name, *string table, *string info);
193 
194  static private runInfoCallback(code info_callback, int ac, string type, string name, *string table,
195  *string new_name, *string info) {
196  bool c = (type == "column");
197  if (c)
198  name = sprintf("%s.%s", table, name);
199  string str = sprintf("%s %s %s", ActionMap{ac}, type, name);
200  if (table && !c)
201  str += sprintf(" %s %s", ac == AC_Drop ? "from" : "on", table);
202  if (new_name)
203  str += sprintf(" to %s", new_name);
204  if (info)
205  str += sprintf(" (%s)", info);
206  info_callback(str, ac, type, name, table, new_name, info);
207  }
208 
209  static *string doCallback(*hash<auto> opt, *string sql, int ac, string type, string name, *string table,
210  *string new_name, *string info) {
211  if (!sql)
212  return;
213  if (opt.info_callback);
214 
215  if (opt.sql_callback);
216 
217  return sql;
218  }
219 
220  static list doCallback(*hash<auto> opt, list sql, int ac, string type, string name, *string table,
221  *string new_name, *string info) {
222  if (!sql)
223  return sql;
224  if (opt.info_callback);
225 
226  if (opt.sql_callback);
227 
228  return sql;
229  }
230 
232 
243  auto tryExec(string sql);
244 
245 
247 
257  auto tryExecArgs(string sql, *softlist<auto> args);
258 
259 
261 
272  auto tryExecRaw(string sql);
273 
274 
276 
290  list<auto> getAlignSql(hash schema_hash, *hash<auto> opt, *Tables table_cache);
291 
292 
294 
307  list<auto> getDropSchemaSql(hash schema_hash, *hash<auto> opt);
308 
309 
310  private list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash<auto> opt,
311  string make_arg_type) {
312  list l = ();
313  hash copt = getCreationOptions();
314  string drv = getDriverName();
315 
316  // drop objects
317  reference<hash> fmap = \schema_hash{type + "s"};
318  AbstractDatabase::checkDriverOptions(\fmap, drv);
319  foreach string name in (fmap.keyIterator());
320 
321 
322  return l;
323  }
324 
325  private list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash<auto> opt,
326  string make_arg_type) {
327  list l = ();
328  hash copt = getCreationOptions();
329  string drv = getDriverName();
330 
331  hash code_cache;
332 
333  // rename objects
334  reference<*hash> fmap = \schema_hash{type + "_map"};
335  AbstractDatabase::checkDriverOptions(\fmap, drv);
336  HashIterator i(fmap);
337  while (i.next());
338 
339 
340  // create any missing functions; replace updated functions
341  reference<hash> fh = \schema_hash{type + "s"};
342  AbstractDatabase::checkDriverOptions(\fh, drv);
343  foreach string name in (fh.keyIterator());
344 
345 
346  return l;
347  }
348 
350 
366  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end,
367  *hash<auto> opts) {
368  validateOptionsIntern("OPTION-ERROR", getCreationOptions(), \opts);
369 
370  // issue #4396: convert letters to lower case if necessary
371  if (!opts.native_case);
372 
373  return makeSequenceImpl(name, start, increment, end, opts);
374  }
375 
376  AbstractSequence makeSequenceFromDescription(string name, *hash<auto> sh, *hash<auto> opts);
377 
378 
380 
395  AbstractTable makeTable(string name, hash<auto> desc, *hash<auto> opts);
396 
397 
399 
414  AbstractFunction makeFunction(string name, string src, *hash<auto> opts);
415 
416 
418 
433  AbstractFunction makeProcedure(string name, string src, *hash<auto> opt);
434 
435 
437 
449  bool dropFunctionIfExists(string name, *hash<auto> opt);
450 
451 
453 
465  bool dropProcedureIfExists(string name, *hash<auto> opt);
466 
467 
469 
481  bool dropSequenceIfExists(string name, *hash<auto> opt);
482 
483 
485 
497  bool dropViewIfExists(string name, *hash<auto> opt);
498 
499 
501 
513  bool dropTableIfExists(string name, *hash<auto> opt);
514 
515 
517 
529  *string getDropFunctionSqlIfExists(string name, *hash<auto> opt);
530 
531 
533 
545  *string getDropProcedureSqlIfExists(string name, *hash<auto> opt);
546 
547 
549 
561  *string getDropSequenceSqlIfExists(string name, *hash<auto> opt);
562 
563 
565 
577  *list<auto> getDropTableSqlIfExists(string name, *hash<auto> opt);
578 
579 
580  doDropSql(*softlist l, string type, string name, *hash<auto> opt);
581 
582 
583  bool doDrop(*softlist l, string type, string name, *hash<auto> opt);
584 
585 
587 
599  list<auto> getAlignFunctionSql(AbstractFunction f, *hash<auto> opt);
600 
601 
603 
615  list<auto> getAlignProcedureSql(AbstractFunction f, *hash<auto> opt);
616 
617 
619 
628  *AbstractTable getTable(string name);
629 
630 
632 
642 
643 
645 
657 
658 
660 
672 
673 
675 
684  *AbstractView getView(string name);
685 
686 
688 
697  int getNextSequenceValue(string name);
698 
699 
701 
710  int getCurrentSequenceValue(string name);
711 
712 
714 
724 
725 
728 
729 
732 
733 
736 
737 
739  list<string> listTables();
740 
741 
744 
745 
747  list<string> listFunctions();
748 
749 
752 
753 
755  list<string> listProcedures();
756 
757 
760 
761 
763  list<string> listSequences();
764 
765 
768 
769 
771  list<string> listViews();
772 
773 
776 
777 
779 
789  bool rebuildIndex(string name, *hash<auto> options);
790 
791 
793 
801  bool rebuildIndex(AbstractIndex index, *hash<auto> options);
802 
803 
805 
812  computeStatistics(*hash<auto> options);
813 
814 
816 
823  reclaimSpace(*hash<auto> options);
824 
825 
827 
837 
838 
840 
845 
846 
848 
853 
854 
855 protected:
856  validateOptionsIntern(string err, hash<auto> ropt, reference<hash> opt);
857 public:
858 
859 
860 protected:
861  validateOptionsIntern(string err, hash<auto> ropt, reference<hash> opt, string tag);
862 public:
863 
864 
865  static AbstractDatabase getDatabase(AbstractDatasource nds, *hash<auto> opts);
866 
867  static string loadModule(AbstractDatasource nds, *reference<string> drv);
868 
869  static string getOdbcDriverName(AbstractDatasource nds);
870 
871  static AbstractDatabase getDatabase(string dsstr, *hash<auto> opts);
872 
873  static AbstractDatabase getDatabase(hash<auto> dsh, *hash<auto> opts);
874 
875  static checkDriverOptions(reference<hash<auto>> h, string drv);
876 
878 protected:
879  hash<auto> getDatabaseOptions();
880 public:
881 
882 
884 protected:
885  hash<auto> getCallbackOptions();
886 public:
887 
888 
890 protected:
891  hash<auto> getCreationOptions();
892 public:
893 
894 
896 protected:
897  hash<auto> getCacheOptions();
898 public:
899 
900 
902 protected:
903  hash<auto> getAlignSchemaOptions();
904 public:
905 
906 
908 protected:
909  hash<auto> getDropSchemaOptions();
910 public:
911 
912 
914 protected:
916 public:
917 
918 
920 protected:
922 public:
923 
924 
926 protected:
928 public:
929 
930 
932 protected:
934 public:
935 
936 
938 protected:
940 public:
941 
942 
944 protected:
945  auto tryExecArgsImpl(string sql, *softlist<auto> args);
946 public:
947 
948 
950 protected:
951  auto tryExecRawImpl(string sql);
952 public:
953 
954 
955 protected:
956  abstract string getCreateSqlImpl(list l);
957 public:
958 protected:
959  abstract list<auto> getAlignSqlImpl(hash schema_hash, *hash<auto> opt);
960 public:
961 protected:
962  abstract list<auto> getDropSchemaSqlImpl(hash schema_hash, *hash<auto> opt);
963 public:
964 
965 protected:
966  abstract *AbstractSequence getSequenceImpl(string name);
967 public:
968 protected:
969  abstract *AbstractFunction getFunctionImpl(string name);
970 public:
971 protected:
972  abstract *AbstractFunction getProcedureImpl(string name);
973 public:
974 protected:
975  abstract *AbstractView getViewImpl(string name);
976 public:
977 
978  private abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1,
979  *softnumber end, *hash<auto> opts);
980 protected:
981  abstract AbstractFunction makeFunctionImpl(string name, string src, *hash<auto> opts);
982 public:
983 protected:
984  abstract AbstractFunction makeProcedureImpl(string name, string src, *hash<auto> opts);
985 public:
986 
987 protected:
988  abstract list<string> featuresImpl();
989 public:
990 protected:
991  abstract list<string> listTablesImpl();
992 public:
993 protected:
994  abstract list<string> listFunctionsImpl();
995 public:
996 protected:
997  abstract list<string> listProceduresImpl();
998 public:
999 protected:
1000  abstract list<string> listSequencesImpl();
1001 public:
1002 protected:
1003  abstract list<string> listViewsImpl();
1004 public:
1005 
1007 protected:
1008  abstract int getNextSequenceValueImpl(string name);
1009 public:
1011 protected:
1012  abstract int getCurrentSequenceValueImpl(string name);
1013 public:
1014 
1016 protected:
1017  abstract bool supportsSequencesImpl();
1018 public:
1019 protected:
1020  abstract bool supportsPackagesImpl();
1021 public:
1022 protected:
1023  abstract bool supportsTypesImpl();
1024 public:
1025 
1026 protected:
1027  abstract bool rebuildIndexImpl(string name, *hash<auto> options);
1028 public:
1029 protected:
1030  abstract computeStatisticsImpl(*hash<auto> options);
1031 public:
1032 protected:
1033  abstract reclaimSpaceImpl(*hash<auto> options);
1034 public:
1035 protected:
1036  abstract int getPhysicalSizeImpl();
1037 public:
1038 };
1039 };
the base abstract class for the database implementation
Definition: AbstractDatabase.qc.dox.h:28
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
const CreationOptions
default generic creation options
Definition: AbstractDatabase.qc.dox.h:118
int getNextSequenceValue(string name)
returns the next value in the given sequence
const CallbackOptions
generic callback options
Definition: AbstractDatabase.qc.dox.h:51
bool dropProcedureIfExists(string name, *hash< auto > opt)
drops the given procedure if it exists; returns True if the procedure was dropped,...
const DropSchemaOptions
default generic drop schema options
Definition: AbstractDatabase.qc.dox.h:132
*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...
list< string > listTables()
returns a list of string table names in the database
hash< auto > getAlignSchemaOptions()
override in subclasses to return driver-specific options
const CacheOptions
generic cache options
Definition: AbstractDatabase.qc.dox.h:42
hash< auto > getCacheOptions()
override in subclasses to return driver-specific options
bool supportsTypes()
returns True if the database supports named types
const AC_NotFound
used when dropping object but the object is not present
Definition: AbstractDatabase.qc.dox.h:96
abstract int getCurrentSequenceValueImpl(string name)
returns the last value issued for the given sequence in the current session
const SchemaDescriptionOptions
default generic schema description keys
Definition: AbstractDatabase.qc.dox.h:148
const AC_Modify
used when an object is modified in place
Definition: AbstractDatabase.qc.dox.h:75
hash< auto > getSchemaDescriptionOptions()
override in subclasses to return driver-specific options
const AC_Add
used when an element is added to an existing object
Definition: AbstractDatabase.qc.dox.h:81
const AC_Recreate
used when an object is recreated (usually dropped and recreated in place)
Definition: AbstractDatabase.qc.dox.h:84
bool rebuildIndex(AbstractIndex index, *hash< auto > options)
Rebuild an index in the DB.
*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...
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...
AbstractFunction makeFunction(string name, string src, *hash< auto > opts)
creates a database-specific AbstractFunction object corresponding to the arguments
bool requiresScale()
Returns True if the driver requires a scale to support decimal values in numeric or decimal columns.
hash< auto > getCreationOptions()
override in subclasses to return driver-specific options
hash< auto > getSequenceDescriptionOptions()
override in subclasses to return driver-specific options
const AC_Update
used when data is updated in a table
Definition: AbstractDatabase.qc.dox.h:90
list< string > listProcedures()
returns a list of string procedure names in the database
list< string > listFunctions()
returns a list of string function names in the database
const ActionMap
maps from action codes to action descriptions
Definition: AbstractDatabase.qc.dox.h:100
const AC_Drop
used when an object is dropped
Definition: AbstractDatabase.qc.dox.h:69
list< string > listViews()
returns a list of string view names in the database
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
int getPhysicalSize()
Get the current database physical size in bytes.
list< string > listSequences()
returns a list of string sequence names in the database
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
Definition: AbstractDatabase.qc.dox.h:366
bool supportsPackages()
returns True if the database supports packages
const ActionDescMap
maps from action descriptions to action codes
Definition: AbstractDatabase.qc.dox.h:104
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...
const AC_Create
used when a new object is created
Definition: AbstractDatabase.qc.dox.h:66
const ComputeStatisticsOptions
Options for computeStatistics()
Definition: AbstractDatabase.qc.dox.h:161
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...
reclaimSpace(*hash< auto > options)
Reclaim taken but unused space in the DB.
const AC_Delete
used when data is deleted in a table
Definition: AbstractDatabase.qc.dox.h:93
bool rebuildIndex(string name, *hash< auto > options)
Rebuild an index in the DB.
hash< auto > getRebuildIndexOptions()
override in subclasses to return driver-specific options
auto tryExecArgs(string sql, *softlist< auto > args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
const AlignSchemaOptions
default generic schema description / alignment options
Definition: AbstractDatabase.qc.dox.h:125
bool native_case
native case option
Definition: AbstractDatabase.qc.dox.h:170
const DatabaseOptions
database options
Definition: AbstractDatabase.qc.dox.h:35
const AC_Truncate
used when a table is truncated
Definition: AbstractDatabase.qc.dox.h:78
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view cannot be found
bool supportsSequences()
returns True if the database supports sequences
int getCurrentSequenceValue(string name)
returns the last value issued for the given sequence in the current session
const AC_Unchanged
used when an existing object matches the template and no changes are made
Definition: AbstractDatabase.qc.dox.h:63
computeStatistics(*hash< auto > options)
Compute database statistics.
bool dropTableIfExists(string name, *hash< auto > opt)
drops the given table if it exists; returns True if the table was dropped, False if not
auto tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost
auto tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
abstract bool supportsSequencesImpl()
returns True if the database supports sequences
hash< auto > getReclaimSpaceOptions()
override in subclasses to return driver-specific options
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
hash< auto > getCallbackOptions()
override in subclasses to return driver-specific options
hash< auto > getComputeStatisticsOptions()
override in subclasses to return driver-specific options
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
const ReclaimSpaceOptions
Options for reclaimSpace()
Definition: AbstractDatabase.qc.dox.h:165
bool dropViewIfExists(string name, *hash< auto > opt)
drops the given view if it exists; returns True if the view was dropped, False if not
hash< auto > getDatabaseOptions()
override in subclasses to return driver-specific options
int getMaximumPrecision()
Returns the maximum precision for numeric or decimal columns.
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 AC_Insert
used when data is inserted in a table
Definition: AbstractDatabase.qc.dox.h:87
AbstractTable makeTable(string name, hash< auto > desc, *hash< auto > opts)
creates a database-specific AbstractTable object corresponding to the arguments
const ActionLetterMap
maps from action codes to action letter codes
Definition: AbstractDatabase.qc.dox.h:108
abstract int getNextSequenceValueImpl(string name)
returns the next value in the given sequence
AbstractFunction makeProcedure(string name, string src, *hash< auto > opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
auto tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost
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...
*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...
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
hash< auto > getDropSchemaOptions()
override in subclasses to return driver-specific options
constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
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...
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
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 SequenceDescriptionOptions
default generic sequence description keys
Definition: AbstractDatabase.qc.dox.h:157
const AC_Rename
used when an object is renamed
Definition: AbstractDatabase.qc.dox.h:72
base class for functions
Definition: SqlUtil.qm.dox.h:7064
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:6525
base class for sequences
Definition: SqlUtil.qm.dox.h:6947
base class for abstract SqlUtil classes
Definition: AbstractSqlUtilBase.qc.dox.h:28
transient Mutex l()
mutex for atomic actions
*hash< auto > opts
option hash
Definition: AbstractSqlUtilBase.qc.dox.h:35
string getDriverName()
returns the database driver name
the base abstract class for the table implementation
Definition: AbstractTable.qc.dox.h:30
base class for views
Definition: SqlUtil.qm.dox.h:6983
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:6076
const False
string sprintf(string fmt,...)
int index(softstring str, softstring substr, softint pos=0)
hash< auto > hash(object obj)
string type(auto arg)
list< auto > list(...)
number number(softnumber n)
Qore AbstractDatabase class definition.
Definition: AbstractDatabase.qc.dox.h:26