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::AbstractIndex::getRenameSql
abstract string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
SqlUtil::AbstractDatabase::ActionMap
const ActionMap
maps from action codes to action descriptions
Definition: SqlUtil.qm.dox.h:5738
SqlUtil::AbstractConstraint::name
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5030
SqlUtil::AbstractSqlUtilBase::validateHashKeysForWhitespaces
private validateHashKeysForWhitespaces(any node)
Check input node for all hash keys - if it contains a key with whitespace in the beginning or at the ...
SqlUtil::AbstractSequence::constructor
constructor(string n_name, number n_start=1, number n_increment=1, *softnumber n_max)
creates the object from the arguments
SqlUtil::cop_avg
hash cop_avg(any column)
returns a hash for the "avg" operator; returns average column values
SqlUtil::Columns::getElementName
string getElementName()
returns "column" since this object stores column objects
SqlUtil::AbstractTable::getDropSql
softlist getDropSql(*hash opt)
returns the sql required to drop the table; reimplement in subclasses if necessary ...
SqlUtil::AbstractConstraint::hasColumn
bool hasColumn(string cname)
returns True if the constraint references the named column
SqlUtil::Tables::constructor
constructor()
creates an empty object
SqlUtil::AbstractTable::addIndex
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql)
adds an index to the table; if the table is already known to be in the database, then it is added in ...
SqlUtil::AbstractTable::SelectOptions
const SelectOptions
default select options
Definition: SqlUtil.qm.dox.h:6724
SqlUtil::AbstractFunctionBase::getDropSql
string getDropSql()
returns a string that can be used to drop the function from the database
SqlUtil::AbstractTable::getConstraints
Constraints getConstraints()
returns a Constraints object describing the non-foreign constraints on the table
SqlUtil::AbstractTable::getCacheOptions
private hash getCacheOptions()
returns the cache options for this driver
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 "lower" 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
SqlUtil::AbstractHashContainer::pairIterator
Qore::AbstractIterator pairIterator()
Returns a HashPairIterator object for the contained hash.
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
SqlUtil::AbstractDatabase::getAlignProcedureSql
list getAlignProcedureSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a stored procedure in the database to the st...
String
const String
SqlUtil::AbstractSqlUtilBase::getDatasource
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
SqlUtil::op_cge
hash op_cge(string arg)
returns a hash for the ">=" 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::AbstractTable::getTriggerOptions
private hash getTriggerOptions()
returns the trigger options for this driver
SqlUtil::AbstractListContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4413
SqlUtil::AbstractTable::TableOmissionOptions
const TableOmissionOptions
alignment omission options
Definition: SqlUtil.qm.dox.h:6741
SqlUtil::AbstractSequence::getDropSql
string getDropSql()
returns a string that can be used to drop the sequence from the database
SqlUtil::AbstractDatabase::getDropSchemaSql
list getDropSchemaSql(hash schema_hash, *hash opt)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
SqlUtil::AbstractHashContainer::copy
copy(AbstractHashContainer old)
creates a "deep copy" of the object
SqlUtil::cop_append
hash cop_append(any column, string arg)
returns a hash for the "append" operator with the given argument
SqlUtil::uop_append
hash uop_append(string arg, *hash nest)
returns a hash for the "append" or concatenate operator with the given argument
sprintf
string sprintf(string fmt,...)
SqlUtil::AbstractHashContainer::constructor
constructor(*hash nh)
creates the object with the hash argument passed
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::AbstractListContainer::iterator
Qore::ListIterator iterator()
Returns a ListIterator object for the contained list.
SqlUtil::AbstractDatabase::getDatabaseOptions
private hash getDatabaseOptions()
override in subclasses to return driver-specific options
SqlUtil::AbstractTable::truncateNoCommit
deprecated truncateNoCommit()
A legacy warpper for truncate()
SqlUtil::AbstractColumnSupportingConstraint::hasColumn
bool hasColumn(string cname)
returns True if the constraint references the named column
SqlUtil::AbstractDatabase::AC_Unchanged
const AC_Unchanged
used when an existing object matches the template and no changes are made
Definition: SqlUtil.qm.dox.h:5701
SqlUtil::AbstractColumnSupportingConstraint::getDisableReenableSql
hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts)
returns lists of SQL strings to disable this constraint plus any dependent constraints and another li...
SqlUtil::Functions::getElementName
string getElementName()
must return the name of the contained element
SqlUtil::ForeignConstraintTarget::equal
bool equal(ForeignConstraintTarget targ)
returns True if the argument is equal to the current object, False if not
SqlUtil::AbstractTable::modifyColumn
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table is already known to be in the database...
SqlUtil::AbstractTable::delCommit
int delCommit()
SqlUtil::AbstractTable::delCommit() variant
SqlUtil::AbstractDatabase::dropProcedureIfExists
bool dropProcedureIfExists(string name, *hash opt)
drops the given procedure if it exists; returns True if the procedure was dropped, False if not
SqlUtil::OP_IN
const OP_IN
the SQL "in" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3607
SqlUtil::AbstractTable::createNoCommit
deprecated createNoCommit(*hash opt)
A legacy wrapper for create()
SqlUtil::Columns::constructor
constructor(*hash c)
creates the object from the argument
SqlUtil::AbstractTable::checkExistence
bool checkExistence()
returns True if the table exists in the database, False if not
SqlUtil::AbstractHashContainer::getHash
*hash getHash()
returns the hash contained by this object
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::AbstractConstraint::equal
bool equal(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
SqlUtil::AbstractTable::hasReturning
bool hasReturning()
returns True if the current database driver supports the "returning" clause in insert statements...
SqlUtil::AbstractColumnSupportingConstraint::setIndexBase
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
SqlUtil::AbstractTable::tryExec
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
SqlUtil::Table::methodGate
any methodGate(string meth)
executes a method on the contained AbstractTable object
SqlUtil::iop_seq
hash iop_seq(string arg)
returns a hash for retrieving the value of the given sequence in insert queries
SqlUtil::AbstractIndex::equalExceptName
bool equalExceptName(AbstractIndex ix)
returns True if the argument is equal to the current index with the exception of the name...
SqlUtil::VARCHAR
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2002
SqlUtil::Functions::memberGate
AbstractFunction memberGate(string k)
returns the AbstractFunction object corresponding to the key given or throws a KEY-ERROR exception ...
SqlUtil::uop_upper
hash uop_upper(*hash nest)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
SqlUtil::AbstractDatabase::getAlignFunctionSql
list getAlignFunctionSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a function in the database to the function d...
SqlUtil::AbstractTable::ForeignConstraintOptions
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:6701
SqlUtil::AbstractTable::insertCommit
*hash insertCommit(hash row)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
SqlUtil::AbstractTable::ColumnOptions
const ColumnOptions
Column options; this is currently empty and can be extended in database-specific modules.
Definition: SqlUtil.qm.dox.h:6824
SqlUtil::Tables
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:4502
SqlUtil::AbstractTable::getUniqueConstraintIterator
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
SqlUtil::AbstractConstraint::constructor
constructor(string n)
creates the object and sets its name
SqlUtil::AbstractView::updatable
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:5348
SqlUtil::AbstractDatabase::getCreationOptions
private hash getCreationOptions()
override in subclasses to return driver-specific options
SqlUtil::AbstractCheckConstraint::equalImpl
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
SqlUtil::AbstractTable::getAddPrimaryKeySql
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
SqlUtil::op_between
hash op_between(any l, any r)
returns a hash for the "between" operator with the given arguments, neither of which can be NULL or N...
SqlUtil::AbstractView::getCreateSql
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
SqlUtil::AbstractTable::UpsertResultLetterMap
const UpsertResultLetterMap
maps upsert result codes to single letter symbols
Definition: SqlUtil.qm.dox.h:7003
SqlUtil::AbstractTable::UpsertStrategyMap
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:6938
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::Indexes::take
AbstractIndex take(string k)
removes the given key from the contained hash and returns the value
SqlUtil::AbstractSequence::getCreateSql
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the sequence in the database
SqlUtil::AbstractTrigger::getRenameSql
abstract list getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the trigger in the database
SqlUtil::AbstractTable::dropCommit
dropCommit(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
SqlUtil::AbstractDatabase::DropSchemaOptions
const DropSchemaOptions
default generic drop schema options
Definition: SqlUtil.qm.dox.h:5807
SqlUtil::uop_prepend
hash uop_prepend(string arg, *hash nest)
returns a hash for the "prepend" operator with the given argument
SqlUtil::AbstractDatabase::SchemaDescriptionOptions
const SchemaDescriptionOptions
default generic schema description keys
Definition: SqlUtil.qm.dox.h:5822
SqlUtil::AbstractTable::UR_Inserted
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:6965
SqlUtil::ForeignConstraintTarget::constructor
constructor(string t, Columns c)
creates the object and sets the target table name and the target columns
SqlUtil::AbstractView::constructor
constructor(string n_name, string n_src)
creates the object from the arguments
SqlUtil::op_in
hash op_in()
returns a hash for the "in" operator with all arguments passed to the function; for use in where clau...
SqlUtil::AbstractTable::cache
cache(*hash opts)
reads in all attributes of the table from the database
printf
string printf(string fmt,...)
SqlUtil::OP_BETWEEN
const OP_BETWEEN
the SQL "between" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3602
SqlUtil::AbstractIndex::constraint
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:4924
SqlUtil::AbstractDatabase::getView
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view cannot be found ...
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::AbstractHashContainer::take
abstract any take(string k)
removes the given key from the contained hash and returns the value
SqlUtil::AbstractDatabase::DatabaseOptions
const DatabaseOptions
database options
Definition: SqlUtil.qm.dox.h:5668
SqlUtil::AbstractConstraint::getDisableSql
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database; if disabli...
SqlUtil::AbstractTable::getIndexOptions
private hash getIndexOptions()
returns the index options for this driver
SqlUtil::AbstractIndex
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:4907
SqlUtil::Constraints::findEqualUniqueConstraint
*AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk)
finds a unique constraint with the same columns as the unique constraint passed
SqlUtil::OP_OR
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3620
SqlUtil::AbstractDatabase::procedureIterator
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
SqlUtil::AbstractTable::getTriggers
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
SqlUtil::Columns::add
add(string k, AbstractColumn val)
adds the given value to the hash with the given key name
SqlUtil::COP_OVER
const COP_OVER
the SQL "over" 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::AbstractTable::UpsertResultDescriptionMap
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:6994
SqlUtil::AbstractTable::insertNoCommit
deprecated *hash insertNoCommit(hash row, *reference sql, *hash opt)
A legacy wrapper for SqlUtil::AbstractTable::insert()
SqlUtil::AbstractTable::UR_Deleted
const UR_Deleted
row was deleted (only possible with batch upsert methods such as AbstractTable::upsertFromIterator() ...
Definition: SqlUtil.qm.dox.h:6977
SqlUtil::AbstractTable::insertFromIteratorCommit
int insertFromIteratorCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
SqlUtil::AbstractTable::InsertFromIteratorOptions
const InsertFromIteratorOptions
default insert option keys
Definition: SqlUtil.qm.dox.h:6869
SqlUtil::AbstractColumnSupportingConstraint::equalImpl
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
SqlUtil::AbstractDatabase::listTables
list listTables()
returns a list of string table names in the database
SqlUtil::op_ne
hash op_ne(any arg)
returns a hash for the "!=" or "<>" operator with the given argument for use in where clauses when co...
SqlUtil::AbstractUniqueConstraint::constructor
constructor(string n, *hash c, *string n_index)
creates the object from the name an a hash of column information
SqlUtil::AbstractTable::uniqueIndexCreatesConstraintImpl
abstract private bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
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::AbstractIndex::hasColumn
bool hasColumn(string cname)
returns True if the constraint references the named column
SqlUtil::AbstractTable::upsertNoCommit
deprecated int upsertNoCommit(hash row, int upsert_strategy=UpsertAuto)
A legacy SqlUtil::AbstractTable::upsert() wrapper.
SqlUtil::OP_NE
const OP_NE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3562
SqlUtil::AbstractTable::dropIndex
AbstractIndex dropIndex(string iname, *reference sql)
drops the given index from the table; if the table is known to be in the database already...
SqlUtil::AbstractDatabase::computeStatistics
computeStatistics(*hash options)
Compute database statistics.
Qore::ListIterator
SqlUtil::AbstractTable::dropColumn
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table
SqlUtil::AbstractIndex::setSupportingConstraint
setSupportingConstraint()
clears the supporting constraint
SqlUtil::cop_sum
hash cop_sum(any column)
returns a hash for the "sum" operator; returns the total sum of a numeric column. ...
SqlUtil::cop_as
hash cop_as(any column, string arg)
returns a hash for the "as" operator with the given argument
SqlUtil::AbstractDatabase::getSchemaDescriptionOptions
private hash getSchemaDescriptionOptions()
override in subclasses to return driver-specific options
SqlUtil::AbstractFunctionBase::getType
string getType()
returns the type of object
SqlUtil::Database::methodGate
any methodGate(string meth)
executes a method on the contained AbstractDatabase object
SqlUtil::AbstractTable::getAddCheckConstraintSql
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
SqlUtil::AbstractView::getRenameSql
abstract softlist getRenameSql(string new_name)
returns a list with command(s) that can be used to rename the view in the database ...
SqlUtil::cop_year_month
hash cop_year_month(any column)
returns a hash for the "year_month" operator with the given argument
SqlUtil::COP_SUM
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2096
SqlUtil::AbstractTable::getAlignSql
list getAlignSql(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
SqlUtil::AbstractConstraint::getDropSql
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from the database
SqlUtil::AbstractTable::getRawUpdateOperatorMap
private hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
SqlUtil::AbstractTable::constructor
private constructor(AbstractDatasource nds, string nname, *hash nopts)
creates the object; private constructor
SqlUtil::AbstractTable::truncateCommit
truncateCommit()
truncates all the table data; releases the transaction lock after executing
SqlUtil::AbstractFunctionBase::name
string name
the name of the object
Definition: SqlUtil.qm.dox.h:5374
SqlUtil::AbstractTable::getAlignSqlString
string getAlignSqlString(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
SqlUtil::ForeignConstraintTarget
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:5260
SqlUtil::AbstractTable::getCreateIndexesSql
*list getCreateIndexesSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
SqlUtil::AbstractDatabase::getDropFunctionSqlIfExists
*string getDropFunctionSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given function if it exists or NOTHING if the named function does...
SqlUtil::AbstractColumn::qore_type
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:4747
SqlUtil::Constraints::add
add(string k, AbstractConstraint val)
adds the given value to the hash with the given key name
SqlUtil::op_gt
hash op_gt(any arg)
returns a hash for the ">" 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::AbstractDatabase::getComputeStatisticsOptions
private hash getComputeStatisticsOptions()
override in subclasses to return driver-specific options
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...
SqlUtil::AbstractIndex::getRecreateSql
list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt)
returns a list of strings to drop and recreate the current index; if there are dependent constraints...
SqlUtil::AbstractDatabase::AC_Create
const AC_Create
used when a new object is created
Definition: SqlUtil.qm.dox.h:5704
SqlUtil::Functions::add
add(string k, AbstractFunction val)
adds the given value to the hash with the given key name
True
const True
SqlUtil::Triggers::memberGate
AbstractTrigger memberGate(string k)
returns the AbstractTrigger object corresponding to the key given or throws a KEY-ERROR exception ...
SqlUtil::AbstractTable::getQoreTypeMapImpl
abstract private hash getQoreTypeMapImpl()
returns the qore type -> column type map
SqlUtil::AbstractHashContainer::keys
list keys()
Returns a list of key names of the contained hash.
SqlUtil::AbstractTable::addForeignConstraint
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql)
adds a foreign constraint to the table; if the table is already known to be in the database...
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 (>) 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 "<" 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::AbstractTable::clearImpl
private clearImpl()
clears any driver-specific table information
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::AbstractTable::getCreateTriggersSql
*list getCreateTriggersSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
SqlUtil::op_cgt
hash op_cgt(string arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing t...
SqlUtil::AbstractTable::getColumnOperatorMap
private hash getColumnOperatorMap()
returns the column operator map for this object
SqlUtil::Indexes::getElementName
string getElementName()
must return the name of the contained element
SqlUtil::AbstractListContainer::add
add(any val)
adds the given value to the list
SqlUtil::AbstractDatabase::getSequence
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
SqlUtil::AbstractHashContainer::getElementName
abstract string getElementName()
must return the name of the contained element
SqlUtil::Columns::subset
Columns subset(softlist l)
returns a subset of the current columns according to the list argument
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 "min" operator; returns minimum column values
SqlUtil::AbstractTable::addPrimaryKey
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql)
adds a primary key to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
SqlUtil::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 "substr" 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::AbstractTable::CacheOptions
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:6693
SqlUtil::AbstractDatabase::makeFunction
AbstractFunction makeFunction(string name, string src, *hash opts)
creates a database-specific AbstractFunction object corresponding to the arguments ...
SqlUtil::AbstractTable::describe
Columns describe()
returns an object of class Columns describing the table
SqlUtil::AbstractTable::getAddTriggerSql
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
SqlUtil::Tables::getDropAllForeignConstraintsOnTableSql
*list getDropAllForeignConstraintsOnTableSql(string name, *hash opt)
returns a list of SQL strings that can be used to drop all the foreign constraints on a particular ta...
SqlUtil::uop_plus
hash uop_plus(any arg, *hash nest)
returns a hash for the "+" operator with the given arguments
SqlUtil::AbstractTable::foreignConstraints
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7023
SqlUtil::AbstractTable::native_case
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:7029
SqlUtil::AbstractTable::getTruncateSql
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
SqlUtil::AbstractTable::renameConstraint
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
SqlUtil::AbstractTable::getDropAllConstraintsAndIndexesOnColumnSql
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt)
gets a list of SQL strings to drop all constraints and indexes with the given column name; if the col...
SqlUtil::AbstractTable::getUpdateOperatorMap
private hash getUpdateOperatorMap()
returns the update operator map for this object
SqlUtil::AbstractDatabase::dropSequenceIfExists
bool dropSequenceIfExists(string name, *hash opt)
drops the given sequence if it exists; returns True if the sequence was dropped, False if not ...
SqlUtil::AbstractTable::getDropPrimaryKeySql
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
SqlUtil::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::Functions::take
AbstractFunction take(string k)
removes the given key from the contained hash and returns the value
SqlUtil::op_cne
hash op_cne(string arg)
returns a hash for the "!=" or "<>" 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 ...
SqlUtil::AbstractTable::addTrigger
AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql)
adds a trigger to the table; if the table is already known to be in the database, then it is added in...
List
const List
SqlUtil::AbstractSqlUtilBase
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:5607
SqlUtil::AbstractDatabase::CacheOptions
const CacheOptions
generic cache options
Definition: SqlUtil.qm.dox.h:5676
SqlUtil::AbstractTable::UpsertUpdateFirst
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:6903
SqlUtil::AbstractSqlUtilBase::constructor
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
SqlUtil::AbstractTable::tryInsertImpl
abstract private bool tryInsertImpl(string sql, hash row)
tries to insert a row, if there is a duplicate key, then it returns False, if successful, returns True
SqlUtil::AbstractTable::getAddColumnSql
list getAddColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
returns a list of SQL strings that can be use to add a column to the table
SqlUtil::AbstractTable::getColumnSqlName
string getColumnSqlName(string col)
returns the column name for use in SQL strings; subclasses can return a special string in case the co...
NULL
const NULL
SqlUtil::AbstractDatabase::AC_Modify
const AC_Modify
used when an object is modified in place
Definition: SqlUtil.qm.dox.h:5713
SqlUtil::Columns::equal
bool equal(Columns cols)
returns True if the argument has the same columns in the same order as the current object...
SqlUtil::AbstractTable::create
create(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
SqlUtil::OP_CNE
const OP_CNE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3592
SqlUtil::AbstractHashContainer::memberGate
any memberGate(string k)
returns the value of the given key in the contained hash if it exists, otherwise throws a KEY-ERROR e...
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::AbstractTable::doSelectLimitOnlyUnlockedImpl
abstract private doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh)
processes a string for use in SQL select statements when there is a "limit" argument, but no "orderby" or "offset" arguments
SqlUtil::Table::constructor
constructor(AbstractDatasource ds, string name, *hash opts)
creates the Table object
SqlUtil::AbstractTable::getSqlDataCallbackOptions
private hash getSqlDataCallbackOptions()
returns the sql data operation callback options for this driver
SqlUtil::OP_CGT
const OP_CGT
the SQL greater than operator (>) 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 "like" operator with the given argument for use in where clauses ...
SqlUtil::Database::getDatabase
SqlUtil::AbstractDatabase getDatabase()
gets the underlying AbstractDatabase
SqlUtil::AbstractForeignConstraint::target
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:5287
SqlUtil::AbstractDatabase::getFunction
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
SqlUtil::AbstractIndex::getSupportingConstraint
*AbstractColumnSupportingConstraint getSupportingConstraint()
returns the supporting constraint, if any
SqlUtil::AbstractTable::upsertFromSelectNoCommit
deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtil::AbstractTable::upsertFromSelect() wrapper.
False
const False
SqlUtil::AbstractCheckConstraint::setIndexBase
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
SqlUtil::AbstractCheckConstraint::constructor
constructor(string n, string n_src)
creates the object and sets its name and the check clause source
SqlUtil::Constraints::memberGate
AbstractConstraint memberGate(string k)
returns the AbstractConstraint object corresponding to the key given or throws a KEY-ERROR exception ...
SqlUtil::AbstractSqlUtilBase::l
Mutex l()
mutex for atomic actions
SqlUtil::AbstractTable::dropNoCommit
deprecated dropNoCommit(*hash opt)
A legacy wrapper for drop()
SqlUtil::AbstractTable::copyImpl
abstract private copyImpl(AbstractTable old)
db-specific copy actions
SqlUtil::AbstractTable::getAddUniqueConstraintSql
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
NothingType
const NothingType
SqlUtil::op_lt
hash op_lt(any arg)
returns a hash for the "<" 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 "coalesce" operator with the given column arguments; the first non-NULL column...
SqlUtil::op_le
hash op_le(any arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
SqlUtil::AbstractTable::getInsertFromIteratorOptions
private hash getInsertFromIteratorOptions()
returns the insert from iterator options for this driver
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::AbstractDatabase::AC_Drop
const AC_Drop
used when an object is dropped
Definition: SqlUtil.qm.dox.h:5707
SqlUtil::AbstractFunctionBase::equal
bool equal(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
SqlUtil::AbstractIndex::constructor
constructor(string n, bool u, hash c)
creates the object from the name, a unique flag, and a hash of column information ...
SqlUtil::COP_COUNT
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2101
list
list list(...)
SqlUtil::AbstractTable::getCreateSql
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
SqlUtil::OP_CEQ
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3597
SqlUtil::AbstractHashContainer
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4131
SqlUtil
the SqlUtil namespace contains all the objects in the SqlUtil module
Definition: SqlUtil.qm.dox.h:1969
SqlUtil::op_substr
hash op_substr(int start, *int count, string text)
returns a hash for the "substr" operator with the given arguments; for use in where clauses ...
SqlUtil::AbstractTable::empty
bool empty()
returns True if the table has no definitions, False if not
SqlUtil::cop_distinct
hash cop_distinct(any column)
returns a hash for the "distinct" operator with the given argument; returns distinct column values ...
SqlUtil::AbstractDatabase::sequenceIterator
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
SqlUtil::AbstractDatabase::ActionLetterMap
const ActionLetterMap
maps from action codes to action letter codes
Definition: SqlUtil.qm.dox.h:5770
SqlUtil::AbstractTable::name
string name
the table's name
Definition: SqlUtil.qm.dox.h:7015
SqlUtil::AbstractTable::supportsTablespacesImpl
abstract private bool supportsTablespacesImpl()
returns True if the database support tablespaces
SqlUtil::AbstractDatabase::supportsPackages
bool supportsPackages()
returns True if the database supports packages
SqlUtil::AbstractTable::getAddIndexSql
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
SqlUtil::Triggers
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:5489
SqlUtil::AbstractTable::dropTrigger
AbstractTrigger dropTrigger(string tname, *reference sql)
drops the given trigger from the table; if the table is known to be in the database already...
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::AbstractSqlUtilBase::getDatasourceDesc
string getDatasourceDesc()
returns a descriptive string for the datasource
SqlUtil::AbstractTable::indexes
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7021
SqlUtil::AbstractTable::getPseudoColumnHash
private *hash getPseudoColumnHash()
returns a hash of valid pseudocolumns
SqlUtil::AbstractColumnSupportingConstraint::addSourceConstraint
addSourceConstraint(string tname, AbstractForeignConstraint fk)
adds a foreign constraint source to the unique constraint
SqlUtil::AbstractDatabase::getDropSequenceSqlIfExists
*string getDropSequenceSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given sequence if it exists or NOTHING if the named sequence does...
Qore::SQL::SQLStatement
SqlUtil::cop_cast
hash cop_cast(any column, string arg, *any arg1, *any arg2)
returns a hash for the "cast" operator with the given argument(s)
SqlUtil::AbstractDatabase::getDropSchemaOptions
private hash getDropSchemaOptions()
override in subclasses to return driver-specific options
SqlUtil::DB_PACKAGES
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:1982
SqlUtil::Columns::take
AbstractColumn take(string k)
removes the given key from the contained hash and returns the value
SqlUtil::AbstractDatabase::listProcedures
list listProcedures()
returns a list of string procedure names in the database
SqlUtil::COP_UPPER
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2066
SqlUtil::AbstractTable::upsertFromIteratorNoCommit
deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtik::AbstractTable::upsertFromIterator() wrapper.
SqlUtil::AbstractDatabase::functionIterator
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
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 "plus" operator
Definition: SqlUtil.qm.dox.h:2116
SqlUtil::AbstractTable::getSelectOptions
private hash getSelectOptions()
returns the select options for this driver
Boolean
const Boolean
SqlUtil::AbstractFunctionBase::equalImpl
abstract private bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
SqlUtil::cop_minus
hash cop_minus(any column1, any column2)
returns a hash for the "-" operator with the given arguments
SqlUtil::cop_substr
hash cop_substr(any column, int start, *int count)
returns a hash for the "substr" operator with the given arguments; returns a substring of a column va...
SqlUtil::AbstractTable::UR_Verified
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:6968
SqlUtil::AbstractDatabase::supportsSequencesImpl
abstract private bool supportsSequencesImpl()
returns True if the database supports sequences
SqlUtil::AbstractTable::clear
clear()
purges the current table definition
SqlUtil::OP_GE
const OP_GE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3557
SqlUtil::Indexes
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:4861
SqlUtil::AbstractTable::validateColumnOptions
private validateColumnOptions(string cname, reference opt, bool nullable)
validates column options
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::AbstractTable::constraintsLinkedToIndexesImpl
abstract private bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
SqlUtil::uop_minus
hash uop_minus(any arg, *hash nest)
returns a hash for the "-" operator with the given arguments
SqlUtil::AbstractTable::TableOptions
const TableOptions
table options
Definition: SqlUtil.qm.dox.h:6672
SqlUtil::AbstractTable::tryExecArgs
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
SqlUtil::AbstractDatabase::AC_Rename
const AC_Rename
used when an object is renamed
Definition: SqlUtil.qm.dox.h:5710
SqlUtil::AbstractIndex::equalImpl
abstract bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
SqlUtil::AbstractTable::getTableColumnDescOptions
private hash getTableColumnDescOptions()
returns the table column description options for this driver
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::AbstractDatabase::getAlignSql
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
SqlUtil::AbstractTable::getForeignConstraints
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
SqlUtil::AbstractDatabase::tryExecArgs
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
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::insertFromIterator
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
SqlUtil::AbstractColumn::getCreateSql
string getCreateSql(AbstractTable t)
returns an sql string that can be used to add the column to a table
SqlUtil::AbstractTable::primaryKey
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7019
SqlUtil::AbstractTable::tryExecRaw
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
SqlUtil::uop_seq_currval
hash uop_seq_currval(string seq)
returns a hash for the "seq" 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::AbstractDatabase::reclaimSpace
reclaimSpace(*hash options)
Reclaim taken but unused space in the DB.
SqlUtil::cop_plus
hash cop_plus(any column1, any column2)
returns a hash for the "+" operator with the given arguments
SqlUtil::AbstractTable::manual
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:7033
SqlUtil::AbstractTable::AlignTableOptions
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:6763
SqlUtil::AbstractTable::getPrimaryKey
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
SqlUtil::Indexes::findEqual
*AbstractIndex findEqual(AbstractIndex ix)
find an index with columns equal to the index passed
SqlUtil::AbstractTable::emptyData
bool emptyData()
returns True if the table has no data rows, False if not
SqlUtil::Tables::tableRenamed
bool tableRenamed(string old_name, string new_name, string old_sql_name)
updates table names and internal references for renamed tables
SqlUtil::AbstractTable::getBaseType
string getBaseType()
returns the base type of the underlying object (normally "table", some DB-specific implementations ma...
SqlUtil::AbstractConstraint::getCreateSql
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
SqlUtil::AbstractColumnSupportingConstraint::removeSourceConstraint
removeSourceConstraint(string tname, list cols)
removes a source constraint
SqlUtil::AbstractTable::getCreateForeignConstraintsSql
*list getCreateForeignConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
SqlUtil::NumericColumnInfo::getNativeTypeString
string getNativeTypeString(string native_type, int precision)
returns the string describing the native type that can be used in SQL (for example to add the column ...
SqlUtil::AbstractTable::hasArrayBind
abstract bool hasArrayBind()
returns True if the underlying DB driver supports bulk DML operations
SqlUtil::cop_lower
hash cop_lower(any column)
returns a hash for the "lower" 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 "_OR_" 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::AbstractTable::getDesc
string getDesc()
returns a descriptive string of the datasource (without the password) and the table name (with a poss...
SqlUtil::Tables::getRenameTableIfExistsSql
*string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts)
returns an SQL string that can be used to rename the given table if it exists and the target does not...
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::AbstractColumn::getRenameSql
abstract string getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
SqlUtil::Tables::memberGate
AbstractTable memberGate(string k)
returns the AbstractTable object corresponding to the key given or throws a KEY-ERROR exception ...
SqlUtil::OP_EQ
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3567
SqlUtil::AbstractConstraint::getEnableSql
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database; if disabling constraints ...
SqlUtil::AbstractTable::getDropColumnSql
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
SqlUtil::AbstractDatabase::dropViewIfExists
bool dropViewIfExists(string name, *hash opt)
drops the given view if it exists; returns True if the view was dropped, False if not ...
exists
bool exists(...)
SqlUtil::AbstractTable::del
int del()
SqlUtil::AbstractTable::del() variant
SqlUtil::ForeignConstraints::take
AbstractForeignConstraint take(string k)
removes the given key from the contained hash and returns the value
SqlUtil::AbstractConstraint::equalImpl
abstract private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
SqlUtil::AbstractListContainer::getElementName
abstract string getElementName()
must return the name of the contained element
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::getBulkUpsertClosure
code getBulkUpsertClosure(hash example_row, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing either a single row or a se...
SqlUtil::Tables::dropIterator
Qore::AbstractIterator dropIterator()
returns an iterator for a list of cached table names in the order that can be used to drop the tables...
SqlUtil::AbstractListContainer::val
bool val()
Returns False if the contained list is empty, True if not.
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::AbstractTable::getDropIndexSql
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
SqlUtil::AbstractColumn::getModifySql
list getModifySql(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
SqlUtil::cop_over
hash cop_over(any column, string arg)
returns a hash for the "over" clause
SqlUtil::AbstractDatabase::AC_Insert
const AC_Insert
used when data is inserted in a table
Definition: SqlUtil.qm.dox.h:5725
SqlUtil::Tables::add
add(string k, Table val)
adds the given value to the hash with the given key name
SqlUtil::Database::constructor
constructor(AbstractDatasource ds, *hash opts)
creates the Database object
SqlUtil::AbstractColumn::getNativeTypeString
string getNativeTypeString()
returns the string describing the native type that can be used in SQL (for example to add the colunn ...
SqlUtil::AbstractHashContainer::iterator
Qore::AbstractIterator iterator()
Returns a HashIterator object for the contained hash.
SqlUtil::AbstractTable::tryExecRawImpl
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
SqlUtil::AbstractDatabase::tableIterator
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
SqlUtil::AbstractTable::getAddForeignConstraintSql
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
SqlUtil::AbstractTable::getSqlName
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifier for schema, etc)
SqlUtil::AbstractColumn::getAddColumnSql
abstract list getAddColumnSql(AbstractTable t)
returns a list of sql strings that can be used to add the column to an existing table ...
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::Triggers::getElementName
string getElementName()
must return the name of the contained element
SqlUtil::AbstractTable::getForeignConstraintOptions
private hash getForeignConstraintOptions()
return the foreign constraint options for this driver
SqlUtil::COP_MAX
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2086
SqlUtil::AbstractTable::dropForeignConstraint
AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql)
drops a foreign constraint from the table; if the table is known to be in the database already...
SqlUtil::COP_AS
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2041
SqlUtil::AbstractSqlUtilBase::getDriverName
string getDriverName()
returns the database driver name
SqlUtil::cop_divide
hash cop_divide(any column1, any column2)
returns a hash for the "/" operator with the given arguments
SqlUtil::op_ge
hash op_ge(any arg)
returns a hash for the ">=" operator with the given argument for use in where clauses when comparing ...
SqlUtil::AbstractConstraint::getRenameSql
abstract list getRenameSql(string table_name, string new_name)
returns a list of SQL strings that can be used to rename the constraint in the database ...
SqlUtil::AbstractTable::columns
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:7017
SqlUtil::AbstractDatabase::constructor
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
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 "not" operator; for use in where clauses
SqlUtil::OP_LE
const OP_LE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3547
SqlUtil::AbstractDatabase::getCacheOptions
private hash getCacheOptions()
override in subclasses to return driver-specific options
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
SqlUtil::AbstractDatabase::getReclaimSpaceOptions
private hash getReclaimSpaceOptions()
override in subclasses to return driver-specific options
type
string type(any arg)
SqlUtil::cop_value
hash cop_value(any arg)
returns a hash for the "value" (literal) operator with the given argument
SqlUtil::AbstractTable::dropConstraint
AbstractConstraint dropConstraint(string cname, *reference sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
SqlUtil::AbstractTable::getCreatePrimaryKeySql
*string getCreatePrimaryKeySql(*hash opt, bool cache=True)
returns an SQL string that could be used to create the primary key on the table
SqlUtil::ForeignConstraintTarget::columns
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:5268
SqlUtil::AbstractTable::drop
drop(*hash opt)
drops the table from the database without any transaction management
SqlUtil::OP_CLE
const OP_CLE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h: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::AbstractTable::addColumn
AbstractColumn addColumn(string cname, hash opt, bool nullable=True, *reference lsql)
adds a column to the table; if the table is already known to be in the database, then it is added in ...
SqlUtil::DB_TABLES
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:1988
SqlUtil::Constraints::getElementName
string getElementName()
must return the name of the contained element
SqlUtil::AbstractTable::createCommit
createCommit(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
SqlUtil::CLOB
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:2014
SqlUtil::AbstractDatabase::getSqlFromList
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
SqlUtil::AbstractDatabase::supportsTypes
bool supportsTypes()
returns True if the database supports named types
SqlUtil::OP_NOT
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3612
SqlUtil::AbstractTable::getRenameSql
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
SqlUtil::AbstractHashContainer::clear
clear()
purges the contained data
SqlUtil::AbstractIndex::columns
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:4918
SqlUtil::AbstractColumnSupportingConstraint::getCreateSql
abstract string getCreateSql(string table_name, *hash opts)
returns a string that can be used to create the constraint in the database
SqlUtil::ForeignConstraints::memberGate
AbstractForeignConstraint memberGate(string k)
returns the AbstractForeignConstraint object corresponding to the key given or throws a KEY-ERROR exc...
SqlUtil::AbstractTable::SqlDataCallbackOptions
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:6831
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::getRenameColumnSql
string getRenameColumnSql(string old_name, string new_name, *hash opt)
gets an SQL string that can be used to rename an existing column in the table
SqlUtil::AbstractTable::updateNoCommit
deprecated int updateNoCommit(hash set, *hash cond, *reference sql)
A legacy SqlUtil::AbstractTable::update() wrapper.
SqlUtil::AbstractListContainer::empty
bool empty()
returns True if the container is empty, False if not
SqlUtil::AbstractTable::copy
copy(AbstractTable old)
copies the object
SqlUtil::AbstractTable::getInsertOptions
private hash getInsertOptions()
returns the insert options for this driver
SqlUtil::AbstractDatabase::viewIterator
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
SqlUtil::AbstractTable::UpsertResultMap
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:6983
SqlUtil::AbstractDatabase::tryExecArgsImpl
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
SqlUtil::AbstractColumn::name
string name
the name of the column
Definition: SqlUtil.qm.dox.h:4741
SqlUtil::AbstractHashContainer::empty
bool empty()
returns True if the container is empty, False if not
SqlUtil::AbstractColumnSupportingConstraint::clearIndex
clearIndex()
clears any index base for the constraint
SqlUtil::AbstractTable::delNoCommit
deprecated int delNoCommit(*hash cond, *reference sql)
A legacy SqlUtil::AbstractTable::del() wrapper.
SqlUtil::AbstractTable::bindEmptyStringsAsNull
bool bindEmptyStringsAsNull()
returns True if the DB treats empty strings as NULL, False if not; by default this method returns Fal...
SqlUtil::AbstractDatabase::getAlignSchemaOptions
private hash getAlignSchemaOptions()
override in subclasses to return driver-specific options
SqlUtil::AbstractTable::getConstraintOptions
private hash getConstraintOptions()
returns the constraint options for this driver
SqlUtil::AbstractSqlUtilBase::ds
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:5612
SqlUtil::AbstractConstraint::getName
string getName()
returns the constraint name
Util::same
bool same(list l)
SqlUtil::AbstractColumn::getModifySqlImpl
abstract private list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
SqlUtil::AbstractIndex::getName
string getName()
returns the index name
SqlUtil::AbstractFunction
base class for functions
Definition: SqlUtil.qm.dox.h:5410
SqlUtil::AbstractTable::getTableDescriptionHashOptions
private hash getTableDescriptionHashOptions()
returns the table description hash options for this driver
SqlUtil::COP_MULTIPLY
const COP_MULTIPLY
the SQL "multiply" operator
Definition: SqlUtil.qm.dox.h:2126
SqlUtil::AbstractTable::addUniqueConstraint
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql)
adds a unique constraint to the table; if the table is known to be in the database already...
SqlUtil::AbstractDatabase::listSequences
list listSequences()
returns a list of string sequence names in the database
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::AbstractTable::getSqlFromList
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
SqlUtil::AbstractDatabase::listFunctions
list listFunctions()
returns a list of string function names in the database
SqlUtil::AbstractHashContainer::partialMatchKeys
bool partialMatchKeys(hash h1)
returns True if the hash argument has at least the same keys (in any order, can have more keys)...
SqlUtil::AbstractDatabase::makeSequence
AbstractSequence makeSequence(string name, number start=1, number increment=1, *softnumber end, *hash opts)
creates a database-specific AbstractSequence object corresponding to the arguments ...
SqlUtil::AbstractDatabase::AC_Recreate
const AC_Recreate
used when an object is recreated (usually dropped and recreated in place)
Definition: SqlUtil.qm.dox.h:5722
SqlUtil::AbstractConstraint::clearIndex
abstract clearIndex()
clears any index base for the constraint
SqlUtil::AbstractTable::insert
*hash insert(hash row)
inserts a row into the table without any transaction management; a transaction will be in progress af...
SqlUtil::AbstractView
base class for views
Definition: SqlUtil.qm.dox.h:5334
SqlUtil::AbstractHashContainer::hasKey
bool hasKey(string k)
Returns True if the key exists in the contained hash (may or may not be assigned a value)...
SqlUtil::AbstractIndex::equal
bool equal(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
SqlUtil::AbstractFunction::getRenameSql
abstract list getRenameSql(string new_name)
returns a string that can be used to rename the function in the database
SqlUtil::AbstractSqlUtilBase::opts
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:5618
SqlUtil::AbstractTable::getCreateSqlString
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
SqlUtil::Table::getTable
AbstractTable getTable()
returns the AbstractTable object contained by this object
SqlUtil::AbstractDatabase::native_case
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:5865
SqlUtil::AbstractTable::getCreateConstraintsSql
*list getCreateConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create non-foreign constraints on the table or NO...
SqlUtil::AbstractDatabase::makeProcedure
AbstractFunction makeProcedure(string name, string src, *hash opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
SqlUtil::AbstractHashContainer::renameKey
renameKey(string old_name, string new_name)
renames the given key; maintains the key order
SqlUtil::AbstractDatabase::getCurrentSequenceValueImpl
abstract private int getCurrentSequenceValueImpl(string name)
returns the last value issued for the given sequence in the current session
SqlUtil::AbstractTable::getTableCreationOptions
private hash getTableCreationOptions()
returns the table creation options for this driver
SqlUtil::AbstractTable::InsertOptions
const InsertOptions
generic SQL insert options
Definition: SqlUtil.qm.dox.h:6846
SqlUtil::Triggers::take
AbstractTrigger take(string k)
removes the given key from the contained hash and returns the value
SqlUtil::AbstractColumn::equalImpl
abstract private bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
SqlUtil::AbstractDatabase::tryExecRaw
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
SqlUtil::AbstractTable::TriggerOptions
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:6708
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 "prepend" operator with the given argument
SqlUtil::AbstractFunctionBase::type
string type
the type of object
Definition: SqlUtil.qm.dox.h:5377
Int
const Int
SqlUtil::AbstractTable::renameIndex
AbstractIndex renameIndex(string old_name, string new_name, reference sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
SqlUtil::COP_YEAR
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:2131
SqlUtil::AbstractListContainer::constructor
constructor(softlist nl)
creates the object with the list argument passed
string
string string(softstring str, *string enc)
SqlUtil::AbstractDatabase::SequenceDescriptionOptions
const SequenceDescriptionOptions
default generic sequence description keys
Definition: SqlUtil.qm.dox.h:5845
SqlUtil::AbstractTable::addCheckConstraint
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
SqlUtil::AbstractTrigger::getCreateSql
abstract list getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the trigger in the database
SqlUtil::AbstractTable::rowCount
softint rowCount()
returns the number of rows in the table
SqlUtil::AbstractTable::rollback
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
SqlUtil::Tables::getElementName
string getElementName()
returns "table" since this object stores AbstractTable objects
SqlUtil::AbstractTable::getTypeMapImpl
abstract private hash getTypeMapImpl()
returns the type name -> type description hash
SqlUtil::AbstractTable::insertFromSelectNoCommit
deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromSelect() wrapper.
SqlUtil::AbstractView::getDropSql
string getDropSql()
returns a string that can be used to drop the view from the database
SqlUtil::uop_divide
hash uop_divide(any arg, *hash nest)
returns a hash for the "/" operator with the given arguments
SqlUtil::ForeignConstraints::getElementName
string getElementName()
returns "foreign constraint" for the type of object encapsulated
SqlUtil::AbstractColumn::size
int size
the size of the column
Definition: SqlUtil.qm.dox.h:4750
SqlUtil::AbstractTable::renameColumn
AbstractColumn renameColumn(string old_name, string new_name, reference sql)
renames an existing column; if the table is already known to be in the database, then the changes are...
SqlUtil::AbstractColumnSupportingConstraint::constructor
constructor(string n, *hash c, *string n_index)
creates the object from the name and a hash of column information
SqlUtil::AbstractDatabase::dropTableIfExists
bool dropTableIfExists(string name, *hash opt)
drops the given table if it exists; returns True if the table was dropped, False if not ...
SqlUtil::AbstractTable::getModifyColumnSql
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
SqlUtil::AbstractTable::getSqlValue
string getSqlValue(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
SqlUtil::AbstractHashContainer::size
int size()
Returns the number of keys in the contained hash.
SqlUtil::AbstractDatabase::tryExecRawImpl
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
SqlUtil::AbstractHashContainer::keyIterator
Qore::AbstractIterator keyIterator()
Returns a HashKeyIterator object for the contained hash.
SqlUtil::AbstractTable::getWhereOperatorMap
private hash getWhereOperatorMap()
returns the "where" operator map for this object
SqlUtil::AbstractSequence::getRenameSql
abstract string getRenameSql(string new_name)
returns a string that can be used to rename the sequence in the database
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::AbstractTable::UpsertUpdateOnly
const UpsertUpdateOnly
Upsert option: update if the row exists, otherwise ignore.
Definition: SqlUtil.qm.dox.h:6933
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 "=" operator with the given argument for use in where clauses when comparing c...
SqlUtil::AbstractColumnSupportingConstraint::getSourceConstraintIterator
Qore::AbstractIterator getSourceConstraintIterator()
returns an iterator through all known source foreign constraints on the current table ...
SqlUtil::AbstractTable::getAlignTableOptions
private hash getAlignTableOptions()
returns the align table options for this driver
SqlUtil::OP_LT
const OP_LT
the SQL less than (<) 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::setDatasource
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
SqlUtil::AbstractTable::findSingle
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
SqlUtil::AbstractDatabase::AlignSchemaOptions
const AlignSchemaOptions
default generic schema description / alignment options
Definition: SqlUtil.qm.dox.h:5802
SqlUtil::ForeignConstraints::findConstraintOn
*hash findConstraintOn(string table, softlist cols)
returns either a hash of AbstractColumn information or NOTHING if no foreign constraint can be found ...
SqlUtil::ForeignConstraints::add
add(string k, AbstractForeignConstraint val)
adds the given value to the hash with the given key name
SqlUtil::Functions
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:5433
SqlUtil::AbstractTable::getIndexes
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
SqlUtil::AbstractTable::UR_Unchanged
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst, UpsertInsertOnly, and UpsertUpdateOnly) ...
Definition: SqlUtil.qm.dox.h:6974
SqlUtil::AbstractTable::dropPrimaryKey
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
SqlUtil::AbstractTable::UR_Updated
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:6971
SqlUtil::AbstractDatabase::getNextSequenceValue
int getNextSequenceValue(string name)
returns the next value in the given sequence
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::AbstractTable::truncate
truncate()
truncates all the table data without any transaction management
SqlUtil::COP_CAST
const COP_CAST
to convert column value into another datatype
Definition: SqlUtil.qm.dox.h:2046
SqlUtil::AbstractTable::UpsertInsertOnly
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:6926
SqlUtil::AbstractFunction::setName
setName(string new_name)
sets the new name of the object
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::Triggers::add
add(string k, AbstractTrigger val)
adds the given value to the hash with the given key name
SqlUtil::OP_CGE
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3587
SqlUtil::AbstractDatabase::AC_Truncate
const AC_Truncate
used when a table is truncated
Definition: SqlUtil.qm.dox.h:5716
SqlUtil::op_cle
hash op_cle(string arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
SqlUtil::AbstractTable::getName
string getName()
returns the name of the table
SqlUtil::Table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:6571
SqlUtil::AbstractTable::IndexOptions
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:6682
SqlUtil::AbstractTable::getColumnOptions
private hash getColumnOptions()
returns the column options for this driver
SqlUtil::AbstractHashContainer::values
list values()
Returns a list of values of the contained hash.
SqlUtil::AbstractTable::find
*hash find(any id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
SqlUtil::AbstractColumn::equal
bool equal(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
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 "seq" operator with the given argument giving the sequence name whose value sh...
SqlUtil::AbstractTable::rename
rename(string new_name, *reference sql, *Tables table_cache)
renames the table; if the table is already known to be in the database in the database, then the changes are effected in the database also immediately; otherwise it is only updated internally
SqlUtil::Tables::take
AbstractTable take(string k)
removes the given key from the contained hash and returns the value
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't exist, insert, otherwise update.
Definition: SqlUtil.qm.dox.h:6912
SqlUtil::AbstractDatabase::rebuildIndex
bool rebuildIndex(string name, *hash options)
Rebuild an index in the DB.
SqlUtil::AbstractDatabase::dropFunctionIfExists
bool dropFunctionIfExists(string name, *hash opt)
drops the given function if it exists; returns True if the function was dropped, False if not ...
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::setupTable
setupTable(hash desc, *hash opt)
creates the object from a table description hash
SqlUtil::Indexes::add
add(string k, AbstractIndex val)
adds the given value to the hash with the given key name
SqlUtil::AbstractTable::UpsertInsertFirst
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:6895
SqlUtil::AbstractDatabase::getCallbackOptions
private hash getCallbackOptions()
override in subclasses to return driver-specific options
SqlUtil::AbstractView::name
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:5342
SqlUtil::AbstractTrigger::constructor
constructor(string n, string n_src)
creates the object and sets its name and the trigger source
SqlUtil::AbstractColumnSupportingConstraint::getIndex
*string getIndex()
returns the name of the associated index, if any
SqlUtil::AbstractDatabase::features
list features()
See DBFeaturesConstants.
SqlUtil::AbstractSequence::max
*number max
the ending number
Definition: SqlUtil.qm.dox.h:5314
SqlUtil::AbstractTable::checkExistenceImpl
abstract private bool checkExistenceImpl()
returns True if the table exists in the DB, False if not
SqlUtil::cop_upper
hash cop_upper(any column)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
SqlUtil::AbstractHashContainer::val
bool val()
Returns False if the contained hash has no keys, True if it does.
SqlUtil::AbstractListContainer::getList
list getList()
returns the list contained by this object
SqlUtil::uop_multiply
hash uop_multiply(any arg, *hash nest)
returns a hash for the "*" operator with the given arguments
SqlUtil::AbstractTable::asteriskRequiresPrefix
private bool asteriskRequiresPrefix()
returns True if the database requires a wildcard "*" to be prefixed with the table name when it appea...
SqlUtil::AbstractTable::ColumnDescOptions
const ColumnDescOptions
Column description options.
Definition: SqlUtil.qm.dox.h:6806
SqlUtil::AbstractSequence::increment
number increment
the increment
Definition: SqlUtil.qm.dox.h:5311
SqlUtil::AbstractTable::getDropConstraintIfExistsSql
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
SqlUtil::Columns::memberGate
AbstractColumn memberGate(string k)
returns the AbstractColumn object corresponding to the key given or throws a KEY-ERROR exception ...
SqlUtil::AbstractHashContainer::matchKeys
bool matchKeys(hash h1)
returns True if the hash argument has the same keys (in any order), False if not
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...
Qore
SqlUtil::AbstractDatabase::listViews
list listViews()
returns a list of string view names in the database
SqlUtil::AbstractDatabase::getDropProcedureSqlIfExists
*string getDropProcedureSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given procedure if it exists or NOTHING if the named procedure do...
SqlUtil::AbstractTable::inDb
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
SqlUtil::OP_LIKE
const OP_LIKE
the SQL "like" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3537
SqlUtil::AbstractColumnSupportingConstraint::findMatchingIndex
findMatchingIndex(*Indexes indexes)
find an index that matches the constraint and marks both objects as related
SqlUtil::AbstractDatabase::CallbackOptions
const CallbackOptions
generic callback options
Definition: SqlUtil.qm.dox.h:5686
SqlUtil::AbstractTable::TableDescriptionHashOptions
const TableDescriptionHashOptions
Table description options.
Definition: SqlUtil.qm.dox.h:6783
SqlUtil::SZ_NONE
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2022
SqlUtil::Indexes::memberGate
AbstractIndex memberGate(string k)
returns the AbstractIndex object corresponding to the key given or throws a KEY-ERROR exception ...
SqlUtil::AbstractListContainer::size
int size()
Returns the number of elements in the contained list.
SqlUtil::AbstractFunction::constructor
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
SqlUtil::Tables::getDropList
list getDropList()
returns a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
SqlUtil::AbstractDatabase::ActionDescMap
const ActionDescMap
maps from action descriptions to action codes
Definition: SqlUtil.qm.dox.h:5754
SqlUtil::Table::t
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6576
SqlUtil::AbstractTable::getSqlValueImpl
abstract private *string getSqlValueImpl(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
SqlUtil::OP_CLT
const OP_CLT
the SQL less than (<) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:3572
SqlUtil::COP_MINUS
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2111
SqlUtil::AbstractDatabase::getProcedure
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
SqlUtil::AbstractFunctionBase::constructor
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
SqlUtil::AbstractCheckConstraint::clearIndex
clearIndex()
clears any index base for the constraint
SqlUtil::ForeignConstraintTarget::table
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:5265
hash
hash hash(object obj)
SqlUtil::AbstractDatabase::getRebuildIndexOptions
private hash getRebuildIndexOptions()
override in subclasses to return driver-specific options
SqlUtil::AbstractDatabase::getCurrentSequenceValue
int getCurrentSequenceValue(string name)
returns the last value issued for the given sequence in the current session
SqlUtil::AbstractTable::commit
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
SqlUtil::AbstractDatabase::getNextSequenceValueImpl
abstract private int getNextSequenceValueImpl(string name)
returns the next value in the given sequence
SqlUtil::AbstractTable::hasReturningImpl
private bool hasReturningImpl()
returns True if the current database driver supports the "returning" clause in insert statements...
SqlUtil::AbstractTable::getColumnDescOptions
private hash getColumnDescOptions()
returns the column description options for this driver
SqlUtil::AbstractTable::findUniqueConstraint
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
SqlUtil::AbstractTable::TableCreationOptions
const TableCreationOptions
table creation options
Definition: SqlUtil.qm.dox.h:6751
SqlUtil::cop_year_day
hash cop_year_day(any column)
returns a hash for the "year_day" operator with the given argument
SqlUtil::AbstractDatabase::AC_Delete
const AC_Delete
used when data is deleted in a table
Definition: SqlUtil.qm.dox.h:5731
SqlUtil::AbstractTable::getCreateMiscSql
*list getCreateMiscSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create other table attributes (such as comments...
SqlUtil::COP_SUBSTR
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2166
SqlUtil::AbstractDatabase::ComputeStatisticsOptions
const ComputeStatisticsOptions
Options for computeStatistics()
Definition: SqlUtil.qm.dox.h:5852
SqlUtil::AbstractIndex::getCreateSql
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
SqlUtil::JOP_RIGHT
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3060
SqlUtil::AbstractTable::getColumnSqlNames
list getColumnSqlNames(softlist cols)
returns a list of column names for use in SQL strings; subclasses can process the argument list in ca...
SqlUtil::OP_SUBSTR
const OP_SUBSTR
the SQL "substr" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h: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::AbstractDatabase::AC_Update
const AC_Update
used when data is updated in a table
Definition: SqlUtil.qm.dox.h:5728
SqlUtil::AbstractTable::getInsertOperatorMap
private hash getInsertOperatorMap()
returns the insert operator map for this object
SqlUtil::Tables::getDropConstraintIfExistsSql
*string getDropConstraintIfExistsSql(string tname, string cname, *hash opts)
returns an SQL string that can be used to drop an existing constraint on a table, if the table is not...
SqlUtil::cop_year
hash cop_year(any column)
returns a hash for the "year" 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::AbstractDatabase::AC_NotFound
const AC_NotFound
used when dropping object but the object is not present
Definition: SqlUtil.qm.dox.h:5734
SqlUtil::AbstractTable::getDropTriggerSql
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
SqlUtil::Tables::populate
populate(AbstractDatasource ds, hash tables, *hash opt)
populates the object from a hash description
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::AbstractTable::getTableOptions
private hash getTableOptions()
returns the table options for this driver
SqlUtil::AbstractDatabase::getDropTableSqlIfExists
*list getDropTableSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given table if it exists or NOTHING if the named table does not e...
SqlUtil::AbstractListContainer::take
any take(int i)
removes the given element from the contained list and returns the value
SqlUtil::cop_multiply
hash cop_multiply(any column1, any column2)
returns a hash for the "*" operator with the given arguments
SqlUtil::AbstractDatabase::AC_Add
const AC_Add
used when an element is added to an existing object
Definition: SqlUtil.qm.dox.h:5719
SqlUtil::cop_seq_currval
hash cop_seq_currval(string seq, *string as)
returns a hash for the "seq_currval" operator with the given argument giving the sequence name whose ...
SqlUtil::AbstractTable::getCreateTableSql
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
SqlUtil::AbstractIndex::getDropSql
string getDropSql(string table_name)
returns a string that can be used to drop the index from the database
SqlUtil::AbstractTable::getDropConstraintSql
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
SqlUtil::AbstractColumnSupportingConstraint::renameSourceConstraintTable
renameSourceConstraintTable(string old_name, string new_name)
renames a table in a source constraint
SqlUtil::ForeignConstraints::findEqual
*AbstractForeignConstraint findEqual(AbstractForeignConstraint fk)
find an index with columns equal to the index passed
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::AbstractDatabase::getTable
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found ...
SqlUtil::AbstractDatabase::getSequenceDescriptionOptions
private hash getSequenceDescriptionOptions()
override in subclasses to return driver-specific options
SqlUtil::AbstractTable::tryExecArgsImpl
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
SqlUtil::AbstractTable::doSelectOrderByWithOffsetSqlUnlockedImpl
abstract private doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch, *hash psch, list coll)
processes a string for use in SQL select statements when there is an "order by" and "offset" argument...
SqlUtil::COP_DIVIDE
const COP_DIVIDE
the SQL "divide" 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::AbstractFunction::getCreateSql
abstract list getCreateSql(*hash opt)
returns a list of SQL strings that can be used to create the function in the database ...
SqlUtil::AbstractConstraint::setIndexBase
abstract bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
SqlUtil::op_ceq
hash op_ceq(string arg)
returns a hash for the "=" 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
SqlUtil::AbstractColumn::getDropSql
string getDropSql(string table_name)
returns a string that can be used to drop the column from the table
SqlUtil::AbstractTable::UpsertStrategyDescriptionMap
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:6950
SqlUtil::AbstractHashContainer::lastKey
*string lastKey()
Returns the last key name in the contained hash or NOTHING if the contained hash has no keys...
SqlUtil::AbstractForeignConstraint::equalImpl
private bool equalImpl(AbstractConstraint con)
returns True if the argument is equal to the current object, False if not
SqlUtil::Constraints::take
AbstractConstraint take(string k)
removes the given key from the contained hash and returns the value
SqlUtil::AbstractHashContainer::firstKey
*string firstKey()
Returns the first key name in the contained hash or NOTHING if the contained hash has no keys...
Qore::AbstractIterator
SqlUtil::AbstractTable::insertFromIteratorNoCommit
deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromIterator() wrapper.
SqlUtil::AbstractTable::upsertFromIterator
*hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
SqlUtil::AbstractDatabase::supportsSequences
bool supportsSequences()
returns True if the database supports sequences
SqlUtil::AbstractDatabase::tryExec
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
SqlUtil::cop_year_hour
hash cop_year_hour(any column)
returns a hash for the "year_hour" operator with the given argument
SqlUtil::AbstractHashContainer::hasKeyValue
bool hasKeyValue(string k)
Returns True if the key exists in the contained hash and is assigned a value, False if not...
SqlUtil::AbstractTable::ConstraintOptions
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:6690
SqlUtil::Tables::getIfExists
*AbstractTable getIfExists(AbstractDatasource ds, string name)
gets a table from the database or from the cache if already cached; if the table does not exist...
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::AbstractConstraint::rename
rename(string n)
renames the constraint
SqlUtil::AbstractTable::getUpsertOptions
private hash getUpsertOptions()
returns the upsert options for this driver
SqlUtil::AbstractDatabase::makeTable
AbstractTable makeTable(string name, hash desc, *hash opts)
creates a database-specific AbstractTable object corresponding to the arguments
SqlUtil::AbstractTable::AdditionalColumnDescOptions
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:6819
SqlUtil::Indexes::tryTake
*AbstractIndex tryTake(string k)
tries to remove the given key from the contained hash and returns the value if it exists ...
SqlUtil::cop_max
hash cop_max(any column)
returns a hash for the "max" operator; returns maximum column values
SqlUtil::AbstractConstraint
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5021
SqlUtil::AbstractDatabase::ReclaimSpaceOptions
const ReclaimSpaceOptions
Options for reclaimSpace()
Definition: SqlUtil.qm.dox.h:5857
SqlUtil::cop_count
hash cop_count(any column="")
returns a hash for the "count" operator; returns row counts
SqlUtil::uop_seq
hash uop_seq(string seq)
returns a hash for the "seq" operator with the given argument giving the sequence name whose value sh...
SqlUtil::AbstractTable::removeForeignConstraint
AbstractForeignConstraint removeForeignConstraint(string cname)
removes the named foreign constraint from the table; no SQL is executed in any case, only the named foreign constraint is removed from the table definition
SqlUtil::Constraints
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:4979
SqlUtil::COP_APPEND
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2056