# Qore Schema Module Reference: doxygen/qlib/Schema.qm.dox.h Source File

Schema.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file Schema.qm Qore user module for working with SQL data
/* Schema.qm Copyright 2014 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// this module requires Qore 0.8.13 or better
// requires the SqlUtil module
// requires the Util module
// don't use "$" signs for variables and class members, assume local variable scope
// require type definitions everywhere
// enable all warnings
// strict args
namespace Schema {
const C_NULL = False;
const C_NOT_NULL = True;
hash<GenericColumnInfo> c_int(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_int(string comment);
hash<GenericColumnInfo> c_varchar(int size, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_varchar(int size, string comment);
hash<GenericColumnInfo> c_char(int size, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_char(int size, string comment);
hash<GenericColumnInfo> c_date(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_date(string comment);
hash<GenericColumnInfo> c_timestamp(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_timestamp(string comment);
hash<GenericColumnInfo> c_number(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_number(int size, int scale, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_number(int size, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_number(int size, string comment);
hash<GenericColumnInfo> c_blob(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_blob(string comment);
hash<GenericColumnInfo> c_clob(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_clob(string comment);
class SchemaCallbackHelper {
public:
public :
AbstractSchema schema;
int verbose;
int change_count = 0;
int dot_count = 0;
int error_count = 0;
list sql_cache = ();
public:
constructor(AbstractSchema sc, int v = 0);
infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info);
sqlCallback(string str);
nothing sqlForceCallback(string str);
hash getCallbacks(bool force = False);
};
class AbstractSchema {
public:
private :
string name;
string version;
hash schema;
*hash index_options;
*hash creation_options;
*hash column_options;
*hash all_options;
Qore::SQL::AbstractDatasource ds;
string drv;
SqlUtil::Database db;
hash pure_callback_opts;
hash callback_opts;
code info_callback;
*string data_ts;
*string index_ts;
public:
constructor(Qore::SQL::AbstractDatasource n_ds, *string dts, *string its, *hash opts);
string getName();
string getVersion();
Qore::SQL::AbstractDatasource getDatasource();
SqlUtil::AbstractDatabase getDatabase();
logpf(string fmt);
log(string fmt);
logProgress(string str);
int align(bool force = False, int verbose = 0);
drop(bool force = False, int verbose = 0);
*hash getIndexOptions();
*hash getCreationOptions();
*hash getColumnOptions();
*hash getTables();
*hash getSequences();
*hash getTypes();
*hash getFunctions();
*hash getProcedures();
*hash getPackages();
*hash getMaterializedViews();
*hash getStrictReferenceDataHash();
*hash getReferenceDataHash();
*hash getCreateOnlyReferenceData();
*hash getInsertOnlyReferenceData();
private:
abstract string getNameImpl();
public:
private:
abstract string getVersionImpl();
public:
private:
*hash getIndexOptionsImpl();
public:
private:
*hash getColumnOptionsImpl();
public:
private:
*hash getGenericOptionsImpl();
public:
private:
*hash getTablesImpl();
public:
private:
*hash getSequencesImpl();
public:
private:
*hash getTypesImpl();
public:
private:
*hash getFunctionsImpl();
public:
private:
*hash getProceduresImpl();
public:
private:
*hash getPackagesImpl();
public:
private:
*hash getMaterializedViewsImpl();
public:
private:
*hash getStrictReferenceDataHashImpl();
public:
private:
*hash getReferenceDataHashImpl();
public:
private:
*hash getCreateOnlyReferenceDataImpl();
public:
private:
*hash getInsertOnlyReferenceDataImpl();
public:
private:
bool checkExistence();
public:
private:
bool checkFirstTimeInstall();
public:
private:
bool checkDropSchema(bool force);
public:
private:
bool checkUpdateSchema(bool force, reference<hash> initial_schema_info);
public:
private:
doPostAlignment(Tables table_cache, bool first_time_install, *hash initial_schema_info);
public:
private:
int getUpsertStrategy(bool first_time_install);
public:
private:
postDataActions(bool first_time_install);
public:
private:
doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose, reference<hash> sh);
public:
static list getRows(*softlist l);
static hash combineOptions(*hash h);
};
class AbstractVersionedSchema : public AbstractSchema {
public:
private :
string version_table;
string version_column;
hash version_where;
public:
constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts) ;
private:
*softstring getSchemaVersion();
public:
private:
bool checkDropSchema(bool force);
public:
private:
bool checkUpdateSchema(bool force, reference<hash> initial_schema_info);
public:
private:
bool checkUpgrade(string current_version);
public:
private:
bool checkDowngrade(string current_version);
public:
private:
string getVersionTable();
public:
private:
string getVersionColumn();
public:
private:
hash getVersionWhere();
public:
private:
abstract string getVersionTableImpl();
public:
private:
abstract string getVersionColumnImpl();
public:
private:
abstract hash getVersionWhereImpl();
public:
};
};
Schema::AbstractSchema::ds
Qore::SQL::AbstractDatasource ds
the datasource for the schema
Definition: Schema.qm.dox.h:348
Schema::SchemaCallbackHelper::getCallbacks
hash getCallbacks(bool force=False)
returns a callback option hash usable with SqlUtil schema operations
Schema::SchemaCallbackHelper::infoCallback
infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info)
this is the informational callback method for schema operations
Schema::c_varchar
hash< GenericColumnInfo > c_varchar(int size, bool notnull=False, *string comment)
returns a column hash for a VARCHAR column
Schema::AbstractSchema::name
string name
the name of the schema
Definition: Schema.qm.dox.h:331
Schema::c_clob
hash< GenericColumnInfo > c_clob(bool notnull=False, *string comment)
returns a column hash for a CLOB column
True
const True
Schema::c_char
hash< GenericColumnInfo > c_char(int size, bool notnull=False, *string comment)
returns a column hash for a CHAR column
Schema::AbstractSchema::column_options
*hash column_options
column options, as provided by getColumnOptions()
Definition: Schema.qm.dox.h:343
Schema::AbstractSchema::callback_opts
hash callback_opts
callback options plus all options
Definition: Schema.qm.dox.h:358
Schema::c_int
hash< GenericColumnInfo > c_int(bool notnull=False, *string comment)
returns a column hash for an INT column
SqlUtil::Database
False
const False
Schema::c_blob
hash< GenericColumnInfo > c_blob(bool notnull=False, *string comment)
returns a column hash for a BLOB column
Qore::SQL::AbstractDatasource
list
list list(...)
Schema::AbstractSchema::index_options
*hash index_options
index options, as provided by getIndexOptions()
Definition: Schema.qm.dox.h:339
Schema::SchemaCallbackHelper::sqlCallback
sqlCallback(string str)
this is the SQL callback method for schema operations
Schema::AbstractVersionedSchema::version_column
string version_column
the name of the column containing the version string
Definition: Schema.qm.dox.h:752
Schema::AbstractSchema::data_ts
*string data_ts
explicit data tablespace name
Definition: Schema.qm.dox.h:364
Schema::c_timestamp
hash< GenericColumnInfo > c_timestamp(bool notnull=False, *string comment)
returns a column hash for a TIMESTAMP column
Schema::c_number
hash< GenericColumnInfo > c_number(bool notnull=False, *string comment)
returns a column hash for a NUMBER or NUMERIC column
Schema::C_NULL
const C_NULL
Helper constant for column hash functions with "NULL" constraint for better readability.
Definition: Schema.qm.dox.h:92
Schema::SchemaCallbackHelper::constructor
constructor(AbstractSchema sc, int v=0)
creates the callback object from the given arguments
Schema
this namespace contains all public definitions in the Schema module
Definition: Schema.qm.dox.h:90
Schema::AbstractVersionedSchema
this class extends Schema::AbstractSchema by providing version logic based on a schema version string...
Definition: Schema.qm.dox.h:745
Schema::AbstractSchema::creation_options
*hash creation_options
creation options, as provided by getCreationOptions()
Definition: Schema.qm.dox.h:341
Schema::AbstractSchema::schema
hash schema
the schema template, as assembled from method callbacks providing schema element definitions ...
Definition: Schema.qm.dox.h:336
Schema::SchemaCallbackHelper
this class provides callback support for schema operations
Definition: Schema.qm.dox.h:256
type
string type(auto arg)
Schema::AbstractVersionedSchema::version_table
string version_table
the name of the table containing the version string
Definition: Schema.qm.dox.h:750
Schema::AbstractSchema::db
SqlUtil::Database db
the Database object for the schema
Definition: Schema.qm.dox.h:353
Schema::AbstractSchema::info_callback
code info_callback
the info callback for schema operations; can be used for explicit logging
Definition: Schema.qm.dox.h:361
Schema::AbstractSchema::version
string version
the version of the schema
Definition: Schema.qm.dox.h:333
Schema::C_NOT_NULL
const C_NOT_NULL
Helper constant for column hash functions with "NOT NULL" constraint for better readability.
Definition: Schema.qm.dox.h:94
Schema::AbstractSchema::all_options
*hash all_options
combined creation and column options
Definition: Schema.qm.dox.h:345
Schema::AbstractSchema::drv
string drv
the name of the database driver
Definition: Schema.qm.dox.h:350
Schema::AbstractVersionedSchema::version_where
hash version_where
a where clause hash defining the row where the schema version string is located
Definition: Schema.qm.dox.h:754
Schema::c_date
hash< GenericColumnInfo > c_date(bool notnull=False, *string comment)
returns a column hash for a DATE column
Schema::AbstractSchema::pure_callback_opts
hash pure_callback_opts
just callback options
Definition: Schema.qm.dox.h:356
hash
hash hash(object obj)
SqlUtil::AbstractDatabase
Schema::AbstractSchema::index_ts
*string index_ts
explicit index tablespace name
Definition: Schema.qm.dox.h:367
Schema::SchemaCallbackHelper::sqlForceCallback
nothing sqlForceCallback(string str)
this is the SQL callback method for forced schema operations
Schema::AbstractSchema
the AbstractSchema class is a base class to assist with automatic schema management ...
Definition: Schema.qm.dox.h:326