Qore SqlUtil Module Reference  1.4.2
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  ...
386  @endcode
387  @warning Oracle: using different comments in the same SQL can lead to new optimizer statement hard parsing.
388 
389  @subsubsection select_option_hint Select Option "hint"
390  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).
391 
392  <b>Hint Example:</b>
393  @code{.py}
394 table.selectRows(("hint": "full(t1)"));
395  @endcode
396  will produce select statement like this:
397  @code{.py}
398 select /*+ full(a) */ ...
399  @endcode
400  The string is taken as-is and it's up to the caller to handle correct aliases in join functions etc.
401  @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
402  @warning Use hints only when you know what you are doing.
403 
404  @subsubsection select_option_columns Select Option "columns"
405  <b>Columns Example:</b>
406  @code{.py}
407 list columns = (
408  "id", "name", "started",
409  cop_as("warnings", "warning_count"),
410  cop_as("errors", "error_count"),
411 );
412 *list rows = table.selectRows(("columns": columns, "where": ("type": "user")));
413  @endcode
414  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
415  This option takes a list, each element of the list can be one of the following.\n\n
416  <b>A Simple String Giving a Column Name</b>\n
417  ex: \c "name"
418  @code{.py}
419 *list rows = table.selectRows(("columns": ("id", "name", "started")));
420  @endcode \n
421  <b>A String in Dot Notation</b>\n
422  This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
423  @code{.py}
424 hash sh = (
425  "columns": ("t1.id", "t2.customer_name"),
426  "join": join_inner(table2, "t2", ("id": "altid"))),
427  "alias": "t1",
428 );
429 *list rows = table.selectRows(sh);
430  @endcode \n
431  <b>A Column Operation Specified by a Column Operator Function</b>\n
432  ex: <tt>cop_as("column_name", "column_alias")</tt> \n
433  See @ref sql_cop_funcs "column operator function" for more information on column operator functions
434  @code{.py}
435 list columns = (
436  "id",
437  cop_as("warnings", "warning_count"),
438  cop_as("errors", "error_count"),
439 );
440 *list rows = table.selectRows(("columns": columns));
441  @endcode
442  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
443  <b>The Value \c "*", Meaning All Columns</b>\n
444  ex: \c "*"
445  @code{.py}
446 *list rows = table.selectRows(("columns": "*"));
447  @endcode
448  This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
449  <b>An \c "*" in Dot Notation</b>\n
450  ex: \c "q.*"
451  @code{.py}
452 hash sh = (
453  "columns": ("table.id", "t2.*"),
454  "join": join_inner(table2, "t2", ("id": "altid")),
455 );
456 *list rows = table.selectRows(sh);
457  @endcode
458 
459  @subsubsection select_option_where Select Option "where"
460  <b>Where Example:</b>
461  @code{.py}
462 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
463  @endcode
464  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.
465 
466  @subsubsection select_option_orderby Select Option "orderby"
467  <b>Orderby Example:</b>
468  @code{.py}
469 hash sh = (
470  "where": (
471  "account_type": "CUSTOMER",
472  ),
473  "orderby": "created_date",
474 );
475 *list rows = table.selectRows(sh);
476  @endcode
477  This option is a list of the following values:
478  - a simple string giving a column name; ex: \c "name"
479  - 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
480  - 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"
481  - a positive integer giving the column number for the ordering
482  @note
483  - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
484 
485  @subsubsection select_option_desc Select Option "desc"
486  <b>Desc Example:</b>
487  @code{.py}
488 hash sh = (
489  "where": (
490  "account_type": "CUSTOMER",
491  ),
492  "orderby": "created_date",
493  "desc": True,
494 );
495 *list rows = table.selectRows(sh);
496  @endcode
497  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
498  Otherwise, ordered results are returned in ascending order by default.
499 
500  @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"
501 
502  @subsubsection select_option_limit Select Option "limit"
503  <b>Limit Example:</b>
504  @code{.py}
505 hash sh = (
506  "where": ("type": "user"),
507  "limit": 100,
508  "offset": 200
509 );
510 *list rows = table.selectRows(sh);
511  @endcode
512  This option will limit the number of rows returned.
513  @note
514  - This option is required if the @ref select_option_offset "offset option" is non-zero
515  - 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
516 
517  @subsubsection select_option_offset Select Option "offset"
518  <b>Offset Example:</b>
519  @code{.py}
520 hash sh = (
521  "where": ("type": "user"),
522  "limit": 100,
523  "offset": 200
524 );
525 *list rows = table.selectRows(sh);
526  @endcode
527  This option specifies the row number offset for the rows returned where the first row is at offset zero.
528  @note
529  - 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.
530  - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
531  @see @ref sql_paging
532 
533  @subsubsection select_option_join Select Option "join"
534  <b>Join Example:</b>
535  @code{.py}
536 hash sh = (
537  "columns": (
538  "name", "version", "id",
539  cop_as("st.value", "source"),
540  cop_as("st.value", "offset"),
541  ),
542  "join": join_left(function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
543  + join_left(function_instance_tags, "lt", NOTHING, ("st.tag": "_offset")),
544 );
545 *list rows = table.selectRows(sh);
546  @endcode
547  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).
548  @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
549 
550  @see @ref joins for more examples
551 
552  @subsubsection select_option_groupby Select Option "groupby"
553  <b>Groupby Example:</b>
554  @code{.py}
555 hash sh = (
556  "columns": (
557  cop_as(cop_max("service_type"), "type"),
558  cop_count(),
559  ),
560  "groupby": "service_type",
561 );
562 *list rows = table.selectRows(sh);
563  @endcode
564  The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
565  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"
566  key are strings giving column names, optionally in dot notation or positive column numbers.
567 
568  @subsubsection select_option_having Select Option "having"
569  <b>Having Example:</b>
570  @code{.py}
571 hash sh = (
572  "columns": (
573  cop_as(cop_max("service_type"), "type"),
574  cop_count(),
575  ),
576  "groupby": "service_type",
577  "having": (
578  "service_type": (COP_COUNT, op_ge(100)),
579  ),
580 );
581 *list rows = table.selectRows(sh);
582  @endcode
583  The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
584  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.
585 
586  @subsubsection select_option_superquery Select Option "superquery"
587  <b>Superquery Example:</b>
588  @code{.py}
589 hash sh = (
590  "columns": (
591  "serviceid", "service_methodid",
592  cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid"),
593  ),
594  "superquery": (
595  "columns": ("serviceid", "service_methodid"),
596  "where": ("max_methodid": op_ceq("service_methodid")),
597  ),
598 );
599 *list rows = table.selectRows(sh);
600  @endcode
601  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
602  The above example results in an SQL command equivalent to the following:
603  @code{.py}
604 *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");
605  @endcode
606  @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
607 
608  @subsubsection select_option_forupdate Select Option "forupdate"
609  <b>For Update Example:</b>
610  @code{.py}
611 on_success ds.commit();
612 on_error ds.rollback();
613 
614 hash sh = (
615  "columns": ("serviceid", "service_methodid"),
616  "forupdate": True,
617 )
618 *list rows = table.selectRows(sh);
619  @endcode
620  \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.
621  The above example results in an SQL commit equivalent to the following:
622  @code{.py}
623 *list rows = table.vselectRows("select serviceid,service_methodid from schema.service_methods for update");
624  @endcode
625 
626  @subsection sql_paging Select With Paging
627 
628  There is support for paging query results in the following methods:
629  - @ref SqlUtil::AbstractTable::getRowIterator()
630  - @ref SqlUtil::AbstractTable::getSelectSql()
631  - @ref SqlUtil::AbstractTable::select()
632  - @ref SqlUtil::AbstractTable::selectRows()
633 
634  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
635 
636  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.
637 
638  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.
639 
640  @par Example:
641  Select 100 rows starting at row 200 (the table's primary key will be used for the \c "orderby" option by default): \n
642  @code{.py}
643 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
644  @endcode
645  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:
646  @code{.py}
647 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));
648  @endcode
649  And for PostgreSQL:
650  @code{.py}
651 ds.vselectRows("select * from public.table where type = %v order by type limit %v offset %v", ("user", 100, 200));
652  @endcode
653 
654  @subsection check_matching_rows Check For At Least One Matching Row
655 
656  Use the @ref SqlUtil::AbstractTable::findSingle() method to find at least one matching row:
657  @code{.py}
658 *hash h = table.findSingle(("account_type": "CUSTOMER"));
659 if (h)
660  printf("found 1 customer row: %y\n", l[0]);
661  @endcode
662 
663  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):
664  @code{.py}
665 *hash h = table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
666 if (h)
667  printf("found 1 customer row: %y\n", l[0]);
668  @endcode
669 
670  @section inserting_data Inserting Data into the Database
671 
672  The following methods can be used to insert data into the database:
673  - @ref SqlUtil::AbstractTable::insert(): inserts a single row into a table without committing the transaction
674  - @ref SqlUtil::AbstractTable::insertCommit(): inserts a single row into a table and commits the transaction
675  - @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
676  - @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
677 
678  @see @ref sql_upsert for information about upserting or merging data
679 
680  @subsection inserting_data_explicitly Inserting Data Explicitly
681 
682  @par Example:
683  @code{.py}
684 table.insert(("id": id, "name": name, "created": now_us()));
685  @endcode
686 
687  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.
688 
689  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.
690 
691  @subsection inserting_data_from_select Inserting Data From a Select Statement
692 
693  @par Example:
694  @code{.py}
695 int rows = table.insertFromSelect(("id", "name", "created"), source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER"))));
696  @endcode
697 
698  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.
699 
700  The example above would generate a %Qore SQL command like the following:
701  @code{.py}
702 return ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER"));
703  @endcode
704 
705  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.
706 
707  @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
708 
709  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:
710 
711  @par Example:
712  @code{.py}
713 # get the rows to be inserted
714 list l = get_table_rows();
715 # insert the data and commit after every 5000 rows
716 table.insertFromIterator(l.iterator(), ("commit_block": 5000));
717  @endcode
718 
719  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".
720 
721  @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
722 
723  @section updating_data Updating Data
724 
725  The following methods can be used to update data:
726  - @ref SqlUtil::AbstractTable::update(): updates a single row and does not commit the transaction
727  - @ref SqlUtil::AbstractTable::updateCommit(): updates a single row and commits the transaction
728 
729  @par Example:
730  @code{.py}
731 int rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
732  @endcode
733 
734  The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
735  @code{.py}
736 return ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
737  @endcode
738  And the following on MySQL:
739  @code{.py}
740 return ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
741  @endcode
742 
743  @section deleting_data Deleting Data
744 
745  The following methods can be used to dekete data:
746  - @ref SqlUtil::AbstractTable::del(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
747  - @ref SqlUtil::AbstractTable::delCommit(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
748  - @ref SqlUtil::AbstractTable::truncate(): truncates the table and does not commit the transaction
749  - @ref SqlUtil::AbstractTable::truncateCommit(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
750 
751  @par Example:
752  @code{.py}
753 int dcnt = table.del(("record_type": "OLD-CUSTOMER"));
754  @endcode
755 
756  The above example would generate a %Qore SQL command like the following:
757  @code{.py}
758 return ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
759  @endcode
760 
761  The @ref SqlUtil::AbstractTable::del() and @ref SqlUtil::AbstractTable::delCommit() methods can be used to delete data from the database.
762 
763  See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
764 
765  @section joins Joining Tables
766 
767  Joining tables is made by providing a join specification to the @ref select_option_join "join select option" in
768  a @ref select_option_hash "select option hash" as in the following example:
769  @code{.py}
770 *list rows = table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner(table2, "t2", ("id": "altid"))));
771  @endcode
772  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
773 
774  Joins on multiple tables are performed by combining the results of @ref sql_jop_funcs "join functions" with the @ref plus_operator "+ operator"
775  as follows:
776  @code{.py}
777 *list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner(table3, "t3")));
778  @endcode
779  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
780  automatically detected primary key to foreign key relationship between the two tables.
781 
782  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
783  argument to the @ref sql_jop_funcs "join function" as in the following example:
784  @code{.py}
785 *list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner("t2", table3, "t3")));
786  @endcode
787  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
788  with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
789 
790  @see @ref select_option_join "join select option"
791 
792  @section where_clauses Where Clauses
793 
794  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:
810 
811  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
812 
813  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:
814  - use the @ref SqlUtil::wop_or() function to combine where expressions with the \c "or" operator
815  - 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".
816 
817  The where condition hash has the following format:
818  - each key gives a column name or a table/alias with column name in dot notation
819  - 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
820 
821  @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
822 
823  See @ref sql_op_funcs for a list of operator functions.
824 
825  @par Where Hash Example:
826  @code{.py}
827 hash w = (
828  "name": "Smith",
829  "account_type": op_like("%CUSTOMER%"),
830  "id": op_ge(500),
831 );
832  @endcode \n
833  The preceding example results in a where clause equivalent to: \c "name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
834  that bind by value is used, so, if used in a context like the following:
835  @code{.py}
836 Table t(ds, "table");
837 *hash qh = t.select(("where": w));
838  @endcode \n
839  the complete query would look instead as follows:
840  @code{.py}
841 ds.vselect("select * from table where name = %v and account_type like %v and id >= %v", ("Smith", "%CUSTOMER%", 500));
842  @endcode
843 
844  @anchor where_list
845  @par Where List Example:
846  @code{.py}
847 hash w1 = (
848  "name": "Smith",
849  "account_type": op_like("%CUSTOMER%"),
850  "id": op_ge(500),
851 );
852 hash w2 = (
853  "name": "Jones",
854  "account_type": op_like("%VENDOR%"),
855  "id": op_ge(2500),
856 );
857 Table t(ds, "table");
858 *hash qh = t.select(("where": (w1, w2)));
859  @endcode \n
860  the complete query would look instead as follows:
861  @code{.py}
862 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));
863  @endcode
864 
865  @par Code Examples:
866  Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
867  @code{.py}
868 *hash row = table.findSingle(("permission_type": op_between("US", "UX")));
869  @endcode
870  resulting in an internal SQL command that looks as follows (depending on the database):
871  @code{.py}
872 *hash row = ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
873  @endcode \n
874  Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
875  @code{.py}
876 int row_count = table.del(("name": op_like("%Smith%")));
877  @endcode
878  resulting in an internal SQL command that looks as follows:
879  @code{.py}
880 ds.vexec("delete from table where name like %v", ("%Smith%"));
881  @endcode \n
882  Find all rows where \c "id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
883  @code{.py}
884 *list rows = table.findAll(("id": op_gt(100), "created": op_gt(2013-03-01)));
885  @endcode
886  resulting in an internal SQL command that looks as follows:
887  @code{.py}
888 ds.vexec("select * from table where id > %v and created > %v", (100, 2013-03-01));
889  @endcode \n
890 
891  @section sql_upsert Upserting or Merging Data
892 
893  This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
902 
903  @subsection sql_upsert_single Upsert a Single Row
904 
905  @par Example:
906  @code{.py}
907 table.upsert(("id": id, "name": name, "account_type": account_type));
908  @endcode
909 
910  To upsert or merge a single row in the database, call @ref SqlUtil::AbstractTable::upsert() or @ref SqlUtil::AbstractTable::upsertCommit() with the
911  single row to be upserted or merged as a hash as in the preceding example.
912 
913  @subsection sql_upsert_many Upserting Many Rows Using An Upsert Closure
914 
915  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.
916 
917  @par Simple Example:
918  @code{.py}
919 # get the rows to be inserted
920 list l = get_table_rows();
921 
922 if (l) {
923  code upsert = table.getUpsertClosure(l[0]);
924 
925  on_success ds.commit();
926  on_error ds.rollback();
927 
928  # loop through the reference data rows
929  map upsert($1), l;
930 }
931  @endcode
932 
933  @par Complex Example With Callbacks:
934  @code{.py}
935 # set the upsert strategy depending on the use case
936 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
937 
938 # hash summarizing changes
939 hash sh;
940 
941 # get the rows to be inserted
942 list l = get_table_rows();
943 
944 if (l) {
945  # get the upsert closure to use based on the first row to be inserted
946  code upsert = table.getUpsertClosure(l[0], upsert_strategy);
947 
948  on_success ds.commit();
949  on_error ds.rollback();
950 
951  # loop through the reference data rows
952  foreach hash h in (l) {
953  int code = upsert(h);
954  if (code == AbstractTable::UR_Unchanged)
955  continue;
956 
957  string change = AbstractTable::UpsertResultMap{code};
958  ++sh{change};
959 
960  if (!verbose) {
961  printf(".");
962  flush();
963  }
964  else if (verbose > 1)
965  printf("*** reference data %s: %y: %s\n", table.getName(), h, change);
966  }
967 
968  # show table summary
969  if (sh)
970  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
971  else
972  printf("*** reference data %s: OK\n", table.getName());
973 }
974  @endcode
975 
976  @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
977 
978  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:
979 
980  @par Simple Example:
981  @code{.py}
982 # get the rows to be inserted
983 list l = get_table_rows();
984 table.upsertFromIterator(l.iterator());
985  @endcode
986 
987  @par Complex Example With Callbacks:
988  @code{.py}
989 # set the upsert strategy depending on the use case
990 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
991 
992 # get the rows to be inserted
993 list l = get_table_rows();
994 
995 code callback = sub (string table_name, hash row, int result) {
996  if (result == AbstractTable::UR_Unchanged)
997  return;
998  string change = AbstractTable::UpsertResultMap{result};
999  if (verbose)
1000  printf("*** reference data %s: %y: %s\n", table_name, row, change);
1001 };
1002 
1003 hash sh = table.upsertFromIterator(l.iterator(), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
1004 if (sh)
1005  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
1006 else
1007  printf("*** reference data %s: OK\n", table.getName());
1008  @endcode
1009 
1010  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".
1011 
1012  @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
1013 
1014  @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
1015 
1016  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:
1017 
1018  @par Simple Example:
1019  @code{.py}
1020 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")));
1021  @endcode
1022 
1023  @par Complex Example With Callbacks:
1024  @code{.py}
1025 # set the upsert strategy depending on the use case
1026 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
1027 
1028 code callback = sub (string table_name, hash row, int result) {
1029  if (result == AbstractTable::UR_Unchanged)
1030  return;
1031  string change = AbstractTable::UpsertResultMap{result};
1032  if (verbose)
1033  printf("*** reference data %s: %y: %s\n", table_name, row, change);
1034 };
1035 
1036 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
1037 if (sh)
1038  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
1039 else
1040  printf("*** reference data %s: OK\n", table.getName());
1041  @endcode
1042 
1043  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).
1044 
1045  @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
1046 
1047  @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
1048 
1049  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.
1050 
1051  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.
1052 
1053  @par Simple Example:
1054  @code{.py}
1055 # get the rows to be inserted
1056 list l = get_table_rows();
1057 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
1058  @endcode
1059 
1060  @par Complex Example With Callbacks:
1061  @code{.py}
1062 # set the upsert strategy depending on the use case
1063 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
1064 
1065 # get the rows to be inserted
1066 list l = get_table_rows();
1067 
1068 code callback = sub (string table_name, hash row, int result) {
1069  if (result == AbstractTable::UR_Unchanged)
1070  return;
1071  string change = AbstractTable::UpsertResultMap{result};
1072  if (verbose)
1073  printf("*** reference data %s: %y: %s\n", table_name, row, change);
1074 };
1075 
1076 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, ("delete_others": True, "info_callback": callback, "commit_block": 5000));
1077 if (sh)
1078  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
1079 else
1080  printf("*** reference data %s: OK\n", table.getName());
1081  @endcode
1082 
1083  @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
1084 
1085  @subsection sql_upsert_strategies Upsert Strategies
1086  The approach used is based on one of the following strategies (see @ref upsert_options):
1087  - @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
1088  - @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
1089  - @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
1090  - @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
1091  - @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
1092  - @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
1093 
1094  @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.
1095 */
2078 namespace SqlUtil {
2081  public struct GenericColumnInfo {
2083  string qore_type;
2085  string native_type;
2087  softint size;
2089  softint scale;
2093  bool default_value_native = False;
2095  *string comment;
2097  bool notnull = False;
2099  hash<string, hash> driver;
2102  };
2103 
2105  public struct OperatorInfo {
2106  string op;
2107  any arg;
2108  };
2109 
2111  public struct ColumnOperatorInfo {
2112  string cop;
2113  any column;
2114  any arg;
2115  };
2116 
2118  public struct InsertOperatorInfo {
2119  string _iop;
2120  any arg;
2121  };
2122 
2124  public struct UpdateOperatorInfo {
2125  string uop;
2126  any arg;
2128  };
2129 
2131  public struct JoinOperatorInfo {
2132  string jop;
2133  any table;
2134  *string alias;
2137  *string ta;
2139  };
2140 
2141  /* @defgroup DBFeaturesConstants DB Features Constants
2142  These constants can be used as a lookup values in AbstractDatabase::features() method.
2143  */
2145 
2148  const DB_FUNCTIONS = "functions";
2150  const DB_MVIEWS = "materialized views";
2152  const DB_PACKAGES = "packages";
2154  const DB_PROCEDURES = "procedures";
2156  const DB_SEQUENCES = "sequences";
2158  const DB_TABLES = "tables";
2160  const DB_TYPES = "named types";
2162  const DB_VIEWS = "views";
2164  const DB_SYNONYMS = "synonyms";
2166 
2167  /* @defgroup SqlTypeConstants SQL Type Constants
2168  These constants can be used for the \c "qore_type" values when creating columns to specify additional SQL column types
2169  */
2171  const VARCHAR = "string";
2173 
2175  const NUMERIC = "number";
2176 
2178  const CHAR = "char";
2179 
2181  const BLOB = "blob";
2182 
2184  const CLOB = "clob";
2186 
2191  const SZ_NONE = 0;
2193 
2195  const SZ_MAND = 1;
2196 
2198  const SZ_OPT = 2;
2199 
2201  const SZ_NUM = 3;
2203 
2208 
2211  const COP_AS = "as";
2212 
2214 
2216  const COP_CAST = "cast";
2217 
2219 
2221  const COP_PREPEND = "prepend";
2222 
2224 
2226  const COP_APPEND = "append";
2227 
2229 
2231  const COP_VALUE = "value";
2232 
2234 
2236  const COP_UPPER = "upper";
2237 
2239 
2241  const COP_LOWER = "lower";
2242 
2244 
2246  const COP_DISTINCT = "distinct";
2247 
2249 
2251  const COP_MIN = "min";
2252 
2254 
2256  const COP_MAX = "max";
2257 
2259 
2261  const COP_AVG = "avg";
2262 
2264 
2266  const COP_SUM = "sum";
2267 
2269 
2271  const COP_COUNT = "count";
2272 
2274 
2276  const COP_OVER = "over";
2277 
2279 
2281  const COP_MINUS = "minus";
2282 
2284 
2286  const COP_PLUS = "plus";
2287 
2289 
2291  const COP_DIVIDE = "divide";
2292 
2294 
2296  const COP_MULTIPLY = "multiply";
2297 
2299 
2301  const COP_YEAR = "year";
2302 
2304 
2306  const COP_YEAR_MONTH = "year_month";
2307 
2309 
2311  const COP_YEAR_DAY = "year_day";
2312 
2314 
2316  const COP_YEAR_HOUR = "year_hour";
2317 
2319 
2321  const COP_SEQ = "seq";
2322 
2324 
2326  const COP_SEQ_CURRVAL = "seq_currval";
2327 
2329 
2331  const COP_COALESCE = "coalesce";
2332 
2334 
2336  const COP_SUBSTR = "substr";
2337 
2339 
2343  const COP_LENGTH = "length";
2344 
2346 
2352  const COP_TRUNC_DATE = "truncate_date";
2353 
2355 
2359  const COP_CUME_DIST = "cume_dist";
2360 
2362 
2366  const COP_DENSE_RANK = "dense_rank";
2367 
2369 
2373  const COP_FIRST_VALUE = "first_value";
2374 
2376 
2380  const COP_LAST_VALUE = "last_value";
2381 
2383 
2387  const COP_NTILE = "ntile";
2388 
2390 
2394  const COP_PERCENT_RANK = "percent_rank";
2395 
2397 
2401  const COP_RANK = "rank";
2402 
2404 
2408  const COP_ROW_NUMBER = "row_number";
2409 
2410 
2412  const DefaultCopMap = (
2413  COP_AS: (
2414  "arg": Type::String,
2415  "withalias": True,
2416  "code": string (string cve, string arg, reference psch) {
2417  // issue #2163: make sure the unquoted alias is inserted in the map
2418  if (arg ==1)
2419  psch{arg.substr(1, -1)} = cve;
2420  else
2421  psch{arg} = cve;
2422  return sprintf("%s as %s", cve, arg);
2423  },
2424  ),
2425  COP_PREPEND: (
2426  "arg": Type::String,
2427  "sqlvalue": True,
2428  "code": string (string cve, string arg) {
2429  return sprintf("%s || %s", arg, cve);
2430  },
2431  ),
2432  COP_APPEND: (
2433  "arg": Type::String,
2434  "sqlvalue": True,
2435  "code": string (string cve, string arg) {
2436  return sprintf("%s || %s", cve, arg);
2437  },
2438  ),
2439  COP_VALUE: (
2440  "sqlvalue": True,
2441  "nocolumn": True,
2442  "code": string (*string cve, auto arg) {
2443  return arg;
2444  },
2445  ),
2446  COP_UPPER: (
2447  "code": string (string cve, auto arg) {
2448  return sprintf("upper(%s)", cve);
2449  },
2450  ),
2451  COP_LOWER: (
2452  "code": string (string cve, auto arg) {
2453  return sprintf("lower(%s)", cve);
2454  },
2455  ),
2456  COP_DISTINCT: (
2457  "code": string (string cve, auto arg) {
2458  return sprintf("distinct %s", cve);
2459  },
2460  ),
2461  COP_MIN: (
2462  "code": string (string cve, auto arg) {
2463  return sprintf("min(%s)", cve);
2464  },
2465  "group": True,
2466  ),
2467  COP_MAX: (
2468  "code": string (string cve, auto arg) {
2469  return sprintf("max(%s)", cve);
2470  },
2471  "group": True,
2472  ),
2473  COP_AVG: (
2474  "code": string (string cve, auto arg) {
2475  return sprintf("avg(%s)", cve);
2476  },
2477  "group": True,
2478  ),
2479  COP_SUM: (
2480  "code": string (string cve, auto arg) {
2481  return sprintf("sum(%s)", cve);
2482  },
2483  "group": True,
2484  ),
2485  COP_COUNT: (
2486  "nocolumn": True,
2487  "code": string (*string cve, auto arg) {
2488  return sprintf("count(%s)", cve ? cve : "*");
2489  },
2490  ),
2491  COP_MINUS: (
2492  "argcolumn": True,
2493  "code": string (string arg1, string arg2) {
2494  return sprintf("%s - %s", arg1, arg2);
2495  },
2496  ),
2497  COP_PLUS: (
2498  "argcolumn": True,
2499  "code": string (string arg1, string arg2) {
2500  return sprintf("%s + %s", arg1, arg2);
2501  },
2502  ),
2503  COP_DIVIDE: (
2504  "argcolumn": True,
2505  "code": string (string arg1, string arg2) {
2506  return sprintf("%s / %s", arg1, arg2);
2507  },
2508  ),
2509  COP_MULTIPLY: (
2510  "argcolumn": True,
2511  "code": string (string arg1, string arg2) {
2512  return sprintf("%s * %s", arg1, arg2);
2513  },
2514  ),
2515  COP_SEQ: (
2516  "nocolumn": True,
2517  "code": string (*string cve, hash arg) {
2518  throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg.seq);
2519  }
2520  ),
2521  COP_SEQ_CURRVAL: (
2522  "nocolumn": True,
2523  "code": string (*string cve, hash arg) {
2524  throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg.seq);
2525  }
2526  ),
2527  COP_COALESCE: (
2528  "columnargs": True,
2529  "code": string (*string cve, hash arg) {
2530  return sprintf("coalesce(%s)", (foldl $1 + "," + $2, arg.args));
2531  }
2532  ),
2533  COP_SUBSTR: (
2534  "code": string (string cve, list args) {
2535  if (!exists args[1])
2536  return sprintf("substring(%s from %d)", cve, args[0]);
2537  return sprintf("substring(%s from %d for %d)", cve, args[0], args[1]);
2538  },
2539  ),
2540  COP_LENGTH: (
2541  "code": string (string cve, auto arg) {
2542  return sprintf("length(%s)", cve);
2543  },
2544  ),
2545  COP_OVER: (
2546  "columnargs" : True,
2547  "columnargs_ignore_nothings" : True,
2548  "code": string (*string cve, hash args)
2549  {
2550  *string partitionby = args.args[0];
2551  *string orderby = args.args[1];
2552  if (!exists partitionby && exists orderby);
2553 
2554  string sql = cve + " over (";
2555  if (exists partitionby)
2556  sql += sprintf("partition by %s", partitionby); // TODO/FIXME: sql injection!
2557  if (exists orderby)
2558  sql += sprintf(" order by %s", orderby); // TODO/FIXME: sql injection!
2559  sql += ")";
2560  return sql;
2561  },
2562  ),
2563  COP_CUME_DIST: (
2564  "nocolumn": True,
2565  "code": string (*string cve, any arg) {
2566  return "cume_dist()";
2567  },
2568  ),
2569  COP_DENSE_RANK: (
2570  "nocolumn": True,
2571  "code": string (*string cve, any arg) {
2572  return "dense_rank()";
2573  },
2574  ),
2575  COP_FIRST_VALUE: (
2576  "code": string (string cve) {
2577  return sprintf("first_value(%s)", cve);
2578  },
2579  ),
2580  COP_LAST_VALUE: (
2581  "code": string (string cve) {
2582  return sprintf("last_value(%s)", cve);
2583  },
2584  ),
2585  COP_NTILE: (
2586  "sqlvalue": True,
2587  "nocolumn": True,
2588  "code": string (*string cve, any arg) {
2589  return sprintf("ntile(%d)", arg);
2590  },
2591  ),
2592  COP_PERCENT_RANK: (
2593  "nocolumn": True,
2594  "code": string (*string cve, any arg) {
2595  return "percent_rank()";
2596  },
2597  ),
2598  COP_RANK: (
2599  "nocolumn": True,
2600  "code": string (*string cve, any arg) {
2601  return "rank()";
2602  },
2603  ),
2604  COP_ROW_NUMBER: (
2605  "nocolumn": True,
2606  "code": string (*string cve, any arg) {
2607  return "row_number()";
2608  },
2609  ),
2610  );
2612 
2654 
2663  hash<ColumnOperatorInfo> make_cop(string cop, auto column, auto arg);
2664 
2665 
2667 
2679  hash<ColumnOperatorInfo> cop_as(auto column, string arg);
2680 
2681 
2683 
2697  hash<ColumnOperatorInfo> cop_cast(auto column, string arg, auto arg1, auto arg2);
2698 
2699 
2701 
2711  hash<ColumnOperatorInfo> cop_prepend(auto column, string arg);
2712 
2713 
2715 
2725  hash<ColumnOperatorInfo> cop_append(auto column, string arg);
2726 
2727 
2729 
2857  hash<ColumnOperatorInfo> cop_value(auto arg);
2858 
2859 
2861 
2870  hash<ColumnOperatorInfo> cop_upper(auto column);
2871 
2872 
2874 
2883  hash<ColumnOperatorInfo> cop_lower(auto column);
2884 
2885 
2887 
2896  hash<ColumnOperatorInfo> cop_distinct(auto column);
2897 
2898 
2900 
2909  hash<ColumnOperatorInfo> cop_min(auto column);
2910 
2911 
2913 
2922  hash<ColumnOperatorInfo> cop_max(auto column);
2923 
2924 
2926 
2935  hash<ColumnOperatorInfo> cop_avg(auto column);
2936 
2937 
2939 
2948  hash<ColumnOperatorInfo> cop_sum(auto column);
2949 
2950 
2952 
2959  hash<ColumnOperatorInfo> cop_count(auto column = "");
2960 
2961 
2963 
2970  hash<ColumnOperatorInfo> cop_over(auto column, *string partitionby, *string orderby);
2971 
2972 
2974 
2984  hash<ColumnOperatorInfo> cop_minus(auto column1, auto column2);
2985 
2986 
2988 
2998  hash<ColumnOperatorInfo> cop_plus(auto column1, auto column2);
2999 
3000 
3002 
3012  hash<ColumnOperatorInfo> cop_divide(auto column1, auto column2);
3013 
3014 
3016 
3026  hash<ColumnOperatorInfo> cop_multiply(auto column1, auto column2);
3027 
3028 
3030 
3039  hash<ColumnOperatorInfo> cop_year(auto column);
3040 
3041 
3043 
3052  hash<ColumnOperatorInfo> cop_year_month(auto column);
3053 
3054 
3056 
3065  hash<ColumnOperatorInfo> cop_year_day(auto column);
3066 
3067 
3069 
3078  hash<ColumnOperatorInfo> cop_year_hour(auto column);
3079 
3080 
3082 
3092  hash<ColumnOperatorInfo> cop_seq(string seq, *string as);
3093 
3094 
3096 
3106  hash<ColumnOperatorInfo> cop_seq_currval(string seq, *string as);
3107 
3108 
3110 
3122  hash<ColumnOperatorInfo> cop_coalesce(auto col1, auto col2);
3123 
3124 
3126 
3137  hash<ColumnOperatorInfo> cop_substr(auto column, int start, *int count);
3138 
3139 
3141 
3152  hash<ColumnOperatorInfo> cop_length(auto column);
3153 
3154 
3156 
3170  hash<ColumnOperatorInfo> cop_trunc_date(auto column, string mask);
3171 
3172 
3173 
3175 
3203  hash<ColumnOperatorInfo> cop_cume_dist();
3204 
3205 
3207 
3235  hash<ColumnOperatorInfo> cop_dense_rank();
3236 
3237 
3239 
3267  hash<ColumnOperatorInfo> cop_first_value(any column);
3268 
3269 
3271 
3299  hash<ColumnOperatorInfo> cop_last_value(any column);
3300 
3301 
3303 
3333  hash<ColumnOperatorInfo> cop_ntile(int value);
3334 
3335 
3337 
3365  hash<ColumnOperatorInfo> cop_percent_rank();
3366 
3367 
3369 
3397  hash<ColumnOperatorInfo> cop_rank();
3398 
3399 
3401 
3429  hash<ColumnOperatorInfo> cop_row_number();
3430 
3431 
3433 
3484  const DT_YEAR = "Y";
3486 
3488  const DT_MONTH = "M";
3489 
3491  const DT_DAY = "D";
3492 
3494  const DT_HOUR = "H";
3495 
3497  const DT_MINUTE = "m";
3498 
3500  const DT_SECOND = "S";
3501 
3502  // let's simulate and enum here'
3503  const DT_ALL_VALUES = ( DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND );
3505 
3510  const DefaultUopMap = (
3512  COP_PREPEND: True,
3513  COP_APPEND: True,
3514  COP_UPPER: True,
3515  COP_LOWER: True,
3516  COP_MINUS: (
3517  "sqlvalue": True,
3518  "code": string (string cve, auto arg) {
3519  return sprintf("%s - %s", cve, arg);
3520  },
3521  ),
3522  COP_PLUS: (
3523  "sqlvalue": True,
3524  "code": string (string cve, auto arg) {
3525  return sprintf("%s + %s", cve, arg);
3526  },
3527  ),
3528  COP_DIVIDE: (
3529  "sqlvalue": True,
3530  "code": string (string cve, auto arg) {
3531  return sprintf("%s / %s", cve, arg);
3532  },
3533  ),
3534  COP_MULTIPLY: (
3535  "sqlvalue": True,
3536  "code": string (string cve, auto arg) {
3537  return sprintf("%s * %s", cve, arg);
3538  },
3539  ),
3540  COP_SUBSTR: True,
3541  COP_SEQ: (
3542  "nocolumn": True,
3543  "code": string (*string cve, string arg) {
3544  throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg);
3545  }
3546  ),
3547  COP_SEQ_CURRVAL: (
3548  "nocolumn": True,
3549  "code": string (*string cve, string arg) {
3550  throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg);
3551  }
3552  ),
3553  COP_COALESCE: (
3554  "columnargs": True,
3555  "code": string (*string cve, softlist args) {
3556  return sprintf("coalesce(%s)", (foldl $1 + "," + $2, args));
3557  }
3558  ),
3559  );
3561 
3583 
3592  hash<UpdateOperatorInfo> make_uop(string uop, auto arg, *hash<UpdateOperatorInfo> nest);
3593 
3594 
3596 
3606  hash<UpdateOperatorInfo> uop_prepend(string arg, *hash<UpdateOperatorInfo> nest);
3607 
3608 
3610 
3620  hash<UpdateOperatorInfo> uop_append(string arg, *hash<UpdateOperatorInfo> nest);
3621 
3622 
3624 
3633  hash<UpdateOperatorInfo> uop_upper(*hash<UpdateOperatorInfo> nest);
3634 
3635 
3637 
3646  hash<UpdateOperatorInfo> uop_lower(*hash<UpdateOperatorInfo> nest);
3647 
3648 
3650 
3661  hash<UpdateOperatorInfo> uop_substr(int start, *int count, *hash<UpdateOperatorInfo> nest);
3662 
3663 
3665 
3675  hash<UpdateOperatorInfo> uop_plus(auto arg, *hash<UpdateOperatorInfo> nest);
3676 
3677 
3679 
3689  hash<UpdateOperatorInfo> uop_minus(auto arg, *hash<UpdateOperatorInfo> nest);
3690 
3691 
3693 
3703  hash<UpdateOperatorInfo> uop_multiply(auto arg, *hash<UpdateOperatorInfo> nest);
3704 
3705 
3707 
3717  hash<UpdateOperatorInfo> uop_divide(auto arg, *hash<UpdateOperatorInfo> nest);
3718 
3719 
3721 
3730  hash<UpdateOperatorInfo> uop_seq(string seq);
3731 
3732 
3734 
3743  hash<UpdateOperatorInfo> uop_seq_currval(string seq);
3744 
3746 
3753 
3756  const JOP_INNER = "inner";
3757 
3759 
3761  const JOP_LEFT = "left";
3762 
3764 
3766  const JOP_RIGHT = "right";
3767 
3769  const JopMap = (
3770  JOP_INNER: "inner",
3771  JOP_LEFT: "left outer",
3772  JOP_RIGHT: "right outer",
3773  );
3775 
3785 
3789  hash<string, hash<JoinOperatorInfo>> make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
3790 
3791 
3793 
3797  hash<string, hash<JoinOperatorInfo>> make_jop(string jop, string table_name, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
3798 
3799 
3801 
3820  hash<string, hash<JoinOperatorInfo>> join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3821 
3822 
3824 
3843  hash<string, hash<JoinOperatorInfo>> join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3844 
3845 
3847 
3866  hash<string, hash<JoinOperatorInfo>> join_inner(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3867 
3868 
3870 
3892  hash<string, hash<JoinOperatorInfo>> join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3893 
3894 
3896 
3916  hash<string, hash<JoinOperatorInfo>> join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3917 
3918 
3920 
3942  hash<string, hash<JoinOperatorInfo>> join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3943 
3944 
3946 
3965  hash<string, hash<JoinOperatorInfo>> join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3966 
3967 
3969 
3988  hash<string, hash<JoinOperatorInfo>> join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3989 
3990 
3992 
4013  hash<string, hash<JoinOperatorInfo>> join_left(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4014 
4015 
4017 
4037  hash<string, hash<JoinOperatorInfo>> join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
4038 
4039 
4041 
4061  hash<string, hash<JoinOperatorInfo>> join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
4062 
4063 
4065 
4087  hash<string, hash<JoinOperatorInfo>> join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4088 
4089 
4091 
4110  hash<string, hash<JoinOperatorInfo>> join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
4111 
4112 
4114 
4133  hash<string, hash<JoinOperatorInfo>> join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
4134 
4135 
4137 
4158  hash<string, hash<JoinOperatorInfo>> join_right(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4159 
4160 
4162 
4182  hash<string, hash<JoinOperatorInfo>> join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
4183 
4184 
4186 
4206  hash<string, hash<JoinOperatorInfo>> join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
4207 
4208 
4210 
4232  hash<string, hash<JoinOperatorInfo>> join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
4233 
4235 
4240 
4243  const OP_LIKE = "like";
4244 
4246 
4248  const OP_LT = "<";
4249 
4251 
4253  const OP_LE = "<=";
4254 
4256 
4258  const OP_GT = ">";
4259 
4261 
4263  const OP_GE = ">=";
4264 
4266 
4268  const OP_NE = "!=";
4269 
4271 
4273  const OP_EQ = "=";
4274 
4276 
4278  const OP_CLT = "C<";
4279 
4281 
4283  const OP_CLE = "C<=";
4284 
4286 
4288  const OP_CGT = "C>";
4289 
4291 
4293  const OP_CGE = "C>=";
4294 
4296 
4298  const OP_CNE = "C!=";
4299 
4301 
4303  const OP_CEQ = "C=";
4304 
4306 
4308  const OP_BETWEEN = "between";
4309 
4311 
4313  const OP_IN = "in";
4314 
4316 
4318  const OP_NOT = "not";
4319 
4321 
4323  const OP_SUBSTR = "substr";
4324 
4326  const OP_OR = "or";
4327 
4329  const DefaultOpMap = (
4330  OP_LIKE: (
4331  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4332  args += arg;
4333  return sprintf("%s like %v", cn);
4334  },
4335  ),
4336  OP_LT: (
4337  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4338  args += arg;
4339  return sprintf("%s < %v", cn);
4340  },
4341  ),
4342  OP_LE: (
4343  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4344  args += arg;
4345  return sprintf("%s <= %v", cn);
4346  },
4347  ),
4348  OP_GT: (
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 > %v", cn);
4352  },
4353  ),
4354  OP_GE: (
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_NE: (
4361  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4362  if (arg === NULL || !exists arg)
4363  return sprintf("%s is not null", cn);
4364  args += arg;
4365  return sprintf("(%s != %v or %s is null)", cn, cn);
4366  },
4367  ),
4368  OP_EQ: (
4369  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4370  if (arg === NULL || !exists arg)
4371  return sprintf("%s is null", cn);
4372  args += arg;
4373  return sprintf("%s = %v", cn);
4374  },
4375  ),
4376  OP_BETWEEN: (
4377  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4378  args += arg[0];
4379  args += arg[1];
4380  return sprintf("%s between %v and %v", cn);
4381  },
4382  ),
4383  OP_IN: (
4384  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4385  *string ins = (foldl $1 + "," + $2, (map t.getSqlValue($1), arg));
4386  return exists ins ? sprintf("%s in (%s)", cn, ins) : "1 != 1";
4387  },
4388  ),
4389  OP_NOT: (
4390  "recursive": True,
4391  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4392  return sprintf("not (%s)", cn);
4393  },
4394  ),
4395  OP_CLT: (
4396  "argcolumn": True,
4397  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4398  return sprintf("%s < %s", cn, arg);
4399  },
4400  ),
4401  OP_CLE: (
4402  "argcolumn": True,
4403  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4404  return sprintf("%s <= %s", cn, arg);
4405  },
4406  ),
4407  OP_CGT: (
4408  "argcolumn": 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("%s > %s", cn, arg);
4411  },
4412  ),
4413  OP_CGE: (
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_CNE: (
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_CEQ: (
4426  "argcolumn": True,
4427  "code": string (object t, string cn, string arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4428  return sprintf("%s = %s", cn, arg);
4429  },
4430  ),
4431  OP_SUBSTR: (
4432  "code": string (object t, string cn, auto arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4433  args += arg[0]; // start
4434  if (!exists arg[1]);
4435 
4436  args += arg[1]; // count
4437  args += arg[2]; // text
4438  return sprintf("substring(%s from %v for %v) = %v", cn);
4439  },
4440  ),
4441  OP_OR: (
4442  "code": string (object t, string cn, list arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch) {
4443  return t.getOrClause(arg, \args, jch, join, ch, psch);
4444  },
4445  ),
4446  );
4448 
4471  hash<OperatorInfo> make_op(string op, auto arg);
4473 
4474 
4476 
4485  hash<OperatorInfo> op_like(string str);
4486 
4487 
4489 
4500  hash<OperatorInfo> op_lt(auto arg);
4501 
4502 
4504 
4515  hash<OperatorInfo> op_le(auto arg);
4516 
4517 
4519 
4530  hash<OperatorInfo> op_gt(auto arg);
4531 
4532 
4534 
4545  hash<OperatorInfo> op_ge(auto arg);
4546 
4547 
4549 
4562  hash<OperatorInfo> op_ne(auto arg);
4563 
4564 
4566 
4579  hash<OperatorInfo> op_eq(auto arg);
4580 
4581 
4583 
4595  hash<OperatorInfo> op_between(auto l, auto r);
4596 
4597 
4599 
4608  hash<OperatorInfo> op_in();
4609 
4610 
4612 
4623  hash<OperatorInfo> op_in(list args);
4624 
4625 
4627 
4634  hash<OperatorInfo> op_not(hash arg);
4635 
4636 
4638 
4649  hash<OperatorInfo> op_clt(string arg);
4650 
4651 
4653 
4664  hash<OperatorInfo> op_cle(string arg);
4665 
4666 
4668 
4679  hash<OperatorInfo> op_cgt(string arg);
4680 
4681 
4683 
4694  hash<OperatorInfo> op_cge(string arg);
4695 
4696 
4698 
4709  hash<OperatorInfo> op_cne(string arg);
4710 
4711 
4713 
4724  hash<OperatorInfo> op_ceq(string arg);
4725 
4726 
4728 
4739  hash<OperatorInfo> op_substr(int start, *int count, string text);
4740 
4741 
4743 
4753  hash<OperatorInfo> op_substr(int start, string text);
4754 
4755 
4757 
4774  hash<string, hash<OperatorInfo>> wop_or(hash h1, hash h2);
4775 
4777 
4784 
4787  const IOP_SEQ = "seq";
4788 
4790 
4792  const IOP_SEQ_CURRVAL = "seq_currval";
4793 
4795  const DefaultIopMap = {};
4797 
4803 
4811  hash<InsertOperatorInfo> make_iop(string iop, auto arg);
4812 
4813 
4815 
4824  hash<InsertOperatorInfo> iop_seq(string arg);
4825 
4826 
4828 
4837  hash<InsertOperatorInfo> iop_seq_currval(string arg);
4838 
4840 
4842  const SqlUtilDrivers = (
4843  "oracle",
4844  "pgsql",
4845  "mysql",
4846  "freetds",
4847  "sybase",
4848  );
4849 
4852 
4853 public:
4854 private:
4855 
4856 public:
4857 
4858  private :
4859  *hash h;
4860 
4861 public:
4862 
4864  constructor(*hash nh);
4865 
4866 
4869 
4870 
4873 
4874 
4876 
4891  auto memberGate(string k);
4892 
4893 
4895 
4901  clear();
4902 
4903 
4905  abstract auto take(string k);
4906 
4908  renameKey(string old_name, string new_name);
4909 
4910 
4912  *hash getHash();
4913 
4914 
4916 
4925  bool matchKeys(hash h1);
4926 
4927 
4929 
4938  bool matchKeys(list l);
4939 
4940 
4942 
4951  bool matchKeys(AbstractHashContainer c);
4952 
4953 
4955 
4964  bool partialMatchKeys(hash h1);
4965 
4966 
4968 
4977  bool partialMatchKeys(list l);
4978 
4979 
4981 
4990  bool partialMatchKeys(AbstractHashContainer c);
4991 
4992 
4994 
5003  bool val();
5004 
5005 
5007 
5014  list<string> keys();
5015 
5016 
5018 
5025  list values();
5026 
5027 
5029 
5036  Qore::AbstractIterator iterator();
5037 
5038 
5040 
5047  Qore::AbstractIterator keyIterator();
5048 
5049 
5051 
5058  Qore::AbstractIterator pairIterator();
5059 
5060 
5062  bool empty();
5063 
5064 
5066 
5073  int size();
5074 
5075 
5077 
5086  bool hasKey(string k);
5087 
5088 
5090 
5099  bool hasKeyValue(string k);
5100 
5101 
5103 
5112  *string firstKey();
5113 
5114 
5116 
5125  *string lastKey();
5126 
5127 
5129  abstract string getElementName();
5130  };
5131 
5134 
5135 public:
5136 private:
5137 
5138 public:
5139 
5140  private :
5141  softlist l;
5142 
5143 public:
5144 
5146  constructor(softlist nl);
5147 
5148 
5150 
5161  abstract auto get(softint i);
5162 
5164  add(auto val);
5165 
5166 
5168  auto take(int i);
5169 
5170 
5172  list getList();
5173 
5174 
5176 
5185  bool val();
5186 
5187 
5189 
5196  Qore::ListIterator iterator();
5197 
5198 
5200  bool empty();
5201 
5202 
5204 
5211  int size();
5212 
5213 
5215  abstract string getElementName();
5216 
5217 
5218 private:
5219  checkIndex(int i);
5220 public:
5221 
5222  };
5223 
5226 
5227 public:
5229  constructor();
5230 
5231 
5233  constructor(AbstractDatasource ds, hash tables, *hash opt);
5234 
5235 
5237  constructor(AbstractDatasource ds);
5238 
5239 
5241  add(string k, Table val);
5242 
5243 
5245  add(string k, AbstractTable val);
5246 
5247 
5249  add(Table val);
5250 
5251 
5253  add(AbstractTable val);
5254 
5255 
5257  AbstractTable take(string k);
5258 
5259 
5261  populate(AbstractDatasource ds, hash tables, *hash opt);
5262 
5263 
5265  populate(AbstractDatasource ds);
5266 
5267 
5269 
5283  *list getDropAllForeignConstraintsOnTableSql(string name, *hash opt);
5284 
5285 
5287 
5302  AbstractTable memberGate(string k);
5303 
5304 
5306  string getElementName();
5307 
5308 
5310  *AbstractTable getIfExists(AbstractDatasource ds, string name);
5311 
5312 
5314  AbstractTable get(AbstractDatasource ds, string name);
5315 
5316 
5318 
5333  *string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts);
5334 
5335 
5337 
5348  bool tableRenamed(string old_name, string new_name, string old_sql_name);
5349 
5350 
5351 
5352 private:
5353  tableRenamedIntern(string old_name, string new_name, string oldsn);
5354 public:
5355 
5356 
5358 
5373  *string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
5374 
5375 
5376  list getCreateList();
5377 
5378 
5379  Qore::AbstractIterator createIterator();
5380 
5381 
5383 
5391  list getDropList();
5392 
5393 
5395 
5402  Qore::AbstractIterator dropIterator();
5403 
5404 
5405 
5406 private:
5407  getDependencies(reference<hash> tdh, reference<hash> sdh, *reference<hash> th);
5408 public:
5409 
5410  };
5411 
5414 
5415 public:
5417  constructor(*hash c) ;
5418 
5419 
5421  constructor(Columns old) ;
5422 
5423 
5425  add(string k, AbstractColumn val);
5426 
5427 
5429  AbstractColumn take(string k);
5430 
5431 
5433 
5448  AbstractColumn memberGate(string k);
5449 
5450 
5452  Columns subset(softlist l);
5453 
5454 
5456  string getElementName();
5457 
5458 
5460  bool equal(Columns cols);
5461 
5462  };
5463 
5466 
5467 public:
5468  public :
5470  string name;
5471 
5473  string native_type;
5474 
5476  *string qore_type;
5477 
5479  int size;
5480 
5482  bool nullable;
5483 
5485  *string def_val;
5486 
5488  *string comment;
5489 
5490 public:
5491 
5492  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string c);
5493 
5494 
5496  string getNativeTypeString();
5497 
5498 
5500  string getCreateSql(AbstractTable t);
5501 
5502 
5504 
5513  abstract list getAddColumnSql(AbstractTable t);
5514 
5516  string getDropSql(string table_name);
5517 
5518 
5520 
5533  list getModifySql(AbstractTable t, AbstractColumn c, *hash opt);
5534 
5535 
5537 
5547  abstract string getRenameSql(AbstractTable t, string new_name);
5548 
5550  bool equal(AbstractColumn c);
5551 
5552 
5554 
5555 private:
5556  abstract bool equalImpl(AbstractColumn c);
5557 public:
5558 
5560 
5574 private:
5575  abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
5576 public:
5577  };
5578 
5581 
5582 public:
5583  public :
5585  int scale;
5586 
5587 public:
5588 
5589  constructor(softint n_scale = 0);
5590 
5591 
5593  string getNativeTypeString(string native_type, int precision);
5594 
5595  };
5596 
5599 
5600 public:
5601  constructor(*hash c) ;
5602 
5603 
5605  add(string k, AbstractIndex val);
5606 
5607 
5609  *AbstractIndex findEqual(AbstractIndex ix);
5610 
5611 
5613  AbstractIndex take(string k);
5614 
5615 
5617  *AbstractIndex tryTake(string k);
5618 
5619 
5621 
5636  AbstractIndex memberGate(string k);
5637 
5638 
5639  string getElementName();
5640 
5641  };
5642 
5645 
5646 public:
5647  public :
5649  string name;
5650 
5652  bool unique;
5653 
5656 
5657 public:
5658 
5659  private :
5662 
5663 public:
5664 
5666  constructor(string n, bool u, hash c);
5667 
5668 
5670  string getName();
5671 
5672 
5674  bool hasColumn(string cname);
5675 
5676 
5678  abstract string getCreateSql(string table_name, *hash opt);
5679 
5681  string getDropSql(string table_name);
5682 
5683 
5685  bool equal(AbstractIndex ix);
5686 
5687 
5689  bool equalExceptName(AbstractIndex ix);
5690 
5691 
5693  abstract bool equalImpl(AbstractIndex ix);
5694 
5696  abstract string getRenameSql(string table_name, string new_name);
5697 
5699  setSupportingConstraint(AbstractColumnSupportingConstraint c);
5700 
5701 
5703  setSupportingConstraint();
5704 
5705 
5707  *AbstractColumnSupportingConstraint getSupportingConstraint();
5708 
5709 
5711  list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt);
5712 
5713  };
5714 
5717 
5718 public:
5719  constructor(*hash c) ;
5720 
5721 
5723  add(string k, AbstractConstraint val);
5724 
5725 
5727  AbstractConstraint take(string k);
5728 
5729 
5731  *AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk);
5732 
5733 
5735 
5750  AbstractConstraint memberGate(string k);
5751 
5752 
5753  string getElementName();
5754 
5755  };
5756 
5759 
5760 public:
5761 private:
5762 
5763 public:
5764 
5765  private :
5767  string name;
5768 
5769 public:
5770 
5772  constructor(string n);
5773 
5774 
5776  string getName();
5777 
5778 
5780  rename(string n);
5781 
5782 
5784  abstract string getCreateSql(string table_name, *hash opt);
5785 
5787  string getDropSql(string table_name);
5788 
5789 
5791  abstract list getRenameSql(string table_name, string new_name);
5792 
5794  string getDisableSql(string table_name);
5795 
5796 
5798  string getEnableSql(string table_name, *hash opt);
5799 
5800 
5802  bool equal(AbstractConstraint c);
5803 
5804 
5806 
5807 private:
5808  abstract bool equalImpl(AbstractConstraint c);
5809 public:
5810 
5812  abstract bool setIndexBase(string ix);
5813 
5815  abstract clearIndex();
5816 
5818  bool hasColumn(string cname);
5819 
5820  };
5821 
5824 
5825 public:
5826  public :
5828  string src;
5829 
5830 public:
5831 
5833  constructor(string n, string n_src) ;
5834 
5835 
5837 
5838 private:
5839  bool equalImpl(AbstractConstraint c);
5840 public:
5841 
5842 
5844  bool setIndexBase(string ix);
5845 
5846 
5848  clearIndex();
5849 
5850  };
5851 
5854 
5855 public:
5856  private :
5859 
5861  *string index;
5862 
5863 public:
5864 
5866  constructor(string n, *hash c, *string n_index) ;
5867 
5868 
5870  constructor(string n, Columns c, *string n_index) ;
5871 
5872 
5874 
5878  Qore::AbstractIterator getSourceConstraintIterator();
5879 
5880 
5882  hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts);
5883 
5884 
5886  findMatchingIndex(*Indexes indexes);
5887 
5888 
5890 
5900  addSourceConstraint(string tname, AbstractForeignConstraint fk);
5901 
5902 
5904  removeSourceConstraint(string tname, list cols);
5905 
5906 
5908  renameSourceConstraintTable(string old_name, string new_name);
5909 
5910 
5912  bool hasColumn(string cname);
5913 
5914 
5916  *string getIndex();
5917 
5918 
5920 
5921 private:
5922  bool equalImpl(AbstractConstraint c);
5923 public:
5924 
5925 
5927  bool setIndexBase(string ix);
5928 
5929 
5931  clearIndex();
5932 
5933 
5935  abstract string getCreateSql(string table_name, *hash opts);
5936  };
5937 
5940 
5941 public:
5943  constructor(string n, *hash c, *string n_index) ;
5944 
5945  };
5946 
5949 
5950 public:
5951  constructor() ;
5952 
5953 
5954  constructor(string n, *hash c) ;
5955 
5956  };
5957 
5960 
5961 public:
5962  constructor(*hash c) ;
5963 
5964 
5966  add(string k, AbstractForeignConstraint val);
5967 
5968 
5970  AbstractForeignConstraint take(string k);
5971 
5972 
5975 
5976 
5978 
5993  AbstractForeignConstraint memberGate(string k);
5994 
5995 
5997  *hash findConstraintOn(string table, softlist cols);
5998 
5999 
6001  string getElementName();
6002 
6003  };
6004 
6007 
6008 public:
6009  public :
6011  string table;
6012 
6015 
6016 public:
6017 
6019  constructor(string t, Columns c);
6020 
6021 
6023  bool equal(ForeignConstraintTarget targ);
6024 
6025  };
6026 
6029 
6030 public:
6031  public :
6034 
6035 public:
6036 
6037  constructor(string n, Columns c, ForeignConstraintTarget t) ;
6038 
6039 
6041 
6042 private:
6043  bool equalImpl(AbstractConstraint con);
6044 public:
6045 
6046  };
6047 
6050 
6051 public:
6052  public :
6054  string name;
6055 
6058 
6061 
6064 
6065 public:
6066 
6068  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_max);
6069 
6070 
6072  abstract string getCreateSql(*hash opt);
6073 
6075 
6077  string getDropSql(*hash opt);
6078 
6079 
6081 
6084  abstract softlist getRenameSql(string new_name, *hash opt);
6085  };
6086 
6089 
6090 public:
6091  public :
6092  // ! potential object schema
6093  *string schema;
6094 
6096  string name;
6097 
6099  string src;
6100 
6103 
6104 public:
6105 
6107  constructor(string n_name, string n_src);
6108 
6109 
6111  abstract string getCreateSql(*hash opt);
6112 
6114 
6116  string getDropSql(*hash opt);
6117 
6118 
6120 
6123  abstract softlist getRenameSql(string new_name, *hash opt);
6124  };
6125 
6128 
6129 public:
6130  public :
6132  string name;
6133 
6135  string type;
6136 
6138  string src;
6139 
6140 public:
6141 
6143 
6147  constructor(string n, string n_type, string n_src);
6148 
6149 
6151  string getType();
6152 
6153 
6155 
6157  string getDropSql(*hash opt);
6158 
6159 
6161  bool equal(AbstractFunctionBase t);
6162 
6163 
6165 
6166 private:
6167  abstract bool equalImpl(AbstractFunctionBase t);
6168 public:
6169  };
6170 
6173 
6174 public:
6176 
6180  constructor(string n, string n_type, string n_src) ;
6181 
6182 
6184  abstract list getCreateSql(*hash opt);
6185 
6187 
6190  abstract softlist getRenameSql(string new_name, *hash opt);
6191 
6193  setName(string new_name);
6194 
6195  };
6196 
6199 
6200 public:
6201  constructor(*hash c) ;
6202 
6203 
6205  add(string k, AbstractFunction val);
6206 
6207 
6209  AbstractFunction take(string k);
6210 
6211 
6213 
6228  AbstractFunction memberGate(string k);
6229 
6230 
6231  string getElementName();
6232 
6233  };
6234 
6237 
6238 public:
6240  constructor(string n, string n_src) ;
6241 
6242 
6244  abstract list getCreateSql(string table_name, *hash opt);
6245 
6247  abstract softlist getRenameSql(string table_name, string new_name);
6248 
6250  abstract list getDropSql(string table_name);
6251  };
6252 
6255 
6256 public:
6257  constructor(*hash c) ;
6258 
6259 
6261  add(string k, AbstractTrigger val);
6262 
6263 
6265  AbstractTrigger take(string k);
6266 
6267 
6269 
6284  AbstractTrigger memberGate(string k);
6285 
6286 
6287  string getElementName();
6288 
6289  };
6290 
6292 
6302  class Database {
6303 
6304 public:
6305  private :
6308 
6309 public:
6310 
6312 
6323  constructor(AbstractDatasource ds, *hash opts);
6324 
6325 
6327 
6337  constructor(string ds, *hash opts);
6338 
6339 
6341 
6360 
6361 
6363  SqlUtil::AbstractDatabase getDatabase();
6364 
6365 
6367  any methodGate(string meth);
6368 
6369  };
6370 
6373 
6374 public:
6375  private :
6377  AbstractDatasource ds;
6379  string dsdesc;
6381  Mutex l();
6384 
6385 public:
6386 
6388 
6394 private:
6395  constructor(AbstractDatasource nds, *hash nopts);
6396 public:
6397 
6398 
6399  static string makeDatasourceDesc(AbstractDatasource ds);
6400 
6401 
6402 private:
6403  validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
6404 public:
6405 
6406 
6407 
6408 private:
6409  static validateOptionIntern(string err, string type, reference opt, string k, string tag);
6410 public:
6411 
6412 
6414 
6415 private:
6416  validateHashKeysForWhitespaces(auto node);
6417 public:
6418 
6419 
6422 
6423 
6425  string getDriverName();
6426 
6427 
6429  string getDatasourceDesc();
6430 
6431  };
6432 
6435 
6436 public:
6437  public :
6439 
6442  const DatabaseOptions = (
6443  "native_case": Type::Boolean,
6444  );
6445 
6447 
6450  const CacheOptions = (
6451  "table_cache": "Tables",
6452  );
6453 
6455 
6460  const CallbackOptions = (
6461  "info_callback": "code",
6462  "sql_callback": "code",
6463  "sql_callback_executed": Type::Boolean,
6464  );
6465 
6474  const AC_Unchanged = 0;
6476 
6478  const AC_Create = 1;
6479 
6481  const AC_Drop = 2;
6482 
6484  const AC_Rename = 3;
6485 
6487  const AC_Modify = 4;
6488 
6490  const AC_Truncate = 5;
6491 
6493  const AC_Add = 6;
6494 
6496  const AC_Recreate = 7;
6497 
6499  const AC_Insert = 8;
6500 
6502  const AC_Update = 9;
6503 
6505  const AC_Delete = 10;
6506 
6508  const AC_NotFound = 11;
6510 
6512  const ActionMap = (
6513  AC_Unchanged: "unchanged",
6514  AC_Create: "create",
6515  AC_Drop: "drop",
6516  AC_Rename: "rename",
6517  AC_Modify: "modify",
6518  AC_Truncate: "truncate",
6519  AC_Add: "add",
6520  AC_Recreate: "recreate",
6521  AC_Insert: "insert",
6522  AC_Update: "update",
6523  AC_Delete: "delete",
6524  AC_NotFound: "not found",
6525  );
6526 
6528  const ActionDescMap = (
6529  "unchanged": AC_Unchanged,
6530  "create": AC_Create,
6531  "drop": AC_Drop,
6532  "rename": AC_Rename,
6533  "modify": AC_Modify,
6534  "truncate": AC_Truncate,
6535  "add": AC_Add,
6536  "recreate": AC_Recreate,
6537  "insert": AC_Insert,
6538  "update": AC_Update,
6539  "delete": AC_Delete,
6540  "not found": AC_NotFound,
6541  );
6542 
6544  const ActionLetterMap = (
6545  AC_Unchanged: ".",
6546  AC_Create: "C",
6547  AC_Drop: "D",
6548  AC_Rename: "N",
6549  AC_Modify: "M",
6550  AC_Truncate: "T",
6551  AC_Add: "A",
6552  AC_Recreate: "R",
6553  AC_Insert: "I",
6554  AC_Update: "U",
6555  AC_Delete: "X",
6556  AC_NotFound: ".",
6557  );
6558 
6560 
6566  const CreationOptions = CallbackOptions + (
6567  "replace": Type::Boolean,
6568  "table_cache": "Tables",
6569  "data_tablespace": Type::String,
6570  "index_tablespace": Type::String,
6571  );
6572 
6574 
6577  const AlignSchemaOptions = CreationOptions + (
6578  "force": Type::Boolean,
6579  );
6580 
6582 
6585  const DropSchemaOptions = CallbackOptions + (
6586  "force": Type::Boolean,
6587  );
6588 
6590 
6602  const SchemaDescriptionOptions = (
6603  "tables": Type::Hash,
6604  "table_map": Type::Hash,
6605 
6606  "sequences": Type::Hash,
6607  "sequence_map": Type::Hash,
6608 
6609  "functions": Type::Hash,
6610  "function_map": Type::Hash,
6611 
6612  "procedures": Type::Hash,
6613  "procedure_map": Type::Hash,
6614 
6615  //"views": Type::Hash,
6616  //"view_map": Type::Hash,
6617  );
6618 
6620 
6625  const SequenceDescriptionOptions = (
6626  "start": Type::Int,
6627  "increment": Type::Int,
6628  "end": Type::Int,
6629  );
6630 
6632  const ComputeStatisticsOptions = (
6633  "tables" : "softstringlist",
6634  );
6635 
6637  const ReclaimSpaceOptions = (
6638  "tables" : "softstringlist",
6639  );
6640 
6641 public:
6642 
6643  private :
6646 
6647 public:
6648 
6650 
6656 private:
6657  constructor(AbstractDatasource nds, *hash nopts) ;
6658 public:
6659 
6660 
6662  list features();
6663 
6664 
6665  static doOkCallback(*hash opt, int ac, string type, string name, *string table, *string info);
6666 
6667  static *string doCallback(*hash opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
6668 
6669  static list doCallback(*hash opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
6670 
6671 /*
6672  static *string doCallback(*hash opt, *string sql, string fmt) {
6673  if (!sql)
6674  return;
6675  if (opt.info_callback)
6676  opt.info_callback(vsprintf(fmt, argv));
6677  if (opt.sql_callback)
6678  opt.sql_callback(sql);
6679  return sql;
6680  }
6681 
6682  static list doCallback(*hash opt, list sql, string fmt) {
6683  if (sql) {
6684  if (opt.info_callback)
6685  opt.info_callback(vsprintf(fmt, argv));
6686  if (opt.sql_callback)
6687  map opt.sql_callback($1), sql;
6688  }
6689  return sql;
6690  }
6691 */
6692 
6694 
6705  any tryExec(string sql);
6706 
6707 
6709 
6719  any tryExecArgs(string sql, *softlist args);
6720 
6721 
6723 
6734  any tryExecRaw(string sql);
6735 
6736 
6738 
6752  list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
6753 
6754 
6756 
6769  list getDropSchemaSql(hash schema_hash, *hash opt);
6770 
6771 
6772 
6773 private:
6774  list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
6775 public:
6776 
6777 
6778 
6779 private:
6780  list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
6781 public:
6782 
6783 
6785 
6799  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
6800 
6801 
6802  AbstractSequence makeSequenceFromDescription(string name, *hash sh, *hash opts);
6803 
6804 
6806 
6819  AbstractTable makeTable(string name, hash desc, *hash opts);
6820 
6821 
6823 
6834  AbstractFunction makeFunction(string name, string src, *hash opts);
6835 
6836 
6838 
6849  AbstractFunction makeProcedure(string name, string src, *hash opt);
6850 
6851 
6853 
6865  bool dropFunctionIfExists(string name, *hash opt);
6866 
6867 
6869 
6881  bool dropProcedureIfExists(string name, *hash opt);
6882 
6883 
6885 
6897  bool dropSequenceIfExists(string name, *hash opt);
6898 
6899 
6901 
6913  bool dropViewIfExists(string name, *hash opt);
6914 
6915 
6917 
6929  bool dropTableIfExists(string name, *hash opt);
6930 
6931 
6933 
6945  *string getDropFunctionSqlIfExists(string name, *hash opt);
6946 
6947 
6949 
6961  *string getDropProcedureSqlIfExists(string name, *hash opt);
6962 
6963 
6965 
6977  *string getDropSequenceSqlIfExists(string name, *hash opt);
6978 
6979 
6981 
6993  *list getDropTableSqlIfExists(string name, *hash opt);
6994 
6995 
6996  doDropSql(*softlist l, string type, string name, *hash opt);
6997 
6998 
6999  bool doDrop(*softlist l, string type, string name, *hash opt);
7000 
7001 
7003 
7015  list getAlignFunctionSql(AbstractFunction f, *hash opt);
7016 
7017 
7019 
7031  list getAlignProcedureSql(AbstractFunction f, *hash opt);
7032 
7033 
7035 
7044  *AbstractTable getTable(string name);
7045 
7046 
7048 
7057  *AbstractSequence getSequence(string name);
7058 
7059 
7061 
7072  *AbstractFunction getFunction(string name);
7073 
7074 
7076 
7087  *AbstractFunction getProcedure(string name);
7088 
7089 
7091 
7100  *AbstractView getView(string name);
7101 
7102 
7104 
7113  int getNextSequenceValue(string name);
7114 
7115 
7117 
7126  int getCurrentSequenceValue(string name);
7127 
7128 
7130 
7139  string getSqlFromList(list l);
7140 
7141 
7143  bool supportsSequences();
7144 
7145 
7147  bool supportsTypes();
7148 
7149 
7151  bool supportsPackages();
7152 
7153 
7155  list listTables();
7156 
7157 
7159  Qore::ListIterator tableIterator();
7160 
7161 
7163  list listFunctions();
7164 
7165 
7167  Qore::ListIterator functionIterator();
7168 
7169 
7171  list listProcedures();
7172 
7173 
7175  Qore::ListIterator procedureIterator();
7176 
7177 
7179  list listSequences();
7180 
7181 
7183  Qore::ListIterator sequenceIterator();
7184 
7185 
7187  list listViews();
7188 
7189 
7191  Qore::ListIterator viewIterator();
7192 
7193 
7195 
7205  bool rebuildIndex(string name, *hash options);
7206 
7207 
7209 
7217  bool rebuildIndex(AbstractIndex index, *hash options);
7218 
7219 
7221 
7228  computeStatistics(*hash options);
7229 
7230 
7232 
7239  reclaimSpace(*hash options);
7240 
7241 
7242 
7243 private:
7244  validateOptionsIntern(string err, hash ropt, reference<hash> opt);
7245 public:
7246 
7247 
7248 
7249 private:
7250  validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
7251 public:
7252 
7253 
7254  static AbstractDatabase getDatabase(AbstractDatasource nds, *hash opts);
7255 
7256  static AbstractDatabase getDatabase(string dsstr, *hash opts);
7257 
7258  static AbstractDatabase getDatabase(hash dsh, *hash opts);
7259 
7260  static checkDriverOptions(reference<hash> h, string drv);
7261 
7263 
7264 private:
7265  hash getDatabaseOptions();
7266 public:
7267 
7268 
7270 
7271 private:
7272  hash getCallbackOptions();
7273 public:
7274 
7275 
7277 
7278 private:
7279  hash getCreationOptions();
7280 public:
7281 
7282 
7284 
7285 private:
7287 public:
7288 
7289 
7291 
7292 private:
7293  hash getAlignSchemaOptions();
7294 public:
7295 
7296 
7298 
7299 private:
7300  hash getDropSchemaOptions();
7301 public:
7302 
7303 
7305 
7306 private:
7307  hash getSchemaDescriptionOptions();
7308 public:
7309 
7310 
7312 
7313 private:
7314  hash getSequenceDescriptionOptions();
7315 public:
7316 
7317 
7319 
7320 private:
7321  hash getRebuildIndexOptions();
7322 public:
7323 
7324 
7326 
7327 private:
7328  hash getComputeStatisticsOptions();
7329 public:
7330 
7331 
7333 
7334 private:
7335  hash getReclaimSpaceOptions();
7336 public:
7337 
7338 
7340 
7341 private:
7342  auto tryExecArgsImpl(string sql, *softlist args);
7343 public:
7344 
7345 
7347 
7348 private:
7349  auto tryExecRawImpl(string sql);
7350 public:
7351 
7352 
7353 
7354 private:
7355  abstract string getCreateSqlImpl(list l);
7356 public:
7357 
7358 private:
7359  abstract list getAlignSqlImpl(hash schema_hash, *hash opt);
7360 public:
7361 
7362 private:
7363  abstract list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
7364 public:
7365 
7366 
7367 private:
7368  abstract *AbstractSequence getSequenceImpl(string name);
7369 public:
7370 
7371 private:
7372  abstract *AbstractFunction getFunctionImpl(string name);
7373 public:
7374 
7375 private:
7376  abstract *AbstractFunction getProcedureImpl(string name);
7377 public:
7378 
7379 private:
7380  abstract *AbstractView getViewImpl(string name);
7381 public:
7382 
7383 
7384 private:
7385  abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
7386 public:
7387 
7388 private:
7389  abstract AbstractFunction makeFunctionImpl(string name, string src, *hash opts);
7390 public:
7391 
7392 private:
7393  abstract AbstractFunction makeProcedureImpl(string name, string src, *hash opts);
7394 public:
7395 
7396 
7397 private:
7398  abstract list featuresImpl();
7399 public:
7400 
7401 private:
7402  abstract list listTablesImpl();
7403 public:
7404 
7405 private:
7406  abstract list listFunctionsImpl();
7407 public:
7408 
7409 private:
7410  abstract list listProceduresImpl();
7411 public:
7412 
7413 private:
7414  abstract list listSequencesImpl();
7415 public:
7416 
7417 private:
7418  abstract list listViewsImpl();
7419 public:
7420 
7422 
7423 private:
7424  abstract int getNextSequenceValueImpl(string name);
7425 public:
7427 
7428 private:
7429  abstract int getCurrentSequenceValueImpl(string name);
7430 public:
7431 
7433 
7434 private:
7435  abstract bool supportsSequencesImpl();
7436 public:
7437 
7438 private:
7439  abstract bool supportsPackagesImpl();
7440 public:
7441 
7442 private:
7443  abstract bool supportsTypesImpl();
7444 public:
7445 
7446 
7447 private:
7448  abstract bool rebuildIndexImpl(string name, *hash options);
7449 public:
7450 
7451 private:
7452  abstract computeStatisticsImpl(*hash options);
7453 public:
7454 
7455 private:
7456  abstract reclaimSpaceImpl(*hash options);
7457 public:
7458  };
7459 
7461 
7477  class Table {
7478 
7479 public:
7480  private :
7483 
7484 public:
7485 
7487 
7499  constructor(AbstractDatasource ds, string name, *hash opts);
7500 
7501 
7503 
7515  constructor(string ds, string name, *hash opts);
7516 
7517 
7519 
7539  constructor(hash ds, string name, *hash opts);
7540 
7541 
7543 
7551  constructor(AbstractDatasource ds, hash desc, string name, *hash opts);
7552 
7553 
7555  AbstractTable getTable();
7556 
7557 
7559 
7561  any methodGate(string meth);
7562 
7563 
7564  }; // class Table
7565 
7567 
7570 
7571 public:
7572  public :
7574 
7578  const TableOptions = (
7579  "native_case": Type::Boolean,
7580  "table_cache": "Tables",
7581  );
7582 
7584 
7588  const IndexOptions = (
7589  "index_tablespace": Type::String,
7590  "replace": Type::Boolean,
7591  );
7592 
7594 
7597 
7599  const CacheOptions = (
7600  "table_cache": "Tables",
7601  );
7602 
7604 
7608  "table_cache": "Tables",
7609  );
7610 
7612 
7615 
7617 
7619  const SelectOptions = (
7620  "alias": Type::String,
7621  "comment": Type::String,
7622  "hint": Type::String,
7623  "columns": Type::NothingType,
7624  "where": "hash/list",
7625  "orderby": "softstringinthashlist",
7626  "desc": Type::Boolean,
7627  "limit": Type::Int,
7628  "offset": Type::Int,
7629  "join": Type::Hash,
7630  "groupby": "softstringinthashlist",
7631  "having": Type::Hash,
7632  "superquery": Type::Hash,
7633  "forupdate": Type::Boolean,
7634  );
7635 
7638  "indexes": True,
7639  "foreign_constraints": True,
7640  "triggers": True,
7641  );
7642 
7644 
7648  "omit": "softstringlist",
7649  );
7650 
7652 
7661  "column_map": Type::Hash,
7662  "index_map": Type::Hash,
7663  "constraint_map": Type::Hash,
7664  "trigger_map": Type::Hash,
7665  "db_table_cache": "Tables",
7666  "force": Type::Boolean,
7667  );
7668 
7670 
7682  "columns": Type::Hash,
7683  "primary_key": Type::Hash,
7684  "indexes": Type::Hash,
7685  "triggers": Type::Hash,
7686  "foreign_constraints": Type::Hash,
7687  "unique_constraints": Type::Hash,
7688  //"check_constraints": Type::Hash,
7689  "table_cache": "Tables",
7690  );
7691 
7693 
7706  "qore_type": Type::String,
7707  "native_type": Type::String,
7708  "size": Type::Int,
7709  "scale": Type::Int,
7710  "default_value": Type::NothingType,
7711  "default_value_native": Type::Boolean,
7712  "comment": Type::String,
7713  "notnull": Type::Boolean,
7714  "driver": Type::Hash,
7715  );
7716 
7718 
7722  "notnull": Type::Boolean,
7723  );
7724 
7726  const ColumnOptions = {};
7727 
7729 
7734  "sqlarg_callback": "code",
7735  "tablecode": "code",
7736  );
7737 
7739 
7749  "returning": "stringhashlist",
7750  );
7751 
7753 
7759  const UpsertOptions = (
7760  "info_callback": "code",
7761  "commit_block": Type::Int,
7762  "delete_others": Type::Boolean,
7763  "omit_update": "softstringlist",
7764  );
7765 
7767 
7772  "info_callback": "code",
7773  "commit_block": Type::Int,
7774  );
7775 
7791 
7798 
7800 
7806 
7808 
7815 
7817 
7821  const UpsertAuto = 4;
7822 
7824 
7828  const UpsertInsertOnly = 5;
7829 
7831 
7835  const UpsertUpdateOnly = 6;
7836 
7838 
7841  UpsertInsertFirst: "UpsertInsertFirst",
7842  UpsertUpdateFirst: "UpsertUpdateFirst",
7843  UpsertSelectFirst: "UpsertSelectFirst",
7844  UpsertAuto: "UpsertAuto",
7845  UpsertInsertOnly: "UpsertInsertOnly",
7846  UpsertUpdateOnly: "UpsertUpdateOnly",
7847  );
7848 
7850 
7853  "UpsertInsertFirst": UpsertInsertFirst,
7854  "UpsertUpdateFirst": UpsertUpdateFirst,
7855  "UpsertSelectFirst": UpsertSelectFirst,
7856  "UpsertAuto": UpsertAuto,
7857  "UpsertInsertOnly": UpsertInsertOnly,
7858  "UpsertUpdateOnly": UpsertUpdateOnly,
7859  );
7861 
7866  const UR_Inserted = 1;
7868 
7870  const UR_Verified = 2;
7871 
7873  const UR_Updated = 3;
7874 
7876  const UR_Unchanged = 4;
7877 
7879  const UR_Deleted = 5;
7881 
7883 
7886  UR_Inserted: "inserted",
7887  UR_Verified: "verified",
7888  UR_Updated: "updated",
7889  UR_Unchanged: "unchanged",
7890  UR_Deleted: "deleted",
7891  );
7892 
7894 
7897  "inserted": UR_Inserted,
7898  "verified": UR_Verified,
7899  "updated": UR_Updated,
7900  "unchanged": UR_Unchanged,
7901  "deleted": UR_Deleted,
7902  );
7903 
7906  UR_Inserted: "I",
7907  UR_Verified: "V",
7908  UR_Updated: "U",
7909  UR_Unchanged: ".",
7910  UR_Deleted: "X",
7911  );
7912 
7913 public:
7914 
7915  private :
7917  string name;
7933  bool inDb = False;
7935  bool manual = False;
7936 
7937  hash m_customCopMap = hash();
7938 
7939 public:
7940 
7942 
7949 private:
7950  constructor(AbstractDatasource nds, string nname, *hash nopts) ;
7951 public:
7952 
7953 
7955  copy(AbstractTable old);
7956 
7957 
7959 
7970  setDatasource(AbstractDatasource nds);
7971 
7972 
7973 
7974 private:
7975  doTableOptions(*hash nopts);
7976 public:
7977 
7978 
7980  commit();
7981 
7982 
7984  rollback();
7985 
7986 
7988 
7997  bool inDb();
7998 
7999 
8001 
8009 
8010 
8012 
8023  dropCommit(*hash opt);
8024 
8025 
8027 
8038  drop(*hash opt);
8039 
8040 
8042  deprecated dropNoCommit(*hash opt);
8043 
8045 
8056  auto tryExec(string sql);
8057 
8058 
8060 
8070  auto tryExecArgs(string sql, *softlist args);
8071 
8072 
8074 
8085  auto tryExecRaw(string sql);
8086 
8087 
8089 
8100  softlist getDropSql(*hash opt);
8101 
8102 
8104 
8111  truncateCommit();
8112 
8113 
8115 
8122  truncate();
8123 
8124 
8126  deprecated truncateNoCommit();
8127 
8129 
8144  string getTruncateSql(*hash opt);
8145 
8146 
8148 
8157  createCommit(*hash opt);
8158 
8159 
8161 
8172  create(*hash opt);
8173 
8174 
8176  deprecated createNoCommit(*hash opt);
8177 
8179 
8190  rename(string new_name, *reference<string> sql, *Tables table_cache);
8191 
8192 
8193 
8194 private:
8195  doRenameIntern(string new_name, *Tables table_cache);
8196 public:
8197 
8198 
8200 
8211  bool emptyData();
8212 
8213 
8215 
8224  bool empty();
8225 
8226 
8227 
8228 private:
8229  bool emptyUnlocked();
8230 public:
8231 
8232 
8234 
8240  setupTable(hash desc, *hash opt);
8241 
8242 
8244 
8268  AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8269 
8270 
8272 
8301  list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8302 
8303 
8304 
8305 private:
8306  AbstractColumn addColumnUnlocked(string cname, hash opt, bool nullable = True, *reference lsql, bool do_exec = True, bool modify_table = True);
8307 public:
8308 
8309 
8310 
8311 private:
8312  addColumnToTableUnlocked(AbstractColumn c);
8313 public:
8314 
8315 
8317 
8342  AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8343 
8344 
8346 
8373  list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8374 
8375 
8377 
8394  AbstractColumn renameColumn(string old_name, string new_name, reference<string> sql);
8395 
8396 
8398 
8416  string getRenameColumnSql(string old_name, string new_name, *hash opt);
8417 
8418 
8419 
8420 private:
8421  AbstractColumn renameColumnIntern(AbstractColumn c, string new_name);
8422 public:
8423 
8424 
8425 
8426 private:
8427  validateOptionsIntern(string err, hash ropt, reference<hash> opt);
8428 public:
8429 
8430 
8431 
8432 private:
8433  validateOptionsIntern(string err, hash ropt, reference<hash> opt, string tag);
8434 public:
8435 
8436 
8437 
8438 private:
8439  execSql(softlist lsql);
8440 public:
8441 
8442 
8444 
8464  AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference<string> sql);
8465 
8466 
8468 
8490  string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
8491 
8492 
8493 
8494 private:
8495  setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
8496 public:
8497 
8498 
8499 
8500 private:
8501  AbstractPrimaryKey addPrimaryKeyUnlocked(string pkname, softlist cols, *hash opt, *reference<string> sql);
8502 public:
8503 
8504 
8505 
8506 private:
8507  AbstractPrimaryKey addPrimaryKeyUnlockedIntern(string pkname, softlist cols, *hash opt, *reference<string> sql);
8508 public:
8509 
8510 
8512 
8529 
8530 
8531 
8532 private:
8533  list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(string cname, *hash opt);
8534 public:
8535 
8536 
8538 
8558 
8559 
8561 
8579  AbstractPrimaryKey dropPrimaryKey(*reference lsql);
8580 
8581 
8583 
8604  AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference<string> sql);
8605 
8606 
8608 
8628  string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
8629 
8630 
8631 
8632 private:
8633  AbstractUniqueConstraint addUniqueConstraintUnlocked(string cname, softlist cols, *hash opt, *reference<string> sql);
8634 public:
8635 
8636 
8637 
8638 private:
8639  AbstractUniqueConstraint addUniqueConstraintUnlockedIntern(string cname, softlist cols, *hash opt, *reference<string> sql);
8640 public:
8641 
8642 
8644 
8665  AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
8666 
8667 
8669 
8690  string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
8691 
8692 
8693 
8694 private:
8695  AbstractIndex addIndexUnlocked(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
8696 public:
8697 
8698 
8699 
8700 private:
8701  AbstractIndex addIndexUnlockedIntern(string iname, bool unique, softlist cols, *hash opt, *reference<string> sql);
8702 public:
8703 
8704 
8706 
8718  AbstractIndex renameIndex(string old_name, string new_name, reference<string> sql);
8719 
8720 
8722 
8740  AbstractIndex dropIndex(string iname, *reference<string> sql);
8741 
8742 
8744 
8763  string getDropIndexSql(string iname, *hash opt);
8764 
8765 
8767 
8789  AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
8790 
8791 
8793 
8815  string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
8816 
8817 
8818 
8819 private:
8820  Columns getReferencedTableColumnsUnlocked(string table, *Tables cache, string err = "FOREIGN-CONSTRAINT-ERROR");
8821 public:
8822 
8823 
8824 
8825 private:
8826  AbstractForeignConstraint addForeignConstraintUnlocked(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
8827 public:
8828 
8829 
8830 
8831 private:
8832  AbstractForeignConstraint addForeignConstraintUnlockedIntern(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference<string> sql);
8833 public:
8834 
8835 
8837 
8855  AbstractForeignConstraint dropForeignConstraint(string cname, *reference<string> sql);
8856 
8857 
8859 
8875 
8876 
8878 
8898  AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference<string> sql);
8899 
8900 
8902 
8924  string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
8925 
8926 
8927 
8928 private:
8929  AbstractCheckConstraint addCheckConstraintUnlocked(string cname, string src, *hash opt, *reference<string> sql);
8930 public:
8931 
8932 
8933 
8934 private:
8935  AbstractCheckConstraint addCheckConstraintUnlockedIntern(string cname, string src, *hash opt, *reference<string> sql);
8936 public:
8937 
8938 
8940 
8952  AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
8953 
8954 
8956 
8975  string getDropConstraintSql(string cname, *hash opt);
8976 
8977 
8979 
8998  *string getDropConstraintIfExistsSql(string cname, *hash opt, *reference<AbstractConstraint> cref);
8999 
9000 
9001 
9002 private:
9003  AbstractConstraint findDropConstraintUnlocked(string cname, reference<code> rmv);
9004 public:
9005 
9006 
9008 
9026  AbstractConstraint dropConstraint(string cname, *reference<string> sql);
9027 
9028 
9030 
9050  AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
9051 
9052 
9054 
9076  list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
9077 
9078 
9079 
9080 private:
9081  AbstractTrigger addTriggerUnlocked(string tname, string src, *hash opt, *reference lsql);
9082 public:
9083 
9084 
9085 
9086 private:
9087  AbstractTrigger addTriggerUnlockedIntern(string tname, string src, *hash opt, *reference lsql);
9088 public:
9089 
9090 
9092 
9110  AbstractTrigger dropTrigger(string tname, *reference<string> sql);
9111 
9112 
9114 
9133  list getDropTriggerSql(string tname, *hash opt);
9134 
9135 
9136 
9137 private:
9138  getAllConstraintsUnlocked(*hash opt);
9139 public:
9140 
9141 
9142 
9143 private:
9144  checkUniqueConstraintName(string err, string cname);
9145 public:
9146 
9147 
9148 
9149 private:
9150  checkUniqueConstraintNameValidateOptions(string err, string cname, hash ropt, reference<hash> opt);
9151 public:
9152 
9153 
9155 
9156 private:
9157  validateColumnOptions(string cname, reference<hash> opt, bool nullable);
9158 public:
9159 
9160 
9162 
9180  AbstractColumn dropColumn(string cname, *reference lsql);
9181 
9182 
9184 
9203  list getDropColumnSql(string cname, *hash opt);
9204 
9205 
9207 
9220  *hash insertCommit(hash row);
9221 
9222 
9224  *hash insertCommit(hash row, reference<string> sql);
9225 
9226 
9228  *hash insertCommit(hash row, hash opt);
9229 
9230 
9232  *hash insertCommit(hash row, reference<string> sql, hash opt);
9233 
9234 
9236 
9250  *hash insert(hash row);
9251 
9252 
9254  *hash insert(hash row, reference<string> sql);
9255 
9256 
9258  *hash insert(hash row, hash opt);
9259 
9260 
9262  *hash insert(hash row, reference<string> sql, hash opt);
9263 
9264 
9266  deprecated *hash insertNoCommit(hash row, *reference<string> sql, *hash opt);
9267 
9269  deprecated *hash insertNoCommit(hash row, hash opt);
9270 
9271 
9272 private:
9273  *hash insertIntern(hash row, *reference<string> sql, *hash opt);
9274 public:
9275 
9276 
9277 
9278 private:
9279  hash getPlaceholdersAndValues(hash row);
9280 public:
9281 
9282 
9284 
9287  bool hasReturning();
9288 
9289 
9291 
9310  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference<string> sql, hash opt);
9311 
9312 
9314  int insertFromSelectCommit(list cols, AbstractTable source);
9315 
9316 
9318  int insertFromSelectCommit(list cols, AbstractTable source, hash sh);
9319 
9320 
9322  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference<string> sql);
9323 
9324 
9326  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, hash opt);
9327 
9328 
9330 
9349  int insertFromSelect(list cols, AbstractTable source, hash sh, reference<string> sql, hash opt);
9350 
9351 
9353  int insertFromSelect(list cols, AbstractTable source);
9354 
9355 
9357  int insertFromSelect(list cols, AbstractTable source, hash sh);
9358 
9359 
9361  int insertFromSelect(list cols, AbstractTable source, hash sh, reference<string> sql);
9362 
9363 
9365  int insertFromSelect(list cols, AbstractTable source, hash sh, hash opt);
9366 
9367 
9369  deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference<string> sql, *hash opt);
9370 
9371 
9372 private:
9373  int insertFromSelectIntern(list cols, AbstractTable source, *hash sh, *reference<string> sql, *hash opt);
9374 public:
9375 
9376 
9378 
9397 
9398 
9400 
9419 
9420 
9422  deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt);
9423 
9424 
9425 private:
9426  int insertFromIteratorIntern(Qore::AbstractIterator i, *hash opt);
9427 public:
9428 
9429 
9431 
9447  int upsertCommit(hash row, int upsert_strategy = UpsertAuto, *hash opt);
9448 
9449 
9451 
9467  int upsert(hash row, int upsert_strategy = UpsertAuto, *hash opt);
9468 
9469 
9471  deprecated int upsertNoCommit(hash row, int upsert_strategy = UpsertAuto);
9472 
9474 
9495  code getUpsertClosure(hash row, int upsert_strategy = UpsertAuto, *hash opt);
9496 
9497 
9499 
9526  code getBulkUpsertClosure(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9527 
9528 
9530 
9551  code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = UpsertAuto, *hash opt);
9552 
9553 
9555 
9588 
9589 
9591 
9624 
9625 
9627  deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9628 
9629 
9630 private:
9631  *hash upsertFromIteratorIntern(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9632 public:
9633 
9634 
9635 
9636 private:
9637  *hash doDeleteOthersIntern(hash pkh, *hash opt);
9638 public:
9639 
9640 
9642 
9680  *hash upsertFromSelectCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9681 
9682 
9684  *hash upsertFromSelectCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9685 
9686 
9688 
9728  *hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9729 
9730 
9732  deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9733 
9735  deprecated *hash upsertFromSelect(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9736 
9738  deprecated *hash upsertFromSelectNoCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9739 
9741 
9752  softint rowCount();
9753 
9754 
9756 
9774  Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference<string> sql, *hash opt);
9775 
9776 
9777 
9778 private:
9779  Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference<string> sql, *hash opt);
9780 public:
9781 
9782 
9784 
9802 
9803 
9805 
9824  *hash selectRow(*hash sh, *reference<string> sql, *hash opt);
9825 
9826 
9828 
9846  *list selectRows(*hash sh, *reference<string> sql, *hash opt);
9847 
9848 
9850 
9868  *hash select(*hash sh, *reference<string> sql, *hash opt);
9869 
9870 
9872 
9890  *hash selectRow(*hash sh, *hash opt);
9891 
9892 
9894 
9911  *list selectRows(*hash sh, *hash opt);
9912 
9913 
9915 
9932  *hash select(*hash sh, *hash opt);
9933 
9934 
9936 
9954  string getSelectSql(*hash sh, *reference<list> args);
9955 
9956 
9957  *AbstractUniqueConstraint matchAnyUnique(list cols);
9958 
9959 
9960  string getSelectSqlIntern(*hash qh, reference<list> args, *hash opt);
9961 
9962 
9963  string getSelectSqlUnlocked(*hash qh, reference<list> args, *hash opt);
9964 
9965 
9966  // column & table information must be retrieved before calling this function
9967  string getSelectSqlUnlockedIntern(*hash qh, string from, reference<list> args, *hash ch, *hash opt);
9968 
9969 
9970 
9971 private:
9972  string getFromIntern(string from, *hash qh);
9973 public:
9974 
9975 
9976 
9977 private:
9978  list getGroupByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
9979 public:
9980 
9981 
9982 
9983 private:
9984  list getOrderByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
9985 public:
9986 
9987 
9988 
9989 private:
9990  list getGroupOrderByListUnlocked(string key, hash qh, *hash jch, *hash ch, *hash psch, list coll);
9991 public:
9992 
9993 
9994 
9995 private:
9996  doForUpdate(reference<string> sql);
9997 public:
9998 
9999 
10000 
10001 private:
10002  string getSelectSqlName(*hash qh);
10003 public:
10004 
10005 
10006 
10007 private:
10008  string getColumnExpressionIntern(auto cvc, *hash jch, bool join, *hash ch, *hash psch);
10009 public:
10010 
10011 
10012 
10013 private:
10014  string doColumnOperatorIntern(hash cvc, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
10015 public:
10016 
10017 
10018 
10019 private:
10020  string doColumnOperatorIntern(auto cop, auto arg, *string cve, hash cm, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
10021 public:
10022 
10023 
10024 
10025 private:
10026  string getColumnNameIntern(string cv, *hash jch, bool join, *hash ch, *hash psch);
10027 public:
10028 
10029 
10031 
10032 private:
10033  bool asteriskRequiresPrefix();
10034 public:
10035 
10036 
10037 
10038 private:
10039  getSelectWhereSqlUnlocked(reference<string> sql, reference<list> args, *hash qh, *hash jch, bool join = False, *hash ch, *hash psch);
10040 public:
10041 
10042 
10043 
10044 private:
10045  *string getWhereClause(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False);
10046 public:
10047 
10048 
10049 
10050 private:
10051  *string getWhereClause(list cond, reference<list> args, *string cprefix, *hash jch, bool join = False);
10052 public:
10053 
10054 
10055 
10056 private:
10057  *string getWhereClauseUnlocked(list cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
10058 public:
10059 
10060 
10061 
10062 private:
10063  *string getWhereClauseUnlocked(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
10064 public:
10065 
10066 
10067 
10068 private:
10069  *list getWhereClauseIntern(*hash cond, reference<list> args, *string cprefix, *hash jch, bool join = False, *hash ch, *hash psch);
10070 public:
10071 
10072 
10073 
10074 private:
10075  string doWhereExpressionIntern(string cn, auto we, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
10076 public:
10077 
10078 
10079  string getOrClause(list arglist, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
10080 
10081 
10082  string getOrClause(hash arg, reference<list> args, *hash jch, bool join = False, *hash ch, *hash psch);
10083 
10084 
10085 
10086 private:
10087  doSelectOrderBySqlUnlocked(reference<string> sql, reference<list> args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
10088 public:
10089 
10090 
10092 
10107  int delCommit(hash cond, reference<string> sql, hash opt);
10108 
10109 
10111  int delCommit(hash cond, hash opt);
10112 
10113 
10115  int delCommit(hash cond, reference<string> sql);
10116 
10117 
10119  int delCommit(hash cond);
10120 
10121 
10123  int delCommit();
10124 
10125 
10127 
10142  int del(hash cond, reference<string> sql, hash opt);
10143 
10144 
10146  int del(hash cond, hash opt);
10147 
10148 
10150  int del(hash cond, reference<string> sql);
10151 
10152 
10154  int del(hash cond);
10155 
10156 
10158  int del();
10159 
10160 
10162  deprecated int delNoCommit(*hash cond, *reference<string> sql);
10163 
10164 
10165 private:
10166  int delIntern(*hash cond, *reference<string> sql, *hash opt);
10167 public:
10168 
10169 
10171 
10188  int updateCommit(hash set, hash cond, reference<string> sql, hash opt);
10189 
10190 
10192  int updateCommit(hash set, hash cond, reference<string> sql);
10193 
10194 
10196  int updateCommit(hash set, hash cond, hash opt);
10197 
10198 
10200  int updateCommit(hash set, hash cond);
10201 
10202 
10204  int updateCommit(hash set);
10205 
10206 
10208 
10225  int update(hash set, hash cond, reference<string> sql, hash opt);
10226 
10227 
10229  int update(hash set, hash cond, reference<string> sql);
10230 
10231 
10233  int update(hash set, hash cond, hash opt);
10234 
10235 
10237  int update(hash set, hash cond);
10238 
10239 
10241  int update(hash set);
10242 
10243 
10245  deprecated int updateNoCommit(hash set, *hash cond, *reference<string> sql);
10246 
10248  deprecated int updateNoCommit(hash set, *hash cond, *hash opt);
10249 
10250 
10251 private:
10252  int updateIntern(hash set, *hash cond, *reference<string> sql, *hash opt);
10253 public:
10254 
10255 
10256 
10257 private:
10258  string getUpdateExpression(string col, hash<UpdateOperatorInfo> uh);
10259 public:
10260 
10261 
10262 
10263 private:
10264  bool emptyDataIntern();
10265 public:
10266 
10267 
10268 
10269 private:
10270  Columns checkUpsertRow(hash row, reference<int> upsert_strategy);
10271 public:
10272 
10273 
10274 
10275 private:
10276  code getUpsertInsertFirst(Columns cols, hash example_row, *hash opt);
10277 public:
10278 
10279 
10280 
10281 private:
10282  code getUpsertUpdateFirst(Columns cols, hash example_row, *hash opt);
10283 public:
10284 
10285 
10286 
10287 private:
10288  code getUpsertSelectFirst(Columns cols, hash example_row, *hash opt);
10289 public:
10290 
10291 
10292 
10293 private:
10294  code getUpsertInsertOnly(Columns cols, hash example_row, *hash opt);
10295 public:
10296 
10297 
10298 
10299 private:
10300  code getUpsertUpdateOnly(Columns cols, hash example_row, *hash opt);
10301 public:
10302 
10303 
10304 
10305 private:
10306  Columns getUpsertColumns(reference csrc);
10307 public:
10308 
10309 
10310 
10311 private:
10312  string getUpsertSelectSql(hash row, Columns cols, reference<list<string>> updc);
10313 public:
10314 
10315 
10316 
10317 private:
10318  string getUpsertInsertSql(hash row);
10319 public:
10320 
10321 
10322 
10323 private:
10324  string getUpsertUpdateSql(hash row, Columns cols, reference updc, *hash opt);
10325 public:
10326 
10327 
10328 
10329 private:
10330  softbool tryUpdate(string sql, hash row, Columns cols, list updc);
10331 public:
10332 
10333 
10334 
10335 private:
10336  checkValue(string cname, string argname, reference val, string type);
10337 public:
10338 
10339 
10341 
10350  string getSqlFromList(list l);
10351 
10352 
10354 
10365  string getSqlValue(auto v);
10366 
10367 
10369  string getName();
10370 
10371 
10373 
10380  cache(*hash opts);
10381 
10382 
10384 
10389  clear();
10390 
10391 
10393 
10400  Columns describe();
10401 
10402 
10404 
10413 
10414 
10416 
10426 
10427 
10428  *AbstractUniqueConstraint findUniqueConstraintUnlocked(string name);
10429 
10430 
10432 
10441  Indexes getIndexes();
10442 
10443 
10446 
10447 
10450 
10451 
10453 
10463 
10464 
10466 
10484  string getRenameSql(string new_name, *hash opt);
10485 
10486 
10488 
10497  string getCreateSqlString(*hash opt);
10498 
10499 
10501 
10510  list getCreateSql(*hash opt);
10511 
10512 
10514 
10525  string getCreateTableSql(*hash opt);
10526 
10527 
10529 
10533  bool checkExistence();
10534 
10535 
10536 
10537 private:
10538  *hash getCheckOmissionOptions(*softlist ol, string err);
10539 public:
10540 
10541 
10543 
10559 
10560 
10561 
10562 private:
10563  list getAlignSqlUnlocked(AbstractTable t, *hash opt);
10564 public:
10565 
10566 
10567 
10568 private:
10569  *AbstractColumnSupportingConstraint getSupportingConstraint(string ixname);
10570 public:
10571 
10572 
10573 
10574 private:
10575  renameIndexUnlocked(AbstractIndex ix, string new_name);
10576 public:
10577 
10578 
10580 
10593  string getAlignSqlString(AbstractTable t, *hash opt);
10594 
10595 
10597 
10609  *list getCreateIndexesSql(*hash opt, bool cache = True);
10610 
10611 
10613 
10625  *string getCreatePrimaryKeySql(*hash opt, bool cache = True);
10626 
10627 
10629 
10641  *list getCreateForeignConstraintsSql(*hash opt, bool cache = True);
10642 
10643 
10645 
10659  *list getCreateConstraintsSql(*hash opt, bool cache = True);
10660 
10661 
10663 
10675  *list getCreateMiscSql(*hash opt, bool cache = True);
10676 
10677 
10679 
10693  *list getCreateTriggersSql(*hash opt, bool cache = True);
10694 
10695 
10697 
10704  *hash find(auto id);
10705 
10706 
10708 
10719  *list find(list ids);
10720 
10721 
10722 
10723 private:
10724  string getPrimaryKeyColumn();
10725 public:
10726 
10727 
10729 
10742  *hash find(hash row);
10743 
10744 
10746 
10759  *hash findSingle(*hash cond);
10760 
10761 
10763 
10776  *list findAll(*hash cond);
10777 
10778 
10780 
10784  string getDesc();
10785 
10786 
10788  string getBaseType();
10789 
10790 
10792  string getSqlName();
10793 
10794 
10796  string getColumnSqlName(string col);
10797 
10798 
10800  list getColumnSqlNames(softlist cols);
10801 
10802 
10804 
10806  bool bindEmptyStringsAsNull();
10807 
10808 
10810  abstract bool hasArrayBind();
10811 
10813 
10816 private:
10818 public:
10819 
10820 
10822 
10825 private:
10827 public:
10828 
10829 
10831 
10834 private:
10836 public:
10837 
10838 
10840 
10843 private:
10845 public:
10846 
10847 
10849 
10852 private:
10854 public:
10855 
10856 
10858 
10861 private:
10863 public:
10864 
10865 
10867 
10870 private:
10872 public:
10873 
10874 
10876 
10879 private:
10881 public:
10882 
10883 
10885 
10888 private:
10890 public:
10891 
10892 
10894 
10897 private:
10899 public:
10900 
10901 
10903 
10906 private:
10908 public:
10909 
10910 
10912 
10915 private:
10917 public:
10918 
10919 
10921 
10924 private:
10926 public:
10927 
10928 
10930 
10933 private:
10935 public:
10936 
10937 
10939 
10942 private:
10944 public:
10945 
10946 
10948 
10951 private:
10953 public:
10954 
10955 
10957 
10960 private:
10962 public:
10963 
10964 
10966 
10969 private:
10971 public:
10972 
10973 
10975 
10978 private:
10980 public:
10981 
10982 
10984 
10985 private:
10987 public:
10988 
10989 
10991 
11027  addCustomCopOperator(string name, hash operator);
11028 
11029 
11031 
11034 private:
11036 public:
11037 
11038 
11040 
11043 private:
11045 public:
11046 
11047 
11049 
11052 private:
11054 public:
11055 
11056 
11058 
11061 private:
11063 public:
11064 
11065 
11066 
11067 private:
11068  string getCreateTableSqlUnlocked(*hash opt);
11069 public:
11070 
11071 
11072 
11073 private:
11074  *list getCreateIndexesSqlUnlocked(*hash opt, bool cache = True);
11075 public:
11076 
11077 
11078 
11079 private:
11080  *string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
11081 public:
11082 
11083 
11084 
11085 private:
11086  *list getCreateConstraintsSqlUnlocked(*hash opt, bool cache = True);
11087 public:
11088 
11089 
11090 
11091 private:
11092  *list getCreateForeignConstraintsSqlUnlocked(*hash opt, bool cache = True);
11093 public:
11094 
11095 
11096 
11097 private:
11098  *list getCreateMiscSqlUnlocked(*hash opt, bool cache = True);
11099 public:
11100 
11101 
11102 
11103 private:
11104  *list getCreateTriggersSqlUnlocked(*hash opt, bool cache = True);
11105 public:
11106 
11107 
11108 
11109 private:
11110  list getCreateSqlUnlocked(*hash opt, bool cache = True);
11111 public:
11112 
11113 
11114 
11115 private:
11116  cacheUnlocked(*hash opt);
11117 public:
11118 
11119 
11120 
11121 private:
11122  auto execData(*hash opt, string sql, *list args);
11123 public:
11124 
11125 
11126 
11127 private:
11128  execData(SQLStatement stmt, *hash opt, *list args);
11129 public:
11130 
11131 
11132  static AbstractTable getTable(AbstractDatasource nds, string nname, *hash opts);
11133 
11134  static AbstractTable getTable(string dsstr, string nname, *hash opts);
11135 
11136  static AbstractTable getTable(hash dsh, string nname, *hash opts);
11137 
11138 
11139 private:
11140  getColumnsUnlocked();
11141 public:
11142 
11143 
11144 
11145 private:
11146  getPrimaryKeyUnlocked();
11147 public:
11148 
11149 
11150  // also loads primary key and constraints (for unique constraints)
11151 
11152 private:
11153  getIndexesUnlocked();
11154 public:
11155 
11156 
11157 
11158 private:
11159  getForeignConstraintsUnlocked(*hash opt);
11160 public:
11161 
11162 
11163 
11164 private:
11165  addSourceConstraint(string table_name, AbstractForeignConstraint fk);
11166 public:
11167 
11168 
11169 
11170 private:
11171  getConstraintsUnlocked();
11172 public:
11173 
11174 
11175 
11176 private:
11177  getTriggersUnlocked();
11178 public:
11179 
11180 
11182 
11183 private:
11184  bool hasReturningImpl();
11185 public:
11186 
11187 
11188 
11189 private:
11190  softlist getDropSqlImpl();
11191 public:
11192 
11193 
11194 
11195 private:
11196  string getTruncateSqlImpl();
11197 public:
11198 
11199 
11201 
11202 private:
11203  auto tryExecArgsImpl(string sql, *softlist args);
11204 public:
11205 
11206 
11208 
11209 private:
11210  auto tryExecRawImpl(string sql);
11211 public:
11212 
11213 
11215 
11216 private:
11217  clearImpl();
11218 public:
11219 
11220 
11221 
11222 private:
11223  preSetupTableImpl(reference desc, *hash opt);
11224 public:
11225 
11226 
11227 
11228 private:
11229  abstract *hash doReturningImpl(hash opt, reference<string> sql, list args);
11230 public:
11231 
11232 
11233 private:
11234  abstract bool emptyImpl();
11235 public:
11236 
11238 
11239 private:
11240  abstract *string getSqlValueImpl(auto v);
11241 public:
11242 
11244 
11248 private:
11249  abstract bool checkExistenceImpl();
11250 public:
11251 
11253 
11254 private:
11255  abstract bool supportsTablespacesImpl();
11256 public:
11257 
11259 
11260 private:
11261  abstract bool constraintsLinkedToIndexesImpl();
11262 public:
11263 
11265 
11266 private:
11267  abstract bool uniqueIndexCreatesConstraintImpl();
11268 public:
11269 
11270 
11271 private:
11272  abstract setupTableImpl(hash desc, *hash opt);
11273 public:
11274 
11275 
11276 private:
11277  abstract Columns describeImpl();
11278 public:
11279 
11280 private:
11281  abstract AbstractPrimaryKey getPrimaryKeyImpl();
11282 public:
11283 
11284 private:
11285  abstract Indexes getIndexesImpl();
11286 public:
11287 
11288 private:
11289  abstract ForeignConstraints getForeignConstraintsImpl(*hash opt);
11290 public:
11291 
11292 private:
11293  abstract Constraints getConstraintsImpl();
11294 public:
11295 
11296 private:
11297  abstract Triggers getTriggersImpl();
11298 public:
11299 
11300 
11301 private:
11302  abstract string getCreateTableSqlImpl(*hash opt);
11303 public:
11304 
11305 private:
11306  abstract *list getCreateMiscSqlImpl(*hash opt, bool cache);
11307 public:
11308 
11309 private:
11310  abstract string getCreateSqlImpl(list l);
11311 public:
11312 
11313 private:
11314  abstract string getRenameSqlImpl(string new_name);
11315 public:
11316 
11317 private:
11318  abstract *list getAlignSqlImpl(AbstractTable t, *hash opt);
11319 public:
11320 
11321 
11322 private:
11323  abstract AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
11324 public:
11325 
11326 private:
11327  abstract AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
11328 public:
11329 
11330 private:
11331  abstract AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
11332 public:
11333 
11334 private:
11335  abstract AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
11336 public:
11337 
11338 private:
11339  abstract AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
11340 public:
11341 
11342 private:
11343  abstract AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
11344 public:
11345 
11346 
11347 private:
11348  abstract AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
11349 public:
11350 
11352 
11353 private:
11354  abstract bool tryInsertImpl(string sql, hash row);
11355 public:
11356 
11358 
11359 private:
11360  abstract hash getQoreTypeMapImpl();
11361 public:
11362 
11364 
11365 private:
11366  abstract hash getTypeMapImpl();
11367 public:
11368 
11370 
11371 private:
11372  abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference<string> sql, reference<list> args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
11373 public:
11374 
11376 
11377 private:
11378  abstract doSelectLimitOnlyUnlockedImpl(reference<string> sql, reference<list> args, *hash qh);
11379 public:
11380 
11382 
11383 private:
11384  abstract copyImpl(AbstractTable old);
11385 public:
11386  };
11387 }
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5767
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:7619
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:6054
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2321
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2126
const Hash
any column
column sopecifier, may be a string or a complex hash
Definition: SqlUtil.qm.dox.h:2113
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:7821
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:4795
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:5133
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:7637
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:2085
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:2112
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:4313
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:7569
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2412
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:2172
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:7607
const COP_FIRST_VALUE
Analytic (window) function: FIRST_VALUE.
Definition: SqlUtil.qm.dox.h:2373
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:7726
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:5225
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:6102
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:7905
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:7840
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:2118
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:7867
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:4308
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:5661
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:2120
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:5644
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4326
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:2276
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:5959
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:7896
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:7879
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:7771
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:2366
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:4268
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:2266
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:6132
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:6006
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:5476
const COP_SEQ_CURRVAL
to return the last value of a sequence issued in the same session
Definition: SqlUtil.qm.dox.h:2326
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:5580
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:3769
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:2195
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4258
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2178
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2261
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:2156
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:2150
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3761
base class for sequences
Definition: SqlUtil.qm.dox.h:6049
*hash upsertFromIteratorCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
*list getCreateTriggersSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
const COP_LAST_VALUE
Analytic (window) function: LAST_VALUE.
Definition: SqlUtil.qm.dox.h:2380
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:5482
abstract hash getQoreTypeMapImpl()
returns the qore type -> column type map
any arg
optional argument
Definition: SqlUtil.qm.dox.h:2107
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:7759
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2246
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:2316
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:7599
*hash opt
optional join options (for example, to specify a partition for the join if supported) ...
Definition: SqlUtil.qm.dox.h:2138
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:7925
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:7931
*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:2133
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:2132
const IOP_SEQ_CURRVAL
for using the last value of a sequence issued in the current session
Definition: SqlUtil.qm.dox.h:4792
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:6372
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:7805
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:4298
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:6302
const SqlUtilDrivers
known drivers
Definition: SqlUtil.qm.dox.h:4842
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4288
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:6028
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:6033
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:5585
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:5823
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:2271
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:4303
const COP_NTILE
Analytic (window) function: NTILE.
Definition: SqlUtil.qm.dox.h:2387
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:2089
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4851
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:2131
any default_value
the default value for the column
Definition: SqlUtil.qm.dox.h:2091
the SqlUtil namespace contains all the objects in the SqlUtil module
Definition: SqlUtil.qm.dox.h:2079
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:7917
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:6254
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:2114
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:5828
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:7923
const DT_DAY
Format unit: day.
Definition: SqlUtil.qm.dox.h:3491
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:2152
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:2236
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:2136
const COP_PLUS
the SQL "plus" operator
Definition: SqlUtil.qm.dox.h:2286
const Boolean
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:7870
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:4263
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:5598
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2201
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:7578
*bool auto_increment
True for DBs that support an auto-increment column
Definition: SqlUtil.qm.dox.h:2101
*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:2164
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:5485
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:7921
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:2331
string op
the operator string code
Definition: SqlUtil.qm.dox.h:2106
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:7935
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:7660
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:7929
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:2154
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:6566
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4273
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:2081
int del()
SqlUtil::AbstractTable::del() variant
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:5488
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:6099
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:5652
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:2306
string src
the source of the object
Definition: SqlUtil.qm.dox.h:6138
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:2256
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:2343
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:2211
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:7919
*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:2162
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:4253
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2181
string name
the name of the index
Definition: SqlUtil.qm.dox.h:5649
string _iop
the insert operator string code
Definition: SqlUtil.qm.dox.h:2119
*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:6014
string uop
the update operator string code
Definition: SqlUtil.qm.dox.h:2125
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:4283
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5853
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:2158
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:2184
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4318
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:5655
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:7733
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:6127
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:2160
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:2124
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:2359
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:7885
string name
the name of the column
Definition: SqlUtil.qm.dox.h:5470
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:6377
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:6172
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:2296
column operator info hash as returned by all column operator functions
Definition: SqlUtil.qm.dox.h:2111
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:7927
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:2221
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:2352
*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:6088
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:6383
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:7748
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:7614
*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:6135
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:2301
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:5479
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:2099
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:5473
const COP_VALUE
to append a constant value (SQL Literal) to use as an output column value
Definition: SqlUtil.qm.dox.h:2231
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:7835
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:5413
the base class for triggers
Definition: SqlUtil.qm.dox.h:6236
*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:2137
*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:4248
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:6379
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:6198
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:7876
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:7873
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6307
the base class for column information
Definition: SqlUtil.qm.dox.h:5465
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:2216
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:7828
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:4293
const DT_MINUTE
Format unit: minute.
Definition: SqlUtil.qm.dox.h:3497
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:3494
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:7477
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:7588
*string comment
an optional comment for the column
Definition: SqlUtil.qm.dox.h:2095
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:3511
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2251
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:7814
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:2311
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:7797
const DT_MONTH
Format unit: month.
Definition: SqlUtil.qm.dox.h:3488
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:6096
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:2394
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:2135
*number max
the ending number
Definition: SqlUtil.qm.dox.h:6063
hash getUpdateOperatorMap()
returns the update operator map for this object
const COP_RANK
Analytic (window) function: RANK.
Definition: SqlUtil.qm.dox.h:2401
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:7705
number increment
the increment
Definition: SqlUtil.qm.dox.h:6060
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:4243
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:7681
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2192
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:7482
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:4278
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2281
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:6011
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:7647
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:2134
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2336
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:3766
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:4323
*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:2198
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:2087
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:2105
number start
the starting number
Definition: SqlUtil.qm.dox.h:6057
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4787
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:6434
const COP_ROW_NUMBER
Analytic (window) function: ROW_NUMBER.
Definition: SqlUtil.qm.dox.h:2408
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:3485
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:5861
represents a primary key
Definition: SqlUtil.qm.dox.h:5948
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3756
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2241
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:2127
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:2291
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:2148
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2175
*hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:5858
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:7852
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:2083
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:7596
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:4329
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5939
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:7721
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:5758
const DT_SECOND
Format unit: hour.
Definition: SqlUtil.qm.dox.h:3500
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:5716
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2226