345 @warning Oracle:
using different comments in the
same SQL can lead to
new optimizer statement hard parsing.
347 @anchor select_option_hint
348 @par Select Option
"hint"
349 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).
353 table.selectRows( (
"hint" :
"full(t1)") );
355 will produce select statement like
this:
359 The
string is taken as is and it
's up to user to handle correct aliases in join functions etc.
360 @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
361 @warning Use hints only when you know what you are doing.
363 @anchor select_option_columns
364 @par Select Option "columns"
365 <b>Columns Example:</b>
367 list columns = ("id", "name", "started", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"));
368 *list rows = table.selectRows(("columns": columns, "where": ("type": "user")));
370 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
371 This option takes a list, each element of the list can be one of the following.\n\n
372 <b>A Simple String Giving a Column Name</b>\n
375 *list rows = table.selectRows(("columns": ("id", "name", "started")));
377 <b>A String in Dot Notation</b>\n
378 This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
380 *list rows = table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner(table2, "t2", ("id": "altid"))));
382 <b>A Column Operation Specified by a Column Operator Function</b>\n
383 ex: <tt>cop_as("column_name", "column_alias")</tt> \n
384 See @ref sql_cop_funcs "column operator function" for more information on column operator functions
386 *list rows = table.selectRows(("columns": ("id", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"))));
388 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
389 <b>The Value \c "*", Meaning All Columns</b>\n
392 *list rows = table.selectRows(("columns": "*"));
394 This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
395 <b>An \c "*" in Dot Notation</b>\n
398 *list rows = table.selectRows(("columns": ("table.id", "t2.*"), "join": join_inner(table2, "t2", ("id": "altid"))));
401 @anchor select_option_where
402 @par Select Option "where"
403 <b>Where Example:</b>
405 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
407 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.
409 @anchor select_option_orderby
410 @par Select Option "orderby"
411 <b>Orderby Example:</b>
413 *list rows = table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date"));
415 This option is a list of the following values:
416 - a simple string giving a column name; ex: \c "name"
417 - 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
418 - 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"
419 - a positive integer giving the column number for the ordering
421 - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
423 @anchor select_option_desc
424 @par Select Option "desc"
427 *list rows = table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date", "desc": True));
429 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
430 Otherwise, ordered results are returned in ascending order by default.
432 @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"
434 @anchor select_option_limit
435 @par Select Option "limit"
436 <b>Limit Example:</b>
438 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
440 This option will limit the number of rows returned.
442 - This option is required if the @ref select_option_offset "offset option" is non-zero
443 - 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
445 @anchor select_option_offset
446 @par Select Option "offset"
447 <b>Offset Example:</b>
449 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
451 This option specifies the row number offset for the rows returned where the first row is at offset zero.
453 - 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.
454 - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
457 @anchor select_option_join
458 @par Select Option "join"
461 *list rows = table.selectRows(("columns": ("name", "version", "id", cop_as("st.value", "source"), cop_as("st.value", "offset")),
462 "join": join_left(function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
463 + join_left(function_instance_tags, "lt", NOTHING, ("st.tag": "_offset"))));
465 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).
466 @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
468 @see @ref joins for more examples
470 @anchor select_option_groupby
471 @par Select Option "groupby"
472 <b>Groupby Example:</b>
474 *list rows = table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type"));
476 The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
477 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"
478 key are strings giving column names, optionally in dot notation or positive column numbers.
480 @anchor select_option_having
481 @par Select Option "having"
482 <b>Having Example:</b>
484 *list rows = table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type", "having": ("service_type": (COP_COUNT, op_ge(100)))));
486 The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
487 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.
489 @anchor select_option_superquery
490 @par Select Option "superquery"
491 <b>Superquery Example:</b>
493 *list rows = table.selectRows("columns": ("serviceid", "service_methodid", cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid")), "superquery": ("columns": ("serviceid", "service_methodid"), "where": ("max_methodid": op_ceq("service_methodid"))));
495 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
496 The above example results in an SQL command equivalent to the following:
498 *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");
500 @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
502 @anchor select_option_forupdate
503 @par Select Option "forupdate"
504 <b>For Update Example:</b>
506 on_success ds.commit();
507 on_error ds.rollback();
509 *list rows = table.selectRows("columns": ("serviceid", "service_methodid"), "forupdate": True);
511 \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.
512 The above example results in an SQL commit equivalent to the following:
514 *list rows = table.vselectRows("select serviceid,service_methodid from schema.service_methods for update");
517 @subsection sql_paging Select With Paging
519 There is support for paging query results in the following methods:
520 - @ref SqlUtil::AbstractTable::getRowIterator()
521 - @ref SqlUtil::AbstractTable::getSelectSql()
522 - @ref SqlUtil::AbstractTable::select()
523 - @ref SqlUtil::AbstractTable::selectRows()
525 @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
527 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.
529 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.
532 Select 100 rows starting at row 200 (the table's primary key will be used
for the \c
"orderby" option by
default): \n
534 *
list rows = table.selectRows((
"where": (
"type":
"user"),
"limit": 100,
"offset": 200));
536 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:
538 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));
542 ds.vselectRows(
"select * from public.table where type = %v order by type limit %v offset %v", (
"user", 100, 200));
545 @subsection check_matching_rows Check For At Least One Matching Row
549 *
hash h = table.findSingle((
"account_type":
"CUSTOMER"));
551 printf(
"found 1 customer row: %y\n", l[0]);
554 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):
556 *hash h = table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
558 printf("found 1 customer row: %y\n", l[0]);
561 @section inserting_data Inserting Data into the Database
563 The following methods can be used to insert data into the database:
564 - @ref SqlUtil::AbstractTable::insert(): inserts a single row into a table without committing the transaction
565 - @ref SqlUtil::AbstractTable::insertCommit(): inserts a single row into a table and commits the transaction
566 - @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
567 - @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
569 @see @ref sql_upsert for information about upserting or merging data
571 @subsection inserting_data_explicitly Inserting Data Explicitly
575 table.insert(("id": id, "name": name, "created": now_us()));
578 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.
580 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.
582 @subsection inserting_data_from_select Inserting Data From a Select Statement
586 int rows = table.insertFromSelect(("id", "name", "created"), source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER"))));
589 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.
591 The example above would generate a %Qore SQL command like the following:
593 return ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER"));
596 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.
598 @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
600 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:
604 # get the rows to be inserted
605 list l = get_table_rows();
606 # insert the data and commit after every 5000 rows
607 table.insertFromIterator(l.iterator(), ("commit_block": 5000));
610 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".
612 @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
614 @section updating_data Updating Data
616 The following methods can be used to update data:
618 - @ref SqlUtil::AbstractTable::updateCommit(): updates a single row and commits the transaction
625 The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL
for example:
627 return ds.vexec(
"update schema.table set permission_type = lower(permission_type) || '-migrated');
629 And the following on MySQL:
631 return ds.vexec("update schema.table set permission_type = concat(lower(permission_type),
'-migrated'));
634 @section deleting_data Deleting Data
636 The following methods can be used to dekete data:
637 - @ref
SqlUtil::AbstractTable::del(): updates the table based on a @ref where_clauses
"where clause" and does not commit the transaction
638 - @ref SqlUtil::AbstractTable::delCommit(): updates the table based on a @ref where_clauses
"where clause" and commits the transaction
639 - @ref SqlUtil::AbstractTable::truncate(): truncates the table and does not commit the transaction
640 - @ref SqlUtil::AbstractTable::truncateCommit(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
644 int dcnt = table.del((
"record_type":
"OLD-CUSTOMER"));
647 The above example would generate a %Qore SQL command like the following:
649 return ds.vexec(
"delete from schema.table where record_type = %v", (
"OLD-CUSTOMER"));
652 The @ref
SqlUtil::AbstractTable::del() and @ref SqlUtil::AbstractTable::delCommit() methods can be used to delete data from the database.
654 See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
656 @section joins Joining Tables
658 Joining tables is made by providing a
join specification to the @ref select_option_join "
join select option" in
659 a @ref select_option_hash "select option
hash" as in the following example:
661 *
list rows = table.selectRows((
"columns": (
"table.id",
"t2.customer_name"),
"join":
join_inner(table2,
"t2", (
"id":
"altid"))));
663 In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
665 Joins on multiple tables are performed by combining the results of @ref sql_op_funcs
"join functions" with the @ref plus_operator
"+ operator"
670 In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
671 automatically detected primary key to foreign key relationship between the two tables.
673 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
674 argument to the @ref sql_op_funcs
"join function" as in the following example:
676 *
list rows = table.selectRows((
"join":
join_inner(table2,
"t2", (
"id":
"altid")) +
join_inner(
"t2", table3,
"t3")));
678 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
679 with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
681 @see @ref select_option_join
"join select option"
683 @section where_clauses Where Clauses
685 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:
704 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:
705 - use the @ref
SqlUtil::wop_or() function to combine where expressions with the \c "or" operator
706 - 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".
708 The where condition
hash has the following format:
709 - each key gives a column name or a table/alias with column name in dot notation
710 - 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
712 @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
714 See @ref sql_op_funcs
for a
list of
operator functions.
716 @par Where
Hash Example:
720 "account_type":
op_like(
"%CUSTOMER%"),
724 The preceding example results in a where clause equivalent to: \c
"name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
725 that bind by value is used, so,
if used in a context like the following:
727 Table t(ds,
"table");
728 *
hash qh = t.select((
"where": w));
730 the complete query would look instead as follows:
732 ds.vselect(
"select * from table where name = %v and account_type like %v and id >= %v", (
"Smith",
"%CUSTOMER%", 500));
736 @par Where
List Example:
740 "account_type":
op_like(
"%CUSTOMER%"),
745 "account_type":
op_like(
"%VENDOR%"),
748 Table t(ds,
"table");
749 *
hash qh = t.select((
"where": (w1, w2)));
751 the complete query would look instead as follows:
753 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));
757 Find a single row in the table where the \c
"permission_type" column is a value between \c
"US" and \c
"UX":\n
759 *
hash row = table.findSingle((
"permission_type":
op_between(
"US",
"UX")));
761 resulting in an
internal SQL command that looks as follows (depending on the database):
763 *
hash row = ds.vselectRow(
"select * from table where permission_type between %v and %v limit %v", (
"US",
"UX", 1));
765 Delete all rows in the table where the \c
"name" column is like \c
"%Smith%":\n
767 int row_count = table.del((
"name":
op_like(
"%Smith%")));
769 resulting in an
internal SQL command that looks as follows:
771 ds.vexec(
"delete from table where name like %v", (
"%Smith%"));
773 Find all rows where \c
"id" is greater than \c 100 and \c
"created" is after \c 2013-03-01:\n
775 *
list rows = table.findAll((
"id":
op_gt(100),
"created":
op_gt(2013-03-01)));
777 resulting in an
internal SQL command that looks as follows:
779 ds.vexec(
"select * from table where id > %v and created > %v", (100, 2013-03-01));
782 @section sql_upsert Upserting or Merging Data
784 This module offers a high-level api
for "upserting" or merging data from one table into another table through the following methods:
794 @subsection sql_upsert_single Upsert a Single Row
798 table.upsert((
"id":
id,
"name": name,
"account_type": account_type));
801 To upsert or merge a single row in the database, call @ref
SqlUtil::AbstractTable::upsert() or @ref SqlUtil::AbstractTable::upsertCommit() with the
802 single row to be upserted or merged as a
hash as in the preceding example.
804 @subsection sql_upsert_many Upserting Many Rows Using An Upsert
Closure
806 To upsert or merge many rows by using an upsert closure, call @ref SqlUtil::AbstractTable::getUpsertClosure() or @ref SqlUtil::AbstractTable::getUpsertClosureWithValidation() and provide an example row as an argument to acquire a closure that will be executed on the rest of the rows as in the following example.
810 # get the rows to be inserted
811 list l = get_table_rows();
814 code upsert = table.getUpsertClosure(l[0]);
816 on_success ds.commit();
817 on_error ds.rollback();
819 # loop through the reference data rows
824 @par Complex Example With Callbacks:
826 # set the upsert strategy depending on the use case
829 # hash summarizing changes
832 # get the rows to be inserted
833 list l = get_table_rows();
836 # get the upsert closure to use based on the first row to be inserted
837 code upsert = table.getUpsertClosure(l[0], upsert_strategy);
839 on_success ds.commit();
840 on_error ds.rollback();
842 # loop through the reference data rows
843 foreach hash h in (l) {
844 int code = upsert(h);
855 else if (verbose > 1)
856 printf(
"*** reference data %s: %y: %s\n", table.getName(), h, change);
861 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
863 printf(
"*** reference data %s: OK\n", table.getName());
867 @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
873 # get the rows to be inserted
874 list l = get_table_rows();
875 table.upsertFromIterator(l.iterator());
878 @par Complex Example With Callbacks:
880 # set the upsert strategy depending on the use case
883 # get the rows to be inserted
884 list l = get_table_rows();
886 code callback = sub (
string table_name,
hash row,
int result) {
891 printf(
"*** reference data %s: %y: %s\n", table_name, row, change);
894 hash sh = table.upsertFromIterator(l.iterator(), upsert_strategy,
False, (
"info_callback": callback,
"commit_block": 5000));
896 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
898 printf(
"*** reference data %s: OK\n", table.getName());
901 The iterator given to the @ref
SqlUtil::AbstractTable::upsertFromIterator() or @ref SqlUtil::AbstractTable::upsertFromIteratorCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "
hash".
903 @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
905 @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
907 To upsert or merge many rows from a select statement, use @ref SqlUtil::AbstractTable::upsertFromSelect() or @ref SqlUtil::AbstractTable::upsertFromSelectCommit() as in the following example:
911 table.upsertFromSelect(table2, (
"where": (
"account_type":
"CUSTOMER")));
914 @par Complex Example With Callbacks:
916 # set the upsert strategy depending on the use case
919 code callback = sub (
string table_name,
hash row,
int result) {
924 printf(
"*** reference data %s: %y: %s\n", table_name, row, change);
927 hash sh = table.upsertFromSelect(table2, (
"where": (
"account_type":
"CUSTOMER")), upsert_strategy, False, (
"info_callback": callback,
"commit_block": 5000));
929 printf(
"*** reference data %s: %s\n", table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), sh.pairIterator())));
931 printf(
"*** reference data %s: OK\n", table.getName());
934 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).
936 @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
938 @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
940 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.
942 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.
946 # get the rows to be inserted
947 list l = get_table_rows();
948 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
951 @par Complex Example With Callbacks:
953 # set the upsert strategy depending on the use case
954 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
956 # get the rows to be inserted
957 list l = get_table_rows();
959 code callback = sub (string table_name, hash row, int result) {
960 if (result == AbstractTable::UR_Unchanged)
962 string change = AbstractTable::UpsertResultMap{result};
964 printf("*** reference data %s: %y: %s\n", table_name, row, change);
967 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, ("delete_others": True, "info_callback": callback, "commit_block": 5000));
969 printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
971 printf("*** reference data %s: OK\n", table.getName());
974 @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
976 @subsection sql_upsert_strategies Upsert Strategies
977 The approach used is based on one of the following strategies (see @ref upsert_options):
978 - @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
979 - @ref
SqlUtil::AbstractTable::UpsertInsertFirst "AbstractTable::UpsertInsertFirst": first an insert will be attempted,
if it fails due to a duplicate key, then an update will be made;
this strategy should be used
if more inserts will be made than updates
980 - @ref
SqlUtil::AbstractTable::UpsertUpdateFirst "AbstractTable::UpsertUpdateFirst": first an update will be attempted,
if it fails due to missing data, then an insert is performed;
this strategy should be used
if more updates will be made then inserts
982 - @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
983 - @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
985 @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.
2173 "code":
string (
string cve,
string arg, reference psch) {
2175 return sprintf(
"%s as %s", cve, arg);
2181 "code":
string (
string cve,
string arg) {
2182 return sprintf(
"%s || %s", arg, cve);
2188 "code":
string (
string cve,
string arg) {
2189 return sprintf(
"%s || %s", cve, arg);
2195 "code":
string (*
string cve, any arg) {
2200 "code":
string (
string cve, any arg) {
2201 return sprintf(
"upper(%s)", cve);
2205 "code":
string (
string cve, any arg) {
2206 return sprintf(
"lower(%s)", cve);
2210 "code":
string (
string cve, any arg) {
2211 return sprintf(
"distinct %s", cve);
2215 "code":
string (
string cve, any arg) {
2216 return sprintf(
"min(%s)", cve);
2221 "code":
string (
string cve, any arg) {
2222 return sprintf(
"max(%s)", cve);
2227 "code":
string (
string cve, any arg) {
2228 return sprintf(
"avg(%s)", cve);
2233 "code":
string (
string cve, any arg) {
2234 return sprintf(
"sum(%s)", cve);
2240 "code":
string (*
string cve, any arg) {
2241 return sprintf(
"count(%s)", cve ? cve :
"*");
2246 "code":
string (
string arg1,
string arg2) {
2247 return sprintf(
"%s - %s", arg1, arg2);
2252 "code":
string (
string arg1,
string arg2) {
2253 return sprintf(
"%s + %s", arg1, arg2);
2258 "code":
string (
string arg1,
string arg2) {
2259 return sprintf(
"%s / %s", arg1, arg2);
2264 "code":
string (
string arg1,
string arg2) {
2265 return sprintf(
"%s * %s", arg1, arg2);
2270 "code":
string (*
string cve,
hash arg) {
2271 throw "SEQUENCE-ERROR",
sprintf(
"cannot select sequence %y because this database does not support sequences", arg.seq);
2276 "code":
string (*
string cve,
hash arg) {
2277 throw "SEQUENCE-ERROR",
sprintf(
"cannot select the current value of sequence %y because this database does not support sequences", arg.seq);
2282 "code":
string (*
string cve,
hash arg) {
2283 return sprintf(
"coalesce(%s)", (foldl $1 +
"," + $2, arg.args));
2287 "code":
string (
string cve,
list args) {
2289 return sprintf(
"substring(%s from %d)", cve, args[0]);
2290 return sprintf(
"substring(%s from %d for %d)", cve, args[0], args[1]);
2356 hash cop_cast(any column,
string arg, *any arg1, *any arg2);
2812 "code":
string (
string cve, any arg) {
2813 return sprintf(
"%s - %s", cve, arg);
2818 "code":
string (
string cve, any arg) {
2819 return sprintf(
"%s + %s", cve, arg);
2824 "code":
string (
string cve, any arg) {
2825 return sprintf(
"%s / %s", cve, arg);
2830 "code":
string (
string cve, any arg) {
2831 return sprintf(
"%s * %s", cve, arg);
2837 "code":
string (*
string cve,
string arg) {
2838 throw "SEQUENCE-ERROR",
sprintf(
"cannot select sequence %y because this database does not support sequences", arg);
2843 "code":
string (*
string cve,
string arg) {
2844 throw "SEQUENCE-ERROR",
sprintf(
"cannot select the current value of sequence %y because this database does not support sequences", arg);
2849 "code":
string (*
string cve, softlist args) {
2850 return sprintf(
"coalesce(%s)", (foldl $1 +
"," + $2, args));
3625 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3627 return sprintf(
"%s like %v", cn);
3631 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3633 return sprintf(
"%s < %v", cn);
3637 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3639 return sprintf(
"%s <= %v", cn);
3643 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3645 return sprintf(
"%s > %v", cn);
3649 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3651 return sprintf(
"%s >= %v", cn);
3655 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3657 return sprintf(
"%s is not null", cn);
3659 return sprintf(
"(%s != %v or %s is null)", cn, cn);
3663 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3665 return sprintf(
"%s is null", cn);
3667 return sprintf(
"%s = %v", cn);
3671 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3674 return sprintf(
"%s between %v and %v", cn);
3678 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3679 *
string ins = (foldl $1 +
"," + $2, (map t.getSqlValue($1), arg));
3680 return exists ins ?
sprintf(
"%s in (%s)", cn, ins) :
"1 != 1";
3685 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3686 return sprintf(
"not (%s)", cn);
3691 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3692 return sprintf(
"%s < %s", cn, arg);
3697 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3698 return sprintf(
"%s <= %s", cn, arg);
3703 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3704 return sprintf(
"%s > %s", cn, arg);
3709 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3710 return sprintf(
"%s >= %s", cn, arg);
3715 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3716 return sprintf(
"%s != %s", cn, arg);
3721 "code":
string (
object t,
string cn,
string arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3722 return sprintf(
"%s = %s", cn, arg);
3726 "code":
string (
object t,
string cn, any arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3732 return sprintf(
"substring(%s from %v for %v) = %v", cn);
3736 "code":
string (
object t,
string cn,
list arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch) {
3737 return t.getOrClause(arg, \args, jch,
join, ch, psch);
4144 constructor(*
hash nh);
4171 any memberGate(
string k);
4185 abstract any take(
string k);
4188 renameKey(
string old_name,
string new_name);
4205 bool matchKeys(
hash h1);
4218 bool matchKeys(
list l);
4244 bool partialMatchKeys(
hash h1);
4257 bool partialMatchKeys(
list l);
4366 bool hasKey(
string k);
4379 bool hasKeyValue(
string k);
4409 abstract string getElementName();
4426 constructor(softlist nl);
4441 abstract any
get(softint i);
4495 abstract string getElementName();
4497 private checkIndex(
int i);
4510 constructor(AbstractDatasource ds,
hash tables, *
hash opt);
4514 constructor(AbstractDatasource ds);
4518 add(
string k,
Table val);
4538 populate(AbstractDatasource ds,
hash tables, *
hash opt);
4542 populate(AbstractDatasource ds);
4560 *
list getDropAllForeignConstraintsOnTableSql(
string name, *
hash opt);
4583 string getElementName();
4587 *
AbstractTable getIfExists(AbstractDatasource ds,
string name);
4610 *
string getRenameTableIfExistsSql(
string old_name,
string new_name, *
hash opts);
4625 bool tableRenamed(
string old_name,
string new_name,
string old_sql_name);
4628 private tableRenamedIntern(
string old_name,
string new_name,
string oldsn);
4647 *
string getDropConstraintIfExistsSql(
string tname,
string cname, *
hash opts);
4650 list getCreateList();
4679 private getDependencies(reference tdh, reference sdh, *reference th);
4688 constructor(*
hash c) ;
4727 string getElementName();
4763 constructor(
string n,
string nt, *
string qt,
int sz,
bool nul, *
string dv, *
string c);
4767 string getNativeTypeString();
4787 string getDropSql(
string table_name);
4817 abstract string getRenameSql(
AbstractTable t,
string new_name);
4852 constructor(softint n_scale = 0);
4856 string getNativeTypeString(
string native_type,
int precision);
4864 constructor(*
hash c) ;
4902 string getElementName();
4929 constructor(
string n,
bool u,
hash c);
4937 bool hasColumn(
string cname);
4941 abstract string getCreateSql(
string table_name, *
hash opt);
4944 string getDropSql(
string table_name);
4959 abstract string getRenameSql(
string table_name,
string new_name);
4966 setSupportingConstraint();
4974 list getRecreateSql(AbstractDatasource ds,
string table_name, *
hash opt);
4982 constructor(*
hash c) ;
5016 string getElementName();
5035 constructor(
string n);
5047 abstract string getCreateSql(
string table_name, *
hash opt);
5050 string getDropSql(
string table_name);
5054 abstract list getRenameSql(
string table_name,
string new_name);
5057 string getDisableSql(
string table_name);
5061 string getEnableSql(
string table_name, *
hash opt);
5072 abstract bool setIndexBase(
string ix);
5075 abstract clearIndex();
5078 bool hasColumn(
string cname);
5093 constructor(
string n,
string n_src) ;
5101 bool setIndexBase(
string ix);
5123 constructor(
string n, *
hash c, *
string n_index) ;
5127 constructor(
string n,
Columns c, *
string n_index) ;
5139 hash getDisableReenableSql(AbstractDatasource ds,
string table_name, *
hash opts);
5143 findMatchingIndex(*
Indexes indexes);
5161 removeSourceConstraint(
string tname,
list cols);
5165 renameSourceConstraintTable(
string old_name,
string new_name);
5169 bool hasColumn(
string cname);
5181 bool setIndexBase(
string ix);
5189 abstract string getCreateSql(
string table_name, *
hash opts);
5197 constructor(
string n, *
hash c, *
string n_index) ;
5208 constructor(
string n, *
hash c) ;
5216 constructor(*
hash c) ;
5251 *
hash findConstraintOn(
string table, softlist cols);
5255 string getElementName();
5273 constructor(
string t,
Columns c);
5319 constructor(
string n_name,
number n_start = 1,
number n_increment = 1, *softnumber n_max);
5323 abstract string getCreateSql(*
hash opt);
5326 string getDropSql();
5330 abstract string getRenameSql(
string new_name);
5353 constructor(
string n_name,
string n_src);
5357 abstract string getCreateSql(*
hash opt);
5360 string getDropSql();
5364 abstract softlist getRenameSql(
string new_name);
5389 constructor(
string n,
string n_type,
string n_src);
5398 string getDropSql();
5418 constructor(
string n,
string n_type,
string n_src) ;
5422 abstract list getCreateSql(*
hash opt);
5425 abstract list getRenameSql(
string new_name);
5428 setName(
string new_name);
5436 constructor(*
hash c) ;
5466 string getElementName();
5475 constructor(
string n,
string n_src) ;
5479 abstract list getCreateSql(
string table_name, *
hash opt);
5482 abstract list getRenameSql(
string table_name,
string new_name);
5485 abstract list getDropSql(
string table_name);
5492 constructor(*
hash c) ;
5522 string getElementName();
5558 constructor(AbstractDatasource ds, *
hash opts);
5572 constructor(
string ds, *
hash opts);
5602 any methodGate(
string meth);
5628 private constructor(AbstractDatasource nds, *
hash nopts);
5631 static string makeDatasourceDesc(AbstractDatasource ds);
5633 private validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
5638 static validateOptionIntern(
string err,
string type, reference opt,
string k,
string tag);
5643 private validateHashKeysForWhitespaces(any node);
5651 string getDriverName();
5655 string getDatasourceDesc();
5668 const DatabaseOptions = (
5676 const CacheOptions = (
5677 "table_cache":
"Tables",
5686 const CallbackOptions = (
5687 "info_callback":
"code",
5688 "sql_callback":
"code",
5700 const AC_Unchanged = 0;
5704 const AC_Create = 1;
5710 const AC_Rename = 3;
5713 const AC_Modify = 4;
5716 const AC_Truncate = 5;
5722 const AC_Recreate = 7;
5725 const AC_Insert = 8;
5728 const AC_Update = 9;
5731 const AC_Delete = 10;
5734 const AC_NotFound = 11;
5739 AC_Unchanged:
"unchanged",
5740 AC_Create:
"create",
5742 AC_Rename:
"rename",
5743 AC_Modify:
"modify",
5744 AC_Truncate:
"truncate",
5746 AC_Recreate:
"recreate",
5747 AC_Insert:
"insert",
5748 AC_Update:
"update",
5749 AC_Delete:
"delete",
5750 AC_NotFound:
"not found",
5754 const ActionDescMap = (
5755 "unchanged": AC_Unchanged,
5756 "create": AC_Create,
5758 "rename": AC_Rename,
5759 "modify": AC_Modify,
5760 "truncate": AC_Truncate,
5762 "recreate": AC_Recreate,
5763 "insert": AC_Insert,
5764 "update": AC_Update,
5765 "delete": AC_Delete,
5766 "not found": AC_NotFound,
5770 const ActionLetterMap = (
5792 const CreationOptions = CallbackOptions + (
5794 "table_cache":
"Tables",
5802 const AlignSchemaOptions = CreationOptions;
5807 const DropSchemaOptions = CallbackOptions;
5822 const SchemaDescriptionOptions = (
5845 const SequenceDescriptionOptions = (
5852 const ComputeStatisticsOptions = (
5853 "tables" :
"softstringlist",
5857 const ReclaimSpaceOptions = (
5858 "tables" :
"softstringlist",
5875 private constructor(AbstractDatasource nds, *
hash nopts) ;
5882 static doOkCallback(*
hash opt,
int ac,
string type,
string name, *
string table, *
string info);
5884 static *
string doCallback(*
hash opt, *
string sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
5886 static list doCallback(*
hash opt,
list sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
5922 any tryExec(
string sql);
5936 any tryExecArgs(
string sql, *softlist args);
5951 any tryExecRaw(
string sql);
5989 private list dropSqlUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
5992 private list alignCodeUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
6076 bool dropFunctionIfExists(
string name, *
hash opt);
6092 bool dropProcedureIfExists(
string name, *
hash opt);
6108 bool dropSequenceIfExists(
string name, *
hash opt);
6124 bool dropViewIfExists(
string name, *
hash opt);
6140 bool dropTableIfExists(
string name, *
hash opt);
6156 *
string getDropFunctionSqlIfExists(
string name, *
hash opt);
6172 *
string getDropProcedureSqlIfExists(
string name, *
hash opt);
6188 *
string getDropSequenceSqlIfExists(
string name, *
hash opt);
6204 *
list getDropTableSqlIfExists(
string name, *
hash opt);
6207 doDropSql(*softlist l,
string type,
string name, *
hash opt);
6210 bool doDrop(*softlist l,
string type,
string name, *
hash opt);
6324 int getNextSequenceValue(
string name);
6337 int getCurrentSequenceValue(
string name);
6350 string getSqlFromList(
list l);
6354 bool supportsSequences();
6358 bool supportsTypes();
6362 bool supportsPackages();
6374 list listFunctions();
6382 list listProcedures();
6390 list listSequences();
6416 bool rebuildIndex(
string name, *
hash options);
6439 computeStatistics(*
hash options);
6450 reclaimSpace(*
hash options);
6453 private validateOptionsIntern(
string err,
hash ropt, reference opt);
6456 private validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
6465 static checkDriverOptions(reference h,
string drv);
6468 private hash getDatabaseOptions();
6472 private hash getCallbackOptions();
6476 private hash getCreationOptions();
6480 private hash getCacheOptions();
6484 private hash getAlignSchemaOptions();
6488 private hash getDropSchemaOptions();
6492 private hash getSchemaDescriptionOptions();
6496 private hash getSequenceDescriptionOptions();
6500 private hash getRebuildIndexOptions();
6504 private hash getComputeStatisticsOptions();
6508 private hash getReclaimSpaceOptions();
6512 private any tryExecArgsImpl(
string sql, *softlist args);
6516 private any tryExecRawImpl(
string sql);
6519 private abstract string getCreateSqlImpl(
list l);
6520 private abstract list getAlignSqlImpl(
hash schema_hash, *
hash opt);
6521 private abstract list getDropSchemaSqlImpl(
hash schema_hash, *
hash opt);
6526 private abstract *
AbstractView getViewImpl(
string name);
6532 private abstract list featuresImpl();
6533 private abstract list listTablesImpl();
6534 private abstract list listFunctionsImpl();
6535 private abstract list listProceduresImpl();
6536 private abstract list listSequencesImpl();
6537 private abstract list listViewsImpl();
6540 private abstract int getNextSequenceValueImpl(
string name);
6542 private abstract int getCurrentSequenceValueImpl(
string name);
6545 private abstract bool supportsSequencesImpl();
6546 private abstract bool supportsPackagesImpl();
6547 private abstract bool supportsTypesImpl();
6549 private abstract bool rebuildIndexImpl(
string name, *
hash options);
6550 private abstract computeStatisticsImpl(*
hash options);
6551 private abstract reclaimSpaceImpl(*
hash options);
6593 constructor(AbstractDatasource ds,
string name, *
hash opts);
6609 constructor(
string ds,
string name, *
hash opts);
6633 constructor(
hash ds,
string name, *
hash opts);
6645 constructor(AbstractDatasource ds,
hash desc,
string name, *
hash opts);
6655 any methodGate(
string meth);
6672 const TableOptions = (
6674 "table_cache":
"Tables",
6682 const IndexOptions = (
6690 const ConstraintOptions = IndexOptions;
6693 const CacheOptions = (
6694 "table_cache":
"Tables",
6701 const ForeignConstraintOptions = ConstraintOptions + (
6702 "table_cache":
"Tables",
6724 const SelectOptions = (
6728 "where":
"hash/list",
6729 "orderby":
"softstringinthashlist",
6734 "groupby":
"softstringinthashlist",
6741 const TableOmissionOptions = (
6743 "foreign_constraints":
True,
6752 "omit":
"softstringlist",
6763 const AlignTableOptions = TableCreationOptions + (
6768 "db_table_cache":
"Tables",
6783 const TableDescriptionHashOptions = (
6791 "table_cache":
"Tables",
6806 const ColumnDescOptions = (
6819 const AdditionalColumnDescOptions = (
6824 const ColumnOptions = {};
6831 const SqlDataCallbackOptions = (
6832 "sqlarg_callback":
"code",
6833 "tablecode":
"code",
6846 const InsertOptions = SqlDataCallbackOptions + (
6847 "returning":
"stringhashlist",
6857 const UpsertOptions = (
6858 "info_callback":
"code",
6861 "omit_update":
"softstringlist",
6869 const InsertFromIteratorOptions = SqlDataCallbackOptions + (
6870 "info_callback":
"code",
6895 const UpsertInsertFirst = 1;
6903 const UpsertUpdateFirst = 2;
6912 const UpsertSelectFirst = 3;
6919 const UpsertAuto = 4;
6926 const UpsertInsertOnly = 5;
6933 const UpsertUpdateOnly = 6;
6938 const UpsertStrategyMap = (
6939 UpsertInsertFirst:
"UpsertInsertFirst",
6940 UpsertUpdateFirst:
"UpsertUpdateFirst",
6941 UpsertSelectFirst:
"UpsertSelectFirst",
6942 UpsertAuto:
"UpsertAuto",
6943 UpsertInsertOnly:
"UpsertInsertOnly",
6944 UpsertUpdateOnly:
"UpsertUpdateOnly",
6950 const UpsertStrategyDescriptionMap = (
6951 "UpsertInsertFirst": UpsertInsertFirst,
6952 "UpsertUpdateFirst": UpsertUpdateFirst,
6953 "UpsertSelectFirst": UpsertSelectFirst,
6954 "UpsertAuto": UpsertAuto,
6955 "UpsertInsertOnly": UpsertInsertOnly,
6956 "UpsertUpdateOnly": UpsertUpdateOnly,
6964 const UR_Inserted = 1;
6968 const UR_Verified = 2;
6971 const UR_Updated = 3;
6974 const UR_Unchanged = 4;
6977 const UR_Deleted = 5;
6983 const UpsertResultMap = (
6984 UR_Inserted:
"inserted",
6985 UR_Verified:
"verified",
6986 UR_Updated:
"updated",
6987 UR_Unchanged:
"unchanged",
6988 UR_Deleted:
"deleted",
6994 const UpsertResultDescriptionMap = (
6995 "inserted": UR_Inserted,
6996 "verified": UR_Verified,
6997 "updated": UR_Updated,
6998 "unchanged": UR_Unchanged,
6999 "deleted": UR_Deleted,
7003 const UpsertResultLetterMap = (
7044 private constructor(AbstractDatasource nds,
string nname, *
hash nopts) ;
7063 setDatasource(AbstractDatasource nds);
7066 private doTableOptions(*
hash nopts);
7113 dropCommit(*
hash opt);
7132 deprecated dropNoCommit(*
hash opt);
7146 any tryExec(
string sql);
7160 any tryExecArgs(
string sql, *softlist args);
7175 any tryExecRaw(
string sql);
7190 softlist getDropSql(*
hash opt);
7216 deprecated truncateNoCommit();
7234 string getTruncateSql(*
hash opt);
7247 createCommit(*
hash opt);
7266 deprecated createNoCommit(*
hash opt);
7280 rename(
string new_name, *reference sql, *
Tables table_cache);
7283 private doRenameIntern(
string new_name, *
Tables table_cache);
7314 private bool emptyUnlocked();
7351 AbstractColumn addColumn(
string cname,
hash opt,
bool nullable = True, *reference lsql);
7383 list getAddColumnSql(
string cname,
hash copt,
bool nullable = True, *
hash opt);
7386 private AbstractColumn addColumnUnlocked(
string cname,
hash opt,
bool nullable = True, *reference lsql,
bool do_exec = True,
bool modify_table = True);
7417 AbstractColumn modifyColumn(
string cname,
hash opt,
bool nullable = True, *reference lsql);
7447 list getModifyColumnSql(
string cname,
hash copt,
bool nullable = True, *
hash opt);
7468 AbstractColumn renameColumn(
string old_name,
string new_name, reference sql);
7490 string getRenameColumnSql(
string old_name,
string new_name, *
hash opt);
7496 private validateOptionsIntern(
string err,
hash ropt, reference opt);
7499 private validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
7502 private execSql(softlist lsql);
7552 string getAddPrimaryKeySql(
string pkname, softlist cols, *
hash pkopt, *
hash opt);
7558 private AbstractPrimaryKey addPrimaryKeyUnlocked(
string pkname, softlist cols, *
hash opt, *reference sql);
7561 private AbstractPrimaryKey addPrimaryKeyUnlockedIntern(
string pkname, softlist cols, *
hash opt, *reference sql);
7581 list getDropAllConstraintsAndIndexesOnColumnSql(
string cname, *
hash opt);
7584 private list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(
string cname, *
hash opt);
7607 list getDropPrimaryKeySql(*
hash opt);
7678 string getAddUniqueConstraintSql(
string cname, softlist cols, *
hash ukopt, *
hash opt);
7709 AbstractIndex addIndex(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
7734 string getAddIndexSql(
string iname,
bool unique, softlist cols, *
hash ixopt, *
hash opt);
7737 private AbstractIndex addIndexUnlocked(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
7740 private AbstractIndex addIndexUnlockedIntern(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
7756 AbstractIndex renameIndex(
string old_name,
string new_name, reference sql);
7801 string getDropIndexSql(
string iname, *
hash opt);
7853 string getAddForeignConstraintSql(
string cname, softlist cols,
string table, *softlist tcols, *
hash fkopt, *
hash opt);
7856 private Columns getReferencedTableColumnsUnlocked(
string table, *
Tables cache,
string err =
"FOREIGN-CONSTRAINT-ERROR");
7859 private AbstractForeignConstraint addForeignConstraintUnlocked(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference sql);
7862 private AbstractForeignConstraint addForeignConstraintUnlockedIntern(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference sql);
7953 string getAddCheckConstraintSql(
string cname,
string src, *
hash copt, *
hash opt);
7975 AbstractConstraint renameConstraint(
string old_name,
string new_name, reference lsql);
7998 string getDropConstraintSql(
string cname, *
hash opt);
8021 *
string getDropConstraintIfExistsSql(
string cname, *
hash opt, *reference cref);
8096 list getAddTriggerSql(
string tname,
string src, *
hash topt, *
hash opt);
8099 private AbstractTrigger addTriggerUnlocked(
string tname,
string src, *
hash opt, *reference lsql);
8102 private AbstractTrigger addTriggerUnlockedIntern(
string tname,
string src, *
hash opt, *reference lsql);
8147 list getDropTriggerSql(
string tname, *
hash opt);
8150 private getAllConstraintsUnlocked(*
hash opt);
8153 private checkUniqueConstraintName(
string err,
string cname);
8156 private checkUniqueConstraintNameValidateOptions(
string err,
string cname,
hash ropt, reference opt);
8160 private validateColumnOptions(
string cname, reference opt,
bool nullable);
8205 list getDropColumnSql(
string cname, *
hash opt);
8226 *
hash insertCommit(
hash row, reference sql);
8256 *
hash insert(
hash row, reference sql);
8268 deprecated *
hash insertNoCommit(
hash row, *reference sql, *
hash opt);
8273 private *
hash insertIntern(
hash row, *reference sql, *
hash opt);
8276 private hash getPlaceholdersAndValues(
hash row);
8283 bool hasReturning();
8437 int upsertCommit(
hash row,
int upsert_strategy = UpsertAuto, *
hash opt);
8457 int upsert(
hash row,
int upsert_strategy = UpsertAuto, *
hash opt);
8461 deprecated
int upsertNoCommit(
hash row,
int upsert_strategy = UpsertAuto);
8485 code getUpsertClosure(
hash row,
int upsert_strategy = UpsertAuto, *
hash opt);
8541 code getUpsertClosureWithValidation(
hash example_row,
int upsert_strategy = UpsertAuto, *
hash opt);
8622 private *
hash doDeleteOthersIntern(
hash pkh, *
hash opt);
8935 string getSelectSql(*
hash sh, *reference args);
8941 string getSelectSqlIntern(*
hash qh, reference args, *
hash opt);
8944 string getSelectSqlUnlocked(*
hash qh, reference args, *
hash opt);
8948 string getSelectSqlUnlockedIntern(*
hash qh,
string from, reference args, *
hash ch, *
hash opt);
8951 private string getFromIntern(
string from, *
hash qh);
8963 private doForUpdate(reference sql);
8966 private string getSelectSqlName(*
hash qh);
8969 private string getColumnExpressionIntern(any cvc, *
hash jch,
bool join, *
hash ch, *
hash psch);
8972 private string doColumnOperatorIntern(
hash cvc, *
hash jch,
bool join, *
hash ch, *
hash psch, *reference psch_ref);
8975 private string doColumnOperatorIntern(any cop, any arg, *
string cve,
hash cm, *
hash jch,
bool join, *
hash ch, *
hash psch, *reference psch_ref);
8978 private string getColumnNameIntern(
string cv, *
hash jch,
bool join, *
hash ch, *
hash psch);
8982 private bool asteriskRequiresPrefix();
8985 private getSelectWhereSqlUnlocked(reference sql, reference args, *
hash qh, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
8988 private *
string getWhereClause(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False);
8991 private *
string getWhereClause(
list cond, reference args, *
string cprefix, *
hash jch,
bool join = False);
8994 private *
string getWhereClauseUnlocked(
list cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch, *
hash psch);
8997 private *
string getWhereClauseUnlocked(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch, *
hash psch);
9000 private *
list getWhereClauseIntern(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
9003 private string doWhereExpressionIntern(
string cn, any we, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
9006 string getOrClause(
list arglist, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
9009 string getOrClause(
hash arg, reference args, *
hash jch,
bool join = False, *
hash ch, *
hash psch);
9012 private doSelectOrderBySqlUnlocked(reference sql, reference args, *
hash qh, *
hash jch, *
hash ch, *
hash psch,
list coll);
9031 int delCommit(
hash cond, reference sql,
hash opt);
9035 int delCommit(
hash cond,
hash opt);
9039 int delCommit(
hash cond, reference sql);
9043 int delCommit(
hash cond);
9066 int del(
hash cond, reference sql,
hash opt);
9074 int del(
hash cond, reference sql);
9086 deprecated
int delNoCommit(*
hash cond, *reference sql);
9088 private int delIntern(*
hash cond, *reference sql, *
hash opt);
9109 int updateCommit(
hash set,
hash cond, reference sql,
hash opt);
9113 int updateCommit(
hash set,
hash cond, reference sql);
9121 int updateCommit(
hash set,
hash cond);
9125 int updateCommit(
hash set);
9146 int update(
hash set,
hash cond, reference sql,
hash opt);
9150 int update(
hash set,
hash cond, reference sql);
9162 int update(
hash set);
9166 deprecated
int updateNoCommit(
hash set, *
hash cond, *reference sql);
9169 deprecated
int updateNoCommit(
hash set, *
hash cond, *
hash opt);
9171 private int updateIntern(
hash set, *
hash cond, *reference sql, *
hash opt);
9174 private string getUpdateExpression(
string col,
hash uh);
9177 private bool emptyDataIntern();
9180 private Columns checkUpsertRow(
hash row, reference upsert_strategy);
9183 private code getUpsertInsertFirst(
Columns cols,
hash example_row, *
hash opt);
9186 private code getUpsertUpdateFirst(
Columns cols,
hash example_row, *
hash opt);
9189 private code getUpsertSelectFirst(
Columns cols,
hash example_row, *
hash opt);
9192 private code getUpsertInsertOnly(
Columns cols,
hash example_row, *
hash opt);
9195 private code getUpsertUpdateOnly(
Columns cols,
hash example_row, *
hash opt);
9198 private Columns getUpsertColumns(reference csrc);
9201 private string getUpsertSelectSql(
hash row,
Columns cols, reference updc);
9204 private string getUpsertInsertSql(
hash row);
9207 private string getUpsertUpdateSql(
hash row,
Columns cols, reference updc, *
hash opt);
9210 private softbool tryUpdate(
string sql,
hash row,
Columns cols,
list updc);
9213 private checkValue(
string cname,
string argname, reference val,
string type);
9226 string getSqlFromList(
list l);
9241 string getSqlValue(any v);
9360 string getRenameSql(
string new_name, *
hash opt);
9373 string getCreateSqlString(*
hash opt);
9401 string getCreateTableSql(*
hash opt);
9409 bool checkExistence();
9412 private *
hash getCheckOmissionOptions(*softlist ol,
string err);
9440 private renameIndexUnlocked(
AbstractIndex ix,
string new_name);
9473 *
list getCreateIndexesSql(*
hash opt,
bool cache = True);
9489 *
string getCreatePrimaryKeySql(*
hash opt,
bool cache = True);
9505 *
list getCreateForeignConstraintsSql(*
hash opt,
bool cache = True);
9523 *
list getCreateConstraintsSql(*
hash opt,
bool cache = True);
9539 *
list getCreateMiscSql(*
hash opt,
bool cache = True);
9557 *
list getCreateTriggersSql(*
hash opt,
bool cache = True);
9586 private string getPrimaryKeyColumn();
9649 string getBaseType();
9653 string getSqlName();
9657 string getColumnSqlName(
string col);
9661 list getColumnSqlNames(softlist cols);
9667 bool bindEmptyStringsAsNull();
9671 abstract bool hasArrayBind();
9676 private hash getTableOptions();
9682 private hash getForeignConstraintOptions();
9688 private hash getConstraintOptions();
9694 private hash getCacheOptions();
9700 private hash getTableCreationOptions();
9706 private hash getAlignTableOptions();
9712 private hash getTableDescriptionHashOptions();
9718 private hash getColumnOptions();
9724 private hash getColumnDescOptions();
9730 private hash getTableColumnDescOptions();
9736 private hash getIndexOptions();
9742 private hash getTriggerOptions();
9748 private hash getSelectOptions();
9754 private hash getUpsertOptions();
9760 private hash getInsertOptions();
9766 private hash getInsertFromIteratorOptions();
9772 private hash getSqlDataCallbackOptions();
9778 private hash getWhereOperatorMap();
9784 private hash getColumnOperatorMap();
9790 private hash getInsertOperatorMap();
9796 private hash getUpdateOperatorMap();
9802 private hash getRawUpdateOperatorMap();
9808 private *
hash getPseudoColumnHash();
9811 private string getCreateTableSqlUnlocked(*
hash opt);
9814 private *
list getCreateIndexesSqlUnlocked(*
hash opt,
bool cache = True);
9817 private *
string getCreatePrimaryKeySqlUnlocked(*
hash opt,
bool cache = True);
9820 private *
list getCreateConstraintsSqlUnlocked(*
hash opt,
bool cache = True);
9823 private *
list getCreateForeignConstraintsSqlUnlocked(*
hash opt,
bool cache = True);
9826 private *
list getCreateMiscSqlUnlocked(*
hash opt,
bool cache = True);
9829 private *
list getCreateTriggersSqlUnlocked(*
hash opt,
bool cache = True);
9832 private list getCreateSqlUnlocked(*
hash opt,
bool cache = True);
9835 private cacheUnlocked(*
hash opt);
9838 private any execData(*
hash opt,
string sql, *
list args);
9841 private execData(SQLStatement stmt, *
hash opt, *
list args);
9844 static AbstractTable getTable(AbstractDatasource nds,
string nname, *
hash opts);
9850 private getColumnsUnlocked();
9853 private getPrimaryKeyUnlocked();
9857 private getIndexesUnlocked();
9860 private getForeignConstraintsUnlocked(*
hash opt);
9866 private getConstraintsUnlocked();
9869 private getTriggersUnlocked();
9873 private bool hasReturningImpl();
9876 private softlist getDropSqlImpl();
9879 private string getTruncateSqlImpl();
9883 private any tryExecArgsImpl(
string sql, *softlist args);
9887 private any tryExecRawImpl(
string sql);
9891 private clearImpl();
9894 private preSetupTableImpl(reference desc, *
hash opt);
9897 private abstract *
hash doReturningImpl(
hash opt, reference sql,
list args);
9899 private abstract bool emptyImpl();
9902 private abstract *
string getSqlValueImpl(any v);
9908 private abstract bool checkExistenceImpl();
9911 private abstract bool supportsTablespacesImpl();
9914 private abstract bool constraintsLinkedToIndexesImpl();
9917 private abstract bool uniqueIndexCreatesConstraintImpl();
9919 private abstract setupTableImpl(
hash desc, *
hash opt);
9921 private abstract Columns describeImpl();
9923 private abstract Indexes getIndexesImpl();
9925 private abstract Constraints getConstraintsImpl();
9926 private abstract Triggers getTriggersImpl();
9928 private abstract string getCreateTableSqlImpl(*
hash opt);
9929 private abstract *
list getCreateMiscSqlImpl(*
hash opt,
bool cache);
9930 private abstract string getCreateSqlImpl(
list l);
9931 private abstract string getRenameSqlImpl(
string new_name);
9934 private abstract AbstractColumn addColumnImpl(
string cname,
hash opt,
bool nullable = True);
9944 private abstract bool tryInsertImpl(
string sql,
hash row);
9947 private abstract hash getQoreTypeMapImpl();
9950 private abstract hash getTypeMapImpl();
9953 private abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *
hash qh, *
hash jch, *
hash ch, *
hash psch,
list coll);
9956 private abstract doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *
hash qh);
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5030
hash cop_avg(any column)
returns a hash for the "avg" operator; returns average column values
nothing rename(string old_path, string new_path)
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:5305
hash uop_lower(*hash nest)
returns a hash for the "lower" operator with the given argument; returns a column value in lower case...
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2151
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:6919
hash op_cge(string arg)
returns a hash for the ">=" operator with the given argument for use in where clauses when comparing ...
const DefaultIopMap
a hash of default insert operator descriptions (currently empty, all operators are driver-dependent) ...
Definition: SqlUtil.qm.dox.h:4084
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4413
hash cop_append(any column, string arg)
returns a hash for the "append" operator with the given argument
hash uop_append(string arg, *hash nest)
returns a hash for the "append" or concatenate operator with the given argument
string sprintf(string fmt,...)
int insertFromSelect(list cols, AbstractTable source, hash sh, reference sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
int delCommit()
SqlUtil::AbstractTable::delCommit() variant
const OP_IN
the SQL "in" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3607
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:6663
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2169
hash iop_seq(string arg)
returns a hash for retrieving the value of the given sequence in insert queries
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2002
hash uop_upper(*hash nest)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:4502
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:5348
hash op_between(any l, any r)
returns a hash for the "between" operator with the given arguments, neither of which can be NULL or N...
hash make_iop(string iop, any arg)
returns a hash with _iop and arg keys
*hash selectRow(*hash sh, *reference sql, *hash opt)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
hash uop_prepend(string arg, *hash nest)
returns a hash for the "prepend" operator with the given argument
hash op_in()
returns a hash for the "in" operator with all arguments passed to the function; for use in where clau...
string printf(string fmt,...)
const OP_BETWEEN
the SQL "between" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3602
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:4924
*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...
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:4907
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3620
const COP_OVER
the SQL "over" clause
Definition: SqlUtil.qm.dox.h:2106
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5213
hash op_ne(any arg)
returns a hash for the "!=" or "<>" operator with the given argument for use in where clauses when co...
hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns a hash keyed with the table name assigned to a hash with jop, table, jcols, cond, alias, and ta keys
const OP_NE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3562
hash cop_sum(any column)
returns a hash for the "sum" operator; returns the total sum of a numeric column. ...
hash cop_as(any column, string arg)
returns a hash for the "as" operator with the given argument
hash cop_year_month(any column)
returns a hash for the "year_month" operator with the given argument
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2096
string name
the name of the object
Definition: SqlUtil.qm.dox.h:5374
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:5260
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:4747
hash op_gt(any arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing c...
const COP_SEQ_CURRVAL
to return the last value of a sequence issued in the same session
Definition: SqlUtil.qm.dox.h:2156
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:4843
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 iop_seq_currval(string arg)
returns a hash for retrieving the current value of the given sequence in insert queries ...
const JopMap
a hash of valid join operators
Definition: SqlUtil.qm.dox.h:3063
hash make_op(string op, any arg)
returns a hash with op and arg keys
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:2025
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3552
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2008
hash op_clt(string arg)
returns a hash for the "<" operator with the given argument for use in where clauses when comparing t...
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2091
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:1986
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:1980
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3055
base class for sequences
Definition: SqlUtil.qm.dox.h:5300
*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...
hash join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments for use when joining with a table ot...
hash op_cgt(string arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing t...
bool nullable
True if the column can hold a NULL value, False if not
Definition: SqlUtil.qm.dox.h:4753
hash cop_min(any column)
returns a hash for the "min" operator; returns minimum column values
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:6857
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2076
hash uop_substr(int start, *int count, *hash nest)
returns a hash for the "substr" operator with the given arguments; returns a substring of a column va...
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:2146
hash uop_plus(any arg, *hash nest)
returns a hash for the "+" operator with the given arguments
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7023
const IOP_SEQ_CURRVAL
for using the last value of a sequence issued in the current session
Definition: SqlUtil.qm.dox.h:4081
hash op_cne(string arg)
returns a hash for the "!=" or "<>" operator with the given argument for use in where clauses when co...
*list selectRows(*hash sh, *reference sql, *hash opt)
returns a list of hashes representing the rows in the table that match the argument hash ...
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:5607
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:6903
const OP_CNE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3592
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:5537
*hash select(*hash sh, *reference sql, *hash opt)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3582
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:5282
hash op_like(string str)
returns a hash for the "like" operator with the given argument for use in where clauses ...
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:5287
hash op_lt(any arg)
returns a hash for the "<" operator with the given argument for use in where clauses when comparing c...
hash cop_coalesce(any col1, any col2)
returns a hash for the "coalesce" operator with the given column arguments; the first non-NULL column...
hash op_le(any arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:4848
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:5083
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2101
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3597
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4131
hash op_substr(int start, *int count, string text)
returns a hash for the "substr" operator with the given arguments; for use in where clauses ...
hash cop_distinct(any column)
returns a hash for the "distinct" operator with the given argument; returns distinct column values ...
string name
the table's name
Definition: SqlUtil.qm.dox.h:7015
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:5489
int index(softstring str, softstring substr, softint pos=0)
string src
the source of the check clause
Definition: SqlUtil.qm.dox.h:5088
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7021
hash cop_cast(any column, string arg, *any arg1, *any arg2)
returns a hash for the "cast" operator with the given argument(s)
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:1982
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2066
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...
const COP_PLUS
the SQL "plus" operator
Definition: SqlUtil.qm.dox.h:2116
hash cop_minus(any column1, any column2)
returns a hash for the "-" operator with the given arguments
hash cop_substr(any column, int start, *int count)
returns a hash for the "substr" operator with the given arguments; returns a substring of a column va...
const OP_GE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3557
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:4861
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2031
hash uop_minus(any arg, *hash nest)
returns a hash for the "-" operator with the given arguments
*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...
const DB_SYNONYMS
Feature: synonyms.
Definition: SqlUtil.qm.dox.h:1994
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:4756
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7019
hash uop_seq_currval(string seq)
returns a hash for the "seq" operator with the given argument giving the sequence name whose current ...
const COP_COALESCE
to return the first non-null argument in the list
Definition: SqlUtil.qm.dox.h:2161
hash cop_plus(any column1, any column2)
returns a hash for the "+" operator with the given arguments
hash cop_lower(any column)
returns a hash for the "lower" operator with the given argument; returns a column value in lower case...
int updateCommit(hash set, hash cond, reference sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
hash wop_or(hash h1, hash h2)
returns a hash with a fake "_OR_" column name; the list of arguments to the function is combined such...
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:7027
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:1984
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:5792
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3567
int del()
SqlUtil::AbstractTable::del() variant
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:4759
hash join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments for use when joining with a table other ...
string getSelectSql(*hash sh, *reference args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
string src
the source code
Definition: SqlUtil.qm.dox.h:5345
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:4915
hash cop_over(any column, string arg)
returns a hash for the "over" clause
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:2136
string src
the source of the object
Definition: SqlUtil.qm.dox.h:5380
hash join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments for use when joining with a table other...
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2086
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2041
hash cop_divide(any column1, any column2)
returns a hash for the "/" operator with the given arguments
hash op_ge(any arg)
returns a hash for the ">=" operator with the given argument for use in where clauses when comparing ...
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:7017
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:1992
hash op_not(hash arg)
returns a hash for the "not" operator; for use in where clauses
const OP_LE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3547
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2011
string name
the name of the index
Definition: SqlUtil.qm.dox.h:4912
hash cop_value(any arg)
returns a hash for the "value" (literal) operator with the given argument
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:5268
const OP_CLE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3577
hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5110
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:1988
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:2014
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3612
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:4918
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:5369
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:1990
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:6983
string name
the name of the column
Definition: SqlUtil.qm.dox.h:4741
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:5612
base class for functions
Definition: SqlUtil.qm.dox.h:5410
const COP_MULTIPLY
the SQL "multiply" operator
Definition: SqlUtil.qm.dox.h:2126
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:7025
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:2051
base class for views
Definition: SqlUtil.qm.dox.h:5334
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:5618
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
hash cop_prepend(any column, string arg)
returns a hash for the "prepend" operator with the given argument
string type
the type of object
Definition: SqlUtil.qm.dox.h:5377
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:2131
string string(softstring str, *string enc)
hash uop_divide(any arg, *hash nest)
returns a hash for the "/" operator with the given arguments
int size
the size of the column
Definition: SqlUtil.qm.dox.h:4750
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:4744
const COP_VALUE
to append a constant value (SQL Literal) to use as an output column value
Definition: SqlUtil.qm.dox.h:2061
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:4684
the base class for triggers
Definition: SqlUtil.qm.dox.h:5471
hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
hash op_eq(any arg)
returns a hash for the "=" operator with the given argument for use in where clauses when comparing c...
const OP_LT
the SQL less than (<) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3542
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:5614
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:5433
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst, UpsertInsertOnly, and UpsertUpdateOnly) ...
Definition: SqlUtil.qm.dox.h:6974
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:5542
the base class for column information
Definition: SqlUtil.qm.dox.h:4736
const COP_CAST
to convert column value into another datatype
Definition: SqlUtil.qm.dox.h:2046
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:6926
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3587
hash op_cle(string arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:6571
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:2805
hash cop_seq(string seq, *string as)
returns a hash for the "seq" operator with the given argument giving the sequence name whose value sh...
hash make_cop(string cop, any column, any arg)
returns a hash with cop, column, and arg keys
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2081
const UpsertSelectFirst
Upsert option: select first, if the row is unchanged, do nothing, if it doesn't exist, insert, otherwise update.
Definition: SqlUtil.qm.dox.h:6912
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:2141
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:6895
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:5342
*number max
the ending number
Definition: SqlUtil.qm.dox.h:5314
hash cop_upper(any column)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
hash uop_multiply(any arg, *hash nest)
returns a hash for the "*" operator with the given arguments
number increment
the increment
Definition: SqlUtil.qm.dox.h:5311
int update(hash set, hash cond, reference sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
const OP_LIKE
the SQL "like" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3537
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2022
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6576
const OP_CLT
the SQL less than (<) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:3572
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2111
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:5265
hash cop_year_day(any column)
returns a hash for the "year_day" operator with the given argument
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2166
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3060
const OP_SUBSTR
the SQL "substr" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3617
hash make_uop(string uop, any arg, *hash nest)
returns a hash with uop, arg, and nest keys
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...
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:2028
hash cop_year(any column)
returns a hash for the "year" operator with the given argument
number start
the starting number
Definition: SqlUtil.qm.dox.h:5308
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4076
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql, *hash opt)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:5660
hash cop_multiply(any column1, any column2)
returns a hash for the "*" operator with the given arguments
hash cop_seq_currval(string seq, *string as)
returns a hash for the "seq_currval" operator with the given argument giving the sequence name whose ...
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:5118
represents a primary key
Definition: SqlUtil.qm.dox.h:5202
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3050
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2071
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:2121
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:1978
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2005
hash op_ceq(string arg)
returns a hash for the "=" operator with the given argument for use in where clauses when comparing t...
*hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:5115
*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...
hash cop_year_hour(any column)
returns a hash for the "year_hour" operator with the given argument
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3623
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5193
hash cop_max(any column)
returns a hash for the "max" operator; returns maximum column values
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5021
hash cop_count(any column="")
returns a hash for the "count" operator; returns row counts
hash uop_seq(string seq)
returns a hash for the "seq" operator with the given argument giving the sequence name whose value sh...
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:4979
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2056