Qore SqlUtil Module Reference 1.9
Loading...
Searching...
No Matches
AbstractDatabase.qc.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
26namespace SqlUtil {
29
30public:
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
126
127
129
132 const DropSchemaOptions = ...;
133
134
136
149
150
152
158
159
162
163
166
167
168protected:
170 bool native_case = False;
171
172 // AbstractDatabase::getPhysicalSize() return in a case of no data
173 const GET_PHYSICAL_DB_SIZE_NOVAL = -1;
174
175public:
176
178
183protected:
184 constructor(AbstractDatasource nds, *hash nopts) ;
185public:
186
187
189 list features();
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
723 string getSqlFromList(list l);
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
855protected:
856 validateOptionsIntern(string err, hash<auto> ropt, reference<hash> opt);
857public:
858
859
860protected:
861 validateOptionsIntern(string err, hash<auto> ropt, reference<hash> opt, string tag);
862public:
863
864
865 static AbstractDatabase getDatabase(AbstractDatasource nds, *hash<auto> opts);
866
867 static string loadModule(AbstractDatasource nds, *reference<string> drv);
868
869 static AbstractDatabase getDatabase(string dsstr, *hash<auto> opts);
870
871 static AbstractDatabase getDatabase(hash<auto> dsh, *hash<auto> opts);
872
873 static checkDriverOptions(reference<hash<auto>> h, string drv);
874
876protected:
877 hash<auto> getDatabaseOptions();
878public:
879
880
882protected:
883 hash<auto> getCallbackOptions();
884public:
885
886
888protected:
889 hash<auto> getCreationOptions();
890public:
891
892
894protected:
895 hash<auto> getCacheOptions();
896public:
897
898
900protected:
902public:
903
904
906protected:
908public:
909
910
912protected:
914public:
915
916
918protected:
920public:
921
922
924protected:
926public:
927
928
930protected:
932public:
933
934
936protected:
938public:
939
940
942protected:
943 auto tryExecArgsImpl(string sql, *softlist<auto> args);
944public:
945
946
948protected:
949 auto tryExecRawImpl(string sql);
950public:
951
952
953protected:
954 abstract string getCreateSqlImpl(list l);
955public:
956protected:
957 abstract list<auto> getAlignSqlImpl(hash schema_hash, *hash<auto> opt);
958public:
959protected:
960 abstract list<auto> getDropSchemaSqlImpl(hash schema_hash, *hash<auto> opt);
961public:
962
963protected:
964 abstract *AbstractSequence getSequenceImpl(string name);
965public:
966protected:
967 abstract *AbstractFunction getFunctionImpl(string name);
968public:
969protected:
970 abstract *AbstractFunction getProcedureImpl(string name);
971public:
972protected:
973 abstract *AbstractView getViewImpl(string name);
974public:
975
976 private abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1,
977 *softnumber end, *hash<auto> opts);
978protected:
979 abstract AbstractFunction makeFunctionImpl(string name, string src, *hash<auto> opts);
980public:
981protected:
982 abstract AbstractFunction makeProcedureImpl(string name, string src, *hash<auto> opts);
983public:
984
985protected:
986 abstract list<string> featuresImpl();
987public:
988protected:
989 abstract list<string> listTablesImpl();
990public:
991protected:
992 abstract list<string> listFunctionsImpl();
993public:
994protected:
995 abstract list<string> listProceduresImpl();
996public:
997protected:
998 abstract list<string> listSequencesImpl();
999public:
1000protected:
1001 abstract list<string> listViewsImpl();
1002public:
1003
1005protected:
1006 abstract int getNextSequenceValueImpl(string name);
1007public:
1009protected:
1010 abstract int getCurrentSequenceValueImpl(string name);
1011public:
1012
1014protected:
1015 abstract bool supportsSequencesImpl();
1016public:
1017protected:
1018 abstract bool supportsPackagesImpl();
1019public:
1020protected:
1021 abstract bool supportsTypesImpl();
1022public:
1023
1024protected:
1025 abstract bool rebuildIndexImpl(string name, *hash<auto> options);
1026public:
1027protected:
1028 abstract computeStatisticsImpl(*hash<auto> options);
1029public:
1030protected:
1031 abstract reclaimSpaceImpl(*hash<auto> options);
1032public:
1033protected:
1034 abstract int getPhysicalSizeImpl();
1035public:
1036};
1037};
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
hash< auto > getReclaimSpaceOptions()
override in subclasses to return driver-specific options
bool dropProcedureIfExists(string name, *hash< auto > opt)
drops the given procedure if it exists; returns True if the procedure was dropped,...
hash< auto > getRebuildIndexOptions()
override in subclasses to return driver-specific options
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...
const CacheOptions
generic cache options
Definition: AbstractDatabase.qc.dox.h:42
bool supportsTypes()
returns True if the database supports named types
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
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...
list< string > listProcedures()
returns a list of string procedure names in the database
hash< auto > getCallbackOptions()
override in subclasses to return driver-specific options
bool rebuildIndex(AbstractIndex index, *hash< auto > options)
Rebuild an index in the DB.
list features()
See DB Features Constants.
hash< auto > getCreationOptions()
override in subclasses to return driver-specific options
*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.
const ActionMap
maps from action codes to action descriptions
Definition: AbstractDatabase.qc.dox.h:100
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
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...
int getPhysicalSize()
Get the current database physical size in bytes.
*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...
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
const ComputeStatisticsOptions
Options for computeStatistics()
Definition: AbstractDatabase.qc.dox.h:161
hash< auto > getDatabaseOptions()
override in subclasses to return driver-specific options
reclaimSpace(*hash< auto > options)
Reclaim taken but unused space in the DB.
hash< auto > getCacheOptions()
override in subclasses to return driver-specific options
bool rebuildIndex(string name, *hash< auto > options)
Rebuild an index in the DB.
hash< auto > getSequenceDescriptionOptions()
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
*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
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...
hash< auto > getSchemaDescriptionOptions()
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
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
list< string > listViews()
returns a list of string view names in the database
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 > getComputeStatisticsOptions()
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
AbstractTable makeTable(string name, hash< auto > desc, *hash< auto > opts)
creates a database-specific AbstractTable object corresponding to the arguments
hash< auto > getAlignSchemaOptions()
override in subclasses to return driver-specific options
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
list< string > listSequences()
returns a list of 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...
list< string > listFunctions()
returns a list of string function names in the database
constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
list< string > listTables()
returns a list of string table names in the database
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...
*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
hash< auto > getDropSchemaOptions()
override in subclasses to return driver-specific options
const SequenceDescriptionOptions
default generic sequence description keys
Definition: AbstractDatabase.qc.dox.h:157
base class for functions
Definition: SqlUtil.qm.dox.h:7082
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:6543
base class for sequences
Definition: SqlUtil.qm.dox.h:6965
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:7001
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:6094
const AC_NotFound
used when dropping object but the object is not present
Definition: AbstractDatabase.qc.dox.h:96
const AC_Modify
used when an object is modified in place
Definition: AbstractDatabase.qc.dox.h:75
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
const AC_Update
used when data is updated in a table
Definition: AbstractDatabase.qc.dox.h:90
const AC_Drop
used when an object is dropped
Definition: AbstractDatabase.qc.dox.h:69
const AC_Create
used when a new object is created
Definition: AbstractDatabase.qc.dox.h:66
const AC_Delete
used when data is deleted in a table
Definition: AbstractDatabase.qc.dox.h:93
const AC_Truncate
used when a table is truncated
Definition: AbstractDatabase.qc.dox.h:78
const AC_Unchanged
Definition: AbstractDatabase.qc.dox.h:63
const AC_Insert
used when data is inserted in a table
Definition: AbstractDatabase.qc.dox.h:87
const AC_Rename
used when an object is renamed
Definition: AbstractDatabase.qc.dox.h:72
string type(auto arg)
list< auto > list(...)
Qore AbstractDatabase class definition.
Definition: AbstractDatabase.qc.dox.h:26