283 @warning Oracle:
using different comments in the same SQL can lead to
new optimizer statement hard parsing.
285 @anchor select_option_hint
286 @par Select Option
"hint"
287 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).
291 $table.selectRows( (
"hint" :
"full(t1)") );
293 will produce select statement like
this:
297 The
string is taken as is and it
's up to user to handle correct aliases in join functions etc.
298 @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
299 @warning Use hints only when you know what you are doing.
301 @anchor select_option_columns
302 @par Select Option "columns"
303 <b>Columns Example:</b>
305 my list $columns = ("id", "name", "started", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"));
306 my *list $rows = $table.selectRows(("columns": $columns, "where": ("type": "user")));
308 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
309 This option takes a list, each element of the list can be one of the following.\n\n
310 <b>A Simple String Giving a Column Name</b>\n
313 my *list $rows = $table.selectRows(("columns": ("id", "name", "started")));
315 <b>A String in Dot Notation</b>\n
316 This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
318 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner($table2, "t2", ("id": "altid"))));
320 <b>A Column Operation Specified by a Column Operator Function</b>\n
321 ex: <tt>cop_as("column_name", "column_alias")</tt> \n
322 See @ref sql_cop_funcs "column operator function" for more information on column operator functions
324 my *list $rows = $table.selectRows(("columns": ("id", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"))));
326 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
327 <b>The Value \c "*", Meaning All Columns</b>\n
330 my *list $rows = $table.selectRows(("columns": "*"));
332 This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
333 <b>An \c "*" in Dot Notation</b>\n
336 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.*"), "join": join_inner($table2, "t2", ("id": "altid"))));
339 @anchor select_option_where
340 @par Select Option "where"
341 <b>Where Example:</b>
343 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
345 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.
347 @anchor select_option_orderby
348 @par Select Option "orderby"
349 <b>Orderby Example:</b>
351 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date"));
353 This option is a list of the following values:
354 - a simple string giving a column name; ex: \c "name"
355 - 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"
357 - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
359 @anchor select_option_desc
360 @par Select Option "desc"
363 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date", "desc": True));
365 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
366 Otherwise, ordered results are returned in ascending order by default.
368 @anchor select_option_limit
369 @par Select Option "limit"
370 <b>Limit Example:</b>
372 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
374 This option will limit the number of rows returned.
376 - This option is required if the @ref select_option_offset "offset option" is non-zero
377 - 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
379 @anchor select_option_offset
380 @par Select Option "offset"
381 <b>Offset Example:</b>
383 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
385 This option specifies the row number offset for the rows returned where the first row is at offset zero.
387 - 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.
388 - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
391 @anchor select_option_join
392 @par Select Option "join"
395 my *list $rows = $table.selectRows(("columns": ("name", "version", "id", cop_as("st.value", "source"), cop_as("st.value", "offset")),
396 "join": join_left($function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
397 + join_left($function_instance_tags, "lt", NOTHING, ("st.tag": "_offset"))));
399 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).
400 @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
402 @see @ref joins for more examples
404 @anchor select_option_groupby
405 @par Select Option "groupby"
406 <b>Groupby Example:</b>
408 my *list $rows = $table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type"));
410 The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
411 The \c "groupby" hash key should be assigned to a list of column specifiers or a single column specifier. Column specifies for the \c "groupby"
412 key are strings giving column names, optionally in dot notation.
414 @anchor select_option_having
415 @par Select Option "having"
416 <b>Having Example:</b>
418 my *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)))));
420 The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
421 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.
423 @anchor select_option_superquery
424 @par Select Option "superquery"
425 <b>Superquery Example:</b>
427 my *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"))));
429 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
430 The above example results in an SQL command equivalent to the following:
432 my *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");
434 @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
436 @subsection sql_paging Select With Paging
438 There is support for paging query results in the following methods:
439 - @ref SqlUtil::Table::getRowIterator()
440 - @ref SqlUtil::Table::getSelectSql()
441 - @ref SqlUtil::Table::select()
442 - @ref SqlUtil::Table::selectRows()
444 @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
446 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.
448 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.
451 Select 100 rows starting at row 200 (the table's primary key will be used
for the \c
"orderby" option by
default): \n
453 my *
list $rows = $table.selectRows((
"where": (
"type":
"user"),
"limit": 100,
"offset": 200));
455 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:
457 $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));
461 $ds.vselectRows(
"select * from public.table where type = %v order by type limit %v offset %v", (
"user", 100, 200));
464 @subsection check_matching_rows Check For At Least One Matching Row
468 my *
hash $h = $table.findSingle(("account_type": "CUSTOMER"));
470 printf("found 1 customer row: %y\n", $l[0]);
473 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):
475 my *
hash $h = $table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
477 printf("found 1 customer row: %y\n", $l[0]);
480 @section inserting_data Inserting Data into the Database
482 The following methods can be used to insert data into the database:
483 - @ref SqlUtil::Table::insert(): inserts a single row into a table and commits the transaction
484 - @ref SqlUtil::Table::insertNoCommit(): inserts a single row into a table without committing the transaction
485 - @ref SqlUtil::Table::insertFromSelect(): 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
486 - @ref SqlUtil::Table::insertFromSelectNoCommit(): 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
488 @see @ref sql_upsert for information about upserting or merging data
490 @subsection inserting_data_explicitly Inserting Data Explicitly
494 $table.insert(("
id": $id, "name": $name, "created":
now_us()));
497 Data can be explicitly inserted into the database with immediate values with @ref SqlUtil::Table::insert() and @ref SqlUtil::Table::insertNoCommit() as in the above example.
499 @subsection inserting_data_from_select Inserting Data From a Select Statement
503 my
int $rows = $table.insertFromSelect(("
id", "name", "created"), $source_table, (("columns": ("cid", "fullname", "created"), "where": ("
type": "CUSTOMER"))));
506 Data can be inserted into the database based on the results of a select statement with @ref SqlUtil::Table::insertFromSelect() and @ref SqlUtil::Table::insertFromSelectNoCommit() as in the above example.
508 The example above would generate a %Qore SQL command like the following:
510 return $ds.vexec("insert into schema.table (
id,name,created) select cid,fullname,created from schema.source_table where
type = %v", ("CUSTOMER"));
513 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.
515 @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
517 To insert data from an iterator source (such as an @ref Qore::SQL::SQLStatement
object), call @ref SqlUtil::Table::insertFromIterator() or @ref SqlUtil::Table::insertFromIteratorNoCommit() as in the following example:
521 # get the rows to be inserted
522 my
list $l = get_table_rows();
523 # insert the data and commit after every 5000 rows
524 $table.insertFromIterator($l.iterator(), (
"commit_block": 5000));
527 The iterator given to the @ref
SqlUtil::Table::insertFromIterator() or @ref SqlUtil::Table::insertFromIteratorNoCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "
hash".
529 @note the @ref SqlUtil::AbstractTable::InsertOptions "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
531 @section updating_data Updating Data
533 The following methods can be used to update data:
534 - @ref SqlUtil::Table::update(): updates a single row and commits the transaction
535 - @ref SqlUtil::Table::updateNoCommit(): updates a single row and does not commit the transaction
539 my
int $rows_updated = t.update(("permission_type":
uop_append("-migrated",
uop_lower())));
542 The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
544 return $ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
546 And the following on MySQL:
548 return $ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
551 @section deleting_data Deleting Data
553 The following methods can be used to dekete data:
554 - @ref SqlUtil::Table::del(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
555 - @ref SqlUtil::Table::delNoCommit(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
556 - @ref SqlUtil::Table::truncate(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource
object
557 - @ref SqlUtil::Table::truncateNoCommit(): truncates the table and does not commit the transaction
561 my
int $dcnt = $table.del(("record_type": "OLD-CUSTOMER"));
564 The above example would generate a %Qore SQL command like the following:
566 return $ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
569 The @ref SqlUtil::Table::del() and @ref SqlUtil::Table::delNoCommit() methods can be used to delete data from the database.
571 See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
573 @section joins Joining Tables
575 Joining tables is made by providing a
join specification to the @ref select_option_join "
join select option" in
576 a @ref select_option_hash "select option
hash" as in the following example:
578 my *
list $rows = $table.selectRows(("columns": ("table.
id", "t2.customer_name"), "
join":
join_inner($table2, "t2", ("
id": "altid"))));
580 In the above example, \a table is joined with \a table2 on <tt>table.
id = table2.altid</tt>.
582 Joins on multiple tables are performed by combining the results of @ref sql_op_funcs "
join functions" with the @ref plus_operator "+ operator"
587 In the above example, \a table is joined with \a table2 on <tt>table.
id = table2.altid</tt> and with \a table3 on an
588 automatically detected primary key to foreign key relationship between the two tables.
590 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
591 argument to the @ref sql_op_funcs "
join function" as in the following example:
595 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
596 with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
598 @see @ref select_option_join "
join select option"
600 @section where_clauses Where Clauses
602 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:
603 - @ref SqlUtil::Table::del()
604 - @ref SqlUtil::Table::delNoCommit()
605 - @ref SqlUtil::Table::findAll()
606 - @ref SqlUtil::Table::findSingle()
607 - @ref SqlUtil::Table::getRowIterator()
608 - @ref SqlUtil::Table::getSelectSql()
609 - @ref SqlUtil::Table::insertFromSelect()
610 - @ref SqlUtil::Table::insertFromSelectNoCommit()
611 - @ref SqlUtil::Table::select()
612 - @ref SqlUtil::Table::selectRow()
613 - @ref SqlUtil::Table::selectRows()
614 - @ref SqlUtil::Table::update()
615 - @ref SqlUtil::Table::updateNoCommit()
616 - @ref SqlUtil::Table::upsertFromSelect()
617 - @ref SqlUtil::Table::upsertFromSelectNoCommit()
619 @note the above
list also applies to the corresponding @ref SqlUtil::AbstractTable methods
621 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", then 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".
623 The where condition
hash has the following format:
624 - each key gives a column name or a table/alias with column name in dot notation
625 - 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
627 @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 my
hash $w = ("0:created":
op_ge($mindate), "1:created":
op_lt($maxdate)); @endcode
629 See @ref sql_op_funcs for a
list of operator functions.
631 @par Where
Hash Example:
635 "account_type":
op_like("%CUSTOMER%"),
639 The preceding example results in a where clause equivalent to: \c "name = 'Smith' and
type like '%CUSTOMER%' and
id >= 500", except
640 that bind by value is used, so, if used in a context like the following:
642 my Table $t($ds, "table");
643 my *
hash $qh = $t.select(("where": $w));
645 the complete query would look instead as follows:
647 $ds.vselect("select * from table where name = %v and account_type like %v and
id >= %v", ("Smith", "%CUSTOMER%", 500));
651 @par Where
List Example:
655 "account_type":
op_like("%CUSTOMER%"),
660 "account_type":
op_like("%VENDOR%"),
663 my Table $t($ds, "table");
664 my *
hash $qh = $t.select(("where": ($w1, $w2)));
666 the complete query would look instead as follows:
668 $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));
672 Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
674 my *
hash $row = $table.findSingle(("permission_type":
op_between("US", "UX")));
676 resulting in an internal SQL command that looks as follows (depending on the database):
678 my *
hash $row = $ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
680 Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
682 my
int $row_count = $table.del(("name":
op_like("%Smith%")));
684 resulting in an internal SQL command that looks as follows:
686 $ds.vexec("delete from table where name like %v", ("%Smith%"));
688 Find all rows where \c "
id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
690 my *
list $rows = $table.findAll(("
id":
op_gt(100), "created": op_gt(2013-03-01)));
692 resulting in an internal SQL command that looks as follows:
694 $ds.vexec("select * from table where
id > %v and created > %v", (100, 2013-03-01));
697 @section sql_upsert Upserting or Merging Data
699 This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
700 - @ref SqlUtil::Table::upsert()
701 - @ref SqlUtil::Table::upsertNoCommit()
702 - @ref SqlUtil::Table::getUpsertClosure()
703 - @ref SqlUtil::Table::getUpsertClosureWithValidation()
704 - @ref SqlUtil::Table::upsertFromIterator()
705 - @ref SqlUtil::Table::upsertFromIteratorNoCommit()
706 - @ref SqlUtil::Table::upsertFromSelect()
707 - @ref SqlUtil::Table::upsertFromSelectNoCommit()
709 @subsection sql_upsert_single Upsert a Single Row
713 $table.upsert(("
id": $id, "name": $name, "account_type": $account_type));
716 To upsert or merge a single row in the database, call @ref SqlUtil::Table::upsert() or @ref SqlUtil::Table::upsertNoCommit() with the
717 single row to be upserted or merged as a
hash as in the preceding example.
719 @subsection sql_upsert_many Upserting Many Rows Using An Upsert
Closure
721 To upsert or merge many rows by using an upsert closure, call @ref SqlUtil::Table::getUpsertClosure() or @ref SqlUtil::Table::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.
725 # get the rows to be inserted
726 my
list $l = get_table_rows();
729 my code $upsert = $table.getUpsertClosure($l[0]);
731 on_success $ds.commit();
732 on_error $ds.rollback();
734 # loop through the reference data rows
739 @par Complex Example With Callbacks:
741 # set the upsert strategy depending on the use case
742 my
int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
744 # hash summarizing changes
747 # get the rows to be inserted
748 my
list $l = get_table_rows();
751 # get the upsert closure to use based on the first row to be inserted
752 my code $upsert = $table.getUpsertClosure($l[0], $upsert_strategy);
754 on_success $ds.commit();
755 on_error $ds.rollback();
757 # loop through the reference data rows
758 foreach my
hash $h in ($l) {
759 my
int $code = $upsert($h);
760 if ($code == AbstractTable::UR_Unchanged)
763 my
string $change = AbstractTable::UpsertResultMap{$code};
770 else if ($verbose > 1)
771 printf(
"*** reference data %s: %y: %s\n", $table.getName(), $h, $change);
776 printf(
"*** reference data %s: %s\n", $table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), $sh.pairIterator())));
778 printf(
"*** reference data %s: OK\n", $table.getName());
782 @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
788 # get the rows to be inserted
789 my
list $l = get_table_rows();
790 $table.upsertFromIterator($l.iterator());
793 @par Complex Example With Callbacks:
795 # set the upsert strategy depending on the use case
796 my
int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
798 # get the rows to be inserted
799 my
list $l = get_table_rows();
801 my code $callback = sub (
string $table_name,
hash $row,
int $result) {
802 if ($result == AbstractTable::UR_Unchanged)
804 my
string $change = AbstractTable::UpsertResultMap{$result};
806 printf(
"*** reference data %s: %y: %s\n", $table_name, $row, $change);
809 my
hash $sh = $table.upsertFromIterator($l.iterator(), $upsert_strategy,
False, (
"info_callback": $callback,
"commit_block": 5000));
811 printf(
"*** reference data %s: %s\n", $table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), $sh.pairIterator())));
813 printf(
"*** reference data %s: OK\n", $table.getName());
816 The iterator given to the @ref
SqlUtil::Table::upsertFromIterator() or @ref SqlUtil::Table::upsertFromIteratorNoCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "
hash".
818 @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
820 @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
822 To upsert or merge many rows from a select statement, use @ref SqlUtil::Table::upsertFromSelect() or @ref SqlUtil::Table::upsertFromSelectNoCommit() as in the following example:
826 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")));
829 @par Complex Example With Callbacks:
831 # set the upsert strategy depending on the use case
832 my
int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
834 my code $callback = sub (
string $table_name,
hash $row,
int $result) {
835 if ($result == AbstractTable::UR_Unchanged)
837 my
string $change = AbstractTable::UpsertResultMap{$result};
839 printf(
"*** reference data %s: %y: %s\n", $table_name, $row, $change);
842 my
hash $sh = $table.upsertFromSelect($table2, (
"where": (
"account_type":
"CUSTOMER")), $upsert_strategy, False, (
"info_callback": $callback,
"commit_block": 5000));
844 printf(
"*** reference data %s: %s\n", $table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), $sh.pairIterator())));
846 printf(
"*** reference data %s: OK\n", $table.getName());
849 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).
851 @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
853 @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
855 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.
857 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.
861 # get the rows to be inserted
862 my list $l = get_table_rows();
863 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
866 @par Complex Example With Callbacks:
868 # set the upsert strategy depending on the use case
869 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
871 # get the rows to be inserted
872 my list $l = get_table_rows();
874 my code $callback = sub (string $table_name, hash $row, int $result) {
875 if ($result == AbstractTable::UR_Unchanged)
877 my string $change = AbstractTable::UpsertResultMap{$result};
879 printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
882 my hash $sh = $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), $upsert_strategy, ("delete_others": True, "info_callback": $callback, "commit_block": 5000));
884 printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
886 printf("*** reference data %s: OK\n", $table.getName());
889 @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
891 @subsection sql_upsert_strategies Upsert Strategies
892 The approach used is based on one of the following strategies (see @ref upsert_options):
893 - @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
894 - @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
895 - @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
1582 /* @defgroup DBFeaturesConstants DB Features Constants
1583 These constants can be used as a lookup values in AbstractDatabase::features() method.
1589 const DB_FUNCTIONS = "functions";
1591 const DB_MVIEWS = "materialized views";
1593 const DB_PACKAGES = "packages";
1595 const DB_PROCEDURES = "procedures";
1597 const DB_SEQUENCES = "sequences";
1599 const DB_TABLES = "tables";
1601 const DB_TYPES = "named types";
1603 const DB_VIEWS = "views";
1607 /* @defgroup SqlTypeConstants SQL Type Constants
1608 These constants can be used for the \c "qore_type" values when creating columns to specify additional SQL column types
1611 const VARCHAR = "string";
1615 const NUMERIC = "number";
1618 const CHAR = "char";
1621 const BLOB = "blob";
1624 const CLOB = "clob";
1651 const COP_AS = "as";
1654 /** @see cop_prepend()
1656 const COP_PREPEND = "prepend";
1659 /** @see cop_append()
1661 const COP_APPEND = "append";
1664 /** @see cop_value()
1666 const COP_VALUE = "value";
1669 /** @see cop_upper()
1671 const COP_UPPER = "upper";
1674 /** @see cop_lower()
1676 const COP_LOWER = "lower";
1679 /** @see cop_distinct
1681 const COP_DISTINCT = "distinct";
1686 const COP_MIN = "min";
1691 const COP_MAX = "max";
1696 const COP_AVG = "avg";
1701 const COP_COUNT = "count";
1706 const COP_OVER = "over";
1709 /** @see cop_minus()
1711 const COP_MINUS = "minus";
1716 const COP_PLUS = "plus";
1719 /** @see cop_divide()
1721 const COP_DIVIDE = "divide";
1724 /** @see cop_multiply()
1726 const COP_MULTIPLY = "multiply";
1731 const COP_YEAR = "year";
1734 /** @see cop_year_month()
1736 const COP_YEAR_MONTH = "year_month";
1739 /** @see cop_year_day()
1741 const COP_YEAR_DAY = "year_day";
1744 /** @see cop_year_hour()
1746 const COP_YEAR_HOUR = "year_hour";
1749 const DefaultCopMap = (
1751 "arg": Type::String,
1752 "code": string (string cve, string arg) {
1753 return sprintf("%s as %s", cve, arg);
1757 "arg": Type::String,
1759 "code": string (string cve, string arg) {
1760 return sprintf("%s||%s", arg, cve);
1764 "arg": Type::String,
1766 "code": string (string cve, string arg) {
1767 return sprintf("%s||%s", cve, arg);
1773 "code": string (*string cve, any arg) {
1778 "code": string (string cve, any arg) {
1779 return sprintf("upper(%s)", cve);
1783 "code": string (string cve, any arg) {
1784 return sprintf("lower(%s)", cve);
1788 "code": string (string cve, any arg) {
1789 return sprintf("distinct %s", cve);
1793 "code": string (string cve, any arg) {
1794 return sprintf("min(%s)", cve);
1799 "code": string (string cve, any arg) {
1800 return sprintf("max(%s)", cve);
1805 "code": string (string cve, any arg) {
1806 return sprintf("avg(%s)", cve);
1812 "code": string (*string cve, any arg) {
1813 return sprintf("count(%s)", cve ? cve : "1");
1818 "code": string (string arg1, string arg2) {
1819 return sprintf("%s - %s", arg1, arg2);
1824 "code": string (string arg1, string arg2) {
1825 return sprintf("%s + %s", arg1, arg2);
1830 "code": string (string arg1, string arg2) {
1831 return sprintf("%s / %s", arg1, arg2);
1836 "code": string (string arg1, string arg2) {
1837 return sprintf("%s * %s", arg1, arg2);
1859 /** @param cop the column operator (one of @ref sql_cops)
1861 @param column the column name
1862 @param arg the argument to the operator
1864 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1866 @note Normally this function is not called directly, but rather by the other column operator functions
1868 hash make_cop(string cop, any column, any arg);
1874 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_as("errors", "error_count")), "where": ("type": "user")));
1877 @param column the column specification for the column (string name or dot notation for use in joins)
1878 @param arg the new name of the output column
1880 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1882 hash cop_as(any column, string arg);
1888 my *list $rows = $table.selectRows(("columns": ("id", cop_prepend("name", "migrated-")), "where": ("type": "user")));
1891 @param column the column specification for the column (string name or dot notation for use in joins)
1892 @param arg the text to prepend to the row values in the output column
1894 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1896 hash cop_prepend(any column, string arg);
1902 my *list $rows = $table.selectRows(("columns": ("id", cop_append("name", "-migrated")), "where": ("type": "user")));
1905 @param column the column specification for the column (string name or dot notation for use in joins)
1906 @param arg the text to append (ie concatenate) to the row values in the output column
1908 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1910 hash cop_append(any column, string arg);
1916 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_value(100)), "where": ("type": "user")));
1919 @param arg the value to be returned in the column
1921 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1923 hash cop_value(any arg);
1929 my *list $rows = $table.selectRows(("columns": ("id", cop_upper("name")), "where": ("type": "user")));
1932 @param column the column specification for the column (string name or dot notation for use in joins)
1934 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1936 hash cop_upper(any column);
1942 my *list $rows = $table.selectRows(("columns": ("id", cop_lower("name")), "where": ("type": "user")));
1945 @param column the column specification for the column (string name or dot notation for use in joins)
1947 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1949 hash cop_lower(any column);
1955 my *list $rows = $table.selectRows(("columns": ("id", cop_distinct("name")), "where": ("type": "user")));
1958 @param column the column specification for the column (string name or dot notation for use in joins)
1960 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1962 hash cop_distinct(any column);
1968 my *list $rows = $table.selectRows(("columns": (cop_min("id")), "where": ("type": "user")));
1971 @param column the column specification for the column (string name or dot notation for use in joins)
1973 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1975 hash cop_min(any column);
1981 my *list $rows = $table.selectRows(("columns": (cop_max("id")), "where": ("type": "user")));
1984 @param column the column specification for the column (string name or dot notation for use in joins)
1986 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1988 hash cop_max(any column);
1994 my *list $rows = $table.selectRows(("columns": (cop_avg("quantity")), "where": ("order_type": "wholesale")));
1997 @param column the column specification for the column (string name or dot notation for use in joins)
1999 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2001 hash cop_avg(any column);
2007 my *list $rows = $table.selectRows(("columns": ("account_type", cop_count()), "where": ("type": "user"), "groupby": "account_type"));
2010 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2012 hash cop_count(string column = "");
2018 my *list $rows = $table.selectRows(("columns": ("account_type", cop_count(), cop_as(cop_over(cop_max("qty"), "account_id"), "max_qty_per_account")), "where": ("type": "user"), "groupby": "account_type"));
2021 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2023 hash cop_over(any column, string arg);
2029 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_minus("complete_count", "error_count")), "where": ("type": "user")));
2032 @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2033 @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2034 @param arg the new name of the output column
2036 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2038 hash cop_minus(any column1, any column2);
2044 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_plus("complete_count", "error_count")), "where": ("type": "user")));
2047 @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2048 @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2049 @param arg the new name of the output column
2051 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2053 hash cop_plus(any column1, any column2);
2059 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_divide("complete_count", "error_count")), "where": ("type": "user")));
2062 @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2063 @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2064 @param arg the new name of the output column
2066 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2068 hash cop_divide(any column1, any column2);
2074 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_multiply("complete_count", "error_count")), "where": ("type": "user")));
2077 @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2078 @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2079 @param arg the new name of the output column
2081 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2083 hash cop_multiply(any column1, any column2);
2089 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year("error_time")), "where": ("type": "user")));
2092 @param column the column specification for the column (string name or dot notation for use in joins)
2094 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2096 hash cop_year(any column);
2102 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year_month("error_time")), "where": ("type": "user")));
2105 @param column the column specification for the column (string name or dot notation for use in joins)
2107 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2109 hash cop_year_month(any column);
2115 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year_day("error_time")), "where": ("type": "user")));
2118 @param column the column specification for the column (string name or dot notation for use in joins)
2120 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2122 hash cop_year_day(any column);
2128 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year_hour("error_time")), "where": ("type": "user")));
2131 @param column the column specification for the column (string name or dot notation for use in joins)
2133 @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2135 hash cop_year_hour(any column);
2142 const DefaultUopMap = (
2165 /** @param uop the update operator (one of @ref sql_uops)
2167 @param arg the argument to the operator
2168 @param nest any nested operation to the operator
2170 @return an update operator description hash corresponding to the arguments for use in update statements
2172 @note Normally this function is not called directly, but rather by the other update operator functions
2174 hash make_uop(string uop, any arg, *hash nest);
2180 my int $rows_updated = t.update(("permission_type": uop_prepend("migrated-", uop_lower())));
2183 @param arg the text to prepend to the row values in the output column
2184 @param nest any nested operation to the operator
2186 @return an update operator description hash corresponding to the arguments for use in update statements
2188 hash uop_prepend(string arg, *hash nest);
2194 my int $rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
2197 @param arg the text to prepend to the row values in the output column
2198 @param nest any nested operation to the operator
2200 @return an update operator description hash corresponding to the arguments for use in update statements
2202 hash uop_append(string arg, *hash nest);
2208 my int $rows_updated = t.update(("permission_type": uop_upper()));
2211 @param nest any nested operation to the operator
2213 @return an update operator description hash corresponding to the arguments for use in update statements
2215 hash uop_upper(*hash nest);
2221 my int $rows_updated = t.update(("permission_type": uop_lower()));
2224 @param nest any nested operation to the operator
2226 @return an update operator description hash corresponding to the arguments for use in update statements
2228 hash uop_lower(*hash nest);
2238 /** @see join_inner()
2241 const JOP_INNER = "inner";
2244 /** @see join_left()
2246 const JOP_LEFT = "left";
2249 /** @see join_right()
2251 const JOP_RIGHT = "right";
2256 JOP_LEFT: "left outer",
2257 JOP_RIGHT: "right outer",
2274 hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
2278 /** @par Example With Explicit Join Columns:
2280 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid"))));
2283 @par Example With Implicit Join Columns:
2284 (using an automatically detected foreign key to primary key constraint)
2286 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2289 @param table the table to join with
2290 @param alias the alias for \a table in the query
2291 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2292 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2293 @param opt optional join options (for example, to specify a partition for the join if supported)
2295 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2297 hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2301 /** @par Example With Explicit Join Columns:
2303 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid"))));
2306 @par Example With Implicit Join Columns:
2307 (using an automatically detected foreign key to primary key constraint)
2309 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2312 @param table the table to join with
2313 @param alias the alias for \a table in the query
2314 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2315 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2316 @param opt optional join options (for example, to specify a partition for the join if supported)
2318 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2320 hash join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2324 /** @par Example With Explicit Join Columns:
2326 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner("t2", $table3)));
2329 @par Example With Implicit Join Columns:
2330 (using an automatically detected foreign key to primary key constraint)
2332 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2335 @param ta the table name or alias of the other table to join with when not joining with the primary table
2336 @param table the table to join with
2337 @param alias the alias for \a table in the query
2338 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2339 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2340 @param opt optional join options (for example, to specify a partition for the join if supported)
2342 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2344 hash join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2348 /** @par Example With Explicit Join Columns:
2350 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner("t2", $table3)));
2353 @par Example With Implicit Join Columns:
2354 (using an automatically detected foreign key to primary key constraint)
2356 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2359 @param ta the table name or alias of the other table to join with when not joining with the primary table
2360 @param table the table to join with
2361 @param alias the alias for \a table in the query
2362 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2363 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2364 @param opt optional join options (for example, to specify a partition for the join if supported)
2366 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2368 hash join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2372 /** @par Example With Explicit Join Columns:
2374 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2377 @par Example With Implicit Join Columns:
2378 (using an automatically detected foreign key to primary key constraint)
2380 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2383 @param table the table to join with
2384 @param alias the alias for \a table in the query
2385 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2386 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2387 @param opt optional join options (for example, to specify a partition for the join if supported)
2389 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2391 hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2395 /** @par Example With Explicit Join Columns:
2397 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2400 @par Example With Implicit Join Columns:
2401 (using an automatically detected foreign key to primary key constraint)
2403 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2406 @param table the table to join with
2407 @param alias the alias for \a table in the query
2408 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2409 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2410 @param opt optional join options (for example, to specify a partition for the join if supported)
2412 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2414 hash join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2418 /** @par Example With Explicit Join Columns:
2420 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2423 @par Example With Implicit Join Columns:
2424 (using an automatically detected foreign key to primary key constraint)
2426 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2429 @param ta the table name or alias of the other table to join with when not joining with the primary table
2430 @param table the table to join with
2431 @param alias the alias for \a table in the query
2432 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2433 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2434 @param opt optional join options (for example, to specify a partition for the join if supported)
2436 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2438 hash join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2442 /** @par Example With Explicit Join Columns:
2444 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2447 @par Example With Implicit Join Columns:
2448 (using an automatically detected foreign key to primary key constraint)
2450 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2453 @param ta the table name or alias of the other table to join with when not joining with the primary table
2454 @param table the table to join with
2455 @param alias the alias for \a table in the query
2456 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2457 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2458 @param opt optional join options (for example, to specify a partition for the join if supported)
2460 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2462 hash join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2466 /** @par Example With Explicit Join Columns:
2468 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2471 @par Example With Implicit Join Columns:
2472 (using an automatically detected foreign key to primary key constraint)
2474 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2477 @param table the table to join with
2478 @param alias the alias for \a table in the query
2479 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2480 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2481 @param opt optional join options (for example, to specify a partition for the join if supported)
2483 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2485 hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2489 /** @par Example With Explicit Join Columns:
2491 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2494 @par Example With Implicit Join Columns:
2495 (using an automatically detected foreign key to primary key constraint)
2497 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2500 @param table the table to join with
2501 @param alias the alias for \a table in the query
2502 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2503 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2504 @param opt optional join options (for example, to specify a partition for the join if supported)
2506 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2508 hash join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2512 /** @par Example With Explicit Join Columns:
2514 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2517 @par Example With Implicit Join Columns:
2518 (using an automatically detected foreign key to primary key constraint)
2520 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2523 @param ta the table name or alias of the other table to join with when not joining with the primary table
2524 @param table the table to join with
2525 @param alias the alias for \a table in the query
2526 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2527 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2528 @param opt optional join options (for example, to specify a partition for the join if supported)
2530 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2532 hash join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2536 /** @par Example With Explicit Join Columns:
2538 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2541 @par Example With Implicit Join Columns:
2542 (using an automatically detected foreign key to primary key constraint)
2544 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2547 @param ta the table name or alias of the other table to join with when not joining with the primary table
2548 @param table the table to join with
2549 @param alias the alias for \a table in the query
2550 @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2551 @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2552 @param opt optional join options (for example, to specify a partition for the join if supported)
2554 @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2556 hash join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2567 const OP_LIKE = "like";
2602 const OP_CLT = "C<";
2607 const OP_CLE = "C<=";
2612 const OP_CGT = "C>";
2617 const OP_CGE = "C>=";
2622 const OP_CNE = "C!=";
2627 const OP_CEQ = "C=";
2630 /** @see op_between()
2632 const OP_BETWEEN = "between";
2642 const OP_NOT = "not";
2645 const DefaultOpMap = (
2647 "code": string (object t, string cn, any arg, reference args) {
2649 return sprintf("%s like %v", cn);
2653 "code": string (object t, string cn, any arg, reference args) {
2655 return sprintf("%s < %v", cn);
2659 "code": string (object t, string cn, any arg, reference args) {
2661 return sprintf("%s <= %v", cn);
2665 "code": string (object t, string cn, any arg, reference args) {
2667 return sprintf("%s > %v", cn);
2671 "code": string (object t, string cn, any arg, reference args) {
2673 return sprintf("%s >= %v", cn);
2677 "code": string (object t, string cn, any arg, reference args) {
2678 if (arg === NULL || !exists arg)
2679 return sprintf("%s is not null", cn);
2681 return sprintf("%s != %v", cn);
2685 "code": string (object t, string cn, any arg, reference args) {
2686 if (arg === NULL || !exists arg)
2687 return sprintf("%s is null", cn);
2689 return sprintf("%s = %v", cn);
2693 "code": string (object t, string cn, any arg, reference args) {
2696 return sprintf("%s between %v and %v", cn);
2700 "code": string (object t, string cn, any arg, reference args) {
2701 *string ins = (foldl $1 + "," + $2, (map t.getSqlValue($1), arg));
2702 return ins ? sprintf("%s in (%s)", cn, ins) : "1 != 1";
2707 "code": string (object t, string cn, any arg, reference args) {
2708 return sprintf("not (%s)", cn);
2713 "code": string (object t, string cn, any arg, reference args) {
2714 return sprintf("%s < %s", cn, arg);
2719 "code": string (object t, string cn, any arg, reference args) {
2720 return sprintf("%s <= %s", cn, arg);
2725 "code": string (object t, string cn, any arg, reference args) {
2726 return sprintf("%s > %s", cn, arg);
2731 "code": string (object t, string cn, any arg, reference args) {
2732 return sprintf("%s >= %s", cn, arg);
2737 "code": string (object t, string cn, any arg, reference args) {
2738 return sprintf("%s != %s", cn, arg);
2743 "code": string (object t, string cn, string arg, reference args) {
2744 return sprintf("%s = %s", cn, arg);
2770 hash make_op(string op, any arg);
2777 my *list $rows = $table.selectRows(("where": ("name": op_like("%smith%"))));
2780 @param str the argument for the operator
2782 @return a where operation description hash for use in @ref where_clauses "where clauses"
2784 hash op_like(string str);
2790 my *list $rows = $table.selectRows(("where": ("name": op_lt("Zebra"))));
2793 @param arg the argument for the operator
2795 @return a where operation description hash for use in @ref where_clauses "where clauses"
2797 @see op_clt() for a function to be used when comparing two column values
2799 hash op_lt(any arg);
2805 my *list $rows = $table.selectRows(("where": ("name": op_le("Zebra"))));
2808 @param arg the argument for the operator
2810 @return a where operation description hash for use in @ref where_clauses "where clauses"
2812 @see op_cle() for a function to be used when comparing two column values
2814 hash op_le(any arg);
2820 my *list $rows = $table.selectRows(("where": ("name": op_gt("Apple"))));
2823 @param arg the argument for the operator
2825 @return a where operation description hash for use in @ref where_clauses "where clauses"
2827 @see op_cgt() for a function to be used when comparing two column values
2829 hash op_gt(any arg);
2835 my *list $rows = $table.selectRows(("where": ("name": op_ge("Apple"))));
2838 @param arg the argument for the operator
2840 @return a where operation description hash for use in @ref where_clauses "where clauses"
2842 @see op_cge() for a function to be used when comparing two column values
2844 hash op_ge(any arg);
2850 my *list $rows = $table.selectRows(("where": ("name": op_ne("Smith"))));
2853 @param arg the argument for the operator
2855 @return a where operation description hash for use in @ref where_clauses "where clauses"
2857 @see op_cne() for a function to be used when comparing two column values
2859 hash op_ne(any arg);
2865 my *list $rows = $table.selectRows(("where": ("name": op_eq("Smith"))));
2868 @param arg the argument for the operator
2870 @return a where operation description hash for use in @ref where_clauses "where clauses"
2872 @see op_ceq() for a function to be used when comparing two column values
2874 hash op_eq(any arg);
2880 my *list $rows = $table.selectRows(("where": ("name": op_between("US", "UX"))));
2883 @param l the lower bound for the \c "between" operator
2884 @param r the upper bound for the \c "between" operator
2886 @return a where operation description hash for use in @ref where_clauses "where clauses"
2888 @throw BETWEEN-ERROR one or both of the required arguments are @ref null or @ref nothing
2890 hash op_between(any l, any r);
2896 my *list $rows = $table.selectRows(("where": ("name": op_in(200, 300, 500, 9))));
2899 @return a where operation description hash for use in @ref where_clauses "where clauses"
2907 my *list $rows = $table.selectRows(("where": ("name": op_in($idlist))));
2910 @param args a list of values for the \c "in" operator
2912 @return a where operation description hash for use in @ref where_clauses "where clauses"
2914 hash op_in(list args);
2920 my *list $rows = $table.selectRows(("where": ("name": opt_not(op_in(200, 300, 500, 9))))_;
2923 @return a where operation description hash for use in @ref where_clauses "where clauses"
2925 hash op_not(hash arg);
2931 my *list $rows = $table.selectRows(("where": ("name": op_clt("other_name"))));
2934 @param arg the name of the column to compare against
2936 @return a where operation description hash for use in @ref where_clauses "where clauses"
2938 @see op_lt() for a function to be used when comparing a column against an immediate value
2940 hash op_clt(string arg);
2946 my *list $rows = $table.selectRows(("where": ("name": op_cle("other_name"))));
2949 @param arg the name of the column to compare against
2951 @return a where operation description hash for use in @ref where_clauses "where clauses"
2953 @see op_le() for a function to be used when comparing a column against an immediate value
2955 hash op_cle(string arg);
2961 my *list $rows = $table.selectRows(("where": ("name": op_cgt("other_name"))));
2964 @param arg the name of the column to compare against
2966 @return a where operation description hash for use in @ref where_clauses "where clauses"
2968 @see op_gt() for a function to be used when comparing a column against an immediate value
2970 hash op_cgt(string arg);
2976 my *list $rows = $table.selectRows(("where": ("name": op_cge("other_name"))));
2979 @param arg the name of the column to compare against
2981 @return a where operation description hash for use in @ref where_clauses "where clauses"
2983 @see op_ge() for a function to be used when comparing a column against an immediate value
2985 hash op_cge(string arg);
2991 my *list $rows = $table.selectRows(("where": ("name": op_cne("other_name"))));
2994 @param arg the name of the column to compare against
2996 @return a where operation description hash for use in @ref where_clauses "where clauses"
2998 @see op_ne() for a function to be used when comparing a column against an immediate value
3000 hash op_cne(string arg);
3006 my *list $rows = $table.selectRows(("where": ("name": op_ceq("other_name"))));
3009 @param arg the name of the column to compare against
3011 @return a where operation description hash for use in @ref where_clauses "where clauses"
3013 @see op_eq() for a function to be used when comparing a column against an immediate value
3015 hash op_ceq(string arg);
3020 class AbstractHashContainer {
3033 constructor(*hash nh);
3037 copy(AbstractHashContainer old);
3043 my any $v = $c.name;
3046 @param k the name of the key to access
3048 @return the value of the given key in the contained hash if it exists
3050 @throw KEY-ERROR the given key does not exist in the contained hash
3052 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3054 @see @ref memberGate_methods
3056 any memberGate(string k);
3070 abstract any take(string k);
3073 renameKey(string old_name, string new_name);
3083 my bool $b = $c.matchKeys($h);
3086 @param h1 the hash to compare
3088 @return @ref Qore::True "True" if the hash argument has the same keys (in any order), @ref Qore::False "False" if not
3090 bool matchKeys(hash h1);
3096 my bool $b = $c.matchKeys($l);
3099 @param l the hash to compare
3101 @return @ref Qore::True "True" if the list argument has the same list of key strings as the keys in the object (in any order), @ref Qore::False "False" if not
3103 bool matchKeys(list l);
3109 my bool $b = $c.matchKeys($c1);
3112 @param c the container to compare
3114 @return @ref Qore::True "True" if the container argument has the same keys (in any order), @ref Qore::False "False" if not
3116 bool matchKeys(AbstractHashContainer c);
3122 my bool $b = $c.partialMatchKeys($h);
3125 @param h1 the hash to compare
3127 @return @ref Qore::True "True" if the hash argument has at least the same keys (in any order, can have more keys), @ref Qore::False "False" if not
3129 bool partialMatchKeys(hash h1);
3135 my bool $b = $c.partialMatchKeys($l);
3138 @param l the list of strings to compare
3140 @return @ref Qore::True "True" if the list argument has at least the same keys (in any order, can have more keys), @ref Qore::False "False" if not
3142 bool partialMatchKeys(list l);
3148 my bool $b = $c.partialMatchKeys($c1);
3151 @param c the container to compare
3153 @return @ref Qore::True "True" if the container argument has at least the same keys (in any order, can have more keys), @ref Qore::False "False" if not
3155 bool partialMatchKeys(AbstractHashContainer c);
3161 my bool $b = $h.val();
3164 The opposite of empty()
3166 @return @ref Qore::False "False" if the contained hash has no keys, @ref Qore::True "True" if it does
3174 my list $l = $h.keys();
3177 @return a list of key names of the contained hash
3185 my list $l = $h.values();
3188 @return a list of values of the contained hash
3196 map printf("+ %y\n", $1.value), $h.iterator();
3199 @return a @ref Qore::HashIterator "HashIterator" object for the contained hash
3201 Qore::AbstractIterator iterator();
3207 map printf("+ %s\n", $1), $h.keyIterator();
3210 @return a @ref Qore::HashKeyIterator "HashKeyIterator" object for the contained hash
3212 Qore::AbstractIterator keyIterator();
3218 map printf("+ %s: %y\n", $1.key, $1.value), $h.pairIterator();
3221 @return a @ref Qore::HashPairIterator "HashPairIterator" object for the contained hash
3223 Qore::AbstractIterator pairIterator();
3233 my int $num = $h.size();
3236 @return the number of keys in the contained hash
3244 my bool $b = $h.hasKey($key);
3247 @param k the key name to check
3249 @return @ref Qore::True "True" if the key exists in the contained hash (may or may not be assigned a value), @ref Qore::False "False" if not
3251 bool hasKey(string k);
3257 my bool $b = $h.hasKeyValue($key);
3260 @param k the key name to check
3262 @return @ref Qore::True "True" if the key exists in the contained hash and is assigned a value, @ref Qore::False "False" if not
3264 bool hasKeyValue(string k);
3270 my *string $n = $h.firstKey();
3273 @return the first key name in the contained hash or @ref nothing if the contained hash has no keys
3283 my *string $n = $h.lastKey();
3286 @return the last key name in the contained hash or @ref nothing if the contained hash has no keys
3294 abstract string getElementName();
3298 class AbstractListContainer {
3311 constructor(softlist nl);
3317 my any $v = $c.get(2);
3320 @param i the index of the element to access
3322 @return the value of the given index in the contained list if it exists
3324 @throw ELEMENT-ERROR the given element does not exist in the contained list
3326 abstract any get(softint i);
3343 my bool $b = $l.val();
3346 The opposite of empty()
3348 @return @ref Qore::False "False" if the contained list is empty, @ref Qore::True "True" if not
3356 map printf("+ %s: %y\n", $1), $h.iterator();
3359 @return a @ref Qore::HashIterator "HashIterator" object for the contained hash
3361 Qore::ListIterator iterator();
3371 my int $num = $l.size();
3374 @return the number of elements in the contained list
3380 abstract string getElementName();
3390 class Tables : public AbstractHashContainer {
3398 constructor(AbstractDatasource ds, hash tables, *hash opt);
3402 constructor(AbstractDatasource ds);
3406 add(string k, Table val);
3410 add(string k, AbstractTable val);
3418 add(AbstractTable val);
3422 AbstractTable take(string k);
3426 populate(AbstractDatasource ds, hash tables, *hash opt);
3430 populate(AbstractDatasource ds);
3436 my *list $l = $tables.getDropAllForeignConstraintsOnTableSql($name);
3439 Make sure that all relevant tables are cached before calling this method; if the table is not cached, then @ref nothing is returned
3441 @param name the name of the table to find all the foreigjn constraints for
3442 @param opt a hash of options for the SQL strings; see @ref AbstractDatabase::DropSchemaOptions for common options; each driver can support additional driver-specific options
3444 @return a list of SQL strings that can be used to drop all the foreign constraints on a particular table
3446 @throw OPTION-ERROR invalid or unsupported option passed
3448 *list getDropAllForeignConstraintsOnTableSql(string name, *hash opt);
3454 my AbstractTable $t = $tables.table_name;
3457 @param k the name of the key to access
3459 @return the value of the given key in the contained hash if it exists
3461 @throw KEY-ERROR the given key does not exist in the contained hash
3463 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3465 @see @ref memberGate_methods
3467 AbstractTable memberGate(string k);
3471 string getElementName();
3475 *AbstractTable getIfExists(AbstractDatasource ds, string name);
3479 AbstractTable get(AbstractDatasource ds, string name);
3485 my *string $sql = $tables.getRenameTableIfExistsSql($old_name, $new_name);
3488 If the @ref sql_callback_executed "sql_callback_executed option key" is @ref Qore::True "True", this
3489 method also takes care of renaming internal foreign constraint references and source constraint references
3490 from unique keys for the renamed table (see @ref sql_callback_executed for more information).
3492 @param old_name the current name of the table
3493 @param new_name the new name of the table
3494 @param opts optional callback options; see @ref AbstractDatabase::CallbackOptions for more info
3496 @return an SQL string that can be used to rename the given table if it exists and the target does not exist, otherwise returns @ref nothing
3498 *string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts);
3504 $tables.tableRenamed($old, $new);
3507 @param old_name the current name of the table
3508 @param new_name the new name of the table
3509 @param old_sql_name the old full SQL name of the table (ie the value returned by @ref SqlUtil::AbstractTable::getSqlName())
3511 @return @ref Qore::True "True" if the table was renamed internally, @ref Qore::False "False" if not
3513 bool tableRenamed(string old_name, string new_name, string old_sql_name);
3518 tableRenamedIntern(string old_name, string new_name, string oldsn);
3525 my *string $sql = $tables.getDropConstraintIfExistsSql("table", "pk_table");
3528 If the @ref sql_callback_executed "sql_callback_executed option key" is @ref Qore::True "True" and
3529 if the constraint to be dropped is a foreign constraint, then if any unique constraint is linked
3530 to this foreign constraint, the link is removed (see @ref sql_callback_executed for more information).
3532 @param tname the name of the table
3533 @param cname the name of the constraint to drop if it exists
3534 @param opts optional callback options; see @ref AbstractDatabase::CallbackOptions for more info
3536 @return an SQL string that can be used to drop an existing constraint on a table, if the table is not already cached or the constraint does not exist, then @ref nothing is returned
3538 *string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
3541 list getCreateList();
3544 Qore::AbstractIterator createIterator();
3550 my list $l = $tables.getDropList();
3554 @return a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
3562 map $1.drop(), $tables.getDropIterator();
3565 @return an iterator for a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
3567 Qore::AbstractIterator dropIterator();
3572 getDependencies(reference tdh, reference sdh, *reference th);
3578 class Columns : public AbstractHashContainer {
3581 constructor(*hash c);
3585 add(string k, AbstractColumn val);
3589 AbstractColumn take(string k);
3595 my AbstractColumn $c = $cols.id;
3598 @param k the name of the key to access
3600 @return the value of the given key in the contained hash if it exists
3602 @throw KEY-ERROR the given key does not exist in the contained hash
3604 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3606 @see @ref memberGate_methods
3608 AbstractColumn memberGate(string k);
3612 Columns subset(softlist l);
3616 string getElementName();
3620 bool equal(Columns cols);
3625 class AbstractColumn {
3652 constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string c);
3656 string getNativeTypeString();
3660 string getCreateSql();
3666 my list $l = $col.getCreateSql($t);
3669 @param t the AbstractTable object to modify
3671 @return a list of sql strings that can be used to add the column to an existing table
3673 abstract list getCreateSql(AbstractTable t);
3676 string getDropSql(string table_name);
3682 my list $l = $col.getModifySql($t, $newcol);
3685 The column names are assumed to be equal.
3687 @param t the AbstractTable object to modify
3688 @param c the new column definition
3690 @return a list of sql strings that can be used to modify the column to the new definition; if the column definitions are identical then an empty list is returned
3692 list getModifySql(AbstractTable t, AbstractColumn c, *hash opt);
3698 my string $str = $col.getRenameSql($t, "new_name");
3701 @param t the AbstractTable object to modify
3702 @param new_name the new name for the column
3704 @return a string that can be used to rename the column
3706 abstract string getRenameSql(AbstractTable t, string new_name);
3709 bool equal(AbstractColumn c);
3715 abstract bool equalImpl(AbstractColumn c);
3721 my list $l = $col.getModifySql($t, $newcol);
3724 The column names are assumed to be equal.
3726 @param t the AbstractTable object to modify
3727 @param c the new column definition
3729 @return a list of sql strings that can be used to modify the column to the new definition; if the column definitions are identical then an empty list is returned
3733 abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
3738 class NumericColumnInfo {
3747 constructor(softint n_scale = 0);
3751 string getNativeTypeString(string native_type, int precision);
3756 class Indexes : public AbstractHashContainer {
3759 constructor(*hash c);
3763 add(string k, AbstractIndex val);
3767 *AbstractIndex findEqual(AbstractIndex ix);
3771 AbstractIndex take(string k);
3777 my AbstractIndex $ix = $indexes.pk_jobs;
3780 @param k the name of the key to access
3782 @return the value of the given key in the contained hash if it exists
3784 @throw KEY-ERROR the given key does not exist in the contained hash
3786 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3788 @see @ref memberGate_methods
3790 AbstractIndex memberGate(string k);
3793 string getElementName();
3798 class AbstractIndex {
3815 *AbstractUniqueConstraint constraint;
3820 constructor(string n, bool u, hash c);
3828 bool hasColumn(string cname);
3832 abstract string getCreateSql(string table_name, *hash opt);
3835 string getDropSql(string table_name);
3839 bool equal(AbstractIndex ix);
3843 bool equalExceptName(AbstractIndex ix);
3847 abstract bool equalImpl(AbstractIndex ix);
3850 abstract string getRenameSql(string table_name, string new_name);
3853 setSupportingConstraint(AbstractUniqueConstraint c);
3857 setSupportingConstraint();
3861 *AbstractUniqueConstraint getSupportingConstraint();
3865 list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt);
3870 class Constraints : public AbstractHashContainer {
3873 constructor(*hash c);
3877 add(string k, AbstractConstraint val);
3881 AbstractConstraint take(string k);
3885 *AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk);
3891 my AbstractConstraint $ix = $constraints.uk_jobs;
3894 @param k the name of the key to access
3896 @return the value of the given key in the contained hash if it exists
3898 @throw KEY-ERROR the given key does not exist in the contained hash
3900 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3902 @see @ref memberGate_methods
3904 AbstractConstraint memberGate(string k);
3907 string getElementName();
3912 class AbstractConstraint {
3926 constructor(string n);
3938 abstract string getCreateSql(string table_name, *hash opt);
3941 string getDropSql(string table_name);
3945 abstract list getRenameSql(string table_name, string new_name);
3948 string getDisableSql(string table_name);
3952 string getEnableSql(string table_name, *hash opt);
3956 bool equal(AbstractConstraint c);
3962 abstract bool equalImpl(AbstractConstraint c);
3966 abstract bool setIndexBase(string ix);
3969 abstract clearIndex();
3972 bool hasColumn(string cname);
3977 class AbstractCheckConstraint : public AbstractConstraint {
3987 constructor(string n, string n_src);
3993 bool equalImpl(AbstractConstraint c);
3998 bool setIndexBase(string ix);
4007 class AbstractUniqueConstraint : public AbstractConstraint,public Columns {
4012 hash sourceConstraints;
4020 constructor(string n, *hash c, *string n_index);
4024 abstract string getCreateSql(string table_name, *hash opts);
4029 bool equalImpl(AbstractConstraint c);
4034 /** each element is a hash with the following keys:
4035 - \c fk: the AbstractForeignConstraint object
4036 - \c table: the table name
4038 Qore::AbstractIterator getSourceConstraintIterator();
4042 hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts);
4046 findMatchingIndex(*Indexes indexes);
4052 $uk.addSourceConstraint($table_name, constraint_name);
4055 @param tname the name of the source table
4056 @param fk the source constraint
4058 @throw SOURCE-CONSTRAINT-ERROR a different source constraint with the given name already exists
4060 addSourceConstraint(string tname, AbstractForeignConstraint fk);
4064 removeSourceConstraint(string tname, list cols);
4068 renameSourceConstraintTable(string old_name, string new_name);
4072 bool hasColumn(string cname);
4077 class AbstractPrimaryKey : public AbstractUniqueConstraint {
4083 constructor(string n, *hash c);
4088 class ForeignConstraints : public AbstractHashContainer {
4091 constructor(*hash c);
4095 add(string k, AbstractForeignConstraint val);
4099 AbstractForeignConstraint take(string k);
4103 *AbstractForeignConstraint findEqual(AbstractForeignConstraint fk);
4109 my AbstractForeignConstraint $ix = $fcs.fk_jobs_job_defs;
4112 @param k the name of the key to access
4114 @return the value of the given key in the contained hash if it exists
4116 @throw KEY-ERROR the given key does not exist in the contained hash
4118 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
4120 @see @ref memberGate_methods
4122 AbstractForeignConstraint memberGate(string k);
4126 *hash findConstraintOn(string table, softlist cols);
4130 string getElementName();
4135 class ForeignConstraintTarget {
4148 constructor(string t, Columns c);
4152 bool equal(ForeignConstraintTarget targ);
4157 class AbstractForeignConstraint : public AbstractConstraint {
4165 ForeignConstraintTarget target;
4169 constructor(string n, Columns c, ForeignConstraintTarget t);
4175 bool equalImpl(AbstractConstraint con);
4180 bool hasColumn(string cname);
4184 bool setIndexBase(string ix);
4193 class AbstractSequence {
4212 constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_max);
4216 abstract string getCreateSql(*hash opt);
4219 string getDropSql();
4223 abstract string getRenameSql(string new_name);
4227 class AbstractFunctionBase {
4243 /** @param n the name of the object
4244 @param n_type the type of object
4245 @param n_src the source of the object
4247 constructor(string n, string n_type, string n_src);
4254 // FIXME: not appropriate for pgsql triggers for example
4256 string getDropSql();
4260 bool equal(AbstractFunctionBase t);
4266 abstract bool equalImpl(AbstractFunctionBase t);
4271 class AbstractFunction : public AbstractFunctionBase {
4275 /** @param n the name of the object
4276 @param n_type the type of object
4277 @param n_src the source of the object
4279 constructor(string n, string n_type, string n_src);
4283 abstract list getCreateSql(*hash opt);
4286 abstract list getRenameSql(string new_name);
4289 setName(string new_name);
4294 class Functions : public AbstractHashContainer {
4297 constructor(*hash c);
4301 add(string k, AbstractFunction val);
4305 AbstractFunction take(string k);
4311 my AbstractFunction $f = $funcs.func1;
4314 @param k the name of the key to access
4316 @return the value of the given key in the contained hash if it exists
4318 @throw KEY-ERROR the given key does not exist in the contained hash
4320 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
4322 @see @ref memberGate_methods
4324 AbstractFunction memberGate(string k);
4327 string getElementName();
4332 class AbstractTrigger : public AbstractFunctionBase {
4336 constructor(string n, string n_src);
4340 abstract list getCreateSql(string table_name, *hash opt);
4343 abstract list getRenameSql(string table_name, string new_name);
4346 abstract list getDropSql(string table_name);
4350 class Triggers : public AbstractHashContainer {
4353 constructor(*hash c);
4357 add(string k, AbstractTrigger val);
4361 AbstractTrigger take(string k);
4367 my AbstractTrigger $trig = $trigs.job_trig;
4370 @param k the name of the key to access
4372 @return the value of the given key in the contained hash if it exists
4374 @throw KEY-ERROR the given key does not exist in the contained hash
4376 @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
4378 @see @ref memberGate_methods
4380 AbstractTrigger memberGate(string k);
4383 string getElementName();
4388 /** Driver-specific modules that provide the AbstractDatabase implementation embedded in this class are loaded on demand based on the driver's name.
4389 The driver-specific module
's name is generated based on the db-driver's name with the first letter capitalized then with \c
"SqlUtil" appended.
4392 - \c
"oracle": <a href=
"../../OracleSqlUtil/html/index.html">OracleSqlUtil</a>
4393 - \c
"pgsql": <a href=
"../../PgsqlSqlUtil/html/index.html">PgsqlSqlUtil</a>
4394 - \c
"mysql": <a href=
"../../MysqlSqlUtil/html/index.html">MysqlSqlUtil</a>
4419 constructor(AbstractDatasource ds, *
hash opts);
4433 constructor(
string ds, *
hash opts);
4470 any tryExec(
string sql);
4484 any tryExecArgs(
string sql, *softlist args);
4499 any tryExecRaw(
string sql);
4542 any methodGate(
string meth);
4623 bool dropFunctionIfExists(
string name, *
hash opt);
4639 bool dropProcedureIfExists(
string name, *
hash opt);
4655 bool dropSequenceIfExists(
string name, *
hash opt);
4671 bool dropTableIfExists(
string name, *
hash opt);
4772 int getNextSequenceValue(
string name);
4785 string getSqlFromList(
list l);
4789 bool supportsSequences();
4801 list listFunctions();
4809 list listProcedures();
4817 list listSequences();
4857 constructor(AbstractDatasource nds, *
hash nopts);
4863 validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
4869 static validateOptionIntern(
string err,
string type, reference opt,
string k,
string tag);
4878 string getDriverName();
4882 string getDatasourceDesc();
4895 const DatabaseOptions = (
4903 const CacheOptions = (
4904 "table_cache":
"Tables",
4913 const CallbackOptions = (
4914 "info_callback":
"code",
4915 "sql_callback":
"code",
4927 const AC_Unchanged = 0;
4931 const AC_Create = 1;
4937 const AC_Rename = 3;
4940 const AC_Modify = 4;
4943 const AC_Truncate = 5;
4949 const AC_Recreate = 7;
4952 const AC_Insert = 8;
4955 const AC_Update = 9;
4958 const AC_Delete = 10;
4961 const AC_NotFound = 11;
4966 AC_Unchanged:
"unchanged",
4967 AC_Create:
"create",
4969 AC_Rename:
"rename",
4970 AC_Modify:
"modify",
4971 AC_Truncate:
"truncate",
4973 AC_Recreate:
"recreate",
4974 AC_Insert:
"insert",
4975 AC_Update:
"update",
4976 AC_Delete:
"delete",
4977 AC_NotFound:
"not found",
4981 const ActionDescMap = (
4982 "unchanged": AC_Unchanged,
4983 "create": AC_Create,
4985 "rename": AC_Rename,
4986 "modify": AC_Modify,
4987 "truncate": AC_Truncate,
4989 "recreate": AC_Recreate,
4990 "insert": AC_Insert,
4991 "update": AC_Update,
4992 "delete": AC_Delete,
4993 "not found": AC_NotFound,
4997 const ActionLetterMap = (
5019 const CreationOptions = CallbackOptions + (
5021 "table_cache":
"Tables",
5029 const AlignSchemaOptions = CreationOptions;
5034 const DropSchemaOptions = CallbackOptions;
5049 const SchemaDescriptionOptions = (
5072 const SequenceDescriptionOptions = (
5094 constructor(AbstractDatasource nds, *
hash nopts);
5102 static doOkCallback(*
hash opt,
int ac,
string type,
string name, *
string table, *
string info);
5104 static *
string doCallback(*
hash opt, *
string sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
5106 static list doCallback(*
hash opt,
list sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
5142 any tryExec(
string sql);
5156 any tryExecArgs(
string sql, *softlist args);
5171 any tryExecRaw(
string sql);
5211 list dropSqlUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
5217 list alignCodeUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
5302 bool dropFunctionIfExists(
string name, *
hash opt);
5318 bool dropProcedureIfExists(
string name, *
hash opt);
5334 bool dropSequenceIfExists(
string name, *
hash opt);
5350 bool dropTableIfExists(
string name, *
hash opt);
5366 *
string getDropFunctionSqlIfExists(
string name, *
hash opt);
5382 *
string getDropProcedureSqlIfExists(
string name, *
hash opt);
5398 *
string getDropSequenceSqlIfExists(
string name, *
hash opt);
5414 *
list getDropTableSqlIfExists(
string name, *
hash opt);
5417 doDropSql(*softlist l,
string type,
string name, *
hash opt);
5420 bool doDrop(*softlist l,
string type,
string name, *
hash opt);
5521 int getNextSequenceValue(
string name);
5534 string getSqlFromList(
list l);
5538 bool supportsSequences();
5542 bool supportsTypes();
5546 bool supportsPackages();
5558 list listFunctions();
5566 list listProcedures();
5574 list listSequences();
5591 validateOptionsIntern(
string err,
hash ropt, reference opt);
5597 validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
5607 static checkDriverOptions(reference h,
string drv);
5612 hash getDatabaseOptions();
5619 hash getCallbackOptions();
5626 hash getCreationOptions();
5633 hash getCacheOptions();
5640 hash getAlignSchemaOptions();
5647 hash getDropSchemaOptions();
5654 hash getSchemaDescriptionOptions();
5661 hash getSequenceDescriptionOptions();
5668 any tryExecArgsImpl(
string sql, *softlist args);
5675 any tryExecRawImpl(
string sql);
5681 abstract string getCreateSqlImpl(
list l);
5685 abstract list getAlignSqlImpl(
hash schema_hash, *
hash opt);
5689 abstract list getDropSchemaSqlImpl(
hash schema_hash, *
hash opt);
5720 abstract list featuresImpl();
5724 abstract list listTablesImpl();
5728 abstract list listFunctionsImpl();
5732 abstract list listProceduresImpl();
5736 abstract list listSequencesImpl();
5740 abstract list listViewsImpl();
5746 abstract int getNextSequenceValueImpl(
string name);
5752 abstract bool supportsSequencesImpl();
5756 abstract bool supportsPackagesImpl();
5760 abstract bool supportsTypesImpl();
5797 constructor(AbstractDatasource ds,
string name, *
hash opts);
5813 constructor(
string ds,
string name, *
hash opts);
5837 constructor(
hash ds,
string name, *
hash opts);
5849 constructor(AbstractDatasource ds,
hash desc,
string name, *
hash opts);
5864 setDatasource(AbstractDatasource nds);
5888 any methodGate(
string meth);
5950 dropNoCommit(*
hash opt);
5965 any tryExec(
string sql);
5979 any tryExecArgs(
string sql, *softlist args);
5994 any tryExecRaw(
string sql);
6035 string getTruncateSql(*
hash opt);
6063 createNoCommit(*
hash opt);
6078 rename(
string new_name, *reference sql, *
Tables table_cache);
6166 list getAddColumnSql(
string cname,
hash copt,
bool nullable =
True, *
hash opt);
6226 list getModifyColumnSql(
string cname,
hash copt,
bool nullable =
True, *
hash opt);
6246 AbstractColumn renameColumn(
string old_name,
string new_name, reference sql);
6268 string getRenameColumnSql(
string old_name,
string new_name, *
hash opt);
6319 string getAddPrimaryKeySql(
string pkname, softlist cols, *
hash pkopt, *
hash opt);
6364 list getDropPrimaryKeySql(*
hash opt);
6415 string getAddUniqueConstraintSql(
string cname, softlist cols, *
hash ukopt, *
hash opt);
6441 AbstractIndex addIndex(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
6466 string getAddIndexSql(
string iname,
bool unique, softlist cols, *
hash ixopt, *
hash opt);
6482 AbstractIndex renameIndex(
string old_name,
string new_name, reference sql);
6505 string getDropIndexSql(
string iname, *
hash opt);
6528 string getDropConstraintSql(
string cname, *
hash opt);
6551 *
string getDropConstraintIfExistsSql(
string cname, *
hash opt, *reference cref);
6626 string getAddForeignConstraintSql(
string cname, softlist cols,
string table, *softlist tcols, *
hash fkopt, *
hash opt);
6717 string getAddCheckConstraintSql(
string cname,
string src, *
hash copt, *
hash opt);
6733 AbstractConstraint renameConstraint(
string old_name,
string new_name, reference lsql);
6805 list getAddTriggerSql(
string tname,
string src, *
hash topt, *
hash opt);
6850 list getDropTriggerSql(
string tname, *
hash opt);
6865 string getSqlValue(any v);
6908 list getDropColumnSql(
string cname, *
hash opt);
6922 insert(
hash row, *reference sql);
6936 insertNoCommit(
hash row, *reference sql);
6964 insertNoCommit(
hash row, *
hash opt);
7120 int upsert(
hash row,
int upsert_strategy = AbstractTable::UpsertAuto);
7144 int upsertNoCommit(
hash row,
int upsert_strategy = AbstractTable::UpsertAuto);
7173 code getUpsertClosure(
hash example_row,
int upsert_strategy = AbstractTable::UpsertAuto);
7202 code getUpsertClosureWithValidation(
hash example_row,
int upsert_strategy = AbstractTable::UpsertAuto);
7352 *
hash upsertFromSelectNoCommit(
AbstractTable src, *
hash sh,
int upsert_strategy = AbstractTable::UpsertAuto, *
hash opt);
7393 *
hash upsertFromSelect(
Table src, *
hash sh,
int upsert_strategy = AbstractTable::UpsertAuto, *
hash opt);
7436 *
hash upsertFromSelectNoCommit(
Table src, *
hash sh,
int upsert_strategy = AbstractTable::UpsertAuto, *
hash opt);
7513 *
hash selectRow(*
hash sh, *reference sql);
7532 *
list selectRows(*
hash sh, *reference sql);
7551 *
hash select(*
hash sh, *reference sql);
7631 string getSelectSql(*
hash sh, *reference args);
7649 int del(*
hash cond, *reference sql);
7667 int delNoCommit(*
hash cond, *reference sql);
7687 int update(
hash set, *
hash cond, *reference sql);
7707 int updateNoCommit(
hash set, *
hash cond, *reference sql);
7743 int delNoCommit(*
hash cond, *
hash opt);
7796 string getSqlFromList(
list l);
7818 string getRenameSql(
string new_name, *
hash opt);
7833 string getCreateSqlString(*
hash opt);
7861 string getCreateTableSql(*
hash opt);
7876 *
list getCreateIndexesSql(*
hash opt);
7891 *
string getCreatePrimaryKeySql(*
hash opt);
7906 *
list getCreateForeignConstraintsSql(*
hash opt);
7923 *
list getCreateConstraintsSql(*
hash opt);
7953 *
list getCreateTriggersSql(*
hash opt);
8021 string getAlignSqlString(
Table table, *
hash opt);
8198 string getDriverName();
8212 const TableOptions = (
8214 "table_cache":
"Tables",
8222 const IndexOptions = (
8230 const ConstraintOptions = IndexOptions;
8233 const CacheOptions = (
8234 "table_cache":
"Tables",
8241 const ForeignConstraintOptions = ConstraintOptions + (
8242 "table_cache":
"Tables",
8248 const TriggerOptions = AbstractDatabase::CreationOptions;
8263 const SelectOptions = (
8267 "where":
"hash/list",
8268 "orderby":
"softstringhashlist",
8273 "groupby":
"softstringhashlist",
8279 const TableOmissionOptions = (
8281 "foreign_constraints":
True,
8289 const TableCreationOptions = IndexOptions + AbstractDatabase::CreationOptions + (
8290 "omit":
"softstringlist",
8301 const AlignTableOptions = TableCreationOptions + (
8306 "db_table_cache":
"Tables",
8321 const TableDescriptionHashOptions = (
8329 "table_cache":
"Tables",
8344 const ColumnDescOptions = (
8357 const AdditionalColumnDescOptions = (
8368 const SqlDataCallbackOptions = (
8369 "sqlarg_callback":
"code",
8378 const UpsertOptions = (
8379 "info_callback":
"code",
8389 const InsertOptions = SqlDataCallbackOptions + (
8390 "info_callback":
"code",
8414 const UpsertInsertFirst = 1;
8422 const UpsertUpdateFirst = 2;
8431 const UpsertSelectFirst = 3;
8438 const UpsertAuto = 4;
8445 const UR_Inserted = 1;
8449 const UR_Verified = 2;
8452 const UR_Updated = 3;
8455 const UR_Unchanged = 4;
8458 const UR_Deleted = 5;
8464 const UpsertResultMap = (
8465 UR_Inserted:
"inserted",
8466 UR_Verified:
"verified",
8467 UR_Updated:
"updated",
8468 UR_Unchanged:
"unchanged",
8469 UR_Deleted:
"deleted",
8475 const UpsertResultDescriptionMap = (
8476 "inserted": UR_Inserted,
8477 "verified": UR_Verified,
8478 "updated": UR_Updated,
8479 "unchanged": UR_Unchanged,
8480 "deleted": UR_Deleted,
8484 const UpsertResultLetterMap = (
8527 constructor(AbstractDatasource nds,
string nname, *
hash nopts);
8547 setDatasource(AbstractDatasource nds);
8552 doTableOptions(*
hash nopts);
8613 any tryExec(
string sql);
8627 any tryExecArgs(
string sql, *softlist args);
8642 any tryExecRaw(
string sql);
8657 dropNoCommit(*
hash opt);
8671 softlist getDropSql(*
hash opt);
8712 string getTruncateSql(*
hash opt);
8740 createNoCommit(*
hash opt);
8755 rename(
string new_name, *reference sql, *
Tables table_cache);
8760 doRenameIntern(
string new_name, *
Tables table_cache);
8794 bool emptyUnlocked();
8864 list getAddColumnSql(
string cname,
hash copt,
bool nullable =
True, *
hash opt);
8934 list getModifyColumnSql(
string cname,
hash copt,
bool nullable =
True, *
hash opt);
8955 AbstractColumn renameColumn(
string old_name,
string new_name, reference sql);
8977 string getRenameColumnSql(
string old_name,
string new_name, *
hash opt);
8988 validateOptionsIntern(
string err,
hash ropt, reference opt);
8994 validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
9000 execSql(softlist lsql);
9051 string getAddPrimaryKeySql(
string pkname, softlist cols, *
hash pkopt, *
hash opt);
9089 list getDropAllConstraintsAndIndexesOnColumnSql(
string cname, *
hash opt);
9094 list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(
string cname, *
hash opt);
9118 list getDropPrimaryKeySql(*
hash opt);
9189 string getAddUniqueConstraintSql(
string cname, softlist cols, *
hash ukopt, *
hash opt);
9226 AbstractIndex addIndex(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
9251 string getAddIndexSql(
string iname,
bool unique, softlist cols, *
hash ixopt, *
hash opt);
9256 AbstractIndex addIndexUnlocked(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
9262 AbstractIndex addIndexUnlockedIntern(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
9279 AbstractIndex renameIndex(
string old_name,
string new_name, reference sql);
9324 string getDropIndexSql(
string iname, *
hash opt);
9376 string getAddForeignConstraintSql(
string cname, softlist cols,
string table, *softlist tcols, *
hash fkopt, *
hash opt);
9379 private Columns getReferencedTableColumnsUnlocked(
string table, *
Tables cache,
string err =
"FOREIGN-CONSTRAINT-ERROR");
9384 AbstractForeignConstraint addForeignConstraintUnlocked(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference sql);
9390 AbstractForeignConstraint addForeignConstraintUnlockedIntern(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference sql);
9482 string getAddCheckConstraintSql(
string cname,
string src, *
hash copt, *
hash opt);
9510 AbstractConstraint renameConstraint(
string old_name,
string new_name, reference lsql);
9533 string getDropConstraintSql(
string cname, *
hash opt);
9556 *
string getDropConstraintIfExistsSql(
string cname, *
hash opt, *reference cref);
9634 list getAddTriggerSql(
string tname,
string src, *
hash topt, *
hash opt);
9645 AbstractTrigger addTriggerUnlockedIntern(
string tname,
string src, *
hash opt, *reference lsql);
9691 list getDropTriggerSql(
string tname, *
hash opt);
9696 getAllConstraintsUnlocked(*
hash opt);
9702 checkUniqueConstraintName(
string err,
string cname);
9708 checkUniqueConstraintNameValidateOptions(
string err,
string cname,
hash ropt, reference opt);
9715 validateColumnOptions(
string cname, reference opt,
bool nullable);
9761 list getDropColumnSql(
string cname, *
hash opt);
9775 insert(
hash row, *reference sql);
9789 insertNoCommit(
hash row, *reference sql);
9794 insertNoCommitIntern(
hash row, *reference sql, *
hash opt);
9823 insertNoCommit(
hash row, *
hash opt);
9986 int upsert(
hash row,
int upsert_strategy = UpsertAuto);
10005 int upsertNoCommit(
hash row,
int upsert_strategy = UpsertAuto);
10029 code getUpsertClosure(
hash example_row,
int upsert_strategy = UpsertAuto);
10053 code getUpsertClosureWithValidation(
hash example_row,
int upsert_strategy = UpsertAuto);
10265 *
hash upsertFromSelect(
Table t, *
hash sh,
int upsert_strategy = AbstractTable::UpsertAuto, *
hash opt);
10309 *
hash upsertFromSelectNoCommit(
Table t, *
hash sh,
int upsert_strategy = AbstractTable::UpsertAuto, *
hash opt);
10324 softint rowCount();
10392 *
hash selectRow(*
hash sh, *reference sql);
10411 *
list selectRows(*
hash sh, *reference sql);
10430 *
hash select(*
hash sh, *reference sql);
10510 string getSelectSql(*
hash sh, *reference args);
10516 string getSelectSqlIntern(*
hash qh, reference args);
10519 string getSelectSqlUnlocked(*
hash qh, reference args);
10522 string getSelectSqlUnlockedIntern(*
hash qh,
string from, reference args, *
hash ch);
10527 string getSelectSqlName(*
hash qh);
10533 string getColumnExpressionIntern(any cvc, *
hash jch,
bool join, *
hash ch);
10545 string doColumnOperatorIntern(any cop, any arg, *
string cve,
hash cm, *
hash jch,
bool join, *
hash ch);
10551 string getColumnNameIntern(
string cv, *
hash jch,
bool join, *
hash ch);
10557 getSelectWhereSqlUnlocked(reference sql, reference args, *
hash qh, *
hash jch,
bool join = False, *
hash ch);
10563 *
string getWhereClause(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False);
10569 *
string getWhereClause(
list cond, reference args, *
string cprefix, *
hash jch,
bool join = False);
10575 *
string getWhereClauseUnlocked(
list cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch);
10581 *
string getWhereClauseUnlocked(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch);
10587 *
list getWhereClauseIntern(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash ch);
10593 string doWhereExpressionIntern(
string cn, any we, reference args, *
hash jch,
bool join = False, *
hash ch);
10605 doSelectOrderBySqlUnlocked(reference sql, reference args, *
hash qh, *
hash jch, *
hash ch);
10624 int del(*
hash cond, *reference sql);
10642 int delNoCommit(*
hash cond, *reference sql);
10647 int delNoCommitIntern(*
hash cond, *reference sql, *
hash opt);
10668 int update(
hash set, *
hash cond, *reference sql);
10688 int updateNoCommit(
hash set, *
hash cond, *reference sql);
10693 int updateNoCommitIntern(
hash set, *
hash cond, *reference sql, *
hash opt);
10730 int delNoCommit(*
hash cond, *
hash opt);
10775 string getUpdateExpression(
string col,
hash uh);
10781 bool emptyDataUnlocked();
10787 code getUpsertClosureUnlocked(
hash row,
int upsert_strategy = UpsertAuto);
10793 code getUpsertInsertFirst(
Columns cols,
hash example_row);
10799 code getUpsertUpdateFirst(
Columns cols,
hash example_row);
10805 code getUpsertSelectFirst(
Columns cols,
hash example_row);
10811 Columns getUpsertColumns(reference csrc);
10817 string getUpsertSelectSql(
hash row,
Columns cols, reference updc);
10823 string getUpsertInsertSql(
hash row);
10829 string getUpsertUpdateSql(
hash row,
Columns cols, reference updc);
10841 checkValue(
string cname,
string argname, reference val,
string type);
10855 string getSqlFromList(
list l);
10870 string getSqlValue(any v);
10989 string getRenameSql(
string new_name, *
hash opt);
11002 string getCreateSqlString(*
hash opt);
11030 string getCreateTableSql(*
hash opt);
11034 bool checkExistence();
11039 *
hash getCheckOmissionOptions(*softlist ol,
string err);
11104 *
list getCreateIndexesSql(*
hash opt,
bool cache =
True);
11120 *
string getCreatePrimaryKeySql(*
hash opt,
bool cache =
True);
11136 *
list getCreateForeignConstraintsSql(*
hash opt,
bool cache =
True);
11154 *
list getCreateConstraintsSql(*
hash opt,
bool cache =
True);
11188 *
list getCreateTriggersSql(*
hash opt,
bool cache =
True);
11199 *
hash find(any
id);
11219 string getPrimaryKeyColumn();
11275 string getSqlName();
11283 hash getTableOptions();
11292 hash getForeignConstraintOptions();
11301 hash getConstraintOptions();
11310 hash getCacheOptions();
11319 hash getTableCreationOptions();
11328 hash getAlignTableOptions();
11337 hash getTableDescriptionHashOptions();
11346 hash getColumnOptions();
11355 hash getColumnDescOptions();
11364 hash getTableColumnDescOptions();
11373 hash getIndexOptions();
11382 hash getTriggerOptions();
11391 hash getSelectOptions();
11400 hash getUpsertOptions();
11409 hash getInsertOptions();
11418 hash getSqlDataCallbackOptions();
11427 hash getWhereOperatorMap();
11436 hash getColumnOperatorMap();
11445 hash getUpdateOperatorMap();
11451 string getCreateTableSqlUnlocked(*
hash opt);
11457 *
list getCreateIndexesSqlUnlocked(*
hash opt,
bool cache =
True);
11463 *
string getCreatePrimaryKeySqlUnlocked(*
hash opt,
bool cache =
True);
11469 *
list getCreateConstraintsSqlUnlocked(*
hash opt,
bool cache =
True);
11475 *
list getCreateForeignConstraintsSqlUnlocked(*
hash opt,
bool cache =
True);
11481 *
list getCreateMiscSqlUnlocked(*
hash opt,
bool cache =
True);
11487 *
list getCreateTriggersSqlUnlocked(*
hash opt,
bool cache =
True);
11493 list getCreateSqlUnlocked(*
hash opt,
bool cache =
True);
11499 cacheUnlocked(*
hash opt);
11505 any execData(*
hash opt,
string sql, *
list args);
11511 execData(SQLStatement stmt, *
hash opt, *
list args);
11515 static AbstractTable getTable(AbstractDatasource nds,
string nname, *
hash opts);
11523 getColumnsUnlocked();
11529 getPrimaryKeyUnlocked();
11536 getIndexesUnlocked();
11542 getForeignConstraintsUnlocked(*
hash opt);
11554 getConstraintsUnlocked();
11560 getTriggersUnlocked();
11566 softlist getDropSqlImpl();
11572 string getTruncateSqlImpl();
11579 any tryExecArgsImpl(
string sql, *softlist args);
11586 any tryExecRawImpl(
string sql);
11599 preSetupTableImpl(reference desc, *
hash opt);
11605 abstract bool emptyImpl();
11611 abstract *
string getSqlValueImpl(any v);
11620 abstract bool checkExistenceImpl();
11626 abstract bool supportsTablespacesImpl();
11632 abstract bool constraintsLinkedToIndexesImpl();
11638 abstract bool uniqueIndexCreatesConstraintImpl();
11643 abstract setupTableImpl(
hash desc, *
hash opt);
11648 abstract Columns describeImpl();
11656 abstract Indexes getIndexesImpl();
11668 abstract Triggers getTriggersImpl();
11673 abstract string getCreateTableSqlImpl(*
hash opt);
11677 abstract *
list getCreateMiscSqlImpl(*
hash opt,
bool cache);
11681 abstract string getCreateSqlImpl(
list l);
11685 abstract string getRenameSqlImpl(
string new_name);
11725 abstract bool tryInsertImpl(
string sql,
hash row);
11731 abstract hash getQoreTypeMapImpl();
11737 abstract hash getTypeMapImpl();
11743 abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *
hash qh, *
hash jch, *
hash ch);
11749 abstract doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *
hash qh);
nothing rename(string old_path, string new_path)
hash uop_lower(*hash nest)
returns a hash for the "lower" operator with the given argument; returns a column value in lower case...
hash uop_append(string arg, *hash nest)
returns a hash for the "append" or concatenate operator with the given argument
string sprintf(string fmt,...)
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:8203
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:3390
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...
string printf(string fmt,...)
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:3798
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:4088
hash op_gt(any arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing c...
base class for sequences
Definition: SqlUtil.qm.dox.h:4193
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:8378
number number(softnumber n)
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:8504
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:4834
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:8422
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:4398
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:4157
hash op_like(string str)
returns a hash for the "like" operator with the given argument for use in where clauses ...
hash op_lt(any arg)
returns a hash for the "<" operator with the given argument for use in where clauses when comparing c...
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:3977
string name
the table's name
Definition: SqlUtil.qm.dox.h:8496
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:4350
int index(softstring str, softstring substr, softint pos=0)
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:8502
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:3756
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:8500
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:8508
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:8498
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:4839
base class for functions
Definition: SqlUtil.qm.dox.h:4271
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:8506
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:4845
*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...
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:3578
the base class for triggers
Definition: SqlUtil.qm.dox.h:4332
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:4841
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8455
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8452
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:4403
the base class for column information
Definition: SqlUtil.qm.dox.h:3625
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:5775
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:8431
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:5780
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:4887
represents a primary key
Definition: SqlUtil.qm.dox.h:4077
string join(string str,...)
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:4007
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:3912
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:3870