387 @warning Oracle:
using different comments in the
same SQL can lead to
new optimizer statement hard parsing.
389 @subsubsection select_option_hint Select Option
"hint" 390 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).
394 table.selectRows((
"hint":
"full(t1)"));
396 will produce select statement like
this:
400 The
string is taken as-is and it
's up to the caller to handle correct aliases in join functions etc. 401 @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module. 402 @warning Use hints only when you know what you are doing. 404 @subsubsection select_option_columns Select Option "columns" 405 <b>Columns Example:</b> 408 "id", "name", "started", 409 cop_as("warnings", "warning_count"), 410 cop_as("errors", "error_count"), 412 *list rows = table.selectRows(("columns": columns, "where": ("type": "user"))); 414 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 415 This option takes a list, each element of the list can be one of the following.\n\n 416 <b>A Simple String Giving a Column Name</b>\n 419 *list rows = table.selectRows(("columns": ("id", "name", "started"))); 421 <b>A String in Dot Notation</b>\n 422 This format is for use with @ref select_option_join "joins"; ex: \c "q.name" 425 "columns": ("t1.id", "t2.customer_name"), 426 "join": join_inner(table2, "t2", ("id": "altid"))), 429 *list rows = table.selectRows(sh); 431 <b>A Column Operation Specified by a Column Operator Function</b>\n 432 ex: <tt>cop_as("column_name", "column_alias")</tt> \n 433 See @ref sql_cop_funcs "column operator function" for more information on column operator functions 437 cop_as("warnings", "warning_count"), 438 cop_as("errors", "error_count"), 440 *list rows = table.selectRows(("columns": columns)); 442 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 443 <b>The Value \c "*", Meaning All Columns</b>\n 446 *list rows = table.selectRows(("columns": "*")); 448 This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n 449 <b>An \c "*" in Dot Notation</b>\n 453 "columns": ("table.id", "t2.*"), 454 "join": join_inner(table2, "t2", ("id": "altid")), 456 *list rows = table.selectRows(sh); 459 @subsubsection select_option_where Select Option "where" 460 <b>Where Example:</b> 462 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200)); 464 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. 466 @subsubsection select_option_orderby Select Option "orderby" 467 <b>Orderby Example:</b> 471 "account_type": "CUSTOMER", 473 "orderby": "created_date", 475 *list rows = table.selectRows(sh); 477 This option is a list of the following values: 478 - a simple string giving a column name; ex: \c "name" 479 - 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 480 - 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" 481 - a positive integer giving the column number for the ordering 483 - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table 485 @subsubsection select_option_desc Select Option "desc" 490 "account_type": "CUSTOMER", 492 "orderby": "created_date", 495 *list rows = table.selectRows(sh); 497 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 498 Otherwise, ordered results are returned in ascending order by default. 500 @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" 502 @subsubsection select_option_limit Select Option "limit" 503 <b>Limit Example:</b> 506 "where": ("type": "user"), 510 *list rows = table.selectRows(sh); 512 This option will limit the number of rows returned. 514 - This option is required if the @ref select_option_offset "offset option" is non-zero 515 - 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 517 @subsubsection select_option_offset Select Option "offset" 518 <b>Offset Example:</b> 521 "where": ("type": "user"), 525 *list rows = table.selectRows(sh); 527 This option specifies the row number offset for the rows returned where the first row is at offset zero. 529 - 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. 530 - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown. 533 @subsubsection select_option_join Select Option "join" 538 "name", "version", "id", 539 cop_as("st.value", "source"), 540 cop_as("st.value", "offset"), 542 "join": join_left(function_instance_tags, "st", NOTHING, ("st.tag": "_source")) 543 + join_left(function_instance_tags, "lt", NOTHING, ("st.tag": "_offset")), 545 *list rows = table.selectRows(sh); 547 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). 548 @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 550 @see @ref joins for more examples 552 @subsubsection select_option_groupby Select Option "groupby" 553 <b>Groupby Example:</b> 557 cop_as(cop_max("service_type"), "type"), 560 "groupby": "service_type", 562 *list rows = table.selectRows(sh); 564 The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements. 565 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" 566 key are strings giving column names, optionally in dot notation or positive column numbers. 568 @subsubsection select_option_having Select Option "having" 569 <b>Having Example:</b> 573 cop_as(cop_max("service_type"), "type"), 576 "groupby": "service_type", 578 "service_type": (COP_COUNT, op_ge(100)), 581 *list rows = table.selectRows(sh); 583 The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria. 584 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. 586 @subsubsection select_option_superquery Select Option "superquery" 587 <b>Superquery Example:</b> 591 "serviceid", "service_methodid", 592 cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid"), 595 "columns": ("serviceid", "service_methodid"), 596 "where": ("max_methodid": op_ceq("service_methodid")), 599 *list rows = table.selectRows(sh); 601 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 602 The above example results in an SQL command equivalent to the following: 604 *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"); 606 @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL. 608 @subsubsection select_option_forupdate Select Option "forupdate" 609 <b>For Update Example:</b> 611 on_success ds.commit(); 612 on_error ds.rollback(); 615 "columns": ("serviceid", "service_methodid"), 618 *list rows = table.selectRows(sh); 620 \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. 621 The above example results in an SQL commit equivalent to the following: 623 *list rows = table.vselectRows("select serviceid,service_methodid from schema.service_methods for update"); 626 @subsection sql_paging Select With Paging 628 There is support for paging query results in the following methods: 629 - @ref SqlUtil::AbstractTable::getRowIterator() 630 - @ref SqlUtil::AbstractTable::getSelectSql() 631 - @ref SqlUtil::AbstractTable::select() 632 - @ref SqlUtil::AbstractTable::selectRows() 634 @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods 636 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. 638 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. 641 Select 100 rows starting at row 200 (the table's primary key will be used
for the \c
"orderby" option by
default): \n
643 *
list rows = table.selectRows((
"where": (
"type":
"user"),
"limit": 100,
"offset": 200));
645 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:
647 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));
651 ds.vselectRows(
"select * from public.table where type = %v order by type limit %v offset %v", (
"user", 100, 200));
654 @subsection check_matching_rows Check For At Least One Matching Row
658 *
hash h = table.findSingle((
"account_type":
"CUSTOMER"));
660 printf(
"found 1 customer row: %y\n",
l[0]);
663 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): 665 *hash h = table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1)); 667 printf("found 1 customer row: %y\n", l[0]); 670 @section inserting_data Inserting Data into the Database 672 The following methods can be used to insert data into the database: 673 - @ref SqlUtil::AbstractTable::insert(): inserts a single row into a table without committing the transaction 674 - @ref SqlUtil::AbstractTable::insertCommit(): inserts a single row into a table and commits the transaction 675 - @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 676 - @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 678 @see @ref sql_upsert for information about upserting or merging data 680 @subsection inserting_data_explicitly Inserting Data Explicitly 684 table.insert(("id": id, "name": name, "created": now_us())); 687 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. 689 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. 691 @subsection inserting_data_from_select Inserting Data From a Select Statement 695 int rows = table.insertFromSelect(("id", "name", "created"), source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER")))); 698 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. 700 The example above would generate a %Qore SQL command like the following: 702 return ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER")); 705 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. 707 @subsection inserting_data_from_iterator Inserting Data from an Iterator Source 709 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: 713 # get the rows to be inserted 714 list l = get_table_rows(); 715 # insert the data and commit after every 5000 rows 716 table.insertFromIterator(l.iterator(), ("commit_block": 5000)); 719 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". 721 @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 723 @section updating_data Updating Data
725 The following methods can be used to
update data:
727 - @ref
SqlUtil::AbstractTable::
updateCommit(): updates a single row and commits the transaction
734 The example above generates a %
Qore SQL command like the following on Oracle and PostgreSQL
for example:
736 return ds.vexec(
"update schema.table set permission_type = lower(permission_type) || '-migrated'); 738 And the following on MySQL: 740 return ds.vexec("update schema.table
set permission_type = concat(lower(permission_type),
'-migrated'));
743 @section deleting_data Deleting Data
745 The following methods can be used to dekete data:
746 - @ref
SqlUtil::AbstractTable::del(): updates the table based on a @ref where_clauses
"where clause" and does not commit the transaction
747 - @ref
SqlUtil::AbstractTable::delCommit(): updates the table based on a @ref where_clauses
"where clause" and commits the transaction
748 - @ref
SqlUtil::AbstractTable::truncate(): truncates the table and does not commit the transaction
749 - @ref
SqlUtil::AbstractTable::truncateCommit(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
753 int dcnt = table.del((
"record_type":
"OLD-CUSTOMER"));
756 The above example would generate a %
Qore SQL command like the following:
758 return ds.vexec(
"delete from schema.table where record_type = %v", (
"OLD-CUSTOMER"));
763 See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
765 @section joins Joining Tables
767 Joining tables is made by providing a
join specification to the @ref select_option_join "
join select option" in
768 a @ref select_option_hash "select option
hash" as in the following example:
770 *
list rows = table.selectRows((
"columns": (
"table.id",
"t2.customer_name"),
"join":
join_inner(table2,
"t2", (
"id":
"altid"))));
772 In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
774 Joins on multiple tables are performed by combining the results of @ref sql_jop_funcs
"join functions" with the @ref plus_operator
"+ operator" 779 In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
780 automatically detected primary key to foreign key relationship between the two tables.
782 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
783 argument to the @ref sql_jop_funcs
"join function" as in the following example:
785 *
list rows = table.selectRows((
"join":
join_inner(table2,
"t2", (
"id":
"altid")) +
join_inner(
"t2", table3,
"t3")));
787 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
788 with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
790 @see @ref select_option_join
"join select option" 792 @section where_clauses Where Clauses
794 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:
813 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:
814 - use the @ref
SqlUtil::wop_or() function to combine where expressions with the \c "or" operator
815 - 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".
817 The where condition
hash has the following format:
818 - each key gives a column
name or a table/alias with column
name in dot notation
819 - 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
821 @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
823 See @ref sql_op_funcs
for a
list of
operator functions.
825 @par Where
Hash Example:
829 "account_type":
op_like(
"%CUSTOMER%"),
833 The preceding example results in a where clause equivalent to: \c
"name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
834 that bind by value is used, so,
if used in a context like the following:
836 Table t(
ds,
"table");
837 *
hash qh = t.select((
"where": w));
839 the complete query would look instead as follows:
841 ds.vselect(
"select * from table where name = %v and account_type like %v and id >= %v", (
"Smith",
"%CUSTOMER%", 500));
845 @par Where
List Example:
849 "account_type":
op_like(
"%CUSTOMER%"),
854 "account_type":
op_like(
"%VENDOR%"),
857 Table t(
ds,
"table");
858 *
hash qh = t.select((
"where": (w1, w2)));
860 the complete query would look instead as follows:
862 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));
866 Find a single row in the table where the \c
"permission_type" column is a value between \c
"US" and \c
"UX":\n
868 *
hash row = table.findSingle((
"permission_type":
op_between(
"US",
"UX")));
870 resulting in an
internal SQL command that looks as follows (depending on the database):
872 *
hash row =
ds.vselectRow(
"select * from table where permission_type between %v and %v limit %v", (
"US",
"UX", 1));
874 Delete all rows in the table where the \c
"name" column is like \c
"%Smith%":\n
876 int row_count = table.del((
"name":
op_like(
"%Smith%")));
878 resulting in an
internal SQL command that looks as follows:
880 ds.vexec(
"delete from table where name like %v", (
"%Smith%"));
882 Find all rows where \c
"id" is greater than \c 100 and \c
"created" is after \c 2013-03-01:\n
884 *
list rows = table.findAll((
"id":
op_gt(100),
"created":
op_gt(2013-03-01)));
886 resulting in an
internal SQL command that looks as follows:
888 ds.vexec(
"select * from table where id > %v and created > %v", (100, 2013-03-01));
891 @section sql_upsert Upserting or Merging Data
893 This module offers a high-level api
for "upserting" or merging data from one table into another table through the following methods:
903 @subsection sql_upsert_single Upsert a Single Row
907 table.upsert((
"id":
id,
"name":
name,
"account_type": account_type));
911 single row to be upserted or merged as a
hash as in the preceding example.
913 @subsection sql_upsert_many Upserting Many Rows Using An Upsert
Closure 919 # get the rows to be inserted 920 list l = get_table_rows();
923 code
upsert = table.getUpsertClosure(l[0]);
925 on_success
ds.commit();
926 on_error
ds.rollback();
928 # loop through the reference data rows 933 @par Complex Example With Callbacks:
935 # set the upsert strategy depending on the use case 938 # hash summarizing changes 941 # get the rows to be inserted 942 list l = get_table_rows();
945 # get the upsert closure to use based on the first row to be inserted 946 code upsert = table.getUpsertClosure(l[0], upsert_strategy);
948 on_success
ds.commit();
949 on_error
ds.rollback();
951 # loop through the reference data rows 952 foreach hash h in (l) {
964 else if (verbose > 1)
965 printf(
"*** reference data %s: %y: %s\n", table.getName(), h, change);
970 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
972 printf(
"*** reference data %s: OK\n", table.getName());
976 @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
982 # get the rows to be inserted 983 list l = get_table_rows();
984 table.upsertFromIterator(l.iterator());
987 @par Complex Example With Callbacks:
989 # set the upsert strategy depending on the use case 992 # get the rows to be inserted 993 list l = get_table_rows();
995 code callback = sub (
string table_name,
hash row,
int result) {
1000 printf(
"*** reference data %s: %y: %s\n", table_name, row, change);
1003 hash sh = table.upsertFromIterator(l.iterator(), upsert_strategy,
False, (
"info_callback": callback,
"commit_block": 5000));
1005 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
1007 printf(
"*** reference data %s: OK\n", table.getName());
1012 @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 1014 @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
1018 @par Simple Example:
1020 table.upsertFromSelect(table2, (
"where": (
"account_type":
"CUSTOMER")));
1023 @par Complex Example With Callbacks:
1025 # set the upsert strategy depending on the use case 1028 code callback = sub (
string table_name,
hash row,
int result) {
1033 printf(
"*** reference data %s: %y: %s\n", table_name, row, change);
1036 hash sh = table.upsertFromSelect(table2, (
"where": (
"account_type":
"CUSTOMER")), upsert_strategy, False, (
"info_callback": callback,
"commit_block": 5000));
1038 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
1040 printf(
"*** reference data %s: OK\n", table.getName());
1043 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).
1047 @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows 1049 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. 1051 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. 1053 @par Simple Example: 1055 # get the rows to be inserted 1056 list l = get_table_rows(); 1057 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000)); 1060 @par Complex Example With Callbacks: 1062 # set the upsert strategy depending on the use case 1063 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto; 1065 # get the rows to be inserted 1066 list l = get_table_rows(); 1068 code callback = sub (string table_name, hash row, int result) { 1069 if (result == AbstractTable::UR_Unchanged) 1071 string change = AbstractTable::UpsertResultMap{result}; 1073 printf("*** reference data %s: %y: %s\n", table_name, row, change); 1076 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, ("delete_others": True, "info_callback": callback, "commit_block": 5000)); 1078 printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator()))); 1080 printf("*** reference data %s: OK\n", table.getName()); 1083 @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 1085 @subsection sql_upsert_strategies Upsert Strategies
1086 The approach used is based on one of the following strategies (see @ref upsert_options):
1087 - @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
1091 - @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 1092 - @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 1094 @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.
2416 "code":
string (
string cve,
string arg, reference psch) {
2419 psch{arg.substr(1, -1)} = cve;
2422 return sprintf(
"%s as %s", cve, arg);
2428 "code":
string (
string cve,
string arg) {
2429 return sprintf(
"%s || %s", arg, cve);
2435 "code":
string (
string cve,
string arg) {
2436 return sprintf(
"%s || %s", cve, arg);
2442 "code":
string (*
string cve,
auto arg) {
2447 "code":
string (
string cve,
auto arg) {
2448 return sprintf(
"upper(%s)", cve);
2452 "code":
string (
string cve,
auto arg) {
2453 return sprintf(
"lower(%s)", cve);
2457 "code":
string (
string cve,
auto arg) {
2458 return sprintf(
"distinct %s", cve);
2462 "code":
string (
string cve,
auto arg) {
2463 return sprintf(
"min(%s)", cve);
2468 "code":
string (
string cve,
auto arg) {
2469 return sprintf(
"max(%s)", cve);
2474 "code":
string (
string cve,
auto arg) {
2475 return sprintf(
"avg(%s)", cve);
2480 "code":
string (
string cve,
auto arg) {
2481 return sprintf(
"sum(%s)", cve);
2487 "code":
string (*
string cve,
auto arg) {
2488 return sprintf(
"count(%s)", cve ? cve :
"*");
2493 "code":
string (
string arg1,
string arg2) {
2494 return sprintf(
"%s - %s", arg1, arg2);
2499 "code":
string (
string arg1,
string arg2) {
2500 return sprintf(
"%s + %s", arg1, arg2);
2505 "code":
string (
string arg1,
string arg2) {
2506 return sprintf(
"%s / %s", arg1, arg2);
2511 "code":
string (
string arg1,
string arg2) {
2512 return sprintf(
"%s * %s", arg1, arg2);
2517 "code":
string (*
string cve,
hash arg) {
2518 throw "SEQUENCE-ERROR",
sprintf(
"cannot select sequence %y because this database does not support sequences", arg.seq);
2523 "code":
string (*
string cve,
hash arg) {
2524 throw "SEQUENCE-ERROR",
sprintf(
"cannot select the current value of sequence %y because this database does not support sequences", arg.seq);
2529 "code":
string (*
string cve,
hash arg) {
2530 return sprintf(
"coalesce(%s)", (foldl $1 +
"," + $2, arg.args));
2534 "code":
string (
string cve,
list args) {
2536 return sprintf(
"substring(%s from %d)", cve, args[0]);
2537 return sprintf(
"substring(%s from %d for %d)", cve, args[0], args[1]);
2541 "code":
string (
string cve,
auto arg) {
2542 return sprintf(
"length(%s)", cve);
2546 "columnargs" :
True,
2547 "columnargs_ignore_nothings" :
True,
2548 "code":
string (*
string cve,
hash args)
2550 *
string partitionby = args.args[0];
2551 *
string orderby = args.args[1];
2554 string sql = cve +
" over (";
2556 sql +=
sprintf(
"partition by %s", partitionby);
2558 sql +=
sprintf(
" order by %s", orderby);
2565 "code":
string (*
string cve, any arg) {
2566 return "cume_dist()";
2571 "code":
string (*
string cve, any arg) {
2572 return "dense_rank()";
2576 "code":
string (
string cve) {
2577 return sprintf(
"first_value(%s)", cve);
2581 "code":
string (
string cve) {
2582 return sprintf(
"last_value(%s)", cve);
2588 "code":
string (*
string cve, any arg) {
2589 return sprintf(
"ntile(%d)", arg);
2594 "code":
string (*
string cve, any arg) {
2595 return "percent_rank()";
2600 "code":
string (*
string cve, any arg) {
2606 "code":
string (*
string cve, any arg) {
2607 return "row_number()";
2663 hash<ColumnOperatorInfo>
make_cop(
string cop,
auto column,
auto arg);
2679 hash<ColumnOperatorInfo>
cop_as(
auto column,
string arg);
2697 hash<ColumnOperatorInfo>
cop_cast(
auto column,
string arg,
auto arg1,
auto arg2);
2711 hash<ColumnOperatorInfo>
cop_prepend(
auto column,
string arg);
2725 hash<ColumnOperatorInfo>
cop_append(
auto column,
string arg);
2857 hash<ColumnOperatorInfo>
cop_value(
auto arg);
2870 hash<ColumnOperatorInfo>
cop_upper(
auto column);
2883 hash<ColumnOperatorInfo>
cop_lower(
auto column);
2909 hash<ColumnOperatorInfo>
cop_min(
auto column);
2922 hash<ColumnOperatorInfo>
cop_max(
auto column);
2935 hash<ColumnOperatorInfo>
cop_avg(
auto column);
2948 hash<ColumnOperatorInfo>
cop_sum(
auto column);
2959 hash<ColumnOperatorInfo>
cop_count(
auto column =
"");
2970 hash<ColumnOperatorInfo>
cop_over(
auto column, *
string partitionby, *
string orderby);
2984 hash<ColumnOperatorInfo>
cop_minus(
auto column1,
auto column2);
2998 hash<ColumnOperatorInfo>
cop_plus(
auto column1,
auto column2);
3012 hash<ColumnOperatorInfo>
cop_divide(
auto column1,
auto column2);
3026 hash<ColumnOperatorInfo>
cop_multiply(
auto column1,
auto column2);
3039 hash<ColumnOperatorInfo>
cop_year(
auto column);
3092 hash<ColumnOperatorInfo>
cop_seq(
string seq, *
string as);
3122 hash<ColumnOperatorInfo>
cop_coalesce(
auto col1,
auto col2);
3137 hash<ColumnOperatorInfo>
cop_substr(
auto column,
int start, *
int count);
3152 hash<ColumnOperatorInfo>
cop_length(
auto column);
3170 hash<ColumnOperatorInfo>
cop_trunc_date(
auto column,
string mask);
3333 hash<ColumnOperatorInfo>
cop_ntile(
int value);
3397 hash<ColumnOperatorInfo>
cop_rank();
3518 "code":
string (
string cve,
auto arg) {
3519 return sprintf(
"%s - %s", cve, arg);
3524 "code":
string (
string cve,
auto arg) {
3525 return sprintf(
"%s + %s", cve, arg);
3530 "code":
string (
string cve,
auto arg) {
3531 return sprintf(
"%s / %s", cve, arg);
3536 "code":
string (
string cve,
auto arg) {
3537 return sprintf(
"%s * %s", cve, arg);
3543 "code":
string (*
string cve,
string arg) {
3544 throw "SEQUENCE-ERROR",
sprintf(
"cannot select sequence %y because this database does not support sequences", arg);
3549 "code":
string (*
string cve,
string arg) {
3550 throw "SEQUENCE-ERROR",
sprintf(
"cannot select the current value of sequence %y because this database does not support sequences", arg);
3555 "code":
string (*
string cve, softlist args) {
3556 return sprintf(
"coalesce(%s)", (foldl $1 +
"," + $2, args));
3592 hash<UpdateOperatorInfo>
make_uop(
string uop,
auto arg, *hash<UpdateOperatorInfo> nest);
3606 hash<UpdateOperatorInfo>
uop_prepend(
string arg, *hash<UpdateOperatorInfo> nest);
3620 hash<UpdateOperatorInfo>
uop_append(
string arg, *hash<UpdateOperatorInfo> nest);
3633 hash<UpdateOperatorInfo>
uop_upper(*hash<UpdateOperatorInfo> nest);
3646 hash<UpdateOperatorInfo>
uop_lower(*hash<UpdateOperatorInfo> nest);
3661 hash<UpdateOperatorInfo>
uop_substr(
int start, *
int count, *hash<UpdateOperatorInfo> nest);
3675 hash<UpdateOperatorInfo>
uop_plus(
auto arg, *hash<UpdateOperatorInfo> nest);
3689 hash<UpdateOperatorInfo>
uop_minus(
auto arg, *hash<UpdateOperatorInfo> nest);
3703 hash<UpdateOperatorInfo>
uop_multiply(
auto arg, *hash<UpdateOperatorInfo> nest);
3717 hash<UpdateOperatorInfo>
uop_divide(
auto arg, *hash<UpdateOperatorInfo> nest);
3730 hash<UpdateOperatorInfo>
uop_seq(
string seq);
3797 hash<string, hash<JoinOperatorInfo>>
make_jop(
string jop,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
string ta, *
hash opt);
3866 hash<string, hash<JoinOperatorInfo>>
join_inner(
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
3942 hash<string, hash<JoinOperatorInfo>>
join_inner_alias(
string ta,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4013 hash<string, hash<JoinOperatorInfo>>
join_left(
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4087 hash<string, hash<JoinOperatorInfo>>
join_left_alias(
string ta,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4158 hash<string, hash<JoinOperatorInfo>>
join_right(
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4232 hash<string, hash<JoinOperatorInfo>>
join_right_alias(
string ta,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4331 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4333 return sprintf(
"%s like %v", cn);
4337 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4339 return sprintf(
"%s < %v", cn);
4343 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4345 return sprintf(
"%s <= %v", cn);
4349 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4351 return sprintf(
"%s > %v", cn);
4355 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4357 return sprintf(
"%s >= %v", cn);
4361 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4363 return sprintf(
"%s is not null", cn);
4365 return sprintf(
"(%s != %v or %s is null)", cn, cn);
4369 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4371 return sprintf(
"%s is null", cn);
4373 return sprintf(
"%s = %v", cn);
4377 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4380 return sprintf(
"%s between %v and %v", cn);
4384 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4385 *
string ins = (foldl $1 +
"," + $2, (map t.getSqlValue($1), arg));
4386 return exists ins ?
sprintf(
"%s in (%s)", cn, ins) :
"1 != 1";
4391 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4392 return sprintf(
"not (%s)", cn);
4397 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4398 return sprintf(
"%s < %s", cn, arg);
4403 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4404 return sprintf(
"%s <= %s", cn, arg);
4409 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4410 return sprintf(
"%s > %s", cn, arg);
4415 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4416 return sprintf(
"%s >= %s", cn, arg);
4421 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4422 return sprintf(
"%s != %s", cn, arg);
4427 "code":
string (
object t,
string cn,
string arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4428 return sprintf(
"%s = %s", cn, arg);
4432 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4438 return sprintf(
"substring(%s from %v for %v) = %v", cn);
4442 "code":
string (
object t,
string cn,
list arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4443 return t.getOrClause(arg, \args, jch,
join, ch, psch);
4471 hash<OperatorInfo>
make_op(
string op,
auto arg);
4485 hash<OperatorInfo>
op_like(
string str);
4500 hash<OperatorInfo>
op_lt(
auto arg);
4515 hash<OperatorInfo>
op_le(
auto arg);
4530 hash<OperatorInfo>
op_gt(
auto arg);
4545 hash<OperatorInfo>
op_ge(
auto arg);
4562 hash<OperatorInfo>
op_ne(
auto arg);
4579 hash<OperatorInfo>
op_eq(
auto arg);
4595 hash<OperatorInfo>
op_between(
auto l,
auto r);
4608 hash<OperatorInfo>
op_in();
4649 hash<OperatorInfo>
op_clt(
string arg);
4664 hash<OperatorInfo>
op_cle(
string arg);
4679 hash<OperatorInfo>
op_cgt(
string arg);
4694 hash<OperatorInfo>
op_cge(
string arg);
4709 hash<OperatorInfo>
op_cne(
string arg);
4724 hash<OperatorInfo>
op_ceq(
string arg);
4739 hash<OperatorInfo>
op_substr(
int start, *
int count,
string text);
4753 hash<OperatorInfo>
op_substr(
int start,
string text);
4811 hash<InsertOperatorInfo>
make_iop(
string iop,
auto arg);
4824 hash<InsertOperatorInfo>
iop_seq(
string arg);
4891 auto memberGate(
string k);
4905 abstract auto take(
string k);
4908 renameKey(
string old_name,
string new_name);
4925 bool matchKeys(
hash h1);
4938 bool matchKeys(
list l);
4964 bool partialMatchKeys(
hash h1);
4977 bool partialMatchKeys(
list l);
5014 list<string> keys();
5086 bool hasKey(
string k);
5099 bool hasKeyValue(
string k);
5129 abstract string getElementName();
5161 abstract auto get(softint i);
5215 abstract string getElementName();
5241 add(
string k,
Table val);
5261 populate(AbstractDatasource ds,
hash tables, *
hash opt);
5265 populate(AbstractDatasource ds);
5283 *
list getDropAllForeignConstraintsOnTableSql(
string name, *
hash opt);
5306 string getElementName();
5310 *
AbstractTable getIfExists(AbstractDatasource ds,
string name);
5333 *
string getRenameTableIfExistsSql(
string old_name,
string new_name, *
hash opts);
5348 bool tableRenamed(
string old_name,
string new_name,
string old_sql_name);
5353 tableRenamedIntern(
string old_name,
string new_name,
string oldsn);
5376 list getCreateList();
5407 getDependencies(reference<hash> tdh, reference<hash> sdh, *reference<hash> th);
5456 string getElementName();
5492 constructor(
string n,
string nt, *
string qt,
int sz,
bool nul, *
string dv, *
string c);
5496 string getNativeTypeString();
5593 string getNativeTypeString(
string native_type,
int precision);
5639 string getElementName();
5674 bool hasColumn(
string cname);
5696 abstract string getRenameSql(
string table_name,
string new_name);
5703 setSupportingConstraint();
5711 list getRecreateSql(AbstractDatasource
ds,
string table_name, *
hash opt);
5753 string getElementName();
5794 string getDisableSql(
string table_name);
5798 string getEnableSql(
string table_name, *
hash opt);
5812 abstract bool setIndexBase(
string ix);
5815 abstract clearIndex();
5818 bool hasColumn(
string cname);
5844 bool setIndexBase(
string ix);
5882 hash getDisableReenableSql(AbstractDatasource
ds,
string table_name, *
hash opts);
5904 removeSourceConstraint(
string tname,
list cols);
5908 renameSourceConstraintTable(
string old_name,
string new_name);
5912 bool hasColumn(
string cname);
5927 bool setIndexBase(
string ix);
5997 *
hash findConstraintOn(
string table, softlist cols);
6001 string getElementName();
6147 constructor(
string n,
string n_type,
string n_src);
6180 constructor(
string n,
string n_type,
string n_src) ;
6193 setName(
string new_name);
6231 string getElementName();
6247 abstract softlist
getRenameSql(
string table_name,
string new_name);
6287 string getElementName();
6367 any methodGate(
string meth);
6399 static string makeDatasourceDesc(AbstractDatasource ds);
6403 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt,
string tag);
6409 static validateOptionIntern(
string err,
string type, reference opt,
string k,
string tag);
6442 const DatabaseOptions = (
6451 "table_cache":
"Tables",
6460 const CallbackOptions = (
6461 "info_callback":
"code",
6462 "sql_callback":
"code",
6474 const AC_Unchanged = 0;
6478 const AC_Create = 1;
6484 const AC_Rename = 3;
6487 const AC_Modify = 4;
6490 const AC_Truncate = 5;
6496 const AC_Recreate = 7;
6499 const AC_Insert = 8;
6502 const AC_Update = 9;
6505 const AC_Delete = 10;
6508 const AC_NotFound = 11;
6513 AC_Unchanged:
"unchanged",
6514 AC_Create:
"create",
6516 AC_Rename:
"rename",
6517 AC_Modify:
"modify",
6518 AC_Truncate:
"truncate",
6520 AC_Recreate:
"recreate",
6521 AC_Insert:
"insert",
6522 AC_Update:
"update",
6523 AC_Delete:
"delete",
6524 AC_NotFound:
"not found",
6528 const ActionDescMap = (
6529 "unchanged": AC_Unchanged,
6530 "create": AC_Create,
6532 "rename": AC_Rename,
6533 "modify": AC_Modify,
6534 "truncate": AC_Truncate,
6536 "recreate": AC_Recreate,
6537 "insert": AC_Insert,
6538 "update": AC_Update,
6539 "delete": AC_Delete,
6540 "not found": AC_NotFound,
6544 const ActionLetterMap = (
6566 const CreationOptions = CallbackOptions + (
6568 "table_cache":
"Tables",
6577 const AlignSchemaOptions = CreationOptions + (
6585 const DropSchemaOptions = CallbackOptions + (
6602 const SchemaDescriptionOptions = (
6625 const SequenceDescriptionOptions = (
6632 const ComputeStatisticsOptions = (
6633 "tables" :
"softstringlist",
6637 const ReclaimSpaceOptions = (
6638 "tables" :
"softstringlist",
6665 static doOkCallback(*
hash opt,
int ac,
string type,
string name, *
string table, *
string info);
6667 static *
string doCallback(*
hash opt, *
string sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
6669 static list doCallback(*
hash opt,
list sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
6774 list dropSqlUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
6780 list alignCodeUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
6865 bool dropFunctionIfExists(
string name, *
hash opt);
6881 bool dropProcedureIfExists(
string name, *
hash opt);
6897 bool dropSequenceIfExists(
string name, *
hash opt);
6913 bool dropViewIfExists(
string name, *
hash opt);
6929 bool dropTableIfExists(
string name, *
hash opt);
6945 *
string getDropFunctionSqlIfExists(
string name, *
hash opt);
6961 *
string getDropProcedureSqlIfExists(
string name, *
hash opt);
6977 *
string getDropSequenceSqlIfExists(
string name, *
hash opt);
6996 doDropSql(*softlist l,
string type,
string name, *
hash opt);
6999 bool doDrop(*softlist l,
string type,
string name, *
hash opt);
7113 int getNextSequenceValue(
string name);
7126 int getCurrentSequenceValue(
string name);
7143 bool supportsSequences();
7147 bool supportsTypes();
7151 bool supportsPackages();
7163 list listFunctions();
7171 list listProcedures();
7179 list listSequences();
7205 bool rebuildIndex(
string name, *
hash options);
7228 computeStatistics(*
hash options);
7239 reclaimSpace(*
hash options);
7244 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt);
7250 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt,
string tag);
7260 static checkDriverOptions(reference<hash> h,
string drv);
7265 hash getDatabaseOptions();
7272 hash getCallbackOptions();
7279 hash getCreationOptions();
7293 hash getAlignSchemaOptions();
7300 hash getDropSchemaOptions();
7307 hash getSchemaDescriptionOptions();
7314 hash getSequenceDescriptionOptions();
7321 hash getRebuildIndexOptions();
7328 hash getComputeStatisticsOptions();
7335 hash getReclaimSpaceOptions();
7355 abstract string getCreateSqlImpl(
list l);
7359 abstract list getAlignSqlImpl(
hash schema_hash, *
hash opt);
7363 abstract list getDropSchemaSqlImpl(
hash schema_hash, *
hash opt);
7398 abstract list featuresImpl();
7402 abstract list listTablesImpl();
7406 abstract list listFunctionsImpl();
7410 abstract list listProceduresImpl();
7414 abstract list listSequencesImpl();
7418 abstract list listViewsImpl();
7424 abstract int getNextSequenceValueImpl(
string name);
7429 abstract int getCurrentSequenceValueImpl(
string name);
7435 abstract bool supportsSequencesImpl();
7439 abstract bool supportsPackagesImpl();
7443 abstract bool supportsTypesImpl();
7448 abstract bool rebuildIndexImpl(
string name, *
hash options);
7452 abstract computeStatisticsImpl(*
hash options);
7456 abstract reclaimSpaceImpl(*
hash options);
7561 any methodGate(
string meth);
7580 "table_cache":
"Tables",
7600 "table_cache":
"Tables",
7608 "table_cache":
"Tables",
7624 "where":
"hash/list",
7625 "orderby":
"softstringinthashlist",
7630 "groupby":
"softstringinthashlist",
7639 "foreign_constraints":
True,
7648 "omit":
"softstringlist",
7665 "db_table_cache":
"Tables",
7689 "table_cache":
"Tables",
7734 "sqlarg_callback":
"code",
7735 "tablecode":
"code",
7749 "returning":
"stringhashlist",
7760 "info_callback":
"code",
7763 "omit_update":
"softstringlist",
7772 "info_callback":
"code",
7975 doTableOptions(*
hash nopts);
8190 rename(
string new_name, *reference<string> sql, *
Tables table_cache);
8195 doRenameIntern(
string new_name, *
Tables table_cache);
8229 bool emptyUnlocked();
8306 AbstractColumn addColumnUnlocked(
string cname,
hash opt,
bool nullable = True, *reference lsql,
bool do_exec = True,
bool modify_table = True);
8427 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt);
8433 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt,
string tag);
8439 execSql(softlist lsql);
8501 AbstractPrimaryKey addPrimaryKeyUnlocked(
string pkname, softlist cols, *
hash opt, *reference<string> sql);
8507 AbstractPrimaryKey addPrimaryKeyUnlockedIntern(
string pkname, softlist cols, *
hash opt, *reference<string> sql);
8533 list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(
string cname, *
hash opt);
8695 AbstractIndex addIndexUnlocked(
string iname,
bool unique, softlist cols, *
hash opt, *reference<string> sql);
8701 AbstractIndex addIndexUnlockedIntern(
string iname,
bool unique, softlist cols, *
hash opt, *reference<string> sql);
8820 Columns getReferencedTableColumnsUnlocked(
string table, *
Tables cache,
string err =
"FOREIGN-CONSTRAINT-ERROR");
8826 AbstractForeignConstraint addForeignConstraintUnlocked(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference<string> sql);
8832 AbstractForeignConstraint addForeignConstraintUnlockedIntern(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference<string> sql);
9087 AbstractTrigger addTriggerUnlockedIntern(
string tname,
string src, *
hash opt, *reference lsql);
9138 getAllConstraintsUnlocked(*
hash opt);
9144 checkUniqueConstraintName(
string err,
string cname);
9150 checkUniqueConstraintNameValidateOptions(
string err,
string cname,
hash ropt, reference<hash> opt);
9273 *
hash insertIntern(
hash row, *reference<string> sql, *
hash opt);
9279 hash getPlaceholdersAndValues(
hash row);
9960 string getSelectSqlIntern(*
hash qh, reference<list> args, *
hash opt);
9963 string getSelectSqlUnlocked(*
hash qh, reference<list> args, *
hash opt);
9967 string getSelectSqlUnlockedIntern(*
hash qh,
string from, reference<list> args, *
hash ch, *
hash opt);
9972 string getFromIntern(
string from, *
hash qh);
9996 doForUpdate(reference<string> sql);
10002 string getSelectSqlName(*
hash qh);
10008 string getColumnExpressionIntern(
auto cvc, *
hash jch,
bool join, *
hash ch, *
hash psch);
10014 string doColumnOperatorIntern(
hash cvc, *
hash jch,
bool join, *
hash ch, *
hash psch, *reference psch_ref);
10020 string doColumnOperatorIntern(
auto cop,
auto arg, *
string cve,
hash cm, *
hash jch,
bool join, *
hash ch, *
hash psch, *reference psch_ref);
10026 string getColumnNameIntern(
string cv, *
hash jch,
bool join, *
hash ch, *
hash psch);
10039 getSelectWhereSqlUnlocked(reference<string> sql, reference<list> args, *
hash qh, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10045 *
string getWhereClause(*
hash cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False);
10051 *
string getWhereClause(
list cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False);
10057 *
string getWhereClauseUnlocked(
list cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch, *
hash psch);
10063 *
string getWhereClauseUnlocked(*
hash cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch, *
hash psch);
10069 *
list getWhereClauseIntern(*
hash cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10075 string doWhereExpressionIntern(
string cn,
auto we, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10079 string getOrClause(
list arglist, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10082 string getOrClause(
hash arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10087 doSelectOrderBySqlUnlocked(reference<string> sql, reference<list> args, *
hash qh, *
hash jch, *
hash ch, *
hash psch,
list coll);
10142 int del(
hash cond, reference<string> sql,
hash opt);
10150 int del(
hash cond, reference<string> sql);
10166 int delIntern(*
hash cond, *reference<string> sql, *
hash opt);
10252 int updateIntern(
hash set, *
hash cond, *reference<string> sql, *
hash opt);
10258 string getUpdateExpression(
string col, hash<UpdateOperatorInfo> uh);
10264 bool emptyDataIntern();
10270 Columns checkUpsertRow(
hash row, reference<int> upsert_strategy);
10276 code getUpsertInsertFirst(
Columns cols,
hash example_row, *
hash opt);
10282 code getUpsertUpdateFirst(
Columns cols,
hash example_row, *
hash opt);
10288 code getUpsertSelectFirst(
Columns cols,
hash example_row, *
hash opt);
10306 Columns getUpsertColumns(reference csrc);
10312 string getUpsertSelectSql(
hash row,
Columns cols, reference<list<string>> updc);
10318 string getUpsertInsertSql(
hash row);
10324 string getUpsertUpdateSql(
hash row,
Columns cols, reference updc, *
hash opt);
10336 checkValue(
string cname,
string argname, reference val,
string type);
10538 *
hash getCheckOmissionOptions(*softlist ol,
string err);
10724 string getPrimaryKeyColumn();
11068 string getCreateTableSqlUnlocked(*
hash opt);
11074 *
list getCreateIndexesSqlUnlocked(*
hash opt,
bool cache = True);
11080 *
string getCreatePrimaryKeySqlUnlocked(*
hash opt,
bool cache = True);
11086 *
list getCreateConstraintsSqlUnlocked(*
hash opt,
bool cache = True);
11092 *
list getCreateForeignConstraintsSqlUnlocked(*
hash opt,
bool cache = True);
11098 *
list getCreateMiscSqlUnlocked(*
hash opt,
bool cache = True);
11104 *
list getCreateTriggersSqlUnlocked(*
hash opt,
bool cache = True);
11116 cacheUnlocked(*
hash opt);
11122 auto execData(*
hash opt,
string sql, *
list args);
11128 execData(SQLStatement stmt, *
hash opt, *
list args);
11140 getColumnsUnlocked();
11146 getPrimaryKeyUnlocked();
11153 getIndexesUnlocked();
11159 getForeignConstraintsUnlocked(*
hash opt);
11171 getConstraintsUnlocked();
11177 getTriggersUnlocked();
11190 softlist getDropSqlImpl();
11196 string getTruncateSqlImpl();
11223 preSetupTableImpl(reference desc, *
hash opt);
11229 abstract *
hash doReturningImpl(
hash opt, reference<string> sql,
list args);
11234 abstract bool emptyImpl();
11272 abstract setupTableImpl(
hash desc, *
hash opt);
11277 abstract Columns describeImpl();
11285 abstract Indexes getIndexesImpl();
11297 abstract Triggers getTriggersImpl();
11302 abstract string getCreateTableSqlImpl(*
hash opt);
11306 abstract *
list getCreateMiscSqlImpl(*
hash opt,
bool cache);
11310 abstract string getCreateSqlImpl(
list l);
11314 abstract string getRenameSqlImpl(
string new_name);
11323 abstract AbstractColumn addColumnImpl(
string cname,
hash opt,
bool nullable = True);
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5767
hash< ColumnOperatorInfo > cop_first_value(any column)
Analytic/window function: value evaluated at the row that is the first row of the window frame...
softlist getDropSql(*hash opt)
returns the sql required to drop the table; reimplement in subclasses if necessary ...
const SelectOptions
default possible select options; can be extended by driver-specific modules
Definition: SqlUtil.qm.dox.h:7619
Constraints getConstraints()
returns a Constraints object describing the non-foreign constraints on the table
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6054
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2321
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2126
any column
column sopecifier, may be a string or a complex hash
Definition: SqlUtil.qm.dox.h:2113
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:7821
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
const DefaultIopMap
a hash of default insert operator descriptions (currently empty, all operators are driver-dependent) ...
Definition: SqlUtil.qm.dox.h:4795
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:5133
hash< ColumnOperatorInfo > cop_append(auto column, string arg)
returns a ColumnOperatorInfo hash for the "append" operator with the given argument ...
const TableOmissionOptions
alignment omission options
Definition: SqlUtil.qm.dox.h:7637
string native_type
the native database column type; if both native_type and qore_type are given then native_type is used...
Definition: SqlUtil.qm.dox.h:2085
rename(string new_name, *reference< string > sql, *Tables table_cache)
renames the table; if the table is already known to be in the database in the database, then the changes are effected in the database also immediately; otherwise it is only updated internally
string cop
the column operator string code
Definition: SqlUtil.qm.dox.h:2112
string sprintf(string fmt,...)
deprecated truncateNoCommit()
A legacy warpper for truncate()
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...
bool hasReturningImpl()
returns True if the current database driver supports the "returning" clause in insert statements...
int delCommit()
SqlUtil::AbstractTable::delCommit() variant
const OP_IN
the SQL "in" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4313
deprecated createNoCommit(*hash opt)
A legacy wrapper for create()
hash getInsertOptions()
returns the insert options for this driver
bool checkExistence()
returns True if the table exists in the database, False if not
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:7569
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2412
bool hasReturning()
returns True if the current database driver supports the "returning" clause in insert statements...
hash< ColumnOperatorInfo > cop_cast(auto column, string arg, auto arg1, auto arg2)
returns a ColumnOperatorInfo hash for the "cast" operator with the given argument(s) ...
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2172
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:7607
const COP_FIRST_VALUE
Analytic (window) function: FIRST_VALUE.
Definition: SqlUtil.qm.dox.h:2373
hash< ColumnOperatorInfo > cop_multiply(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "*" operator with the given arguments
*hash insertCommit(hash row)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
const ColumnOptions
Column options; this is currently empty and can be extended in database-specific modules.
Definition: SqlUtil.qm.dox.h:7726
auto tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:5225
validateColumnOptions(string cname, reference< hash > opt, bool nullable)
validates column options
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:6102
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
hash getIndexOptions()
returns the index options for this driver
const UpsertResultLetterMap
maps upsert result codes to single letter symbols
Definition: SqlUtil.qm.dox.h:7905
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:7840
dropCommit(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
insert operator info hash as returned by all insert operator functions
Definition: SqlUtil.qm.dox.h:2118
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:7867
hash< OperatorInfo > op_ne(auto arg)
returns an OperatorInfo hash for the "!=" or "<>" operator with the given argument for use in where c...
cache(*hash opts)
reads in all attributes of the table from the database
string printf(string fmt,...)
const OP_BETWEEN
the SQL "between" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4308
string getSqlValue(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:5661
deprecated int delNoCommit(*hash cond, *reference< string > sql)
A legacy SqlUtil::AbstractTable::del() wrapper.
*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...
hash< ColumnOperatorInfo > make_cop(string cop, auto column, auto arg)
returns a ColumnOperatorInfo hash
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2120
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:5644
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4326
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
const COP_OVER
the SQL "over" clause
Definition: SqlUtil.qm.dox.h:2276
hash< ColumnOperatorInfo > cop_as(auto column, string arg)
returns a ColumnOperatorInfo hash for the "as" operator with the given argument
auto tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5959
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:7896
hash< ColumnOperatorInfo > cop_minus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "-" operator with the given arguments
const UR_Deleted
row was deleted (only possible with batch upsert methods such as AbstractTable::upsertFromIterator() ...
Definition: SqlUtil.qm.dox.h:7879
int insertFromIteratorCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
const InsertFromIteratorOptions
default insert option keys
Definition: SqlUtil.qm.dox.h:7771
hash< ColumnOperatorInfo > cop_last_value(any column)
Analytic/window function: value evaluated at the row that is the last row of the window frame...
const COP_DENSE_RANK
Analytic (window) function: DENSE_RANK.
Definition: SqlUtil.qm.dox.h:2366
deprecated int upsertNoCommit(hash row, int upsert_strategy=UpsertAuto)
A legacy SqlUtil::AbstractTable::upsert() wrapper.
const OP_NE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4268
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table
hash< ColumnOperatorInfo > cop_rank()
Analytic/window function: rank of the current row with gaps.
deprecated *hash insertNoCommit(hash row, *reference< string > sql, *hash opt)
A legacy wrapper for SqlUtil::AbstractTable::insert()
constructor(AbstractDatasource nds, string nname, *hash nopts)
creates the object; private constructor
hash< InsertOperatorInfo > iop_seq_currval(string arg)
returns an InsertOperatorInfo hash for retrieving the current value of the given sequence in insert q...
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
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2266
list getAlignSql(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
truncateCommit()
truncates all the table data; releases the transaction lock after executing
string name
the name of the object
Definition: SqlUtil.qm.dox.h:6132
string getAlignSqlString(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:6006
hash< ColumnOperatorInfo > cop_length(auto column)
returns a ColumnOperatorInfo hash for the "len" operator with the given argument; returns the length ...
*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...
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:5476
const COP_SEQ_CURRVAL
to return the last value of a sequence issued in the same session
Definition: SqlUtil.qm.dox.h:2326
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:5580
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...
hash< InsertOperatorInfo > make_iop(string iop, auto arg)
returns an InsertOperatorInfo hash
const JopMap
a hash of valid join operators
Definition: SqlUtil.qm.dox.h:3769
hash getTableCreationOptions()
returns the table creation options for this driver
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:2195
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4258
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2178
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2261
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:2156
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:2150
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3761
base class for sequences
Definition: SqlUtil.qm.dox.h:6049
*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...
*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 ...
const COP_LAST_VALUE
Analytic (window) function: LAST_VALUE.
Definition: SqlUtil.qm.dox.h:2380
hash< OperatorInfo > op_clt(string arg)
returns an OperatorInfo hash for the "<" operator with the given argument for use in where clauses wh...
bool nullable
True if the column can hold a NULL value, False if not
Definition: SqlUtil.qm.dox.h:5482
abstract hash getQoreTypeMapImpl()
returns the qore type -> column type map
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2107
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:7759
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2246
hash< OperatorInfo > op_cge(string arg)
returns an OperatorInfo hash for the ">=" operator with the given argument for use in where clauses w...
hash getTriggerOptions()
returns the trigger options for this driver
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:2316
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:7599
*hash opt
optional join options (for example, to specify a partition for the join if supported) ...
Definition: SqlUtil.qm.dox.h:2138
Columns describe()
returns an object of class Columns describing the table
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
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7925
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:7931
*list selectRows(*hash sh, *reference< string > sql, *hash opt)
returns a list of hashes representing the rows in the table that match the argument hash ...
hash< UpdateOperatorInfo > uop_multiply(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "*" operator with the given arguments
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
hash< ColumnOperatorInfo > cop_plus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "+" operator with the given arguments
AbstractConstraint dropConstraint(string cname, *reference< string > sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
hash< ColumnOperatorInfo > cop_value(auto arg)
returns a ColumnOperatorInfo hash for the "value" (literal) operator with the given argument ...
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...
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...
any table
the table to join with (either an AbstractTable object or a string table name)
Definition: SqlUtil.qm.dox.h:2133
hash< UpdateOperatorInfo > uop_substr(int start, *int count, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "substr" operator with the given arguments; returns a subs...
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
string jop
the join operator string code
Definition: SqlUtil.qm.dox.h:2132
const IOP_SEQ_CURRVAL
for using the last value of a sequence issued in the current session
Definition: SqlUtil.qm.dox.h:4792
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...
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:6372
abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference< string > sql, reference< list > args, *hash qh, *hash jch, *hash ch, *hash psch, list coll)
processes a string for use in SQL select statements when there is an "order by" and "offset" argument...
hash getAlignTableOptions()
returns the align table options for this driver
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:7805
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference< string > sql, *hash opt)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
hash< ColumnOperatorInfo > cop_year_day(auto column)
returns a ColumnOperatorInfo hash for the "year_day" operator with the given argument ...
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
string getColumnSqlName(string col)
returns the column name for use in SQL strings; subclasses can return a special string in case the co...
create(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
const OP_CNE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4298
auto tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
hash< UpdateOperatorInfo > uop_prepend(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "prepend" operator with the given argument ...
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:6302
const SqlUtilDrivers
known drivers
Definition: SqlUtil.qm.dox.h:4842
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4288
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:6028
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:6033
hash< OperatorInfo > op_le(auto arg)
returns an OperatorInfo hash for the "<=" operator with the given argument for use in where clauses w...
deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtil::AbstractTable::upsertFromSelect() wrapper.
Mutex l()
mutex for atomic actions
deprecated dropNoCommit(*hash opt)
A legacy wrapper for drop()
int insertFromSelect(list cols, AbstractTable source, hash sh, reference< string > sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
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
AbstractIndex renameIndex(string old_name, string new_name, reference< string > sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
hash< string, hash< JoinOperatorInfo > > join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments for use when joining with a table other...
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:5585
abstract hash getTypeMapImpl()
returns the type name -> type description hash
hash< string, hash< JoinOperatorInfo > > join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
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...
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:5823
hash< UpdateOperatorInfo > uop_divide(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "/" operator with the given arguments
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2271
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4303
const COP_NTILE
Analytic (window) function: NTILE.
Definition: SqlUtil.qm.dox.h:2387
hash< UpdateOperatorInfo > uop_plus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "+" operator with the given arguments
softint scale
for numeric data types, this value gives the scale
Definition: SqlUtil.qm.dox.h:2089
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4851
hash< ColumnOperatorInfo > cop_year_hour(auto column)
returns a ColumnOperatorInfo hash for the "year_hour" operator with the given argument ...
join operator info hash as returned by all join operator functions
Definition: SqlUtil.qm.dox.h:2131
any default_value
the default value for the column
Definition: SqlUtil.qm.dox.h:2091
the SqlUtil namespace contains all the objects in the SqlUtil module
Definition: SqlUtil.qm.dox.h:2079
bool empty()
returns True if the table has no definitions, False if not
string name
the table's name
Definition: SqlUtil.qm.dox.h:7917
hash< OperatorInfo > op_cne(string arg)
returns an OperatorInfo hash for the "!=" or "<>" operator with the given argument for use in where c...
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
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:6254
int updateCommit(hash set, hash cond, reference< string > sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2114
string getSelectSql(*hash sh, *reference< list > args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
int index(softstring str, softstring substr, softint pos=0)
string src
the source of the check clause
Definition: SqlUtil.qm.dox.h:5828
string getDatasourceDesc()
returns a descriptive string for the datasource
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference< string > sql)
adds an index to the table; if the table is already known to be in the database, then it is added in ...
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7923
const DT_DAY
Format unit: day.
Definition: SqlUtil.qm.dox.h:3491
hash< OperatorInfo > op_cle(string arg)
returns an OperatorInfo hash for the "<=" operator with the given argument for use in where clauses w...
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:2152
hash< ColumnOperatorInfo > cop_avg(auto column)
returns a ColumnOperatorInfo hash for the "avg" operator; returns average column values ...
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2236
hash< string, hash< JoinOperatorInfo > > join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
hash getColumnDescOptions()
returns the column description options for this driver
deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtik::AbstractTable::upsertFromIterator() wrapper.
*hash getColumnOperatorMapImpl()
Reimplement in subclasses to provide driver specific column operators.
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...
clearImpl()
clears any driver-specific table information
*hash cond
additional conditions for the join clause for the table argument; see Where Clauses for more informat...
Definition: SqlUtil.qm.dox.h:2136
const COP_PLUS
the SQL "plus" operator
Definition: SqlUtil.qm.dox.h:2286
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7870
clear()
purges the current table definition
const OP_GE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4263
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:5598
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2201
hash< OperatorInfo > op_between(auto l, auto r)
returns an OperatorInfo hash for the "between" operator with the given arguments, neither of which ca...
const TableOptions
table options
Definition: SqlUtil.qm.dox.h:7578
*bool auto_increment
True for DBs that support an auto-increment column
Definition: SqlUtil.qm.dox.h:2101
*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...
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
const DB_SYNONYMS
Feature: synonyms.
Definition: SqlUtil.qm.dox.h:2164
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:5485
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7921
hash< UpdateOperatorInfo > uop_upper(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "upper" operator with the given argument; returns a column...
const COP_COALESCE
to return the first non-null argument in the list
Definition: SqlUtil.qm.dox.h:2331
string op
the operator string code
Definition: SqlUtil.qm.dox.h:2106
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:7935
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:7660
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
bool emptyData()
returns True if the table has no data rows, False if not
string getBaseType()
returns the base type of the underlying object (normally "table", some DB-specific implementations ma...
hash< ColumnOperatorInfo > cop_min(auto column)
returns a ColumnOperatorInfo hash for the "min" operator; returns minimum column values ...
*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...
abstract bool hasArrayBind()
returns True if the underlying DB driver supports bulk DML operations
hash< OperatorInfo > op_ge(auto arg)
returns an OperatorInfo hash for the ">=" operator with the given argument for use in where clauses w...
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:7929
string getDesc()
returns a descriptive string of the datasource (without the password) and the table name (with a poss...
abstract *string getSqlValueImpl(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:2154
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:6566
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4273
validateHashKeysForWhitespaces(auto node)
Check input node for all hash keys - if it contains a key with whitespace in the beginning or at the ...
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
generic column description hash in schema descriptions
Definition: SqlUtil.qm.dox.h:2081
int del()
SqlUtil::AbstractTable::del() variant
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:5488
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...
hash< ColumnOperatorInfo > cop_coalesce(auto col1, auto col2)
returns a ColumnOperatorInfo hash for the "coalesce" operator with the given column arguments; the fi...
string src
the source code
Definition: SqlUtil.qm.dox.h:6099
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:5652
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
hash< ColumnOperatorInfo > cop_trunc_date(auto column, string mask)
Truncates a date column or value regarding the given mask. The resulting value remains Qore::date (no...
hash< ColumnOperatorInfo > cop_dense_rank()
Analytic/window function: rank of the current row without gaps.
hash< OperatorInfo > op_eq(auto arg)
returns an OperatorInfo hash for the "=" operator with the given argument for use in where clauses wh...
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
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifier for schema, etc)
*hash find(auto id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:2306
string src
the source of the object
Definition: SqlUtil.qm.dox.h:6138
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference< string > sql)
adds a primary key to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2256
hash< OperatorInfo > op_cgt(string arg)
returns an OperatorInfo hash for the ">" operator with the given argument for use in where clauses wh...
const COP_LENGTH
to get the length of a text field
Definition: SqlUtil.qm.dox.h:2343
auto tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2211
string getDriverName()
returns the database driver name
hash< string, hash< JoinOperatorInfo > > join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments for use when joining with a table other ...
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:7919
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference< AbstractConstraint > cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:2162
hash< ColumnOperatorInfo > cop_max(auto column)
returns a ColumnOperatorInfo hash for the "max" operator; returns maximum column values ...
AbstractTrigger dropTrigger(string tname, *reference< string > sql)
drops the given trigger from the table; if the table is known to be in the database already...
const OP_LE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4253
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2181
string name
the name of the index
Definition: SqlUtil.qm.dox.h:5649
string _iop
the insert operator string code
Definition: SqlUtil.qm.dox.h:2119
*string getCreatePrimaryKeySql(*hash opt, bool cache=True)
returns an SQL string that could be used to create the primary key on the table
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:6014
string uop
the update operator string code
Definition: SqlUtil.qm.dox.h:2125
drop(*hash opt)
drops the table from the database without any transaction management
const OP_CLE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4283
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5853
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 ...
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:2158
abstract bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
hash< UpdateOperatorInfo > uop_append(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "append" or concatenate operator with the given argument ...
createCommit(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
hash< UpdateOperatorInfo > uop_seq_currval(string seq)
returns an UpdateOperatorInfo hash for the "seq" operator with the given argument giving the sequence...
hash< ColumnOperatorInfo > cop_ntile(int value)
Analytic/window function: integer ranging from 1 to the argument value, dividing the partition as equ...
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:2184
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4318
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:5655
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:7733
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:6127
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:2160
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
update operator info hash as returned by all update operator functions
Definition: SqlUtil.qm.dox.h:2124
hash< string, hash< JoinOperatorInfo > > make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns hash keyed with the table name assigned to a JoinOperatorInfo hash
const COP_CUME_DIST
Analytic (window) function: CUME_DIST.
Definition: SqlUtil.qm.dox.h:2359
copy(AbstractTable old)
copies the object
hash< ColumnOperatorInfo > cop_lower(auto column)
returns a ColumnOperatorInfo hash for the "lower" operator with the given argument; returns a column ...
hash< ColumnOperatorInfo > cop_distinct(auto column)
returns a ColumnOperatorInfo hash for the "distinct" operator with the given argument; returns distin...
hash getColumnOptions()
returns the column options for this driver
bool asteriskRequiresPrefix()
returns True if the database requires a wildcard "*" to be prefixed with the table name when it appea...
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:7885
string name
the name of the column
Definition: SqlUtil.qm.dox.h:5470
bool bindEmptyStringsAsNull()
returns True if the DB treats empty strings as NULL, False if not; by default this method returns Fal...
hash< ColumnOperatorInfo > cop_year(auto column)
returns a ColumnOperatorInfo hash for the "year" operator with the given argument ...
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:6377
hash< UpdateOperatorInfo > uop_lower(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "lower" operator with the given argument; returns a column...
hash< string, hash< OperatorInfo > > wop_or(hash h1, hash h2)
returns an OperatorInfo hash with a fake "_OR_" column name; the list of arguments to the function is...
hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
base class for functions
Definition: SqlUtil.qm.dox.h:6172
auto tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
abstract copyImpl(AbstractTable old)
db-specific copy actions
const COP_MULTIPLY
the SQL "multiply" operator
Definition: SqlUtil.qm.dox.h:2296
column operator info hash as returned by all column operator functions
Definition: SqlUtil.qm.dox.h:2111
hash< ColumnOperatorInfo > cop_count(auto column="")
returns a ColumnOperatorInfo hash for the "count" operator; returns row counts
abstract bool tryInsertImpl(string sql, hash row)
tries to insert a row, if there is a duplicate key, then it returns False, if successful, returns True
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:7927
hash< ColumnOperatorInfo > cop_cume_dist()
Analytic/window function: relative rank of the current row.
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:2221
hash getInsertFromIteratorOptions()
returns the insert from iterator options for this driver
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
const COP_TRUNC_DATE
to return the date with truncated value
Definition: SqlUtil.qm.dox.h:2352
*hash insert(hash row)
inserts a row into the table without any transaction management; a transaction will be in progress af...
base class for views
Definition: SqlUtil.qm.dox.h:6088
deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference< string > sql, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromSelect() wrapper.
hash< OperatorInfo > op_like(string str)
returns an OperatorInfo hash for the "like" operator with the given argument for use in where clauses...
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:6383
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
abstract bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
*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...
*hash select(*hash sh, *reference< string > sql, *hash opt)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference< string > sql)
adds a foreign constraint to the table; if the table is already known to be in the database...
const InsertOptions
generic SQL insert options
Definition: SqlUtil.qm.dox.h:7748
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:7614
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
hash< string, hash< JoinOperatorInfo > > join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
string type
the type of object
Definition: SqlUtil.qm.dox.h:6135
deprecated int updateNoCommit(hash set, *hash cond, *reference< string > sql)
A legacy SqlUtil::AbstractTable::update() wrapper.
hash< ColumnOperatorInfo > cop_seq(string seq, *string as)
returns a ColumnOperatorInfo hash for the "seq" operator with the given argument giving the sequence ...
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:2301
hash< string, hash< JoinOperatorInfo > > join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments for use when joining with a table ot...
string string(softstring str, *string enc)
hash getWhereOperatorMap()
returns the "where" operator map for this object
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference< string > sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
softint rowCount()
returns the number of rows in the table
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
hash getForeignConstraintOptions()
return the foreign constraint options for this driver
int size
the size of the column
Definition: SqlUtil.qm.dox.h:5479
hash< string, hash > driver
this key can optionally contain a hash keyed by driver name which contains a hash of values that will...
Definition: SqlUtil.qm.dox.h:2099
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 ...
hash getConstraintOptions()
returns the constraint options for this driver
hash getUpsertOptions()
returns the upsert options for this driver
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:5473
const COP_VALUE
to append a constant value (SQL Literal) to use as an output column value
Definition: SqlUtil.qm.dox.h:2231
hash< UpdateOperatorInfo > uop_seq(string seq)
returns an UpdateOperatorInfo hash for the "seq" operator with the given argument giving the sequence...
const UpsertUpdateOnly
Upsert option: update if the row exists, otherwise ignore.
Definition: SqlUtil.qm.dox.h:7835
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:5413
the base class for triggers
Definition: SqlUtil.qm.dox.h:6236
*string ta
optional table name or alias of the other table to join with when not joining with the primary table ...
Definition: SqlUtil.qm.dox.h:2137
*hash getPseudoColumnHash()
returns a hash of valid pseudocolumns
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference< string > sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
const OP_LT
the SQL less than (<) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4248
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:6379
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
hash< ColumnOperatorInfo > cop_sum(auto column)
returns a ColumnOperatorInfo hash for the "sum" operator; returns the total sum of a numeric column...
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:6198
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst, UpsertInsertOnly, and UpsertUpdateOnly) ...
Definition: SqlUtil.qm.dox.h:7876
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7873
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6307
the base class for column information
Definition: SqlUtil.qm.dox.h:5465
truncate()
truncates all the table data without any transaction management
const COP_CAST
to convert column value into another datatype
Definition: SqlUtil.qm.dox.h:2216
hash< OperatorInfo > op_in()
returns an OperatorInfo hash for the "in" operator with all arguments passed to the function; for use...
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:7828
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4293
const DT_MINUTE
Format unit: minute.
Definition: SqlUtil.qm.dox.h:3497
hash< ColumnOperatorInfo > cop_seq_currval(string seq, *string as)
returns a ColumnOperatorInfo hash for the "seq_currval" operator with the given argument giving the s...
const DT_HOUR
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3494
string getName()
returns the name of the table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:7477
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:7588
*string comment
an optional comment for the column
Definition: SqlUtil.qm.dox.h:2095
AbstractIndex dropIndex(string iname, *reference< string > sql)
drops the given index from the table; if the table is known to be in the database already...
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference< string > sql)
adds a unique constraint to the table; if the table is known to be in the database already...
hash< ColumnOperatorInfo > cop_divide(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "/" operator with the given arguments
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:3511
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2251
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:7814
AbstractForeignConstraint dropForeignConstraint(string cname, *reference< string > sql)
drops a foreign constraint from the table; if the table is known to be in the database already...
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:2311
hash< OperatorInfo > op_gt(auto arg)
returns an OperatorInfo hash for the ">" operator with the given argument for use in where clauses wh...
setupTable(hash desc, *hash opt)
creates the object from a table description hash
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:7797
const DT_MONTH
Format unit: month.
Definition: SqlUtil.qm.dox.h:3488
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6096
hash getTableColumnDescOptions()
returns the table column description options for this driver
const COP_PERCENT_RANK
Analytic (window) function: PERCENT_RANK.
Definition: SqlUtil.qm.dox.h:2394
abstract doSelectLimitOnlyUnlockedImpl(reference< string > sql, reference< list > args, *hash qh)
processes a string for use in SQL select statements when there is a "limit" argument, but no "orderby" or "offset" arguments
*hash jcols
the columns to use for the join, the keys will be columns in the source table and the values are colu...
Definition: SqlUtil.qm.dox.h:2135
*number max
the ending number
Definition: SqlUtil.qm.dox.h:6063
hash getUpdateOperatorMap()
returns the update operator map for this object
const COP_RANK
Analytic (window) function: RANK.
Definition: SqlUtil.qm.dox.h:2401
hash< OperatorInfo > op_not(hash arg)
returns an OperatorInfo hash for the "not" operator; for use in where clauses
const ColumnDescOptions
Column description options.
Definition: SqlUtil.qm.dox.h:7705
number increment
the increment
Definition: SqlUtil.qm.dox.h:6060
hash getTableOptions()
returns the table options for this driver
hash< ColumnOperatorInfo > cop_row_number()
Analytic/window function: number of the current row within its partition, counting from 1...
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
const OP_LIKE
the SQL "like" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4243
hash< OperatorInfo > op_lt(auto arg)
returns an OperatorInfo hash for the "<" operator with the given argument for use in where clauses wh...
hash< OperatorInfo > make_op(string op, auto arg)
returns an OperatorInfo hash
hash< OperatorInfo > op_substr(int start, *int count, string text)
returns an OperatorInfo hash for the "substr" operator with the given arguments; for use in where cla...
const TableDescriptionHashOptions
Table description options.
Definition: SqlUtil.qm.dox.h:7681
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2192
hash< UpdateOperatorInfo > uop_minus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "-" operator with the given arguments
AbstractColumn renameColumn(string old_name, string new_name, reference< string > sql)
renames an existing column; if the table is already known to be in the database, then the changes are...
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:7482
hash getColumnOperatorMap()
returns the column operator map for this object
hash< ColumnOperatorInfo > cop_upper(auto column)
returns a ColumnOperatorInfo hash for the "upper" operator with the given argument; returns a column ...
const OP_CLT
the SQL less than (<) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:4278
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2281
hash< ColumnOperatorInfo > cop_percent_rank()
Analytic/window function: relative rank of the current row.
hash getTableDescriptionHashOptions()
returns the table description hash options for this driver
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:6011
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
const TableCreationOptions
table creation options
Definition: SqlUtil.qm.dox.h:7647
hash< ColumnOperatorInfo > cop_over(auto column, *string partitionby, *string orderby)
returns a ColumnOperatorInfo hash for the "over" clause
hash< ColumnOperatorInfo > cop_year_month(auto column)
returns a ColumnOperatorInfo hash for the "year_month" operator with the given argument ...
*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...
*string alias
optional alias for table in the query
Definition: SqlUtil.qm.dox.h:2134
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2336
hash getSelectOptions()
returns the select options for this driver
hash getCacheOptions()
returns the cache options for this driver
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3766
list getColumnSqlNames(softlist cols)
returns a list of column names for use in SQL strings; subclasses can process the argument list in ca...
const OP_SUBSTR
the SQL "substr" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4323
*hash selectRow(*hash sh, *reference< string > sql, *hash opt)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
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...
hash< ColumnOperatorInfo > cop_substr(auto column, int start, *int count)
returns a ColumnOperatorInfo hash for the "substr" operator with the given arguments; returns a subst...
hash getSqlDataCallbackOptions()
returns the sql data operation callback options for this driver
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:2198
hash< InsertOperatorInfo > iop_seq(string arg)
returns an InsertOperatorInfo hash for retrieving the value of the given sequence in insert queries ...
abstract bool checkExistenceImpl()
returns True if the table exists in the DB, False if not
softint size
for data types requiring a size component, the size; for numeric columns this represents the precisio...
Definition: SqlUtil.qm.dox.h:2087
int update(hash set, hash cond, reference< string > sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
SQL operator info hash as returned by all operator functions.
Definition: SqlUtil.qm.dox.h:2105
number start
the starting number
Definition: SqlUtil.qm.dox.h:6057
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4787
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:6434
const COP_ROW_NUMBER
Analytic (window) function: ROW_NUMBER.
Definition: SqlUtil.qm.dox.h:2408
addCustomCopOperator(string name, hash operator)
register custom user column operator for this table object
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
const DT_YEAR
Format unit: year.
Definition: SqlUtil.qm.dox.h:3485
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 ...
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:5861
represents a primary key
Definition: SqlUtil.qm.dox.h:5948
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3756
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2241
hash< ColumnOperatorInfo > cop_prepend(auto column, string arg)
returns a ColumnOperatorInfo hash for the "prepend" operator with the given argument ...
*hash nest
option nested operation hash
Definition: SqlUtil.qm.dox.h:2127
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:2291
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:2148
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2175
*hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:5858
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:7852
deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromIterator() wrapper.
*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...
string qore_type
a qore type string that will be converted to a native DB type with some default conversion ...
Definition: SqlUtil.qm.dox.h:2083
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:7596
hash< UpdateOperatorInfo > make_uop(string uop, auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4329
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5939
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:7721
hash< OperatorInfo > op_ceq(string arg)
returns an OperatorInfo hash for the "=" operator with the given argument for use in where clauses wh...
hash getInsertOperatorMap()
returns the insert operator map for this object
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5758
const DT_SECOND
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3500
abstract bool supportsTablespacesImpl()
returns True if the database support tablespaces
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
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5716
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2226