297 @warning Oracle:
using different comments in the same SQL can lead to
new optimizer statement hard parsing.
299 @anchor select_option_hint
300 @par Select Option
"hint"
301 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).
305 $table.selectRows( (
"hint" :
"full(t1)") );
307 will produce select statement like
this:
311 The
string is taken as is and it
's up to user to handle correct aliases in join functions etc.
312 @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
313 @warning Use hints only when you know what you are doing.
315 @anchor select_option_columns
316 @par Select Option "columns"
317 <b>Columns Example:</b>
319 my list $columns = ("id", "name", "started", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"));
320 my *list $rows = $table.selectRows(("columns": $columns, "where": ("type": "user")));
322 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
323 This option takes a list, each element of the list can be one of the following.\n\n
324 <b>A Simple String Giving a Column Name</b>\n
327 my *list $rows = $table.selectRows(("columns": ("id", "name", "started")));
329 <b>A String in Dot Notation</b>\n
330 This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
332 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner($table2, "t2", ("id": "altid"))));
334 <b>A Column Operation Specified by a Column Operator Function</b>\n
335 ex: <tt>cop_as("column_name", "column_alias")</tt> \n
336 See @ref sql_cop_funcs "column operator function" for more information on column operator functions
338 my *list $rows = $table.selectRows(("columns": ("id", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"))));
340 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
341 <b>The Value \c "*", Meaning All Columns</b>\n
344 my *list $rows = $table.selectRows(("columns": "*"));
346 This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
347 <b>An \c "*" in Dot Notation</b>\n
350 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.*"), "join": join_inner($table2, "t2", ("id": "altid"))));
353 @anchor select_option_where
354 @par Select Option "where"
355 <b>Where Example:</b>
357 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
359 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.
361 @anchor select_option_orderby
362 @par Select Option "orderby"
363 <b>Orderby Example:</b>
365 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date"));
367 This option is a list of the following values:
368 - a simple string giving a column name; ex: \c "name"
369 - 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"
371 - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
373 @anchor select_option_desc
374 @par Select Option "desc"
377 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date", "desc": True));
379 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
380 Otherwise, ordered results are returned in ascending order by default.
382 @anchor select_option_limit
383 @par Select Option "limit"
384 <b>Limit Example:</b>
386 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
388 This option will limit the number of rows returned.
390 - This option is required if the @ref select_option_offset "offset option" is non-zero
391 - 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
393 @anchor select_option_offset
394 @par Select Option "offset"
395 <b>Offset Example:</b>
397 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
399 This option specifies the row number offset for the rows returned where the first row is at offset zero.
401 - 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.
402 - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
405 @anchor select_option_join
406 @par Select Option "join"
409 my *list $rows = $table.selectRows(("columns": ("name", "version", "id", cop_as("st.value", "source"), cop_as("st.value", "offset")),
410 "join": join_left($function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
411 + join_left($function_instance_tags, "lt", NOTHING, ("st.tag": "_offset"))));
413 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).
414 @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
416 @see @ref joins for more examples
418 @anchor select_option_groupby
419 @par Select Option "groupby"
420 <b>Groupby Example:</b>
422 my *list $rows = $table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type"));
424 The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
425 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"
426 key are strings giving column names, optionally in dot notation.
428 @anchor select_option_having
429 @par Select Option "having"
430 <b>Having Example:</b>
432 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)))));
434 The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
435 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.
437 @anchor select_option_superquery
438 @par Select Option "superquery"
439 <b>Superquery Example:</b>
441 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"))));
443 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
444 The above example results in an SQL command equivalent to the following:
446 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");
448 @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
450 @anchor select_option_forupdate
451 @par Select Option "forupdate"
452 <b>For Update Example:</b>
454 on_success $ds.commit();
455 on_error $ds.rollback();
457 my *list $rows = $table.selectRows("columns": ("serviceid", "service_methodid"), "forupdate": True);
459 \n The \c "forupdate" option allows for the rows selected to be locked for updating; to release the locks, call commit() or rollback() on the underlying datasource object.
460 The above example results in an SQL commit equivalent to the following:
462 my *list $rows = $table.vselectRows("select serviceid,service_methodid from schema.service_methods for update");
465 @subsection sql_paging Select With Paging
467 There is support for paging query results in the following methods:
468 - @ref SqlUtil::Table::getRowIterator()
469 - @ref SqlUtil::Table::getSelectSql()
470 - @ref SqlUtil::Table::select()
471 - @ref SqlUtil::Table::selectRows()
473 @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
475 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.
477 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.
480 Select 100 rows starting at row 200 (the table's primary key will be used
for the \c
"orderby" option by
default): \n
482 my *
list $rows = $table.selectRows((
"where": (
"type":
"user"),
"limit": 100,
"offset": 200));
484 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:
486 $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));
490 $ds.vselectRows(
"select * from public.table where type = %v order by type limit %v offset %v", (
"user", 100, 200));
493 @subsection check_matching_rows Check For At Least One Matching Row
497 my *
hash $h = $table.findSingle(("account_type": "CUSTOMER"));
499 printf("found 1 customer row: %y\n", $l[0]);
502 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):
504 my *
hash $h = $table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
506 printf("found 1 customer row: %y\n", $l[0]);
509 @section inserting_data Inserting Data into the Database
511 The following methods can be used to insert data into the database:
512 - @ref SqlUtil::Table::insert(): inserts a single row into a table and commits the transaction
513 - @ref SqlUtil::Table::insertNoCommit(): inserts a single row into a table without committing the transaction
514 - @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
515 - @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
517 @see @ref sql_upsert for information about upserting or merging data
519 @subsection inserting_data_explicitly Inserting Data Explicitly
523 $table.insert(("
id": $id, "name": $name, "created":
now_us()));
526 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.
528 @subsection inserting_data_from_select Inserting Data From a Select Statement
532 my
int $rows = $table.insertFromSelect(("
id", "name", "created"), $source_table, (("columns": ("cid", "fullname", "created"), "where": ("
type": "CUSTOMER"))));
535 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.
537 The example above would generate a %Qore SQL command like the following:
539 return $ds.vexec("insert into schema.table (
id,name,created) select cid,fullname,created from schema.source_table where
type = %v", ("CUSTOMER"));
542 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.
544 @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
546 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:
550 # get the rows to be inserted
551 my
list $l = get_table_rows();
552 # insert the data and commit after every 5000 rows
553 $table.insertFromIterator($l.iterator(), (
"commit_block": 5000));
556 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".
558 @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
560 @section updating_data Updating Data
562 The following methods can be used to update data:
563 - @ref SqlUtil::Table::update(): updates a single row and commits the transaction
564 - @ref SqlUtil::Table::updateNoCommit(): updates a single row and does not commit the transaction
568 my
int $rows_updated = t.update(("permission_type":
uop_append("-migrated",
uop_lower())));
571 The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
573 return $ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
575 And the following on MySQL:
577 return $ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
580 @section deleting_data Deleting Data
582 The following methods can be used to dekete data:
583 - @ref SqlUtil::Table::del(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
584 - @ref SqlUtil::Table::delNoCommit(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
585 - @ref SqlUtil::Table::truncate(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource
object
586 - @ref SqlUtil::Table::truncateNoCommit(): truncates the table and does not commit the transaction
590 my
int $dcnt = $table.del(("record_type": "OLD-CUSTOMER"));
593 The above example would generate a %Qore SQL command like the following:
595 return $ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
598 The @ref SqlUtil::Table::del() and @ref SqlUtil::Table::delNoCommit() methods can be used to delete data from the database.
600 See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
602 @section joins Joining Tables
604 Joining tables is made by providing a
join specification to the @ref select_option_join "
join select option" in
605 a @ref select_option_hash "select option
hash" as in the following example:
607 my *
list $rows = $table.selectRows(("columns": ("table.
id", "t2.customer_name"), "
join":
join_inner($table2, "t2", ("
id": "altid"))));
609 In the above example, \a table is joined with \a table2 on <tt>table.
id = table2.altid</tt>.
611 Joins on multiple tables are performed by combining the results of @ref sql_op_funcs "
join functions" with the @ref plus_operator "+ operator"
616 In the above example, \a table is joined with \a table2 on <tt>table.
id = table2.altid</tt> and with \a table3 on an
617 automatically detected primary key to foreign key relationship between the two tables.
619 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
620 argument to the @ref sql_op_funcs "
join function" as in the following example:
624 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
625 with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
627 @see @ref select_option_join "
join select option"
629 @section where_clauses Where Clauses
631 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:
632 - @ref SqlUtil::Table::del()
633 - @ref SqlUtil::Table::delNoCommit()
634 - @ref SqlUtil::Table::findAll()
635 - @ref SqlUtil::Table::findSingle()
636 - @ref SqlUtil::Table::getRowIterator()
637 - @ref SqlUtil::Table::getSelectSql()
638 - @ref SqlUtil::Table::insertFromSelect()
639 - @ref SqlUtil::Table::insertFromSelectNoCommit()
640 - @ref SqlUtil::Table::select()
641 - @ref SqlUtil::Table::selectRow()
642 - @ref SqlUtil::Table::selectRows()
643 - @ref SqlUtil::Table::update()
644 - @ref SqlUtil::Table::updateNoCommit()
645 - @ref SqlUtil::Table::upsertFromSelect()
646 - @ref SqlUtil::Table::upsertFromSelectNoCommit()
648 @note the above
list also applies to the corresponding @ref SqlUtil::AbstractTable methods
650 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".
652 The where condition
hash has the following format:
653 - each key gives a column name or a table/alias with column name in dot notation
654 - 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
656 @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
658 See @ref sql_op_funcs for a
list of operator functions.
660 @par Where
Hash Example:
664 "account_type":
op_like("%CUSTOMER%"),
668 The preceding example results in a where clause equivalent to: \c "name = 'Smith' and
type like '%CUSTOMER%' and
id >= 500", except
669 that bind by value is used, so, if used in a context like the following:
671 my Table $t($ds, "table");
672 my *
hash $qh = $t.select(("where": $w));
674 the complete query would look instead as follows:
676 $ds.vselect("select * from table where name = %v and account_type like %v and
id >= %v", ("Smith", "%CUSTOMER%", 500));
680 @par Where
List Example:
684 "account_type":
op_like("%CUSTOMER%"),
689 "account_type":
op_like("%VENDOR%"),
692 my Table $t($ds, "table");
693 my *
hash $qh = $t.select(("where": ($w1, $w2)));
695 the complete query would look instead as follows:
697 $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));
701 Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
703 my *
hash $row = $table.findSingle(("permission_type":
op_between("US", "UX")));
705 resulting in an internal SQL command that looks as follows (depending on the database):
707 my *
hash $row = $ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
709 Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
711 my
int $row_count = $table.del(("name":
op_like("%Smith%")));
713 resulting in an internal SQL command that looks as follows:
715 $ds.vexec("delete from table where name like %v", ("%Smith%"));
717 Find all rows where \c "
id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
719 my *
list $rows = $table.findAll(("
id":
op_gt(100), "created": op_gt(2013-03-01)));
721 resulting in an internal SQL command that looks as follows:
723 $ds.vexec("select * from table where
id > %v and created > %v", (100, 2013-03-01));
726 @section sql_upsert Upserting or Merging Data
728 This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
729 - @ref SqlUtil::Table::upsert()
730 - @ref SqlUtil::Table::upsertNoCommit()
731 - @ref SqlUtil::Table::getUpsertClosure()
732 - @ref SqlUtil::Table::getUpsertClosureWithValidation()
733 - @ref SqlUtil::Table::upsertFromIterator()
734 - @ref SqlUtil::Table::upsertFromIteratorNoCommit()
735 - @ref SqlUtil::Table::upsertFromSelect()
736 - @ref SqlUtil::Table::upsertFromSelectNoCommit()
738 @subsection sql_upsert_single Upsert a Single Row
742 $table.upsert(("
id": $id, "name": $name, "account_type": $account_type));
745 To upsert or merge a single row in the database, call @ref SqlUtil::Table::upsert() or @ref SqlUtil::Table::upsertNoCommit() with the
746 single row to be upserted or merged as a
hash as in the preceding example.
748 @subsection sql_upsert_many Upserting Many Rows Using An Upsert
Closure
750 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.
754 # get the rows to be inserted
755 my
list $l = get_table_rows();
758 my code $upsert = $table.getUpsertClosure($l[0]);
760 on_success $ds.commit();
761 on_error $ds.rollback();
763 # loop through the reference data rows
768 @par Complex Example With Callbacks:
770 # set the upsert strategy depending on the use case
771 my
int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
773 # hash summarizing changes
776 # get the rows to be inserted
777 my
list $l = get_table_rows();
780 # get the upsert closure to use based on the first row to be inserted
781 my code $upsert = $table.getUpsertClosure($l[0], $upsert_strategy);
783 on_success $ds.commit();
784 on_error $ds.rollback();
786 # loop through the reference data rows
787 foreach my
hash $h in ($l) {
788 my
int $code = $upsert($h);
789 if ($code == AbstractTable::UR_Unchanged)
792 my
string $change = AbstractTable::UpsertResultMap{$code};
799 else if ($verbose > 1)
800 printf(
"*** reference data %s: %y: %s\n", $table.getName(), $h, $change);
805 printf(
"*** reference data %s: %s\n", $table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), $sh.pairIterator())));
807 printf(
"*** reference data %s: OK\n", $table.getName());
811 @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
817 # get the rows to be inserted
818 my
list $l = get_table_rows();
819 $table.upsertFromIterator($l.iterator());
822 @par Complex Example With Callbacks:
824 # set the upsert strategy depending on the use case
825 my
int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
827 # get the rows to be inserted
828 my
list $l = get_table_rows();
830 my code $callback = sub (
string $table_name,
hash $row,
int $result) {
831 if ($result == AbstractTable::UR_Unchanged)
833 my
string $change = AbstractTable::UpsertResultMap{$result};
835 printf(
"*** reference data %s: %y: %s\n", $table_name, $row, $change);
838 my
hash $sh = $table.upsertFromIterator($l.iterator(), $upsert_strategy,
False, (
"info_callback": $callback,
"commit_block": 5000));
840 printf(
"*** reference data %s: %s\n", $table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), $sh.pairIterator())));
842 printf(
"*** reference data %s: OK\n", $table.getName());
845 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".
847 @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
849 @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
851 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:
855 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")));
858 @par Complex Example With Callbacks:
860 # set the upsert strategy depending on the use case
861 my
int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
863 my code $callback = sub (
string $table_name,
hash $row,
int $result) {
864 if ($result == AbstractTable::UR_Unchanged)
866 my
string $change = AbstractTable::UpsertResultMap{$result};
868 printf(
"*** reference data %s: %y: %s\n", $table_name, $row, $change);
871 my
hash $sh = $table.upsertFromSelect($table2, (
"where": (
"account_type":
"CUSTOMER")), $upsert_strategy, False, (
"info_callback": $callback,
"commit_block": 5000));
873 printf(
"*** reference data %s: %s\n", $table.getName(), (foldl $1 +
", " + $2, (map
sprintf(
"%s: %d", $1.key, $1.value), $sh.pairIterator())));
875 printf(
"*** reference data %s: OK\n", $table.getName());
878 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).
880 @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
882 @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
884 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.
886 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.
890 # get the rows to be inserted
891 my list $l = get_table_rows();
892 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
895 @par Complex Example With Callbacks:
897 # set the upsert strategy depending on the use case
898 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
900 # get the rows to be inserted
901 my list $l = get_table_rows();
903 my code $callback = sub (string $table_name, hash $row, int $result) {
904 if ($result == AbstractTable::UR_Unchanged)
906 my string $change = AbstractTable::UpsertResultMap{$result};
908 printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
911 my hash $sh = $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), $upsert_strategy, ("delete_others": True, "info_callback": $callback, "commit_block": 5000));
913 printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
915 printf("*** reference data %s: OK\n", $table.getName());
918 @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
920 @subsection sql_upsert_strategies Upsert Strategies
921 The approach used is based on one of the following strategies (see @ref upsert_options):
922 - @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
923 - @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
924 - @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
926 - @ref
SqlUtil::AbstractTable::UpsertInsertOnly "AbstractTable::UpsertInsertOnly": insert
if the row doesn
't exist, otherwise do nothing and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
928 @note @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" is the only upsert strategy that can return @ref SqlUtil::AbstractTable::UR_Updated; the @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" strategy should be used when verbose reporting is required, particularly if it's necessary to report the actual
number of changed rows.
1786 "code":
string (
string cve,
string arg) {
1787 return sprintf(
"%s as %s", cve, arg);
1793 "code":
string (
string cve,
string arg) {
1794 return sprintf(
"%s||%s", arg, cve);
1800 "code":
string (
string cve,
string arg) {
1801 return sprintf(
"%s||%s", cve, arg);
1807 "code":
string (*
string cve, any arg) {
1812 "code":
string (
string cve, any arg) {
1813 return sprintf(
"upper(%s)", cve);
1817 "code":
string (
string cve, any arg) {
1818 return sprintf(
"lower(%s)", cve);
1822 "code":
string (
string cve, any arg) {
1823 return sprintf(
"distinct %s", cve);
1827 "code":
string (
string cve, any arg) {
1828 return sprintf(
"min(%s)", cve);
1833 "code":
string (
string cve, any arg) {
1834 return sprintf(
"max(%s)", cve);
1839 "code":
string (
string cve, any arg) {
1840 return sprintf(
"avg(%s)", cve);
1846 "code":
string (*
string cve, any arg) {
1847 return sprintf(
"count(%s)", cve ? cve :
"1");
1852 "code":
string (
string arg1,
string arg2) {
1853 return sprintf(
"%s - %s", arg1, arg2);
1858 "code":
string (
string arg1,
string arg2) {
1859 return sprintf(
"%s + %s", arg1, arg2);
1864 "code":
string (
string arg1,
string arg2) {
1865 return sprintf(
"%s / %s", arg1, arg2);
1870 "code":
string (
string arg1,
string arg2) {
1871 return sprintf(
"%s * %s", arg1, arg2);
2709 "code":
string (
object t,
string cn, any arg, reference args) {
2711 return sprintf(
"%s like %v", cn);
2715 "code":
string (
object t,
string cn, any arg, reference args) {
2717 return sprintf(
"%s < %v", cn);
2721 "code":
string (
object t,
string cn, any arg, reference args) {
2723 return sprintf(
"%s <= %v", cn);
2727 "code":
string (
object t,
string cn, any arg, reference args) {
2729 return sprintf(
"%s > %v", cn);
2733 "code":
string (
object t,
string cn, any arg, reference args) {
2735 return sprintf(
"%s >= %v", cn);
2739 "code":
string (
object t,
string cn, any arg, reference args) {
2741 return sprintf(
"%s is not null", cn);
2743 return sprintf(
"%s != %v", cn);
2747 "code":
string (
object t,
string cn, any arg, reference args) {
2749 return sprintf(
"%s is null", cn);
2751 return sprintf(
"%s = %v", cn);
2755 "code":
string (
object t,
string cn, any arg, reference args) {
2758 return sprintf(
"%s between %v and %v", cn);
2762 "code":
string (
object t,
string cn, any arg, reference args) {
2763 *
string ins = (foldl $1 +
"," + $2, (map t.getSqlValue($1), arg));
2764 return ins ?
sprintf(
"%s in (%s)", cn, ins) :
"1 != 1";
2769 "code":
string (
object t,
string cn, any arg, reference args) {
2770 return sprintf(
"not (%s)", cn);
2775 "code":
string (
object t,
string cn, any arg, reference args) {
2776 return sprintf(
"%s < %s", cn, arg);
2781 "code":
string (
object t,
string cn, any arg, reference args) {
2782 return sprintf(
"%s <= %s", cn, arg);
2787 "code":
string (
object t,
string cn, any arg, reference args) {
2788 return sprintf(
"%s > %s", cn, arg);
2793 "code":
string (
object t,
string cn, any arg, reference args) {
2794 return sprintf(
"%s >= %s", cn, arg);
2799 "code":
string (
object t,
string cn, any arg, reference args) {
2800 return sprintf(
"%s != %s", cn, arg);
2805 "code":
string (
object t,
string cn,
string arg, reference args) {
2806 return sprintf(
"%s = %s", cn, arg);
3177 abstract any
take(
string k);
3180 renameKey(
string old_name,
string new_name);
3433 abstract any
get(softint i);
3489 private checkIndex(
int i);
3617 bool tableRenamed(
string old_name,
string new_name,
string old_sql_name);
3620 private tableRenamedIntern(
string old_name,
string new_name,
string oldsn);
3642 list getCreateList();
3671 private getDependencies(reference tdh, reference sdh, *reference th);
3679 constructor(*
hash c);
3750 constructor(
string n,
string nt, *
string qt,
int sz,
bool nul, *
string dv, *
string c);
3839 constructor(softint n_scale = 0);
3851 constructor(*
hash c);
3942 abstract string getRenameSql(
string table_name,
string new_name);
3965 constructor(*
hash c);
4170 constructor(
string n, *
hash c);
4178 constructor(*
hash c);
4366 constructor(
string n,
string n_type,
string n_src);
4395 constructor(
string n,
string n_type,
string n_src);
4413 constructor(*
hash c);
4469 constructor(*
hash c);
4987 static string makeDatasourceDesc(AbstractDatasource
ds);
4989 private validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
4994 static validateOptionIntern(
string err,
string type, reference opt,
string k,
string tag);
5033 "table_cache":
"Tables",
5043 "info_callback":
"code",
5044 "sql_callback":
"code",
5150 "table_cache":
"Tables",
5228 static doOkCallback(*
hash opt,
int ac,
string type,
string name, *
string table, *
string info);
5230 static *
string doCallback(*
hash opt, *
string sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
5232 static list doCallback(*
hash opt,
list sql,
int ac,
string type,
string name, *
string table, *
string new_name, *
string info);
5335 private list dropSqlUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
5338 private list alignCodeUnlocked(
string type,
hash schema_hash, code
get, code make, *
hash opt,
string make_arg_type);
5553 doDropSql(*softlist
l,
string type,
string name, *
hash opt);
5556 bool doDrop(*softlist
l,
string type,
string name, *
hash opt);
5738 private validateOptionsIntern(
string err,
hash ropt, reference opt);
5741 private validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
5750 static checkDriverOptions(reference h,
string drv);
5792 private abstract string getCreateSqlImpl(
list l);
5793 private abstract list getAlignSqlImpl(
hash schema_hash, *
hash opt);
5794 private abstract list getDropSchemaSqlImpl(
hash schema_hash, *
hash opt);
5799 private abstract *
AbstractView getViewImpl(
string name);
5805 private abstract list featuresImpl();
5806 private abstract list listTablesImpl();
5807 private abstract list listFunctionsImpl();
5808 private abstract list listProceduresImpl();
5809 private abstract list listSequencesImpl();
5810 private abstract list listViewsImpl();
5817 private abstract bool supportsPackagesImpl();
5818 private abstract bool supportsTypesImpl();
6145 rename(
string new_name, *reference sql, *
Tables table_cache);
7816 int del(*
hash cond, *reference sql);
8381 "table_cache":
"Tables",
8401 "table_cache":
"Tables",
8409 "table_cache":
"Tables",
8435 "where":
"hash/list",
8436 "orderby":
"softstringhashlist",
8441 "groupby":
"softstringhashlist",
8450 "foreign_constraints":
True,
8459 "omit":
"softstringlist",
8475 "db_table_cache":
"Tables",
8498 "table_cache":
"Tables",
8538 "sqlarg_callback":
"code",
8548 "info_callback":
"code",
8559 "info_callback":
"code",
8723 private constructor(AbstractDatasource nds,
string nname, *
hash nopts);
8745 private doTableOptions(*
hash nopts);
8949 rename(
string new_name, *reference sql, *
Tables table_cache);
8952 private doRenameIntern(
string new_name, *
Tables table_cache);
8983 private bool emptyUnlocked();
9055 private AbstractColumn addColumnUnlocked(
string cname,
hash opt,
bool nullable =
True, *reference lsql,
bool do_exec =
True,
bool modify_table =
True);
9165 private validateOptionsIntern(
string err,
hash ropt, reference opt);
9168 private validateOptionsIntern(
string err,
hash ropt, reference opt,
string tag);
9171 private execSql(softlist lsql);
9227 private AbstractPrimaryKey addPrimaryKeyUnlocked(
string pkname, softlist cols, *
hash opt, *reference sql);
9230 private AbstractPrimaryKey addPrimaryKeyUnlockedIntern(
string pkname, softlist cols, *
hash opt, *reference sql);
9253 private list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(
string cname, *
hash opt);
9406 private AbstractIndex addIndexUnlocked(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
9409 private AbstractIndex addIndexUnlockedIntern(
string iname,
bool unique, softlist cols, *
hash opt, *reference sql);
9525 private Columns getReferencedTableColumnsUnlocked(
string table, *
Tables cache,
string err =
"FOREIGN-CONSTRAINT-ERROR");
9528 private AbstractForeignConstraint addForeignConstraintUnlocked(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference sql);
9531 private AbstractForeignConstraint addForeignConstraintUnlockedIntern(
string cname, softlist cols,
string table, *softlist tcols, *
hash opt, *reference sql);
9768 private AbstractTrigger addTriggerUnlocked(
string tname,
string src, *
hash opt, *reference lsql);
9771 private AbstractTrigger addTriggerUnlockedIntern(
string tname,
string src, *
hash opt, *reference lsql);
9819 private getAllConstraintsUnlocked(*
hash opt);
9822 private checkUniqueConstraintName(
string err,
string cname);
9825 private checkUniqueConstraintNameValidateOptions(
string err,
string cname,
hash ropt, reference opt);
9905 private insertNoCommitIntern(
hash row, *reference sql, *
hash opt);
9908 private hash getPlaceholdersAndValues(
hash row);
10238 private *
hash doDeleteOthersIntern(
hash pkh, *
hash opt);
10626 string getSelectSqlIntern(*
hash qh, reference args);
10629 string getSelectSqlUnlocked(*
hash qh, reference args);
10632 string getSelectSqlUnlockedIntern(*
hash qh,
string from, reference args, *
hash ch);
10635 private doForUpdate(reference sql);
10638 private string getSelectSqlName(*
hash qh);
10641 private string getColumnExpressionIntern(any cvc, *
hash jch,
bool join, *
hash ch);
10644 private string doColumnOperatorIntern(
hash cvc, *
hash jch,
bool join, *
hash ch);
10647 private string doColumnOperatorIntern(any cop, any arg, *
string cve,
hash cm, *
hash jch,
bool join, *
hash ch);
10650 private string getColumnNameIntern(
string cv, *
hash jch,
bool join, *
hash ch);
10653 private getSelectWhereSqlUnlocked(reference sql, reference args, *
hash qh, *
hash jch,
bool join = False, *
hash ch);
10656 private *
string getWhereClause(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False);
10659 private *
string getWhereClause(
list cond, reference args, *
string cprefix, *
hash jch,
bool join = False);
10662 private *
string getWhereClauseUnlocked(
list cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch);
10665 private *
string getWhereClauseUnlocked(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash pch);
10668 private *
list getWhereClauseIntern(*
hash cond, reference args, *
string cprefix, *
hash jch,
bool join = False, *
hash ch);
10671 private string doWhereExpressionIntern(
string cn, any we, reference args, *
hash jch,
bool join = False, *
hash ch);
10677 private doSelectOrderBySqlUnlocked(reference sql, reference args, *
hash qh, *
hash jch, *
hash ch);
10695 int del(*
hash cond, *reference sql);
10716 private int delNoCommitIntern(*
hash cond, *reference sql, *
hash opt);
10759 private int updateNoCommitIntern(
hash set, *
hash cond, *reference sql, *
hash opt);
10838 private string getUpdateExpression(
string col,
hash uh);
10841 private bool emptyDataUnlocked();
10844 private code getUpsertClosureUnlocked(
hash row,
int upsert_strategy =
UpsertAuto);
10847 private code getUpsertInsertFirst(
Columns cols,
hash example_row);
10850 private code getUpsertUpdateFirst(
Columns cols,
hash example_row);
10853 private code getUpsertSelectFirst(
Columns cols,
hash example_row);
10856 private code getUpsertInsertOnly(
Columns cols,
hash example_row);
10859 private Columns getUpsertColumns(reference csrc);
10862 private string getUpsertSelectSql(
hash row,
Columns cols, reference updc);
10865 private string getUpsertInsertSql(
hash row);
10868 private string getUpsertUpdateSql(
hash row,
Columns cols, reference updc);
10871 private softbool tryUpdate(
string sql,
hash row,
Columns cols,
list updc);
10874 private checkValue(
string cname,
string argname, reference val,
string type);
11073 private *
hash getCheckOmissionOptions(*softlist ol,
string err);
11098 private renameIndexUnlocked(
AbstractIndex ix,
string new_name);
11244 private string getPrimaryKeyColumn();
11422 private string getCreateTableSqlUnlocked(*
hash opt);
11428 private *
string getCreatePrimaryKeySqlUnlocked(*
hash opt,
bool cache =
True);
11434 private *
list getCreateForeignConstraintsSqlUnlocked(*
hash opt,
bool cache =
True);
11446 private cacheUnlocked(*
hash opt);
11449 private any execData(*
hash opt,
string sql, *
list args);
11452 private execData(SQLStatement stmt, *
hash opt, *
list args);
11461 private getColumnsUnlocked();
11464 private getPrimaryKeyUnlocked();
11468 private getIndexesUnlocked();
11471 private getForeignConstraintsUnlocked(*
hash opt);
11477 private getConstraintsUnlocked();
11480 private getTriggersUnlocked();
11483 private softlist getDropSqlImpl();
11486 private string getTruncateSqlImpl();
11501 private preSetupTableImpl(reference desc, *
hash opt);
11504 private abstract bool emptyImpl();
11524 private abstract setupTableImpl(
hash desc, *
hash opt);
11526 private abstract Columns describeImpl();
11528 private abstract Indexes getIndexesImpl();
11530 private abstract Constraints getConstraintsImpl();
11531 private abstract Triggers getTriggersImpl();
11533 private abstract string getCreateTableSqlImpl(*
hash opt);
11534 private abstract *
list getCreateMiscSqlImpl(*
hash opt,
bool cache);
11535 private abstract string getCreateSqlImpl(
list l);
11536 private abstract string getRenameSqlImpl(
string new_name);
abstract string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
const ActionMap
maps from action codes to action descriptions
Definition: SqlUtil.qm.dox.h:5094
list getAlignSql(AbstractTable table, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:4013
string getRenameColumnSql(string old_name, string new_name, *hash opt)
gets an SQL string that can be used to rename an existing column in the table
private validateHashKeysForWhitespaces(any node)
Check input node for all hash keys - if it contains a key with whitespace in the beginning or at the ...
constructor(string n_name, number n_start=1, number n_increment=1, *softnumber n_max)
creates the object from the arguments
int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
hash cop_avg(any column)
returns a hash for the "avg" operator; returns average column values
string getElementName()
returns "column" since this object stores column objects
softlist getDropSql(*hash opt)
returns the sql required to drop the table; reimplement in subclasses if necessary ...
bool hasColumn(string cname)
returns True if the constraint references the named column
constructor()
creates an empty object
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:4101
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql)
adds an index to the table; if the table is already known to be in the database, then it is added in ...
createNoCommit(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
const SelectOptions
default select options
Definition: SqlUtil.qm.dox.h:8431
string getDropSql()
returns a string that can be used to drop the function from the database
Constraints getConstraints()
returns a Constraints object describing the non-foreign constraints on the table
private hash getCacheOptions()
returns the cache options for this driver
*hash find(any id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:4282
hash uop_lower(*hash nest)
returns a hash for the "lower" operator with the given argument; returns a column value in lower case...
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
const COP_SEQ
to return the value of a sequence
Definition: SqlUtil.qm.dox.h:1780
Qore::AbstractIterator pairIterator()
Returns a HashPairIterator object for the contained hash.
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:8607
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
list getAlignProcedureSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a stored procedure in the database to the st...
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
hash op_cge(string arg)
returns a hash for the ">=" operator with the given argument for use in where clauses when comparing ...
const DefaultIopMap
a hash of default insert operator descriptions
Definition: SqlUtil.qm.dox.h:3093
int updateNoCommit(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
private hash getTriggerOptions()
returns the trigger options for this driver
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:3405
*list getCreateTriggersSql(*hash opt)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
const TableOmissionOptions
alignment omission options
Definition: SqlUtil.qm.dox.h:8448
string getDropSql()
returns a string that can be used to drop the sequence from the database
list getDropSchemaSql(hash schema_hash, *hash opt)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
copy(AbstractHashContainer old)
creates a "deep copy" of the object
hash cop_append(any column, string arg)
returns a hash for the "append" operator with the given argument
hash uop_append(string arg, *hash nest)
returns a hash for the "append" or concatenate operator with the given argument
string sprintf(string fmt,...)
constructor(*hash nh)
creates the object with the hash argument passed
Qore::ListIterator iterator()
Returns a ListIterator object for the contained list.
private hash getDatabaseOptions()
override in subclasses to return driver-specific options
const AC_Unchanged
used when an existing object matches the template and no changes are made
Definition: SqlUtil.qm.dox.h:5057
string getElementName()
must return the name of the contained element
bool equal(ForeignConstraintTarget targ)
returns True if the argument is equal to the current object, False if not
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table is already known to be in the database...
bool dropProcedureIfExists(string name, *hash opt)
drops the given procedure if it exists; returns True if the procedure was dropped, False if not
const OP_IN
the SQL "in" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2699
bool checkExistence()
returns True if the table exists in the database, False if not
*hash getHash()
returns the hash contained by this object
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:8370
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:1783
bool equal(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
any methodGate(string meth)
executes a method on the contained AbstractTable object
hash iop_seq(string arg)
returns a hash for retrieving the value of the given sequence in insert queries
bool equalExceptName(AbstractIndex ix)
returns True if the argument is equal to the current index with the exception of the name...
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:1641
AbstractFunction memberGate(string k)
returns the AbstractFunction object corresponding to the key given or throws a KEY-ERROR exception ...
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
hash uop_upper(*hash nest)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
list getAlignFunctionSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a function in the database to the function d...
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:8408
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
int delNoCommit(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; no transactio...
const ColumnOptions
Column options; this is currently empty and can be extended in database-specific modules.
Definition: SqlUtil.qm.dox.h:8531
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:3494
*list getCreateForeignConstraintsSql(*hash opt)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
constructor(string n)
creates the object and sets its name
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:4325
private hash getCreationOptions()
override in subclasses to return driver-specific options
drop(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
hash 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...
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
const UpsertResultLetterMap
maps upsert result codes to single letter symbols
Definition: SqlUtil.qm.dox.h:8682
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:8619
hash make_iop(string iop, any arg)
returns a hash with _iop and arg keys
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
AbstractIndex take(string k)
removes the given key from the contained hash and returns the value
int update(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the sequence in the database
abstract list getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the trigger in the database
const DropSchemaOptions
default generic drop schema options
Definition: SqlUtil.qm.dox.h:5163
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
hash uop_prepend(string arg, *hash nest)
returns a hash for the "prepend" operator with the given argument
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
const SchemaDescriptionOptions
default generic schema description keys
Definition: SqlUtil.qm.dox.h:5178
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:8644
constructor(string t, Columns c)
creates the object and sets the target table name and the target columns
constructor(string n_name, string n_src)
creates the object from the arguments
string getDriverName()
returns the database driver name
hash op_in()
returns a hash for the "in" operator with all arguments passed to the function; for use in where clau...
cache(*hash opts)
reads in all attributes of the table from the database
string printf(string fmt,...)
const OP_BETWEEN
the SQL "between" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2694
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view cannot be found ...
int upsert(hash row, int upsert_strategy=UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
abstract any take(string k)
removes the given key from the contained hash and returns the value
const DatabaseOptions
database options
Definition: SqlUtil.qm.dox.h:5024
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database; if disabli...
private hash getIndexOptions()
returns the index options for this driver
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:3890
*AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk)
finds a unique constraint with the same columns as the unique constraint passed
hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:4098
*AbstractUniqueConstraint getSupportingConstraint()
returns the supporting constraint, if any
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
*hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
add(string k, AbstractColumn val)
adds the given value to the hash with the given key name
const COP_OVER
the SQL "over" clause
Definition: SqlUtil.qm.dox.h:1735
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:4175
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:8673
Columns columns
an object of class Columns giving the source table that make up the constraint
Definition: SqlUtil.qm.dox.h:4249
const UR_Deleted
row was deleted (only possible with batch upsert methods such as Table::upsertFromIterator() where up...
Definition: SqlUtil.qm.dox.h:8656
list listTables()
returns a list of string table names in the database
bool dropProcedureIfExists(string name, *hash opt)
drops the given procedure if it exists; returns True if the procedure was dropped, False if not
hash op_ne(any arg)
returns a hash for the "!=" or "<>" operator with the given argument for use in where clauses when co...
bool dropFunctionIfExists(string name, *hash opt)
drops the given function if it exists; returns True if the function was dropped, False if not ...
constructor(string n, *hash c, *string n_index)
creates the object from the name an a hash of column information
abstract private bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns a hash keyed with the table name assigned to a hash with jop, table, jcols, cond, alias, and ta keys
clearIndex()
clears any index base for the constraint
AbstractForeignConstraint removeForeignConstraint(string cname)
removes the named foreign constraint from the table; no SQL is executed in any case, only the named foreign constraint is removed from the table definition
bool hasColumn(string cname)
returns True if the constraint references the named column
const OP_NE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2654
AbstractIndex dropIndex(string iname, *reference sql)
drops the given index from the table; if the table is known to be in the database already...
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table
list listSequences()
returns a list of string sequence names in the database
setSupportingConstraint()
clears the supporting constraint
hash cop_as(any column, string arg)
returns a hash for the "as" operator with the given argument
private hash getSchemaDescriptionOptions()
override in subclasses to return driver-specific options
string getType()
returns the type of object
any methodGate(string meth)
executes a method on the contained AbstractDatabase object
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
abstract softlist getRenameSql(string new_name)
returns a list with command(s) that can be used to rename the view in the database ...
hash cop_year_month(any column)
returns a hash for the "year_month" operator with the given argument
list getAlignSql(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from the database
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
private constructor(AbstractDatasource nds, string nname, *hash nopts)
creates the object; private constructor
truncate()
truncates all the table data; releases the transaction lock after executing
string name
the name of the object
Definition: SqlUtil.qm.dox.h:4351
string getAlignSqlString(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table; if the table is known to be in the database already, then it is also dropped from the database immediately; otherwise it is only removed internally
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:4222
string getAlignSqlString(AbstractTable table, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
*list getCreateIndexesSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
*string getDropFunctionSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given function if it exists or NOTHING if the named function does...
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:3734
add(string k, AbstractConstraint val)
adds the given value to the hash with the given key name
hash op_gt(any arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing c...
Constraints getConstraints()
returns a Constraints object describing non-foreign constraints on the table
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:3830
AbstractIndex renameIndex(string old_name, string new_name, reference sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt)
returns a list of strings to drop and recreate the current index; if there are dependent constraints...
const AC_Create
used when a new object is created
Definition: SqlUtil.qm.dox.h:5060
add(string k, AbstractFunction val)
adds the given value to the hash with the given key name
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
AbstractTrigger memberGate(string k)
returns the AbstractTrigger object corresponding to the key given or throws a KEY-ERROR exception ...
list listViews()
returns a list of string view names in the database
softint rowCount()
returns the number of rows in the table
*string getCreatePrimaryKeySql(*hash opt)
returns an SQL string that could be used to create the primary key on the table
abstract private hash getQoreTypeMapImpl()
returns the qore type -> column type map
list keys()
Returns a list of key names of the contained hash.
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql)
adds a foreign constraint to the table; if the table is already known to be in the database...
const JopMap
a hash of valid join operators
Definition: SqlUtil.qm.dox.h:2316
hash make_op(string op, any arg)
returns a hash with op and arg keys
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:1664
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2644
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:1647
hash op_clt(string arg)
returns a hash for the "<" operator with the given argument for use in where clauses when comparing t...
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:1725
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:1627
const DB_MVIEWS
Feature: materialized views/snapshots.
Definition: SqlUtil.qm.dox.h:1621
int del(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; the transacti...
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
private clearImpl()
clears any driver-specific table information
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:2308
base class for sequences
Definition: SqlUtil.qm.dox.h:4277
*list getCreateTriggersSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
list listFunctions()
returns a list of string function names in the database
hash op_cgt(string arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing t...
private hash getColumnOperatorMap()
returns the column operator map for this object
string getElementName()
must return the name of the contained element
add(any val)
adds the given value to the list
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
abstract string getElementName()
must return the name of the contained element
int updateNoCommit(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
Columns subset(softlist l)
returns a subset of the current columns according to the list argument
bool nullable
True if the column can hold a NULL value, False if not
Definition: SqlUtil.qm.dox.h:3740
hash cop_min(any column)
returns a hash for the "min" operator; returns minimum column values
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql)
adds a primary key to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:8547
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:1710
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:1775
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:8400
AbstractFunction makeFunction(string name, string src, *hash opts)
creates a database-specific AbstractFunction object corresponding to the arguments ...
Columns describe()
returns an object of class Columns describing the table
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found ...
*list getDropAllForeignConstraintsOnTableSql(string name, *hash opt)
returns a list of SQL strings that can be used to drop all the foreign constraints on a particular ta...
int update(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:8702
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:8708
*AbstractUniqueConstraint constraint
the AbstractUniqueConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:3907
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt)
gets a list of SQL strings to drop all constraints and indexes with the given column name; if the col...
private hash getUpdateOperatorMap()
returns the update operator map for this object
bool dropSequenceIfExists(string name, *hash opt)
drops the given sequence if it exists; returns True if the sequence was dropped, False if not ...
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
string getSelectSql(*hash sh, *reference args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
AbstractFunction take(string k)
removes the given key from the contained hash and returns the value
hash op_cne(string arg)
returns a hash for the "!=" or "<>" operator with the given argument for use in where clauses when co...
create(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql)
adds a trigger to the table; if the table is already known to be in the database, then it is added in...
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:4963
const CacheOptions
generic cache options
Definition: SqlUtil.qm.dox.h:5032
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:8591
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
abstract private bool tryInsertImpl(string sql, hash row)
tries to insert a row, if there is a duplicate key, then it returns False, if successful, returns True
int del(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; the transacti...
list getAddColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
returns a list of SQL strings that can be use to add a column to the table
const AC_Modify
used when an object is modified in place
Definition: SqlUtil.qm.dox.h:5069
bool equal(Columns cols)
returns True if the argument has the same columns in the same order as the current object...
*hash upsertFromSelectNoCommit(AbstractTable src, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
create(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
const OP_CNE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2684
any memberGate(string k)
returns the value of the given key in the contained hash if it exists, otherwise throws a KEY-ERROR e...
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:4514
int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
abstract private doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh)
processes a string for use in SQL select statements when there is a "limit" argument, but no "orderby" or "offset" arguments
constructor(AbstractDatasource ds, string name, *hash opts)
creates the Table object
private hash getSqlDataCallbackOptions()
returns the sql data operation callback options for this driver
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2674
bool dropSequenceIfExists(string name, *hash opt)
drops the given sequence if it exists; returns True if the sequence was dropped, False if not ...
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:4244
hash op_like(string str)
returns a hash for the "like" operator with the given argument for use in where clauses ...
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:4252
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
constructor(string n, string n_src)
creates the object and sets its name and the check clause source
AbstractConstraint memberGate(string k)
returns the AbstractConstraint object corresponding to the key given or throws a KEY-ERROR exception ...
Mutex l()
mutex for atomic actions
abstract private copyImpl(AbstractTable old)
db-specific copy actions
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
hash op_lt(any arg)
returns a hash for the "<" operator with the given argument for use in where clauses when comparing c...
abstract string getCreateSql(string table_name, *hash opts)
returns a string that can be used to create the constraint in the database
hash op_le(any arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:3835
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:4066
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
bool emptyData()
returns True if the table has no data rows, False if not
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
const AC_Drop
used when an object is dropped
Definition: SqlUtil.qm.dox.h:5063
bool equal(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
constructor(string n, bool u, hash c)
creates the object from the name, a unique flag, and a hash of column information ...
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:1730
createNoCommit(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
int getNextSequenceValue(string name)
returns the next value in the given sequence
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2689
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:3127
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
bool empty()
returns True if the table has no definitions, False if not
hash cop_distinct(any column)
returns a hash for the "distinct" operator with the given argument; returns distinct column values ...
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
const ActionLetterMap
maps from action codes to action letter codes
Definition: SqlUtil.qm.dox.h:5126
string name
the table's name
Definition: SqlUtil.qm.dox.h:8694
abstract private bool supportsTablespacesImpl()
returns True if the database support tablespaces
bool supportsPackages()
returns True if the database supports packages
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:4466
renameSourceConstraintTable(string old_name, string new_name)
renames a table in a source constraint
AbstractTrigger dropTrigger(string tname, *reference sql)
drops the given trigger from the table; if the table is known to be in the database already...
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:2190
int index(softstring str, softstring substr, softint pos=0)
string src
the source of the check clause
Definition: SqlUtil.qm.dox.h:4071
string getDatasourceDesc()
returns a descriptive string for the datasource
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:8700
*string getDropSequenceSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given sequence if it exists or NOTHING if the named sequence does...
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
private hash getDropSchemaOptions()
override in subclasses to return driver-specific options
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:1623
AbstractColumn take(string k)
removes the given key from the contained hash and returns the value
*hash upsertFromSelect(AbstractTable src, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
list listProcedures()
returns a list of string procedure names in the database
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:1700
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
const COP_PLUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:1745
private hash getSelectOptions()
returns the select options for this driver
abstract private bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
hash cop_minus(any column1, any column2)
returns a hash for the "-" operator with the given arguments
cache(*hash opts)
reads in all attributes of the table from the database
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8647
abstract private bool supportsSequencesImpl()
returns True if the database supports sequences
clear()
purges the current table definition
const OP_GE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2649
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:3848
private validateColumnOptions(string cname, reference opt, bool nullable)
validates column options
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:1670
abstract private bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql)
adds a unique constraint to the table; if the table is known to be in the database already...
const TableOptions
table options
Definition: SqlUtil.qm.dox.h:8379
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
const AC_Rename
used when an object is renamed
Definition: SqlUtil.qm.dox.h:5066
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
abstract bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
private hash getTableColumnDescOptions()
returns the table column description options for this driver
*hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:3743
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
string getCreateSql(AbstractTable t)
returns an sql string that can be used to add the column to a table
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:8698
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
insertNoCommit(hash row, *reference sql)
inserts a row into the table without any transaction management; a transaction will be in progress af...
AbstractPrimaryKey addPrimaryKey(string cname, softlist cols, *hash opt, *reference sql)
adds a primary key to the table; if the table already exists, then it is added in the database also i...
hash cop_plus(any column1, any column2)
returns a hash for the "+" operator with the given arguments
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:8712
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:8470
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
*AbstractIndex findEqual(AbstractIndex ix)
find an index with columns equal to the index passed
bool emptyData()
returns True if the table has no data rows, False if not
bool tableRenamed(string old_name, string new_name, string old_sql_name)
updates table names and internal references for renamed tables
removeSourceConstraint(string tname, list cols)
removes a source constraint
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
AbstractColumn addColumn(string cname, hash opt, bool nullable=True, *reference lsql)
adds a column to the table; if the table already exists, then it is added in the database also immedi...
int upsertNoCommit(hash row, int upsert_strategy=AbstractTable::UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
*list getCreateForeignConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
string getNativeTypeString(string native_type, int precision)
returns the string describing the native type that can be used in SQL (for example to add the column ...
hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts)
returns lists of SQL strings to disable this constraint plus any dependent constraints and another li...
hash cop_lower(any column)
returns a hash for the "lower" operator with the given argument; returns a column value in lower case...
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:8706
*string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts)
returns an SQL string that can be used to rename the given table if it exists and the target does not...
Columns describe()
returns an object of class Columns describing the Table
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:1625
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:5148
abstract string getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
AbstractTable memberGate(string k)
returns the AbstractTable object corresponding to the key given or throws a KEY-ERROR exception ...
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2659
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database; if disabling constraints ...
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
bool dropViewIfExists(string name, *hash opt)
drops the given view if it exists; returns True if the view was dropped, False if not ...
AbstractForeignConstraint take(string k)
removes the given key from the contained hash and returns the value
abstract private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
abstract string getElementName()
must return the name of the contained element
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:3746
Qore::AbstractIterator dropIterator()
returns an iterator for a list of cached table names in the order that can be used to drop the tables...
Qore::AbstractIterator getSourceConstraintIterator()
returns an iterator through all known source foreign constraints on the current table ...
list getAlignFunctionSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a function in the database to the function d...
AbstractIndex dropIndex(string iname, *reference sql)
drops the index from the table; if the table is known to be in the database already, then it is also dropped from the database immediately; otherwise it is only removed internally
string getName()
returns the name of the table
code getUpsertClosure(hash example_row, int upsert_strategy=AbstractTable::UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
bool val()
Returns False if the contained list is empty, True if not.
string getSelectSql(*hash sh, *reference args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
string src
the source code
Definition: SqlUtil.qm.dox.h:4322
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:3898
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
list getModifySql(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
hash cop_over(any column, string arg)
returns a hash for the "over" clause
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
const AC_Insert
used when data is inserted in a table
Definition: SqlUtil.qm.dox.h:5081
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
add(string k, Table val)
adds the given value to the hash with the given key name
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
constructor(AbstractDatasource ds, *hash opts)
creates the Database object
string getNativeTypeString()
returns the string describing the native type that can be used in SQL (for example to add the colunn ...
Qore::AbstractIterator iterator()
Returns a HashIterator object for the contained hash.
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifiers for schema, etc)
abstract list getAddColumnSql(AbstractTable t)
returns a list of sql strings that can be used to add the column to an existing table ...
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:1765
string src
the source of the object
Definition: SqlUtil.qm.dox.h:4357
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
string getElementName()
must return the name of the contained element
private hash getForeignConstraintOptions()
return the foreign constraint options for this driver
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:1720
AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql)
drops a foreign constraint from the table; if the table is known to be in the database already...
insert(hash row, *reference sql)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:1680
string getDriverName()
returns the database driver name
hash cop_divide(any column1, any column2)
returns a hash for the "/" operator with the given arguments
hash op_ge(any arg)
returns a hash for the ">=" operator with the given argument for use in where clauses when comparing ...
abstract list getRenameSql(string table_name, string new_name)
returns a list of SQL strings that can be used to rename the constraint in the database ...
hash cop_seq(string seq)
returns a hash for the "seq" operator with the given argument giving the sequence name whose value sh...
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:8696
int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:1633
hash op_not(hash arg)
returns a hash for the "not" operator; for use in where clauses
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql)
adds an foreign constraint to the table; if the table is already known to be in the database...
const OP_LE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2639
private hash getCacheOptions()
override in subclasses to return driver-specific options
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:1650
string name
the name of the index
Definition: SqlUtil.qm.dox.h:3895
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
hash cop_value(any arg)
returns a hash for the "value" operator with the given argument
AbstractConstraint dropConstraint(string cname, *reference sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
*string getCreatePrimaryKeySql(*hash opt, bool cache=True)
returns an SQL string that could be used to create the primary key on the table
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:4230
drop(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
const OP_CLE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2669
hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
AbstractColumn addColumn(string cname, hash opt, bool nullable=True, *reference lsql)
adds a column to the table; if the table is already known to be in the database, then it is added in ...
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table already exists, then the changes are effected ...
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:1629
list getAlignProcedureSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a stored procedure in the database to the st...
string getElementName()
must return the name of the contained element
*hash select(*hash sh, *reference sql)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:1653
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
bool supportsTypes()
returns True if the database supports named types
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2704
AbstractColumn renameColumn(string old_name, string new_name, reference sql)
renames an existing column; if the table already exists, then the changes are effected in the databas...
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
clear()
purges the contained data
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:3901
*list getCreateConstraintsSql(*hash opt)
returns a list of SQL strings that could be used to create non-foreign constraints on the table or NO...
AbstractForeignConstraint memberGate(string k)
returns the AbstractForeignConstraint object corresponding to the key given or throws a KEY-ERROR exc...
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:8537
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:4346
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:1631
addSourceConstraint(string tname, AbstractForeignConstraint fk)
adds a foreign constraint source to the unique constraint
string getRenameColumnSql(string old_name, string new_name, *hash opt)
gets an SQL string that can be used to rename an existing column in the table
AbstractTable makeTable(string name, hash desc, *hash opts)
creates a database-specific AbstractTable object corresponding to the arguments
bool empty()
returns True if the container is empty, False if not
copy(AbstractTable old)
copies the object
private hash getInsertOptions()
returns the insert options for this driver
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
AbstractFunction makeFunction(string name, string src, *hash opt)
creates a database-specific AbstractFunction object corresponding to the arguments ...
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:8662
findMatchingIndex(*Indexes indexes)
find an index that matches the constraint and marks both objects as related
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
string name
the name of the column
Definition: SqlUtil.qm.dox.h:3728
bool empty()
returns True if the container is empty, False if not
bool supportsSequences()
returns True if the database supports sequences
private hash getAlignSchemaOptions()
override in subclasses to return driver-specific options
string string(softstring str)
private hash getConstraintOptions()
returns the constraint options for this driver
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:4968
string getName()
returns the constraint name
insert(hash row, *reference sql)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
*list getCreateMiscSql(*hash opt)
returns a list of SQL strings that could be used to create other table attributes (such as comments...
abstract private list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
string getName()
returns the index name
base class for functions
Definition: SqlUtil.qm.dox.h:4387
private hash getTableDescriptionHashOptions()
returns the table description hash options for this driver
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
const COP_MULTIPLY
the SQL "multiply" operator
Definition: SqlUtil.qm.dox.h:1755
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql)
adds a unique constraint to the table; if the table is known to be in the database already...
list listSequences()
returns a list of string sequence names in the database
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:8704
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:1685
list getDropSchemaSql(hash schema_hash, *hash opt)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
hash cop_count(string column="")
returns a hash for the "count" operator; returns row counts
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
list listFunctions()
returns a list of string function names in the database
bool partialMatchKeys(hash h1)
returns True if the hash argument has at least the same keys (in any order, can have more keys)...
AbstractSequence makeSequence(string name, number start=1, number increment=1, *softnumber end, *hash opts)
creates a database-specific AbstractSequence object corresponding to the arguments ...
const AC_Recreate
used when an object is recreated (usually dropped and recreated in place)
Definition: SqlUtil.qm.dox.h:5078
*string getIndex()
returns the name of the associated index, if any
abstract clearIndex()
clears any index base for the constraint
base class for views
Definition: SqlUtil.qm.dox.h:4311
bool dropTableIfExists(string name, *hash opt)
drops the given table if it exists; returns True if the table was dropped, False if not ...
bool hasKey(string k)
Returns True if the key exists in the contained hash (may or may not be assigned a value)...
bool equal(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
abstract list getRenameSql(string new_name)
returns a string that can be used to rename the function in the database
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:4974
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
AbstractTable getTable()
returns the AbstractTable object contained by this object
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:5211
*list getCreateConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create non-foreign constraints on the table or NO...
list getAddColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
returns a list of SQL strings that can be use to add a column to the table
bool checkExistence()
returns True if the table exists in the database, False if not
AbstractFunction makeProcedure(string name, string src, *hash opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
renameKey(string old_name, string new_name)
renames the given key; maintains the key order
*hash selectRow(*hash sh, *reference sql)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
private hash getTableCreationOptions()
returns the table creation options for this driver
const InsertOptions
default insert option keys
Definition: SqlUtil.qm.dox.h:8558
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
AbstractTrigger take(string k)
removes the given key from the contained hash and returns the value
abstract private bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
*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...
insertNoCommit(hash row, *reference sql)
inserts a row into the table without any transaction management; a transaction will be in progress af...
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:8415
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
hash cop_prepend(any column, string arg)
returns a hash for the "prepend" operator with the given argument
AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql)
drops the foreign constraint from the table; if the table is known to be in the database already...
string type
the type of object
Definition: SqlUtil.qm.dox.h:4354
setupTable(hash desc, *hash opt)
creates the object from a table description hash
AbstractIndex renameIndex(string old_name, string new_name, reference sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
abstract private doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch)
processes a string for use in SQL select statements when there is an "order by" and "offset" argument...
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:1760
constructor(softlist nl)
creates the object with the list argument passed
bool hasColumn(string cname)
returns True if the constraint references the named column
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
const SequenceDescriptionOptions
default generic sequence description keys
Definition: SqlUtil.qm.dox.h:5201
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
abstract list getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the trigger in the database
*list getCreateIndexesSql(*hash opt)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
softint rowCount()
returns the number of rows in the table
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
string getElementName()
returns "table" since this object stores AbstractTable objects
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
abstract private hash getTypeMapImpl()
returns the type name -> type description hash
string getDropSql()
returns a string that can be used to drop the view from the database
dropNoCommit(*hash opt)
drops the table from the database without any transaction management
string getElementName()
returns "foreign constraint" for the type of object encapsulated
int size
the size of the column
Definition: SqlUtil.qm.dox.h:3737
AbstractColumn renameColumn(string old_name, string new_name, reference sql)
renames an existing column; if the table is already known to be in the database, then the changes are...
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
bool dropTableIfExists(string name, *hash opt)
drops the given table if it exists; returns True if the table was dropped, False if not ...
list listProcedures()
returns a list of string procedure names in the database
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
string getSqlValue(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
int size()
Returns the number of keys in the contained hash.
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
Qore::AbstractIterator keyIterator()
Returns a HashKeyIterator object for the contained hash.
private hash getWhereOperatorMap()
returns the "where" operator map for this object
*hash upsertFromIteratorNoCommit(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...
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
abstract string getRenameSql(string new_name)
returns a string that can be used to rename the sequence in the database
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:3731
const COP_VALUE
to append a constant value to use as an output column value
Definition: SqlUtil.qm.dox.h:1695
truncateNoCommit()
truncates all the table data without any transaction management
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:3676
the base class for triggers
Definition: SqlUtil.qm.dox.h:4448
hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
hash op_eq(any arg)
returns a hash for the "=" operator with the given argument for use in where clauses when comparing c...
private hash getAlignTableOptions()
returns the align table options for this driver
int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
const OP_LT
the SQL less than (<) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2634
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:4970
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
bool empty()
returns True if the table has no definitions, False if not
const AlignSchemaOptions
default generic schema description / alignment options
Definition: SqlUtil.qm.dox.h:5158
*hash findConstraintOn(string table, softlist cols)
returns either a hash of AbstractColumn information or NOTHING if no foreign constraint can be found ...
add(string k, AbstractForeignConstraint val)
adds the given value to the hash with the given key name
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:4410
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8653
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
rename(string new_name, *reference sql, *Tables table_cache)
renames the table; if the table already exists in the database, then the changes are effected in the ...
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8650
int getNextSequenceValue(string name)
returns the next value in the given sequence
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:4519
the base class for column information
Definition: SqlUtil.qm.dox.h:3723
truncate()
truncates all the table data; releases the transaction lock after executing
bool hasColumn(string cname)
returns True if the constraint references the named column
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:8614
setName(string new_name)
sets the new name of the object
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
add(string k, AbstractTrigger val)
adds the given value to the hash with the given key name
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2679
const AC_Truncate
used when a table is truncated
Definition: SqlUtil.qm.dox.h:5072
hash op_cle(string arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
string getName()
returns the name of the table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:5832
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:8389
private hash getColumnOptions()
returns the column options for this driver
list values()
Returns a list of values of the contained hash.
AbstractConstraint dropConstraint(string cname, *reference sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
*hash find(any id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
bool equal(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
rename(string new_name, *reference sql, *Tables table_cache)
renames the table; if the table is already known to be in the database in the database, then the changes are effected in the database also immediately; otherwise it is only updated internally
AbstractTable take(string k)
removes the given key from the contained hash and returns the value
hash make_cop(string cop, any column, any arg)
returns a hash with cop, column, and arg keys
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:1715
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:8600
bool dropFunctionIfExists(string name, *hash opt)
drops the given function if it exists; returns True if the function was dropped, False if not ...
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:1770
dropNoCommit(*hash opt)
drops the table from the database without any transaction management
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy=AbstractTable::UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
setupTable(hash desc, *hash opt)
creates the object from a table description hash
add(string k, AbstractIndex val)
adds the given value to the hash with the given key name
AbstractFunction makeProcedure(string name, string src, *hash opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:8583
private hash getCallbackOptions()
override in subclasses to return driver-specific options
*hash selectRow(*hash sh, *reference sql)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql)
adds an index to the table; if the table already exists, then it is added in the database also immedi...
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:4319
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
constructor(string n, string n_src)
creates the object and sets its name and the trigger source
list features()
See DBFeaturesConstants.
*number max
the ending number
Definition: SqlUtil.qm.dox.h:4291
abstract private bool checkExistenceImpl()
returns True if the table exists in the DB, False if not
hash cop_upper(any column)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
code getUpsertClosure(hash example_row, int upsert_strategy=UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
bool val()
Returns False if the contained hash has no keys, True if it does.
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
*list selectRows(*hash sh, *reference sql)
returns a list of hashes representing the rows in the table that match the argument hash ...
list getList()
returns the list contained by this object
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
const ColumnDescOptions
Column description options.
Definition: SqlUtil.qm.dox.h:8513
number increment
the increment
Definition: SqlUtil.qm.dox.h:4288
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
AbstractColumn memberGate(string k)
returns the AbstractColumn object corresponding to the key given or throws a KEY-ERROR exception ...
bool matchKeys(hash h1)
returns True if the hash argument has the same keys (in any order), False if not
list listViews()
returns a list of string view names in the database
*string getDropProcedureSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given procedure if it exists or NOTHING if the named procedure do...
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
const OP_LIKE
the SQL "like" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2629
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
const CallbackOptions
generic callback options
Definition: SqlUtil.qm.dox.h:5042
const TableDescriptionHashOptions
Table description options.
Definition: SqlUtil.qm.dox.h:8490
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:1661
AbstractIndex memberGate(string k)
returns the AbstractIndex object corresponding to the key given or throws a KEY-ERROR exception ...
int size()
Returns the number of elements in the contained list.
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
list getDropList()
returns a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql)
adds a trigger to the table; if the table is already known to be in the database, then it is added in...
const ActionDescMap
maps from action descriptions to action codes
Definition: SqlUtil.qm.dox.h:5110
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:5837
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy=UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
abstract private *string getSqlValueImpl(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
const OP_CLT
the SQL less than (<) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:2664
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:1740
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
clear()
purges the current table definition
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
clearIndex()
clears any index base for the constraint
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:4227
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
abstract private int getNextSequenceValueImpl(string name)
returns the next value in the given sequence
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
private hash getColumnDescOptions()
returns the column description options for this driver
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
const TableCreationOptions
table creation options
Definition: SqlUtil.qm.dox.h:8458
hash cop_year_day(any column)
returns a hash for the "year_day" operator with the given argument
const AC_Delete
used when data is deleted in a table
Definition: SqlUtil.qm.dox.h:5087
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
list listTables()
returns a list of string table names in the database
*list getCreateMiscSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create other table attributes (such as comments...
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:2313
AbstractTrigger dropTrigger(string tname, *reference sql)
drops the given trigger from the table; if the table is known to be in the database already...
hash make_uop(string uop, any arg, *hash nest)
returns a hash with uop, arg, and nest keys
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:1667
const AC_Update
used when data is updated in a table
Definition: SqlUtil.qm.dox.h:5084
int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
private hash getInsertOperatorMap()
returns the insert operator map for this object
*string getDropConstraintIfExistsSql(string tname, string cname, *hash opts)
returns an SQL string that can be used to drop an existing constraint on a table, if the table is not...
AbstractSequence makeSequence(string name, number start=1, number increment=1, *softnumber end, *hash opts)
creates a database-specific AbstractSequence object corresponding to the arguments ...
hash cop_year(any column)
returns a hash for the "year" operator with the given argument
number start
the starting number
Definition: SqlUtil.qm.dox.h:4285
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:3090
const AC_NotFound
used when dropping object but the object is not present
Definition: SqlUtil.qm.dox.h:5090
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
populate(AbstractDatasource ds, hash tables, *hash opt)
populates the object from a hash description
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:5016
int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
private hash getTableOptions()
returns the table options for this driver
*list getDropTableSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given table if it exists or NOTHING if the named table does not e...
int upsert(hash row, int upsert_strategy=AbstractTable::UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
any take(int i)
removes the given element from the contained list and returns the value
hash cop_multiply(any column1, any column2)
returns a hash for the "*" operator with the given arguments
*hash select(*hash sh, *reference sql)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
const AC_Add
used when an element is added to an existing object
Definition: SqlUtil.qm.dox.h:5075
truncateNoCommit()
truncates all the table data without any transaction management
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
string getDropSql(string table_name)
returns a string that can be used to drop the index from the database
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
*AbstractForeignConstraint findEqual(AbstractForeignConstraint fk)
find an index with columns equal to the index passed
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
represents a primary key
Definition: SqlUtil.qm.dox.h:4164
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:2303
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:1705
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found ...
private hash getSequenceDescriptionOptions()
override in subclasses to return driver-specific options
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:1750
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:1619
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:1644
abstract list getCreateSql(*hash opt)
returns a list of SQL strings that can be used to create the function in the database ...
abstract bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
hash op_ceq(string arg)
returns a hash for the "=" operator with the given argument for use in where clauses when comparing t...
*list selectRows(*hash sh, *reference sql)
returns a list of hashes representing the rows in the table that match the argument hash ...
string getDropSql(string table_name)
returns a string that can be used to drop the column from the table
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:8630
*string lastKey()
Returns the last key name in the contained hash or NOTHING if the contained hash has no keys...
int delNoCommit(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; no transactio...
private bool equalImpl(AbstractConstraint con)
returns True if the argument is equal to the current object, False if not
AbstractConstraint take(string k)
removes the given key from the contained hash and returns the value
*string firstKey()
Returns the first key name in the contained hash or NOTHING if the contained hash has no keys...
*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...
bool supportsSequences()
returns True if the database supports sequences
*hash upsertFromIteratorNoCommit(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...
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
hash cop_year_hour(any column)
returns a hash for the "year_hour" operator with the given argument
bool hasKeyValue(string k)
Returns True if the key exists in the contained hash and is assigned a value, False if not...
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:8397
*AbstractTable getIfExists(AbstractDatasource ds, string name)
gets a table from the database or from the cache if already cached; if the table does not exist...
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2707
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:4093
rename(string n)
renames the constraint
private hash getUpsertOptions()
returns the upsert options for this driver
AbstractTable makeTable(string name, hash desc, *hash opts)
creates a database-specific AbstractTable object corresponding to the arguments
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:8526
hash cop_max(any column)
returns a hash for the "max" operator; returns maximum column values
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:4004
string getSqlValue(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
hash uop_seq(string seq)
returns a hash for the "seq" operator with the given argument giving the sequence name whose value sh...
AbstractForeignConstraint removeForeignConstraint(string cname)
removes the named foreign constraint from the table; no SQL is executed in any case, only the named foreign constraint is removed from the table definition
int upsertNoCommit(hash row, int upsert_strategy=UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:3962
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:1690