381 @warning Oracle:
using different comments in the
same SQL can lead to
new optimizer statement hard parsing.
383 @subsubsection select_option_hint Select Option
"hint" 384 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).
388 table.selectRows((
"hint":
"full(t1)"));
390 will produce select statement like
this:
394 The
string is taken as-is and it
's up to the caller to handle correct aliases in join functions etc. 395 @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module. 396 @warning Use hints only when you know what you are doing. 398 @subsubsection select_option_columns Select Option "columns" 399 <b>Columns Example:</b> 402 "id", "name", "started", 403 cop_as("warnings", "warning_count"), 404 cop_as("errors", "error_count"), 406 *list rows = table.selectRows(("columns": columns, "where": ("type": "user"))); 408 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 409 This option takes a list, each element of the list can be one of the following.\n\n 410 <b>A Simple String Giving a Column Name</b>\n 413 *list rows = table.selectRows(("columns": ("id", "name", "started"))); 415 <b>A String in Dot Notation</b>\n 416 This format is for use with @ref select_option_join "joins"; ex: \c "q.name" 419 "columns": ("t1.id", "t2.customer_name"), 420 "join": join_inner(table2, "t2", ("id": "altid"))), 423 *list rows = table.selectRows(sh); 425 <b>A Column Operation Specified by a Column Operator Function</b>\n 426 ex: <tt>cop_as("column_name", "column_alias")</tt> \n 427 See @ref sql_cop_funcs "column operator function" for more information on column operator functions 431 cop_as("warnings", "warning_count"), 432 cop_as("errors", "error_count"), 434 *list rows = table.selectRows(("columns": columns)); 436 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 437 <b>The Value \c "*", Meaning All Columns</b>\n 440 *list rows = table.selectRows(("columns": "*")); 442 This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n 443 <b>An \c "*" in Dot Notation</b>\n 447 "columns": ("table.id", "t2.*"), 448 "join": join_inner(table2, "t2", ("id": "altid")), 450 *list rows = table.selectRows(sh); 453 @subsubsection select_option_where Select Option "where" 454 <b>Where Example:</b> 456 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200)); 458 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. 460 @subsubsection select_option_orderby Select Option "orderby" 461 <b>Orderby Example:</b> 465 "account_type": "CUSTOMER", 467 "orderby": "created_date", 469 *list rows = table.selectRows(sh); 471 This option is a list of the following values: 472 - a simple string giving a column name; ex: \c "name" 473 - 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 474 - 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" 475 - a positive integer giving the column number for the ordering 477 - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table 479 @subsubsection select_option_desc Select Option "desc" 484 "account_type": "CUSTOMER", 486 "orderby": "created_date", 489 *list rows = table.selectRows(sh); 491 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 492 Otherwise, ordered results are returned in ascending order by default. 494 @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" 496 @subsubsection select_option_limit Select Option "limit" 497 <b>Limit Example:</b> 500 "where": ("type": "user"), 504 *list rows = table.selectRows(sh); 506 This option will limit the number of rows returned. 508 - This option is required if the @ref select_option_offset "offset option" is non-zero 509 - 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 511 @subsubsection select_option_offset Select Option "offset" 512 <b>Offset Example:</b> 515 "where": ("type": "user"), 519 *list rows = table.selectRows(sh); 521 This option specifies the row number offset for the rows returned where the first row is at offset zero. 523 - 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. 524 - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown. 527 @subsubsection select_option_join Select Option "join" 532 "name", "version", "id", 533 cop_as("st.value", "source"), 534 cop_as("st.value", "offset"), 536 "join": join_left(function_instance_tags, "st", NOTHING, ("st.tag": "_source")) 537 + join_left(function_instance_tags, "lt", NOTHING, ("st.tag": "_offset")), 539 *list rows = table.selectRows(sh); 541 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). 542 @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 544 @see @ref joins for more examples 546 @subsubsection select_option_groupby Select Option "groupby" 547 <b>Groupby Example:</b> 551 cop_as(cop_max("service_type"), "type"), 554 "groupby": "service_type", 556 *list rows = table.selectRows(sh); 558 The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements. 559 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" 560 key are strings giving column names, optionally in dot notation or positive column numbers. 562 @subsubsection select_option_having Select Option "having" 563 <b>Having Example:</b> 567 cop_as(cop_max("service_type"), "type"), 570 "groupby": "service_type", 572 "service_type": (COP_COUNT, op_ge(100)), 575 *list rows = table.selectRows(sh); 577 The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria. 578 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. 580 @subsubsection select_option_superquery Select Option "superquery" 581 <b>Superquery Example:</b> 585 "serviceid", "service_methodid", 586 cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid"), 589 "columns": ("serviceid", "service_methodid"), 590 "where": ("max_methodid": op_ceq("service_methodid")), 593 *list rows = table.selectRows(sh); 595 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 596 The above example results in an SQL command equivalent to the following: 598 *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"); 600 @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL. 602 @subsubsection select_option_forupdate Select Option "forupdate" 603 <b>For Update Example:</b> 605 on_success ds.commit(); 606 on_error ds.rollback(); 609 "columns": ("serviceid", "service_methodid"), 612 *list rows = table.selectRows(sh); 614 \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. 615 The above example results in an SQL commit equivalent to the following: 617 *list rows = table.vselectRows("select serviceid,service_methodid from schema.service_methods for update"); 620 @subsection sql_paging Select With Paging 622 There is support for paging query results in the following methods: 623 - @ref SqlUtil::AbstractTable::getRowIterator() 624 - @ref SqlUtil::AbstractTable::getSelectSql() 625 - @ref SqlUtil::AbstractTable::select() 626 - @ref SqlUtil::AbstractTable::selectRows() 628 @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods 630 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. 632 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. 635 Select 100 rows starting at row 200 (the table's primary key will be used
for the \c
"orderby" option by
default): \n
637 *
list rows = table.selectRows((
"where": (
"type":
"user"),
"limit": 100,
"offset": 200));
639 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:
641 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));
645 ds.vselectRows(
"select * from public.table where type = %v order by type limit %v offset %v", (
"user", 100, 200));
648 @subsection check_matching_rows Check For At Least One Matching Row
652 *
hash h = table.findSingle((
"account_type":
"CUSTOMER"));
654 printf(
"found 1 customer row: %y\n",
l[0]);
657 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): 659 *hash h = table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1)); 661 printf("found 1 customer row: %y\n", l[0]); 664 @section inserting_data Inserting Data into the Database 666 The following methods can be used to insert data into the database: 667 - @ref SqlUtil::AbstractTable::insert(): inserts a single row into a table without committing the transaction 668 - @ref SqlUtil::AbstractTable::insertCommit(): inserts a single row into a table and commits the transaction 669 - @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 670 - @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 672 @see @ref sql_upsert for information about upserting or merging data 674 @subsection inserting_data_explicitly Inserting Data Explicitly 678 table.insert(("id": id, "name": name, "created": now_us())); 681 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. 683 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. 685 @subsection inserting_data_from_select Inserting Data From a Select Statement 689 int rows = table.insertFromSelect(("id", "name", "created"), source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER")))); 692 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. 694 The example above would generate a %Qore SQL command like the following: 696 return ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER")); 699 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. 701 @subsection inserting_data_from_iterator Inserting Data from an Iterator Source 703 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: 707 # get the rows to be inserted 708 list l = get_table_rows(); 709 # insert the data and commit after every 5000 rows 710 table.insertFromIterator(l.iterator(), ("commit_block": 5000)); 713 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". 715 @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 717 @section updating_data Updating Data
719 The following methods can be used to
update data:
721 - @ref
SqlUtil::AbstractTable::
updateCommit(): updates a single row and commits the transaction
728 The example above generates a %
Qore SQL command like the following on Oracle and PostgreSQL
for example:
730 return ds.vexec(
"update schema.table set permission_type = lower(permission_type) || '-migrated'); 732 And the following on MySQL: 734 return ds.vexec("update schema.table
set permission_type = concat(lower(permission_type),
'-migrated'));
737 @section deleting_data Deleting Data
739 The following methods can be used to dekete data:
740 - @ref
SqlUtil::AbstractTable::del(): updates the table based on a @ref where_clauses
"where clause" and does not commit the transaction
741 - @ref
SqlUtil::AbstractTable::delCommit(): updates the table based on a @ref where_clauses
"where clause" and commits the transaction
742 - @ref
SqlUtil::AbstractTable::truncate(): truncates the table and does not commit the transaction
743 - @ref
SqlUtil::AbstractTable::truncateCommit(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
747 int dcnt = table.del((
"record_type":
"OLD-CUSTOMER"));
750 The above example would generate a %
Qore SQL command like the following:
752 return ds.vexec(
"delete from schema.table where record_type = %v", (
"OLD-CUSTOMER"));
757 See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
759 @section joins Joining Tables
761 Joining tables is made by providing a
join specification to the @ref select_option_join "
join select option" in
762 a @ref select_option_hash "select option
hash" as in the following example:
764 *
list rows = table.selectRows((
"columns": (
"table.id",
"t2.customer_name"),
"join":
join_inner(table2,
"t2", (
"id":
"altid"))));
766 In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
768 Joins on multiple tables are performed by combining the results of @ref sql_jop_funcs
"join functions" with the @ref plus_operator
"+ operator" 773 In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
774 automatically detected primary key to foreign key relationship between the two tables.
776 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
777 argument to the @ref sql_jop_funcs
"join function" as in the following example:
779 *
list rows = table.selectRows((
"join":
join_inner(table2,
"t2", (
"id":
"altid")) +
join_inner(
"t2", table3,
"t3")));
781 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
782 with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
784 @see @ref select_option_join
"join select option" 786 @section where_clauses Where Clauses
788 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:
807 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:
808 - use the @ref
SqlUtil::wop_or() function to combine where expressions with the \c "or" operator
809 - 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".
811 The where condition
hash has the following format:
812 - each key gives a column
name or a table/alias with column
name in dot notation
813 - 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
815 @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
817 See @ref sql_op_funcs
for a
list of
operator functions.
819 @par Where
Hash Example:
823 "account_type":
op_like(
"%CUSTOMER%"),
827 The preceding example results in a where clause equivalent to: \c
"name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
828 that bind by value is used, so,
if used in a context like the following:
830 Table t(
ds,
"table");
831 *
hash qh = t.select((
"where": w));
833 the complete query would look instead as follows:
835 ds.vselect(
"select * from table where name = %v and account_type like %v and id >= %v", (
"Smith",
"%CUSTOMER%", 500));
839 @par Where
List Example:
843 "account_type":
op_like(
"%CUSTOMER%"),
848 "account_type":
op_like(
"%VENDOR%"),
851 Table t(
ds,
"table");
852 *
hash qh = t.select((
"where": (w1, w2)));
854 the complete query would look instead as follows:
856 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));
860 Find a single row in the table where the \c
"permission_type" column is a value between \c
"US" and \c
"UX":\n
862 *
hash row = table.findSingle((
"permission_type":
op_between(
"US",
"UX")));
864 resulting in an
internal SQL command that looks as follows (depending on the database):
866 *
hash row =
ds.vselectRow(
"select * from table where permission_type between %v and %v limit %v", (
"US",
"UX", 1));
868 Delete all rows in the table where the \c
"name" column is like \c
"%Smith%":\n
870 int row_count = table.del((
"name":
op_like(
"%Smith%")));
872 resulting in an
internal SQL command that looks as follows:
874 ds.vexec(
"delete from table where name like %v", (
"%Smith%"));
876 Find all rows where \c
"id" is greater than \c 100 and \c
"created" is after \c 2013-03-01:\n
878 *
list rows = table.findAll((
"id":
op_gt(100),
"created":
op_gt(2013-03-01)));
880 resulting in an
internal SQL command that looks as follows:
882 ds.vexec(
"select * from table where id > %v and created > %v", (100, 2013-03-01));
885 @section sql_upsert Upserting or Merging Data
887 This module offers a high-level api
for "upserting" or merging data from one table into another table through the following methods:
897 @subsection sql_upsert_single Upsert a Single Row
901 table.upsert((
"id":
id,
"name":
name,
"account_type": account_type));
905 single row to be upserted or merged as a
hash as in the preceding example.
907 @subsection sql_upsert_many Upserting Many Rows Using An Upsert
Closure 913 # get the rows to be inserted 914 list l = get_table_rows();
917 code
upsert = table.getUpsertClosure(l[0]);
919 on_success
ds.commit();
920 on_error
ds.rollback();
922 # loop through the reference data rows 927 @par Complex Example With Callbacks:
929 # set the upsert strategy depending on the use case 932 # hash summarizing changes 935 # get the rows to be inserted 936 list l = get_table_rows();
939 # get the upsert closure to use based on the first row to be inserted 940 code upsert = table.getUpsertClosure(l[0], upsert_strategy);
942 on_success
ds.commit();
943 on_error
ds.rollback();
945 # loop through the reference data rows 946 foreach hash h in (l) {
958 else if (verbose > 1)
959 printf(
"*** reference data %s: %y: %s\n", table.getName(), h, change);
964 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
966 printf(
"*** reference data %s: OK\n", table.getName());
970 @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
976 # get the rows to be inserted 977 list l = get_table_rows();
978 table.upsertFromIterator(l.iterator());
981 @par Complex Example With Callbacks:
983 # set the upsert strategy depending on the use case 986 # get the rows to be inserted 987 list l = get_table_rows();
989 code callback = sub (
string table_name,
hash row,
int result) {
994 printf(
"*** reference data %s: %y: %s\n", table_name, row, change);
997 hash sh = table.upsertFromIterator(l.iterator(), upsert_strategy,
False, (
"info_callback": callback,
"commit_block": 5000));
999 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
1001 printf(
"*** reference data %s: OK\n", table.getName());
1006 @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 1008 @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
1012 @par Simple Example:
1014 table.upsertFromSelect(table2, (
"where": (
"account_type":
"CUSTOMER")));
1017 @par Complex Example With Callbacks:
1019 # set the upsert strategy depending on the use case 1022 code callback = sub (
string table_name,
hash row,
int result) {
1027 printf(
"*** reference data %s: %y: %s\n", table_name, row, change);
1030 hash sh = table.upsertFromSelect(table2, (
"where": (
"account_type":
"CUSTOMER")), upsert_strategy, False, (
"info_callback": callback,
"commit_block": 5000));
1032 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
1034 printf(
"*** reference data %s: OK\n", table.getName());
1037 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).
1041 @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows 1043 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. 1045 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. 1047 @par Simple Example: 1049 # get the rows to be inserted 1050 list l = get_table_rows(); 1051 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000)); 1054 @par Complex Example With Callbacks: 1056 # set the upsert strategy depending on the use case 1057 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto; 1059 # get the rows to be inserted 1060 list l = get_table_rows(); 1062 code callback = sub (string table_name, hash row, int result) { 1063 if (result == AbstractTable::UR_Unchanged) 1065 string change = AbstractTable::UpsertResultMap{result}; 1067 printf("*** reference data %s: %y: %s\n", table_name, row, change); 1070 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, ("delete_others": True, "info_callback": callback, "commit_block": 5000)); 1072 printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator()))); 1074 printf("*** reference data %s: OK\n", table.getName()); 1077 @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 1079 @subsection sql_upsert_strategies Upsert Strategies
1080 The approach used is based on one of the following strategies (see @ref upsert_options):
1081 - @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
1085 - @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 1086 - @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 1088 @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.
2410 "code":
string (
string cve,
string arg, reference<hash> psch) {
2412 return sprintf(
"%s as %s", cve, arg);
2418 "code":
string (
string cve,
string arg) {
2419 return sprintf(
"%s || %s", arg, cve);
2425 "code":
string (
string cve,
string arg) {
2426 return sprintf(
"%s || %s", cve, arg);
2432 "code":
string (*
string cve,
auto arg) {
2437 "code":
string (
string cve,
auto arg) {
2438 return sprintf(
"upper(%s)", cve);
2442 "code":
string (
string cve,
auto arg) {
2443 return sprintf(
"lower(%s)", cve);
2447 "code":
string (
string cve,
auto arg) {
2448 return sprintf(
"distinct %s", cve);
2452 "code":
string (
string cve,
auto arg) {
2453 return sprintf(
"min(%s)", cve);
2458 "code":
string (
string cve,
auto arg) {
2459 return sprintf(
"max(%s)", cve);
2464 "code":
string (
string cve,
auto arg) {
2465 return sprintf(
"avg(%s)", cve);
2470 "code":
string (
string cve,
auto arg) {
2471 return sprintf(
"sum(%s)", cve);
2477 "code":
string (*
string cve,
auto arg) {
2478 return sprintf(
"count(%s)", cve ? cve :
"*");
2483 "code":
string (
string arg1,
string arg2) {
2484 return sprintf(
"%s - %s", arg1, arg2);
2489 "code":
string (
string arg1,
string arg2) {
2490 return sprintf(
"%s + %s", arg1, arg2);
2495 "code":
string (
string arg1,
string arg2) {
2496 return sprintf(
"%s / %s", arg1, arg2);
2501 "code":
string (
string arg1,
string arg2) {
2502 return sprintf(
"%s * %s", arg1, arg2);
2507 "code":
string (*
string cve,
hash arg) {
2508 throw "SEQUENCE-ERROR",
sprintf(
"cannot select sequence %y because this database does not support sequences", arg.seq);
2513 "code":
string (*
string cve,
hash arg) {
2514 throw "SEQUENCE-ERROR",
sprintf(
"cannot select the current value of sequence %y because this database does not support sequences", arg.seq);
2519 "code":
string (*
string cve,
hash arg) {
2520 return sprintf(
"coalesce(%s)", (foldl $1 +
"," + $2, arg.args));
2524 "code":
string (
string cve,
list args) {
2526 return sprintf(
"substring(%s from %d)", cve, args[0]);
2527 return sprintf(
"substring(%s from %d for %d)", cve, args[0], args[1]);
2531 "code":
string (
string cve,
auto arg) {
2532 return sprintf(
"length(%s)", cve);
2536 "columnargs" :
True,
2537 "columnargs_ignore_nothings" :
True,
2538 "code":
string (*
string cve,
hash args)
2540 *
string partitionby = args.args[0];
2541 *
string orderby = args.args[1];
2544 string sql = cve +
" over (";
2546 sql +=
sprintf(
"partition by %s", partitionby);
2548 sql +=
sprintf(
" order by %s", orderby);
2555 "code":
string (*
string cve, any arg) {
2556 return "cume_dist()";
2561 "code":
string (*
string cve, any arg) {
2562 return "dense_rank()";
2566 "code":
string (
string cve) {
2567 return sprintf(
"first_value(%s)", cve);
2571 "code":
string (
string cve) {
2572 return sprintf(
"last_value(%s)", cve);
2578 "code":
string (*
string cve, any arg) {
2579 return sprintf(
"ntile(%d)", arg);
2584 "code":
string (*
string cve, any arg) {
2585 return "percent_rank()";
2590 "code":
string (*
string cve, any arg) {
2596 "code":
string (*
string cve, any arg) {
2597 return "row_number()";
2653 hash<ColumnOperatorInfo>
make_cop(
string cop,
auto column,
auto arg);
2669 hash<ColumnOperatorInfo>
cop_as(
auto column,
string arg);
2687 hash<ColumnOperatorInfo>
cop_cast(
auto column,
string arg,
auto arg1,
auto arg2);
2701 hash<ColumnOperatorInfo>
cop_prepend(
auto column,
string arg);
2715 hash<ColumnOperatorInfo>
cop_append(
auto column,
string arg);
2847 hash<ColumnOperatorInfo>
cop_value(
auto arg);
2860 hash<ColumnOperatorInfo>
cop_upper(
auto column);
2873 hash<ColumnOperatorInfo>
cop_lower(
auto column);
2899 hash<ColumnOperatorInfo>
cop_min(
auto column);
2912 hash<ColumnOperatorInfo>
cop_max(
auto column);
2925 hash<ColumnOperatorInfo>
cop_avg(
auto column);
2938 hash<ColumnOperatorInfo>
cop_sum(
auto column);
2949 hash<ColumnOperatorInfo>
cop_count(
auto column =
"");
2960 hash<ColumnOperatorInfo>
cop_over(
auto column, *
string partitionby, *
string orderby);
2974 hash<ColumnOperatorInfo>
cop_minus(
auto column1,
auto column2);
2988 hash<ColumnOperatorInfo>
cop_plus(
auto column1,
auto column2);
3002 hash<ColumnOperatorInfo>
cop_divide(
auto column1,
auto column2);
3016 hash<ColumnOperatorInfo>
cop_multiply(
auto column1,
auto column2);
3029 hash<ColumnOperatorInfo>
cop_year(
auto column);
3082 hash<ColumnOperatorInfo>
cop_seq(
string seq, *
string as);
3112 hash<ColumnOperatorInfo>
cop_coalesce(
auto col1,
auto col2);
3127 hash<ColumnOperatorInfo>
cop_substr(
auto column,
int start, *
int count);
3142 hash<ColumnOperatorInfo>
cop_length(
auto column);
3160 hash<ColumnOperatorInfo>
cop_trunc_date(
auto column,
string mask);
3323 hash<ColumnOperatorInfo>
cop_ntile(
int value);
3387 hash<ColumnOperatorInfo>
cop_rank();
3508 "code":
string (
string cve,
auto arg) {
3509 return sprintf(
"%s - %s", cve, arg);
3514 "code":
string (
string cve,
auto arg) {
3515 return sprintf(
"%s + %s", cve, arg);
3520 "code":
string (
string cve,
auto arg) {
3521 return sprintf(
"%s / %s", cve, arg);
3526 "code":
string (
string cve,
auto arg) {
3527 return sprintf(
"%s * %s", cve, arg);
3533 "code":
string (*
string cve,
string arg) {
3534 throw "SEQUENCE-ERROR",
sprintf(
"cannot select sequence %y because this database does not support sequences", arg);
3539 "code":
string (*
string cve,
string arg) {
3540 throw "SEQUENCE-ERROR",
sprintf(
"cannot select the current value of sequence %y because this database does not support sequences", arg);
3545 "code":
string (*
string cve, softlist args) {
3546 return sprintf(
"coalesce(%s)", (foldl $1 +
"," + $2, args));
3582 hash<UpdateOperatorInfo>
make_uop(
string uop,
auto arg, *hash<UpdateOperatorInfo> nest);
3596 hash<UpdateOperatorInfo>
uop_prepend(
string arg, *hash<UpdateOperatorInfo> nest);
3610 hash<UpdateOperatorInfo>
uop_append(
string arg, *hash<UpdateOperatorInfo> nest);
3623 hash<UpdateOperatorInfo>
uop_upper(*hash<UpdateOperatorInfo> nest);
3636 hash<UpdateOperatorInfo>
uop_lower(*hash<UpdateOperatorInfo> nest);
3651 hash<UpdateOperatorInfo>
uop_substr(
int start, *
int count, *hash<UpdateOperatorInfo> nest);
3665 hash<UpdateOperatorInfo>
uop_plus(
auto arg, *hash<UpdateOperatorInfo> nest);
3679 hash<UpdateOperatorInfo>
uop_minus(
auto arg, *hash<UpdateOperatorInfo> nest);
3693 hash<UpdateOperatorInfo>
uop_multiply(
auto arg, *hash<UpdateOperatorInfo> nest);
3707 hash<UpdateOperatorInfo>
uop_divide(
auto arg, *hash<UpdateOperatorInfo> nest);
3720 hash<UpdateOperatorInfo>
uop_seq(
string seq);
3787 hash<string, hash<JoinOperatorInfo>>
make_jop(
string jop,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
string ta, *
hash opt);
3856 hash<string, hash<JoinOperatorInfo>>
join_inner(
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
3932 hash<string, hash<JoinOperatorInfo>>
join_inner_alias(
string ta,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4003 hash<string, hash<JoinOperatorInfo>>
join_left(
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4077 hash<string, hash<JoinOperatorInfo>>
join_left_alias(
string ta,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4148 hash<string, hash<JoinOperatorInfo>>
join_right(
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4222 hash<string, hash<JoinOperatorInfo>>
join_right_alias(
string ta,
string table_name, *
string alias, *
hash jcols, *
hash cond, *
hash opt);
4321 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4323 return sprintf(
"%s like %v", cn);
4327 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4329 return sprintf(
"%s < %v", cn);
4333 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4335 return sprintf(
"%s <= %v", cn);
4339 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4341 return sprintf(
"%s > %v", cn);
4345 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4347 return sprintf(
"%s >= %v", cn);
4351 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4353 return sprintf(
"%s is not null", cn);
4355 return sprintf(
"(%s != %v or %s is null)", cn, cn);
4359 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4361 return sprintf(
"%s is null", cn);
4363 return sprintf(
"%s = %v", cn);
4367 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4370 return sprintf(
"%s between %v and %v", cn);
4374 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4375 *
string ins = (foldl $1 +
"," + $2, (map t.getSqlValue($1), arg));
4376 return exists ins ?
sprintf(
"%s in (%s)", cn, ins) :
"1 != 1";
4381 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4382 return sprintf(
"not (%s)", cn);
4387 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4388 return sprintf(
"%s < %s", cn, arg);
4393 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4394 return sprintf(
"%s <= %s", cn, arg);
4399 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4400 return sprintf(
"%s > %s", cn, arg);
4405 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4406 return sprintf(
"%s >= %s", cn, arg);
4411 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4412 return sprintf(
"%s != %s", cn, arg);
4417 "code":
string (
object t,
string cn,
string arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4418 return sprintf(
"%s = %s", cn, arg);
4422 "code":
string (
object t,
string cn,
auto arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4428 return sprintf(
"substring(%s from %v for %v) = %v", cn);
4432 "code":
string (
object t,
string cn,
list arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
4433 return t.getOrClause(arg, \args, jch,
join, ch, psch);
4461 hash<OperatorInfo>
make_op(
string op,
auto arg);
4475 hash<OperatorInfo>
op_like(
string str);
4490 hash<OperatorInfo>
op_lt(
auto arg);
4505 hash<OperatorInfo>
op_le(
auto arg);
4520 hash<OperatorInfo>
op_gt(
auto arg);
4535 hash<OperatorInfo>
op_ge(
auto arg);
4552 hash<OperatorInfo>
op_ne(
auto arg);
4569 hash<OperatorInfo>
op_eq(
auto arg);
4585 hash<OperatorInfo>
op_between(
auto l,
auto r);
4598 hash<OperatorInfo>
op_in();
4639 hash<OperatorInfo>
op_clt(
string arg);
4654 hash<OperatorInfo>
op_cle(
string arg);
4669 hash<OperatorInfo>
op_cgt(
string arg);
4684 hash<OperatorInfo>
op_cge(
string arg);
4699 hash<OperatorInfo>
op_cne(
string arg);
4714 hash<OperatorInfo>
op_ceq(
string arg);
4729 hash<OperatorInfo>
op_substr(
int start, *
int count,
string text);
4743 hash<OperatorInfo>
op_substr(
int start,
string text);
4801 hash<InsertOperatorInfo>
make_iop(
string iop,
auto arg);
4814 hash<InsertOperatorInfo>
iop_seq(
string arg);
4881 auto memberGate(
string k);
4895 abstract auto take(
string k);
4898 renameKey(
string old_name,
string new_name);
4915 bool matchKeys(
hash h1);
4928 bool matchKeys(
list l);
4954 bool partialMatchKeys(
hash h1);
4967 bool partialMatchKeys(
list l);
5004 list<string> keys();
5076 bool hasKey(
string k);
5089 bool hasKeyValue(
string k);
5119 abstract string getElementName();
5151 abstract auto get(softint i);
5205 abstract string getElementName();
5231 add(
string k,
Table val);
5251 populate(AbstractDatasource ds,
hash tables, *
hash opt);
5255 populate(AbstractDatasource ds);
5273 *
list getDropAllForeignConstraintsOnTableSql(
string name, *
hash opt);
5296 string getElementName();
5300 *
AbstractTable getIfExists(AbstractDatasource ds,
string name);
5323 *
string getRenameTableIfExistsSql(
string old_name,
string new_name, *
hash opts);
5338 bool tableRenamed(
string old_name,
string new_name,
string old_sql_name);
5343 tableRenamedIntern(
string old_name,
string new_name,
string oldsn);
5366 list getCreateList();
5397 getDependencies(reference<hash> tdh, reference<hash> sdh, *reference<hash> th);
5446 string getElementName();
5482 constructor(
string n,
string nt, *
string qt,
int sz,
bool nul, *
string dv, *
string c);
5486 string getNativeTypeString();
5583 string getNativeTypeString(
string native_type,
int precision);
5629 string getElementName();
5664 bool hasColumn(
string cname);
5686 abstract string getRenameSql(
string table_name,
string new_name);
5693 setSupportingConstraint();
5701 list getRecreateSql(AbstractDatasource
ds,
string table_name, *
hash opt);
5743 string getElementName();
5784 string getDisableSql(
string table_name);
5788 string getEnableSql(
string table_name, *
hash opt);
5802 abstract bool setIndexBase(
string ix);
5805 abstract clearIndex();
5808 bool hasColumn(
string cname);
5834 bool setIndexBase(
string ix);
5872 hash getDisableReenableSql(AbstractDatasource
ds,
string table_name, *
hash opts);
5894 removeSourceConstraint(
string tname,
list cols);
5898 renameSourceConstraintTable(
string old_name,
string new_name);
5902 bool hasColumn(
string cname);
5917 bool setIndexBase(
string ix);
5987 *
hash findConstraintOn(
string table, softlist cols);
5991 string getElementName();
6137 constructor(
string n,
string n_type,
string n_src);
6170 constructor(
string n,
string n_type,
string n_src) ;
6183 setName(
string new_name);
6221 string getElementName();
6237 abstract softlist
getRenameSql(
string table_name,
string new_name);
6277 string getElementName();
6357 any methodGate(
string meth);
6389 static string makeDatasourceDesc(AbstractDatasource ds);
6393 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt,
string tag);
6399 static validateOptionIntern(
string err,
string type, reference opt,
string k,
string tag);
6432 const DatabaseOptions = (
6441 "table_cache":
"Tables",
6450 const CallbackOptions = (
6451 "info_callback":
"code",
6452 "sql_callback":
"code",
6464 const AC_Unchanged = 0;
6468 const AC_Create = 1;
6474 const AC_Rename = 3;
6477 const AC_Modify = 4;
6480 const AC_Truncate = 5;
6486 const AC_Recreate = 7;
6489 const AC_Insert = 8;
6492 const AC_Update = 9;
6495 const AC_Delete = 10;
6498 const AC_NotFound = 11;
6503 AC_Unchanged:
"unchanged",
6504 AC_Create:
"create",
6506 AC_Rename:
"rename",
6507 AC_Modify:
"modify",
6508 AC_Truncate:
"truncate",
6510 AC_Recreate:
"recreate",
6511 AC_Insert:
"insert",
6512 AC_Update:
"update",
6513 AC_Delete:
"delete",
6514 AC_NotFound:
"not found",
6518 const ActionDescMap = (
6519 "unchanged": AC_Unchanged,
6520 "create": AC_Create,
6522 "rename": AC_Rename,
6523 "modify": AC_Modify,
6524 "truncate": AC_Truncate,
6526 "recreate": AC_Recreate,
6527 "insert": AC_Insert,
6528 "update": AC_Update,
6529 "delete": AC_Delete,
6530 "not found": AC_NotFound,
6534 const ActionLetterMap = (
6556 const CreationOptions = CallbackOptions + (
6558 "table_cache":
"Tables",
6567 const AlignSchemaOptions = CreationOptions + (
6575 const DropSchemaOptions = CallbackOptions + (
6592 const SchemaDescriptionOptions = (
6615 const SequenceDescriptionOptions = (
6622 const ComputeStatisticsOptions = (
6623 "tables" :
"softstringlist",
6627 const ReclaimSpaceOptions = (
6628 "tables" :
"softstringlist",
6655 static doOkCallback(*
hash opt,
int ac,
string type,
string name, *
string table, *
string info);
6657 static *
string doCallback(*
hash opt, *
string sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
6659 static list doCallback(*
hash opt,
list sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
6764 list dropSqlUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
6770 list alignCodeUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
6855 bool dropFunctionIfExists(
string name, *
hash opt);
6871 bool dropProcedureIfExists(
string name, *
hash opt);
6887 bool dropSequenceIfExists(
string name, *
hash opt);
6903 bool dropViewIfExists(
string name, *
hash opt);
6919 bool dropTableIfExists(
string name, *
hash opt);
6935 *
string getDropFunctionSqlIfExists(
string name, *
hash opt);
6951 *
string getDropProcedureSqlIfExists(
string name, *
hash opt);
6967 *
string getDropSequenceSqlIfExists(
string name, *
hash opt);
6986 doDropSql(*softlist l,
string type,
string name, *
hash opt);
6989 bool doDrop(*softlist l,
string type,
string name, *
hash opt);
7103 int getNextSequenceValue(
string name);
7116 int getCurrentSequenceValue(
string name);
7133 bool supportsSequences();
7137 bool supportsTypes();
7141 bool supportsPackages();
7153 list listFunctions();
7161 list listProcedures();
7169 list listSequences();
7195 bool rebuildIndex(
string name, *
hash options);
7218 computeStatistics(*
hash options);
7229 reclaimSpace(*
hash options);
7234 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt);
7240 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt,
string tag);
7250 static checkDriverOptions(reference<hash> h,
string drv);
7255 hash getDatabaseOptions();
7262 hash getCallbackOptions();
7269 hash getCreationOptions();
7283 hash getAlignSchemaOptions();
7290 hash getDropSchemaOptions();
7297 hash getSchemaDescriptionOptions();
7304 hash getSequenceDescriptionOptions();
7311 hash getRebuildIndexOptions();
7318 hash getComputeStatisticsOptions();
7325 hash getReclaimSpaceOptions();
7345 abstract string getCreateSqlImpl(
list l);
7349 abstract list getAlignSqlImpl(
hash schema_hash, *
hash opt);
7353 abstract list getDropSchemaSqlImpl(
hash schema_hash, *
hash opt);
7388 abstract list featuresImpl();
7392 abstract list listTablesImpl();
7396 abstract list listFunctionsImpl();
7400 abstract list listProceduresImpl();
7404 abstract list listSequencesImpl();
7408 abstract list listViewsImpl();
7414 abstract int getNextSequenceValueImpl(
string name);
7419 abstract int getCurrentSequenceValueImpl(
string name);
7425 abstract bool supportsSequencesImpl();
7429 abstract bool supportsPackagesImpl();
7433 abstract bool supportsTypesImpl();
7438 abstract bool rebuildIndexImpl(
string name, *
hash options);
7442 abstract computeStatisticsImpl(*
hash options);
7446 abstract reclaimSpaceImpl(*
hash options);
7551 any methodGate(
string meth);
7570 "table_cache":
"Tables",
7590 "table_cache":
"Tables",
7598 "table_cache":
"Tables",
7614 "where":
"hash/list",
7615 "orderby":
"softstringinthashlist",
7620 "groupby":
"softstringinthashlist",
7629 "foreign_constraints":
True,
7638 "omit":
"softstringlist",
7655 "db_table_cache":
"Tables",
7679 "table_cache":
"Tables",
7724 "sqlarg_callback":
"code",
7725 "tablecode":
"code",
7739 "returning":
"stringhashlist",
7750 "info_callback":
"code",
7753 "omit_update":
"softstringlist",
7762 "info_callback":
"code",
7963 doTableOptions(*
hash nopts);
8178 rename(
string new_name, *reference<string> sql, *
Tables table_cache);
8183 doRenameIntern(
string new_name, *
Tables table_cache);
8217 bool emptyUnlocked();
8294 AbstractColumn addColumnUnlocked(
string cname,
hash opt,
bool nullable = True, *reference lsql,
bool do_exec = True,
bool modify_table = True);
8415 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt);
8421 validateOptionsIntern(
string err,
hash ropt, reference<hash> opt,
string tag);
8427 execSql(softlist lsql);
8489 AbstractPrimaryKey addPrimaryKeyUnlocked(
string pkname, softlist cols, *
hash opt, *reference<string> sql);
8495 AbstractPrimaryKey addPrimaryKeyUnlockedIntern(
string pkname, softlist cols, *
hash opt, *reference<string> sql);
8521 list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(
string cname, *
hash opt);
8683 AbstractIndex addIndexUnlocked(
string iname,
bool unique, softlist cols, *
hash opt, *reference<string> sql);
8689 AbstractIndex addIndexUnlockedIntern(
string iname,
bool unique, softlist cols, *
hash opt, *reference<string> sql);
8808 Columns getReferencedTableColumnsUnlocked(
string table, *
Tables cache,
string err =
"FOREIGN-CONSTRAINT-ERROR");
8814 AbstractForeignConstraint addForeignConstraintUnlocked(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference<string> sql);
8820 AbstractForeignConstraint addForeignConstraintUnlockedIntern(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference<string> sql);
9075 AbstractTrigger addTriggerUnlockedIntern(
string tname,
string src, *
hash opt, *reference lsql);
9126 getAllConstraintsUnlocked(*
hash opt);
9132 checkUniqueConstraintName(
string err,
string cname);
9138 checkUniqueConstraintNameValidateOptions(
string err,
string cname,
hash ropt, reference<hash> opt);
9261 *
hash insertIntern(
hash row, *reference<string> sql, *
hash opt);
9267 hash getPlaceholdersAndValues(
hash row);
9948 string getSelectSqlIntern(*
hash qh, reference<list> args, *
hash opt);
9951 string getSelectSqlUnlocked(*
hash qh, reference<list> args, *
hash opt);
9955 string getSelectSqlUnlockedIntern(*
hash qh,
string from, reference<list> args, *
hash ch, *
hash opt);
9960 string getFromIntern(
string from, *
hash qh);
9984 doForUpdate(reference<string> sql);
9990 string getSelectSqlName(*
hash qh);
9996 string getColumnExpressionIntern(
auto cvc, *
hash jch,
bool join, *
hash ch, *
hash psch);
10002 string doColumnOperatorIntern(
hash cvc, *
hash jch,
bool join, *
hash ch, *
hash psch, *reference psch_ref);
10008 string doColumnOperatorIntern(
auto cop,
auto arg, *
string cve,
hash cm, *
hash jch,
bool join, *
hash ch, *
hash psch, *reference psch_ref);
10014 string getColumnNameIntern(
string cv, *
hash jch,
bool join, *
hash ch, *
hash psch);
10027 getSelectWhereSqlUnlocked(reference<string> sql, reference<list> args, *
hash qh, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10033 *
string getWhereClause(*
hash cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False);
10039 *
string getWhereClause(
list cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False);
10045 *
string getWhereClauseUnlocked(
list cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch, *
hash psch);
10051 *
string getWhereClauseUnlocked(*
hash cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch, *
hash psch);
10057 *
list getWhereClauseIntern(*
hash cond, reference<list> args, *
string cprefix, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10063 string doWhereExpressionIntern(
string cn,
auto we, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10067 string getOrClause(
list arglist, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10070 string getOrClause(
hash arg, reference<list> args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
10075 doSelectOrderBySqlUnlocked(reference<string> sql, reference<list> args, *
hash qh, *
hash jch, *
hash ch, *
hash psch,
list coll);
10130 int del(
hash cond, reference<string> sql,
hash opt);
10138 int del(
hash cond, reference<string> sql);
10154 int delIntern(*
hash cond, *reference<string> sql, *
hash opt);
10240 int updateIntern(
hash set, *
hash cond, *reference<string> sql, *
hash opt);
10246 string getUpdateExpression(
string col, hash<UpdateOperatorInfo> uh);
10252 bool emptyDataIntern();
10258 Columns checkUpsertRow(
hash row, reference<int> upsert_strategy);
10264 code getUpsertInsertFirst(
Columns cols,
hash example_row, *
hash opt);
10270 code getUpsertUpdateFirst(
Columns cols,
hash example_row, *
hash opt);
10276 code getUpsertSelectFirst(
Columns cols,
hash example_row, *
hash opt);
10294 Columns getUpsertColumns(reference csrc);
10300 string getUpsertSelectSql(
hash row,
Columns cols, reference<list<string>> updc);
10306 string getUpsertInsertSql(
hash row);
10312 string getUpsertUpdateSql(
hash row,
Columns cols, reference updc, *
hash opt);
10324 checkValue(
string cname,
string argname, reference val,
string type);
10526 *
hash getCheckOmissionOptions(*softlist ol,
string err);
10712 string getPrimaryKeyColumn();
11009 string getCreateTableSqlUnlocked(*
hash opt);
11015 *
list getCreateIndexesSqlUnlocked(*
hash opt,
bool cache = True);
11021 *
string getCreatePrimaryKeySqlUnlocked(*
hash opt,
bool cache = True);
11027 *
list getCreateConstraintsSqlUnlocked(*
hash opt,
bool cache = True);
11033 *
list getCreateForeignConstraintsSqlUnlocked(*
hash opt,
bool cache = True);
11039 *
list getCreateMiscSqlUnlocked(*
hash opt,
bool cache = True);
11045 *
list getCreateTriggersSqlUnlocked(*
hash opt,
bool cache = True);
11057 cacheUnlocked(*
hash opt);
11063 auto execData(*
hash opt,
string sql, *
list args);
11069 execData(SQLStatement stmt, *
hash opt, *
list args);
11081 getColumnsUnlocked();
11087 getPrimaryKeyUnlocked();
11094 getIndexesUnlocked();
11100 getForeignConstraintsUnlocked(*
hash opt);
11112 getConstraintsUnlocked();
11118 getTriggersUnlocked();
11131 softlist getDropSqlImpl();
11137 string getTruncateSqlImpl();
11164 preSetupTableImpl(reference desc, *
hash opt);
11170 abstract *
hash doReturningImpl(
hash opt, reference<string> sql,
list args);
11175 abstract bool emptyImpl();
11213 abstract setupTableImpl(
hash desc, *
hash opt);
11218 abstract Columns describeImpl();
11226 abstract Indexes getIndexesImpl();
11238 abstract Triggers getTriggersImpl();
11243 abstract string getCreateTableSqlImpl(*
hash opt);
11247 abstract *
list getCreateMiscSqlImpl(*
hash opt,
bool cache);
11251 abstract string getCreateSqlImpl(
list l);
11255 abstract string getRenameSqlImpl(
string new_name);
11264 abstract AbstractColumn addColumnImpl(
string cname,
hash opt,
bool nullable = True);
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5757
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:7609
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:6044
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2315
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2120
any column
column sopecifier, may be a string or a complex hash
Definition: SqlUtil.qm.dox.h:2107
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:7811
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:4785
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:5123
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:7627
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:2079
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:2106
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:4303
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:7559
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2406
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:2166
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:7597
const COP_FIRST_VALUE
Analytic (window) function: FIRST_VALUE.
Definition: SqlUtil.qm.dox.h:2367
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:7716
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:5215
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:6092
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:7895
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:7830
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:2112
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:7857
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:4298
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:5651
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:2114
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:5634
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4316
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:2270
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:5949
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:7886
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:7869
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:7761
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:2360
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:4258
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:2260
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:6122
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:5996
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:5466
const COP_SEQ_CURRVAL
to return the last value of a sequence issued in the same session
Definition: SqlUtil.qm.dox.h:2320
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:5570
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:3759
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:2189
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4248
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2172
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2255
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:2150
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:2144
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3751
base class for sequences
Definition: SqlUtil.qm.dox.h:6039
*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:2374
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:5472
abstract hash getQoreTypeMapImpl()
returns the qore type -> column type map
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2101
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:7749
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2240
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:2310
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:7589
*hash opt
optional join options (for example, to specify a partition for the join if supported) ...
Definition: SqlUtil.qm.dox.h:2132
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:7915
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:7921
*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:2127
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:2126
const IOP_SEQ_CURRVAL
for using the last value of a sequence issued in the current session
Definition: SqlUtil.qm.dox.h:4782
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:6362
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:7795
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:4288
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:6292
const SqlUtilDrivers
known drivers
Definition: SqlUtil.qm.dox.h:4832
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4278
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:6018
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:6023
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:5575
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:5813
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:2265
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:4293
const COP_NTILE
Analytic (window) function: NTILE.
Definition: SqlUtil.qm.dox.h:2381
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:2083
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4841
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:2125
any default_value
the default value for the column
Definition: SqlUtil.qm.dox.h:2085
the SqlUtil namespace contains all the objects in the SqlUtil module
Definition: SqlUtil.qm.dox.h:2073
bool empty()
returns True if the table has no definitions, False if not
string name
the table's name
Definition: SqlUtil.qm.dox.h:7907
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:6244
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:2108
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:5818
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:7913
const DT_DAY
Format unit: day.
Definition: SqlUtil.qm.dox.h:3481
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:2146
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:2230
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.
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:2130
const COP_PLUS
the SQL "plus" operator
Definition: SqlUtil.qm.dox.h:2280
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7860
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:4253
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:5588
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2195
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:7568
*bool auto_increment
True for DBs that support an auto-increment column
Definition: SqlUtil.qm.dox.h:2095
*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:2158
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:5475
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:7911
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:2325
string op
the operator string code
Definition: SqlUtil.qm.dox.h:2100
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:7925
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:7650
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:7919
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:2148
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:6556
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4263
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:2075
int del()
SqlUtil::AbstractTable::del() variant
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:5478
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:6089
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:5642
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:2300
string src
the source of the object
Definition: SqlUtil.qm.dox.h:6128
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:2250
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:2337
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:2205
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:7909
*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:2156
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:4243
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2175
string name
the name of the index
Definition: SqlUtil.qm.dox.h:5639
string _iop
the insert operator string code
Definition: SqlUtil.qm.dox.h:2113
*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:6004
string uop
the update operator string code
Definition: SqlUtil.qm.dox.h:2119
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:4273
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5843
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:2152
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:2178
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4308
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:5645
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:7723
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:6117
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:2154
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:2118
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:2353
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:7875
string name
the name of the column
Definition: SqlUtil.qm.dox.h:5460
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:6367
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:6162
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:2290
column operator info hash as returned by all column operator functions
Definition: SqlUtil.qm.dox.h:2105
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:7917
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:2215
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:2346
*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:6078
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:6373
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:7738
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:7604
*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:6125
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:2295
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:5469
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:2093
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:5463
const COP_VALUE
to append a constant value (SQL Literal) to use as an output column value
Definition: SqlUtil.qm.dox.h:2225
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:7825
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:5403
the base class for triggers
Definition: SqlUtil.qm.dox.h:6226
*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:2131
*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:4238
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:6369
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:6188
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:7866
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:7863
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6297
the base class for column information
Definition: SqlUtil.qm.dox.h:5455
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:2210
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:7818
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4283
const DT_MINUTE
Format unit: minute.
Definition: SqlUtil.qm.dox.h:3487
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:3484
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:7467
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:7578
*string comment
an optional comment for the column
Definition: SqlUtil.qm.dox.h:2089
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:3501
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2245
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:7804
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:2305
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:7787
const DT_MONTH
Format unit: month.
Definition: SqlUtil.qm.dox.h:3478
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6086
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:2388
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:2129
*number max
the ending number
Definition: SqlUtil.qm.dox.h:6053
hash getUpdateOperatorMap()
returns the update operator map for this object
const COP_RANK
Analytic (window) function: RANK.
Definition: SqlUtil.qm.dox.h:2395
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:7695
number increment
the increment
Definition: SqlUtil.qm.dox.h:6050
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:4233
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:7671
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2186
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:7472
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:4268
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2275
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:6001
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:7637
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:2128
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2330
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:3756
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:4313
*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:2192
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:2081
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:2099
number start
the starting number
Definition: SqlUtil.qm.dox.h:6047
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4777
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:6424
const COP_ROW_NUMBER
Analytic (window) function: ROW_NUMBER.
Definition: SqlUtil.qm.dox.h:2402
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:3475
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:5851
represents a primary key
Definition: SqlUtil.qm.dox.h:5938
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3746
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2235
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:2121
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:2285
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:2142
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2169
*hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:5848
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:7842
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:2077
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:7586
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:4319
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5929
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:7711
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:5748
const DT_SECOND
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3490
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:5706
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2220