SqlUtil.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file SqlUtil.qm Qore user module for working with SQL data
/* SqlUtil.qm Copyright (C) 2013 - 2018 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 Util module
// don't use "$" signs for variables and class members, assume local variable scope
// require type definitions everywhere
// enable all warnings
// version history is included below in the docs
...
@endcode
@warning Oracle: using different comments in the same SQL can lead to new optimizer statement hard parsing.
@subsubsection select_option_hint Select Option "hint"
In database query operations, various SQL implementations use hints as additions to the SQL standard that instruct the database engine on how to execute the query. For example, a hint may tell the engine to use as little memory as possible (even if the query will run slowly), or to use or not to use an index (even if the query optimizer would decide otherwise).
<b>Hint Example:</b>
@code{.py}
table.selectRows(("hint": "full(t1)"));
@endcode
will produce select statement like this:
@code{.py}
select /*+ full(a) */ ...
@endcode
The string is taken as-is and it's up to the caller to handle correct aliases in join functions etc.
@note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
@warning Use hints only when you know what you are doing.
@subsubsection select_option_columns Select Option "columns"
<b>Columns Example:</b>
@code{.py}
list columns = (
"id", "name", "started",
cop_as("warnings", "warning_count"),
cop_as("errors", "error_count"),
);
*list rows = table.selectRows(("columns": columns, "where": ("type": "user")));
@endcode
By default, all columns are returned from a query; to limit the columns returned, or to perform column operations on the columns returned, use the \c "columns" option of the @ref select_option_hash "select option hash". \n\n
This option takes a list, each element of the list can be one of the following.\n\n
<b>A Simple String Giving a Column Name</b>\n
ex: \c "name"
@code{.py}
*list rows = table.selectRows(("columns": ("id", "name", "started")));
@endcode \n
<b>A String in Dot Notation</b>\n
This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
@code{.py}
hash sh = (
"columns": ("t1.id", "t2.customer_name"),
"join": join_inner(table2, "t2", ("id": "altid"))),
"alias": "t1",
);
*list rows = table.selectRows(sh);
@endcode \n
<b>A Column Operation Specified by a Column Operator Function</b>\n
ex: <tt>cop_as("column_name", "column_alias")</tt> \n
See @ref sql_cop_funcs "column operator function" for more information on column operator functions
@code{.py}
list columns = (
"id",
cop_as("warnings", "warning_count"),
cop_as("errors", "error_count"),
);
*list rows = table.selectRows(("columns": columns));
@endcode
For @ref sql_cop_funcs "column operator functions" taking a column name, either a string name or a name in dot notation is acceptable\n\n
<b>The Value \c "*", Meaning All Columns</b>\n
ex: \c "*"
@code{.py}
*list rows = table.selectRows(("columns": "*"));
@endcode
This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
<b>An \c "*" in Dot Notation</b>\n
ex: \c "q.*"
@code{.py}
hash sh = (
"columns": ("table.id", "t2.*"),
"join": join_inner(table2, "t2", ("id": "altid")),
);
*list rows = table.selectRows(sh);
@endcode
@subsubsection select_option_where Select Option "where"
<b>Where Example:</b>
@code{.py}
*list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
@endcode
The hash value assigned to this key describes how the \c "where" clause in the query is built. Because the \c "where" clause logic is common to many SQL methods, this topic is covered in a separate section. See @ref where_clauses for a detailed description of the value of this key.
@subsubsection select_option_orderby Select Option "orderby"
<b>Orderby Example:</b>
@code{.py}
hash sh = (
"where": (
"account_type": "CUSTOMER",
),
"orderby": "created_date",
);
*list rows = table.selectRows(sh);
@endcode
This option is a list of the following values:
- a simple string giving a column name; ex: \c "name"
- a simple string with a column name preceded by a \c "-" sign; ex: \c "-name", meaning that that column should be sorted in descending order
- a string giving a table or table alias and a column name in dot notation (for use with @ref select_option_join "joins"); ex: \c "q.name"
- a positive integer giving the column number for the ordering
@note
- By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
@subsubsection select_option_desc Select Option "desc"
<b>Desc Example:</b>
@code{.py}
hash sh = (
"where": (
"account_type": "CUSTOMER",
),
"orderby": "created_date",
"desc": True,
);
*list rows = table.selectRows(sh);
@endcode
If the value of this key is @ref Qore::True "True" and results are ordered (either due to the @ref select_option_orderby "orderby option" or due to implicit ordering by the primary key due to the use of the @ref select_option_offset "offset option"), then results will be sorted in descending order.\n\n
Otherwise, ordered results are returned in ascending order by default.
@note per-column descending options can be given by prepending a \c "-" character to the column name in the @ref select_option_orderby "orderby option list"
@subsubsection select_option_limit Select Option "limit"
<b>Limit Example:</b>
@code{.py}
hash sh = (
"where": ("type": "user"),
"limit": 100,
"offset": 200
);
*list rows = table.selectRows(sh);
@endcode
This option will limit the number of rows returned.
@note
- This option is required if the @ref select_option_offset "offset option" is non-zero
- If this option is present and an @ref select_option_orderby "orderby option" is also present, then at least a subset of the @ref select_option_orderby "orderby" columns must correspond to a unique key of the table or an exception is raised
@subsubsection select_option_offset Select Option "offset"
<b>Offset Example:</b>
@code{.py}
hash sh = (
"where": ("type": "user"),
"limit": 100,
"offset": 200
);
*list rows = table.selectRows(sh);
@endcode
This option specifies the row number offset for the rows returned where the first row is at offset zero.
@note
- If this option is present, then either an @ref select_option_orderby "orderby option" must be present of which at least a subset of the @ref select_option_orderby "orderby" columns must correspond to a unique key of the table, or, if no @ref select_option_orderby "orderby option" is used, then the table must have a primary key which is used for the ordering instead.
- Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
@see @ref sql_paging
@subsubsection select_option_join Select Option "join"
<b>Join Example:</b>
@code{.py}
hash sh = (
"columns": (
"name", "version", "id",
cop_as("st.value", "source"),
cop_as("st.value", "offset"),
),
"join": join_left(function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
+ join_left(function_instance_tags, "lt", NOTHING, ("st.tag": "_offset")),
);
*list rows = table.selectRows(sh);
@endcode
To join multiple tables in a single query, use the \c "join" option. The \c "join" hash key should be assigned to a join description hash as returned by one of the @ref sql_jop_funcs or combined join description hash created by concatenating such values (see an example of this above).
@note the join columns do not need to be specified in the case that a foreign key in one table exists to the primary key of the other table; in this case this information is assumed for the join automatically
@see @ref joins for more examples
@subsubsection select_option_groupby Select Option "groupby"
<b>Groupby Example:</b>
@code{.py}
hash sh = (
"columns": (
cop_as(cop_max("service_type"), "type"),
cop_count(),
),
"groupby": "service_type",
);
*list rows = table.selectRows(sh);
@endcode
The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
The \c "groupby" hash key should be assigned to a list of column specifiers or a single column specifier. Column specifiers for the \c "groupby"
key are strings giving column names, optionally in dot notation or positive column numbers.
@subsubsection select_option_having Select Option "having"
<b>Having Example:</b>
@code{.py}
hash sh = (
"columns": (
cop_as(cop_max("service_type"), "type"),
cop_count(),
),
"groupby": "service_type",
"having": (
"service_type": (COP_COUNT, op_ge(100)),
),
);
*list rows = table.selectRows(sh);
@endcode
The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
The \c "having" hash key should be assigned to a hash where each key is a column specifier (optionally in dot notation) and the values are lists with two elements; the first element must be a @ref sql_cops "column operator code", and the second element is a column operator description normally provided by using a @ref sql_cop_funcs "column operator function" as in the above example.
@subsubsection select_option_superquery Select Option "superquery"
<b>Superquery Example:</b>
@code{.py}
hash sh = (
"columns": (
"serviceid", "service_methodid",
cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid"),
),
"superquery": (
"columns": ("serviceid", "service_methodid"),
"where": ("max_methodid": op_ceq("service_methodid")),
),
);
*list rows = table.selectRows(sh);
@endcode
The \c "superquery" option allows for the rest of the query arguments to define a subquery where as the hash arguments assigned to the \c "superquery" key define the select made from the subquery. In the example above, the \c "OVER" sql windowing function is used and then rows matching the \c "max_methodid)" result value are selected.\n\n
The above example results in an SQL command equivalent to the following:
@code{.py}
*list rows = table.vselectRows("select serviceid,service_methodid from (select serviceid,service_methodid,max(service_methodid) over (partition by serviceid) as max_methodid from schema.service_methods) subquery where max_methodid = service_methodid");
@endcode
@note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
@subsubsection select_option_forupdate Select Option "forupdate"
<b>For Update Example:</b>
@code{.py}
on_success ds.commit();
on_error ds.rollback();
hash sh = (
"columns": ("serviceid", "service_methodid"),
"forupdate": True,
)
*list rows = table.selectRows(sh);
@endcode
\n The \c "forupdate" option allows for the rows selected to be locked for updating; to release the locks, call commit() or rollback() on the underlying datasource object.
The above example results in an SQL commit equivalent to the following:
@code{.py}
*list rows = table.vselectRows("select serviceid,service_methodid from schema.service_methods for update");
@endcode
@subsection sql_paging Select With Paging
There is support for paging query results in the following methods:
- @ref SqlUtil::AbstractTable::getRowIterator()
- @ref SqlUtil::AbstractTable::getSelectSql()
- @ref SqlUtil::AbstractTable::select()
- @ref SqlUtil::AbstractTable::selectRows()
@note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
Each of these methods takes a @ref select_option_hash "select option hash argument" that allows the \c "limit" and \c "offset" options to be specified to specify the data window for the results.
If the \c "offset" options is used, then an \c "orderby" option is required which must match some unique constraint or unique index on the table to guarantee the order of results, unless the table has a primary key, in which case the primary key will be used by default if no \c "orderby" option is supplied.
@par Example:
Select 100 rows starting at row 200 (the table's primary key will be used for the \c "orderby" option by default): \n
@code{.py}
*list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
@endcode
As an illustration of the different SQL that is generated for different database types; for the above query, here is the SQL generated for Oracle:
@code{.py}
ds.vselectRows("select * from (select /*+ first_rows(100) */ a.*, rownum rnum from (select * from schema.table where type = %v order by type) a where rownum <= %v) where rnum > %v", ("user", 300, 200));
@endcode
And for PostgreSQL:
@code{.py}
ds.vselectRows("select * from public.table where type = %v order by type limit %v offset %v", ("user", 100, 200));
@endcode
@subsection check_matching_rows Check For At Least One Matching Row
Use the @ref SqlUtil::AbstractTable::findSingle() method to find at least one matching row:
@code{.py}
*hash h = table.findSingle(("account_type": "CUSTOMER"));
if (h)
printf("found 1 customer row: %y\n", l[0]);
@endcode
Also it's possible to use the \c "limit" option to make an efficient check for at least one matching row as in the following example (which is functionally equivalent to the previous example):
@code{.py}
*hash h = table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
if (h)
printf("found 1 customer row: %y\n", l[0]);
@endcode
@section inserting_data Inserting Data into the Database
The following methods can be used to insert data into the database:
- @ref SqlUtil::AbstractTable::insert(): inserts a single row into a table without committing the transaction
- @ref SqlUtil::AbstractTable::insertCommit(): inserts a single row into a table and commits the transaction
- @ref SqlUtil::AbstractTable::insertFromSelect(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and without committing the transaction
- @ref SqlUtil::AbstractTable::insertFromSelectCommit(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and commits the transaction
@see @ref sql_upsert for information about upserting or merging data
@subsection inserting_data_explicitly Inserting Data Explicitly
@par Example:
@code{.py}
table.insert(("id": id, "name": name, "created": now_us()));
@endcode
Data can be explicitly inserted into the database with immediate values with @ref SqlUtil::AbstractTable::insert() and @ref SqlUtil::AbstractTable::insertCommit() as in the above example.
Additionally, instead of giving a literal value to be inserted, @ref sql_iop_funcs can be used to insert values based on SQL operations used directly in the insert statement.
@subsection inserting_data_from_select Inserting Data From a Select Statement
@par Example:
@code{.py}
int rows = table.insertFromSelect(("id", "name", "created"), source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER"))));
@endcode
Data can be inserted into the database based on the results of a select statement with @ref SqlUtil::AbstractTable::insertFromSelect() and @ref SqlUtil::AbstractTable::insertFromSelectCommit() as in the above example.
The example above would generate a %Qore SQL command like the following:
@code{.py}
return ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER"));
@endcode
The return value of these methods is the number of rows inserted. See @ref select_option_hash "select option hash" for more information about how to form the select criteria in these methods.
@subsection inserting_data_from_iterator Inserting Data from an Iterator Source
To insert data from an iterator source (such as an @ref Qore::SQL::SQLStatement object), call @ref SqlUtil::AbstractTable::insertFromIterator() or @ref SqlUtil::AbstractTable::insertFromIteratorCommit() as in the following example:
@par Example:
@code{.py}
# get the rows to be inserted
list l = get_table_rows();
# insert the data and commit after every 5000 rows
table.insertFromIterator(l.iterator(), ("commit_block": 5000));
@endcode
The iterator given to the @ref SqlUtil::AbstractTable::insertFromIterator() or @ref SqlUtil::AbstractTable::insertFromIteratorCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
@note the @ref SqlUtil::AbstractTable::InsertFromIteratorOptions "insert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
@section updating_data Updating Data
The following methods can be used to update data:
- @ref SqlUtil::AbstractTable::update(): updates a single row and does not commit the transaction
- @ref SqlUtil::AbstractTable::updateCommit(): updates a single row and commits the transaction
@par Example:
@code{.py}
int rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
@endcode
The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
@code{.py}
return ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
@endcode
And the following on MySQL:
@code{.py}
return ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
@endcode
@section deleting_data Deleting Data
The following methods can be used to dekete data:
- @ref SqlUtil::AbstractTable::del(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
- @ref SqlUtil::AbstractTable::delCommit(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
- @ref SqlUtil::AbstractTable::truncate(): truncates the table and does not commit the transaction
- @ref SqlUtil::AbstractTable::truncateCommit(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
@par Example:
@code{.py}
int dcnt = table.del(("record_type": "OLD-CUSTOMER"));
@endcode
The above example would generate a %Qore SQL command like the following:
@code{.py}
return ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
@endcode
The @ref SqlUtil::AbstractTable::del() and @ref SqlUtil::AbstractTable::delCommit() methods can be used to delete data from the database.
See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
@section joins Joining Tables
Joining tables is made by providing a join specification to the @ref select_option_join "join select option" in
a @ref select_option_hash "select option hash" as in the following example:
@code{.py}
*list rows = table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner(table2, "t2", ("id": "altid"))));
@endcode
In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
Joins on multiple tables are performed by combining the results of @ref sql_jop_funcs "join functions" with the @ref plus_operator "+ operator"
as follows:
@code{.py}
*list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner(table3, "t3")));
@endcode
In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
automatically detected primary key to foreign key relationship between the two tables.
Joins are by default made with the primary table; to join with another join table, then give the alias for the table as the first
argument to the @ref sql_jop_funcs "join function" as in the following example:
@code{.py}
*list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner("t2", table3, "t3")));
@endcode
In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and \a table2 (aliased as \c t2) is joined
with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
@see @ref select_option_join "join select option"
@section where_clauses Where Clauses
Several methods accept a hash of conditions to build a \c "where" clause to restrict the rows that are operated on or returned; for example:
- @ref SqlUtil::AbstractTable::del()
- @ref SqlUtil::AbstractTable::delCommit()
- @ref SqlUtil::AbstractTable::findAll()
- @ref SqlUtil::AbstractTable::findSingle()
- @ref SqlUtil::AbstractTable::getRowIterator()
- @ref SqlUtil::AbstractTable::getSelectSql()
- @ref SqlUtil::AbstractTable::insertFromSelect()
- @ref SqlUtil::AbstractTable::insertFromSelectCommit()
- @ref SqlUtil::AbstractTable::select()
- @ref SqlUtil::AbstractTable::selectRow()
- @ref SqlUtil::AbstractTable::selectRows()
- @ref SqlUtil::AbstractTable::update()
- @ref SqlUtil::AbstractTable::updateCommit()
- @ref SqlUtil::AbstractTable::upsertFromSelect()
- @ref SqlUtil::AbstractTable::upsertFromSelectCommit()
@note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
The where clause or condition hash is made of keys signifying the column names, and either a direct value meaning that the column value has to match exactly, or SQL operators can be given by using the appropriate operator function as the key value. Each member of the where hash translates to an expression that is combined with \c "AND" in the SQL query; to combine expressions with \c "OR", there are two options:
- use the @ref SqlUtil::wop_or() function to combine where expressions with the \c "or" operator
- use a list of @ref select_option_hash "select option hashes", which will combine each @ref select_option_hash "select option hash" with \c "OR" as in @ref where_list "this example".
The where condition hash has the following format:
- each key gives a column name or a table/alias with column name in dot notation
- the values are either direct values, meaning that the equality operator (\c "=") is used, or a @ref sql_op_funcs "SQL operator function" for operators in the where clause
@note To reference a column more than once in a where clause, prefix the column specification with a unique number and a colon as in the following example: @code{.py} hash w = ("0:created": op_ge(mindate), "1:created": op_lt(maxdate)); @endcode
See @ref sql_op_funcs for a list of operator functions.
@par Where Hash Example:
@code{.py}
hash w = (
"name": "Smith",
"account_type": op_like("%CUSTOMER%"),
"id": op_ge(500),
);
@endcode \n
The preceding example results in a where clause equivalent to: \c "name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
that bind by value is used, so, if used in a context like the following:
@code{.py}
Table t(ds, "table");
*hash qh = t.select(("where": w));
@endcode \n
the complete query would look instead as follows:
@code{.py}
ds.vselect("select * from table where name = %v and account_type like %v and id >= %v", ("Smith", "%CUSTOMER%", 500));
@endcode
@anchor where_list
@par Where List Example:
@code{.py}
hash w1 = (
"name": "Smith",
"account_type": op_like("%CUSTOMER%"),
"id": op_ge(500),
);
hash w2 = (
"name": "Jones",
"account_type": op_like("%VENDOR%"),
"id": op_ge(2500),
);
Table t(ds, "table");
*hash qh = t.select(("where": (w1, w2)));
@endcode \n
the complete query would look instead as follows:
@code{.py}
ds.vselect("select * from table where (name = %v and account_type like %v and id >= %v) or (name = %v and account_type like %v and id >= %v)", ("Smith", "%CUSTOMER%", 500, "Jones", "%VENDOR%", 2500));
@endcode
@par Code Examples:
Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
@code{.py}
*hash row = table.findSingle(("permission_type": op_between("US", "UX")));
@endcode
resulting in an internal SQL command that looks as follows (depending on the database):
@code{.py}
*hash row = ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
@endcode \n
Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
@code{.py}
int row_count = table.del(("name": op_like("%Smith%")));
@endcode
resulting in an internal SQL command that looks as follows:
@code{.py}
ds.vexec("delete from table where name like %v", ("%Smith%"));
@endcode \n
Find all rows where \c "id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
@code{.py}
*list rows = table.findAll(("id": op_gt(100), "created": op_gt(2013-03-01)));
@endcode
resulting in an internal SQL command that looks as follows:
@code{.py}
ds.vexec("select * from table where id > %v and created > %v", (100, 2013-03-01));
@endcode \n
@section sql_upsert Upserting or Merging Data
This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
- @ref SqlUtil::AbstractTable::upsert()
- @ref SqlUtil::AbstractTable::upsertCommit()
- @ref SqlUtil::AbstractTable::getUpsertClosure()
- @ref SqlUtil::AbstractTable::getUpsertClosureWithValidation()
- @ref SqlUtil::AbstractTable::upsertFromIterator()
- @ref SqlUtil::AbstractTable::upsertFromIteratorCommit()
- @ref SqlUtil::AbstractTable::upsertFromSelect()
- @ref SqlUtil::AbstractTable::upsertFromSelectCommit()
@subsection sql_upsert_single Upsert a Single Row
@par Example:
@code{.py}
table.upsert(("id": id, "name": name, "account_type": account_type));
@endcode
To upsert or merge a single row in the database, call @ref SqlUtil::AbstractTable::upsert() or @ref SqlUtil::AbstractTable::upsertCommit() with the
single row to be upserted or merged as a hash as in the preceding example.
@subsection sql_upsert_many Upserting Many Rows Using An Upsert Closure
To upsert or merge many rows by using an upsert closure, call @ref SqlUtil::AbstractTable::getUpsertClosure() or @ref SqlUtil::AbstractTable::getUpsertClosureWithValidation() and provide an example row as an argument to acquire a closure that will be executed on the rest of the rows as in the following example.
@par Simple Example:
@code{.py}
# get the rows to be inserted
list l = get_table_rows();
if (l) {
code upsert = table.getUpsertClosure(l[0]);
on_success ds.commit();
on_error ds.rollback();
# loop through the reference data rows
map upsert($1), l;
}
@endcode
@par Complex Example With Callbacks:
@code{.py}
# set the upsert strategy depending on the use case
int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
# hash summarizing changes
hash sh;
# get the rows to be inserted
list l = get_table_rows();
if (l) {
# get the upsert closure to use based on the first row to be inserted
code upsert = table.getUpsertClosure(l[0], upsert_strategy);
on_success ds.commit();
on_error ds.rollback();
# loop through the reference data rows
foreach hash h in (l) {
int code = upsert(h);
if (code == AbstractTable::UR_Unchanged)
continue;
string change = AbstractTable::UpsertResultMap{code};
++sh{change};
if (!verbose) {
printf(".");
flush();
}
else if (verbose > 1)
printf("*** reference data %s: %y: %s\n", table.getName(), h, change);
}
# show table summary
if (sh)
printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
else
printf("*** reference data %s: OK\n", table.getName());
}
@endcode
@subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
To upsert or merge many rows from an iterator source (such as an @ref Qore::SQL::SQLStatement object), call @ref SqlUtil::AbstractTable::upsertFromIterator() or @ref SqlUtil::AbstractTable::upsertFromIteratorCommit() as in the following example:
@par Simple Example:
@code{.py}
# get the rows to be inserted
list l = get_table_rows();
table.upsertFromIterator(l.iterator());
@endcode
@par Complex Example With Callbacks:
@code{.py}
# set the upsert strategy depending on the use case
int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
# get the rows to be inserted
list l = get_table_rows();
code callback = sub (string table_name, hash row, int result) {
if (result == AbstractTable::UR_Unchanged)
return;
string change = AbstractTable::UpsertResultMap{result};
if (verbose)
printf("*** reference data %s: %y: %s\n", table_name, row, change);
};
hash sh = table.upsertFromIterator(l.iterator(), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
if (sh)
printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
else
printf("*** reference data %s: OK\n", table.getName());
@endcode
The iterator given to the @ref SqlUtil::AbstractTable::upsertFromIterator() or @ref SqlUtil::AbstractTable::upsertFromIteratorCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
@note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
@subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
To upsert or merge many rows from a select statement, use @ref SqlUtil::AbstractTable::upsertFromSelect() or @ref SqlUtil::AbstractTable::upsertFromSelectCommit() as in the following example:
@par Simple Example:
@code{.py}
table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")));
@endcode
@par Complex Example With Callbacks:
@code{.py}
# set the upsert strategy depending on the use case
int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
code callback = sub (string table_name, hash row, int result) {
if (result == AbstractTable::UR_Unchanged)
return;
string change = AbstractTable::UpsertResultMap{result};
if (verbose)
printf("*** reference data %s: %y: %s\n", table_name, row, change);
};
hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
if (sh)
printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
else
printf("*** reference data %s: OK\n", table.getName());
@endcode
The source table does not have to be in the same database or even of the same database type (ie you can upsert to and from any database type supported by SqlUtil).
@note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
@subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
Call any of the batch upsert methods with @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c delete_others set to @ref Qore::True "True" to perform a batch upsert / merge operation on a table, and then scan the table and delete any unwanted rows. If there are no rows to be deleted, these calls have very similar performance to the batch upsert method calls without any deletions, however, if there are rows to be deleted, then the entire source table must be iterated to compare each row to valid data to delete the rows that do not belong. Therefore for large tables this can be an expensive operation.
The only difference in the following examples and the preceding ones is that @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c delete_others is @ref Qore::True "True" in these examples.
@par Simple Example:
@code{.py}
# get the rows to be inserted
list l = get_table_rows();
table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
@endcode
@par Complex Example With Callbacks:
@code{.py}
# set the upsert strategy depending on the use case
int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
# get the rows to be inserted
list l = get_table_rows();
code callback = sub (string table_name, hash row, int result) {
if (result == AbstractTable::UR_Unchanged)
return;
string change = AbstractTable::UpsertResultMap{result};
if (verbose)
printf("*** reference data %s: %y: %s\n", table_name, row, change);
};
hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, ("delete_others": True, "info_callback": callback, "commit_block": 5000));
if (sh)
printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
else
printf("*** reference data %s: OK\n", table.getName());
@endcode
@note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
@subsection sql_upsert_strategies Upsert Strategies
The approach used is based on one of the following strategies (see @ref upsert_options):
- @ref SqlUtil::AbstractTable::UpsertAuto "AbstractTable::UpsertAuto": if the target table is empty, then @ref SqlUtil::AbstractTable::UpsertInsertFirst is used, otherwise @ref SqlUtil::AbstractTable::UpsertUpdateFirst is used; note that if a driver-specific optimized version of the upsert operation is implemented, this strategy will normally result in the best performance
- @ref SqlUtil::AbstractTable::UpsertInsertFirst "AbstractTable::UpsertInsertFirst": first an insert will be attempted, if it fails due to a duplicate key, then an update will be made; this strategy should be used if more inserts will be made than updates
- @ref SqlUtil::AbstractTable::UpsertUpdateFirst "AbstractTable::UpsertUpdateFirst": first an update will be attempted, if it fails due to missing data, then an insert is performed; this strategy should be used if more updates will be made then inserts
- @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst": first a select is made on the unique key, if the data to be updated is equal, nothing is done and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
- @ref SqlUtil::AbstractTable::UpsertInsertOnly "AbstractTable::UpsertInsertOnly": insert if the row doesn't exist, otherwise do nothing and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
- @ref SqlUtil::AbstractTable::UpsertUpdateOnly "AbstractTable::UpsertUpdateOnly": update if the row exists, otherwise do nothing and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
@note @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" is the only upsert strategy that can return @ref SqlUtil::AbstractTable::UR_Updated; the @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" strategy should be used when verbose reporting is required, particularly if it's necessary to report the actual number of changed rows.
*/
namespace SqlUtil {
public struct GenericColumnInfo {
string qore_type;
string native_type;
softint size;
softint scale;
any default_value;
bool default_value_native = False;
*string comment;
bool notnull = False;
hash<string, hash> driver;
*bool auto_increment;
};
public struct OperatorInfo {
string op;
any arg;
};
public struct ColumnOperatorInfo {
string cop;
any column;
any arg;
};
public struct InsertOperatorInfo {
string _iop;
any arg;
};
public struct UpdateOperatorInfo {
string uop;
any arg;
*hash nest;
};
public struct JoinOperatorInfo {
string jop;
any table;
*string alias;
*hash jcols;
*hash cond;
*string ta;
*hash opt;
};
/* @defgroup DBFeaturesConstants DB Features Constants
These constants can be used as a lookup values in AbstractDatabase::features() method.
*/
const DB_FUNCTIONS = "functions";
const DB_MVIEWS = "materialized views";
const DB_PACKAGES = "packages";
const DB_PROCEDURES = "procedures";
const DB_SEQUENCES = "sequences";
const DB_TABLES = "tables";
const DB_TYPES = "named types";
const DB_VIEWS = "views";
const DB_SYNONYMS = "synonyms";
/* @defgroup SqlTypeConstants SQL Type Constants
These constants can be used for the \c "qore_type" values when creating columns to specify additional SQL column types
*/
const VARCHAR = "string";
const NUMERIC = "number";
const CHAR = "char";
const BLOB = "blob";
const CLOB = "clob";
const SZ_NONE = 0;
const SZ_MAND = 1;
const SZ_OPT = 2;
const SZ_NUM = 3;
const COP_AS = "as";
const COP_CAST = "cast";
const COP_PREPEND = "prepend";
const COP_APPEND = "append";
const COP_VALUE = "value";
const COP_UPPER = "upper";
const COP_LOWER = "lower";
const COP_DISTINCT = "distinct";
const COP_MIN = "min";
const COP_MAX = "max";
const COP_AVG = "avg";
const COP_SUM = "sum";
const COP_COUNT = "count";
const COP_OVER = "over";
const COP_MINUS = "minus";
const COP_PLUS = "plus";
const COP_DIVIDE = "divide";
const COP_MULTIPLY = "multiply";
const COP_YEAR = "year";
const COP_YEAR_MONTH = "year_month";
const COP_YEAR_DAY = "year_day";
const COP_YEAR_HOUR = "year_hour";
const COP_SEQ = "seq";
const COP_SEQ_CURRVAL = "seq_currval";
const COP_COALESCE = "coalesce";
const COP_SUBSTR = "substr";
const COP_LENGTH = "length";
const COP_TRUNC_DATE = "truncate_date";
const COP_CUME_DIST = "cume_dist";
const COP_DENSE_RANK = "dense_rank";
const COP_FIRST_VALUE = "first_value";
const COP_LAST_VALUE = "last_value";
const COP_NTILE = "ntile";
const COP_PERCENT_RANK = "percent_rank";
const COP_RANK = "rank";
const COP_ROW_NUMBER = "row_number";
const DefaultCopMap = (
COP_AS: (
"arg": Type::String,
"withalias": True,
"code": string (string cve, string arg, reference psch) {
// issue #2163: make sure the unquoted alias is inserted in the map
if (arg ==1)
psch{arg.substr(1, -1)} = cve;
else
psch{arg} = cve;
return sprintf("%s as %s", cve, arg);
},
),
COP_PREPEND: (
"arg": Type::String,
"sqlvalue": True,
"code": string (string cve, string arg) {
return sprintf("%s || %s", arg, cve);
},
),
COP_APPEND: (
"arg": Type::String,
"sqlvalue": True,
"code": string (string cve, string arg) {
return sprintf("%s || %s", cve, arg);
},
),
COP_VALUE: (
"sqlvalue": True,
"nocolumn": True,
"code": string (*string cve, auto arg) {
return arg;
},
),
COP_UPPER: (
"code": string (string cve, auto arg) {
return sprintf("upper(%s)", cve);
},
),
COP_LOWER: (
"code": string (string cve, auto arg) {
return sprintf("lower(%s)", cve);
},
),
COP_DISTINCT: (
"code": string (string cve, auto arg) {
return sprintf("distinct %s", cve);
},
),
COP_MIN: (
"code": string (string cve, auto arg) {
return sprintf("min(%s)", cve);
},
"group": True,
),
COP_MAX: (
"code": string (string cve, auto arg) {
return sprintf("max(%s)", cve);
},
"group": True,
),
COP_AVG: (
"code": string (string cve, auto arg) {
return sprintf("avg(%s)", cve);
},
"group": True,
),
COP_SUM: (
"code": string (string cve, auto arg) {
return sprintf("sum(%s)", cve);
},
"group": True,
),
COP_COUNT: (
"nocolumn": True,
"code": string (*string cve, auto arg) {
return sprintf("count(%s)", cve ? cve : "*");
},
),
COP_MINUS: (
"argcolumn": True,
"code": string (string arg1, string arg2) {
return sprintf("%s - %s", arg1, arg2);
},
),
COP_PLUS: (
"argcolumn": True,
"code": string (string arg1, string arg2) {
return sprintf("%s + %s", arg1, arg2);
},
),
COP_DIVIDE: (
"argcolumn": True,
"code": string (string arg1, string arg2) {
return sprintf("%s / %s", arg1, arg2);
},
),
COP_MULTIPLY: (
"argcolumn": True,
"code": string (string arg1, string arg2) {
return sprintf("%s * %s", arg1, arg2);
},
),
COP_SEQ: (
"nocolumn": True,
"code": string (*string cve, hash arg) {
throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg.seq);
}
),
COP_SEQ_CURRVAL: (
"nocolumn": True,
"code": string (*string cve, hash arg) {
throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg.seq);
}
),
COP_COALESCE: (
"columnargs": True,
"code": string (*string cve, hash arg) {
return sprintf("coalesce(%s)", (foldl $1 + "," + $2, arg.args));
}
),
COP_SUBSTR: (
"code": string (string cve, list args) {
if (!exists args[1])
return sprintf("substring(%s from %d)", cve, args[0]);
return sprintf("substring(%s from %d for %d)", cve, args[0], args[1]);
},
),
COP_LENGTH: (
"code": string (string cve, auto arg) {
return sprintf("length(%s)", cve);
},
),
COP_OVER: (
"columnargs" : True,
"columnargs_ignore_nothings" : True,
"code": string (*string cve, hash args)
{
*string partitionby = args.args[0];
*string orderby = args.args[1];
if (!exists partitionby && exists orderby);
string sql = cve + " over (";
if (exists partitionby)
sql += sprintf("partition by %s", partitionby); // TODO/FIXME: sql injection!
if (exists orderby)
sql += sprintf(" order by %s", orderby); // TODO/FIXME: sql injection!
sql += ")";
return sql;
},
),
COP_CUME_DIST: (
"nocolumn": True,
"code": string (*string cve, any arg) {
return "cume_dist()";
},
),
COP_DENSE_RANK: (
"nocolumn": True,
"code": string (*string cve, any arg) {
return "dense_rank()";
},
),
COP_FIRST_VALUE: (
"code": string (string cve) {
return sprintf("first_value(%s)", cve);
},
),
COP_LAST_VALUE: (
"code": string (string cve) {
return sprintf("last_value(%s)", cve);
},
),
COP_NTILE: (
"sqlvalue": True,
"nocolumn": True,
"code": string (*string cve, any arg) {
return sprintf("ntile(%d)", arg);
},
),
COP_PERCENT_RANK: (
"nocolumn": True,
"code": string (*string cve, any arg) {
return "percent_rank()";
},
),
COP_RANK: (
"nocolumn": True,
"code": string (*string cve, any arg) {
return "rank()";
},
),
COP_ROW_NUMBER: (
"nocolumn": True,
"code": string (*string cve, any arg) {
return "row_number()";
},
),
);
hash<ColumnOperatorInfo> make_cop(string cop, auto column, auto arg);
hash<ColumnOperatorInfo> cop_as(auto column, string arg);
hash<ColumnOperatorInfo> cop_cast(auto column, string arg, auto arg1, auto arg2);
hash<ColumnOperatorInfo> cop_prepend(auto column, string arg);
hash<ColumnOperatorInfo> cop_append(auto column, string arg);
hash<ColumnOperatorInfo> cop_value(auto arg);
hash<ColumnOperatorInfo> cop_upper(auto column);
hash<ColumnOperatorInfo> cop_lower(auto column);
hash<ColumnOperatorInfo> cop_distinct(auto column);
hash<ColumnOperatorInfo> cop_min(auto column);
hash<ColumnOperatorInfo> cop_max(auto column);
hash<ColumnOperatorInfo> cop_avg(auto column);
hash<ColumnOperatorInfo> cop_sum(auto column);
hash<ColumnOperatorInfo> cop_count(auto column = "");
hash<ColumnOperatorInfo> cop_over(auto column, *string partitionby, *string orderby);
hash<ColumnOperatorInfo> cop_minus(auto column1, auto column2);
hash<ColumnOperatorInfo> cop_plus(auto column1, auto column2);
hash<ColumnOperatorInfo> cop_divide(auto column1, auto column2);
hash<ColumnOperatorInfo> cop_multiply(auto column1, auto column2);
hash<ColumnOperatorInfo> cop_year(auto column);
hash<ColumnOperatorInfo> cop_year_month(auto column);
hash<ColumnOperatorInfo> cop_year_day(auto column);
hash<ColumnOperatorInfo> cop_year_hour(auto column);
hash<ColumnOperatorInfo> cop_seq(string seq, *string as);
hash<ColumnOperatorInfo> cop_seq_currval(string seq, *string as);
hash<ColumnOperatorInfo> cop_coalesce(auto col1, auto col2);
hash<ColumnOperatorInfo> cop_substr(auto column, int start, *int count);
hash<ColumnOperatorInfo> cop_length(auto column);
hash<ColumnOperatorInfo> cop_trunc_date(auto column, string mask);
hash<ColumnOperatorInfo> cop_cume_dist();
hash<ColumnOperatorInfo> cop_dense_rank();
hash<ColumnOperatorInfo> cop_first_value(any column);
hash<ColumnOperatorInfo> cop_last_value(any column);
hash<ColumnOperatorInfo> cop_ntile(int value);
hash<ColumnOperatorInfo> cop_percent_rank();
hash<ColumnOperatorInfo> cop_rank();
hash<ColumnOperatorInfo> cop_row_number();
const DT_YEAR = "Y";
const DT_MONTH = "M";
const DT_DAY = "D";
const DT_HOUR = "H";
const DT_MINUTE = "m";
const DT_SECOND = "S";
// let's simulate and enum here'
const DT_ALL_VALUES = ( DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND );
const DefaultUopMap = (
COP_PREPEND: True,
COP_APPEND: True,
COP_UPPER: True,
COP_LOWER: True,
COP_MINUS: (
"sqlvalue": True,
"code": string (string cve, auto arg) {
return sprintf("%s - %s", cve, arg);
},
),
COP_PLUS: (
"sqlvalue": True,
"code": string (string cve, auto arg) {
return sprintf("%s + %s", cve, arg);
},
),
COP_DIVIDE: (
"sqlvalue": True,
"code": string (string cve, auto arg) {
return sprintf("%s / %s", cve, arg);
},
),
COP_MULTIPLY: (
"sqlvalue": True,
"code": string (string cve, auto arg) {
return sprintf("%s * %s", cve, arg);
},
),
COP_SUBSTR: True,
COP_SEQ: (
"nocolumn": True,
"code": string (*string cve, string arg) {
throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg);
}
),
COP_SEQ_CURRVAL: (
"nocolumn": True,
"code": string (*string cve, string arg) {
throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg);
}
),
COP_COALESCE: (
"columnargs": True,
"code": string (*string cve, softlist args) {
return sprintf("coalesce(%s)", (foldl $1 + "," + $2, args));
}
),
);
hash<UpdateOperatorInfo> make_uop(string uop, auto arg, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_prepend(string arg, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_append(string arg, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_upper(*hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_lower(*hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_substr(int start, *int count, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_plus(auto arg, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_minus(auto arg, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_multiply(auto arg, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_divide(auto arg, *hash<UpdateOperatorInfo> nest);
hash<UpdateOperatorInfo> uop_seq(string seq);
hash<UpdateOperatorInfo> uop_seq_currval(string seq);
const JOP_INNER = "inner";
const JOP_LEFT = "left";
const JOP_RIGHT = "right";
const JopMap = (
JOP_INNER: "inner",
JOP_LEFT: "left outer",
JOP_RIGHT: "right outer",
);
hash<string, hash<JoinOperatorInfo>> make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
hash<string, hash<JoinOperatorInfo>> make_jop(string jop, string table_name, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_inner(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_left(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_right(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash<string, hash<JoinOperatorInfo>> join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
const OP_LIKE = "like";
const OP_LT = "<";
const OP_LE = "<=";
const OP_GT = ">";
const OP_GE = ">=";
const OP_NE = "!=";
const OP_EQ = "=";
const OP_CLT = "C<";
const OP_CLE = "C<=";
const OP_CGT = "C>";
const OP_CGE = "C>=";
const OP_CNE = "C!=";
const OP_CEQ = "C=";
const OP_BETWEEN = "between";
const OP_IN = "in";
const OP_NOT = "not";
const OP_SUBSTR = "substr";
const OP_OR = "or";
const DefaultOpMap = (
OP_LIKE: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
args += arg;
return sprintf("%s like %v", cn);
},
),
OP_LT: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
args += arg;
return sprintf("%s < %v", cn);
},
),
OP_LE: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
args += arg;
return sprintf("%s <= %v", cn);
},
),
OP_GT: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
args += arg;
return sprintf("%s > %v", cn);
},
),
OP_GE: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
args += arg;
return sprintf("%s >= %v", cn);
},
),
OP_NE: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
if (arg === NULL || !exists arg)
return sprintf("%s is not null", cn);
args += arg;
return sprintf("(%s != %v or %s is null)", cn, cn);
},
),
OP_EQ: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
if (arg === NULL || !exists arg)
return sprintf("%s is null", cn);
args += arg;
return sprintf("%s = %v", cn);
},
),
OP_BETWEEN: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
args += arg[0];
args += arg[1];
return sprintf("%s between %v and %v", cn);
},
),
OP_IN: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
*string ins = (foldl $1 + "," + $2, (map t.getSqlValue($1), arg));
return exists ins ? sprintf("%s in (%s)", cn, ins) : "1 != 1";
},
),
OP_NOT: (
"recursive": True,
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("not (%s)", cn);
},
),
OP_CLT: (
"argcolumn": True,
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("%s < %s", cn, arg);
},
),
OP_CLE: (
"argcolumn": True,
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("%s <= %s", cn, arg);
},
),
OP_CGT: (
"argcolumn": True,
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("%s > %s", cn, arg);
},
),
OP_CGE: (
"argcolumn": True,
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("%s >= %s", cn, arg);
},
),
OP_CNE: (
"argcolumn": True,
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("%s != %s", cn, arg);
},
),
OP_CEQ: (
"argcolumn": True,
"code": string (object t, string cn, string arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("%s = %s", cn, arg);
},
),
OP_SUBSTR: (
"code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
args += arg[0]; // start
if (!exists arg[1]);
args += arg[1]; // count
args += arg[2]; // text
return sprintf("substring(%s from %v for %v) = %v", cn);
},
),
OP_OR: (
"code": string (object t, string cn, list arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
return t.getOrClause(arg, \args, jch, join, ch, psch);
},
),
);
hash<OperatorInfo> make_op(string op, auto arg);
hash<OperatorInfo> op_like(string str);
hash<OperatorInfo> op_lt(auto arg);
hash<OperatorInfo> op_le(auto arg);
hash<OperatorInfo> op_gt(auto arg);
hash<OperatorInfo> op_ge(auto arg);
hash<OperatorInfo> op_ne(auto arg);
hash<OperatorInfo> op_eq(auto arg);
hash<OperatorInfo> op_between(auto l, auto r);
hash<OperatorInfo> op_in();
hash<OperatorInfo> op_in(list args);
hash<OperatorInfo> op_not(hash arg);
hash<OperatorInfo> op_clt(string arg);
hash<OperatorInfo> op_cle(string arg);
hash<OperatorInfo> op_cgt(string arg);
hash<OperatorInfo> op_cge(string arg);
hash<OperatorInfo> op_cne(string arg);
hash<OperatorInfo> op_ceq(string arg);
hash<OperatorInfo> op_substr(int start, *int count, string text);
hash<OperatorInfo> op_substr(int start, string text);
hash<string, hash<OperatorInfo>> wop_or(hash h1, hash h2);
const IOP_SEQ = "seq";
const IOP_SEQ_CURRVAL = "seq_currval";
const DefaultIopMap = {};
hash<InsertOperatorInfo> make_iop(string iop, auto arg);
hash<InsertOperatorInfo> iop_seq(string arg);
hash<InsertOperatorInfo> iop_seq_currval(string arg);
const SqlUtilDrivers = (
"oracle",
"pgsql",
"mysql",
"freetds",
"sybase",
);
class AbstractHashContainer {
public:
private:
public:
private :
*hash h;
public:
constructor(*hash nh);
constructor(AbstractHashContainer old);
copy(AbstractHashContainer old);
auto memberGate(string k);
clear();
abstract auto take(string k);
renameKey(string old_name, string new_name);
*hash getHash();
bool matchKeys(hash h1);
bool matchKeys(list l);
bool matchKeys(AbstractHashContainer c);
bool partialMatchKeys(hash h1);
bool partialMatchKeys(list l);
bool partialMatchKeys(AbstractHashContainer c);
bool val();
list<string> keys();
list values();
Qore::AbstractIterator iterator();
Qore::AbstractIterator keyIterator();
Qore::AbstractIterator pairIterator();
bool empty();
int size();
bool hasKey(string k);
bool hasKeyValue(string k);
*string firstKey();
*string lastKey();
abstract string getElementName();
};
class AbstractListContainer {
public:
private:
public:
private :
softlist l;
public:
constructor(softlist nl);
abstract auto get(softint i);
add(auto val);
auto take(int i);
list getList();
bool val();
Qore::ListIterator iterator();
bool empty();
int size();
abstract string getElementName();
private:
checkIndex(int i);
public:
};
class Tables : public AbstractHashContainer {
public:
constructor();
constructor(AbstractDatasource ds, hash tables, *hash opt);
constructor(AbstractDatasource ds);
add(string k, Table val);
add(string k, AbstractTable val);
add(Table val);
add(AbstractTable val);
AbstractTable take(string k);
populate(AbstractDatasource ds, hash tables, *hash opt);
populate(AbstractDatasource ds);
*list getDropAllForeignConstraintsOnTableSql(string name, *hash opt);
AbstractTable memberGate(string k);
string getElementName();
*AbstractTable getIfExists(AbstractDatasource ds, string name);
AbstractTable get(AbstractDatasource ds, string name);
*string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts);
bool tableRenamed(string old_name, string new_name, string old_sql_name);
private:
tableRenamedIntern(string old_name, string new_name, string oldsn);
public:
*string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
list getCreateList();
Qore::AbstractIterator createIterator();
list getDropList();
Qore::AbstractIterator dropIterator();
private:
getDependencies(reference<hash> tdh, reference<hash> sdh, *reference<hash> th);
public:
};
class Columns : public AbstractHashContainer {
public:
constructor(*hash c) ;
constructor(Columns old) ;
add(string k, AbstractColumn val);
AbstractColumn take(string k);
AbstractColumn memberGate(string k);
Columns subset(softlist l);
string getElementName();
bool equal(Columns cols);
};
class AbstractColumn {
public:
public :
string name;
string native_type;
*string qore_type;
int size;
bool nullable;
*string def_val;
*string comment;
public:
constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string c);
string getNativeTypeString();
string getCreateSql(AbstractTable t);
abstract list getAddColumnSql(AbstractTable t);
string getDropSql(string table_name);
list getModifySql(AbstractTable t, AbstractColumn c, *hash opt);
abstract string getRenameSql(AbstractTable t, string new_name);
bool equal(AbstractColumn c);
private:
abstract bool equalImpl(AbstractColumn c);
public:
private:
abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
public:
};
class NumericColumnInfo {
public:
public :
int scale;
public:
constructor(softint n_scale = 0);
string getNativeTypeString(string native_type, int precision);
};
class Indexes : public AbstractHashContainer {
public:
constructor(*hash c) ;
add(string k, AbstractIndex val);
*AbstractIndex findEqual(AbstractIndex ix);
AbstractIndex take(string k);
*AbstractIndex tryTake(string k);
AbstractIndex memberGate(string k);
string getElementName();
};
class AbstractIndex {
public:
public :
string name;
bool unique;
Columns columns;
public:
private :
*AbstractColumnSupportingConstraint constraint;
public:
constructor(string n, bool u, hash c);
string getName();
bool hasColumn(string cname);
abstract string getCreateSql(string table_name, *hash opt);
string getDropSql(string table_name);
bool equal(AbstractIndex ix);
bool equalExceptName(AbstractIndex ix);
abstract bool equalImpl(AbstractIndex ix);
abstract string getRenameSql(string table_name, string new_name);
setSupportingConstraint(AbstractColumnSupportingConstraint c);
setSupportingConstraint();
*AbstractColumnSupportingConstraint getSupportingConstraint();
list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt);
};
class Constraints : public AbstractHashContainer {
public:
constructor(*hash c) ;
add(string k, AbstractConstraint val);
AbstractConstraint take(string k);
*AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk);
AbstractConstraint memberGate(string k);
string getElementName();
};
class AbstractConstraint {
public:
private:
public:
private :
string name;
public:
constructor(string n);
string getName();
rename(string n);
abstract string getCreateSql(string table_name, *hash opt);
string getDropSql(string table_name);
abstract list getRenameSql(string table_name, string new_name);
string getDisableSql(string table_name);
string getEnableSql(string table_name, *hash opt);
bool equal(AbstractConstraint c);
private:
abstract bool equalImpl(AbstractConstraint c);
public:
abstract bool setIndexBase(string ix);
abstract clearIndex();
bool hasColumn(string cname);
};
class AbstractCheckConstraint : public AbstractConstraint {
public:
public :
string src;
public:
constructor(string n, string n_src) ;
private:
bool equalImpl(AbstractConstraint c);
public:
bool setIndexBase(string ix);
clearIndex();
};
class AbstractColumnSupportingConstraint : public AbstractConstraint,public Columns {
public:
private :
*hash sourceConstraints;
*string index;
public:
constructor(string n, *hash c, *string n_index) ;
constructor(string n, Columns c, *string n_index) ;
Qore::AbstractIterator getSourceConstraintIterator();
hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts);
findMatchingIndex(*Indexes indexes);
addSourceConstraint(string tname, AbstractForeignConstraint fk);
removeSourceConstraint(string tname, list cols);
renameSourceConstraintTable(string old_name, string new_name);
bool hasColumn(string cname);
*string getIndex();
private:
bool equalImpl(AbstractConstraint c);
public:
bool setIndexBase(string ix);
clearIndex();
abstract string getCreateSql(string table_name, *hash opts);
};
class AbstractUniqueConstraint : public AbstractColumnSupportingConstraint {
public:
constructor(string n, *hash c, *string n_index) ;
};
class AbstractPrimaryKey : public AbstractUniqueConstraint {
public:
constructor() ;
constructor(string n, *hash c) ;
};
class ForeignConstraints : public AbstractHashContainer {
public:
constructor(*hash c) ;
add(string k, AbstractForeignConstraint val);
AbstractForeignConstraint take(string k);
*AbstractForeignConstraint findEqual(AbstractForeignConstraint fk);
AbstractForeignConstraint memberGate(string k);
*hash findConstraintOn(string table, softlist cols);
string getElementName();
};
class ForeignConstraintTarget {
public:
public :
string table;
Columns columns;
public:
constructor(string t, Columns c);
bool equal(ForeignConstraintTarget targ);
};
class AbstractForeignConstraint : public AbstractColumnSupportingConstraint {
public:
public :
ForeignConstraintTarget target;
public:
constructor(string n, Columns c, ForeignConstraintTarget t) ;
private:
bool equalImpl(AbstractConstraint con);
public:
};
class AbstractSequence {
public:
public :
string name;
number start;
number increment;
*number max;
public:
constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_max);
abstract string getCreateSql(*hash opt);
string getDropSql(*hash opt);
abstract softlist getRenameSql(string new_name, *hash opt);
};
class AbstractView {
public:
public :
// ! potential object schema
*string schema;
string name;
string src;
bool updatable;
public:
constructor(string n_name, string n_src);
abstract string getCreateSql(*hash opt);
string getDropSql(*hash opt);
abstract softlist getRenameSql(string new_name, *hash opt);
};
class AbstractFunctionBase {
public:
public :
string name;
string type;
string src;
public:
constructor(string n, string n_type, string n_src);
string getType();
string getDropSql(*hash opt);
bool equal(AbstractFunctionBase t);
private:
abstract bool equalImpl(AbstractFunctionBase t);
public:
};
class AbstractFunction : public AbstractFunctionBase {
public:
constructor(string n, string n_type, string n_src) ;
abstract list getCreateSql(*hash opt);
abstract softlist getRenameSql(string new_name, *hash opt);
setName(string new_name);
};
class Functions : public AbstractHashContainer {
public:
constructor(*hash c) ;
add(string k, AbstractFunction val);
AbstractFunction take(string k);
AbstractFunction memberGate(string k);
string getElementName();
};
class AbstractTrigger : public AbstractFunctionBase {
public:
constructor(string n, string n_src) ;
abstract list getCreateSql(string table_name, *hash opt);
abstract softlist getRenameSql(string table_name, string new_name);
abstract list getDropSql(string table_name);
};
class Triggers : public AbstractHashContainer {
public:
constructor(*hash c) ;
add(string k, AbstractTrigger val);
AbstractTrigger take(string k);
AbstractTrigger memberGate(string k);
string getElementName();
};
class Database {
public:
private :
AbstractDatabase db;
public:
constructor(AbstractDatasource ds, *hash opts);
constructor(string ds, *hash opts);
constructor(hash ds, *hash opts);
SqlUtil::AbstractDatabase getDatabase();
any methodGate(string meth);
};
class AbstractSqlUtilBase {
public:
private :
AbstractDatasource ds;
string dsdesc;
Mutex l();
*hash opts;
public:
private:
constructor(AbstractDatasource nds, *hash nopts);
public:
static string makeDatasourceDesc(AbstractDatasource ds);
private:
validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
public:
private:
static validateOptionIntern(string err, string type, reference opt, string k, string tag);
public:
private:
validateHashKeysForWhitespaces(auto node);
public:
Qore::SQL::AbstractDatasource getDatasource();
string getDriverName();
string getDatasourceDesc();
};
class AbstractDatabase : public AbstractSqlUtilBase {
public:
public :
const DatabaseOptions = (
"native_case": Type::Boolean,
);
const CacheOptions = (
"table_cache": "Tables",
);
const CallbackOptions = (
"info_callback": "code",
"sql_callback": "code",
"sql_callback_executed": Type::Boolean,
);
const AC_Unchanged = 0;
const AC_Create = 1;
const AC_Drop = 2;
const AC_Rename = 3;
const AC_Modify = 4;
const AC_Truncate = 5;
const AC_Add = 6;
const AC_Recreate = 7;
const AC_Insert = 8;
const AC_Update = 9;
const AC_Delete = 10;
const AC_NotFound = 11;
const ActionMap = (
AC_Unchanged: "unchanged",
AC_Create: "create",
AC_Drop: "drop",
AC_Rename: "rename",
AC_Modify: "modify",
AC_Truncate: "truncate",
AC_Add: "add",
AC_Recreate: "recreate",
AC_Insert: "insert",
AC_Update: "update",
AC_Delete: "delete",
AC_NotFound: "not found",
);
const ActionDescMap = (
"unchanged": AC_Unchanged,
"create": AC_Create,
"drop": AC_Drop,
"rename": AC_Rename,
"modify": AC_Modify,
"truncate": AC_Truncate,
"add": AC_Add,
"recreate": AC_Recreate,
"insert": AC_Insert,
"update": AC_Update,
"delete": AC_Delete,
"not found": AC_NotFound,
);
const ActionLetterMap = (
AC_Unchanged: ".",
AC_Create: "C",
AC_Drop: "D",
AC_Rename: "N",
AC_Modify: "M",
AC_Truncate: "T",
AC_Add: "A",
AC_Recreate: "R",
AC_Insert: "I",
AC_Update: "U",
AC_Delete: "X",
AC_NotFound: ".",
);
const CreationOptions = CallbackOptions + (
"replace": Type::Boolean,
"table_cache": "Tables",
"data_tablespace": Type::String,
"index_tablespace": Type::String,
);
const AlignSchemaOptions = CreationOptions + (
"force": Type::Boolean,
);
const DropSchemaOptions = CallbackOptions + (
"force": Type::Boolean,
);
const SchemaDescriptionOptions = (
"tables": Type::Hash,
"table_map": Type::Hash,
"sequences": Type::Hash,
"sequence_map": Type::Hash,
"functions": Type::Hash,
"function_map": Type::Hash,
"procedures": Type::Hash,
"procedure_map": Type::Hash,
//"views": Type::Hash,
//"view_map": Type::Hash,
);
const SequenceDescriptionOptions = (
"start": Type::Int,
"increment": Type::Int,
"end": Type::Int,
);
const ComputeStatisticsOptions = (
"tables" : "softstringlist",
);
const ReclaimSpaceOptions = (
"tables" : "softstringlist",
);
public:
private :
bool native_case = False;
public:
private:
constructor(AbstractDatasource nds, *hash nopts) ;
public:
list features();
static doOkCallback(*hash opt, int ac, string type, string name, *string table, *string info);
static *string doCallback(*hash opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
static list doCallback(*hash opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
/*
static *string doCallback(*hash opt, *string sql, string fmt) {
if (!sql)
return;
if (opt.info_callback)
opt.info_callback(vsprintf(fmt, argv));
if (opt.sql_callback)
opt.sql_callback(sql);
return sql;
}
static list doCallback(*hash opt, list sql, string fmt) {
if (sql) {
if (opt.info_callback)
opt.info_callback(vsprintf(fmt, argv));
if (opt.sql_callback)
map opt.sql_callback($1), sql;
}
return sql;
}
*/
any tryExec(string sql);
any tryExecArgs(string sql, *softlist args);
any tryExecRaw(string sql);
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
list getDropSchemaSql(hash schema_hash, *hash opt);
private:
list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
public:
private:
list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
public:
AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
AbstractSequence makeSequenceFromDescription(string name, *hash sh, *hash opts);
AbstractTable makeTable(string name, hash desc, *hash opts);
AbstractFunction makeFunction(string name, string src, *hash opts);
AbstractFunction makeProcedure(string name, string src, *hash opt);
bool dropFunctionIfExists(string name, *hash opt);
bool dropProcedureIfExists(string name, *hash opt);
bool dropSequenceIfExists(string name, *hash opt);
bool dropViewIfExists(string name, *hash opt);
bool dropTableIfExists(string name, *hash opt);
*string getDropFunctionSqlIfExists(string name, *hash opt);
*string getDropProcedureSqlIfExists(string name, *hash opt);
*string getDropSequenceSqlIfExists(string name, *hash opt);
*list getDropTableSqlIfExists(string name, *hash opt);
doDropSql(*softlist l, string type, string name, *hash opt);
bool doDrop(*softlist l, string type, string name, *hash opt);
list getAlignFunctionSql(AbstractFunction f, *hash opt);
list getAlignProcedureSql(AbstractFunction f, *hash opt);
*AbstractTable getTable(string name);
*AbstractSequence getSequence(string name);
*AbstractFunction getFunction(string name);
*AbstractFunction getProcedure(string name);
*AbstractView getView(string name);
int getNextSequenceValue(string name);
int getCurrentSequenceValue(string name);
string getSqlFromList(list l);
bool supportsSequences();
bool supportsTypes();
bool supportsPackages();
list listTables();
Qore::ListIterator tableIterator();
list listFunctions();
Qore::ListIterator functionIterator();
list listProcedures();
Qore::ListIterator procedureIterator();
list listSequences();
Qore::ListIterator sequenceIterator();
list listViews();
Qore::ListIterator viewIterator();
bool rebuildIndex(string name, *hash options);
bool rebuildIndex(AbstractIndex index, *hash options);
computeStatistics(*hash options);
reclaimSpace(*hash options);
private:
validateOptionsIntern(string err, hash ropt, reference<hash> opt);
public:
private:
validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
public:
static AbstractDatabase getDatabase(AbstractDatasource nds, *hash opts);
static AbstractDatabase getDatabase(string dsstr, *hash opts);
static AbstractDatabase getDatabase(hash dsh, *hash opts);
static checkDriverOptions(reference<hash> h, string drv);
private:
hash getDatabaseOptions();
public:
private:
hash getCallbackOptions();
public:
private:
hash getCreationOptions();
public:
private:
hash getCacheOptions();
public:
private:
hash getAlignSchemaOptions();
public:
private:
hash getDropSchemaOptions();
public:
private:
hash getSchemaDescriptionOptions();
public:
private:
hash getSequenceDescriptionOptions();
public:
private:
hash getRebuildIndexOptions();
public:
private:
hash getComputeStatisticsOptions();
public:
private:
hash getReclaimSpaceOptions();
public:
private:
auto tryExecArgsImpl(string sql, *softlist args);
public:
private:
auto tryExecRawImpl(string sql);
public:
private:
abstract string getCreateSqlImpl(list l);
public:
private:
abstract list getAlignSqlImpl(hash schema_hash, *hash opt);
public:
private:
abstract list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
public:
private:
abstract *AbstractSequence getSequenceImpl(string name);
public:
private:
abstract *AbstractFunction getFunctionImpl(string name);
public:
private:
abstract *AbstractFunction getProcedureImpl(string name);
public:
private:
abstract *AbstractView getViewImpl(string name);
public:
private:
abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
public:
private:
abstract AbstractFunction makeFunctionImpl(string name, string src, *hash opts);
public:
private:
abstract AbstractFunction makeProcedureImpl(string name, string src, *hash opts);
public:
private:
abstract list featuresImpl();
public:
private:
abstract list listTablesImpl();
public:
private:
abstract list listFunctionsImpl();
public:
private:
abstract list listProceduresImpl();
public:
private:
abstract list listSequencesImpl();
public:
private:
abstract list listViewsImpl();
public:
private:
abstract int getNextSequenceValueImpl(string name);
public:
private:
abstract int getCurrentSequenceValueImpl(string name);
public:
private:
abstract bool supportsSequencesImpl();
public:
private:
abstract bool supportsPackagesImpl();
public:
private:
abstract bool supportsTypesImpl();
public:
private:
abstract bool rebuildIndexImpl(string name, *hash options);
public:
private:
abstract computeStatisticsImpl(*hash options);
public:
private:
abstract reclaimSpaceImpl(*hash options);
public:
};
class Table {
public:
private :
AbstractTable t;
public:
constructor(AbstractDatasource ds, string name, *hash opts);
constructor(string ds, string name, *hash opts);
constructor(hash ds, string name, *hash opts);
constructor(AbstractDatasource ds, hash desc, string name, *hash opts);
AbstractTable getTable();
any methodGate(string meth);
}; // class Table
class AbstractTable : public AbstractSqlUtilBase {
public:
public :
const TableOptions = (
"native_case": Type::Boolean,
"table_cache": "Tables",
);
const IndexOptions = (
"index_tablespace": Type::String,
"replace": Type::Boolean,
);
const ConstraintOptions = IndexOptions;
const CacheOptions = (
"table_cache": "Tables",
);
const ForeignConstraintOptions = ConstraintOptions + (
"table_cache": "Tables",
);
const TriggerOptions = AbstractDatabase::CreationOptions;
const SelectOptions = (
"alias": Type::String,
"comment": Type::String,
"hint": Type::String,
"columns": Type::NothingType,
"where": "hash/list",
"orderby": "softstringinthashlist",
"desc": Type::Boolean,
"limit": Type::Int,
"offset": Type::Int,
"join": Type::Hash,
"groupby": "softstringinthashlist",
"having": Type::Hash,
"superquery": Type::Hash,
"forupdate": Type::Boolean,
);
const TableOmissionOptions = (
"indexes": True,
"foreign_constraints": True,
"triggers": True,
);
const TableCreationOptions = IndexOptions + AbstractDatabase::CreationOptions + (
"omit": "softstringlist",
);
const AlignTableOptions = TableCreationOptions + (
"column_map": Type::Hash,
"index_map": Type::Hash,
"constraint_map": Type::Hash,
"trigger_map": Type::Hash,
"db_table_cache": "Tables",
"force": Type::Boolean,
);
const TableDescriptionHashOptions = (
"columns": Type::Hash,
"primary_key": Type::Hash,
"indexes": Type::Hash,
"triggers": Type::Hash,
"foreign_constraints": Type::Hash,
"unique_constraints": Type::Hash,
//"check_constraints": Type::Hash,
"table_cache": "Tables",
);
const ColumnDescOptions = (
"qore_type": Type::String,
"native_type": Type::String,
"size": Type::Int,
"scale": Type::Int,
"default_value": Type::NothingType,
"default_value_native": Type::Boolean,
"comment": Type::String,
"notnull": Type::Boolean,
"driver": Type::Hash,
);
const AdditionalColumnDescOptions = (
"notnull": Type::Boolean,
);
const ColumnOptions = {};
const SqlDataCallbackOptions = (
"sqlarg_callback": "code",
"tablecode": "code",
);
const InsertOptions = SqlDataCallbackOptions + (
"returning": "stringhashlist",
);
const UpsertOptions = (
"info_callback": "code",
"commit_block": Type::Int,
"delete_others": Type::Boolean,
"omit_update": "softstringlist",
);
const InsertFromIteratorOptions = SqlDataCallbackOptions + (
"info_callback": "code",
"commit_block": Type::Int,
);
const UpsertInsertFirst = 1;
const UpsertUpdateFirst = 2;
const UpsertSelectFirst = 3;
const UpsertAuto = 4;
const UpsertInsertOnly = 5;
const UpsertUpdateOnly = 6;
const UpsertStrategyMap = (
UpsertInsertFirst: "UpsertInsertFirst",
UpsertUpdateFirst: "UpsertUpdateFirst",
UpsertSelectFirst: "UpsertSelectFirst",
UpsertAuto: "UpsertAuto",
UpsertInsertOnly: "UpsertInsertOnly",
UpsertUpdateOnly: "UpsertUpdateOnly",
);
const UpsertStrategyDescriptionMap = (
"UpsertInsertFirst": UpsertInsertFirst,
"UpsertUpdateFirst": UpsertUpdateFirst,
"UpsertSelectFirst": UpsertSelectFirst,
"UpsertAuto": UpsertAuto,
"UpsertInsertOnly": UpsertInsertOnly,
"UpsertUpdateOnly": UpsertUpdateOnly,
);
const UR_Inserted = 1;
const UR_Verified = 2;
const UR_Updated = 3;
const UR_Unchanged = 4;
const UR_Deleted = 5;
const UpsertResultMap = (
UR_Inserted: "inserted",
UR_Verified: "verified",
UR_Updated: "updated",
UR_Unchanged: "unchanged",
UR_Deleted: "deleted",
);
const UpsertResultDescriptionMap = (
"inserted": UR_Inserted,
"verified": UR_Verified,
"updated": UR_Updated,
"unchanged": UR_Unchanged,
"deleted": UR_Deleted,
);
const UpsertResultLetterMap = (
UR_Inserted: "I",
UR_Verified: "V",
UR_Updated: "U",
UR_Unchanged: ".",
UR_Deleted: "X",
);
public:
private :
string name;
Columns columns;
AbstractPrimaryKey primaryKey;
Indexes indexes;
ForeignConstraints foreignConstraints;
Constraints constraints;
Triggers triggers;
bool native_case = False;
bool inDb = False;
bool manual = False;
hash m_customCopMap = hash();
public:
private:
constructor(AbstractDatasource nds, string nname, *hash nopts) ;
public:
copy(AbstractTable old);
setDatasource(AbstractDatasource nds);
private:
doTableOptions(*hash nopts);
public:
commit();
rollback();
bool inDb();
Qore::AbstractIterator getUniqueConstraintIterator();
dropCommit(*hash opt);
drop(*hash opt);
deprecated dropNoCommit(*hash opt);
auto tryExec(string sql);
auto tryExecArgs(string sql, *softlist args);
auto tryExecRaw(string sql);
softlist getDropSql(*hash opt);
truncateCommit();
truncate();
deprecated truncateNoCommit();
string getTruncateSql(*hash opt);
createCommit(*hash opt);
create(*hash opt);
deprecated createNoCommit(*hash opt);
rename(string new_name, *reference<string> sql, *Tables table_cache);
private:
doRenameIntern(string new_name, *Tables table_cache);
public:
bool emptyData();
bool empty();
private:
bool emptyUnlocked();
public:
setupTable(hash desc, *hash opt);
AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
private:
AbstractColumn addColumnUnlocked(string cname, hash opt, bool nullable = True, *reference lsql, bool do_exec = True, bool modify_table = True);
public:
private:
addColumnToTableUnlocked(AbstractColumn c);
public:
AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
AbstractColumn renameColumn(string old_name, string new_name, reference<string> sql);
string getRenameColumnSql(string old_name, string new_name, *hash opt);
private:
AbstractColumn renameColumnIntern(AbstractColumn c, string new_name);
public:
private:
validateOptionsIntern(string err, hash ropt, reference<hash> opt);
public:
private:
validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
public:
private:
execSql(softlist lsql);
public:
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference<string> sql);
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
private:
setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
public:
private:
AbstractPrimaryKey addPrimaryKeyUnlocked(string pkname, softlist cols, *hash opt, *reference<string> sql);
public:
private:
AbstractPrimaryKey addPrimaryKeyUnlockedIntern(string pkname, softlist cols, *hash opt, *reference<string> sql);
public:
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt);
private:
list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(string cname, *hash opt);
public:
list getDropPrimaryKeySql(*hash opt);
AbstractPrimaryKey dropPrimaryKey(*reference lsql);
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference<string> sql);
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
private:
AbstractUniqueConstraint addUniqueConstraintUnlocked(string cname, softlist cols, *hash opt, *reference<string> sql);
public:
private:
AbstractUniqueConstraint addUniqueConstraintUnlockedIntern(string cname, softlist cols, *hash opt, *reference<string> sql);
public:
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
private:
AbstractIndex addIndexUnlocked(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
public:
private:
AbstractIndex addIndexUnlockedIntern(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
public:
AbstractIndex renameIndex(string old_name, string new_name, reference<string> sql);
AbstractIndex dropIndex(string iname, *reference<string> sql);
string getDropIndexSql(string iname, *hash opt);
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
private:
Columns getReferencedTableColumnsUnlocked(string table, *Tables cache, string err = "FOREIGN-CONSTRAINT-ERROR");
public:
private:
AbstractForeignConstraint addForeignConstraintUnlocked(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
public:
private:
AbstractForeignConstraint addForeignConstraintUnlockedIntern(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
public:
AbstractForeignConstraint dropForeignConstraint(string cname, *reference<string> sql);
AbstractForeignConstraint removeForeignConstraint(string cname);
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference<string> sql);
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
private:
AbstractCheckConstraint addCheckConstraintUnlocked(string cname, string src, *hash opt, *reference<string> sql);
public:
private:
AbstractCheckConstraint addCheckConstraintUnlockedIntern(string cname, string src, *hash opt, *reference<string> sql);
public:
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
string getDropConstraintSql(string cname, *hash opt);
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference<AbstractConstraint> cref);
private:
AbstractConstraint findDropConstraintUnlocked(string cname, reference<code> rmv);
public:
AbstractConstraint dropConstraint(string cname, *reference<string> sql);
AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
private:
AbstractTrigger addTriggerUnlocked(string tname, string src, *hash opt, *reference lsql);
public:
private:
AbstractTrigger addTriggerUnlockedIntern(string tname, string src, *hash opt, *reference lsql);
public:
AbstractTrigger dropTrigger(string tname, *reference<string> sql);
list getDropTriggerSql(string tname, *hash opt);
private:
getAllConstraintsUnlocked(*hash opt);
public:
private:
checkUniqueConstraintName(string err, string cname);
public:
private:
checkUniqueConstraintNameValidateOptions(string err, string cname, hash ropt, reference<hash> opt);
public:
private:
validateColumnOptions(string cname, reference<hash> opt, bool nullable);
public:
AbstractColumn dropColumn(string cname, *reference lsql);
list getDropColumnSql(string cname, *hash opt);
*hash insertCommit(hash row);
*hash insertCommit(hash row, reference<string> sql);
*hash insertCommit(hash row, hash opt);
*hash insertCommit(hash row, reference<string> sql, hash opt);
*hash insert(hash row);
*hash insert(hash row, reference<string> sql);
*hash insert(hash row, hash opt);
*hash insert(hash row, reference<string> sql, hash opt);
deprecated *hash insertNoCommit(hash row, *reference<string> sql, *hash opt);
deprecated *hash insertNoCommit(hash row, hash opt);
private:
*hash insertIntern(hash row, *reference<string> sql, *hash opt);
public:
private:
hash getPlaceholdersAndValues(hash row);
public:
bool hasReturning();
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference<string> sql, hash opt);
int insertFromSelectCommit(list cols, AbstractTable source);
int insertFromSelectCommit(list cols, AbstractTable source, hash sh);
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference<string> sql);
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, hash opt);
int insertFromSelect(list cols, AbstractTable source, hash sh, reference<string> sql, hash opt);
int insertFromSelect(list cols, AbstractTable source);
int insertFromSelect(list cols, AbstractTable source, hash sh);
int insertFromSelect(list cols, AbstractTable source, hash sh, reference<string> sql);
int insertFromSelect(list cols, AbstractTable source, hash sh, hash opt);
deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference<string> sql, *hash opt);
private:
int insertFromSelectIntern(list cols, AbstractTable source, *hash sh, *reference<string> sql, *hash opt);
public:
int insertFromIteratorCommit(Qore::AbstractIterator i, *hash opt);
int insertFromIterator(Qore::AbstractIterator i, *hash opt);
deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt);
private:
int insertFromIteratorIntern(Qore::AbstractIterator i, *hash opt);
public:
int upsertCommit(hash row, int upsert_strategy = UpsertAuto, *hash opt);
int upsert(hash row, int upsert_strategy = UpsertAuto, *hash opt);
deprecated int upsertNoCommit(hash row, int upsert_strategy = UpsertAuto);
code getUpsertClosure(hash row, int upsert_strategy = UpsertAuto, *hash opt);
code getBulkUpsertClosure(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = UpsertAuto, *hash opt);
*hash upsertFromIteratorCommit(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
*hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
private:
*hash upsertFromIteratorIntern(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
public:
private:
*hash doDeleteOthersIntern(hash pkh, *hash opt);
public:
*hash upsertFromSelectCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
*hash upsertFromSelectCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
*hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
deprecated *hash upsertFromSelect(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
deprecated *hash upsertFromSelectNoCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
softint rowCount();
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference<string> sql, *hash opt);
private:
Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference<string> sql, *hash opt);
public:
Qore::SQL::SQLStatement getRowIterator(*hash sh, *hash opt);
*hash selectRow(*hash sh, *reference<string> sql, *hash opt);
*list selectRows(*hash sh, *reference<string> sql, *hash opt);
*hash select(*hash sh, *reference<string> sql, *hash opt);
*hash selectRow(*hash sh, *hash opt);
*list selectRows(*hash sh, *hash opt);
*hash select(*hash sh, *hash opt);
string getSelectSql(*hash sh, *reference<list> args);
*AbstractUniqueConstraint matchAnyUnique(list cols);
string getSelectSqlIntern(*hash qh, reference<list> args, *hash opt);
string getSelectSqlUnlocked(*hash qh, reference<list> args, *hash opt);
// column & table information must be retrieved before calling this function
string getSelectSqlUnlockedIntern(*hash qh, string from, reference<list> args, *hash ch, *hash opt);
private:
string getFromIntern(string from, *hash qh);
public:
private:
list getGroupByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
public:
private:
list getOrderByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
public:
private:
list getGroupOrderByListUnlocked(string key, hash qh, *hash jch, *hash ch, *hash psch, list coll);
public:
private:
doForUpdate(reference<string> sql);
public:
private:
string getSelectSqlName(*hash qh);
public:
private:
string getColumnExpressionIntern(auto cvc, *hash jch, bool join, *hash ch, *hash psch);
public:
private:
string doColumnOperatorIntern(hash cvc, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
public:
private:
string doColumnOperatorIntern(auto cop, auto arg, *string cve, hash cm, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
public:
private:
string getColumnNameIntern(string cv, *hash jch, bool join, *hash ch, *hash psch);
public:
private:
bool asteriskRequiresPrefix();
public:
private:
getSelectWhereSqlUnlocked(reference<string> sql, reference<list> args, *hash qh, *hash jch, bool join = False, *hash ch, *hash psch);
public:
private:
*string getWhereClause(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False);
public:
private:
*string getWhereClause(list cond, reference<list> args, *string cprefix, *hash jch, bool join = False);
public:
private:
*string getWhereClauseUnlocked(list cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
public:
private:
*string getWhereClauseUnlocked(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
public:
private:
*list getWhereClauseIntern(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash ch, *hash psch);
public:
private:
string doWhereExpressionIntern(string cn, auto we, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
public:
string getOrClause(list arglist, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
string getOrClause(hash arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
private:
doSelectOrderBySqlUnlocked(reference<string> sql, reference<list> args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
public:
int delCommit(hash cond, reference<string> sql, hash opt);
int delCommit(hash cond, hash opt);
int delCommit(hash cond, reference<string> sql);
int delCommit(hash cond);
int delCommit();
int del(hash cond, reference<string> sql, hash opt);
int del(hash cond, hash opt);
int del(hash cond, reference<string> sql);
int del(hash cond);
int del();
deprecated int delNoCommit(*hash cond, *reference<string> sql);
private:
int delIntern(*hash cond, *reference<string> sql, *hash opt);
public:
int updateCommit(hash set, hash cond, reference<string> sql, hash opt);
int updateCommit(hash set, hash cond, reference<string> sql);
int updateCommit(hash set, hash cond, hash opt);
int updateCommit(hash set, hash cond);
int updateCommit(hash set);
int update(hash set, hash cond, reference<string> sql, hash opt);
int update(hash set, hash cond, reference<string> sql);
int update(hash set, hash cond, hash opt);
int update(hash set, hash cond);
int update(hash set);
deprecated int updateNoCommit(hash set, *hash cond, *reference<string> sql);
deprecated int updateNoCommit(hash set, *hash cond, *hash opt);
private:
int updateIntern(hash set, *hash cond, *reference<string> sql, *hash opt);
public:
private:
string getUpdateExpression(string col, hash<UpdateOperatorInfo> uh);
public:
private:
bool emptyDataIntern();
public:
private:
Columns checkUpsertRow(hash row, reference<int> upsert_strategy);
public:
private:
code getUpsertInsertFirst(Columns cols, hash example_row, *hash opt);
public:
private:
code getUpsertUpdateFirst(Columns cols, hash example_row, *hash opt);
public:
private:
code getUpsertSelectFirst(Columns cols, hash example_row, *hash opt);
public:
private:
code getUpsertInsertOnly(Columns cols, hash example_row, *hash opt);
public:
private:
code getUpsertUpdateOnly(Columns cols, hash example_row, *hash opt);
public:
private:
Columns getUpsertColumns(reference csrc);
public:
private:
string getUpsertSelectSql(hash row, Columns cols, reference<list<string>> updc);
public:
private:
string getUpsertInsertSql(hash row);
public:
private:
string getUpsertUpdateSql(hash row, Columns cols, reference updc, *hash opt);
public:
private:
softbool tryUpdate(string sql, hash row, Columns cols, list updc);
public:
private:
checkValue(string cname, string argname, reference val, string type);
public:
string getSqlFromList(list l);
string getSqlValue(auto v);
string getName();
cache(*hash opts);
clear();
Columns describe();
AbstractPrimaryKey getPrimaryKey();
*AbstractUniqueConstraint findUniqueConstraint(string name);
*AbstractUniqueConstraint findUniqueConstraintUnlocked(string name);
Indexes getIndexes();
ForeignConstraints getForeignConstraints(*hash opt);
Constraints getConstraints();
Triggers getTriggers();
string getRenameSql(string new_name, *hash opt);
string getCreateSqlString(*hash opt);
list getCreateSql(*hash opt);
string getCreateTableSql(*hash opt);
bool checkExistence();
private:
*hash getCheckOmissionOptions(*softlist ol, string err);
public:
list getAlignSql(AbstractTable t, *hash opt);
private:
list getAlignSqlUnlocked(AbstractTable t, *hash opt);
public:
private:
*AbstractColumnSupportingConstraint getSupportingConstraint(string ixname);
public:
private:
renameIndexUnlocked(AbstractIndex ix, string new_name);
public:
string getAlignSqlString(AbstractTable t, *hash opt);
*list getCreateIndexesSql(*hash opt, bool cache = True);
*string getCreatePrimaryKeySql(*hash opt, bool cache = True);
*list getCreateForeignConstraintsSql(*hash opt, bool cache = True);
*list getCreateConstraintsSql(*hash opt, bool cache = True);
*list getCreateMiscSql(*hash opt, bool cache = True);
*list getCreateTriggersSql(*hash opt, bool cache = True);
*hash find(auto id);
*list find(list ids);
private:
string getPrimaryKeyColumn();
public:
*hash find(hash row);
*hash findSingle(*hash cond);
*list findAll(*hash cond);
string getDesc();
string getBaseType();
string getSqlName();
string getColumnSqlName(string col);
list getColumnSqlNames(softlist cols);
bool bindEmptyStringsAsNull();
abstract bool hasArrayBind();
private:
hash getTableOptions();
public:
private:
hash getForeignConstraintOptions();
public:
private:
hash getConstraintOptions();
public:
private:
hash getCacheOptions();
public:
private:
hash getTableCreationOptions();
public:
private:
hash getAlignTableOptions();
public:
private:
hash getTableDescriptionHashOptions();
public:
private:
hash getColumnOptions();
public:
private:
hash getColumnDescOptions();
public:
private:
hash getTableColumnDescOptions();
public:
private:
hash getIndexOptions();
public:
private:
hash getTriggerOptions();
public:
private:
hash getSelectOptions();
public:
private:
hash getUpsertOptions();
public:
private:
hash getInsertOptions();
public:
private:
hash getInsertFromIteratorOptions();
public:
private:
hash getSqlDataCallbackOptions();
public:
private:
hash getWhereOperatorMap();
public:
private:
hash getColumnOperatorMap();
public:
private:
*hash getColumnOperatorMapImpl();
public:
addCustomCopOperator(string name, hash operator);
private:
hash getInsertOperatorMap();
public:
private:
hash getUpdateOperatorMap();
public:
private:
hash getRawUpdateOperatorMap();
public:
private:
*hash getPseudoColumnHash();
public:
private:
string getCreateTableSqlUnlocked(*hash opt);
public:
private:
*list getCreateIndexesSqlUnlocked(*hash opt, bool cache = True);
public:
private:
*string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
public:
private:
*list getCreateConstraintsSqlUnlocked(*hash opt, bool cache = True);
public:
private:
*list getCreateForeignConstraintsSqlUnlocked(*hash opt, bool cache = True);
public:
private:
*list getCreateMiscSqlUnlocked(*hash opt, bool cache = True);
public:
private:
*list getCreateTriggersSqlUnlocked(*hash opt, bool cache = True);
public:
private:
list getCreateSqlUnlocked(*hash opt, bool cache = True);
public:
private:
cacheUnlocked(*hash opt);
public:
private:
auto execData(*hash opt, string sql, *list args);
public:
private:
execData(SQLStatement stmt, *hash opt, *list args);
public:
static AbstractTable getTable(AbstractDatasource nds, string nname, *hash opts);
static AbstractTable getTable(string dsstr, string nname, *hash opts);
static AbstractTable getTable(hash dsh, string nname, *hash opts);
private:
getColumnsUnlocked();
public:
private:
getPrimaryKeyUnlocked();
public:
// also loads primary key and constraints (for unique constraints)
private:
getIndexesUnlocked();
public:
private:
getForeignConstraintsUnlocked(*hash opt);
public:
private:
addSourceConstraint(string table_name, AbstractForeignConstraint fk);
public:
private:
getConstraintsUnlocked();
public:
private:
getTriggersUnlocked();
public:
private:
bool hasReturningImpl();
public:
private:
softlist getDropSqlImpl();
public:
private:
string getTruncateSqlImpl();
public:
private:
auto tryExecArgsImpl(string sql, *softlist args);
public:
private:
auto tryExecRawImpl(string sql);
public:
private:
clearImpl();
public:
private:
preSetupTableImpl(reference desc, *hash opt);
public:
private:
abstract *hash doReturningImpl(hash opt, reference<string> sql, list args);
public:
private:
abstract bool emptyImpl();
public:
private:
abstract *string getSqlValueImpl(auto v);
public:
private:
abstract bool checkExistenceImpl();
public:
private:
abstract bool supportsTablespacesImpl();
public:
private:
abstract bool constraintsLinkedToIndexesImpl();
public:
private:
abstract bool uniqueIndexCreatesConstraintImpl();
public:
private:
abstract setupTableImpl(hash desc, *hash opt);
public:
private:
abstract Columns describeImpl();
public:
private:
abstract AbstractPrimaryKey getPrimaryKeyImpl();
public:
private:
abstract Indexes getIndexesImpl();
public:
private:
abstract ForeignConstraints getForeignConstraintsImpl(*hash opt);
public:
private:
abstract Constraints getConstraintsImpl();
public:
private:
abstract Triggers getTriggersImpl();
public:
private:
abstract string getCreateTableSqlImpl(*hash opt);
public:
private:
abstract *list getCreateMiscSqlImpl(*hash opt, bool cache);
public:
private:
abstract string getCreateSqlImpl(list l);
public:
private:
abstract string getRenameSqlImpl(string new_name);
public:
private:
abstract *list getAlignSqlImpl(AbstractTable t, *hash opt);
public:
private:
abstract AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
public:
private:
abstract AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
public:
private:
abstract AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
public:
private:
abstract AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
public:
private:
abstract AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
public:
private:
abstract AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
public:
private:
abstract AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
public:
private:
abstract bool tryInsertImpl(string sql, hash row);
public:
private:
abstract hash getQoreTypeMapImpl();
public:
private:
abstract hash getTypeMapImpl();
public:
private:
abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference<string> sql, reference<list> args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
public:
private:
abstract doSelectLimitOnlyUnlockedImpl(reference<string> sql, reference<list> args, *hash qh);
public:
private:
abstract copyImpl(AbstractTable old);
public:
};
}
SqlUtil::AbstractConstraint::name
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5767
SqlUtil::cop_first_value
hash< ColumnOperatorInfo > cop_first_value(any column)
Analytic/window function: value evaluated at the row that is the first row of the window frame...
SqlUtil::AbstractTable::getDropSql
softlist getDropSql(*hash opt)
returns the sql required to drop the table; reimplement in subclasses if necessary ...
SqlUtil::AbstractTable::SelectOptions
const SelectOptions
default possible select options; can be extended by driver-specific modules
Definition: SqlUtil.qm.dox.h:7619
SqlUtil::AbstractTable::getConstraints
Constraints getConstraints()
returns a Constraints object describing the non-foreign constraints on the table
SqlUtil::AbstractSequence::name
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6054
SqlUtil::COP_SEQ
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2321
SqlUtil::UpdateOperatorInfo::arg
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2126
Hash
const Hash
SqlUtil::ColumnOperatorInfo::column
any column
column sopecifier, may be a string or a complex hash
Definition: SqlUtil.qm.dox.h:2113
SqlUtil::AbstractTable::UpsertAuto
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:7821
String
const String
SqlUtil::AbstractSqlUtilBase::getDatasource
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
SqlUtil::DefaultIopMap
const DefaultIopMap
a hash of default insert operator descriptions (currently empty, all operators are driver-dependent) ...
Definition: SqlUtil.qm.dox.h:4795
SqlUtil::AbstractListContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:5133
SqlUtil::cop_append
hash< ColumnOperatorInfo > cop_append(auto column, string arg)
returns a ColumnOperatorInfo hash for the "append" operator with the given argument ...
SqlUtil::AbstractTable::TableOmissionOptions
const TableOmissionOptions
alignment omission options
Definition: SqlUtil.qm.dox.h:7637
SqlUtil::GenericColumnInfo::native_type
string native_type
the native database column type; if both native_type and qore_type are given then native_type is used...
Definition: SqlUtil.qm.dox.h:2085
SqlUtil::AbstractTable::rename
rename(string new_name, *reference< string > sql, *Tables table_cache)
renames the table; if the table is already known to be in the database in the database, then the changes are effected in the database also immediately; otherwise it is only updated internally
SqlUtil::ColumnOperatorInfo::cop
string cop
the column operator string code
Definition: SqlUtil.qm.dox.h:2112
sprintf
string sprintf(string fmt,...)
SqlUtil::AbstractTable::truncateNoCommit
deprecated truncateNoCommit()
A legacy warpper for truncate()
SqlUtil::AbstractTable::modifyColumn
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table is already known to be in the database...
SqlUtil::AbstractTable::hasReturningImpl
bool hasReturningImpl()
returns True if the current database driver supports the "returning" clause in insert statements...
SqlUtil::AbstractTable::delCommit
int delCommit()
SqlUtil::AbstractTable::delCommit() variant
SqlUtil::OP_IN
const OP_IN
the SQL "in" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4313
SqlUtil::AbstractTable::createNoCommit
deprecated createNoCommit(*hash opt)
A legacy wrapper for create()
SqlUtil::AbstractTable::getInsertOptions
hash getInsertOptions()
returns the insert options for this driver
SqlUtil::AbstractTable::checkExistence
bool checkExistence()
returns True if the table exists in the database, False if not
SqlUtil::AbstractTable
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:7569
SqlUtil::DefaultCopMap
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2412
SqlUtil::AbstractTable::hasReturning
bool hasReturning()
returns True if the current database driver supports the "returning" clause in insert statements...
SqlUtil::cop_cast
hash< ColumnOperatorInfo > cop_cast(auto column, string arg, auto arg1, auto arg2)
returns a ColumnOperatorInfo hash for the "cast" operator with the given argument(s) ...
SqlUtil::VARCHAR
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2172
SqlUtil::AbstractTable::ForeignConstraintOptions
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:7607
SqlUtil::COP_FIRST_VALUE
const COP_FIRST_VALUE
Analytic (window) function: FIRST_VALUE.
Definition: SqlUtil.qm.dox.h:2373
SqlUtil::cop_multiply
hash< ColumnOperatorInfo > cop_multiply(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "*" operator with the given arguments
SqlUtil::AbstractTable::insertCommit
*hash insertCommit(hash row)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
SqlUtil::AbstractTable::ColumnOptions
const ColumnOptions
Column options; this is currently empty and can be extended in database-specific modules.
Definition: SqlUtil.qm.dox.h:7726
SqlUtil::AbstractTable::tryExecArgsImpl
auto tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
SqlUtil::Tables
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:5225
SqlUtil::AbstractTable::validateColumnOptions
validateColumnOptions(string cname, reference< hash > opt, bool nullable)
validates column options
SqlUtil::AbstractTable::getUniqueConstraintIterator
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
SqlUtil::AbstractView::updatable
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:6102
SqlUtil::AbstractTable::getAddPrimaryKeySql
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
SqlUtil::AbstractTable::getIndexOptions
hash getIndexOptions()
returns the index options for this driver
SqlUtil::AbstractTable::UpsertResultLetterMap
const UpsertResultLetterMap
maps upsert result codes to single letter symbols
Definition: SqlUtil.qm.dox.h:7905
SqlUtil::AbstractTable::UpsertStrategyMap
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:7840
SqlUtil::AbstractTable::dropCommit
dropCommit(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
SqlUtil::InsertOperatorInfo
insert operator info hash as returned by all insert operator functions
Definition: SqlUtil.qm.dox.h:2118
SqlUtil::AbstractTable::UR_Inserted
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:7867
SqlUtil::op_ne
hash< OperatorInfo > op_ne(auto arg)
returns an OperatorInfo hash for the "!=" or "<>" operator with the given argument for use in where c...
SqlUtil::AbstractTable::cache
cache(*hash opts)
reads in all attributes of the table from the database
printf
string printf(string fmt,...)
SqlUtil::OP_BETWEEN
const OP_BETWEEN
the SQL "between" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4308
SqlUtil::AbstractTable::getSqlValue
string getSqlValue(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
SqlUtil::AbstractIndex::constraint
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:5661
SqlUtil::AbstractTable::delNoCommit
deprecated int delNoCommit(*hash cond, *reference< string > sql)
A legacy SqlUtil::AbstractTable::del() wrapper.
SqlUtil::AbstractTable::upsertFromSelectCommit
*hash upsertFromSelectCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
SqlUtil::make_cop
hash< ColumnOperatorInfo > make_cop(string cop, auto column, auto arg)
returns a ColumnOperatorInfo hash
SqlUtil::InsertOperatorInfo::arg
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2120
SqlUtil::AbstractIndex
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:5644
SqlUtil::OP_OR
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4326
SqlUtil::AbstractTable::getTriggers
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
SqlUtil::COP_OVER
const COP_OVER
the SQL "over" clause
Definition: SqlUtil.qm.dox.h:2276
SqlUtil::cop_as
hash< ColumnOperatorInfo > cop_as(auto column, string arg)
returns a ColumnOperatorInfo hash for the "as" operator with the given argument
SqlUtil::AbstractTable::tryExec
auto tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
SqlUtil::ForeignConstraints
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5959
SqlUtil::AbstractTable::UpsertResultDescriptionMap
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:7896
SqlUtil::cop_minus
hash< ColumnOperatorInfo > cop_minus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "-" operator with the given arguments
SqlUtil::AbstractTable::UR_Deleted
const UR_Deleted
row was deleted (only possible with batch upsert methods such as AbstractTable::upsertFromIterator() ...
Definition: SqlUtil.qm.dox.h:7879
SqlUtil::AbstractTable::insertFromIteratorCommit
int insertFromIteratorCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
SqlUtil::AbstractTable::InsertFromIteratorOptions
const InsertFromIteratorOptions
default insert option keys
Definition: SqlUtil.qm.dox.h:7771
SqlUtil::cop_last_value
hash< ColumnOperatorInfo > cop_last_value(any column)
Analytic/window function: value evaluated at the row that is the last row of the window frame...
SqlUtil::COP_DENSE_RANK
const COP_DENSE_RANK
Analytic (window) function: DENSE_RANK.
Definition: SqlUtil.qm.dox.h:2366
SqlUtil::AbstractTable::upsertNoCommit
deprecated int upsertNoCommit(hash row, int upsert_strategy=UpsertAuto)
A legacy SqlUtil::AbstractTable::upsert() wrapper.
SqlUtil::OP_NE
const OP_NE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4268
Qore::ListIterator
SqlUtil::AbstractTable::dropColumn
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table
SqlUtil::cop_rank
hash< ColumnOperatorInfo > cop_rank()
Analytic/window function: rank of the current row with gaps.
SqlUtil::AbstractTable::insertNoCommit
deprecated *hash insertNoCommit(hash row, *reference< string > sql, *hash opt)
A legacy wrapper for SqlUtil::AbstractTable::insert()
SqlUtil::AbstractTable::constructor
constructor(AbstractDatasource nds, string nname, *hash nopts)
creates the object; private constructor
SqlUtil::iop_seq_currval
hash< InsertOperatorInfo > iop_seq_currval(string arg)
returns an InsertOperatorInfo hash for retrieving the current value of the given sequence in insert q...
SqlUtil::AbstractTable::getAddCheckConstraintSql
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
SqlUtil::COP_SUM
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2266
SqlUtil::AbstractTable::getAlignSql
list getAlignSql(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
SqlUtil::AbstractTable::truncateCommit
truncateCommit()
truncates all the table data; releases the transaction lock after executing
SqlUtil::AbstractFunctionBase::name
string name
the name of the object
Definition: SqlUtil.qm.dox.h:6132
SqlUtil::AbstractTable::getAlignSqlString
string getAlignSqlString(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
SqlUtil::ForeignConstraintTarget
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:6006
SqlUtil::cop_length
hash< ColumnOperatorInfo > cop_length(auto column)
returns a ColumnOperatorInfo hash for the "len" operator with the given argument; returns the length ...
SqlUtil::AbstractTable::getCreateIndexesSql
*list getCreateIndexesSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
SqlUtil::AbstractColumn::qore_type
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:5476
SqlUtil::COP_SEQ_CURRVAL
const COP_SEQ_CURRVAL
to return the last value of a sequence issued in the same session
Definition: SqlUtil.qm.dox.h:2326
SqlUtil::NumericColumnInfo
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:5580
SqlUtil::AbstractTable::upsert
int upsert(hash row, int upsert_strategy=UpsertAuto, *hash opt)
update or insert the data in the table according to the hash argument; the table must have a unique k...
True
const True
SqlUtil::make_iop
hash< InsertOperatorInfo > make_iop(string iop, auto arg)
returns an InsertOperatorInfo hash
SqlUtil::JopMap
const JopMap
a hash of valid join operators
Definition: SqlUtil.qm.dox.h:3769
SqlUtil::AbstractTable::getTableCreationOptions
hash getTableCreationOptions()
returns the table creation options for this driver
SqlUtil::SZ_MAND
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:2195
SqlUtil::OP_GT
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4258
SqlUtil::CHAR
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2178
SqlUtil::COP_AVG
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2261
SqlUtil::DB_SEQUENCES
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:2156
SqlUtil::DB_MVIEWS
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:2150
SqlUtil::JOP_LEFT
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3761
SqlUtil::AbstractSequence
base class for sequences
Definition: SqlUtil.qm.dox.h:6049
SqlUtil::AbstractTable::upsertFromIteratorCommit
*hash upsertFromIteratorCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
SqlUtil::AbstractTable::getCreateTriggersSql
*list getCreateTriggersSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
SqlUtil::COP_LAST_VALUE
const COP_LAST_VALUE
Analytic (window) function: LAST_VALUE.
Definition: SqlUtil.qm.dox.h:2380
SqlUtil::op_clt
hash< OperatorInfo > op_clt(string arg)
returns an OperatorInfo hash for the "<" operator with the given argument for use in where clauses wh...
flush
nothing flush()
SqlUtil::AbstractColumn::nullable
bool nullable
True if the column can hold a NULL value, False if not
Definition: SqlUtil.qm.dox.h:5482
SqlUtil::AbstractTable::getQoreTypeMapImpl
abstract hash getQoreTypeMapImpl()
returns the qore type -> column type map
SqlUtil::OperatorInfo::arg
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2107
SqlUtil::AbstractTable::UpsertOptions
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:7759
number
number number(softnumber n)
SqlUtil::COP_DISTINCT
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2246
SqlUtil::op_cge
hash< OperatorInfo > op_cge(string arg)
returns an OperatorInfo hash for the ">=" operator with the given argument for use in where clauses w...
SqlUtil::AbstractTable::getTriggerOptions
hash getTriggerOptions()
returns the trigger options for this driver
SqlUtil::COP_YEAR_HOUR
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:2316
SqlUtil::AbstractTable::CacheOptions
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:7599
SqlUtil::JoinOperatorInfo::opt
*hash opt
optional join options (for example, to specify a partition for the join if supported) ...
Definition: SqlUtil.qm.dox.h:2138
SqlUtil::AbstractTable::describe
Columns describe()
returns an object of class Columns describing the table
SqlUtil::AbstractTable::getAddTriggerSql
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
SqlUtil::AbstractTable::foreignConstraints
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7925
SqlUtil::AbstractTable::native_case
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:7931
SqlUtil::AbstractTable::selectRows
*list selectRows(*hash sh, *reference< string > sql, *hash opt)
returns a list of hashes representing the rows in the table that match the argument hash ...
SqlUtil::uop_multiply
hash< UpdateOperatorInfo > uop_multiply(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "*" operator with the given arguments
SqlUtil::AbstractTable::getTruncateSql
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
SqlUtil::cop_plus
hash< ColumnOperatorInfo > cop_plus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "+" operator with the given arguments
SqlUtil::AbstractTable::dropConstraint
AbstractConstraint dropConstraint(string cname, *reference< string > sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
SqlUtil::cop_value
hash< ColumnOperatorInfo > cop_value(auto arg)
returns a ColumnOperatorInfo hash for the "value" (literal) operator with the given argument ...
SqlUtil::AbstractTable::renameConstraint
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
SqlUtil::AbstractTable::getDropAllConstraintsAndIndexesOnColumnSql
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt)
gets a list of SQL strings to drop all constraints and indexes with the given column name; if the col...
SqlUtil::JoinOperatorInfo::table
any table
the table to join with (either an AbstractTable object or a string table name)
Definition: SqlUtil.qm.dox.h:2133
SqlUtil::uop_substr
hash< UpdateOperatorInfo > uop_substr(int start, *int count, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "substr" operator with the given arguments; returns a subs...
SqlUtil::AbstractTable::getDropPrimaryKeySql
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
SqlUtil::JoinOperatorInfo::jop
string jop
the join operator string code
Definition: SqlUtil.qm.dox.h:2132
SqlUtil::IOP_SEQ_CURRVAL
const IOP_SEQ_CURRVAL
for using the last value of a sequence issued in the current session
Definition: SqlUtil.qm.dox.h:4792
SqlUtil::AbstractTable::addTrigger
AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql)
adds a trigger to the table; if the table is already known to be in the database, then it is added in...
List
const List
SqlUtil::AbstractSqlUtilBase
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:6372
SqlUtil::AbstractTable::doSelectOrderByWithOffsetSqlUnlockedImpl
abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference< string > sql, reference< list > args, *hash qh, *hash jch, *hash ch, *hash psch, list coll)
processes a string for use in SQL select statements when there is an "order by" and "offset" argument...
SqlUtil::AbstractTable::getAlignTableOptions
hash getAlignTableOptions()
returns the align table options for this driver
SqlUtil::AbstractTable::UpsertUpdateFirst
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:7805
SqlUtil::AbstractTable::getRowIterator
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference< string > sql, *hash opt)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
SqlUtil::cop_year_day
hash< ColumnOperatorInfo > cop_year_day(auto column)
returns a ColumnOperatorInfo hash for the "year_day" operator with the given argument ...
SqlUtil::AbstractTable::getAddColumnSql
list getAddColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
returns a list of SQL strings that can be use to add a column to the table
SqlUtil::AbstractTable::getColumnSqlName
string getColumnSqlName(string col)
returns the column name for use in SQL strings; subclasses can return a special string in case the co...
NULL
const NULL
SqlUtil::AbstractTable::create
create(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
SqlUtil::OP_CNE
const OP_CNE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4298
SqlUtil::AbstractTable::tryExecRawImpl
auto tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
SqlUtil::uop_prepend
hash< UpdateOperatorInfo > uop_prepend(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "prepend" operator with the given argument ...
SqlUtil::Database
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:6302
SqlUtil::SqlUtilDrivers
const SqlUtilDrivers
known drivers
Definition: SqlUtil.qm.dox.h:4842
SqlUtil::OP_CGT
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4288
SqlUtil::AbstractForeignConstraint
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:6028
SqlUtil::AbstractForeignConstraint::target
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:6033
SqlUtil::op_le
hash< OperatorInfo > op_le(auto arg)
returns an OperatorInfo hash for the "<=" operator with the given argument for use in where clauses w...
SqlUtil::AbstractTable::upsertFromSelectNoCommit
deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtil::AbstractTable::upsertFromSelect() wrapper.
False
const False
SqlUtil::AbstractSqlUtilBase::l
Mutex l()
mutex for atomic actions
SqlUtil::AbstractTable::dropNoCommit
deprecated dropNoCommit(*hash opt)
A legacy wrapper for drop()
SqlUtil::AbstractTable::insertFromSelect
int insertFromSelect(list cols, AbstractTable source, hash sh, reference< string > sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
SqlUtil::AbstractTable::getAddUniqueConstraintSql
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
NothingType
const NothingType
SqlUtil::AbstractTable::renameIndex
AbstractIndex renameIndex(string old_name, string new_name, reference< string > sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
Qore::SQL::AbstractDatasource
SqlUtil::join_right_alias
hash< string, hash< JoinOperatorInfo > > join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments for use when joining with a table other...
SqlUtil::NumericColumnInfo::scale
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:5585
SqlUtil::AbstractTable::getTypeMapImpl
abstract hash getTypeMapImpl()
returns the type name -> type description hash
SqlUtil::join_inner
hash< string, hash< JoinOperatorInfo > > join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
SqlUtil::AbstractTable::getUpsertClosureWithValidation
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy=UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing a single row that will be u...
SqlUtil::AbstractCheckConstraint
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:5823
SqlUtil::uop_divide
hash< UpdateOperatorInfo > uop_divide(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "/" operator with the given arguments
SqlUtil::COP_COUNT
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2271
list
list list(...)
SqlUtil::AbstractTable::getCreateSql
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
SqlUtil::OP_CEQ
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4303
SqlUtil::COP_NTILE
const COP_NTILE
Analytic (window) function: NTILE.
Definition: SqlUtil.qm.dox.h:2387
SqlUtil::uop_plus
hash< UpdateOperatorInfo > uop_plus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "+" operator with the given arguments
SqlUtil::GenericColumnInfo::scale
softint scale
for numeric data types, this value gives the scale
Definition: SqlUtil.qm.dox.h:2089
SqlUtil::AbstractHashContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4851
SqlUtil::cop_year_hour
hash< ColumnOperatorInfo > cop_year_hour(auto column)
returns a ColumnOperatorInfo hash for the "year_hour" operator with the given argument ...
SqlUtil::JoinOperatorInfo
join operator info hash as returned by all join operator functions
Definition: SqlUtil.qm.dox.h:2131
SqlUtil::GenericColumnInfo::default_value
any default_value
the default value for the column
Definition: SqlUtil.qm.dox.h:2091
SqlUtil
the SqlUtil namespace contains all the objects in the SqlUtil module
Definition: SqlUtil.qm.dox.h:2079
SqlUtil::AbstractTable::empty
bool empty()
returns True if the table has no definitions, False if not
SqlUtil::AbstractTable::name
string name
the table&#39;s name
Definition: SqlUtil.qm.dox.h:7917
SqlUtil::op_cne
hash< OperatorInfo > op_cne(string arg)
returns an OperatorInfo hash for the "!=" or "<>" operator with the given argument for use in where c...
SqlUtil::AbstractTable::getAddIndexSql
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
SqlUtil::Triggers
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:6254
SqlUtil::AbstractTable::updateCommit
int updateCommit(hash set, hash cond, reference< string > sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
SqlUtil::ColumnOperatorInfo::arg
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2114
SqlUtil::AbstractTable::getSelectSql
string getSelectSql(*hash sh, *reference< list > args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
index
int index(softstring str, softstring substr, softint pos=0)
SqlUtil::AbstractCheckConstraint::src
string src
the source of the check clause
Definition: SqlUtil.qm.dox.h:5828
SqlUtil::AbstractSqlUtilBase::getDatasourceDesc
string getDatasourceDesc()
returns a descriptive string for the datasource
SqlUtil::AbstractTable::addIndex
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference< string > sql)
adds an index to the table; if the table is already known to be in the database, then it is added in ...
SqlUtil::AbstractTable::indexes
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7923
SqlUtil::DT_DAY
const DT_DAY
Format unit: day.
Definition: SqlUtil.qm.dox.h:3491
SqlUtil::op_cle
hash< OperatorInfo > op_cle(string arg)
returns an OperatorInfo hash for the "<=" operator with the given argument for use in where clauses w...
Qore::SQL::SQLStatement
SqlUtil::DB_PACKAGES
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:2152
SqlUtil::cop_avg
hash< ColumnOperatorInfo > cop_avg(auto column)
returns a ColumnOperatorInfo hash for the "avg" operator; returns average column values ...
SqlUtil::COP_UPPER
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2236
SqlUtil::join_right
hash< string, hash< JoinOperatorInfo > > join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
SqlUtil::AbstractTable::getColumnDescOptions
hash getColumnDescOptions()
returns the column description options for this driver
SqlUtil::AbstractTable::upsertFromIteratorNoCommit
deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtik::AbstractTable::upsertFromIterator() wrapper.
SqlUtil::AbstractTable::getColumnOperatorMapImpl
*hash getColumnOperatorMapImpl()
Reimplement in subclasses to provide driver specific column operators.
SqlUtil::AbstractTable::getUpsertClosure
code getUpsertClosure(hash row, int upsert_strategy=UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing a single row that will be u...
SqlUtil::AbstractTable::clearImpl
clearImpl()
clears any driver-specific table information
SqlUtil::JoinOperatorInfo::cond
*hash cond
additional conditions for the join clause for the table argument; see Where Clauses for more informat...
Definition: SqlUtil.qm.dox.h:2136
SqlUtil::COP_PLUS
const COP_PLUS
the SQL "plus" operator
Definition: SqlUtil.qm.dox.h:2286
Boolean
const Boolean
SqlUtil::AbstractTable::UR_Verified
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7870
SqlUtil::AbstractTable::clear
clear()
purges the current table definition
SqlUtil::OP_GE
const OP_GE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4263
SqlUtil::Indexes
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:5598
SqlUtil::SZ_NUM
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2201
SqlUtil::op_between
hash< OperatorInfo > op_between(auto l, auto r)
returns an OperatorInfo hash for the "between" operator with the given arguments, neither of which ca...
SqlUtil::AbstractTable::TableOptions
const TableOptions
table options
Definition: SqlUtil.qm.dox.h:7578
SqlUtil::GenericColumnInfo::auto_increment
*bool auto_increment
True for DBs that support an auto-increment column
Definition: SqlUtil.qm.dox.h:2101
SqlUtil::AbstractTable::upsertFromSelect
*hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
SqlUtil::AbstractTable::getForeignConstraints
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
SqlUtil::DB_SYNONYMS
const DB_SYNONYMS
Feature: synonyms.
Definition: SqlUtil.qm.dox.h:2164
SqlUtil::AbstractColumn::def_val
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:5485
SqlUtil::AbstractTable::insertFromIterator
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
SqlUtil::AbstractTable::primaryKey
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7921
SqlUtil::uop_upper
hash< UpdateOperatorInfo > uop_upper(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "upper" operator with the given argument; returns a column...
SqlUtil::COP_COALESCE
const COP_COALESCE
to return the first non-null argument in the list
Definition: SqlUtil.qm.dox.h:2331
SqlUtil::OperatorInfo::op
string op
the operator string code
Definition: SqlUtil.qm.dox.h:2106
SqlUtil::AbstractTable::manual
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:7935
SqlUtil::AbstractTable::AlignTableOptions
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:7660
SqlUtil::AbstractTable::getPrimaryKey
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
SqlUtil::AbstractTable::emptyData
bool emptyData()
returns True if the table has no data rows, False if not
SqlUtil::AbstractTable::getBaseType
string getBaseType()
returns the base type of the underlying object (normally "table", some DB-specific implementations ma...
SqlUtil::cop_min
hash< ColumnOperatorInfo > cop_min(auto column)
returns a ColumnOperatorInfo hash for the "min" operator; returns minimum column values ...
SqlUtil::AbstractTable::getCreateForeignConstraintsSql
*list getCreateForeignConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
SqlUtil::AbstractTable::hasArrayBind
abstract bool hasArrayBind()
returns True if the underlying DB driver supports bulk DML operations
SqlUtil::op_ge
hash< OperatorInfo > op_ge(auto arg)
returns an OperatorInfo hash for the ">=" operator with the given argument for use in where clauses w...
SqlUtil::AbstractTable::triggers
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:7929
SqlUtil::AbstractTable::getDesc
string getDesc()
returns a descriptive string of the datasource (without the password) and the table name (with a poss...
SqlUtil::AbstractTable::getSqlValueImpl
abstract *string getSqlValueImpl(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
SqlUtil::DB_PROCEDURES
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:2154
SqlUtil::AbstractDatabase::CreationOptions
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:6566
SqlUtil::OP_EQ
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4273
SqlUtil::AbstractSqlUtilBase::validateHashKeysForWhitespaces
validateHashKeysForWhitespaces(auto node)
Check input node for all hash keys - if it contains a key with whitespace in the beginning or at the ...
SqlUtil::AbstractTable::getDropColumnSql
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
exists
bool exists(...)
SqlUtil::GenericColumnInfo
generic column description hash in schema descriptions
Definition: SqlUtil.qm.dox.h:2081
SqlUtil::AbstractTable::del
int del()
SqlUtil::AbstractTable::del() variant
SqlUtil::AbstractColumn::comment
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:5488
SqlUtil::AbstractTable::getBulkUpsertClosure
code getBulkUpsertClosure(hash example_row, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing either a single row or a se...
SqlUtil::cop_coalesce
hash< ColumnOperatorInfo > cop_coalesce(auto col1, auto col2)
returns a ColumnOperatorInfo hash for the "coalesce" operator with the given column arguments; the fi...
SqlUtil::AbstractView::src
string src
the source code
Definition: SqlUtil.qm.dox.h:6099
SqlUtil::AbstractIndex::unique
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:5652
SqlUtil::AbstractTable::getDropIndexSql
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
SqlUtil::cop_trunc_date
hash< ColumnOperatorInfo > cop_trunc_date(auto column, string mask)
Truncates a date column or value regarding the given mask. The resulting value remains Qore::date (no...
SqlUtil::cop_dense_rank
hash< ColumnOperatorInfo > cop_dense_rank()
Analytic/window function: rank of the current row without gaps.
SqlUtil::op_eq
hash< OperatorInfo > op_eq(auto arg)
returns an OperatorInfo hash for the "=" operator with the given argument for use in where clauses wh...
SqlUtil::AbstractTable::getAddForeignConstraintSql
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
SqlUtil::AbstractTable::getSqlName
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifier for schema, etc)
SqlUtil::AbstractTable::find
*hash find(auto id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
SqlUtil::COP_YEAR_MONTH
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:2306
SqlUtil::AbstractFunctionBase::src
string src
the source of the object
Definition: SqlUtil.qm.dox.h:6138
SqlUtil::AbstractTable::addPrimaryKey
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference< string > sql)
adds a primary key to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
SqlUtil::COP_MAX
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2256
SqlUtil::op_cgt
hash< OperatorInfo > op_cgt(string arg)
returns an OperatorInfo hash for the ">" operator with the given argument for use in where clauses wh...
SqlUtil::COP_LENGTH
const COP_LENGTH
to get the length of a text field
Definition: SqlUtil.qm.dox.h:2343
SqlUtil::AbstractTable::tryExecArgs
auto tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
SqlUtil::COP_AS
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2211
SqlUtil::AbstractSqlUtilBase::getDriverName
string getDriverName()
returns the database driver name
SqlUtil::join_left_alias
hash< string, hash< JoinOperatorInfo > > join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments for use when joining with a table other ...
SqlUtil::AbstractTable::columns
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:7919
SqlUtil::AbstractTable::getDropConstraintIfExistsSql
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference< AbstractConstraint > cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
SqlUtil::DB_VIEWS
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:2162
SqlUtil::cop_max
hash< ColumnOperatorInfo > cop_max(auto column)
returns a ColumnOperatorInfo hash for the "max" operator; returns maximum column values ...
SqlUtil::AbstractTable::dropTrigger
AbstractTrigger dropTrigger(string tname, *reference< string > sql)
drops the given trigger from the table; if the table is known to be in the database already...
SqlUtil::OP_LE
const OP_LE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4253
SqlUtil::BLOB
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2181
SqlUtil::AbstractIndex::name
string name
the name of the index
Definition: SqlUtil.qm.dox.h:5649
SqlUtil::InsertOperatorInfo::_iop
string _iop
the insert operator string code
Definition: SqlUtil.qm.dox.h:2119
SqlUtil::AbstractTable::getCreatePrimaryKeySql
*string getCreatePrimaryKeySql(*hash opt, bool cache=True)
returns an SQL string that could be used to create the primary key on the table
SqlUtil::ForeignConstraintTarget::columns
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:6014
SqlUtil::UpdateOperatorInfo::uop
string uop
the update operator string code
Definition: SqlUtil.qm.dox.h:2125
SqlUtil::AbstractTable::drop
drop(*hash opt)
drops the table from the database without any transaction management
SqlUtil::OP_CLE
const OP_CLE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4283
SqlUtil::AbstractColumnSupportingConstraint
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5853
SqlUtil::AbstractTable::addColumn
AbstractColumn addColumn(string cname, hash opt, bool nullable=True, *reference lsql)
adds a column to the table; if the table is already known to be in the database, then it is added in ...
SqlUtil::DB_TABLES
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:2158
SqlUtil::AbstractTable::uniqueIndexCreatesConstraintImpl
abstract bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
SqlUtil::uop_append
hash< UpdateOperatorInfo > uop_append(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "append" or concatenate operator with the given argument ...
SqlUtil::AbstractTable::createCommit
createCommit(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
SqlUtil::uop_seq_currval
hash< UpdateOperatorInfo > uop_seq_currval(string seq)
returns an UpdateOperatorInfo hash for the "seq" operator with the given argument giving the sequence...
SqlUtil::cop_ntile
hash< ColumnOperatorInfo > cop_ntile(int value)
Analytic/window function: integer ranging from 1 to the argument value, dividing the partition as equ...
SqlUtil::CLOB
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:2184
SqlUtil::OP_NOT
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4318
SqlUtil::AbstractTable::getRenameSql
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
SqlUtil::AbstractIndex::columns
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:5655
SqlUtil::AbstractTable::SqlDataCallbackOptions
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:7733
SqlUtil::AbstractFunctionBase
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:6127
SqlUtil::DB_TYPES
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:2160
SqlUtil::AbstractTable::getRenameColumnSql
string getRenameColumnSql(string old_name, string new_name, *hash opt)
gets an SQL string that can be used to rename an existing column in the table
SqlUtil::UpdateOperatorInfo
update operator info hash as returned by all update operator functions
Definition: SqlUtil.qm.dox.h:2124
SqlUtil::make_jop
hash< string, hash< JoinOperatorInfo > > make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns hash keyed with the table name assigned to a JoinOperatorInfo hash
SqlUtil::COP_CUME_DIST
const COP_CUME_DIST
Analytic (window) function: CUME_DIST.
Definition: SqlUtil.qm.dox.h:2359
SqlUtil::AbstractTable::copy
copy(AbstractTable old)
copies the object
SqlUtil::cop_lower
hash< ColumnOperatorInfo > cop_lower(auto column)
returns a ColumnOperatorInfo hash for the "lower" operator with the given argument; returns a column ...
SqlUtil::cop_distinct
hash< ColumnOperatorInfo > cop_distinct(auto column)
returns a ColumnOperatorInfo hash for the "distinct" operator with the given argument; returns distin...
SqlUtil::AbstractTable::getColumnOptions
hash getColumnOptions()
returns the column options for this driver
SqlUtil::AbstractTable::asteriskRequiresPrefix
bool asteriskRequiresPrefix()
returns True if the database requires a wildcard "*" to be prefixed with the table name when it appea...
SqlUtil::AbstractTable::UpsertResultMap
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:7885
SqlUtil::AbstractColumn::name
string name
the name of the column
Definition: SqlUtil.qm.dox.h:5470
SqlUtil::AbstractTable::bindEmptyStringsAsNull
bool bindEmptyStringsAsNull()
returns True if the DB treats empty strings as NULL, False if not; by default this method returns Fal...
SqlUtil::cop_year
hash< ColumnOperatorInfo > cop_year(auto column)
returns a ColumnOperatorInfo hash for the "year" operator with the given argument ...
SqlUtil::AbstractSqlUtilBase::ds
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:6377
SqlUtil::uop_lower
hash< UpdateOperatorInfo > uop_lower(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "lower" operator with the given argument; returns a column...
Util::same
bool same(list l)
SqlUtil::wop_or
hash< string, hash< OperatorInfo > > wop_or(hash h1, hash h2)
returns an OperatorInfo hash with a fake "_OR_" column name; the list of arguments to the function is...
SqlUtil::AbstractTable::getRawUpdateOperatorMap
hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
SqlUtil::AbstractFunction
base class for functions
Definition: SqlUtil.qm.dox.h:6172
SqlUtil::AbstractTable::tryExecRaw
auto tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
SqlUtil::AbstractTable::copyImpl
abstract copyImpl(AbstractTable old)
db-specific copy actions
SqlUtil::COP_MULTIPLY
const COP_MULTIPLY
the SQL "multiply" operator
Definition: SqlUtil.qm.dox.h:2296
SqlUtil::ColumnOperatorInfo
column operator info hash as returned by all column operator functions
Definition: SqlUtil.qm.dox.h:2111
SqlUtil::cop_count
hash< ColumnOperatorInfo > cop_count(auto column="")
returns a ColumnOperatorInfo hash for the "count" operator; returns row counts
SqlUtil::AbstractTable::tryInsertImpl
abstract bool tryInsertImpl(string sql, hash row)
tries to insert a row, if there is a duplicate key, then it returns False, if successful, returns True
SqlUtil::AbstractTable::constraints
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:7927
SqlUtil::cop_cume_dist
hash< ColumnOperatorInfo > cop_cume_dist()
Analytic/window function: relative rank of the current row.
SqlUtil::COP_PREPEND
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:2221
SqlUtil::AbstractTable::getInsertFromIteratorOptions
hash getInsertFromIteratorOptions()
returns the insert from iterator options for this driver
SqlUtil::AbstractTable::getSqlFromList
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
type
string type(auto arg)
SqlUtil::COP_TRUNC_DATE
const COP_TRUNC_DATE
to return the date with truncated value
Definition: SqlUtil.qm.dox.h:2352
SqlUtil::AbstractTable::insert
*hash insert(hash row)
inserts a row into the table without any transaction management; a transaction will be in progress af...
SqlUtil::AbstractView
base class for views
Definition: SqlUtil.qm.dox.h:6088
SqlUtil::AbstractTable::insertFromSelectNoCommit
deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference< string > sql, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromSelect() wrapper.
SqlUtil::op_like
hash< OperatorInfo > op_like(string str)
returns an OperatorInfo hash for the "like" operator with the given argument for use in where clauses...
SqlUtil::AbstractSqlUtilBase::opts
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:6383
SqlUtil::AbstractTable::getCreateSqlString
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
SqlUtil::AbstractTable::constraintsLinkedToIndexesImpl
abstract bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
SqlUtil::AbstractTable::getCreateConstraintsSql
*list getCreateConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create non-foreign constraints on the table or NO...
SqlUtil::AbstractTable::select
*hash select(*hash sh, *reference< string > sql, *hash opt)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
SqlUtil::AbstractTable::addForeignConstraint
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference< string > sql)
adds a foreign constraint to the table; if the table is already known to be in the database...
SqlUtil::AbstractTable::InsertOptions
const InsertOptions
generic SQL insert options
Definition: SqlUtil.qm.dox.h:7748
SqlUtil::AbstractTable::TriggerOptions
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:7614
SqlUtil::AbstractTable::findAll
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
SqlUtil::join_left
hash< string, hash< JoinOperatorInfo > > join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
SqlUtil::AbstractFunctionBase::type
string type
the type of object
Definition: SqlUtil.qm.dox.h:6135
SqlUtil::AbstractTable::updateNoCommit
deprecated int updateNoCommit(hash set, *hash cond, *reference< string > sql)
A legacy SqlUtil::AbstractTable::update() wrapper.
SqlUtil::cop_seq
hash< ColumnOperatorInfo > cop_seq(string seq, *string as)
returns a ColumnOperatorInfo hash for the "seq" operator with the given argument giving the sequence ...
Int
const Int
SqlUtil::COP_YEAR
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:2301
SqlUtil::join_inner_alias
hash< string, hash< JoinOperatorInfo > > join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments for use when joining with a table ot...
string
string string(softstring str, *string enc)
SqlUtil::AbstractTable::getWhereOperatorMap
hash getWhereOperatorMap()
returns the "where" operator map for this object
SqlUtil::AbstractTable::insertFromSelectCommit
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference< string > sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
SqlUtil::AbstractTable::rowCount
softint rowCount()
returns the number of rows in the table
SqlUtil::AbstractTable::rollback
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
SqlUtil::AbstractTable::getForeignConstraintOptions
hash getForeignConstraintOptions()
return the foreign constraint options for this driver
SqlUtil::AbstractColumn::size
int size
the size of the column
Definition: SqlUtil.qm.dox.h:5479
SqlUtil::GenericColumnInfo::driver
hash< string, hash > driver
this key can optionally contain a hash keyed by driver name which contains a hash of values that will...
Definition: SqlUtil.qm.dox.h:2099
SqlUtil::AbstractTable::getModifyColumnSql
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
SqlUtil::AbstractTable::getConstraintOptions
hash getConstraintOptions()
returns the constraint options for this driver
SqlUtil::AbstractTable::getUpsertOptions
hash getUpsertOptions()
returns the upsert options for this driver
SqlUtil::AbstractColumn::native_type
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:5473
SqlUtil::COP_VALUE
const COP_VALUE
to append a constant value (SQL Literal) to use as an output column value
Definition: SqlUtil.qm.dox.h:2231
SqlUtil::uop_seq
hash< UpdateOperatorInfo > uop_seq(string seq)
returns an UpdateOperatorInfo hash for the "seq" operator with the given argument giving the sequence...
SqlUtil::AbstractTable::UpsertUpdateOnly
const UpsertUpdateOnly
Upsert option: update if the row exists, otherwise ignore.
Definition: SqlUtil.qm.dox.h:7835
SqlUtil::Columns
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:5413
SqlUtil::AbstractTrigger
the base class for triggers
Definition: SqlUtil.qm.dox.h:6236
SqlUtil::JoinOperatorInfo::ta
*string ta
optional table name or alias of the other table to join with when not joining with the primary table ...
Definition: SqlUtil.qm.dox.h:2137
SqlUtil::AbstractTable::getPseudoColumnHash
*hash getPseudoColumnHash()
returns a hash of valid pseudocolumns
SqlUtil::AbstractTable::addCheckConstraint
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference< string > sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
SqlUtil::OP_LT
const OP_LT
the SQL less than (<) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4248
SqlUtil::AbstractSqlUtilBase::dsdesc
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:6379
SqlUtil::AbstractTable::setDatasource
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
SqlUtil::AbstractTable::findSingle
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
SqlUtil::cop_sum
hash< ColumnOperatorInfo > cop_sum(auto column)
returns a ColumnOperatorInfo hash for the "sum" operator; returns the total sum of a numeric column...
SqlUtil::Functions
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:6198
SqlUtil::AbstractTable::getIndexes
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
SqlUtil::AbstractTable::UR_Unchanged
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst, UpsertInsertOnly, and UpsertUpdateOnly) ...
Definition: SqlUtil.qm.dox.h:7876
SqlUtil::AbstractTable::dropPrimaryKey
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
SqlUtil::AbstractTable::UR_Updated
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7873
SqlUtil::Database::db
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6307
SqlUtil::AbstractColumn
the base class for column information
Definition: SqlUtil.qm.dox.h:5465
SqlUtil::AbstractTable::truncate
truncate()
truncates all the table data without any transaction management
SqlUtil::COP_CAST
const COP_CAST
to convert column value into another datatype
Definition: SqlUtil.qm.dox.h:2216
SqlUtil::op_in
hash< OperatorInfo > op_in()
returns an OperatorInfo hash for the "in" operator with all arguments passed to the function; for use...
SqlUtil::AbstractTable::UpsertInsertOnly
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:7828
SqlUtil::OP_CGE
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4293
SqlUtil::DT_MINUTE
const DT_MINUTE
Format unit: minute.
Definition: SqlUtil.qm.dox.h:3497
SqlUtil::cop_seq_currval
hash< ColumnOperatorInfo > cop_seq_currval(string seq, *string as)
returns a ColumnOperatorInfo hash for the "seq_currval" operator with the given argument giving the s...
SqlUtil::DT_HOUR
const DT_HOUR
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3494
SqlUtil::AbstractTable::getName
string getName()
returns the name of the table
SqlUtil::Table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:7477
SqlUtil::AbstractTable::IndexOptions
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:7588
SqlUtil::GenericColumnInfo::comment
*string comment
an optional comment for the column
Definition: SqlUtil.qm.dox.h:2095
SqlUtil::AbstractTable::dropIndex
AbstractIndex dropIndex(string iname, *reference< string > sql)
drops the given index from the table; if the table is known to be in the database already...
SqlUtil::AbstractTable::addUniqueConstraint
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference< string > sql)
adds a unique constraint to the table; if the table is known to be in the database already...
SqlUtil::cop_divide
hash< ColumnOperatorInfo > cop_divide(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "/" operator with the given arguments
SqlUtil::DefaultUopMap
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:3511
SqlUtil::COP_MIN
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2251
SqlUtil::AbstractTable::UpsertSelectFirst
const UpsertSelectFirst
Upsert option: select first, if the row is unchanged, do nothing, if it doesn&#39;t exist, insert, otherwise update.
Definition: SqlUtil.qm.dox.h:7814
SqlUtil::AbstractTable::dropForeignConstraint
AbstractForeignConstraint dropForeignConstraint(string cname, *reference< string > sql)
drops a foreign constraint from the table; if the table is known to be in the database already...
SqlUtil::COP_YEAR_DAY
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:2311
SqlUtil::op_gt
hash< OperatorInfo > op_gt(auto arg)
returns an OperatorInfo hash for the ">" operator with the given argument for use in where clauses wh...
Closure
const Closure
SqlUtil::AbstractTable::setupTable
setupTable(hash desc, *hash opt)
creates the object from a table description hash
SqlUtil::AbstractTable::UpsertInsertFirst
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:7797
SqlUtil::DT_MONTH
const DT_MONTH
Format unit: month.
Definition: SqlUtil.qm.dox.h:3488
SqlUtil::AbstractView::name
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6096
SqlUtil::AbstractTable::getTableColumnDescOptions
hash getTableColumnDescOptions()
returns the table column description options for this driver
SqlUtil::COP_PERCENT_RANK
const COP_PERCENT_RANK
Analytic (window) function: PERCENT_RANK.
Definition: SqlUtil.qm.dox.h:2394
SqlUtil::AbstractTable::doSelectLimitOnlyUnlockedImpl
abstract doSelectLimitOnlyUnlockedImpl(reference< string > sql, reference< list > args, *hash qh)
processes a string for use in SQL select statements when there is a "limit" argument, but no "orderby" or "offset" arguments
SqlUtil::JoinOperatorInfo::jcols
*hash jcols
the columns to use for the join, the keys will be columns in the source table and the values are colu...
Definition: SqlUtil.qm.dox.h:2135
SqlUtil::AbstractSequence::max
*number max
the ending number
Definition: SqlUtil.qm.dox.h:6063
SqlUtil::AbstractTable::getUpdateOperatorMap
hash getUpdateOperatorMap()
returns the update operator map for this object
SqlUtil::COP_RANK
const COP_RANK
Analytic (window) function: RANK.
Definition: SqlUtil.qm.dox.h:2401
SqlUtil::op_not
hash< OperatorInfo > op_not(hash arg)
returns an OperatorInfo hash for the "not" operator; for use in where clauses
SqlUtil::AbstractTable::ColumnDescOptions
const ColumnDescOptions
Column description options.
Definition: SqlUtil.qm.dox.h:7705
SqlUtil::AbstractSequence::increment
number increment
the increment
Definition: SqlUtil.qm.dox.h:6060
SqlUtil::AbstractTable::getTableOptions
hash getTableOptions()
returns the table options for this driver
SqlUtil::cop_row_number
hash< ColumnOperatorInfo > cop_row_number()
Analytic/window function: number of the current row within its partition, counting from 1...
Qore
SqlUtil::AbstractTable::inDb
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
SqlUtil::OP_LIKE
const OP_LIKE
the SQL "like" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4243
SqlUtil::op_lt
hash< OperatorInfo > op_lt(auto arg)
returns an OperatorInfo hash for the "<" operator with the given argument for use in where clauses wh...
SqlUtil::make_op
hash< OperatorInfo > make_op(string op, auto arg)
returns an OperatorInfo hash
SqlUtil::op_substr
hash< OperatorInfo > op_substr(int start, *int count, string text)
returns an OperatorInfo hash for the "substr" operator with the given arguments; for use in where cla...
SqlUtil::AbstractTable::TableDescriptionHashOptions
const TableDescriptionHashOptions
Table description options.
Definition: SqlUtil.qm.dox.h:7681
SqlUtil::SZ_NONE
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2192
SqlUtil::uop_minus
hash< UpdateOperatorInfo > uop_minus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "-" operator with the given arguments
SqlUtil::AbstractTable::renameColumn
AbstractColumn renameColumn(string old_name, string new_name, reference< string > sql)
renames an existing column; if the table is already known to be in the database, then the changes are...
SqlUtil::Table::t
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:7482
SqlUtil::AbstractTable::getColumnOperatorMap
hash getColumnOperatorMap()
returns the column operator map for this object
SqlUtil::cop_upper
hash< ColumnOperatorInfo > cop_upper(auto column)
returns a ColumnOperatorInfo hash for the "upper" operator with the given argument; returns a column ...
SqlUtil::OP_CLT
const OP_CLT
the SQL less than (<) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:4278
SqlUtil::COP_MINUS
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2281
SqlUtil::cop_percent_rank
hash< ColumnOperatorInfo > cop_percent_rank()
Analytic/window function: relative rank of the current row.
SqlUtil::AbstractTable::getTableDescriptionHashOptions
hash getTableDescriptionHashOptions()
returns the table description hash options for this driver
SqlUtil::ForeignConstraintTarget::table
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:6011
hash
hash hash(object obj)
SqlUtil::AbstractTable::commit
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
SqlUtil::AbstractTable::findUniqueConstraint
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
SqlUtil::AbstractTable::TableCreationOptions
const TableCreationOptions
table creation options
Definition: SqlUtil.qm.dox.h:7647
SqlUtil::cop_over
hash< ColumnOperatorInfo > cop_over(auto column, *string partitionby, *string orderby)
returns a ColumnOperatorInfo hash for the "over" clause
SqlUtil::cop_year_month
hash< ColumnOperatorInfo > cop_year_month(auto column)
returns a ColumnOperatorInfo hash for the "year_month" operator with the given argument ...
SqlUtil::AbstractTable::getCreateMiscSql
*list getCreateMiscSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create other table attributes (such as comments...
SqlUtil::JoinOperatorInfo::alias
*string alias
optional alias for table in the query
Definition: SqlUtil.qm.dox.h:2134
SqlUtil::COP_SUBSTR
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2336
SqlUtil::AbstractTable::getSelectOptions
hash getSelectOptions()
returns the select options for this driver
SqlUtil::AbstractTable::getCacheOptions
hash getCacheOptions()
returns the cache options for this driver
SqlUtil::JOP_RIGHT
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3766
SqlUtil::AbstractTable::getColumnSqlNames
list getColumnSqlNames(softlist cols)
returns a list of column names for use in SQL strings; subclasses can process the argument list in ca...
SqlUtil::OP_SUBSTR
const OP_SUBSTR
the SQL "substr" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4323
SqlUtil::AbstractTable::selectRow
*hash selectRow(*hash sh, *reference< string > sql, *hash opt)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
SqlUtil::AbstractTable::upsertCommit
int upsertCommit(hash row, int upsert_strategy=UpsertAuto, *hash opt)
update or insert the data in the table according to the hash argument; the table must have a unique k...
SqlUtil::cop_substr
hash< ColumnOperatorInfo > cop_substr(auto column, int start, *int count)
returns a ColumnOperatorInfo hash for the "substr" operator with the given arguments; returns a subst...
SqlUtil::AbstractTable::getSqlDataCallbackOptions
hash getSqlDataCallbackOptions()
returns the sql data operation callback options for this driver
SqlUtil::SZ_OPT
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:2198
SqlUtil::iop_seq
hash< InsertOperatorInfo > iop_seq(string arg)
returns an InsertOperatorInfo hash for retrieving the value of the given sequence in insert queries ...
SqlUtil::AbstractTable::checkExistenceImpl
abstract bool checkExistenceImpl()
returns True if the table exists in the DB, False if not
SqlUtil::GenericColumnInfo::size
softint size
for data types requiring a size component, the size; for numeric columns this represents the precisio...
Definition: SqlUtil.qm.dox.h:2087
SqlUtil::AbstractTable::update
int update(hash set, hash cond, reference< string > sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
SqlUtil::OperatorInfo
SQL operator info hash as returned by all operator functions.
Definition: SqlUtil.qm.dox.h:2105
SqlUtil::AbstractSequence::start
number start
the starting number
Definition: SqlUtil.qm.dox.h:6057
SqlUtil::IOP_SEQ
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4787
SqlUtil::AbstractTable::getDropTriggerSql
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
SqlUtil::AbstractDatabase
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:6434
SqlUtil::COP_ROW_NUMBER
const COP_ROW_NUMBER
Analytic (window) function: ROW_NUMBER.
Definition: SqlUtil.qm.dox.h:2408
SqlUtil::AbstractTable::addCustomCopOperator
addCustomCopOperator(string name, hash operator)
register custom user column operator for this table object
SqlUtil::AbstractTable::getCreateTableSql
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
SqlUtil::DT_YEAR
const DT_YEAR
Format unit: year.
Definition: SqlUtil.qm.dox.h:3485
SqlUtil::AbstractTable::getDropConstraintSql
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
SqlUtil::AbstractColumnSupportingConstraint::index
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:5861
SqlUtil::AbstractPrimaryKey
represents a primary key
Definition: SqlUtil.qm.dox.h:5948
SqlUtil::JOP_INNER
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3756
SqlUtil::COP_LOWER
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2241
SqlUtil::cop_prepend
hash< ColumnOperatorInfo > cop_prepend(auto column, string arg)
returns a ColumnOperatorInfo hash for the "prepend" operator with the given argument ...
SqlUtil::UpdateOperatorInfo::nest
*hash nest
option nested operation hash
Definition: SqlUtil.qm.dox.h:2127
SqlUtil::COP_DIVIDE
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:2291
join
string join(string str,...)
SqlUtil::DB_FUNCTIONS
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:2148
SqlUtil::NUMERIC
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2175
SqlUtil::AbstractColumnSupportingConstraint::sourceConstraints
*hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:5858
SqlUtil::AbstractTable::UpsertStrategyDescriptionMap
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:7852
Qore::AbstractIterator
SqlUtil::AbstractTable::insertFromIteratorNoCommit
deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromIterator() wrapper.
SqlUtil::AbstractTable::upsertFromIterator
*hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
SqlUtil::GenericColumnInfo::qore_type
string qore_type
a qore type string that will be converted to a native DB type with some default conversion ...
Definition: SqlUtil.qm.dox.h:2083
SqlUtil::AbstractTable::ConstraintOptions
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:7596
SqlUtil::make_uop
hash< UpdateOperatorInfo > make_uop(string uop, auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash
SqlUtil::DefaultOpMap
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4329
SqlUtil::AbstractUniqueConstraint
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5939
SqlUtil::AbstractTable::AdditionalColumnDescOptions
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:7721
SqlUtil::op_ceq
hash< OperatorInfo > op_ceq(string arg)
returns an OperatorInfo hash for the "=" operator with the given argument for use in where clauses wh...
SqlUtil::AbstractTable::getInsertOperatorMap
hash getInsertOperatorMap()
returns the insert operator map for this object
SqlUtil::AbstractConstraint
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5758
SqlUtil::DT_SECOND
const DT_SECOND
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3500
SqlUtil::AbstractTable::supportsTablespacesImpl
abstract bool supportsTablespacesImpl()
returns True if the database support tablespaces
SqlUtil::AbstractTable::removeForeignConstraint
AbstractForeignConstraint removeForeignConstraint(string cname)
removes the named foreign constraint from the table; no SQL is executed in any case, only the named foreign constraint is removed from the table definition
SqlUtil::Constraints
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5716
SqlUtil::COP_APPEND
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2226