All Classes Namespaces Functions Variables Groups Pages
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);
private:
static runInfoCallback(code info_callback, int ac, string type, string name, *string table, *string new_name, *string info);
public:
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);
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);
Qore::SQL::SQLStatement getRowIteratorNoExec(*hash sh, *reference<string> sql, *hash opt);
private:
Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference<string> sql, *hash opt, *bool no_exec);
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:5785
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...
rename
nothing rename(string old_path, string new_path)
SqlUtil::AbstractSequence::name
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6072
SqlUtil::COP_SEQ
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2339
SqlUtil::UpdateOperatorInfo::arg
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2144
Hash
const Hash
SqlUtil::ColumnOperatorInfo::column
any column
column sopecifier, may be a string or a complex hash
Definition: SqlUtil.qm.dox.h:2131
SqlUtil::AbstractTable::UpsertAuto
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:7823
String
const String
SqlUtil::DefaultIopMap
const DefaultIopMap
a hash of default insert operator descriptions (currently empty, all operators are driver-dependent) ...
Definition: SqlUtil.qm.dox.h:4813
SqlUtil::AbstractListContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:5151
SqlUtil::cop_append
hash< ColumnOperatorInfo > cop_append(auto column, string arg)
returns a ColumnOperatorInfo hash for the &quot;append&quot; operator with the given argument ...
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:2103
SqlUtil::ColumnOperatorInfo::cop
string cop
the column operator string code
Definition: SqlUtil.qm.dox.h:2130
sprintf
string sprintf(string fmt,...)
SqlUtil::AbstractTable::delCommit
int delCommit()
SqlUtil::AbstractTable::delCommit() variant
SqlUtil::OP_IN
const OP_IN
the SQL &quot;in&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4331
SqlUtil::AbstractTable
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:7571
SqlUtil::DefaultCopMap
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2430
SqlUtil::cop_cast
hash< ColumnOperatorInfo > cop_cast(auto column, string arg, auto arg1, auto arg2)
returns a ColumnOperatorInfo hash for the &quot;cast&quot; operator with the given argument(s) ...
SqlUtil::VARCHAR
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2190
SqlUtil::COP_FIRST_VALUE
const COP_FIRST_VALUE
Analytic (window) function: FIRST_VALUE.
Definition: SqlUtil.qm.dox.h:2391
SqlUtil::cop_multiply
hash< ColumnOperatorInfo > cop_multiply(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the &quot;*&quot; operator with the given arguments
SqlUtil::Tables
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:5243
SqlUtil::AbstractView::updatable
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:6120
SqlUtil::InsertOperatorInfo
insert operator info hash as returned by all insert operator functions
Definition: SqlUtil.qm.dox.h:2136
SqlUtil::op_ne
hash< OperatorInfo > op_ne(auto arg)
returns an OperatorInfo hash for the &quot;!=&quot; or &quot;&lt;&gt;&quot; operator with the given argument for use in where c...
printf
string printf(string fmt,...)
SqlUtil::OP_BETWEEN
const OP_BETWEEN
the SQL &quot;between&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4326
SqlUtil::AbstractIndex::constraint
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:5679
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:2138
SqlUtil::AbstractIndex
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:5662
SqlUtil::OP_OR
const OP_OR
to combine SQL expressions with &quot;or&quot; for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4344
SqlUtil::COP_OVER
const COP_OVER
the SQL &quot;over&quot; clause
Definition: SqlUtil.qm.dox.h:2294
SqlUtil::cop_as
hash< ColumnOperatorInfo > cop_as(auto column, string arg)
returns a ColumnOperatorInfo hash for the &quot;as&quot; operator with the given argument
SqlUtil::ForeignConstraints
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5977
SqlUtil::cop_minus
hash< ColumnOperatorInfo > cop_minus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the &quot;-&quot; operator with the given arguments
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:2384
SqlUtil::OP_NE
const OP_NE
the SQL not equals operator (!= or &lt;&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4286
Qore::ListIterator
SqlUtil::cop_rank
hash< ColumnOperatorInfo > cop_rank()
Analytic/window function: rank of the current row with gaps.
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::COP_SUM
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2284
SqlUtil::AbstractFunctionBase::name
string name
the name of the object
Definition: SqlUtil.qm.dox.h:6150
SqlUtil::ForeignConstraintTarget
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:6024
SqlUtil::cop_length
hash< ColumnOperatorInfo > cop_length(auto column)
returns a ColumnOperatorInfo hash for the &quot;len&quot; operator with the given argument; returns the length ...
SqlUtil::AbstractColumn::qore_type
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:5494
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:2344
SqlUtil::NumericColumnInfo
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:5598
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:3787
SqlUtil::SZ_MAND
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:2213
SqlUtil::OP_GT
const OP_GT
the SQL greater than operator (&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4276
SqlUtil::CHAR
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2196
SqlUtil::COP_AVG
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2279
SqlUtil::DB_SEQUENCES
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:2174
SqlUtil::DB_MVIEWS
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:2168
SqlUtil::JOP_LEFT
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3779
SqlUtil::AbstractSequence
base class for sequences
Definition: SqlUtil.qm.dox.h:6067
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::COP_LAST_VALUE
const COP_LAST_VALUE
Analytic (window) function: LAST_VALUE.
Definition: SqlUtil.qm.dox.h:2398
SqlUtil::op_clt
hash< OperatorInfo > op_clt(string arg)
returns an OperatorInfo hash for the &quot;&lt;&quot; 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:5500
SqlUtil::OperatorInfo::arg
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2125
SqlUtil::AbstractTable::UpsertOptions
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:7761
number
number number(softnumber n)
SqlUtil::COP_DISTINCT
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2264
SqlUtil::op_cge
hash< OperatorInfo > op_cge(string arg)
returns an OperatorInfo hash for the &quot;&gt;=&quot; operator with the given argument for use in where clauses w...
SqlUtil::COP_YEAR_HOUR
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:2334
SqlUtil::JoinOperatorInfo::opt
*hash opt
optional join options (for example, to specify a partition for the join if supported) ...
Definition: SqlUtil.qm.dox.h:2156
SqlUtil::AbstractTable::foreignConstraints
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7927
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 &quot;*&quot; operator with the given arguments
SqlUtil::cop_plus
hash< ColumnOperatorInfo > cop_plus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the &quot;+&quot; operator with the given arguments
SqlUtil::cop_value
hash< ColumnOperatorInfo > cop_value(auto arg)
returns a ColumnOperatorInfo hash for the &quot;value&quot; (literal) operator with the given argument ...
SqlUtil::JoinOperatorInfo::table
any table
the table to join with (either an AbstractTable object or a string table name)
Definition: SqlUtil.qm.dox.h:2151
SqlUtil::uop_substr
hash< UpdateOperatorInfo > uop_substr(int start, *int count, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;substr&quot; operator with the given arguments; returns a subs...
SqlUtil::JoinOperatorInfo::jop
string jop
the join operator string code
Definition: SqlUtil.qm.dox.h:2150
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:4810
List
const List
SqlUtil::AbstractSqlUtilBase
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:6390
SqlUtil::AbstractTable::UpsertUpdateFirst
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:7807
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 &quot;year_day&quot; operator with the given argument ...
NULL
const NULL
SqlUtil::OP_CNE
const OP_CNE
the SQL not equals operator (!= or &lt;&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4316
SqlUtil::uop_prepend
hash< UpdateOperatorInfo > uop_prepend(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;prepend&quot; 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:6320
SqlUtil::SqlUtilDrivers
const SqlUtilDrivers
known drivers
Definition: SqlUtil.qm.dox.h:4860
SqlUtil::OP_CGT
const OP_CGT
the SQL greater than operator (&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4306
SqlUtil::AbstractForeignConstraint
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:6046
SqlUtil::AbstractForeignConstraint::target
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:6051
SqlUtil::op_le
hash< OperatorInfo > op_le(auto arg)
returns an OperatorInfo hash for the &quot;&lt;=&quot; operator with the given argument for use in where clauses w...
False
const False
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...
NothingType
const NothingType
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:5603
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:5841
SqlUtil::uop_divide
hash< UpdateOperatorInfo > uop_divide(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;/&quot; operator with the given arguments
SqlUtil::COP_COUNT
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2289
list
list list(...)
SqlUtil::OP_CEQ
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4321
SqlUtil::COP_NTILE
const COP_NTILE
Analytic (window) function: NTILE.
Definition: SqlUtil.qm.dox.h:2405
SqlUtil::uop_plus
hash< UpdateOperatorInfo > uop_plus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;+&quot; operator with the given arguments
SqlUtil::GenericColumnInfo::scale
softint scale
for numeric data types, this value gives the scale
Definition: SqlUtil.qm.dox.h:2107
SqlUtil::AbstractHashContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4869
SqlUtil::cop_year_hour
hash< ColumnOperatorInfo > cop_year_hour(auto column)
returns a ColumnOperatorInfo hash for the &quot;year_hour&quot; operator with the given argument ...
SqlUtil::JoinOperatorInfo
join operator info hash as returned by all join operator functions
Definition: SqlUtil.qm.dox.h:2149
SqlUtil::GenericColumnInfo::default_value
any default_value
the default value for the column
Definition: SqlUtil.qm.dox.h:2109
SqlUtil::AbstractTable::name
string name
the table&#39;s name
Definition: SqlUtil.qm.dox.h:7919
SqlUtil::op_cne
hash< OperatorInfo > op_cne(string arg)
returns an OperatorInfo hash for the &quot;!=&quot; or &quot;&lt;&gt;&quot; operator with the given argument for use in where c...
SqlUtil::Triggers
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:6272
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:2132
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:5846
SqlUtil::AbstractTable::indexes
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7925
SqlUtil::DT_DAY
const DT_DAY
Format unit: day.
Definition: SqlUtil.qm.dox.h:3509
SqlUtil::op_cle
hash< OperatorInfo > op_cle(string arg)
returns an OperatorInfo hash for the &quot;&lt;=&quot; 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:2170
SqlUtil::cop_avg
hash< ColumnOperatorInfo > cop_avg(auto column)
returns a ColumnOperatorInfo hash for the &quot;avg&quot; operator; returns average column values ...
SqlUtil::COP_UPPER
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2254
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::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::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:2154
SqlUtil::COP_PLUS
const COP_PLUS
the SQL &quot;plus&quot; operator
Definition: SqlUtil.qm.dox.h:2304
Boolean
const Boolean
SqlUtil::OP_GE
const OP_GE
the SQL greater than or equals operator (&gt;=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4281
SqlUtil::Indexes
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:5616
SqlUtil::SZ_NUM
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2219
SqlUtil::op_between
hash< OperatorInfo > op_between(auto l, auto r)
returns an OperatorInfo hash for the &quot;between&quot; operator with the given arguments, neither of which ca...
SqlUtil::GenericColumnInfo::auto_increment
*bool auto_increment
True for DBs that support an auto-increment column
Definition: SqlUtil.qm.dox.h:2119
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::DB_SYNONYMS
const DB_SYNONYMS
Feature: synonyms.
Definition: SqlUtil.qm.dox.h:2182
SqlUtil::AbstractColumn::def_val
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:5503
SqlUtil::AbstractTable::primaryKey
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7923
SqlUtil::uop_upper
hash< UpdateOperatorInfo > uop_upper(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;upper&quot; 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:2349
SqlUtil::OperatorInfo::op
string op
the operator string code
Definition: SqlUtil.qm.dox.h:2124
SqlUtil::cop_min
hash< ColumnOperatorInfo > cop_min(auto column)
returns a ColumnOperatorInfo hash for the &quot;min&quot; operator; returns minimum column values ...
SqlUtil::op_ge
hash< OperatorInfo > op_ge(auto arg)
returns an OperatorInfo hash for the &quot;&gt;=&quot; operator with the given argument for use in where clauses w...
SqlUtil::AbstractTable::triggers
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:7931
SqlUtil::DB_PROCEDURES
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:2172
SqlUtil::AbstractDatabase::CreationOptions
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:6584
SqlUtil::OP_EQ
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4291
exists
bool exists(...)
SqlUtil::GenericColumnInfo
generic column description hash in schema descriptions
Definition: SqlUtil.qm.dox.h:2099
SqlUtil::AbstractTable::del
int del()
SqlUtil::AbstractTable::del() variant
SqlUtil::AbstractColumn::comment
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:5506
SqlUtil::cop_coalesce
hash< ColumnOperatorInfo > cop_coalesce(auto col1, auto col2)
returns a ColumnOperatorInfo hash for the &quot;coalesce&quot; operator with the given column arguments; the fi...
SqlUtil::AbstractView::src
string src
the source code
Definition: SqlUtil.qm.dox.h:6117
SqlUtil::AbstractIndex::unique
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:5670
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 &quot;=&quot; operator with the given argument for use in where clauses wh...
SqlUtil::COP_YEAR_MONTH
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:2324
SqlUtil::AbstractFunctionBase::src
string src
the source of the object
Definition: SqlUtil.qm.dox.h:6156
SqlUtil::COP_MAX
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2274
SqlUtil::op_cgt
hash< OperatorInfo > op_cgt(string arg)
returns an OperatorInfo hash for the &quot;&gt;&quot; 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:2361
SqlUtil::COP_AS
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2229
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:7921
SqlUtil::DB_VIEWS
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:2180
SqlUtil::cop_max
hash< ColumnOperatorInfo > cop_max(auto column)
returns a ColumnOperatorInfo hash for the &quot;max&quot; operator; returns maximum column values ...
SqlUtil::OP_LE
const OP_LE
the SQL less than or equals (&lt;=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4271
SqlUtil::BLOB
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2199
SqlUtil::AbstractIndex::name
string name
the name of the index
Definition: SqlUtil.qm.dox.h:5667
SqlUtil::InsertOperatorInfo::_iop
string _iop
the insert operator string code
Definition: SqlUtil.qm.dox.h:2137
SqlUtil::ForeignConstraintTarget::columns
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:6032
SqlUtil::UpdateOperatorInfo::uop
string uop
the update operator string code
Definition: SqlUtil.qm.dox.h:2143
SqlUtil::OP_CLE
const OP_CLE
the SQL less than or equals (&lt;=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4301
SqlUtil::AbstractColumnSupportingConstraint
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5871
SqlUtil::DB_TABLES
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:2176
SqlUtil::uop_append
hash< UpdateOperatorInfo > uop_append(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;append&quot; or concatenate operator with the given argument ...
SqlUtil::uop_seq_currval
hash< UpdateOperatorInfo > uop_seq_currval(string seq)
returns an UpdateOperatorInfo hash for the &quot;seq&quot; 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:2202
SqlUtil::OP_NOT
const OP_NOT
the SQL &quot;not&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4336
SqlUtil::AbstractIndex::columns
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:5673
SqlUtil::AbstractFunctionBase
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:6145
SqlUtil::DB_TYPES
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:2178
SqlUtil::UpdateOperatorInfo
update operator info hash as returned by all update operator functions
Definition: SqlUtil.qm.dox.h:2142
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:2377
SqlUtil::cop_lower
hash< ColumnOperatorInfo > cop_lower(auto column)
returns a ColumnOperatorInfo hash for the &quot;lower&quot; operator with the given argument; returns a column ...
SqlUtil::cop_distinct
hash< ColumnOperatorInfo > cop_distinct(auto column)
returns a ColumnOperatorInfo hash for the &quot;distinct&quot; operator with the given argument; returns distin...
SqlUtil::AbstractTable::UpsertResultMap
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:7887
SqlUtil::AbstractColumn::name
string name
the name of the column
Definition: SqlUtil.qm.dox.h:5488
SqlUtil::cop_year
hash< ColumnOperatorInfo > cop_year(auto column)
returns a ColumnOperatorInfo hash for the &quot;year&quot; operator with the given argument ...
SqlUtil::AbstractSqlUtilBase::ds
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:6395
SqlUtil::uop_lower
hash< UpdateOperatorInfo > uop_lower(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;lower&quot; 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 &quot;_OR_&quot; column name; the list of arguments to the function is...
SqlUtil::AbstractFunction
base class for functions
Definition: SqlUtil.qm.dox.h:6190
SqlUtil::COP_MULTIPLY
const COP_MULTIPLY
the SQL &quot;multiply&quot; operator
Definition: SqlUtil.qm.dox.h:2314
SqlUtil::ColumnOperatorInfo
column operator info hash as returned by all column operator functions
Definition: SqlUtil.qm.dox.h:2129
SqlUtil::cop_count
hash< ColumnOperatorInfo > cop_count(auto column="")
returns a ColumnOperatorInfo hash for the &quot;count&quot; operator; returns row counts
SqlUtil::AbstractTable::constraints
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:7929
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:2239
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:2370
SqlUtil::AbstractView
base class for views
Definition: SqlUtil.qm.dox.h:6106
SqlUtil::op_like
hash< OperatorInfo > op_like(string str)
returns an OperatorInfo hash for the &quot;like&quot; operator with the given argument for use in where clauses...
SqlUtil::AbstractSqlUtilBase::opts
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:6401
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::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:6153
SqlUtil::cop_seq
hash< ColumnOperatorInfo > cop_seq(string seq, *string as)
returns a ColumnOperatorInfo hash for the &quot;seq&quot; 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:2319
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::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::AbstractColumn::size
int size
the size of the column
Definition: SqlUtil.qm.dox.h:5497
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:2117
SqlUtil::AbstractColumn::native_type
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:5491
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:2249
SqlUtil::uop_seq
hash< UpdateOperatorInfo > uop_seq(string seq)
returns an UpdateOperatorInfo hash for the &quot;seq&quot; operator with the given argument giving the sequence...
SqlUtil::Columns
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:5431
SqlUtil::AbstractTrigger
the base class for triggers
Definition: SqlUtil.qm.dox.h:6254
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:2155
SqlUtil::OP_LT
const OP_LT
the SQL less than (&lt;) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4266
SqlUtil::AbstractSqlUtilBase::dsdesc
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:6397
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 &quot;sum&quot; 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:6216
SqlUtil::AbstractTable::UR_Unchanged
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst, UpsertInsertOnly, and UpsertUpdateOnly) ...
Definition: SqlUtil.qm.dox.h:7878
SqlUtil::Database::db
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6325
SqlUtil::AbstractColumn
the base class for column information
Definition: SqlUtil.qm.dox.h:5483
SqlUtil::COP_CAST
const COP_CAST
to convert column value into another datatype
Definition: SqlUtil.qm.dox.h:2234
SqlUtil::op_in
hash< OperatorInfo > op_in()
returns an OperatorInfo hash for the &quot;in&quot; 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:7830
SqlUtil::OP_CGE
const OP_CGE
the SQL greater than or equals operator (&gt;=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4311
SqlUtil::DT_MINUTE
const DT_MINUTE
Format unit: minute.
Definition: SqlUtil.qm.dox.h:3515
SqlUtil::cop_seq_currval
hash< ColumnOperatorInfo > cop_seq_currval(string seq, *string as)
returns a ColumnOperatorInfo hash for the &quot;seq_currval&quot; operator with the given argument giving the s...
SqlUtil::DT_HOUR
const DT_HOUR
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3512
SqlUtil::Table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:7479
SqlUtil::GenericColumnInfo::comment
*string comment
an optional comment for the column
Definition: SqlUtil.qm.dox.h:2113
SqlUtil::cop_divide
hash< ColumnOperatorInfo > cop_divide(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the &quot;/&quot; operator with the given arguments
SqlUtil::DefaultUopMap
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:3529
SqlUtil::COP_MIN
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2269
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:7816
SqlUtil::COP_YEAR_DAY
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:2329
SqlUtil::op_gt
hash< OperatorInfo > op_gt(auto arg)
returns an OperatorInfo hash for the &quot;&gt;&quot; operator with the given argument for use in where clauses wh...
Closure
const Closure
SqlUtil::AbstractTable::UpsertInsertFirst
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:7799
SqlUtil::DT_MONTH
const DT_MONTH
Format unit: month.
Definition: SqlUtil.qm.dox.h:3506
SqlUtil::AbstractView::name
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6114
SqlUtil::COP_PERCENT_RANK
const COP_PERCENT_RANK
Analytic (window) function: PERCENT_RANK.
Definition: SqlUtil.qm.dox.h:2412
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:2153
SqlUtil::AbstractSequence::max
*number max
the ending number
Definition: SqlUtil.qm.dox.h:6081
SqlUtil::COP_RANK
const COP_RANK
Analytic (window) function: RANK.
Definition: SqlUtil.qm.dox.h:2419
SqlUtil::op_not
hash< OperatorInfo > op_not(hash arg)
returns an OperatorInfo hash for the &quot;not&quot; operator; for use in where clauses
SqlUtil::AbstractSequence::increment
number increment
the increment
Definition: SqlUtil.qm.dox.h:6078
SqlUtil::cop_row_number
hash< ColumnOperatorInfo > cop_row_number()
Analytic/window function: number of the current row within its partition, counting from 1...
SqlUtil::OP_LIKE
const OP_LIKE
the SQL &quot;like&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4261
SqlUtil::op_lt
hash< OperatorInfo > op_lt(auto arg)
returns an OperatorInfo hash for the &quot;&lt;&quot; 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 &quot;substr&quot; operator with the given arguments; for use in where cla...
SqlUtil::SZ_NONE
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2210
SqlUtil::uop_minus
hash< UpdateOperatorInfo > uop_minus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the &quot;-&quot; operator with the given arguments
SqlUtil::Table::t
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:7484
SqlUtil::cop_upper
hash< ColumnOperatorInfo > cop_upper(auto column)
returns a ColumnOperatorInfo hash for the &quot;upper&quot; operator with the given argument; returns a column ...
SqlUtil::OP_CLT
const OP_CLT
the SQL less than (&lt;) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:4296
SqlUtil::COP_MINUS
const COP_MINUS
the SQL &quot;minus&quot; operator
Definition: SqlUtil.qm.dox.h:2299
SqlUtil::cop_percent_rank
hash< ColumnOperatorInfo > cop_percent_rank()
Analytic/window function: relative rank of the current row.
SqlUtil::ForeignConstraintTarget::table
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:6029
hash
hash hash(object obj)
SqlUtil::cop_over
hash< ColumnOperatorInfo > cop_over(auto column, *string partitionby, *string orderby)
returns a ColumnOperatorInfo hash for the &quot;over&quot; clause
SqlUtil::cop_year_month
hash< ColumnOperatorInfo > cop_year_month(auto column)
returns a ColumnOperatorInfo hash for the &quot;year_month&quot; operator with the given argument ...
SqlUtil::JoinOperatorInfo::alias
*string alias
optional alias for table in the query
Definition: SqlUtil.qm.dox.h:2152
SqlUtil::COP_SUBSTR
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2354
SqlUtil::JOP_RIGHT
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3784
SqlUtil::OP_SUBSTR
const OP_SUBSTR
the SQL &quot;substr&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4341
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 &quot;substr&quot; operator with the given arguments; returns a subst...
SqlUtil::SZ_OPT
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:2216
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::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:2105
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:2123
SqlUtil::AbstractSequence::start
number start
the starting number
Definition: SqlUtil.qm.dox.h:6075
SqlUtil::IOP_SEQ
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4805
SqlUtil::AbstractDatabase
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:6452
SqlUtil::COP_ROW_NUMBER
const COP_ROW_NUMBER
Analytic (window) function: ROW_NUMBER.
Definition: SqlUtil.qm.dox.h:2426
SqlUtil::DT_YEAR
const DT_YEAR
Format unit: year.
Definition: SqlUtil.qm.dox.h:3503
SqlUtil::AbstractColumnSupportingConstraint::index
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:5879
SqlUtil::AbstractPrimaryKey
represents a primary key
Definition: SqlUtil.qm.dox.h:5966
SqlUtil::JOP_INNER
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3774
SqlUtil::COP_LOWER
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2259
SqlUtil::cop_prepend
hash< ColumnOperatorInfo > cop_prepend(auto column, string arg)
returns a ColumnOperatorInfo hash for the &quot;prepend&quot; operator with the given argument ...
SqlUtil::UpdateOperatorInfo::nest
*hash nest
option nested operation hash
Definition: SqlUtil.qm.dox.h:2145
SqlUtil::COP_DIVIDE
const COP_DIVIDE
the SQL &quot;divide&quot; operator
Definition: SqlUtil.qm.dox.h:2309
join
string join(string str,...)
SqlUtil::DB_FUNCTIONS
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:2166
SqlUtil::NUMERIC
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2193
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:5876
Qore::AbstractIterator
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:2101
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:4347
SqlUtil::AbstractUniqueConstraint
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5957
SqlUtil::op_ceq
hash< OperatorInfo > op_ceq(string arg)
returns an OperatorInfo hash for the &quot;=&quot; operator with the given argument for use in where clauses wh...
SqlUtil::AbstractConstraint
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5776
SqlUtil::DT_SECOND
const DT_SECOND
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3518
SqlUtil::Constraints
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5734
SqlUtil::COP_APPEND
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2244