Qore SqlUtil Module Reference  1.4.4
SqlUtil.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file SqlUtil.qm Qore user module for working with SQL data
3 
4 /* SqlUtil.qm Copyright (C) 2013 - 2018 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // this module requires Qore 0.8.13 or better
26 
27 // requires the Util module
28 
29 // don't use "$" signs for variables and class members, assume local variable scope
30 
31 // require type definitions everywhere
32 
33 // enable all warnings
34 
35 
36 // version history is included below in the docs
37  ...
392  @endcode
393  @warning Oracle: using different comments in the same SQL can lead to new optimizer statement hard parsing.
394 
395  @subsubsection select_option_hint Select Option "hint"
396  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).
397 
398  <b>Hint Example:</b>
399  @code{.py}
400 table.selectRows(("hint": "full(t1)"));
401  @endcode
402  will produce select statement like this:
403  @code{.py}
404 select /*+ full(a) */ ...
405  @endcode
406  The string is taken as-is and it's up to the caller to handle correct aliases in join functions etc.
407  @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
408  @warning Use hints only when you know what you are doing.
409 
410  @subsubsection select_option_columns Select Option "columns"
411  <b>Columns Example:</b>
412  @code{.py}
413 list columns = (
414  "id", "name", "started",
415  cop_as("warnings", "warning_count"),
416  cop_as("errors", "error_count"),
417 );
418 *list rows = table.selectRows(("columns": columns, "where": ("type": "user")));
419  @endcode
420  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
421  This option takes a list, each element of the list can be one of the following.\n\n
422  <b>A Simple String Giving a Column Name</b>\n
423  ex: \c "name"
424  @code{.py}
425 *list rows = table.selectRows(("columns": ("id", "name", "started")));
426  @endcode \n
427  <b>A String in Dot Notation</b>\n
428  This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
429  @code{.py}
430 hash sh = (
431  "columns": ("t1.id", "t2.customer_name"),
432  "join": join_inner(table2, "t2", ("id": "altid"))),
433  "alias": "t1",
434 );
435 *list rows = table.selectRows(sh);
436  @endcode \n
437  <b>A Column Operation Specified by a Column Operator Function</b>\n
438  ex: <tt>cop_as("column_name", "column_alias")</tt> \n
439  See @ref sql_cop_funcs "column operator function" for more information on column operator functions
440  @code{.py}
441 list columns = (
442  "id",
443  cop_as("warnings", "warning_count"),
444  cop_as("errors", "error_count"),
445 );
446 *list rows = table.selectRows(("columns": columns));
447  @endcode
448  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
449  <b>The Value \c "*", Meaning All Columns</b>\n
450  ex: \c "*"
451  @code{.py}
452 *list rows = table.selectRows(("columns": "*"));
453  @endcode
454  This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
455  <b>An \c "*" in Dot Notation</b>\n
456  ex: \c "q.*"
457  @code{.py}
458 hash sh = (
459  "columns": ("table.id", "t2.*"),
460  "join": join_inner(table2, "t2", ("id": "altid")),
461 );
462 *list rows = table.selectRows(sh);
463  @endcode
464 
465  @subsubsection select_option_where Select Option "where"
466  <b>Where Example:</b>
467  @code{.py}
468 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
469  @endcode
470  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.
471 
472  @subsubsection select_option_orderby Select Option "orderby"
473  <b>Orderby Example:</b>
474  @code{.py}
475 hash sh = (
476  "where": (
477  "account_type": "CUSTOMER",
478  ),
479  "orderby": "created_date",
480 );
481 *list rows = table.selectRows(sh);
482  @endcode
483  This option is a list of the following values:
484  - a simple string giving a column name; ex: \c "name"
485  - a simple string with a column name preceded by a \c "-" sign; ex: \c "-name", meaning that that column should be sorted in descending order
486  - 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"
487  - a positive integer giving the column number for the ordering
488  @note
489  - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
490 
491  @subsubsection select_option_desc Select Option "desc"
492  <b>Desc Example:</b>
493  @code{.py}
494 hash sh = (
495  "where": (
496  "account_type": "CUSTOMER",
497  ),
498  "orderby": "created_date",
499  "desc": True,
500 );
501 *list rows = table.selectRows(sh);
502  @endcode
503  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
504  Otherwise, ordered results are returned in ascending order by default.
505 
506  @note per-column descending options can be given by prepending a \c "-" character to the column name in the @ref select_option_orderby "orderby option list"
507 
508  @subsubsection select_option_limit Select Option "limit"
509  <b>Limit Example:</b>
510  @code{.py}
511 hash sh = (
512  "where": ("type": "user"),
513  "limit": 100,
514  "offset": 200
515 );
516 *list rows = table.selectRows(sh);
517  @endcode
518  This option will limit the number of rows returned.
519  @note
520  - This option is required if the @ref select_option_offset "offset option" is non-zero
521  - 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
522 
523  @subsubsection select_option_offset Select Option "offset"
524  <b>Offset Example:</b>
525  @code{.py}
526 hash sh = (
527  "where": ("type": "user"),
528  "limit": 100,
529  "offset": 200
530 );
531 *list rows = table.selectRows(sh);
532  @endcode
533  This option specifies the row number offset for the rows returned where the first row is at offset zero.
534  @note
535  - 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.
536  - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
537  @see @ref sql_paging
538 
539  @subsubsection select_option_join Select Option "join"
540  <b>Join Example:</b>
541  @code{.py}
542 hash sh = (
543  "columns": (
544  "name", "version", "id",
545  cop_as("st.value", "source"),
546  cop_as("st.value", "offset"),
547  ),
548  "join": join_left(function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
549  + join_left(function_instance_tags, "lt", NOTHING, ("st.tag": "_offset")),
550 );
551 *list rows = table.selectRows(sh);
552  @endcode
553  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).
554  @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
555 
556  @see @ref joins for more examples
557 
558  @subsubsection select_option_groupby Select Option "groupby"
559  <b>Groupby Example:</b>
560  @code{.py}
561 hash sh = (
562  "columns": (
563  cop_as(cop_max("service_type"), "type"),
564  cop_count(),
565  ),
566  "groupby": "service_type",
567 );
568 *list rows = table.selectRows(sh);
569  @endcode
570  The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
571  The \c "groupby" hash key should be assigned to a list of column specifiers or a single column specifier. Column specifiers for the \c "groupby"
572  key are strings giving column names, optionally in dot notation or positive column numbers.
573 
574  @subsubsection select_option_having Select Option "having"
575  <b>Having Example:</b>
576  @code{.py}
577 hash sh = (
578  "columns": (
579  cop_as(cop_max("service_type"), "type"),
580  cop_count(),
581  ),
582  "groupby": "service_type",
583  "having": (
584  "service_type": (COP_COUNT, op_ge(100)),
585  ),
586 );
587 *list rows = table.selectRows(sh);
588  @endcode
589  The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
590  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.
591 
592  @subsubsection select_option_superquery Select Option "superquery"
593  <b>Superquery Example:</b>
594  @code{.py}
595 hash sh = (
596  "columns": (
597  "serviceid", "service_methodid",
598  cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid"),
599  ),
600  "superquery": (
601  "columns": ("serviceid", "service_methodid"),
602  "where": ("max_methodid": op_ceq("service_methodid")),
603  ),
604 );
605 *list rows = table.selectRows(sh);
606  @endcode
607  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
608  The above example results in an SQL command equivalent to the following:
609  @code{.py}
610 *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");
611  @endcode
612  @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
613 
614  @subsubsection select_option_forupdate Select Option "forupdate"
615  <b>For Update Example:</b>
616  @code{.py}
617 on_success ds.commit();
618 on_error ds.rollback();
619 
620 hash sh = (
621  "columns": ("serviceid", "service_methodid"),
622  "forupdate": True,
623 )
624 *list rows = table.selectRows(sh);
625  @endcode
626  \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.
627  The above example results in an SQL commit equivalent to the following:
628  @code{.py}
629 *list rows = table.vselectRows("select serviceid,service_methodid from schema.service_methods for update");
630  @endcode
631 
632  @subsection sql_paging Select With Paging
633 
634  There is support for paging query results in the following methods:
635  - @ref SqlUtil::AbstractTable::getRowIterator()
636  - @ref SqlUtil::AbstractTable::getSelectSql()
637  - @ref SqlUtil::AbstractTable::select()
638  - @ref SqlUtil::AbstractTable::selectRows()
639 
640  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
641 
642  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.
643 
644  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.
645 
646  @par Example:
647  Select 100 rows starting at row 200 (the table's primary key will be used for the \c "orderby" option by default): \n
648  @code{.py}
649 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
650  @endcode
651  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:
652  @code{.py}
653 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));
654  @endcode
655  And for PostgreSQL:
656  @code{.py}
657 ds.vselectRows("select * from public.table where type = %v order by type limit %v offset %v", ("user", 100, 200));
658  @endcode
659 
660  @subsection check_matching_rows Check For At Least One Matching Row
661 
662  Use the @ref SqlUtil::AbstractTable::findSingle() method to find at least one matching row:
663  @code{.py}
664 *hash h = table.findSingle(("account_type": "CUSTOMER"));
665 if (h)
666  printf("found 1 customer row: %y\n", l[0]);
667  @endcode
668 
669  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):
670  @code{.py}
671 *hash h = table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
672 if (h)
673  printf("found 1 customer row: %y\n", l[0]);
674  @endcode
675 
676  @section inserting_data Inserting Data into the Database
677 
678  The following methods can be used to insert data into the database:
679  - @ref SqlUtil::AbstractTable::insert(): inserts a single row into a table without committing the transaction
680  - @ref SqlUtil::AbstractTable::insertCommit(): inserts a single row into a table and commits the transaction
681  - @ref SqlUtil::AbstractTable::insertFromSelect(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and without committing the transaction
682  - @ref SqlUtil::AbstractTable::insertFromSelectCommit(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and commits the transaction
683 
684  @see @ref sql_upsert for information about upserting or merging data
685 
686  @subsection inserting_data_explicitly Inserting Data Explicitly
687 
688  @par Example:
689  @code{.py}
690 table.insert(("id": id, "name": name, "created": now_us()));
691  @endcode
692 
693  Data can be explicitly inserted into the database with immediate values with @ref SqlUtil::AbstractTable::insert() and @ref SqlUtil::AbstractTable::insertCommit() as in the above example.
694 
695  Additionally, instead of giving a literal value to be inserted, @ref sql_iop_funcs can be used to insert values based on SQL operations used directly in the insert statement.
696 
697  @subsection inserting_data_from_select Inserting Data From a Select Statement
698 
699  @par Example:
700  @code{.py}
701 int rows = table.insertFromSelect(("id", "name", "created"), source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER"))));
702  @endcode
703 
704  Data can be inserted into the database based on the results of a select statement with @ref SqlUtil::AbstractTable::insertFromSelect() and @ref SqlUtil::AbstractTable::insertFromSelectCommit() as in the above example.
705 
706  The example above would generate a %Qore SQL command like the following:
707  @code{.py}
708 return ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER"));
709  @endcode
710 
711  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.
712 
713  @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
714 
715  To insert data from an iterator source (such as an @ref Qore::SQL::SQLStatement object), call @ref SqlUtil::AbstractTable::insertFromIterator() or @ref SqlUtil::AbstractTable::insertFromIteratorCommit() as in the following example:
716 
717  @par Example:
718  @code{.py}
719 # get the rows to be inserted
720 list l = get_table_rows();
721 # insert the data and commit after every 5000 rows
722 table.insertFromIterator(l.iterator(), ("commit_block": 5000));
723  @endcode
724 
725  The iterator given to the @ref SqlUtil::AbstractTable::insertFromIterator() or @ref SqlUtil::AbstractTable::insertFromIteratorCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
726 
727  @note the @ref SqlUtil::AbstractTable::InsertFromIteratorOptions "insert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
728 
729  @section updating_data Updating Data
730 
731  The following methods can be used to update data:
732  - @ref SqlUtil::AbstractTable::update(): updates a single row and does not commit the transaction
733  - @ref SqlUtil::AbstractTable::updateCommit(): updates a single row and commits the transaction
734 
735  @par Example:
736  @code{.py}
737 int rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
738  @endcode
739 
740  The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
741  @code{.py}
742 return ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
743  @endcode
744  And the following on MySQL:
745  @code{.py}
746 return ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
747  @endcode
748 
749  @section deleting_data Deleting Data
750 
751  The following methods can be used to dekete data:
752  - @ref SqlUtil::AbstractTable::del(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
753  - @ref SqlUtil::AbstractTable::delCommit(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
754  - @ref SqlUtil::AbstractTable::truncate(): truncates the table and does not commit the transaction
755  - @ref SqlUtil::AbstractTable::truncateCommit(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
756 
757  @par Example:
758  @code{.py}
759 int dcnt = table.del(("record_type": "OLD-CUSTOMER"));
760  @endcode
761 
762  The above example would generate a %Qore SQL command like the following:
763  @code{.py}
764 return ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
765  @endcode
766 
767  The @ref SqlUtil::AbstractTable::del() and @ref SqlUtil::AbstractTable::delCommit() methods can be used to delete data from the database.
768 
769  See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
770 
771  @section joins Joining Tables
772 
773  Joining tables is made by providing a join specification to the @ref select_option_join "join select option" in
774  a @ref select_option_hash "select option hash" as in the following example:
775  @code{.py}
776 *list rows = table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner(table2, "t2", ("id": "altid"))));
777  @endcode
778  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
779 
780  Joins on multiple tables are performed by combining the results of @ref sql_jop_funcs "join functions" with the @ref plus_operator "+ operator"
781  as follows:
782  @code{.py}
783 *list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner(table3, "t3")));
784  @endcode
785  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
786  automatically detected primary key to foreign key relationship between the two tables.
787 
788  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
789  argument to the @ref sql_jop_funcs "join function" as in the following example:
790  @code{.py}
791 *list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner("t2", table3, "t3")));
792  @endcode
793  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
794  with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
795 
796  @see @ref select_option_join "join select option"
797 
798  @section where_clauses Where Clauses
799 
800  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:
816 
817  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
818 
819  The where clause or condition hash is made of keys signifying the column names, and either a direct value meaning that the column value has to match exactly, or SQL operators can be given by using the appropriate operator function as the key value. Each member of the where hash translates to an expression that is combined with \c "AND" in the SQL query; to combine expressions with \c "OR", there are two options:
820  - use the @ref SqlUtil::wop_or() function to combine where expressions with the \c "or" operator
821  - 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".
822 
823  The where condition hash has the following format:
824  - each key gives a column name or a table/alias with column name in dot notation
825  - 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
826 
827  @note To reference a column more than once in a where clause, prefix the column specification with a unique number and a colon as in the following example: @code{.py} hash w = ("0:created": op_ge(mindate), "1:created": op_lt(maxdate)); @endcode
828 
829  See @ref sql_op_funcs for a list of operator functions.
830 
831  @par Where Hash Example:
832  @code{.py}
833 hash w = (
834  "name": "Smith",
835  "account_type": op_like("%CUSTOMER%"),
836  "id": op_ge(500),
837 );
838  @endcode \n
839  The preceding example results in a where clause equivalent to: \c "name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
840  that bind by value is used, so, if used in a context like the following:
841  @code{.py}
842 Table t(ds, "table");
843 *hash qh = t.select(("where": w));
844  @endcode \n
845  the complete query would look instead as follows:
846  @code{.py}
847 ds.vselect("select * from table where name = %v and account_type like %v and id >= %v", ("Smith", "%CUSTOMER%", 500));
848  @endcode
849 
850  @anchor where_list
851  @par Where List Example:
852  @code{.py}
853 hash w1 = (
854  "name": "Smith",
855  "account_type": op_like("%CUSTOMER%"),
856  "id": op_ge(500),
857 );
858 hash w2 = (
859  "name": "Jones",
860  "account_type": op_like("%VENDOR%"),
861  "id": op_ge(2500),
862 );
863 Table t(ds, "table");
864 *hash qh = t.select(("where": (w1, w2)));
865  @endcode \n
866  the complete query would look instead as follows:
867  @code{.py}
868 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));
869  @endcode
870 
871  @par Code Examples:
872  Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
873  @code{.py}
874 *hash row = table.findSingle(("permission_type": op_between("US", "UX")));
875  @endcode
876  resulting in an internal SQL command that looks as follows (depending on the database):
877  @code{.py}
878 *hash row = ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
879  @endcode \n
880  Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
881  @code{.py}
882 int row_count = table.del(("name": op_like("%Smith%")));
883  @endcode
884  resulting in an internal SQL command that looks as follows:
885  @code{.py}
886 ds.vexec("delete from table where name like %v", ("%Smith%"));
887  @endcode \n
888  Find all rows where \c "id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
889  @code{.py}
890 *list rows = table.findAll(("id": op_gt(100), "created": op_gt(2013-03-01)));
891  @endcode
892  resulting in an internal SQL command that looks as follows:
893  @code{.py}
894 ds.vexec("select * from table where id > %v and created > %v", (100, 2013-03-01));
895  @endcode \n
896 
897  @section sql_upsert Upserting or Merging Data
898 
899  This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
908 
909  @subsection sql_upsert_single Upsert a Single Row
910 
911  @par Example:
912  @code{.py}
913 table.upsert(("id": id, "name": name, "account_type": account_type));
914  @endcode
915 
916  To upsert or merge a single row in the database, call @ref SqlUtil::AbstractTable::upsert() or @ref SqlUtil::AbstractTable::upsertCommit() with the
917  single row to be upserted or merged as a hash as in the preceding example.
918 
919  @subsection sql_upsert_many Upserting Many Rows Using An Upsert Closure
920 
921  To upsert or merge many rows by using an upsert closure, call @ref SqlUtil::AbstractTable::getUpsertClosure() or @ref SqlUtil::AbstractTable::getUpsertClosureWithValidation() and provide an example row as an argument to acquire a closure that will be executed on the rest of the rows as in the following example.
922 
923  @par Simple Example:
924  @code{.py}
925 # get the rows to be inserted
926 list l = get_table_rows();
927 
928 if (l) {
929  code upsert = table.getUpsertClosure(l[0]);
930 
931  on_success ds.commit();
932  on_error ds.rollback();
933 
934  # loop through the reference data rows
935  map upsert($1), l;
936 }
937  @endcode
938 
939  @par Complex Example With Callbacks:
940  @code{.py}
941 # set the upsert strategy depending on the use case
942 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
943 
944 # hash summarizing changes
945 hash sh;
946 
947 # get the rows to be inserted
948 list l = get_table_rows();
949 
950 if (l) {
951  # get the upsert closure to use based on the first row to be inserted
952  code upsert = table.getUpsertClosure(l[0], upsert_strategy);
953 
954  on_success ds.commit();
955  on_error ds.rollback();
956 
957  # loop through the reference data rows
958  foreach hash h in (l) {
959  int code = upsert(h);
960  if (code == AbstractTable::UR_Unchanged)
961  continue;
962 
963  string change = AbstractTable::UpsertResultMap{code};
964  ++sh{change};
965 
966  if (!verbose) {
967  printf(".");
968  flush();
969  }
970  else if (verbose > 1)
971  printf("*** reference data %s: %y: %s\n", table.getName(), h, change);
972  }
973 
974  # show table summary
975  if (sh)
976  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
977  else
978  printf("*** reference data %s: OK\n", table.getName());
979 }
980  @endcode
981 
982  @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
983 
984  To upsert or merge many rows from an iterator source (such as an @ref Qore::SQL::SQLStatement object), call @ref SqlUtil::AbstractTable::upsertFromIterator() or @ref SqlUtil::AbstractTable::upsertFromIteratorCommit() as in the following example:
985 
986  @par Simple Example:
987  @code{.py}
988 # get the rows to be inserted
989 list l = get_table_rows();
990 table.upsertFromIterator(l.iterator());
991  @endcode
992 
993  @par Complex Example With Callbacks:
994  @code{.py}
995 # set the upsert strategy depending on the use case
996 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
997 
998 # get the rows to be inserted
999 list l = get_table_rows();
1000 
1001 code callback = sub (string table_name, hash row, int result) {
1002  if (result == AbstractTable::UR_Unchanged)
1003  return;
1004  string change = AbstractTable::UpsertResultMap{result};
1005  if (verbose)
1006  printf("*** reference data %s: %y: %s\n", table_name, row, change);
1007 };
1008 
1009 hash sh = table.upsertFromIterator(l.iterator(), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
1010 if (sh)
1011  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
1012 else
1013  printf("*** reference data %s: OK\n", table.getName());
1014  @endcode
1015 
1016  The iterator given to the @ref SqlUtil::AbstractTable::upsertFromIterator() or @ref SqlUtil::AbstractTable::upsertFromIteratorCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
1017 
1018  @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
1019 
1020  @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
1021 
1022  To upsert or merge many rows from a select statement, use @ref SqlUtil::AbstractTable::upsertFromSelect() or @ref SqlUtil::AbstractTable::upsertFromSelectCommit() as in the following example:
1023 
1024  @par Simple Example:
1025  @code{.py}
1026 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")));
1027  @endcode
1028 
1029  @par Complex Example With Callbacks:
1030  @code{.py}
1031 # set the upsert strategy depending on the use case
1032 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
1033 
1034 code callback = sub (string table_name, hash row, int result) {
1035  if (result == AbstractTable::UR_Unchanged)
1036  return;
1037  string change = AbstractTable::UpsertResultMap{result};
1038  if (verbose)
1039  printf("*** reference data %s: %y: %s\n", table_name, row, change);
1040 };
1041 
1042 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
1043 if (sh)
1044  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
1045 else
1046  printf("*** reference data %s: OK\n", table.getName());
1047  @endcode
1048 
1049  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).
1050 
1051  @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
1052 
1053  @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
1054 
1055  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.
1056 
1057  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.
1058 
1059  @par Simple Example:
1060  @code{.py}
1061 # get the rows to be inserted
1062 list l = get_table_rows();
1063 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
1064  @endcode
1065 
1066  @par Complex Example With Callbacks:
1067  @code{.py}
1068 # set the upsert strategy depending on the use case
1069 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
1070 
1071 # get the rows to be inserted
1072 list l = get_table_rows();
1073 
1074 code callback = sub (string table_name, hash row, int result) {
1075  if (result == AbstractTable::UR_Unchanged)
1076  return;
1077  string change = AbstractTable::UpsertResultMap{result};
1078  if (verbose)
1079  printf("*** reference data %s: %y: %s\n", table_name, row, change);
1080 };
1081 
1082 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, ("delete_others": True, "info_callback": callback, "commit_block": 5000));
1083 if (sh)
1084  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
1085 else
1086  printf("*** reference data %s: OK\n", table.getName());
1087  @endcode
1088 
1089  @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
1090 
1091  @subsection sql_upsert_strategies Upsert Strategies
1092  The approach used is based on one of the following strategies (see @ref upsert_options):
1093  - @ref SqlUtil::AbstractTable::UpsertAuto "AbstractTable::UpsertAuto": if the target table is empty, then @ref SqlUtil::AbstractTable::UpsertInsertFirst is used, otherwise @ref SqlUtil::AbstractTable::UpsertUpdateFirst is used; note that if a driver-specific optimized version of the upsert operation is implemented, this strategy will normally result in the best performance
1094  - @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
1095  - @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
1096  - @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst": first a select is made on the unique key, if the data to be updated is equal, nothing is done and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
1097  - @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
1098  - @ref SqlUtil::AbstractTable::UpsertUpdateOnly "AbstractTable::UpsertUpdateOnly": update if the row exists, otherwise do nothing and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
1099 
1100  @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.
1101 */
2096 namespace SqlUtil {
2099  public struct GenericColumnInfo {
2101  string qore_type;
2103  string native_type;
2105  softint size;
2107  softint scale;
2111  bool default_value_native = False;
2113  *string comment;
2115  bool notnull = False;
2117  hash<string, hash> driver;
2120  };
2121 
2123  public struct OperatorInfo {
2124  string op;
2125  any arg;
2126  };
2127 
2129  public struct ColumnOperatorInfo {
2130  string cop;
2131  any column;
2132  any arg;
2133  };
2134 
2136  public struct InsertOperatorInfo {
2137  string _iop;
2138  any arg;
2139  };
2140 
2142  public struct UpdateOperatorInfo {
2143  string uop;
2144  any arg;
2146  };
2147 
2149  public struct JoinOperatorInfo {
2150  string jop;
2151  any table;
2152  *string alias;
2155  *string ta;
2157  };
2158 
2159  /* @defgroup DBFeaturesConstants DB Features Constants
2160  These constants can be used as a lookup values in AbstractDatabase::features() method.
2161  */
2163 
2166  const DB_FUNCTIONS = "functions";
2168  const DB_MVIEWS = "materialized views";
2170  const DB_PACKAGES = "packages";
2172  const DB_PROCEDURES = "procedures";
2174  const DB_SEQUENCES = "sequences";
2176  const DB_TABLES = "tables";
2178  const DB_TYPES = "named types";
2180  const DB_VIEWS = "views";
2182  const DB_SYNONYMS = "synonyms";
2184 
2185  /* @defgroup SqlTypeConstants SQL Type Constants
2186  These constants can be used for the \c "qore_type" values when creating columns to specify additional SQL column types
2187  */
2189  const VARCHAR = "string";
2191 
2193  const NUMERIC = "number";
2194 
2196  const CHAR = "char";
2197 
2199  const BLOB = "blob";
2200 
2202  const CLOB = "clob";
2204 
2209  const SZ_NONE = 0;
2211 
2213  const SZ_MAND = 1;
2214 
2216  const SZ_OPT = 2;
2217 
2219  const SZ_NUM = 3;
2221 
2226 
2229  const COP_AS = "as";
2230 
2232 
2234  const COP_CAST = "cast";
2235 
2237 
2239  const COP_PREPEND = "prepend";
2240 
2242 
2244  const COP_APPEND = "append";
2245 
2247 
2249  const COP_VALUE = "value";
2250 
2252 
2254  const COP_UPPER = "upper";
2255 
2257 
2259  const COP_LOWER = "lower";
2260 
2262 
2264  const COP_DISTINCT = "distinct";
2265 
2267 
2269  const COP_MIN = "min";
2270 
2272 
2274  const COP_MAX = "max";
2275 
2277 
2279  const COP_AVG = "avg";
2280 
2282 
2284  const COP_SUM = "sum";
2285 
2287 
2289  const COP_COUNT = "count";
2290 
2292 
2294  const COP_OVER = "over";
2295 
2297 
2299  const COP_MINUS = "minus";
2300 
2302 
2304  const COP_PLUS = "plus";
2305 
2307 
2309  const COP_DIVIDE = "divide";
2310 
2312 
2314  const COP_MULTIPLY = "multiply";
2315 
2317 
2319  const COP_YEAR = "year";
2320 
2322 
2324  const COP_YEAR_MONTH = "year_month";
2325 
2327 
2329  const COP_YEAR_DAY = "year_day";
2330 
2332 
2334  const COP_YEAR_HOUR = "year_hour";
2335 
2337 
2339  const COP_SEQ = "seq";
2340 
2342 
2344  const COP_SEQ_CURRVAL = "seq_currval";
2345 
2347 
2349  const COP_COALESCE = "coalesce";
2350 
2352 
2354  const COP_SUBSTR = "substr";
2355 
2357 
2361  const COP_LENGTH = "length";
2362 
2364 
2370  const COP_TRUNC_DATE = "truncate_date";
2371 
2373 
2377  const COP_CUME_DIST = "cume_dist";
2378 
2380 
2384  const COP_DENSE_RANK = "dense_rank";
2385 
2387 
2391  const COP_FIRST_VALUE = "first_value";
2392 
2394 
2398  const COP_LAST_VALUE = "last_value";
2399 
2401 
2405  const COP_NTILE = "ntile";
2406 
2408 
2412  const COP_PERCENT_RANK = "percent_rank";
2413 
2415 
2419  const COP_RANK = "rank";
2420 
2422 
2426  const COP_ROW_NUMBER = "row_number";
2427 
2428 
2430  const DefaultCopMap = (
2431  COP_AS: (
2432  "arg": Type::String,
2433  "withalias": True,
2434  "code": string (string cve, string arg, reference psch) {
2435  // issue #2163: make sure the unquoted alias is inserted in the map
2436  if (arg ==1)
2437  psch{arg.substr(1, -1)} = cve;
2438  else
2439  psch{arg} = cve;
2440  return sprintf("%s as %s", cve, arg);
2441  },
2442  ),
2443  COP_PREPEND: (
2444  "arg": Type::String,
2445  "sqlvalue": True,
2446  "code": string (string cve, string arg) {
2447  return sprintf("%s || %s", arg, cve);
2448  },
2449  ),
2450  COP_APPEND: (
2451  "arg": Type::String,
2452  "sqlvalue": True,
2453  "code": string (string cve, string arg) {
2454  return sprintf("%s || %s", cve, arg);
2455  },
2456  ),
2457  COP_VALUE: (
2458  "sqlvalue": True,
2459  "nocolumn": True,
2460  "code": string (*string cve, auto arg) {
2461  return arg;
2462  },
2463  ),
2464  COP_UPPER: (
2465  "code": string (string cve, auto arg) {
2466  return sprintf("upper(%s)", cve);
2467  },
2468  ),
2469  COP_LOWER: (
2470  "code": string (string cve, auto arg) {
2471  return sprintf("lower(%s)", cve);
2472  },
2473  ),
2474  COP_DISTINCT: (
2475  "code": string (string cve, auto arg) {
2476  return sprintf("distinct %s", cve);
2477  },
2478  ),
2479  COP_MIN: (
2480  "code": string (string cve, auto arg) {
2481  return sprintf("min(%s)", cve);
2482  },
2483  "group": True,
2484  ),
2485  COP_MAX: (
2486  "code": string (string cve, auto arg) {
2487  return sprintf("max(%s)", cve);
2488  },
2489  "group": True,
2490  ),
2491  COP_AVG: (
2492  "code": string (string cve, auto arg) {
2493  return sprintf("avg(%s)", cve);
2494  },
2495  "group": True,
2496  ),
2497  COP_SUM: (
2498  "code": string (string cve, auto arg) {
2499  return sprintf("sum(%s)", cve);
2500  },
2501  "group": True,
2502  ),
2503  COP_COUNT: (
2504  "nocolumn": True,
2505  "code": string (*string cve, auto arg) {
2506  return sprintf("count(%s)", cve ? cve : "*");
2507  },
2508  ),
2509  COP_MINUS: (
2510  "argcolumn": True,
2511  "code": string (string arg1, string arg2) {
2512  return sprintf("%s - %s", arg1, arg2);
2513  },
2514  ),
2515  COP_PLUS: (
2516  "argcolumn": True,
2517  "code": string (string arg1, string arg2) {
2518  return sprintf("%s + %s", arg1, arg2);
2519  },
2520  ),
2521  COP_DIVIDE: (
2522  "argcolumn": True,
2523  "code": string (string arg1, string arg2) {
2524  return sprintf("%s / %s", arg1, arg2);
2525  },
2526  ),
2527  COP_MULTIPLY: (
2528  "argcolumn": True,
2529  "code": string (string arg1, string arg2) {
2530  return sprintf("%s * %s", arg1, arg2);
2531  },
2532  ),
2533  COP_SEQ: (
2534  "nocolumn": True,
2535  "code": string (*string cve, hash arg) {
2536  throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg.seq);
2537  }
2538  ),
2539  COP_SEQ_CURRVAL: (
2540  "nocolumn": True,
2541  "code": string (*string cve, hash arg) {
2542  throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg.seq);
2543  }
2544  ),
2545  COP_COALESCE: (
2546  "columnargs": True,
2547  "code": string (*string cve, hash arg) {
2548  return sprintf("coalesce(%s)", (foldl $1 + "," + $2, arg.args));
2549  }
2550  ),
2551  COP_SUBSTR: (
2552  "code": string (string cve, list args) {
2553  if (!exists args[1])
2554  return sprintf("substring(%s from %d)", cve, args[0]);
2555  return sprintf("substring(%s from %d for %d)", cve, args[0], args[1]);
2556  },
2557  ),
2558  COP_LENGTH: (
2559  "code": string (string cve, auto arg) {
2560  return sprintf("length(%s)", cve);
2561  },
2562  ),
2563  COP_OVER: (
2564  "columnargs" : True,
2565  "columnargs_ignore_nothings" : True,
2566  "code": string (*string cve, hash args)
2567  {
2568  *string partitionby = args.args[0];
2569  *string orderby = args.args[1];
2570  if (!exists partitionby && exists orderby);
2571 
2572  string sql = cve + " over (";
2573  if (exists partitionby)
2574  sql += sprintf("partition by %s", partitionby); // TODO/FIXME: sql injection!
2575  if (exists orderby)
2576  sql += sprintf(" order by %s", orderby); // TODO/FIXME: sql injection!
2577  sql += ")";
2578  return sql;
2579  },
2580  ),
2581  COP_CUME_DIST: (
2582  "nocolumn": True,
2583  "code": string (*string cve, any arg) {
2584  return "cume_dist()";
2585  },
2586  ),
2587  COP_DENSE_RANK: (
2588  "nocolumn": True,
2589  "code": string (*string cve, any arg) {
2590  return "dense_rank()";
2591  },
2592  ),
2593  COP_FIRST_VALUE: (
2594  "code": string (string cve) {
2595  return sprintf("first_value(%s)", cve);
2596  },
2597  ),
2598  COP_LAST_VALUE: (
2599  "code": string (string cve) {
2600  return sprintf("last_value(%s)", cve);
2601  },
2602  ),
2603  COP_NTILE: (
2604  "sqlvalue": True,
2605  "nocolumn": True,
2606  "code": string (*string cve, any arg) {
2607  return sprintf("ntile(%d)", arg);
2608  },
2609  ),
2610  COP_PERCENT_RANK: (
2611  "nocolumn": True,
2612  "code": string (*string cve, any arg) {
2613  return "percent_rank()";
2614  },
2615  ),
2616  COP_RANK: (
2617  "nocolumn": True,
2618  "code": string (*string cve, any arg) {
2619  return "rank()";
2620  },
2621  ),
2622  COP_ROW_NUMBER: (
2623  "nocolumn": True,
2624  "code": string (*string cve, any arg) {
2625  return "row_number()";
2626  },
2627  ),
2628  );
2630 
2672 
2681  hash<ColumnOperatorInfo> make_cop(string cop, auto column, auto arg);
2682 
2683 
2685 
2697  hash<ColumnOperatorInfo> cop_as(auto column, string arg);
2698 
2699 
2701 
2715  hash<ColumnOperatorInfo> cop_cast(auto column, string arg, auto arg1, auto arg2);
2716 
2717 
2719 
2729  hash<ColumnOperatorInfo> cop_prepend(auto column, string arg);
2730 
2731 
2733 
2743  hash<ColumnOperatorInfo> cop_append(auto column, string arg);
2744 
2745 
2747 
2875  hash<ColumnOperatorInfo> cop_value(auto arg);
2876 
2877 
2879 
2888  hash<ColumnOperatorInfo> cop_upper(auto column);
2889 
2890 
2892 
2901  hash<ColumnOperatorInfo> cop_lower(auto column);
2902 
2903 
2905 
2914  hash<ColumnOperatorInfo> cop_distinct(auto column);
2915 
2916 
2918 
2927  hash<ColumnOperatorInfo> cop_min(auto column);
2928 
2929 
2931 
2940  hash<ColumnOperatorInfo> cop_max(auto column);
2941 
2942 
2944 
2953  hash<ColumnOperatorInfo> cop_avg(auto column);
2954 
2955 
2957 
2966  hash<ColumnOperatorInfo> cop_sum(auto column);
2967 
2968 
2970 
2977  hash<ColumnOperatorInfo> cop_count(auto column = "");
2978 
2979 
2981 
2988  hash<ColumnOperatorInfo> cop_over(auto column, *string partitionby, *string orderby);
2989 
2990 
2992 
3002  hash<ColumnOperatorInfo> cop_minus(auto column1, auto column2);
3003 
3004 
3006 
3016  hash<ColumnOperatorInfo> cop_plus(auto column1, auto column2);
3017 
3018 
3020 
3030  hash<ColumnOperatorInfo> cop_divide(auto column1, auto column2);
3031 
3032 
3034 
3044  hash<ColumnOperatorInfo> cop_multiply(auto column1, auto column2);
3045 
3046 
3048 
3057  hash<ColumnOperatorInfo> cop_year(auto column);
3058 
3059 
3061 
3070  hash<ColumnOperatorInfo> cop_year_month(auto column);
3071 
3072 
3074 
3083  hash<ColumnOperatorInfo> cop_year_day(auto column);
3084 
3085 
3087 
3096  hash<ColumnOperatorInfo> cop_year_hour(auto column);
3097 
3098 
3100 
3110  hash<ColumnOperatorInfo> cop_seq(string seq, *string as);
3111 
3112 
3114 
3124  hash<ColumnOperatorInfo> cop_seq_currval(string seq, *string as);
3125 
3126 
3128 
3140  hash<ColumnOperatorInfo> cop_coalesce(auto col1, auto col2);
3141 
3142 
3144 
3155  hash<ColumnOperatorInfo> cop_substr(auto column, int start, *int count);
3156 
3157 
3159 
3170  hash<ColumnOperatorInfo> cop_length(auto column);
3171 
3172 
3174 
3188  hash<ColumnOperatorInfo> cop_trunc_date(auto column, string mask);
3189 
3190 
3191 
3193 
3221  hash<ColumnOperatorInfo> cop_cume_dist();
3222 
3223 
3225 
3253  hash<ColumnOperatorInfo> cop_dense_rank();
3254 
3255 
3257 
3285  hash<ColumnOperatorInfo> cop_first_value(any column);
3286 
3287 
3289 
3317  hash<ColumnOperatorInfo> cop_last_value(any column);
3318 
3319 
3321 
3351  hash<ColumnOperatorInfo> cop_ntile(int value);
3352 
3353 
3355 
3383  hash<ColumnOperatorInfo> cop_percent_rank();
3384 
3385 
3387 
3415  hash<ColumnOperatorInfo> cop_rank();
3416 
3417 
3419 
3447  hash<ColumnOperatorInfo> cop_row_number();
3448 
3449 
3451 
3502  const DT_YEAR = "Y";
3504 
3506  const DT_MONTH = "M";
3507 
3509  const DT_DAY = "D";
3510 
3512  const DT_HOUR = "H";
3513 
3515  const DT_MINUTE = "m";
3516 
3518  const DT_SECOND = "S";
3519 
3520  // let's simulate and enum here'
3521  const DT_ALL_VALUES = ( DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND );
3523 
3528  const DefaultUopMap = (
3530  COP_PREPEND: True,
3531  COP_APPEND: True,
3532  COP_UPPER: True,
3533  COP_LOWER: True,
3534  COP_MINUS: (
3535  "sqlvalue": True,
3536  "code": string (string cve, auto arg) {
3537  return sprintf("%s - %s", cve, arg);
3538  },
3539  ),
3540  COP_PLUS: (
3541  "sqlvalue": True,
3542  "code": string (string cve, auto arg) {
3543  return sprintf("%s + %s", cve, arg);
3544  },
3545  ),
3546  COP_DIVIDE: (
3547  "sqlvalue": True,
3548  "code": string (string cve, auto arg) {
3549  return sprintf("%s / %s", cve, arg);
3550  },
3551  ),
3552  COP_MULTIPLY: (
3553  "sqlvalue": True,
3554  "code": string (string cve, auto arg) {
3555  return sprintf("%s * %s", cve, arg);
3556  },
3557  ),
3558  COP_SUBSTR: True,
3559  COP_SEQ: (
3560  "nocolumn": True,
3561  "code": string (*string cve, string arg) {
3562  throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg);
3563  }
3564  ),
3565  COP_SEQ_CURRVAL: (
3566  "nocolumn": True,
3567  "code": string (*string cve, string arg) {
3568  throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg);
3569  }
3570  ),
3571  COP_COALESCE: (
3572  "columnargs": True,
3573  "code": string (*string cve, softlist args) {
3574  return sprintf("coalesce(%s)", (foldl $1 + "," + $2, args));
3575  }
3576  ),
3577  );
3579 
3601 
3610  hash<UpdateOperatorInfo> make_uop(string uop, auto arg, *hash<UpdateOperatorInfo> nest);
3611 
3612 
3614 
3624  hash<UpdateOperatorInfo> uop_prepend(string arg, *hash<UpdateOperatorInfo> nest);
3625 
3626 
3628 
3638  hash<UpdateOperatorInfo> uop_append(string arg, *hash<UpdateOperatorInfo> nest);
3639 
3640 
3642 
3651  hash<UpdateOperatorInfo> uop_upper(*hash<UpdateOperatorInfo> nest);
3652 
3653 
3655 
3664  hash<UpdateOperatorInfo> uop_lower(*hash<UpdateOperatorInfo> nest);
3665 
3666 
3668 
3679  hash<UpdateOperatorInfo> uop_substr(int start, *int count, *hash<UpdateOperatorInfo> nest);
3680 
3681 
3683 
3693  hash<UpdateOperatorInfo> uop_plus(auto arg, *hash<UpdateOperatorInfo> nest);
3694 
3695 
3697 
3707  hash<UpdateOperatorInfo> uop_minus(auto arg, *hash<UpdateOperatorInfo> nest);
3708 
3709 
3711 
3721  hash<UpdateOperatorInfo> uop_multiply(auto arg, *hash<UpdateOperatorInfo> nest);
3722 
3723 
3725 
3735  hash<UpdateOperatorInfo> uop_divide(auto arg, *hash<UpdateOperatorInfo> nest);
3736 
3737 
3739 
3748  hash<UpdateOperatorInfo> uop_seq(string seq);
3749 
3750 
3752 
3761  hash<UpdateOperatorInfo> uop_seq_currval(string seq);
3762 
3764 
3771 
3774  const JOP_INNER = "inner";
3775 
3777 
3779  const JOP_LEFT = "left";
3780 
3782 
3784  const JOP_RIGHT = "right";
3785 
3787  const JopMap = (
3788  JOP_INNER: "inner",
3789  JOP_LEFT: "left outer",
3790  JOP_RIGHT: "right outer",
3791  );
3793 
3803 
3807  hash<string, hash<JoinOperatorInfo>> make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
3808 
3809 
3811 
3815  hash<string, hash<JoinOperatorInfo>> make_jop(string jop, string table_name, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
3816 
3817 
3819 
3838  hash<string, hash<JoinOperatorInfo>> join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3839 
3840 
3842 
3861  hash<string, hash<JoinOperatorInfo>> join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3862 
3863 
3865 
3884  hash<string, hash<JoinOperatorInfo>> join_inner(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3885 
3886 
3888 
3910  hash<string, hash<JoinOperatorInfo>> join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3911 
3912 
3914 
3934  hash<string, hash<JoinOperatorInfo>> join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3935 
3936 
3938 
3960  hash<string, hash<JoinOperatorInfo>> join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3961 
3962 
3964 
3983  hash<string, hash<JoinOperatorInfo>> join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3984 
3985 
3987 
4006  hash<string, hash<JoinOperatorInfo>> join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
4007 
4008 
4010 
4031  hash<string, hash<JoinOperatorInfo>> join_left(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4032 
4033 
4035 
4055  hash<string, hash<JoinOperatorInfo>> join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
4056 
4057 
4059 
4079  hash<string, hash<JoinOperatorInfo>> join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
4080 
4081 
4083 
4105  hash<string, hash<JoinOperatorInfo>> join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4106 
4107 
4109 
4128  hash<string, hash<JoinOperatorInfo>> join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
4129 
4130 
4132 
4151  hash<string, hash<JoinOperatorInfo>> join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
4152 
4153 
4155 
4176  hash<string, hash<JoinOperatorInfo>> join_right(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4177 
4178 
4180 
4200  hash<string, hash<JoinOperatorInfo>> join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
4201 
4202 
4204 
4224  hash<string, hash<JoinOperatorInfo>> join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
4225 
4226 
4228 
4250  hash<string, hash<JoinOperatorInfo>> join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4251 
4253 
4258 
4261  const OP_LIKE = "like";
4262 
4264 
4266  const OP_LT = "<";
4267 
4269 
4271  const OP_LE = "<=";
4272 
4274 
4276  const OP_GT = ">";
4277 
4279 
4281  const OP_GE = ">=";
4282 
4284 
4286  const OP_NE = "!=";
4287 
4289 
4291  const OP_EQ = "=";
4292 
4294 
4296  const OP_CLT = "C<";
4297 
4299 
4301  const OP_CLE = "C<=";
4302 
4304 
4306  const OP_CGT = "C>";
4307 
4309 
4311  const OP_CGE = "C>=";
4312 
4314 
4316  const OP_CNE = "C!=";
4317 
4319 
4321  const OP_CEQ = "C=";
4322 
4324 
4326  const OP_BETWEEN = "between";
4327 
4329 
4331  const OP_IN = "in";
4332 
4334 
4336  const OP_NOT = "not";
4337 
4339 
4341  const OP_SUBSTR = "substr";
4342 
4344  const OP_OR = "or";
4345 
4347  const DefaultOpMap = (
4348  OP_LIKE: (
4349  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4350  args += arg;
4351  return sprintf("%s like %v", cn);
4352  },
4353  ),
4354  OP_LT: (
4355  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4356  args += arg;
4357  return sprintf("%s < %v", cn);
4358  },
4359  ),
4360  OP_LE: (
4361  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4362  args += arg;
4363  return sprintf("%s <= %v", cn);
4364  },
4365  ),
4366  OP_GT: (
4367  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4368  args += arg;
4369  return sprintf("%s > %v", cn);
4370  },
4371  ),
4372  OP_GE: (
4373  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4374  args += arg;
4375  return sprintf("%s >= %v", cn);
4376  },
4377  ),
4378  OP_NE: (
4379  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4380  if (arg === NULL || !exists arg)
4381  return sprintf("%s is not null", cn);
4382  args += arg;
4383  return sprintf("(%s != %v or %s is null)", cn, cn);
4384  },
4385  ),
4386  OP_EQ: (
4387  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4388  if (arg === NULL || !exists arg)
4389  return sprintf("%s is null", cn);
4390  args += arg;
4391  return sprintf("%s = %v", cn);
4392  },
4393  ),
4394  OP_BETWEEN: (
4395  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4396  args += arg[0];
4397  args += arg[1];
4398  return sprintf("%s between %v and %v", cn);
4399  },
4400  ),
4401  OP_IN: (
4402  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4403  *string ins = (foldl $1 + "," + $2, (map t.getSqlValue($1), arg));
4404  return exists ins ? sprintf("%s in (%s)", cn, ins) : "1 != 1";
4405  },
4406  ),
4407  OP_NOT: (
4408  "recursive": True,
4409  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4410  return sprintf("not (%s)", cn);
4411  },
4412  ),
4413  OP_CLT: (
4414  "argcolumn": True,
4415  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4416  return sprintf("%s < %s", cn, arg);
4417  },
4418  ),
4419  OP_CLE: (
4420  "argcolumn": True,
4421  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4422  return sprintf("%s <= %s", cn, arg);
4423  },
4424  ),
4425  OP_CGT: (
4426  "argcolumn": True,
4427  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4428  return sprintf("%s > %s", cn, arg);
4429  },
4430  ),
4431  OP_CGE: (
4432  "argcolumn": True,
4433  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4434  return sprintf("%s >= %s", cn, arg);
4435  },
4436  ),
4437  OP_CNE: (
4438  "argcolumn": True,
4439  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4440  return sprintf("%s != %s", cn, arg);
4441  },
4442  ),
4443  OP_CEQ: (
4444  "argcolumn": True,
4445  "code": string (object t, string cn, string arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4446  return sprintf("%s = %s", cn, arg);
4447  },
4448  ),
4449  OP_SUBSTR: (
4450  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4451  args += arg[0]; // start
4452  if (!exists arg[1]);
4453 
4454  args += arg[1]; // count
4455  args += arg[2]; // text
4456  return sprintf("substring(%s from %v for %v) = %v", cn);
4457  },
4458  ),
4459  OP_OR: (
4460  "code": string (object t, string cn, list arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4461  return t.getOrClause(arg, \args, jch, join, ch, psch);
4462  },
4463  ),
4464  );
4466 
4489  hash<OperatorInfo> make_op(string op, auto arg);
4491 
4492 
4494 
4503  hash<OperatorInfo> op_like(string str);
4504 
4505 
4507 
4518  hash<OperatorInfo> op_lt(auto arg);
4519 
4520 
4522 
4533  hash<OperatorInfo> op_le(auto arg);
4534 
4535 
4537 
4548  hash<OperatorInfo> op_gt(auto arg);
4549 
4550 
4552 
4563  hash<OperatorInfo> op_ge(auto arg);
4564 
4565 
4567 
4580  hash<OperatorInfo> op_ne(auto arg);
4581 
4582 
4584 
4597  hash<OperatorInfo> op_eq(auto arg);
4598 
4599 
4601 
4613  hash<OperatorInfo> op_between(auto l, auto r);
4614 
4615 
4617 
4626  hash<OperatorInfo> op_in();
4627 
4628 
4630 
4641  hash<OperatorInfo> op_in(list args);
4642 
4643 
4645 
4652  hash<OperatorInfo> op_not(hash arg);
4653 
4654 
4656 
4667  hash<OperatorInfo> op_clt(string arg);
4668 
4669 
4671 
4682  hash<OperatorInfo> op_cle(string arg);
4683 
4684 
4686 
4697  hash<OperatorInfo> op_cgt(string arg);
4698 
4699 
4701 
4712  hash<OperatorInfo> op_cge(string arg);
4713 
4714 
4716 
4727  hash<OperatorInfo> op_cne(string arg);
4728 
4729 
4731 
4742  hash<OperatorInfo> op_ceq(string arg);
4743 
4744 
4746 
4757  hash<OperatorInfo> op_substr(int start, *int count, string text);
4758 
4759 
4761 
4771  hash<OperatorInfo> op_substr(int start, string text);
4772 
4773 
4775 
4792  hash<string, hash<OperatorInfo>> wop_or(hash h1, hash h2);
4793 
4795 
4802 
4805  const IOP_SEQ = "seq";
4806 
4808 
4810  const IOP_SEQ_CURRVAL = "seq_currval";
4811 
4813  const DefaultIopMap = {};
4815 
4821 
4829  hash<InsertOperatorInfo> make_iop(string iop, auto arg);
4830 
4831 
4833 
4842  hash<InsertOperatorInfo> iop_seq(string arg);
4843 
4844 
4846 
4855  hash<InsertOperatorInfo> iop_seq_currval(string arg);
4856 
4858 
4860  const SqlUtilDrivers = (
4861  "oracle",
4862  "pgsql",
4863  "mysql",
4864  "freetds",
4865  "sybase",
4866  );
4867 
4870 
4871 public:
4872 private:
4873 
4874 public:
4875 
4876  private :
4877  *hash h;
4878 
4879 public:
4880 
4882  constructor(*hash nh);
4883 
4884 
4887 
4888 
4891 
4892 
4894 
4909  auto memberGate(string k);
4910 
4911 
4913 
4919  clear();
4920 
4921 
4923  abstract auto take(string k);
4924 
4926  renameKey(string old_name, string new_name);
4927 
4928 
4930  *hash getHash();
4931 
4932 
4934 
4943  bool matchKeys(hash h1);
4944 
4945 
4947 
4956  bool matchKeys(list l);
4957 
4958 
4960 
4969  bool matchKeys(AbstractHashContainer c);
4970 
4971 
4973 
4982  bool partialMatchKeys(hash h1);
4983 
4984 
4986 
4995  bool partialMatchKeys(list l);
4996 
4997 
4999 
5008  bool partialMatchKeys(AbstractHashContainer c);
5009 
5010 
5012 
5021  bool val();
5022 
5023 
5025 
5032  list<string> keys();
5033 
5034 
5036 
5043  list values();
5044 
5045 
5047 
5054  Qore::AbstractIterator iterator();
5055 
5056 
5058 
5065  Qore::AbstractIterator keyIterator();
5066 
5067 
5069 
5076  Qore::AbstractIterator pairIterator();
5077 
5078 
5080  bool empty();
5081 
5082 
5084 
5091  int size();
5092 
5093 
5095 
5104  bool hasKey(string k);
5105 
5106 
5108 
5117  bool hasKeyValue(string k);
5118 
5119 
5121 
5130  *string firstKey();
5131 
5132 
5134 
5143  *string lastKey();
5144 
5145 
5147  abstract string getElementName();
5148  };
5149 
5152 
5153 public:
5154 private:
5155 
5156 public:
5157 
5158  private :
5159  softlist l;
5160 
5161 public:
5162 
5164  constructor(softlist nl);
5165 
5166 
5168 
5179  abstract auto get(softint i);
5180 
5182  add(auto val);
5183 
5184 
5186  auto take(int i);
5187 
5188 
5190  list getList();
5191 
5192 
5194 
5203  bool val();
5204 
5205 
5207 
5214  Qore::ListIterator iterator();
5215 
5216 
5218  bool empty();
5219 
5220 
5222 
5229  int size();
5230 
5231 
5233  abstract string getElementName();
5234 
5235 
5236 private:
5237  checkIndex(int i);
5238 public:
5239 
5240  };
5241 
5244 
5245 public:
5247  constructor();
5248 
5249 
5251  constructor(AbstractDatasource ds, hash tables, *hash opt);
5252 
5253 
5255  constructor(AbstractDatasource ds);
5256 
5257 
5259  add(string k, Table val);
5260 
5261 
5263  add(string k, AbstractTable val);
5264 
5265 
5267  add(Table val);
5268 
5269 
5271  add(AbstractTable val);
5272 
5273 
5275  AbstractTable take(string k);
5276 
5277 
5279  populate(AbstractDatasource ds, hash tables, *hash opt);
5280 
5281 
5283  populate(AbstractDatasource ds);
5284 
5285 
5287 
5301  *list getDropAllForeignConstraintsOnTableSql(string name, *hash opt);
5302 
5303 
5305 
5320  AbstractTable memberGate(string k);
5321 
5322 
5324  string getElementName();
5325 
5326 
5328  *AbstractTable getIfExists(AbstractDatasource ds, string name);
5329 
5330 
5332  AbstractTable get(AbstractDatasource ds, string name);
5333 
5334 
5336 
5351  *string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts);
5352 
5353 
5355 
5366  bool tableRenamed(string old_name, string new_name, string old_sql_name);
5367 
5368 
5369 
5370 private:
5371  tableRenamedIntern(string old_name, string new_name, string oldsn);
5372 public:
5373 
5374 
5376 
5391  *string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
5392 
5393 
5394  list getCreateList();
5395 
5396 
5397  Qore::AbstractIterator createIterator();
5398 
5399 
5401 
5409  list getDropList();
5410 
5411 
5413 
5420  Qore::AbstractIterator dropIterator();
5421 
5422 
5423 
5424 private:
5425  getDependencies(reference<hash> tdh, reference<hash> sdh, *reference<hash> th);
5426 public:
5427 
5428  };
5429 
5432 
5433 public:
5435  constructor(*hash c) ;
5436 
5437 
5439  constructor(Columns old) ;
5440 
5441 
5443  add(string k, AbstractColumn val);
5444 
5445 
5447  AbstractColumn take(string k);
5448 
5449 
5451 
5466  AbstractColumn memberGate(string k);
5467 
5468 
5470  Columns subset(softlist l);
5471 
5472 
5474  string getElementName();
5475 
5476 
5478  bool equal(Columns cols);
5479 
5480  };
5481 
5484 
5485 public:
5486  public :
5488  string name;
5489 
5491  string native_type;
5492 
5494  *string qore_type;
5495 
5497  int size;
5498 
5500  bool nullable;
5501 
5503  *string def_val;
5504 
5506  *string comment;
5507 
5508 public:
5509 
5510  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string c);
5511 
5512 
5514  string getNativeTypeString();
5515 
5516 
5518  string getCreateSql(AbstractTable t);
5519 
5520 
5522 
5531  abstract list getAddColumnSql(AbstractTable t);
5532 
5534  string getDropSql(string table_name);
5535 
5536 
5538 
5551  list getModifySql(AbstractTable t, AbstractColumn c, *hash opt);
5552 
5553 
5555 
5565  abstract string getRenameSql(AbstractTable t, string new_name);
5566 
5568  bool equal(AbstractColumn c);
5569 
5570 
5572 
5573 private:
5574  abstract bool equalImpl(AbstractColumn c);
5575 public:
5576 
5578 
5592 private:
5593  abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
5594 public:
5595  };
5596 
5599 
5600 public:
5601  public :
5603  int scale;
5604 
5605 public:
5606 
5607  constructor(softint n_scale = 0);
5608 
5609 
5611  string getNativeTypeString(string native_type, int precision);
5612 
5613  };
5614 
5617 
5618 public:
5619  constructor(*hash c) ;
5620 
5621 
5623  add(string k, AbstractIndex val);
5624 
5625 
5627  *AbstractIndex findEqual(AbstractIndex ix);
5628 
5629 
5631  AbstractIndex take(string k);
5632 
5633 
5635  *AbstractIndex tryTake(string k);
5636 
5637 
5639 
5654  AbstractIndex memberGate(string k);
5655 
5656 
5657  string getElementName();
5658 
5659  };
5660 
5663 
5664 public:
5665  public :
5667  string name;
5668 
5670  bool unique;
5671 
5674 
5675 public:
5676 
5677  private :
5680 
5681 public:
5682 
5684  constructor(string n, bool u, hash c);
5685 
5686 
5688  string getName();
5689 
5690 
5692  bool hasColumn(string cname);
5693 
5694 
5696  abstract string getCreateSql(string table_name, *hash opt);
5697 
5699  string getDropSql(string table_name);
5700 
5701 
5703  bool equal(AbstractIndex ix);
5704 
5705 
5707  bool equalExceptName(AbstractIndex ix);
5708 
5709 
5711  abstract bool equalImpl(AbstractIndex ix);
5712 
5714  abstract string getRenameSql(string table_name, string new_name);
5715 
5717  setSupportingConstraint(AbstractColumnSupportingConstraint c);
5718 
5719 
5721  setSupportingConstraint();
5722 
5723 
5725  *AbstractColumnSupportingConstraint getSupportingConstraint();
5726 
5727 
5729  list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt);
5730 
5731  };
5732 
5735 
5736 public:
5737  constructor(*hash c) ;
5738 
5739 
5741  add(string k, AbstractConstraint val);
5742 
5743 
5745  AbstractConstraint take(string k);
5746 
5747 
5749  *AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk);
5750 
5751 
5753 
5768  AbstractConstraint memberGate(string k);
5769 
5770 
5771  string getElementName();
5772 
5773  };
5774 
5777 
5778 public:
5779 private:
5780 
5781 public:
5782 
5783  private :
5785  string name;
5786 
5787 public:
5788 
5790  constructor(string n);
5791 
5792 
5794  string getName();
5795 
5796 
5798  rename(string n);
5799 
5800 
5802  abstract string getCreateSql(string table_name, *hash opt);
5803 
5805  string getDropSql(string table_name);
5806 
5807 
5809  abstract list getRenameSql(string table_name, string new_name);
5810 
5812  string getDisableSql(string table_name);
5813 
5814 
5816  string getEnableSql(string table_name, *hash opt);
5817 
5818 
5820  bool equal(AbstractConstraint c);
5821 
5822 
5824 
5825 private:
5826  abstract bool equalImpl(AbstractConstraint c);
5827 public:
5828 
5830  abstract bool setIndexBase(string ix);
5831 
5833  abstract clearIndex();
5834 
5836  bool hasColumn(string cname);
5837 
5838  };
5839 
5842 
5843 public:
5844  public :
5846  string src;
5847 
5848 public:
5849 
5851  constructor(string n, string n_src) ;
5852 
5853 
5855 
5856 private:
5857  bool equalImpl(AbstractConstraint c);
5858 public:
5859 
5860 
5862  bool setIndexBase(string ix);
5863 
5864 
5866  clearIndex();
5867 
5868  };
5869 
5872 
5873 public:
5874  private :
5877 
5879  *string index;
5880 
5881 public:
5882 
5884  constructor(string n, *hash c, *string n_index) ;
5885 
5886 
5888  constructor(string n, Columns c, *string n_index) ;
5889 
5890 
5892 
5896  Qore::AbstractIterator getSourceConstraintIterator();
5897 
5898 
5900  hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts);
5901 
5902 
5904  findMatchingIndex(*Indexes indexes);
5905 
5906 
5908 
5918  addSourceConstraint(string tname, AbstractForeignConstraint fk);
5919 
5920 
5922  removeSourceConstraint(string tname, list cols);
5923 
5924 
5926  renameSourceConstraintTable(string old_name, string new_name);
5927 
5928 
5930  bool hasColumn(string cname);
5931 
5932 
5934  *string getIndex();
5935 
5936 
5938 
5939 private:
5940  bool equalImpl(AbstractConstraint c);
5941 public:
5942 
5943 
5945  bool setIndexBase(string ix);
5946 
5947 
5949  clearIndex();
5950 
5951 
5953  abstract string getCreateSql(string table_name, *hash opts);
5954  };
5955 
5958 
5959 public:
5961  constructor(string n, *hash c, *string n_index) ;
5962 
5963  };
5964 
5967 
5968 public:
5969  constructor() ;
5970 
5971 
5972  constructor(string n, *hash c) ;
5973 
5974  };
5975 
5978 
5979 public:
5980  constructor(*hash c) ;
5981 
5982 
5984  add(string k, AbstractForeignConstraint val);
5985 
5986 
5988  AbstractForeignConstraint take(string k);
5989 
5990 
5993 
5994 
5996 
6011  AbstractForeignConstraint memberGate(string k);
6012 
6013 
6015  *hash findConstraintOn(string table, softlist cols);
6016 
6017 
6019  string getElementName();
6020 
6021  };
6022 
6025 
6026 public:
6027  public :
6029  string table;
6030 
6033 
6034 public:
6035 
6037  constructor(string t, Columns c);
6038 
6039 
6041  bool equal(ForeignConstraintTarget targ);
6042 
6043  };
6044 
6047 
6048 public:
6049  public :
6052 
6053 public:
6054 
6055  constructor(string n, Columns c, ForeignConstraintTarget t) ;
6056 
6057 
6059 
6060 private:
6061  bool equalImpl(AbstractConstraint con);
6062 public:
6063 
6064  };
6065 
6068 
6069 public:
6070  public :
6072  string name;
6073 
6076 
6079 
6082 
6083 public:
6084 
6086  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_max);
6087 
6088 
6090  abstract string getCreateSql(*hash opt);
6091 
6093 
6095  string getDropSql(*hash opt);
6096 
6097 
6099 
6102  abstract softlist getRenameSql(string new_name, *hash opt);
6103  };
6104 
6107 
6108 public:
6109  public :
6110  // ! potential object schema
6111  *string schema;
6112 
6114  string name;
6115 
6117  string src;
6118 
6121 
6122 public:
6123 
6125  constructor(string n_name, string n_src);
6126 
6127 
6129  abstract string getCreateSql(*hash opt);
6130 
6132 
6134  string getDropSql(*hash opt);
6135 
6136 
6138 
6141  abstract softlist getRenameSql(string new_name, *hash opt);
6142  };
6143 
6146 
6147 public:
6148  public :
6150  string name;
6151 
6153  string type;
6154 
6156  string src;
6157 
6158 public:
6159 
6161 
6165  constructor(string n, string n_type, string n_src);
6166 
6167 
6169  string getType();
6170 
6171 
6173 
6175  string getDropSql(*hash opt);
6176 
6177 
6179  bool equal(AbstractFunctionBase t);
6180 
6181 
6183 
6184 private:
6185  abstract bool equalImpl(AbstractFunctionBase t);
6186 public:
6187  };
6188 
6191 
6192 public:
6194 
6198  constructor(string n, string n_type, string n_src) ;
6199 
6200 
6202  abstract list getCreateSql(*hash opt);
6203 
6205 
6208  abstract softlist getRenameSql(string new_name, *hash opt);
6209 
6211  setName(string new_name);
6212 
6213  };
6214 
6217 
6218 public:
6219  constructor(*hash c) ;
6220 
6221 
6223  add(string k, AbstractFunction val);
6224 
6225 
6227  AbstractFunction take(string k);
6228 
6229 
6231 
6246  AbstractFunction memberGate(string k);
6247 
6248 
6249  string getElementName();
6250 
6251  };
6252 
6255 
6256 public:
6258  constructor(string n, string n_src) ;
6259 
6260 
6262  abstract list getCreateSql(string table_name, *hash opt);
6263 
6265  abstract softlist getRenameSql(string table_name, string new_name);
6266 
6268  abstract list getDropSql(string table_name);
6269  };
6270 
6273 
6274 public:
6275  constructor(*hash c) ;
6276 
6277 
6279  add(string k, AbstractTrigger val);
6280 
6281 
6283  AbstractTrigger take(string k);
6284 
6285 
6287 
6302  AbstractTrigger memberGate(string k);
6303 
6304 
6305  string getElementName();
6306 
6307  };
6308 
6310 
6320  class Database {
6321 
6322 public:
6323  private :
6326 
6327 public:
6328 
6330 
6341  constructor(AbstractDatasource ds, *hash opts);
6342 
6343 
6345 
6355  constructor(string ds, *hash opts);
6356 
6357 
6359 
6378 
6379 
6381  SqlUtil::AbstractDatabase getDatabase();
6382 
6383 
6385  any methodGate(string meth);
6386 
6387  };
6388 
6391 
6392 public:
6393  private :
6395  AbstractDatasource ds;
6397  string dsdesc;
6399  Mutex l();
6402 
6403 public:
6404 
6406 
6412 private:
6413  constructor(AbstractDatasource nds, *hash nopts);
6414 public:
6415 
6416 
6417  static string makeDatasourceDesc(AbstractDatasource ds);
6418 
6419 
6420 private:
6421  validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
6422 public:
6423 
6424 
6425 
6426 private:
6427  static validateOptionIntern(string err, string type, reference opt, string k, string tag);
6428 public:
6429 
6430 
6432 
6433 private:
6434  validateHashKeysForWhitespaces(auto node);
6435 public:
6436 
6437 
6440 
6441 
6443  string getDriverName();
6444 
6445 
6447  string getDatasourceDesc();
6448 
6449  };
6450 
6453 
6454 public:
6455  public :
6457 
6460  const DatabaseOptions = (
6461  "native_case": Type::Boolean,
6462  );
6463 
6465 
6468  const CacheOptions = (
6469  "table_cache": "Tables",
6470  );
6471 
6473 
6478  const CallbackOptions = (
6479  "info_callback": "code",
6480  "sql_callback": "code",
6481  "sql_callback_executed": Type::Boolean,
6482  );
6483 
6492  const AC_Unchanged = 0;
6494 
6496  const AC_Create = 1;
6497 
6499  const AC_Drop = 2;
6500 
6502  const AC_Rename = 3;
6503 
6505  const AC_Modify = 4;
6506 
6508  const AC_Truncate = 5;
6509 
6511  const AC_Add = 6;
6512 
6514  const AC_Recreate = 7;
6515 
6517  const AC_Insert = 8;
6518 
6520  const AC_Update = 9;
6521 
6523  const AC_Delete = 10;
6524 
6526  const AC_NotFound = 11;
6528 
6530  const ActionMap = (
6531  AC_Unchanged: "unchanged",
6532  AC_Create: "create",
6533  AC_Drop: "drop",
6534  AC_Rename: "rename",
6535  AC_Modify: "modify",
6536  AC_Truncate: "truncate",
6537  AC_Add: "add",
6538  AC_Recreate: "recreate",
6539  AC_Insert: "insert",
6540  AC_Update: "update",
6541  AC_Delete: "delete",
6542  AC_NotFound: "not found",
6543  );
6544 
6546  const ActionDescMap = (
6547  "unchanged": AC_Unchanged,
6548  "create": AC_Create,
6549  "drop": AC_Drop,
6550  "rename": AC_Rename,
6551  "modify": AC_Modify,
6552  "truncate": AC_Truncate,
6553  "add": AC_Add,
6554  "recreate": AC_Recreate,
6555  "insert": AC_Insert,
6556  "update": AC_Update,
6557  "delete": AC_Delete,
6558  "not found": AC_NotFound,
6559  );
6560 
6562  const ActionLetterMap = (
6563  AC_Unchanged: ".",
6564  AC_Create: "C",
6565  AC_Drop: "D",
6566  AC_Rename: "N",
6567  AC_Modify: "M",
6568  AC_Truncate: "T",
6569  AC_Add: "A",
6570  AC_Recreate: "R",
6571  AC_Insert: "I",
6572  AC_Update: "U",
6573  AC_Delete: "X",
6574  AC_NotFound: ".",
6575  );
6576 
6578 
6584  const CreationOptions = CallbackOptions + (
6585  "replace": Type::Boolean,
6586  "table_cache": "Tables",
6587  "data_tablespace": Type::String,
6588  "index_tablespace": Type::String,
6589  );
6590 
6592 
6595  const AlignSchemaOptions = CreationOptions + (
6596  "force": Type::Boolean,
6597  );
6598 
6600 
6603  const DropSchemaOptions = CallbackOptions + (
6604  "force": Type::Boolean,
6605  );
6606 
6608 
6620  const SchemaDescriptionOptions = (
6621  "tables": Type::Hash,
6622  "table_map": Type::Hash,
6623 
6624  "sequences": Type::Hash,
6625  "sequence_map": Type::Hash,
6626 
6627  "functions": Type::Hash,
6628  "function_map": Type::Hash,
6629 
6630  "procedures": Type::Hash,
6631  "procedure_map": Type::Hash,
6632 
6633  //"views": Type::Hash,
6634  //"view_map": Type::Hash,
6635  );
6636 
6638 
6643  const SequenceDescriptionOptions = (
6644  "start": Type::Int,
6645  "increment": Type::Int,
6646  "end": Type::Int,
6647  );
6648 
6650  const ComputeStatisticsOptions = (
6651  "tables" : "softstringlist",
6652  );
6653 
6655  const ReclaimSpaceOptions = (
6656  "tables" : "softstringlist",
6657  );
6658 
6659 public:
6660 
6661  private :
6664 
6665 public:
6666 
6668 
6674 private:
6675  constructor(AbstractDatasource nds, *hash nopts) ;
6676 public:
6677 
6678 
6680  list features();
6681 
6682 
6683  static doOkCallback(*hash opt, int ac, string type, string name, *string table, *string info);
6684 
6685 
6686 private:
6687  static runInfoCallback(code info_callback, int ac, string type, string name, *string table, *string new_name, *string info);
6688 public:
6689 
6690 
6691  static *string doCallback(*hash opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
6692 
6693  static list doCallback(*hash opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
6694 
6696 
6707  any tryExec(string sql);
6708 
6709 
6711 
6721  any tryExecArgs(string sql, *softlist args);
6722 
6723 
6725 
6736  any tryExecRaw(string sql);
6737 
6738 
6740 
6754  list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
6755 
6756 
6758 
6771  list getDropSchemaSql(hash schema_hash, *hash opt);
6772 
6773 
6774 
6775 private:
6776  list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
6777 public:
6778 
6779 
6780 
6781 private:
6782  list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
6783 public:
6784 
6785 
6787 
6801  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
6802 
6803 
6804  AbstractSequence makeSequenceFromDescription(string name, *hash sh, *hash opts);
6805 
6806 
6808 
6821  AbstractTable makeTable(string name, hash desc, *hash opts);
6822 
6823 
6825 
6836  AbstractFunction makeFunction(string name, string src, *hash opts);
6837 
6838 
6840 
6851  AbstractFunction makeProcedure(string name, string src, *hash opt);
6852 
6853 
6855 
6867  bool dropFunctionIfExists(string name, *hash opt);
6868 
6869 
6871 
6883  bool dropProcedureIfExists(string name, *hash opt);
6884 
6885 
6887 
6899  bool dropSequenceIfExists(string name, *hash opt);
6900 
6901 
6903 
6915  bool dropViewIfExists(string name, *hash opt);
6916 
6917 
6919 
6931  bool dropTableIfExists(string name, *hash opt);
6932 
6933 
6935 
6947  *string getDropFunctionSqlIfExists(string name, *hash opt);
6948 
6949 
6951 
6963  *string getDropProcedureSqlIfExists(string name, *hash opt);
6964 
6965 
6967 
6979  *string getDropSequenceSqlIfExists(string name, *hash opt);
6980 
6981 
6983 
6995  *list getDropTableSqlIfExists(string name, *hash opt);
6996 
6997 
6998  doDropSql(*softlist l, string type, string name, *hash opt);
6999 
7000 
7001  bool doDrop(*softlist l, string type, string name, *hash opt);
7002 
7003 
7005 
7017  list getAlignFunctionSql(AbstractFunction f, *hash opt);
7018 
7019 
7021 
7033  list getAlignProcedureSql(AbstractFunction f, *hash opt);
7034 
7035 
7037 
7046  *AbstractTable getTable(string name);
7047 
7048 
7050 
7059  *AbstractSequence getSequence(string name);
7060 
7061 
7063 
7074  *AbstractFunction getFunction(string name);
7075 
7076 
7078 
7089  *AbstractFunction getProcedure(string name);
7090 
7091 
7093 
7102  *AbstractView getView(string name);
7103 
7104 
7106 
7115  int getNextSequenceValue(string name);
7116 
7117 
7119 
7128  int getCurrentSequenceValue(string name);
7129 
7130 
7132 
7141  string getSqlFromList(list l);
7142 
7143 
7145  bool supportsSequences();
7146 
7147 
7149  bool supportsTypes();
7150 
7151 
7153  bool supportsPackages();
7154 
7155 
7157  list listTables();
7158 
7159 
7161  Qore::ListIterator tableIterator();
7162 
7163 
7165  list listFunctions();
7166 
7167 
7169  Qore::ListIterator functionIterator();
7170 
7171 
7173  list listProcedures();
7174 
7175 
7177  Qore::ListIterator procedureIterator();
7178 
7179 
7181  list listSequences();
7182 
7183 
7185  Qore::ListIterator sequenceIterator();
7186 
7187 
7189  list listViews();
7190 
7191 
7193  Qore::ListIterator viewIterator();
7194 
7195 
7197 
7207  bool rebuildIndex(string name, *hash options);
7208 
7209 
7211 
7219  bool rebuildIndex(AbstractIndex index, *hash options);
7220 
7221 
7223 
7230  computeStatistics(*hash options);
7231 
7232 
7234 
7241  reclaimSpace(*hash options);
7242 
7243 
7244 
7245 private:
7246  validateOptionsIntern(string err, hash ropt, reference<hash> opt);
7247 public:
7248 
7249 
7250 
7251 private:
7252  validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
7253 public:
7254 
7255 
7256  static AbstractDatabase getDatabase(AbstractDatasource nds, *hash opts);
7257 
7258  static AbstractDatabase getDatabase(string dsstr, *hash opts);
7259 
7260  static AbstractDatabase getDatabase(hash dsh, *hash opts);
7261 
7262  static checkDriverOptions(reference<hash> h, string drv);
7263 
7265 
7266 private:
7267  hash getDatabaseOptions();
7268 public:
7269 
7270 
7272 
7273 private:
7274  hash getCallbackOptions();
7275 public:
7276 
7277 
7279 
7280 private:
7281  hash getCreationOptions();
7282 public:
7283 
7284 
7286 
7287 private:
7289 public:
7290 
7291 
7293 
7294 private:
7295  hash getAlignSchemaOptions();
7296 public:
7297 
7298 
7300 
7301 private:
7302  hash getDropSchemaOptions();
7303 public:
7304 
7305 
7307 
7308 private:
7309  hash getSchemaDescriptionOptions();
7310 public:
7311 
7312 
7314 
7315 private:
7316  hash getSequenceDescriptionOptions();
7317 public:
7318 
7319 
7321 
7322 private:
7323  hash getRebuildIndexOptions();
7324 public:
7325 
7326 
7328 
7329 private:
7330  hash getComputeStatisticsOptions();
7331 public:
7332 
7333 
7335 
7336 private:
7337  hash getReclaimSpaceOptions();
7338 public:
7339 
7340 
7342 
7343 private:
7344  auto tryExecArgsImpl(string sql, *softlist args);
7345 public:
7346 
7347 
7349 
7350 private:
7351  auto tryExecRawImpl(string sql);
7352 public:
7353 
7354 
7355 
7356 private:
7357  abstract string getCreateSqlImpl(list l);
7358 public:
7359 
7360 private:
7361  abstract list getAlignSqlImpl(hash schema_hash, *hash opt);
7362 public:
7363 
7364 private:
7365  abstract list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
7366 public:
7367 
7368 
7369 private:
7370  abstract *AbstractSequence getSequenceImpl(string name);
7371 public:
7372 
7373 private:
7374  abstract *AbstractFunction getFunctionImpl(string name);
7375 public:
7376 
7377 private:
7378  abstract *AbstractFunction getProcedureImpl(string name);
7379 public:
7380 
7381 private:
7382  abstract *AbstractView getViewImpl(string name);
7383 public:
7384 
7385 
7386 private:
7387  abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
7388 public:
7389 
7390 private:
7391  abstract AbstractFunction makeFunctionImpl(string name, string src, *hash opts);
7392 public:
7393 
7394 private:
7395  abstract AbstractFunction makeProcedureImpl(string name, string src, *hash opts);
7396 public:
7397 
7398 
7399 private:
7400  abstract list featuresImpl();
7401 public:
7402 
7403 private:
7404  abstract list listTablesImpl();
7405 public:
7406 
7407 private:
7408  abstract list listFunctionsImpl();
7409 public:
7410 
7411 private:
7412  abstract list listProceduresImpl();
7413 public:
7414 
7415 private:
7416  abstract list listSequencesImpl();
7417 public:
7418 
7419 private:
7420  abstract list listViewsImpl();
7421 public:
7422 
7424 
7425 private:
7426  abstract int getNextSequenceValueImpl(string name);
7427 public:
7429 
7430 private:
7431  abstract int getCurrentSequenceValueImpl(string name);
7432 public:
7433 
7435 
7436 private:
7437  abstract bool supportsSequencesImpl();
7438 public:
7439 
7440 private:
7441  abstract bool supportsPackagesImpl();
7442 public:
7443 
7444 private:
7445  abstract bool supportsTypesImpl();
7446 public:
7447 
7448 
7449 private:
7450  abstract bool rebuildIndexImpl(string name, *hash options);
7451 public:
7452 
7453 private:
7454  abstract computeStatisticsImpl(*hash options);
7455 public:
7456 
7457 private:
7458  abstract reclaimSpaceImpl(*hash options);
7459 public:
7460  };
7461 
7463 
7479  class Table {
7480 
7481 public:
7482  private :
7485 
7486 public:
7487 
7489 
7501  constructor(AbstractDatasource ds, string name, *hash opts);
7502 
7503 
7505 
7517  constructor(string ds, string name, *hash opts);
7518 
7519 
7521 
7541  constructor(hash ds, string name, *hash opts);
7542 
7543 
7545 
7553  constructor(AbstractDatasource ds, hash desc, string name, *hash opts);
7554 
7555 
7557  AbstractTable getTable();
7558 
7559 
7561 
7563  any methodGate(string meth);
7564 
7565 
7566  }; // class Table
7567 
7569 
7572 
7573 public:
7574  public :
7576 
7580  const TableOptions = (
7581  "native_case": Type::Boolean,
7582  "table_cache": "Tables",
7583  );
7584 
7586 
7590  const IndexOptions = (
7591  "index_tablespace": Type::String,
7592  "replace": Type::Boolean,
7593  );
7594 
7596 
7599 
7601  const CacheOptions = (
7602  "table_cache": "Tables",
7603  );
7604 
7606 
7610  "table_cache": "Tables",
7611  );
7612 
7614 
7617 
7619 
7621  const SelectOptions = (
7622  "alias": Type::String,
7623  "comment": Type::String,
7624  "hint": Type::String,
7625  "columns": Type::NothingType,
7626  "where": "hash/list",
7627  "orderby": "softstringinthashlist",
7628  "desc": Type::Boolean,
7629  "limit": Type::Int,
7630  "offset": Type::Int,
7631  "join": Type::Hash,
7632  "groupby": "softstringinthashlist",
7633  "having": Type::Hash,
7634  "superquery": Type::Hash,
7635  "forupdate": Type::Boolean,
7636  );
7637 
7640  "indexes": True,
7641  "foreign_constraints": True,
7642  "triggers": True,
7643  );
7644 
7646 
7650  "omit": "softstringlist",
7651  );
7652 
7654 
7663  "column_map": Type::Hash,
7664  "index_map": Type::Hash,
7665  "constraint_map": Type::Hash,
7666  "trigger_map": Type::Hash,
7667  "db_table_cache": "Tables",
7668  "force": Type::Boolean,
7669  );
7670 
7672 
7684  "columns": Type::Hash,
7685  "primary_key": Type::Hash,
7686  "indexes": Type::Hash,
7687  "triggers": Type::Hash,
7688  "foreign_constraints": Type::Hash,
7689  "unique_constraints": Type::Hash,
7690  //"check_constraints": Type::Hash,
7691  "table_cache": "Tables",
7692  );
7693 
7695 
7708  "qore_type": Type::String,
7709  "native_type": Type::String,
7710  "size": Type::Int,
7711  "scale": Type::Int,
7712  "default_value": Type::NothingType,
7713  "default_value_native": Type::Boolean,
7714  "comment": Type::String,
7715  "notnull": Type::Boolean,
7716  "driver": Type::Hash,
7717  );
7718 
7720 
7724  "notnull": Type::Boolean,
7725  );
7726 
7728  const ColumnOptions = {};
7729 
7731 
7736  "sqlarg_callback": "code",
7737  "tablecode": "code",
7738  );
7739 
7741 
7751  "returning": "stringhashlist",
7752  );
7753 
7755 
7761  const UpsertOptions = (
7762  "info_callback": "code",
7763  "commit_block": Type::Int,
7764  "delete_others": Type::Boolean,
7765  "omit_update": "softstringlist",
7766  );
7767 
7769 
7774  "info_callback": "code",
7775  "commit_block": Type::Int,
7776  );
7777 
7793 
7800 
7802 
7808 
7810 
7817 
7819 
7823  const UpsertAuto = 4;
7824 
7826 
7830  const UpsertInsertOnly = 5;
7831 
7833 
7837  const UpsertUpdateOnly = 6;
7838 
7840 
7843  UpsertInsertFirst: "UpsertInsertFirst",
7844  UpsertUpdateFirst: "UpsertUpdateFirst",
7845  UpsertSelectFirst: "UpsertSelectFirst",
7846  UpsertAuto: "UpsertAuto",
7847  UpsertInsertOnly: "UpsertInsertOnly",
7848  UpsertUpdateOnly: "UpsertUpdateOnly",
7849  );
7850 
7852 
7855  "UpsertInsertFirst": UpsertInsertFirst,
7856  "UpsertUpdateFirst": UpsertUpdateFirst,
7857  "UpsertSelectFirst": UpsertSelectFirst,
7858  "UpsertAuto": UpsertAuto,
7859  "UpsertInsertOnly": UpsertInsertOnly,
7860  "UpsertUpdateOnly": UpsertUpdateOnly,
7861  );
7863 
7868  const UR_Inserted = 1;
7870 
7872  const UR_Verified = 2;
7873 
7875  const UR_Updated = 3;
7876 
7878  const UR_Unchanged = 4;
7879 
7881  const UR_Deleted = 5;
7883 
7885 
7888  UR_Inserted: "inserted",
7889  UR_Verified: "verified",
7890  UR_Updated: "updated",
7891  UR_Unchanged: "unchanged",
7892  UR_Deleted: "deleted",
7893  );
7894 
7896 
7899  "inserted": UR_Inserted,
7900  "verified": UR_Verified,
7901  "updated": UR_Updated,
7902  "unchanged": UR_Unchanged,
7903  "deleted": UR_Deleted,
7904  );
7905 
7908  UR_Inserted: "I",
7909  UR_Verified: "V",
7910  UR_Updated: "U",
7911  UR_Unchanged: ".",
7912  UR_Deleted: "X",
7913  );
7914 
7915 public:
7916 
7917  private :
7919  string name;
7935  bool inDb = False;
7937  bool manual = False;
7938 
7939  hash m_customCopMap = hash();
7940 
7941 public:
7942 
7944 
7951 private:
7952  constructor(AbstractDatasource nds, string nname, *hash nopts) ;
7953 public:
7954 
7955 
7957  copy(AbstractTable old);
7958 
7959 
7961 
7972  setDatasource(AbstractDatasource nds);
7973 
7974 
7975 
7976 private:
7977  doTableOptions(*hash nopts);
7978 public:
7979 
7980 
7982  commit();
7983 
7984 
7986  rollback();
7987 
7988 
7990 
7999  bool inDb();
8000 
8001 
8003 
8011 
8012 
8014 
8025  dropCommit(*hash opt);
8026 
8027 
8029 
8040  drop(*hash opt);
8041 
8042 
8044  deprecated dropNoCommit(*hash opt);
8045 
8047 
8058  auto tryExec(string sql);
8059 
8060 
8062 
8072  auto tryExecArgs(string sql, *softlist args);
8073 
8074 
8076 
8087  auto tryExecRaw(string sql);
8088 
8089 
8091 
8102  softlist getDropSql(*hash opt);
8103 
8104 
8106 
8113  truncateCommit();
8114 
8115 
8117 
8124  truncate();
8125 
8126 
8128  deprecated truncateNoCommit();
8129 
8131 
8146  string getTruncateSql(*hash opt);
8147 
8148 
8150 
8159  createCommit(*hash opt);
8160 
8161 
8163 
8174  create(*hash opt);
8175 
8176 
8178  deprecated createNoCommit(*hash opt);
8179 
8181 
8192  rename(string new_name, *reference<string> sql, *Tables table_cache);
8193 
8194 
8195 
8196 private:
8197  doRenameIntern(string new_name, *Tables table_cache);
8198 public:
8199 
8200 
8202 
8213  bool emptyData();
8214 
8215 
8217 
8226  bool empty();
8227 
8228 
8229 
8230 private:
8231  bool emptyUnlocked();
8232 public:
8233 
8234 
8236 
8242  setupTable(hash desc, *hash opt);
8243 
8244 
8246 
8270  AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8271 
8272 
8274 
8303  list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8304 
8305 
8306 
8307 private:
8308  AbstractColumn addColumnUnlocked(string cname, hash opt, bool nullable = True, *reference lsql, bool do_exec = True, bool modify_table = True);
8309 public:
8310 
8311 
8312 
8313 private:
8314  addColumnToTableUnlocked(AbstractColumn c);
8315 public:
8316 
8317 
8319 
8344  AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8345 
8346 
8348 
8375  list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8376 
8377 
8379 
8396  AbstractColumn renameColumn(string old_name, string new_name, reference<string> sql);
8397 
8398 
8400 
8418  string getRenameColumnSql(string old_name, string new_name, *hash opt);
8419 
8420 
8421 
8422 private:
8423  AbstractColumn renameColumnIntern(AbstractColumn c, string new_name);
8424 public:
8425 
8426 
8427 
8428 private:
8429  validateOptionsIntern(string err, hash ropt, reference<hash> opt);
8430 public:
8431 
8432 
8433 
8434 private:
8435  validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
8436 public:
8437 
8438 
8439 
8440 private:
8441  execSql(softlist lsql);
8442 public:
8443 
8444 
8446 
8466  AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference<string> sql);
8467 
8468 
8470 
8492  string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
8493 
8494 
8495 
8496 private:
8497  setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
8498 public:
8499 
8500 
8501 
8502 private:
8503  AbstractPrimaryKey addPrimaryKeyUnlocked(string pkname, softlist cols, *hash opt, *reference<string> sql);
8504 public:
8505 
8506 
8507 
8508 private:
8509  AbstractPrimaryKey addPrimaryKeyUnlockedIntern(string pkname, softlist cols, *hash opt, *reference<string> sql);
8510 public:
8511 
8512 
8514 
8531 
8532 
8533 
8534 private:
8535  list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(string cname, *hash opt);
8536 public:
8537 
8538 
8540 
8560 
8561 
8563 
8581  AbstractPrimaryKey dropPrimaryKey(*reference lsql);
8582 
8583 
8585 
8606  AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference<string> sql);
8607 
8608 
8610 
8630  string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
8631 
8632 
8633 
8634 private:
8635  AbstractUniqueConstraint addUniqueConstraintUnlocked(string cname, softlist cols, *hash opt, *reference<string> sql);
8636 public:
8637 
8638 
8639 
8640 private:
8641  AbstractUniqueConstraint addUniqueConstraintUnlockedIntern(string cname, softlist cols, *hash opt, *reference<string> sql);
8642 public:
8643 
8644 
8646 
8667  AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
8668 
8669 
8671 
8692  string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
8693 
8694 
8695 
8696 private:
8697  AbstractIndex addIndexUnlocked(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
8698 public:
8699 
8700 
8701 
8702 private:
8703  AbstractIndex addIndexUnlockedIntern(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
8704 public:
8705 
8706 
8708 
8720  AbstractIndex renameIndex(string old_name, string new_name, reference<string> sql);
8721 
8722 
8724 
8742  AbstractIndex dropIndex(string iname, *reference<string> sql);
8743 
8744 
8746 
8765  string getDropIndexSql(string iname, *hash opt);
8766 
8767 
8769 
8791  AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
8792 
8793 
8795 
8817  string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
8818 
8819 
8820 
8821 private:
8822  Columns getReferencedTableColumnsUnlocked(string table, *Tables cache, string err = "FOREIGN-CONSTRAINT-ERROR");
8823 public:
8824 
8825 
8826 
8827 private:
8828  AbstractForeignConstraint addForeignConstraintUnlocked(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
8829 public:
8830 
8831 
8832 
8833 private:
8834  AbstractForeignConstraint addForeignConstraintUnlockedIntern(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
8835 public:
8836 
8837 
8839 
8857  AbstractForeignConstraint dropForeignConstraint(string cname, *reference<string> sql);
8858 
8859 
8861 
8877 
8878 
8880 
8900  AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference<string> sql);
8901 
8902 
8904 
8926  string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
8927 
8928 
8929 
8930 private:
8931  AbstractCheckConstraint addCheckConstraintUnlocked(string cname, string src, *hash opt, *reference<string> sql);
8932 public:
8933 
8934 
8935 
8936 private:
8937  AbstractCheckConstraint addCheckConstraintUnlockedIntern(string cname, string src, *hash opt, *reference<string> sql);
8938 public:
8939 
8940 
8942 
8954  AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
8955 
8956 
8958 
8977  string getDropConstraintSql(string cname, *hash opt);
8978 
8979 
8981 
9000  *string getDropConstraintIfExistsSql(string cname, *hash opt, *reference<AbstractConstraint> cref);
9001 
9002 
9003 
9004 private:
9005  AbstractConstraint findDropConstraintUnlocked(string cname, reference<code> rmv);
9006 public:
9007 
9008 
9010 
9028  AbstractConstraint dropConstraint(string cname, *reference<string> sql);
9029 
9030 
9032 
9052  AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
9053 
9054 
9056 
9078  list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
9079 
9080 
9081 
9082 private:
9083  AbstractTrigger addTriggerUnlocked(string tname, string src, *hash opt, *reference lsql);
9084 public:
9085 
9086 
9087 
9088 private:
9089  AbstractTrigger addTriggerUnlockedIntern(string tname, string src, *hash opt, *reference lsql);
9090 public:
9091 
9092 
9094 
9112  AbstractTrigger dropTrigger(string tname, *reference<string> sql);
9113 
9114 
9116 
9135  list getDropTriggerSql(string tname, *hash opt);
9136 
9137 
9138 
9139 private:
9140  getAllConstraintsUnlocked(*hash opt);
9141 public:
9142 
9143 
9144 
9145 private:
9146  checkUniqueConstraintName(string err, string cname);
9147 public:
9148 
9149 
9150 
9151 private:
9152  checkUniqueConstraintNameValidateOptions(string err, string cname, hash ropt, reference<hash> opt);
9153 public:
9154 
9155 
9157 
9158 private:
9159  validateColumnOptions(string cname, reference<hash> opt, bool nullable);
9160 public:
9161 
9162 
9164 
9182  AbstractColumn dropColumn(string cname, *reference lsql);
9183 
9184 
9186 
9205  list getDropColumnSql(string cname, *hash opt);
9206 
9207 
9209 
9222  *hash insertCommit(hash row);
9223 
9224 
9226  *hash insertCommit(hash row, reference<string> sql);
9227 
9228 
9230  *hash insertCommit(hash row, hash opt);
9231 
9232 
9234  *hash insertCommit(hash row, reference<string> sql, hash opt);
9235 
9236 
9238 
9252  *hash insert(hash row);
9253 
9254 
9256  *hash insert(hash row, reference<string> sql);
9257 
9258 
9260  *hash insert(hash row, hash opt);
9261 
9262 
9264  *hash insert(hash row, reference<string> sql, hash opt);
9265 
9266 
9268  deprecated *hash insertNoCommit(hash row, *reference<string> sql, *hash opt);
9269 
9271  deprecated *hash insertNoCommit(hash row, hash opt);
9272 
9273 
9274 private:
9275  *hash insertIntern(hash row, *reference<string> sql, *hash opt);
9276 public:
9277 
9278 
9279 
9280 private:
9281  hash getPlaceholdersAndValues(hash row);
9282 public:
9283 
9284 
9286 
9289  bool hasReturning();
9290 
9291 
9293 
9312  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference<string> sql, hash opt);
9313 
9314 
9316  int insertFromSelectCommit(list cols, AbstractTable source);
9317 
9318 
9320  int insertFromSelectCommit(list cols, AbstractTable source, hash sh);
9321 
9322 
9324  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference<string> sql);
9325 
9326 
9328  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, hash opt);
9329 
9330 
9332 
9351  int insertFromSelect(list cols, AbstractTable source, hash sh, reference<string> sql, hash opt);
9352 
9353 
9355  int insertFromSelect(list cols, AbstractTable source);
9356 
9357 
9359  int insertFromSelect(list cols, AbstractTable source, hash sh);
9360 
9361 
9363  int insertFromSelect(list cols, AbstractTable source, hash sh, reference<string> sql);
9364 
9365 
9367  int insertFromSelect(list cols, AbstractTable source, hash sh, hash opt);
9368 
9369 
9371  deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference<string> sql, *hash opt);
9372 
9373 
9374 private:
9375  int insertFromSelectIntern(list cols, AbstractTable source, *hash sh, *reference<string> sql, *hash opt);
9376 public:
9377 
9378 
9380 
9399 
9400 
9402 
9421 
9422 
9424  deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt);
9425 
9426 
9427 private:
9428  int insertFromIteratorIntern(Qore::AbstractIterator i, *hash opt);
9429 public:
9430 
9431 
9433 
9449  int upsertCommit(hash row, int upsert_strategy = UpsertAuto, *hash opt);
9450 
9451 
9453 
9469  int upsert(hash row, int upsert_strategy = UpsertAuto, *hash opt);
9470 
9471 
9473  deprecated int upsertNoCommit(hash row, int upsert_strategy = UpsertAuto);
9474 
9476 
9497  code getUpsertClosure(hash row, int upsert_strategy = UpsertAuto, *hash opt);
9498 
9499 
9501 
9528  code getBulkUpsertClosure(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9529 
9530 
9532 
9553  code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = UpsertAuto, *hash opt);
9554 
9555 
9557 
9590 
9591 
9593 
9626 
9627 
9629  deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9630 
9631 
9632 private:
9633  *hash upsertFromIteratorIntern(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9634 public:
9635 
9636 
9637 
9638 private:
9639  *hash doDeleteOthersIntern(hash pkh, *hash opt);
9640 public:
9641 
9642 
9644 
9682  *hash upsertFromSelectCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9683 
9684 
9686  *hash upsertFromSelectCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9687 
9688 
9690 
9730  *hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9731 
9732 
9734  deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9735 
9737  deprecated *hash upsertFromSelect(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9738 
9740  deprecated *hash upsertFromSelectNoCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9741 
9743 
9754  softint rowCount();
9755 
9756 
9758 
9778  Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference<string> sql, *hash opt);
9779 
9780 
9782 
9802  Qore::SQL::SQLStatement getRowIteratorNoExec(*hash sh, *reference<string> sql, *hash opt);
9803 
9804 
9805 
9806 private:
9807  Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference<string> sql, *hash opt, *bool no_exec);
9808 public:
9809 
9810 
9812 
9830 
9831 
9833 
9852  *hash selectRow(*hash sh, *reference<string> sql, *hash opt);
9853 
9854 
9856 
9874  *list selectRows(*hash sh, *reference<string> sql, *hash opt);
9875 
9876 
9878 
9896  *hash select(*hash sh, *reference<string> sql, *hash opt);
9897 
9898 
9900 
9918  *hash selectRow(*hash sh, *hash opt);
9919 
9920 
9922 
9939  *list selectRows(*hash sh, *hash opt);
9940 
9941 
9943 
9960  *hash select(*hash sh, *hash opt);
9961 
9962 
9964 
9982  string getSelectSql(*hash sh, *reference<list> args);
9983 
9984 
9985  *AbstractUniqueConstraint matchAnyUnique(list cols);
9986 
9987 
9988  string getSelectSqlIntern(*hash qh, reference<list> args, *hash opt);
9989 
9990 
9991  string getSelectSqlUnlocked(*hash qh, reference<list> args, *hash opt);
9992 
9993 
9994  // column & table information must be retrieved before calling this function
9995  string getSelectSqlUnlockedIntern(*hash qh, string from, reference<list> args, *hash ch, *hash opt);
9996 
9997 
9998 
9999 private:
10000  string getFromIntern(string from, *hash qh);
10001 public:
10002 
10003 
10004 
10005 private:
10006  list getGroupByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
10007 public:
10008 
10009 
10010 
10011 private:
10012  list getOrderByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
10013 public:
10014 
10015 
10016 
10017 private:
10018  list getGroupOrderByListUnlocked(string key, hash qh, *hash jch, *hash ch, *hash psch, list coll);
10019 public:
10020 
10021 
10022 
10023 private:
10024  doForUpdate(reference<string> sql);
10025 public:
10026 
10027 
10028 
10029 private:
10030  string getSelectSqlName(*hash qh);
10031 public:
10032 
10033 
10034 
10035 private:
10036  string getColumnExpressionIntern(auto cvc, *hash jch, bool join, *hash ch, *hash psch);
10037 public:
10038 
10039 
10040 
10041 private:
10042  string doColumnOperatorIntern(hash cvc, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
10043 public:
10044 
10045 
10046 
10047 private:
10048  string doColumnOperatorIntern(auto cop, auto arg, *string cve, hash cm, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
10049 public:
10050 
10051 
10052 
10053 private:
10054  string getColumnNameIntern(string cv, *hash jch, bool join, *hash ch, *hash psch);
10055 public:
10056 
10057 
10059 
10060 private:
10061  bool asteriskRequiresPrefix();
10062 public:
10063 
10064 
10065 
10066 private:
10067  getSelectWhereSqlUnlocked(reference<string> sql, reference<list> args, *hash qh, *hash jch, bool join = False, *hash ch, *hash psch);
10068 public:
10069 
10070 
10071 
10072 private:
10073  *string getWhereClause(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False);
10074 public:
10075 
10076 
10077 
10078 private:
10079  *string getWhereClause(list cond, reference<list> args, *string cprefix, *hash jch, bool join = False);
10080 public:
10081 
10082 
10083 
10084 private:
10085  *string getWhereClauseUnlocked(list cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
10086 public:
10087 
10088 
10089 
10090 private:
10091  *string getWhereClauseUnlocked(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
10092 public:
10093 
10094 
10095 
10096 private:
10097  *list getWhereClauseIntern(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash ch, *hash psch);
10098 public:
10099 
10100 
10101 
10102 private:
10103  string doWhereExpressionIntern(string cn, auto we, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
10104 public:
10105 
10106 
10107  string getOrClause(list arglist, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
10108 
10109 
10110  string getOrClause(hash arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
10111 
10112 
10113 
10114 private:
10115  doSelectOrderBySqlUnlocked(reference<string> sql, reference<list> args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
10116 public:
10117 
10118 
10120 
10135  int delCommit(hash cond, reference<string> sql, hash opt);
10136 
10137 
10139  int delCommit(hash cond, hash opt);
10140 
10141 
10143  int delCommit(hash cond, reference<string> sql);
10144 
10145 
10147  int delCommit(hash cond);
10148 
10149 
10151  int delCommit();
10152 
10153 
10155 
10170  int del(hash cond, reference<string> sql, hash opt);
10171 
10172 
10174  int del(hash cond, hash opt);
10175 
10176 
10178  int del(hash cond, reference<string> sql);
10179 
10180 
10182  int del(hash cond);
10183 
10184 
10186  int del();
10187 
10188 
10190  deprecated int delNoCommit(*hash cond, *reference<string> sql);
10191 
10192 
10193 private:
10194  int delIntern(*hash cond, *reference<string> sql, *hash opt);
10195 public:
10196 
10197 
10199 
10216  int updateCommit(hash set, hash cond, reference<string> sql, hash opt);
10217 
10218 
10220  int updateCommit(hash set, hash cond, reference<string> sql);
10221 
10222 
10224  int updateCommit(hash set, hash cond, hash opt);
10225 
10226 
10228  int updateCommit(hash set, hash cond);
10229 
10230 
10232  int updateCommit(hash set);
10233 
10234 
10236 
10253  int update(hash set, hash cond, reference<string> sql, hash opt);
10254 
10255 
10257  int update(hash set, hash cond, reference<string> sql);
10258 
10259 
10261  int update(hash set, hash cond, hash opt);
10262 
10263 
10265  int update(hash set, hash cond);
10266 
10267 
10269  int update(hash set);
10270 
10271 
10273  deprecated int updateNoCommit(hash set, *hash cond, *reference<string> sql);
10274 
10276  deprecated int updateNoCommit(hash set, *hash cond, *hash opt);
10277 
10278 
10279 private:
10280  int updateIntern(hash set, *hash cond, *reference<string> sql, *hash opt);
10281 public:
10282 
10283 
10284 
10285 private:
10286  string getUpdateExpression(string col, hash<UpdateOperatorInfo> uh);
10287 public:
10288 
10289 
10290 
10291 private:
10292  bool emptyDataIntern();
10293 public:
10294 
10295 
10296 
10297 private:
10298  Columns checkUpsertRow(hash row, reference<int> upsert_strategy);
10299 public:
10300 
10301 
10302 
10303 private:
10304  code getUpsertInsertFirst(Columns cols, hash example_row, *hash opt);
10305 public:
10306 
10307 
10308 
10309 private:
10310  code getUpsertUpdateFirst(Columns cols, hash example_row, *hash opt);
10311 public:
10312 
10313 
10314 
10315 private:
10316  code getUpsertSelectFirst(Columns cols, hash example_row, *hash opt);
10317 public:
10318 
10319 
10320 
10321 private:
10322  code getUpsertInsertOnly(Columns cols, hash example_row, *hash opt);
10323 public:
10324 
10325 
10326 
10327 private:
10328  code getUpsertUpdateOnly(Columns cols, hash example_row, *hash opt);
10329 public:
10330 
10331 
10332 
10333 private:
10334  Columns getUpsertColumns(reference csrc);
10335 public:
10336 
10337 
10338 
10339 private:
10340  string getUpsertSelectSql(hash row, Columns cols, reference<list<string>> updc);
10341 public:
10342 
10343 
10344 
10345 private:
10346  string getUpsertInsertSql(hash row);
10347 public:
10348 
10349 
10350 
10351 private:
10352  string getUpsertUpdateSql(hash row, Columns cols, reference updc, *hash opt);
10353 public:
10354 
10355 
10356 
10357 private:
10358  softbool tryUpdate(string sql, hash row, Columns cols, list updc);
10359 public:
10360 
10361 
10362 
10363 private:
10364  checkValue(string cname, string argname, reference val, string type);
10365 public:
10366 
10367 
10369 
10378  string getSqlFromList(list l);
10379 
10380 
10382 
10393  string getSqlValue(auto v);
10394 
10395 
10397  string getName();
10398 
10399 
10401 
10408  cache(*hash opts);
10409 
10410 
10412 
10417  clear();
10418 
10419 
10421 
10428  Columns describe();
10429 
10430 
10432 
10441 
10442 
10444 
10454 
10455 
10456  *AbstractUniqueConstraint findUniqueConstraintUnlocked(string name);
10457 
10458 
10460 
10469  Indexes getIndexes();
10470 
10471 
10474 
10475 
10478 
10479 
10481 
10491 
10492 
10494 
10512  string getRenameSql(string new_name, *hash opt);
10513 
10514 
10516 
10525  string getCreateSqlString(*hash opt);
10526 
10527 
10529 
10538  list getCreateSql(*hash opt);
10539 
10540 
10542 
10553  string getCreateTableSql(*hash opt);
10554 
10555 
10557 
10561  bool checkExistence();
10562 
10563 
10564 
10565 private:
10566  *hash getCheckOmissionOptions(*softlist ol, string err);
10567 public:
10568 
10569 
10571 
10587 
10588 
10589 
10590 private:
10591  list getAlignSqlUnlocked(AbstractTable t, *hash opt);
10592 public:
10593 
10594 
10595 
10596 private:
10597  *AbstractColumnSupportingConstraint getSupportingConstraint(string ixname);
10598 public:
10599 
10600 
10601 
10602 private:
10603  renameIndexUnlocked(AbstractIndex ix, string new_name);
10604 public:
10605 
10606 
10608 
10621  string getAlignSqlString(AbstractTable t, *hash opt);
10622 
10623 
10625 
10637  *list getCreateIndexesSql(*hash opt, bool cache = True);
10638 
10639 
10641 
10653  *string getCreatePrimaryKeySql(*hash opt, bool cache = True);
10654 
10655 
10657 
10669  *list getCreateForeignConstraintsSql(*hash opt, bool cache = True);
10670 
10671 
10673 
10687  *list getCreateConstraintsSql(*hash opt, bool cache = True);
10688 
10689 
10691 
10703  *list getCreateMiscSql(*hash opt, bool cache = True);
10704 
10705 
10707 
10721  *list getCreateTriggersSql(*hash opt, bool cache = True);
10722 
10723 
10725 
10732  *hash find(auto id);
10733 
10734 
10736 
10747  *list find(list ids);
10748 
10749 
10750 
10751 private:
10752  string getPrimaryKeyColumn();
10753 public:
10754 
10755 
10757 
10770  *hash find(hash row);
10771 
10772 
10774 
10787  *hash findSingle(*hash cond);
10788 
10789 
10791 
10804  *list findAll(*hash cond);
10805 
10806 
10808 
10812  string getDesc();
10813 
10814 
10816  string getBaseType();
10817 
10818 
10820  string getSqlName();
10821 
10822 
10824  string getColumnSqlName(string col);
10825 
10826 
10828  list getColumnSqlNames(softlist cols);
10829 
10830 
10832 
10834  bool bindEmptyStringsAsNull();
10835 
10836 
10838  abstract bool hasArrayBind();
10839 
10841 
10844 private:
10846 public:
10847 
10848 
10850 
10853 private:
10855 public:
10856 
10857 
10859 
10862 private:
10864 public:
10865 
10866 
10868 
10871 private:
10873 public:
10874 
10875 
10877 
10880 private:
10882 public:
10883 
10884 
10886 
10889 private:
10891 public:
10892 
10893 
10895 
10898 private:
10900 public:
10901 
10902 
10904 
10907 private:
10909 public:
10910 
10911 
10913 
10916 private:
10918 public:
10919 
10920 
10922 
10925 private:
10927 public:
10928 
10929 
10931 
10934 private:
10936 public:
10937 
10938 
10940 
10943 private:
10945 public:
10946 
10947 
10949 
10952 private:
10954 public:
10955 
10956 
10958 
10961 private:
10963 public:
10964 
10965 
10967 
10970 private:
10972 public:
10973 
10974 
10976 
10979 private:
10981 public:
10982 
10983 
10985 
10988 private:
10990 public:
10991 
10992 
10994 
10997 private:
10999 public:
11000 
11001 
11003 
11006 private:
11008 public:
11009 
11010 
11012 
11013 private:
11015 public:
11016 
11017 
11019 
11055  addCustomCopOperator(string name, hash operator);
11056 
11057 
11059 
11062 private:
11064 public:
11065 
11066 
11068 
11071 private:
11073 public:
11074 
11075 
11077 
11080 private:
11082 public:
11083 
11084 
11086 
11089 private:
11091 public:
11092 
11093 
11094 
11095 private:
11096  string getCreateTableSqlUnlocked(*hash opt);
11097 public:
11098 
11099 
11100 
11101 private:
11102  *list getCreateIndexesSqlUnlocked(*hash opt, bool cache = True);
11103 public:
11104 
11105 
11106 
11107 private:
11108  *string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
11109 public:
11110 
11111 
11112 
11113 private:
11114  *list getCreateConstraintsSqlUnlocked(*hash opt, bool cache = True);
11115 public:
11116 
11117 
11118 
11119 private:
11120  *list getCreateForeignConstraintsSqlUnlocked(*hash opt, bool cache = True);
11121 public:
11122 
11123 
11124 
11125 private:
11126  *list getCreateMiscSqlUnlocked(*hash opt, bool cache = True);
11127 public:
11128 
11129 
11130 
11131 private:
11132  *list getCreateTriggersSqlUnlocked(*hash opt, bool cache = True);
11133 public:
11134 
11135 
11136 
11137 private:
11138  list getCreateSqlUnlocked(*hash opt, bool cache = True);
11139 public:
11140 
11141 
11142 
11143 private:
11144  cacheUnlocked(*hash opt);
11145 public:
11146 
11147 
11148 
11149 private:
11150  auto execData(*hash opt, string sql, *list args);
11151 public:
11152 
11153 
11154 
11155 private:
11156  execData(SQLStatement stmt, *hash opt, *list args);
11157 public:
11158 
11159 
11160  static AbstractTable getTable(AbstractDatasource nds, string nname, *hash opts);
11161 
11162  static AbstractTable getTable(string dsstr, string nname, *hash opts);
11163 
11164  static AbstractTable getTable(hash dsh, string nname, *hash opts);
11165 
11166 
11167 private:
11168  getColumnsUnlocked();
11169 public:
11170 
11171 
11172 
11173 private:
11174  getPrimaryKeyUnlocked();
11175 public:
11176 
11177 
11178  // also loads primary key and constraints (for unique constraints)
11179 
11180 private:
11181  getIndexesUnlocked();
11182 public:
11183 
11184 
11185 
11186 private:
11187  getForeignConstraintsUnlocked(*hash opt);
11188 public:
11189 
11190 
11191 
11192 private:
11193  addSourceConstraint(string table_name, AbstractForeignConstraint fk);
11194 public:
11195 
11196 
11197 
11198 private:
11199  getConstraintsUnlocked();
11200 public:
11201 
11202 
11203 
11204 private:
11205  getTriggersUnlocked();
11206 public:
11207 
11208 
11210 
11211 private:
11212  bool hasReturningImpl();
11213 public:
11214 
11215 
11216 
11217 private:
11218  softlist getDropSqlImpl();
11219 public:
11220 
11221 
11222 
11223 private:
11224  string getTruncateSqlImpl();
11225 public:
11226 
11227 
11229 
11230 private:
11231  auto tryExecArgsImpl(string sql, *softlist args);
11232 public:
11233 
11234 
11236 
11237 private:
11238  auto tryExecRawImpl(string sql);
11239 public:
11240 
11241 
11243 
11244 private:
11245  clearImpl();
11246 public:
11247 
11248 
11249 
11250 private:
11251  preSetupTableImpl(reference desc, *hash opt);
11252 public:
11253 
11254 
11255 
11256 private:
11257  abstract *hash doReturningImpl(hash opt, reference<string> sql, list args);
11258 public:
11259 
11260 
11261 private:
11262  abstract bool emptyImpl();
11263 public:
11264 
11266 
11267 private:
11268  abstract *string getSqlValueImpl(auto v);
11269 public:
11270 
11272 
11276 private:
11277  abstract bool checkExistenceImpl();
11278 public:
11279 
11281 
11282 private:
11283  abstract bool supportsTablespacesImpl();
11284 public:
11285 
11287 
11288 private:
11289  abstract bool constraintsLinkedToIndexesImpl();
11290 public:
11291 
11293 
11294 private:
11295  abstract bool uniqueIndexCreatesConstraintImpl();
11296 public:
11297 
11298 
11299 private:
11300  abstract setupTableImpl(hash desc, *hash opt);
11301 public:
11302 
11303 
11304 private:
11305  abstract Columns describeImpl();
11306 public:
11307 
11308 private:
11309  abstract AbstractPrimaryKey getPrimaryKeyImpl();
11310 public:
11311 
11312 private:
11313  abstract Indexes getIndexesImpl();
11314 public:
11315 
11316 private:
11317  abstract ForeignConstraints getForeignConstraintsImpl(*hash opt);
11318 public:
11319 
11320 private:
11321  abstract Constraints getConstraintsImpl();
11322 public:
11323 
11324 private:
11325  abstract Triggers getTriggersImpl();
11326 public:
11327 
11328 
11329 private:
11330  abstract string getCreateTableSqlImpl(*hash opt);
11331 public:
11332 
11333 private:
11334  abstract *list getCreateMiscSqlImpl(*hash opt, bool cache);
11335 public:
11336 
11337 private:
11338  abstract string getCreateSqlImpl(list l);
11339 public:
11340 
11341 private:
11342  abstract string getRenameSqlImpl(string new_name);
11343 public:
11344 
11345 private:
11346  abstract *list getAlignSqlImpl(AbstractTable t, *hash opt);
11347 public:
11348 
11349 
11350 private:
11351  abstract AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
11352 public:
11353 
11354 private:
11355  abstract AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
11356 public:
11357 
11358 private:
11359  abstract AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
11360 public:
11361 
11362 private:
11363  abstract AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
11364 public:
11365 
11366 private:
11367  abstract AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
11368 public:
11369 
11370 private:
11371  abstract AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
11372 public:
11373 
11374 
11375 private:
11376  abstract AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
11377 public:
11378 
11380 
11381 private:
11382  abstract bool tryInsertImpl(string sql, hash row);
11383 public:
11384 
11386 
11387 private:
11388  abstract hash getQoreTypeMapImpl();
11389 public:
11390 
11392 
11393 private:
11394  abstract hash getTypeMapImpl();
11395 public:
11396 
11398 
11399 private:
11400  abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference<string> sql, reference<list> args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
11401 public:
11402 
11404 
11405 private:
11406  abstract doSelectLimitOnlyUnlockedImpl(reference<string> sql, reference<list> args, *hash qh);
11407 public:
11408 
11410 
11411 private:
11412  abstract copyImpl(AbstractTable old);
11413 public:
11414  };
11415 }
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5785
hash< ColumnOperatorInfo > cop_first_value(any column)
Analytic/window function: value evaluated at the row that is the first row of the window frame...
softlist getDropSql(*hash opt)
returns the sql required to drop the table; reimplement in subclasses if necessary ...
const SelectOptions
default possible select options; can be extended by driver-specific modules
Definition: SqlUtil.qm.dox.h:7621
Constraints getConstraints()
returns a Constraints object describing the non-foreign constraints on the table
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6072
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2339
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2144
const Hash
any column
column sopecifier, may be a string or a complex hash
Definition: SqlUtil.qm.dox.h:2131
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:7823
const String
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
const DefaultIopMap
a hash of default insert operator descriptions (currently empty, all operators are driver-dependent) ...
Definition: SqlUtil.qm.dox.h:4813
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:5151
hash< ColumnOperatorInfo > cop_append(auto column, string arg)
returns a ColumnOperatorInfo hash for the "append" operator with the given argument ...
const TableOmissionOptions
alignment omission options
Definition: SqlUtil.qm.dox.h:7639
string native_type
the native database column type; if both native_type and qore_type are given then native_type is used...
Definition: SqlUtil.qm.dox.h:2103
rename(string new_name, *reference< string > sql, *Tables table_cache)
renames the table; if the table is already known to be in the database in the database, then the changes are effected in the database also immediately; otherwise it is only updated internally
string cop
the column operator string code
Definition: SqlUtil.qm.dox.h:2130
string sprintf(string fmt,...)
deprecated truncateNoCommit()
A legacy warpper for truncate()
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table is already known to be in the database...
bool hasReturningImpl()
returns True if the current database driver supports the "returning" clause in insert statements...
int delCommit()
SqlUtil::AbstractTable::delCommit() variant
const OP_IN
the SQL "in" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4331
deprecated createNoCommit(*hash opt)
A legacy wrapper for create()
hash getInsertOptions()
returns the insert options for this driver
bool checkExistence()
returns True if the table exists in the database, False if not
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:7571
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2430
bool hasReturning()
returns True if the current database driver supports the "returning" clause in insert statements...
hash< ColumnOperatorInfo > cop_cast(auto column, string arg, auto arg1, auto arg2)
returns a ColumnOperatorInfo hash for the "cast" operator with the given argument(s) ...
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2190
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:7609
const COP_FIRST_VALUE
Analytic (window) function: FIRST_VALUE.
Definition: SqlUtil.qm.dox.h:2391
hash< ColumnOperatorInfo > cop_multiply(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "*" operator with the given arguments
*hash insertCommit(hash row)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
const ColumnOptions
Column options; this is currently empty and can be extended in database-specific modules.
Definition: SqlUtil.qm.dox.h:7728
auto tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:5243
validateColumnOptions(string cname, reference< hash > opt, bool nullable)
validates column options
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:6120
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
hash getIndexOptions()
returns the index options for this driver
const UpsertResultLetterMap
maps upsert result codes to single letter symbols
Definition: SqlUtil.qm.dox.h:7907
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:7842
dropCommit(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
insert operator info hash as returned by all insert operator functions
Definition: SqlUtil.qm.dox.h:2136
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:7869
hash< OperatorInfo > op_ne(auto arg)
returns an OperatorInfo hash for the "!=" or "<>" operator with the given argument for use in where c...
cache(*hash opts)
reads in all attributes of the table from the database
string printf(string fmt,...)
const OP_BETWEEN
the SQL "between" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4326
string getSqlValue(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:5679
deprecated int delNoCommit(*hash cond, *reference< string > sql)
A legacy SqlUtil::AbstractTable::del() wrapper.
*hash upsertFromSelectCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
hash< ColumnOperatorInfo > make_cop(string cop, auto column, auto arg)
returns a ColumnOperatorInfo hash
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2138
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:5662
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4344
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
const COP_OVER
the SQL "over" clause
Definition: SqlUtil.qm.dox.h:2294
hash< ColumnOperatorInfo > cop_as(auto column, string arg)
returns a ColumnOperatorInfo hash for the "as" operator with the given argument
auto tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5977
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:7898
hash< ColumnOperatorInfo > cop_minus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "-" operator with the given arguments
const UR_Deleted
row was deleted (only possible with batch upsert methods such as AbstractTable::upsertFromIterator() ...
Definition: SqlUtil.qm.dox.h:7881
int insertFromIteratorCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
const InsertFromIteratorOptions
default insert option keys
Definition: SqlUtil.qm.dox.h:7773
hash< ColumnOperatorInfo > cop_last_value(any column)
Analytic/window function: value evaluated at the row that is the last row of the window frame...
const COP_DENSE_RANK
Analytic (window) function: DENSE_RANK.
Definition: SqlUtil.qm.dox.h:2384
deprecated int upsertNoCommit(hash row, int upsert_strategy=UpsertAuto)
A legacy SqlUtil::AbstractTable::upsert() wrapper.
const OP_NE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4286
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table
hash< ColumnOperatorInfo > cop_rank()
Analytic/window function: rank of the current row with gaps.
deprecated *hash insertNoCommit(hash row, *reference< string > sql, *hash opt)
A legacy wrapper for SqlUtil::AbstractTable::insert()
constructor(AbstractDatasource nds, string nname, *hash nopts)
creates the object; private constructor
hash< InsertOperatorInfo > iop_seq_currval(string arg)
returns an InsertOperatorInfo hash for retrieving the current value of the given sequence in insert q...
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2284
list getAlignSql(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
truncateCommit()
truncates all the table data; releases the transaction lock after executing
string name
the name of the object
Definition: SqlUtil.qm.dox.h:6150
string getAlignSqlString(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:6024
hash< ColumnOperatorInfo > cop_length(auto column)
returns a ColumnOperatorInfo hash for the "len" operator with the given argument; returns the length ...
*list getCreateIndexesSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:5494
const COP_SEQ_CURRVAL
to return the last value of a sequence issued in the same session
Definition: SqlUtil.qm.dox.h:2344
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:5598
int upsert(hash row, int upsert_strategy=UpsertAuto, *hash opt)
update or insert the data in the table according to the hash argument; the table must have a unique k...
const True
hash< InsertOperatorInfo > make_iop(string iop, auto arg)
returns an InsertOperatorInfo hash
const JopMap
a hash of valid join operators
Definition: SqlUtil.qm.dox.h:3787
hash getTableCreationOptions()
returns the table creation options for this driver
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:2213
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4276
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2196
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2279
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:2174
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:2168
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3779
base class for sequences
Definition: SqlUtil.qm.dox.h:6067
*hash upsertFromIteratorCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
*list getCreateTriggersSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
Qore::SQL::SQLStatement getRowIteratorNoExec(*hash sh, *reference< string > sql, *hash opt)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
const COP_LAST_VALUE
Analytic (window) function: LAST_VALUE.
Definition: SqlUtil.qm.dox.h:2398
hash< OperatorInfo > op_clt(string arg)
returns an OperatorInfo hash for the "<" operator with the given argument for use in where clauses wh...
nothing flush()
bool nullable
True if the column can hold a NULL value, False if not
Definition: SqlUtil.qm.dox.h:5500
abstract hash getQoreTypeMapImpl()
returns the qore type -> column type map
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2125
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:7761
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2264
hash< OperatorInfo > op_cge(string arg)
returns an OperatorInfo hash for the ">=" operator with the given argument for use in where clauses w...
hash getTriggerOptions()
returns the trigger options for this driver
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:2334
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:7601
*hash opt
optional join options (for example, to specify a partition for the join if supported) ...
Definition: SqlUtil.qm.dox.h:2156
Columns describe()
returns an object of class Columns describing the table
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7927
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:7933
*list selectRows(*hash sh, *reference< string > sql, *hash opt)
returns a list of hashes representing the rows in the table that match the argument hash ...
hash< UpdateOperatorInfo > uop_multiply(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "*" operator with the given arguments
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
hash< ColumnOperatorInfo > cop_plus(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "+" operator with the given arguments
AbstractConstraint dropConstraint(string cname, *reference< string > sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
hash< ColumnOperatorInfo > cop_value(auto arg)
returns a ColumnOperatorInfo hash for the "value" (literal) operator with the given argument ...
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt)
gets a list of SQL strings to drop all constraints and indexes with the given column name; if the col...
any table
the table to join with (either an AbstractTable object or a string table name)
Definition: SqlUtil.qm.dox.h:2151
hash< UpdateOperatorInfo > uop_substr(int start, *int count, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "substr" operator with the given arguments; returns a subs...
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
string jop
the join operator string code
Definition: SqlUtil.qm.dox.h:2150
const IOP_SEQ_CURRVAL
for using the last value of a sequence issued in the current session
Definition: SqlUtil.qm.dox.h:4810
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 List
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:6390
abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference< string > sql, reference< list > args, *hash qh, *hash jch, *hash ch, *hash psch, list coll)
processes a string for use in SQL select statements when there is an "order by" and "offset" argument...
hash getAlignTableOptions()
returns the align table options for this driver
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:7807
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference< string > sql, *hash opt)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
hash< ColumnOperatorInfo > cop_year_day(auto column)
returns a ColumnOperatorInfo hash for the "year_day" operator with the given argument ...
list getAddColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
returns a list of SQL strings that can be use to add a column to the table
string getColumnSqlName(string col)
returns the column name for use in SQL strings; subclasses can return a special string in case the co...
const NULL
create(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
const OP_CNE
the SQL not equals operator (!= or <>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4316
auto tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
hash< UpdateOperatorInfo > uop_prepend(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "prepend" operator with the given argument ...
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:6320
const SqlUtilDrivers
known drivers
Definition: SqlUtil.qm.dox.h:4860
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4306
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:6046
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:6051
hash< OperatorInfo > op_le(auto arg)
returns an OperatorInfo hash for the "<=" operator with the given argument for use in where clauses w...
deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtil::AbstractTable::upsertFromSelect() wrapper.
const False
Mutex l()
mutex for atomic actions
deprecated dropNoCommit(*hash opt)
A legacy wrapper for drop()
int insertFromSelect(list cols, AbstractTable source, hash sh, reference< string > sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
const NothingType
AbstractIndex renameIndex(string old_name, string new_name, reference< string > sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
hash< string, hash< JoinOperatorInfo > > join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments for use when joining with a table other...
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:5603
abstract hash getTypeMapImpl()
returns the type name -> type description hash
hash< string, hash< JoinOperatorInfo > > join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy=UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing a single row that will be u...
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:5841
hash< UpdateOperatorInfo > uop_divide(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "/" operator with the given arguments
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2289
list list(...)
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4321
const COP_NTILE
Analytic (window) function: NTILE.
Definition: SqlUtil.qm.dox.h:2405
hash< UpdateOperatorInfo > uop_plus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "+" operator with the given arguments
softint scale
for numeric data types, this value gives the scale
Definition: SqlUtil.qm.dox.h:2107
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4869
hash< ColumnOperatorInfo > cop_year_hour(auto column)
returns a ColumnOperatorInfo hash for the "year_hour" operator with the given argument ...
join operator info hash as returned by all join operator functions
Definition: SqlUtil.qm.dox.h:2149
any default_value
the default value for the column
Definition: SqlUtil.qm.dox.h:2109
the SqlUtil namespace contains all the objects in the SqlUtil module
Definition: SqlUtil.qm.dox.h:2097
bool empty()
returns True if the table has no definitions, False if not
string name
the table&#39;s name
Definition: SqlUtil.qm.dox.h:7919
hash< OperatorInfo > op_cne(string arg)
returns an OperatorInfo hash for the "!=" or "<>" operator with the given argument for use in where c...
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:6272
int updateCommit(hash set, hash cond, reference< string > sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2132
string getSelectSql(*hash sh, *reference< list > args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
int index(softstring str, softstring substr, softint pos=0)
string src
the source of the check clause
Definition: SqlUtil.qm.dox.h:5846
string getDatasourceDesc()
returns a descriptive string for the datasource
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference< string > sql)
adds an index to the table; if the table is already known to be in the database, then it is added in ...
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7925
const DT_DAY
Format unit: day.
Definition: SqlUtil.qm.dox.h:3509
hash< OperatorInfo > op_cle(string arg)
returns an OperatorInfo hash for the "<=" operator with the given argument for use in where clauses w...
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:2170
hash< ColumnOperatorInfo > cop_avg(auto column)
returns a ColumnOperatorInfo hash for the "avg" operator; returns average column values ...
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2254
hash< string, hash< JoinOperatorInfo > > join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
hash getColumnDescOptions()
returns the column description options for this driver
deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtik::AbstractTable::upsertFromIterator() wrapper.
*hash getColumnOperatorMapImpl()
Reimplement in subclasses to provide driver specific column operators.
code getUpsertClosure(hash row, int upsert_strategy=UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing a single row that will be u...
clearImpl()
clears any driver-specific table information
*hash cond
additional conditions for the join clause for the table argument; see Where Clauses for more informat...
Definition: SqlUtil.qm.dox.h:2154
const COP_PLUS
the SQL "plus" operator
Definition: SqlUtil.qm.dox.h:2304
const Boolean
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7872
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:4281
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:5616
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2219
hash< OperatorInfo > op_between(auto l, auto r)
returns an OperatorInfo hash for the "between" operator with the given arguments, neither of which ca...
const TableOptions
table options
Definition: SqlUtil.qm.dox.h:7580
*bool auto_increment
True for DBs that support an auto-increment column
Definition: SqlUtil.qm.dox.h:2119
*hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
const DB_SYNONYMS
Feature: synonyms.
Definition: SqlUtil.qm.dox.h:2182
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:5503
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7923
hash< UpdateOperatorInfo > uop_upper(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "upper" operator with the given argument; returns a column...
const COP_COALESCE
to return the first non-null argument in the list
Definition: SqlUtil.qm.dox.h:2349
string op
the operator string code
Definition: SqlUtil.qm.dox.h:2124
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:7937
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:7662
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
bool emptyData()
returns True if the table has no data rows, False if not
string getBaseType()
returns the base type of the underlying object (normally "table", some DB-specific implementations ma...
hash< ColumnOperatorInfo > cop_min(auto column)
returns a ColumnOperatorInfo hash for the "min" operator; returns minimum column values ...
*list getCreateForeignConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
abstract bool hasArrayBind()
returns True if the underlying DB driver supports bulk DML operations
hash< OperatorInfo > op_ge(auto arg)
returns an OperatorInfo hash for the ">=" operator with the given argument for use in where clauses w...
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:7931
string getDesc()
returns a descriptive string of the datasource (without the password) and the table name (with a poss...
abstract *string getSqlValueImpl(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:2172
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:6584
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4291
validateHashKeysForWhitespaces(auto node)
Check input node for all hash keys - if it contains a key with whitespace in the beginning or at the ...
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
bool exists(...)
generic column description hash in schema descriptions
Definition: SqlUtil.qm.dox.h:2099
int del()
SqlUtil::AbstractTable::del() variant
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:5506
code getBulkUpsertClosure(hash example_row, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing either a single row or a se...
hash< ColumnOperatorInfo > cop_coalesce(auto col1, auto col2)
returns a ColumnOperatorInfo hash for the "coalesce" operator with the given column arguments; the fi...
string src
the source code
Definition: SqlUtil.qm.dox.h:6117
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:5670
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
hash< ColumnOperatorInfo > cop_trunc_date(auto column, string mask)
Truncates a date column or value regarding the given mask. The resulting value remains Qore::date (no...
hash< ColumnOperatorInfo > cop_dense_rank()
Analytic/window function: rank of the current row without gaps.
hash< OperatorInfo > op_eq(auto arg)
returns an OperatorInfo hash for the "=" operator with the given argument for use in where clauses wh...
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifier for schema, etc)
*hash find(auto id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:2324
string src
the source of the object
Definition: SqlUtil.qm.dox.h:6156
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference< string > sql)
adds a primary key to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2274
hash< OperatorInfo > op_cgt(string arg)
returns an OperatorInfo hash for the ">" operator with the given argument for use in where clauses wh...
const COP_LENGTH
to get the length of a text field
Definition: SqlUtil.qm.dox.h:2361
auto tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2229
string getDriverName()
returns the database driver name
hash< string, hash< JoinOperatorInfo > > join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments for use when joining with a table other ...
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:7921
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference< AbstractConstraint > cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:2180
hash< ColumnOperatorInfo > cop_max(auto column)
returns a ColumnOperatorInfo hash for the "max" operator; returns maximum column values ...
AbstractTrigger dropTrigger(string tname, *reference< string > sql)
drops the given trigger from the table; if the table is known to be in the database already...
const OP_LE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4271
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2199
string name
the name of the index
Definition: SqlUtil.qm.dox.h:5667
string _iop
the insert operator string code
Definition: SqlUtil.qm.dox.h:2137
*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:6032
string uop
the update operator string code
Definition: SqlUtil.qm.dox.h:2143
drop(*hash opt)
drops the table from the database without any transaction management
const OP_CLE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4301
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5871
AbstractColumn addColumn(string cname, hash opt, bool nullable=True, *reference lsql)
adds a column to the table; if the table is already known to be in the database, then it is added in ...
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:2176
abstract bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
hash< UpdateOperatorInfo > uop_append(string arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "append" or concatenate operator with the given argument ...
createCommit(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
hash< UpdateOperatorInfo > uop_seq_currval(string seq)
returns an UpdateOperatorInfo hash for the "seq" operator with the given argument giving the sequence...
hash< ColumnOperatorInfo > cop_ntile(int value)
Analytic/window function: integer ranging from 1 to the argument value, dividing the partition as equ...
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:2202
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4336
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:5673
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:7735
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:6145
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:2178
string getRenameColumnSql(string old_name, string new_name, *hash opt)
gets an SQL string that can be used to rename an existing column in the table
update operator info hash as returned by all update operator functions
Definition: SqlUtil.qm.dox.h:2142
hash< string, hash< JoinOperatorInfo > > make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns hash keyed with the table name assigned to a JoinOperatorInfo hash
const COP_CUME_DIST
Analytic (window) function: CUME_DIST.
Definition: SqlUtil.qm.dox.h:2377
copy(AbstractTable old)
copies the object
hash< ColumnOperatorInfo > cop_lower(auto column)
returns a ColumnOperatorInfo hash for the "lower" operator with the given argument; returns a column ...
hash< ColumnOperatorInfo > cop_distinct(auto column)
returns a ColumnOperatorInfo hash for the "distinct" operator with the given argument; returns distin...
hash getColumnOptions()
returns the column options for this driver
bool asteriskRequiresPrefix()
returns True if the database requires a wildcard "*" to be prefixed with the table name when it appea...
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:7887
string name
the name of the column
Definition: SqlUtil.qm.dox.h:5488
bool bindEmptyStringsAsNull()
returns True if the DB treats empty strings as NULL, False if not; by default this method returns Fal...
hash< ColumnOperatorInfo > cop_year(auto column)
returns a ColumnOperatorInfo hash for the "year" operator with the given argument ...
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:6395
hash< UpdateOperatorInfo > uop_lower(*hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "lower" operator with the given argument; returns a column...
bool same(list l)
hash< string, hash< OperatorInfo > > wop_or(hash h1, hash h2)
returns an OperatorInfo hash with a fake "_OR_" column name; the list of arguments to the function is...
hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
base class for functions
Definition: SqlUtil.qm.dox.h:6190
auto tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
abstract copyImpl(AbstractTable old)
db-specific copy actions
const COP_MULTIPLY
the SQL "multiply" operator
Definition: SqlUtil.qm.dox.h:2314
column operator info hash as returned by all column operator functions
Definition: SqlUtil.qm.dox.h:2129
hash< ColumnOperatorInfo > cop_count(auto column="")
returns a ColumnOperatorInfo hash for the "count" operator; returns row counts
abstract bool tryInsertImpl(string sql, hash row)
tries to insert a row, if there is a duplicate key, then it returns False, if successful, returns True
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:7929
hash< ColumnOperatorInfo > cop_cume_dist()
Analytic/window function: relative rank of the current row.
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:2239
hash getInsertFromIteratorOptions()
returns the insert from iterator options for this driver
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
string type(auto arg)
const COP_TRUNC_DATE
to return the date with truncated value
Definition: SqlUtil.qm.dox.h:2370
*hash insert(hash row)
inserts a row into the table without any transaction management; a transaction will be in progress af...
base class for views
Definition: SqlUtil.qm.dox.h:6106
deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference< string > sql, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromSelect() wrapper.
hash< OperatorInfo > op_like(string str)
returns an OperatorInfo hash for the "like" operator with the given argument for use in where clauses...
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:6401
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
abstract bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
*list getCreateConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create non-foreign constraints on the table or NO...
*hash select(*hash sh, *reference< string > sql, *hash opt)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference< string > sql)
adds a foreign constraint to the table; if the table is already known to be in the database...
const InsertOptions
generic SQL insert options
Definition: SqlUtil.qm.dox.h:7750
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:7616
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
hash< string, hash< JoinOperatorInfo > > join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
string type
the type of object
Definition: SqlUtil.qm.dox.h:6153
deprecated int updateNoCommit(hash set, *hash cond, *reference< string > sql)
A legacy SqlUtil::AbstractTable::update() wrapper.
hash< ColumnOperatorInfo > cop_seq(string seq, *string as)
returns a ColumnOperatorInfo hash for the "seq" operator with the given argument giving the sequence ...
const Int
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:2319
hash< string, hash< JoinOperatorInfo > > join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments for use when joining with a table ot...
string string(softstring str, *string enc)
hash getWhereOperatorMap()
returns the "where" operator map for this object
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference< string > sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
softint rowCount()
returns the number of rows in the table
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
hash getForeignConstraintOptions()
return the foreign constraint options for this driver
int size
the size of the column
Definition: SqlUtil.qm.dox.h:5497
hash< string, hash > driver
this key can optionally contain a hash keyed by driver name which contains a hash of values that will...
Definition: SqlUtil.qm.dox.h:2117
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
hash getConstraintOptions()
returns the constraint options for this driver
hash getUpsertOptions()
returns the upsert options for this driver
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:5491
const COP_VALUE
to append a constant value (SQL Literal) to use as an output column value
Definition: SqlUtil.qm.dox.h:2249
hash< UpdateOperatorInfo > uop_seq(string seq)
returns an UpdateOperatorInfo hash for the "seq" operator with the given argument giving the sequence...
const UpsertUpdateOnly
Upsert option: update if the row exists, otherwise ignore.
Definition: SqlUtil.qm.dox.h:7837
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:5431
the base class for triggers
Definition: SqlUtil.qm.dox.h:6254
*string ta
optional table name or alias of the other table to join with when not joining with the primary table ...
Definition: SqlUtil.qm.dox.h:2155
*hash getPseudoColumnHash()
returns a hash of valid pseudocolumns
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference< string > sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
const OP_LT
the SQL less than (<) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4266
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:6397
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
hash< ColumnOperatorInfo > cop_sum(auto column)
returns a ColumnOperatorInfo hash for the "sum" operator; returns the total sum of a numeric column...
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:6216
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst, UpsertInsertOnly, and UpsertUpdateOnly) ...
Definition: SqlUtil.qm.dox.h:7878
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7875
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6325
the base class for column information
Definition: SqlUtil.qm.dox.h:5483
truncate()
truncates all the table data without any transaction management
const COP_CAST
to convert column value into another datatype
Definition: SqlUtil.qm.dox.h:2234
hash< OperatorInfo > op_in()
returns an OperatorInfo hash for the "in" operator with all arguments passed to the function; for use...
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:7830
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4311
const DT_MINUTE
Format unit: minute.
Definition: SqlUtil.qm.dox.h:3515
hash< ColumnOperatorInfo > cop_seq_currval(string seq, *string as)
returns a ColumnOperatorInfo hash for the "seq_currval" operator with the given argument giving the s...
const DT_HOUR
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3512
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:7479
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:7590
*string comment
an optional comment for the column
Definition: SqlUtil.qm.dox.h:2113
AbstractIndex dropIndex(string iname, *reference< string > sql)
drops the given index from the table; if the table is known to be in the database already...
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference< string > sql)
adds a unique constraint to the table; if the table is known to be in the database already...
hash< ColumnOperatorInfo > cop_divide(auto column1, auto column2)
returns a ColumnOperatorInfo hash for the "/" operator with the given arguments
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:3529
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2269
const UpsertSelectFirst
Upsert option: select first, if the row is unchanged, do nothing, if it doesn&#39;t exist, insert, otherwise update.
Definition: SqlUtil.qm.dox.h:7816
AbstractForeignConstraint dropForeignConstraint(string cname, *reference< string > sql)
drops a foreign constraint from the table; if the table is known to be in the database already...
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:2329
hash< OperatorInfo > op_gt(auto arg)
returns an OperatorInfo hash for the ">" operator with the given argument for use in where clauses wh...
const Closure
setupTable(hash desc, *hash opt)
creates the object from a table description hash
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:7799
const DT_MONTH
Format unit: month.
Definition: SqlUtil.qm.dox.h:3506
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6114
hash getTableColumnDescOptions()
returns the table column description options for this driver
const COP_PERCENT_RANK
Analytic (window) function: PERCENT_RANK.
Definition: SqlUtil.qm.dox.h:2412
abstract doSelectLimitOnlyUnlockedImpl(reference< string > sql, reference< list > args, *hash qh)
processes a string for use in SQL select statements when there is a "limit" argument, but no "orderby" or "offset" arguments
*hash jcols
the columns to use for the join, the keys will be columns in the source table and the values are colu...
Definition: SqlUtil.qm.dox.h:2153
*number max
the ending number
Definition: SqlUtil.qm.dox.h:6081
hash getUpdateOperatorMap()
returns the update operator map for this object
const COP_RANK
Analytic (window) function: RANK.
Definition: SqlUtil.qm.dox.h:2419
hash< OperatorInfo > op_not(hash arg)
returns an OperatorInfo hash for the "not" operator; for use in where clauses
const ColumnDescOptions
Column description options.
Definition: SqlUtil.qm.dox.h:7707
number increment
the increment
Definition: SqlUtil.qm.dox.h:6078
hash getTableOptions()
returns the table options for this driver
hash< ColumnOperatorInfo > cop_row_number()
Analytic/window function: number of the current row within its partition, counting from 1...
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
const OP_LIKE
the SQL "like" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4261
hash< OperatorInfo > op_lt(auto arg)
returns an OperatorInfo hash for the "<" operator with the given argument for use in where clauses wh...
hash< OperatorInfo > make_op(string op, auto arg)
returns an OperatorInfo hash
hash< OperatorInfo > op_substr(int start, *int count, string text)
returns an OperatorInfo hash for the "substr" operator with the given arguments; for use in where cla...
const TableDescriptionHashOptions
Table description options.
Definition: SqlUtil.qm.dox.h:7683
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2210
hash< UpdateOperatorInfo > uop_minus(auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash for the "-" operator with the given arguments
AbstractColumn renameColumn(string old_name, string new_name, reference< string > sql)
renames an existing column; if the table is already known to be in the database, then the changes are...
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:7484
hash getColumnOperatorMap()
returns the column operator map for this object
hash< ColumnOperatorInfo > cop_upper(auto column)
returns a ColumnOperatorInfo hash for the "upper" operator with the given argument; returns a column ...
const OP_CLT
the SQL less than (<) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:4296
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2299
hash< ColumnOperatorInfo > cop_percent_rank()
Analytic/window function: relative rank of the current row.
hash getTableDescriptionHashOptions()
returns the table description hash options for this driver
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:6029
hash hash(object obj)
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
const TableCreationOptions
table creation options
Definition: SqlUtil.qm.dox.h:7649
hash< ColumnOperatorInfo > cop_over(auto column, *string partitionby, *string orderby)
returns a ColumnOperatorInfo hash for the "over" clause
hash< ColumnOperatorInfo > cop_year_month(auto column)
returns a ColumnOperatorInfo hash for the "year_month" operator with the given argument ...
*list getCreateMiscSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create other table attributes (such as comments...
*string alias
optional alias for table in the query
Definition: SqlUtil.qm.dox.h:2152
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2354
hash getSelectOptions()
returns the select options for this driver
hash getCacheOptions()
returns the cache options for this driver
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3784
list getColumnSqlNames(softlist cols)
returns a list of column names for use in SQL strings; subclasses can process the argument list in ca...
const OP_SUBSTR
the SQL "substr" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4341
*hash selectRow(*hash sh, *reference< string > sql, *hash opt)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
int upsertCommit(hash row, int upsert_strategy=UpsertAuto, *hash opt)
update or insert the data in the table according to the hash argument; the table must have a unique k...
hash< ColumnOperatorInfo > cop_substr(auto column, int start, *int count)
returns a ColumnOperatorInfo hash for the "substr" operator with the given arguments; returns a subst...
hash getSqlDataCallbackOptions()
returns the sql data operation callback options for this driver
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:2216
hash< InsertOperatorInfo > iop_seq(string arg)
returns an InsertOperatorInfo hash for retrieving the value of the given sequence in insert queries ...
abstract bool checkExistenceImpl()
returns True if the table exists in the DB, False if not
softint size
for data types requiring a size component, the size; for numeric columns this represents the precisio...
Definition: SqlUtil.qm.dox.h:2105
int update(hash set, hash cond, reference< string > sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
SQL operator info hash as returned by all operator functions.
Definition: SqlUtil.qm.dox.h:2123
number start
the starting number
Definition: SqlUtil.qm.dox.h:6075
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4805
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:6452
const COP_ROW_NUMBER
Analytic (window) function: ROW_NUMBER.
Definition: SqlUtil.qm.dox.h:2426
addCustomCopOperator(string name, hash operator)
register custom user column operator for this table object
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
const DT_YEAR
Format unit: year.
Definition: SqlUtil.qm.dox.h:3503
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:5879
represents a primary key
Definition: SqlUtil.qm.dox.h:5966
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3774
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2259
hash< ColumnOperatorInfo > cop_prepend(auto column, string arg)
returns a ColumnOperatorInfo hash for the "prepend" operator with the given argument ...
*hash nest
option nested operation hash
Definition: SqlUtil.qm.dox.h:2145
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:2309
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:2166
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2193
*hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:5876
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:7854
deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromIterator() wrapper.
*hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
string qore_type
a qore type string that will be converted to a native DB type with some default conversion ...
Definition: SqlUtil.qm.dox.h:2101
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:7598
hash< UpdateOperatorInfo > make_uop(string uop, auto arg, *hash< UpdateOperatorInfo > nest)
returns an UpdateOperatorInfo hash
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4347
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5957
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:7723
hash< OperatorInfo > op_ceq(string arg)
returns an OperatorInfo hash for the "=" operator with the given argument for use in where clauses wh...
hash getInsertOperatorMap()
returns the insert operator map for this object
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5776
const DT_SECOND
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3518
abstract bool supportsTablespacesImpl()
returns True if the database support tablespaces
AbstractForeignConstraint removeForeignConstraint(string cname)
removes the named foreign constraint from the table; no SQL is executed in any case, only the named foreign constraint is removed from the table definition
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5734
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2244