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 - 2016 Qore Technologies, sro
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.12 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.
@anchor select_option_hint
@par 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 user 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.
@anchor select_option_columns
@par 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}
*list rows = table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner(table2, "t2", ("id": "altid"))));
@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 rows = table.selectRows(("columns": ("id", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"))));
@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}
*list rows = table.selectRows(("columns": ("table.id", "t2.*"), "join": join_inner(table2, "t2", ("id": "altid"))));
@endcode
@anchor select_option_where
@par 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.
@anchor select_option_orderby
@par Select Option "orderby"
<b>Orderby Example:</b>
@code{.py}
*list rows = table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date"));
@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
@anchor select_option_desc
@par Select Option "desc"
<b>Desc Example:</b>
@code{.py}
*list rows = table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date", "desc": True));
@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"
@anchor select_option_limit
@par Select Option "limit"
<b>Limit Example:</b>
@code{.py}
*list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
@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
@anchor select_option_offset
@par Select Option "offset"
<b>Offset Example:</b>
@code{.py}
*list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
@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
@anchor select_option_join
@par Select Option "join"
<b>Join Example:</b>
@code{.py}
*list rows = table.selectRows(("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"))));
@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
@anchor select_option_groupby
@par Select Option "groupby"
<b>Groupby Example:</b>
@code{.py}
*list rows = table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type"));
@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.
@anchor select_option_having
@par Select Option "having"
<b>Having Example:</b>
@code{.py}
*list rows = table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type", "having": ("service_type": (COP_COUNT, op_ge(100)))));
@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.
@anchor select_option_superquery
@par Select Option "superquery"
<b>Superquery Example:</b>
@code{.py}
*list rows = table.selectRows("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"))));
@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.
@anchor select_option_forupdate
@par Select Option "forupdate"
<b>For Update Example:</b>
@code{.py}
on_success ds.commit();
on_error ds.rollback();
*list rows = table.selectRows("columns": ("serviceid", "service_methodid"), "forupdate": True);
@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_op_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_op_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 {
/* @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 DefaultCopMap = (
COP_AS: (
"arg": Type::String,
"withalias": True,
"code": string (string cve, string arg, reference psch) {
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, any arg) {
return arg;
},
),
COP_UPPER: (
"code": string (string cve, any arg) {
return sprintf("upper(%s)", cve);
},
),
COP_LOWER: (
"code": string (string cve, any arg) {
return sprintf("lower(%s)", cve);
},
),
COP_DISTINCT: (
"code": string (string cve, any arg) {
return sprintf("distinct %s", cve);
},
),
COP_MIN: (
"code": string (string cve, any arg) {
return sprintf("min(%s)", cve);
},
"group": True,
),
COP_MAX: (
"code": string (string cve, any arg) {
return sprintf("max(%s)", cve);
},
"group": True,
),
COP_AVG: (
"code": string (string cve, any arg) {
return sprintf("avg(%s)", cve);
},
"group": True,
),
COP_SUM: (
"code": string (string cve, any arg) {
return sprintf("sum(%s)", cve);
},
"group": True,
),
COP_COUNT: (
"nocolumn": True,
"code": string (*string cve, any 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]);
},
),
);
hash make_cop(string cop, any column, any arg);
hash cop_as(any column, string arg);
hash cop_cast(any column, string arg, *any arg1, *any arg2);
hash cop_prepend(any column, string arg);
hash cop_append(any column, string arg);
hash cop_value(any arg);
hash cop_upper(any column);
hash cop_lower(any column);
hash cop_distinct(any column);
hash cop_min(any column);
hash cop_max(any column);
hash cop_avg(any column);
hash cop_sum(any column);
hash cop_count(any column = "");
hash cop_over(any column, string arg);
hash cop_minus(any column1, any column2);
hash cop_plus(any column1, any column2);
hash cop_divide(any column1, any column2);
hash cop_multiply(any column1, any column2);
hash cop_year(any column);
hash cop_year_month(any column);
hash cop_year_day(any column);
hash cop_year_hour(any column);
hash cop_seq(string seq, *string as);
hash cop_seq_currval(string seq, *string as);
hash cop_coalesce(any col1, any col2);
hash cop_substr(any column, int start, *int count);
const DefaultUopMap = (
COP_PREPEND: True,
COP_APPEND: True,
COP_UPPER: True,
COP_LOWER: True,
COP_MINUS: (
"sqlvalue": True,
"code": string (string cve, any arg) {
return sprintf("%s - %s", cve, arg);
},
),
COP_PLUS: (
"sqlvalue": True,
"code": string (string cve, any arg) {
return sprintf("%s + %s", cve, arg);
},
),
COP_DIVIDE: (
"sqlvalue": True,
"code": string (string cve, any arg) {
return sprintf("%s / %s", cve, arg);
},
),
COP_MULTIPLY: (
"sqlvalue": True,
"code": string (string cve, any 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 make_uop(string uop, any arg, *hash nest);
hash uop_prepend(string arg, *hash nest);
hash uop_append(string arg, *hash nest);
hash uop_upper(*hash nest);
hash uop_lower(*hash nest);
hash uop_substr(int start, *int count, *hash nest);
hash uop_plus (any arg, *hash nest);
hash uop_minus (any arg, *hash nest);
hash uop_multiply (any arg, *hash nest);
hash uop_divide (any arg, *hash nest);
hash uop_seq(string seq);
hash 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 make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
hash make_jop(string jop, string table_name, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_inner(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_left(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_right(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
hash join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
hash 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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, any arg, reference 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 args, *hash jch, bool join = False, *hash ch, *hash psch) {
return sprintf("%s = %s", cn, arg);
},
),
OP_SUBSTR: (
"code": string (object t, string cn, any arg, reference 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 args, *hash jch, bool join = False, *hash ch, *hash psch) {
return t.getOrClause(arg, \args, jch, join, ch, psch);
},
),
);
hash make_op(string op, any arg);
hash op_like(string str);
hash op_lt(any arg);
hash op_le(any arg);
hash op_gt(any arg);
hash op_ge(any arg);
hash op_ne(any arg);
hash op_eq(any arg);
hash op_between(any l, any r);
hash op_in();
hash op_in(list args);
hash op_not(hash arg);
hash op_clt(string arg);
hash op_cle(string arg);
hash op_cgt(string arg);
hash op_cge(string arg);
hash op_cne(string arg);
hash op_ceq(string arg);
hash op_substr(int start, *int count, string text);
hash op_substr(int start, string text);
hash wop_or(hash h1, hash h2);
const IOP_SEQ = "seq";
const IOP_SEQ_CURRVAL = "seq_currval";
const DefaultIopMap = {};
hash make_iop(string iop, any arg);
hash iop_seq(string arg);
hash iop_seq_currval(string arg);
class AbstractHashContainer {
public:
private:
public:
private :
*hash h;
public:
constructor(*hash nh);
constructor(AbstractHashContainer old);
copy(AbstractHashContainer old);
any memberGate(string k);
clear();
abstract any 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 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 any get(softint i);
add(any val);
any take(int i);
list getList();
bool val();
Qore::ListIterator iterator();
bool empty();
int size();
abstract string getElementName();
private checkIndex(int i);
};
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);
*string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
list getCreateList();
Qore::AbstractIterator createIterator();
list getDropList();
Qore::AbstractIterator dropIterator();
private getDependencies(reference tdh, reference sdh, *reference th);
};
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);
private abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
};
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);
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);
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);
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);
};
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();
abstract string getRenameSql(string new_name);
};
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();
abstract softlist getRenameSql(string new_name);
};
class AbstractFunctionBase {
public:
public :
string name;
string type;
string src;
public:
constructor(string n, string n_type, string n_src);
string getType();
// FIXME: not appropriate for pgsql triggers for example
string getDropSql();
bool equal(AbstractFunctionBase t);
private abstract bool equalImpl(AbstractFunctionBase t);
};
class AbstractFunction : public AbstractFunctionBase {
public:
constructor(string n, string n_type, string n_src) ;
abstract list getCreateSql(*hash opt);
abstract list getRenameSql(string new_name);
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 list 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);
static string makeDatasourceDesc(AbstractDatasource ds);
private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
private:
static validateOptionIntern(string err, string type, reference opt, string k, string tag);
public:
private validateHashKeysForWhitespaces(any node);
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;
const DropSchemaOptions = CallbackOptions;
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) ;
list features();
static doOkCallback(*hash opt, int ac, string type, string name, *string table, *string info);
static *string doCallback(*hash opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
static list doCallback(*hash opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
/*
static *string doCallback(*hash opt, *string sql, string fmt) {
if (!sql)
return;
if (opt.info_callback)
opt.info_callback(vsprintf(fmt, argv));
if (opt.sql_callback)
opt.sql_callback(sql);
return sql;
}
static list doCallback(*hash opt, list sql, string fmt) {
if (sql) {
if (opt.info_callback)
opt.info_callback(vsprintf(fmt, argv));
if (opt.sql_callback)
map opt.sql_callback($1), sql;
}
return sql;
}
*/
any tryExec(string sql);
any tryExecArgs(string sql, *softlist args);
any tryExecRaw(string sql);
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
list getDropSchemaSql(hash schema_hash, *hash opt);
private list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
private list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
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 opt);
private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
static AbstractDatabase getDatabase(AbstractDatasource nds, *hash opts);
static AbstractDatabase getDatabase(string dsstr, *hash opts);
static AbstractDatabase getDatabase(hash dsh, *hash opts);
static checkDriverOptions(reference h, string drv);
private hash getDatabaseOptions();
private hash getCallbackOptions();
private hash getCreationOptions();
private hash getCacheOptions();
private hash getAlignSchemaOptions();
private hash getDropSchemaOptions();
private hash getSchemaDescriptionOptions();
private hash getSequenceDescriptionOptions();
private hash getRebuildIndexOptions();
private hash getComputeStatisticsOptions();
private hash getReclaimSpaceOptions();
private any tryExecArgsImpl(string sql, *softlist args);
private any tryExecRawImpl(string sql);
private abstract string getCreateSqlImpl(list l);
private abstract list getAlignSqlImpl(hash schema_hash, *hash opt);
private abstract list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
private abstract *AbstractSequence getSequenceImpl(string name);
private abstract *AbstractFunction getFunctionImpl(string name);
private abstract *AbstractFunction getProcedureImpl(string name);
private abstract *AbstractView getViewImpl(string name);
private abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
private abstract AbstractFunction makeFunctionImpl(string name, string src, *hash opts);
private abstract AbstractFunction makeProcedureImpl(string name, string src, *hash opts);
private abstract list featuresImpl();
private abstract list listTablesImpl();
private abstract list listFunctionsImpl();
private abstract list listProceduresImpl();
private abstract list listSequencesImpl();
private abstract list listViewsImpl();
private abstract int getNextSequenceValueImpl(string name);
private abstract int getCurrentSequenceValueImpl(string name);
private abstract bool supportsSequencesImpl();
private abstract bool supportsPackagesImpl();
private abstract bool supportsTypesImpl();
private abstract bool rebuildIndexImpl(string name, *hash options);
private abstract computeStatisticsImpl(*hash options);
private abstract reclaimSpaceImpl(*hash options);
};
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 = (
"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",
);
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,
"comment": Type::String,
);
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;
public:
private constructor(AbstractDatasource nds, string nname, *hash nopts) ;
copy(AbstractTable old);
setDatasource(AbstractDatasource nds);
private doTableOptions(*hash nopts);
commit();
rollback();
bool inDb();
Qore::AbstractIterator getUniqueConstraintIterator();
dropCommit(*hash opt);
drop(*hash opt);
deprecated dropNoCommit(*hash opt);
any tryExec(string sql);
any tryExecArgs(string sql, *softlist args);
any 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 sql, *Tables table_cache);
private doRenameIntern(string new_name, *Tables table_cache);
bool emptyData();
bool empty();
private bool emptyUnlocked();
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);
private addColumnToTableUnlocked(AbstractColumn c);
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 sql);
string getRenameColumnSql(string old_name, string new_name, *hash opt);
private AbstractColumn renameColumnIntern(AbstractColumn c, string new_name);
private validateOptionsIntern(string err, hash ropt, reference opt);
private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
private execSql(softlist lsql);
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql);
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
private setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
private AbstractPrimaryKey addPrimaryKeyUnlocked(string pkname, softlist cols, *hash opt, *reference sql);
private AbstractPrimaryKey addPrimaryKeyUnlockedIntern(string pkname, softlist cols, *hash opt, *reference sql);
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt);
private list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(string cname, *hash opt);
list getDropPrimaryKeySql(*hash opt);
AbstractPrimaryKey dropPrimaryKey(*reference lsql);
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql);
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
private AbstractUniqueConstraint addUniqueConstraintUnlocked(string cname, softlist cols, *hash opt, *reference sql);
private AbstractUniqueConstraint addUniqueConstraintUnlockedIntern(string cname, softlist cols, *hash opt, *reference sql);
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference 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 sql);
private AbstractIndex addIndexUnlockedIntern(string iname, bool unique, softlist cols, *hash opt, *reference sql);
AbstractIndex renameIndex(string old_name, string new_name, reference sql);
AbstractIndex dropIndex(string iname, *reference sql);
string getDropIndexSql(string iname, *hash opt);
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference 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");
private AbstractForeignConstraint addForeignConstraintUnlocked(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
private AbstractForeignConstraint addForeignConstraintUnlockedIntern(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql);
AbstractForeignConstraint removeForeignConstraint(string cname);
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql);
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
private AbstractCheckConstraint addCheckConstraintUnlocked(string cname, string src, *hash opt, *reference sql);
private AbstractCheckConstraint addCheckConstraintUnlockedIntern(string cname, string src, *hash opt, *reference sql);
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
string getDropConstraintSql(string cname, *hash opt);
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref);
private AbstractConstraint findDropConstraintUnlocked(string cname, reference rmv);
AbstractConstraint dropConstraint(string cname, *reference 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);
private AbstractTrigger addTriggerUnlockedIntern(string tname, string src, *hash opt, *reference lsql);
AbstractTrigger dropTrigger(string tname, *reference sql);
list getDropTriggerSql(string tname, *hash opt);
private getAllConstraintsUnlocked(*hash opt);
private checkUniqueConstraintName(string err, string cname);
private checkUniqueConstraintNameValidateOptions(string err, string cname, hash ropt, reference opt);
private validateColumnOptions(string cname, reference opt, bool nullable);
AbstractColumn dropColumn(string cname, *reference lsql);
list getDropColumnSql(string cname, *hash opt);
*hash insertCommit(hash row);
*hash insertCommit(hash row, reference sql);
*hash insertCommit(hash row, hash opt);
*hash insertCommit(hash row, reference sql, hash opt);
*hash insert(hash row);
*hash insert(hash row, reference sql);
*hash insert(hash row, hash opt);
*hash insert(hash row, reference sql, hash opt);
deprecated *hash insertNoCommit(hash row, *reference sql, *hash opt);
deprecated *hash insertNoCommit(hash row, hash opt);
private *hash insertIntern(hash row, *reference sql, *hash opt);
private hash getPlaceholdersAndValues(hash row);
bool hasReturning();
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference 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 sql);
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, hash opt);
int insertFromSelect(list cols, AbstractTable source, hash sh, reference 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 sql);
int insertFromSelect(list cols, AbstractTable source, hash sh, hash opt);
deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt);
private int insertFromSelectIntern(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt);
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);
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);
private *hash doDeleteOthersIntern(hash pkh, *hash opt);
*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 sql, *hash opt);
private Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference sql, *hash opt);
Qore::SQL::SQLStatement getRowIterator(*hash sh, *hash opt);
*hash selectRow(*hash sh, *reference sql, *hash opt);
*list selectRows(*hash sh, *reference sql, *hash opt);
*hash select(*hash sh, *reference 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 args);
*AbstractUniqueConstraint matchAnyUnique(list cols);
string getSelectSqlIntern(*hash qh, reference args, *hash opt);
string getSelectSqlUnlocked(*hash qh, reference args, *hash opt);
// column & table information must be retrieved before calling this function
string getSelectSqlUnlockedIntern(*hash qh, string from, reference args, *hash ch, *hash opt);
private string getFromIntern(string from, *hash qh);
private list getGroupByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
private list getOrderByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
private list getGroupOrderByListUnlocked(string key, hash qh, *hash jch, *hash ch, *hash psch, list coll);
private doForUpdate(reference sql);
private string getSelectSqlName(*hash qh);
private string getColumnExpressionIntern(any cvc, *hash jch, bool join, *hash ch, *hash psch);
private string doColumnOperatorIntern(hash cvc, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
private string doColumnOperatorIntern(any cop, any arg, *string cve, hash cm, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
private string getColumnNameIntern(string cv, *hash jch, bool join, *hash ch, *hash psch);
private bool asteriskRequiresPrefix();
private getSelectWhereSqlUnlocked(reference sql, reference args, *hash qh, *hash jch, bool join = False, *hash ch, *hash psch);
private *string getWhereClause(*hash cond, reference args, *string cprefix, *hash jch, bool join = False);
private *string getWhereClause(list cond, reference args, *string cprefix, *hash jch, bool join = False);
private *string getWhereClauseUnlocked(list cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
private *string getWhereClauseUnlocked(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
private *list getWhereClauseIntern(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash ch, *hash psch);
private string doWhereExpressionIntern(string cn, any we, reference args, *hash jch, bool join = False, *hash ch, *hash psch);
string getOrClause(list arglist, reference args, *hash jch, bool join = False, *hash ch, *hash psch);
string getOrClause(hash arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch);
private doSelectOrderBySqlUnlocked(reference sql, reference args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
int delCommit(hash cond, reference sql, hash opt);
int delCommit(hash cond, hash opt);
int delCommit(hash cond, reference sql);
int delCommit(hash cond);
int delCommit();
int del(hash cond, reference sql, hash opt);
int del(hash cond, hash opt);
int del(hash cond, reference sql);
int del(hash cond);
int del();
deprecated int delNoCommit(*hash cond, *reference sql);
private int delIntern(*hash cond, *reference sql, *hash opt);
int updateCommit(hash set, hash cond, reference sql, hash opt);
int updateCommit(hash set, hash cond, reference 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 sql, hash opt);
int update(hash set, hash cond, reference 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 sql);
deprecated int updateNoCommit(hash set, *hash cond, *hash opt);
private int updateIntern(hash set, *hash cond, *reference sql, *hash opt);
private string getUpdateExpression(string col, hash uh);
private bool emptyDataIntern();
private Columns checkUpsertRow(hash row, reference upsert_strategy);
private code getUpsertInsertFirst(Columns cols, hash example_row, *hash opt);
private code getUpsertUpdateFirst(Columns cols, hash example_row, *hash opt);
private code getUpsertSelectFirst(Columns cols, hash example_row, *hash opt);
private code getUpsertInsertOnly(Columns cols, hash example_row, *hash opt);
private code getUpsertUpdateOnly(Columns cols, hash example_row, *hash opt);
private Columns getUpsertColumns(reference csrc);
private string getUpsertSelectSql(hash row, Columns cols, reference updc);
private string getUpsertInsertSql(hash row);
private string getUpsertUpdateSql(hash row, Columns cols, reference updc, *hash opt);
private softbool tryUpdate(string sql, hash row, Columns cols, list updc);
private checkValue(string cname, string argname, reference val, string type);
string getSqlFromList(list l);
string getSqlValue(any 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);
list getAlignSql(AbstractTable t, *hash opt);
private list getAlignSqlUnlocked(AbstractTable t, *hash opt);
private *AbstractColumnSupportingConstraint getSupportingConstraint(string ixname);
private renameIndexUnlocked(AbstractIndex ix, string new_name);
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(any id);
*list find(list ids);
private string getPrimaryKeyColumn();
*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();
private hash getForeignConstraintOptions();
private hash getConstraintOptions();
private hash getCacheOptions();
private hash getTableCreationOptions();
private hash getAlignTableOptions();
private hash getTableDescriptionHashOptions();
private hash getColumnOptions();
private hash getColumnDescOptions();
private hash getTableColumnDescOptions();
private hash getIndexOptions();
private hash getTriggerOptions();
private hash getSelectOptions();
private hash getUpsertOptions();
private hash getInsertOptions();
private hash getInsertFromIteratorOptions();
private hash getSqlDataCallbackOptions();
private hash getWhereOperatorMap();
private hash getColumnOperatorMap();
private hash getInsertOperatorMap();
private hash getUpdateOperatorMap();
private hash getRawUpdateOperatorMap();
private *hash getPseudoColumnHash();
private string getCreateTableSqlUnlocked(*hash opt);
private *list getCreateIndexesSqlUnlocked(*hash opt, bool cache = True);
private *string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
private *list getCreateConstraintsSqlUnlocked(*hash opt, bool cache = True);
private *list getCreateForeignConstraintsSqlUnlocked(*hash opt, bool cache = True);
private *list getCreateMiscSqlUnlocked(*hash opt, bool cache = True);
private *list getCreateTriggersSqlUnlocked(*hash opt, bool cache = True);
private list getCreateSqlUnlocked(*hash opt, bool cache = True);
private cacheUnlocked(*hash opt);
private any execData(*hash opt, string sql, *list args);
private execData(SQLStatement stmt, *hash opt, *list args);
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();
private getPrimaryKeyUnlocked();
// also loads primary key and constraints (for unique constraints)
private getIndexesUnlocked();
private getForeignConstraintsUnlocked(*hash opt);
private addSourceConstraint(string table_name, AbstractForeignConstraint fk);
private getConstraintsUnlocked();
private getTriggersUnlocked();
private bool hasReturningImpl();
private softlist getDropSqlImpl();
private string getTruncateSqlImpl();
private any tryExecArgsImpl(string sql, *softlist args);
private any tryExecRawImpl(string sql);
private clearImpl();
private preSetupTableImpl(reference desc, *hash opt);
private abstract *hash doReturningImpl(hash opt, reference sql, list args);
private abstract bool emptyImpl();
private abstract *string getSqlValueImpl(any v);
private abstract bool checkExistenceImpl();
private abstract bool supportsTablespacesImpl();
private abstract bool constraintsLinkedToIndexesImpl();
private abstract bool uniqueIndexCreatesConstraintImpl();
private abstract setupTableImpl(hash desc, *hash opt);
private abstract Columns describeImpl();
private abstract AbstractPrimaryKey getPrimaryKeyImpl();
private abstract Indexes getIndexesImpl();
private abstract ForeignConstraints getForeignConstraintsImpl(*hash opt);
private abstract Constraints getConstraintsImpl();
private abstract Triggers getTriggersImpl();
private abstract string getCreateTableSqlImpl(*hash opt);
private abstract *list getCreateMiscSqlImpl(*hash opt, bool cache);
private abstract string getCreateSqlImpl(list l);
private abstract string getRenameSqlImpl(string new_name);
private abstract *list getAlignSqlImpl(AbstractTable t, *hash opt);
private abstract AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
private abstract AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
private abstract AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
private abstract AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
private abstract AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
private abstract AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
private abstract AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
private abstract bool tryInsertImpl(string sql, hash row);
private abstract hash getQoreTypeMapImpl();
private abstract hash getTypeMapImpl();
private abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
private abstract doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh);
private abstract copyImpl(AbstractTable old);
};
}
SqlUtil::AbstractConstraint::name
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5030
SqlUtil::cop_avg
hash cop_avg(any column)
returns a hash for the &quot;avg&quot; operator; returns average column values
rename
nothing rename(string old_path, string new_path)
SqlUtil::AbstractSequence::name
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:5305
SqlUtil::uop_lower
hash uop_lower(*hash nest)
returns a hash for the &quot;lower&quot; operator with the given argument; returns a column value in lower case...
SqlUtil::COP_SEQ
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2151
Hash
const Hash
SqlUtil::AbstractTable::UpsertAuto
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:6919
String
const String
SqlUtil::op_cge
hash op_cge(string arg)
returns a hash for the &quot;&gt;=&quot; operator with the given argument for use in where clauses when comparing ...
SqlUtil::DefaultIopMap
const DefaultIopMap
a hash of default insert operator descriptions (currently empty, all operators are driver-dependent) ...
Definition: SqlUtil.qm.dox.h:4084
SqlUtil::AbstractListContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4413
SqlUtil::cop_append
hash cop_append(any column, string arg)
returns a hash for the &quot;append&quot; operator with the given argument
SqlUtil::uop_append
hash uop_append(string arg, *hash nest)
returns a hash for the &quot;append&quot; or concatenate operator with the given argument
sprintf
string sprintf(string fmt,...)
SqlUtil::AbstractTable::insertFromSelect
int insertFromSelect(list cols, AbstractTable source, hash sh, reference sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
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:3607
SqlUtil::AbstractTable
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:6663
SqlUtil::DefaultCopMap
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2169
SqlUtil::iop_seq
hash iop_seq(string arg)
returns a hash for retrieving the value of the given sequence in insert queries
SqlUtil::VARCHAR
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2002
SqlUtil::uop_upper
hash uop_upper(*hash nest)
returns a hash for the &quot;upper&quot; operator with the given argument; returns a column value in upper case...
SqlUtil::Tables
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:4502
SqlUtil::AbstractView::updatable
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:5348
SqlUtil::op_between
hash op_between(any l, any r)
returns a hash for the &quot;between&quot; operator with the given arguments, neither of which can be NULL or N...
SqlUtil::make_iop
hash make_iop(string iop, any arg)
returns a hash with _iop and arg keys
SqlUtil::AbstractTable::selectRow
*hash selectRow(*hash sh, *reference sql, *hash opt)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
SqlUtil::uop_prepend
hash uop_prepend(string arg, *hash nest)
returns a hash for the &quot;prepend&quot; operator with the given argument
SqlUtil::op_in
hash op_in()
returns a hash for the &quot;in&quot; operator with all arguments passed to the function; for use in where clau...
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:3602
SqlUtil::AbstractIndex::constraint
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:4924
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::AbstractIndex
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:4907
SqlUtil::OP_OR
const OP_OR
to combine SQL expressions with &quot;or&quot; for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3620
SqlUtil::COP_OVER
const COP_OVER
the SQL &quot;over&quot; clause
Definition: SqlUtil.qm.dox.h:2106
SqlUtil::ForeignConstraints
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5213
SqlUtil::op_ne
hash op_ne(any arg)
returns a hash for the &quot;!=&quot; or &quot;&lt;&gt;&quot; operator with the given argument for use in where clauses when co...
SqlUtil::make_jop
hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns a hash keyed with the table name assigned to a hash with jop, table, jcols, cond, alias, and ta keys
SqlUtil::OP_NE
const OP_NE
the SQL not equals operator (!= or &lt;&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3562
Qore::ListIterator
SqlUtil::cop_sum
hash cop_sum(any column)
returns a hash for the &quot;sum&quot; operator; returns the total sum of a numeric column. ...
SqlUtil::cop_as
hash cop_as(any column, string arg)
returns a hash for the &quot;as&quot; operator with the given argument
SqlUtil::cop_year_month
hash cop_year_month(any column)
returns a hash for the &quot;year_month&quot; operator with the given argument
SqlUtil::COP_SUM
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2096
SqlUtil::AbstractFunctionBase::name
string name
the name of the object
Definition: SqlUtil.qm.dox.h:5374
SqlUtil::ForeignConstraintTarget
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:5260
SqlUtil::AbstractColumn::qore_type
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:4747
SqlUtil::op_gt
hash op_gt(any arg)
returns a hash for the &quot;&gt;&quot; operator with the given argument for use in where clauses when comparing c...
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:2156
SqlUtil::NumericColumnInfo
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:4843
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::iop_seq_currval
hash iop_seq_currval(string arg)
returns a hash for retrieving the current value of the given sequence in insert queries ...
SqlUtil::JopMap
const JopMap
a hash of valid join operators
Definition: SqlUtil.qm.dox.h:3063
SqlUtil::make_op
hash make_op(string op, any arg)
returns a hash with op and arg keys
SqlUtil::SZ_MAND
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:2025
SqlUtil::OP_GT
const OP_GT
the SQL greater than operator (&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3552
SqlUtil::CHAR
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2008
SqlUtil::op_clt
hash op_clt(string arg)
returns a hash for the &quot;&lt;&quot; operator with the given argument for use in where clauses when comparing t...
SqlUtil::COP_AVG
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2091
SqlUtil::DB_SEQUENCES
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:1986
SqlUtil::DB_MVIEWS
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:1980
SqlUtil::JOP_LEFT
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3055
SqlUtil::AbstractSequence
base class for sequences
Definition: SqlUtil.qm.dox.h:5300
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::join_inner_alias
hash 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...
SqlUtil::op_cgt
hash op_cgt(string arg)
returns a hash for the &quot;&gt;&quot; operator with the given argument for use in where clauses when comparing t...
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:4753
SqlUtil::cop_min
hash cop_min(any column)
returns a hash for the &quot;min&quot; operator; returns minimum column values
SqlUtil::AbstractTable::UpsertOptions
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:6857
number
number number(softnumber n)
SqlUtil::COP_DISTINCT
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2076
SqlUtil::uop_substr
hash uop_substr(int start, *int count, *hash nest)
returns a hash for the &quot;substr&quot; operator with the given arguments; returns a substring of a column va...
SqlUtil::COP_YEAR_HOUR
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:2146
SqlUtil::uop_plus
hash uop_plus(any arg, *hash nest)
returns a hash for the &quot;+&quot; operator with the given arguments
SqlUtil::AbstractTable::foreignConstraints
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7023
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:4081
SqlUtil::op_cne
hash op_cne(string arg)
returns a hash for the &quot;!=&quot; or &quot;&lt;&gt;&quot; operator with the given argument for use in where clauses when co...
SqlUtil::AbstractTable::selectRows
*list selectRows(*hash sh, *reference sql, *hash opt)
returns a list of hashes representing the rows in the table that match the argument hash ...
List
const List
SqlUtil::AbstractSqlUtilBase
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:5607
SqlUtil::AbstractTable::UpsertUpdateFirst
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:6903
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:3592
SqlUtil::Database
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:5537
SqlUtil::AbstractTable::select
*hash select(*hash sh, *reference sql, *hash opt)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
SqlUtil::OP_CGT
const OP_CGT
the SQL greater than operator (&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3582
SqlUtil::AbstractForeignConstraint
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:5282
SqlUtil::op_like
hash op_like(string str)
returns a hash for the &quot;like&quot; operator with the given argument for use in where clauses ...
SqlUtil::AbstractForeignConstraint::target
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:5287
False
const False
NothingType
const NothingType
SqlUtil::op_lt
hash op_lt(any arg)
returns a hash for the &quot;&lt;&quot; operator with the given argument for use in where clauses when comparing c...
SqlUtil::cop_coalesce
hash cop_coalesce(any col1, any col2)
returns a hash for the &quot;coalesce&quot; operator with the given column arguments; the first non-NULL column...
SqlUtil::op_le
hash op_le(any arg)
returns a hash for the &quot;&lt;=&quot; operator with the given argument for use in where clauses when comparing ...
Qore::SQL::AbstractDatasource
SqlUtil::NumericColumnInfo::scale
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:4848
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:5083
SqlUtil::COP_COUNT
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2101
list
list list(...)
SqlUtil::OP_CEQ
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3597
SqlUtil::AbstractHashContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4131
SqlUtil::op_substr
hash op_substr(int start, *int count, string text)
returns a hash for the &quot;substr&quot; operator with the given arguments; for use in where clauses ...
SqlUtil::cop_distinct
hash cop_distinct(any column)
returns a hash for the &quot;distinct&quot; operator with the given argument; returns distinct column values ...
SqlUtil::AbstractTable::name
string name
the table&#39;s name
Definition: SqlUtil.qm.dox.h:7015
SqlUtil::Triggers
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:5489
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:5088
SqlUtil::AbstractTable::indexes
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7021
Qore::SQL::SQLStatement
SqlUtil::cop_cast
hash cop_cast(any column, string arg, *any arg1, *any arg2)
returns a hash for the &quot;cast&quot; operator with the given argument(s)
SqlUtil::DB_PACKAGES
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:1982
SqlUtil::COP_UPPER
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2066
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::COP_PLUS
const COP_PLUS
the SQL &quot;plus&quot; operator
Definition: SqlUtil.qm.dox.h:2116
Boolean
const Boolean
SqlUtil::cop_minus
hash cop_minus(any column1, any column2)
returns a hash for the &quot;-&quot; operator with the given arguments
SqlUtil::cop_substr
hash cop_substr(any column, int start, *int count)
returns a hash for the &quot;substr&quot; operator with the given arguments; returns a substring of a column va...
SqlUtil::OP_GE
const OP_GE
the SQL greater than or equals operator (&gt;=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3557
SqlUtil::Indexes
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:4861
SqlUtil::SZ_NUM
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2031
SqlUtil::uop_minus
hash uop_minus(any arg, *hash nest)
returns a hash for the &quot;-&quot; operator with the given arguments
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:1994
SqlUtil::AbstractColumn::def_val
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:4756
SqlUtil::AbstractTable::primaryKey
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7019
SqlUtil::uop_seq_currval
hash uop_seq_currval(string seq)
returns a hash for the &quot;seq&quot; operator with the given argument giving the sequence name whose current ...
SqlUtil::COP_COALESCE
const COP_COALESCE
to return the first non-null argument in the list
Definition: SqlUtil.qm.dox.h:2161
SqlUtil::cop_plus
hash cop_plus(any column1, any column2)
returns a hash for the &quot;+&quot; operator with the given arguments
SqlUtil::cop_lower
hash cop_lower(any column)
returns a hash for the &quot;lower&quot; operator with the given argument; returns a column value in lower case...
SqlUtil::AbstractTable::updateCommit
int updateCommit(hash set, hash cond, reference sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
SqlUtil::wop_or
hash wop_or(hash h1, hash h2)
returns a hash with a fake &quot;_OR_&quot; column name; the list of arguments to the function is combined such...
SqlUtil::AbstractTable::triggers
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:7027
SqlUtil::DB_PROCEDURES
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:1984
SqlUtil::AbstractDatabase::CreationOptions
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:5792
SqlUtil::OP_EQ
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3567
exists
bool exists(...)
SqlUtil::AbstractTable::del
int del()
SqlUtil::AbstractTable::del() variant
SqlUtil::AbstractColumn::comment
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:4759
SqlUtil::join_left_alias
hash 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::getSelectSql
string getSelectSql(*hash sh, *reference args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
SqlUtil::AbstractView::src
string src
the source code
Definition: SqlUtil.qm.dox.h:5345
SqlUtil::AbstractIndex::unique
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:4915
SqlUtil::cop_over
hash cop_over(any column, string arg)
returns a hash for the &quot;over&quot; clause
SqlUtil::COP_YEAR_MONTH
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:2136
SqlUtil::AbstractFunctionBase::src
string src
the source of the object
Definition: SqlUtil.qm.dox.h:5380
SqlUtil::join_right_alias
hash 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::COP_MAX
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2086
SqlUtil::COP_AS
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2041
SqlUtil::cop_divide
hash cop_divide(any column1, any column2)
returns a hash for the &quot;/&quot; operator with the given arguments
SqlUtil::op_ge
hash op_ge(any arg)
returns a hash for the &quot;&gt;=&quot; operator with the given argument for use in where clauses when comparing ...
SqlUtil::AbstractTable::columns
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:7017
SqlUtil::DB_VIEWS
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:1992
SqlUtil::op_not
hash op_not(hash arg)
returns a hash for the &quot;not&quot; operator; for use in where clauses
SqlUtil::OP_LE
const OP_LE
the SQL less than or equals (&lt;=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3547
SqlUtil::BLOB
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2011
SqlUtil::AbstractIndex::name
string name
the name of the index
Definition: SqlUtil.qm.dox.h:4912
type
string type(any arg)
SqlUtil::cop_value
hash cop_value(any arg)
returns a hash for the &quot;value&quot; (literal) operator with the given argument
SqlUtil::ForeignConstraintTarget::columns
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:5268
SqlUtil::OP_CLE
const OP_CLE
the SQL less than or equals (&lt;=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3577
SqlUtil::join_left
hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
SqlUtil::AbstractColumnSupportingConstraint
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5110
SqlUtil::DB_TABLES
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:1988
SqlUtil::CLOB
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:2014
SqlUtil::OP_NOT
const OP_NOT
the SQL &quot;not&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3612
SqlUtil::AbstractIndex::columns
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:4918
SqlUtil::AbstractFunctionBase
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:5369
SqlUtil::DB_TYPES
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:1990
SqlUtil::AbstractTable::UpsertResultMap
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:6983
SqlUtil::AbstractColumn::name
string name
the name of the column
Definition: SqlUtil.qm.dox.h:4741
SqlUtil::AbstractSqlUtilBase::ds
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:5612
Util::same
bool same(list l)
SqlUtil::AbstractFunction
base class for functions
Definition: SqlUtil.qm.dox.h:5410
SqlUtil::COP_MULTIPLY
const COP_MULTIPLY
the SQL &quot;multiply&quot; operator
Definition: SqlUtil.qm.dox.h:2126
SqlUtil::AbstractTable::constraints
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:7025
SqlUtil::AbstractTable::insertFromSelectCommit
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
SqlUtil::COP_PREPEND
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:2051
SqlUtil::AbstractView
base class for views
Definition: SqlUtil.qm.dox.h:5334
SqlUtil::AbstractSqlUtilBase::opts
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:5618
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::cop_prepend
hash cop_prepend(any column, string arg)
returns a hash for the &quot;prepend&quot; operator with the given argument
SqlUtil::AbstractFunctionBase::type
string type
the type of object
Definition: SqlUtil.qm.dox.h:5377
Int
const Int
SqlUtil::COP_YEAR
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:2131
string
string string(softstring str, *string enc)
SqlUtil::uop_divide
hash uop_divide(any arg, *hash nest)
returns a hash for the &quot;/&quot; operator with the given arguments
SqlUtil::AbstractColumn::size
int size
the size of the column
Definition: SqlUtil.qm.dox.h:4750
SqlUtil::AbstractColumn::native_type
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:4744
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:2061
SqlUtil::Columns
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:4684
SqlUtil::AbstractTrigger
the base class for triggers
Definition: SqlUtil.qm.dox.h:5471
SqlUtil::join_right
hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
SqlUtil::op_eq
hash op_eq(any arg)
returns a hash for the &quot;=&quot; operator with the given argument for use in where clauses when comparing c...
SqlUtil::OP_LT
const OP_LT
the SQL less than (&lt;) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3542
SqlUtil::AbstractSqlUtilBase::dsdesc
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:5614
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::Functions
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:5433
SqlUtil::AbstractTable::UR_Unchanged
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst, UpsertInsertOnly, and UpsertUpdateOnly) ...
Definition: SqlUtil.qm.dox.h:6974
SqlUtil::Database::db
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:5542
SqlUtil::AbstractColumn
the base class for column information
Definition: SqlUtil.qm.dox.h:4736
SqlUtil::COP_CAST
const COP_CAST
to convert column value into another datatype
Definition: SqlUtil.qm.dox.h:2046
SqlUtil::AbstractTable::UpsertInsertOnly
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:6926
SqlUtil::join_inner
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
SqlUtil::OP_CGE
const OP_CGE
the SQL greater than or equals operator (&gt;=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3587
SqlUtil::op_cle
hash op_cle(string arg)
returns a hash for the &quot;&lt;=&quot; operator with the given argument for use in where clauses when comparing ...
SqlUtil::Table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:6571
SqlUtil::DefaultUopMap
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:2805
SqlUtil::cop_seq
hash cop_seq(string seq, *string as)
returns a hash for the &quot;seq&quot; operator with the given argument giving the sequence name whose value sh...
SqlUtil::make_cop
hash make_cop(string cop, any column, any arg)
returns a hash with cop, column, and arg keys
SqlUtil::COP_MIN
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2081
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:6912
SqlUtil::COP_YEAR_DAY
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:2141
Closure
const Closure
SqlUtil::AbstractTable::UpsertInsertFirst
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:6895
SqlUtil::AbstractView::name
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:5342
SqlUtil::AbstractSequence::max
*number max
the ending number
Definition: SqlUtil.qm.dox.h:5314
SqlUtil::cop_upper
hash cop_upper(any column)
returns a hash for the &quot;upper&quot; operator with the given argument; returns a column value in upper case...
SqlUtil::uop_multiply
hash uop_multiply(any arg, *hash nest)
returns a hash for the &quot;*&quot; operator with the given arguments
SqlUtil::AbstractSequence::increment
number increment
the increment
Definition: SqlUtil.qm.dox.h:5311
SqlUtil::AbstractTable::update
int update(hash set, hash cond, reference sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
SqlUtil::OP_LIKE
const OP_LIKE
the SQL &quot;like&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3537
SqlUtil::SZ_NONE
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2022
SqlUtil::Table::t
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6576
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:3572
SqlUtil::COP_MINUS
const COP_MINUS
the SQL &quot;minus&quot; operator
Definition: SqlUtil.qm.dox.h:2111
SqlUtil::ForeignConstraintTarget::table
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:5265
hash
hash hash(object obj)
SqlUtil::cop_year_day
hash cop_year_day(any column)
returns a hash for the &quot;year_day&quot; operator with the given argument
SqlUtil::COP_SUBSTR
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2166
SqlUtil::JOP_RIGHT
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3060
SqlUtil::OP_SUBSTR
const OP_SUBSTR
the SQL &quot;substr&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3617
SqlUtil::make_uop
hash make_uop(string uop, any arg, *hash nest)
returns a hash with uop, arg, and nest keys
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::SZ_OPT
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:2028
SqlUtil::cop_year
hash cop_year(any column)
returns a hash for the &quot;year&quot; operator with the given argument
SqlUtil::AbstractSequence::start
number start
the starting number
Definition: SqlUtil.qm.dox.h:5308
SqlUtil::IOP_SEQ
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4076
SqlUtil::AbstractTable::getRowIterator
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql, *hash opt)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
SqlUtil::AbstractDatabase
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:5660
SqlUtil::cop_multiply
hash cop_multiply(any column1, any column2)
returns a hash for the &quot;*&quot; operator with the given arguments
SqlUtil::cop_seq_currval
hash cop_seq_currval(string seq, *string as)
returns a hash for the &quot;seq_currval&quot; operator with the given argument giving the sequence name whose ...
SqlUtil::AbstractColumnSupportingConstraint::index
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:5118
SqlUtil::AbstractPrimaryKey
represents a primary key
Definition: SqlUtil.qm.dox.h:5202
SqlUtil::JOP_INNER
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3050
SqlUtil::COP_LOWER
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2071
SqlUtil::COP_DIVIDE
const COP_DIVIDE
the SQL &quot;divide&quot; operator
Definition: SqlUtil.qm.dox.h:2121
join
string join(string str,...)
SqlUtil::DB_FUNCTIONS
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:1978
SqlUtil::NUMERIC
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2005
SqlUtil::op_ceq
hash op_ceq(string arg)
returns a hash for the &quot;=&quot; operator with the given argument for use in where clauses when comparing t...
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:5115
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::cop_year_hour
hash cop_year_hour(any column)
returns a hash for the &quot;year_hour&quot; operator with the given argument
SqlUtil::DefaultOpMap
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3623
SqlUtil::AbstractUniqueConstraint
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5193
SqlUtil::cop_max
hash cop_max(any column)
returns a hash for the &quot;max&quot; operator; returns maximum column values
SqlUtil::AbstractConstraint
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5021
SqlUtil::cop_count
hash cop_count(any column="")
returns a hash for the &quot;count&quot; operator; returns row counts
SqlUtil::uop_seq
hash uop_seq(string seq)
returns a hash for the &quot;seq&quot; operator with the given argument giving the sequence name whose value sh...
SqlUtil::Constraints
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:4979
SqlUtil::COP_APPEND
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2056