Qore SqlUtil Module Reference  1.3
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 - 2016 Qore Technologies, sro
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.12 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  ...
344  @endcode
345  @warning Oracle: using different comments in the same SQL can lead to new optimizer statement hard parsing.
346 
347  @anchor select_option_hint
348  @par Select Option "hint"
349  In database query operations, various SQL implementations use hints as additions to the SQL standard that instruct the database engine on how to execute the query. For example, a hint may tell the engine to use as little memory as possible (even if the query will run slowly), or to use or not to use an index (even if the query optimizer would decide otherwise).
350 
351  <b>Hint Example:</b>
352  @code{.py}
353 table.selectRows( ("hint" : "full(t1)") );
354  @endcode
355  will produce select statement like this:
356  @code{.py}
357 select /*+ full(a) */ ...
358  @endcode
359  The string is taken as is and it's up to user to handle correct aliases in join functions etc.
360  @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
361  @warning Use hints only when you know what you are doing.
362 
363  @anchor select_option_columns
364  @par Select Option "columns"
365  <b>Columns Example:</b>
366  @code{.py}
367 list columns = ("id", "name", "started", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"));
368 *list rows = table.selectRows(("columns": columns, "where": ("type": "user")));
369  @endcode
370  By default, all columns are returned from a query; to limit the columns returned, or to perform column operations on the columns returned, use the \c "columns" option of the @ref select_option_hash "select option hash". \n\n
371  This option takes a list, each element of the list can be one of the following.\n\n
372  <b>A Simple String Giving a Column Name</b>\n
373  ex: \c "name"
374  @code{.py}
375 *list rows = table.selectRows(("columns": ("id", "name", "started")));
376  @endcode \n
377  <b>A String in Dot Notation</b>\n
378  This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
379  @code{.py}
380 *list rows = table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner(table2, "t2", ("id": "altid"))));
381  @endcode \n
382  <b>A Column Operation Specified by a Column Operator Function</b>\n
383  ex: <tt>cop_as("column_name", "column_alias")</tt> \n
384  See @ref sql_cop_funcs "column operator function" for more information on column operator functions
385  @code{.py}
386 *list rows = table.selectRows(("columns": ("id", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"))));
387  @endcode
388  For @ref sql_cop_funcs "column operator functions" taking a column name, either a string name or a name in dot notation is acceptable\n\n
389  <b>The Value \c "*", Meaning All Columns</b>\n
390  ex: \c "*"
391  @code{.py}
392 *list rows = table.selectRows(("columns": "*"));
393  @endcode
394  This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
395  <b>An \c "*" in Dot Notation</b>\n
396  ex: \c "q.*"
397  @code{.py}
398 *list rows = table.selectRows(("columns": ("table.id", "t2.*"), "join": join_inner(table2, "t2", ("id": "altid"))));
399  @endcode
400 
401  @anchor select_option_where
402  @par Select Option "where"
403  <b>Where Example:</b>
404  @code{.py}
405 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
406  @endcode
407  The hash value assigned to this key describes how the \c "where" clause in the query is built. Because the \c "where" clause logic is common to many SQL methods, this topic is covered in a separate section. See @ref where_clauses for a detailed description of the value of this key.
408 
409  @anchor select_option_orderby
410  @par Select Option "orderby"
411  <b>Orderby Example:</b>
412  @code{.py}
413 *list rows = table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date"));
414  @endcode
415  This option is a list of the following values:
416  - a simple string giving a column name; ex: \c "name"
417  - a simple string with a column name preceded by a \c "-" sign; ex: \c "-name", meaning that that column should be sorted in descending order
418  - a string giving a table or table alias and a column name in dot notation (for use with @ref select_option_join "joins"); ex: \c "q.name"
419  - a positive integer giving the column number for the ordering
420  @note
421  - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
422 
423  @anchor select_option_desc
424  @par Select Option "desc"
425  <b>Desc Example:</b>
426  @code{.py}
427 *list rows = table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date", "desc": True));
428  @endcode
429  If the value of this key is @ref Qore::True "True" and results are ordered (either due to the @ref select_option_orderby "orderby option" or due to implicit ordering by the primary key due to the use of the @ref select_option_offset "offset option"), then results will be sorted in descending order.\n\n
430  Otherwise, ordered results are returned in ascending order by default.
431 
432  @note per-column descending options can be given by prepending a \c "-" character to the column name in the @ref select_option_orderby "orderby option list"
433 
434  @anchor select_option_limit
435  @par Select Option "limit"
436  <b>Limit Example:</b>
437  @code{.py}
438 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
439  @endcode
440  This option will limit the number of rows returned.
441  @note
442  - This option is required if the @ref select_option_offset "offset option" is non-zero
443  - If this option is present and an @ref select_option_orderby "orderby option" is also present, then at least a subset of the @ref select_option_orderby "orderby" columns must correspond to a unique key of the table or an exception is raised
444 
445  @anchor select_option_offset
446  @par Select Option "offset"
447  <b>Offset Example:</b>
448  @code{.py}
449 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
450  @endcode
451  This option specifies the row number offset for the rows returned where the first row is at offset zero.
452  @note
453  - If this option is present, then either an @ref select_option_orderby "orderby option" must be present of which at least a subset of the @ref select_option_orderby "orderby" columns must correspond to a unique key of the table, or, if no @ref select_option_orderby "orderby option" is used, then the table must have a primary key which is used for the ordering instead.
454  - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
455  @see @ref sql_paging
456 
457  @anchor select_option_join
458  @par Select Option "join"
459  <b>Join Example:</b>
460  @code{.py}
461 *list rows = table.selectRows(("columns": ("name", "version", "id", cop_as("st.value", "source"), cop_as("st.value", "offset")),
462  "join": join_left(function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
463  + join_left(function_instance_tags, "lt", NOTHING, ("st.tag": "_offset"))));
464  @endcode
465  To join multiple tables in a single query, use the \c "join" option. The \c "join" hash key should be assigned to a join description hash as returned by one of the @ref sql_jop_funcs or combined join description hash created by concatenating such values (see an example of this above).
466  @note the join columns do not need to be specified in the case that a foreign key in one table exists to the primary key of the other table; in this case this information is assumed for the join automatically
467 
468  @see @ref joins for more examples
469 
470  @anchor select_option_groupby
471  @par Select Option "groupby"
472  <b>Groupby Example:</b>
473  @code{.py}
474 *list rows = table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type"));
475  @endcode
476  The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
477  The \c "groupby" hash key should be assigned to a list of column specifiers or a single column specifier. Column specifiers for the \c "groupby"
478  key are strings giving column names, optionally in dot notation or positive column numbers.
479 
480  @anchor select_option_having
481  @par Select Option "having"
482  <b>Having Example:</b>
483  @code{.py}
484 *list rows = table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type", "having": ("service_type": (COP_COUNT, op_ge(100)))));
485  @endcode
486  The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
487  The \c "having" hash key should be assigned to a hash where each key is a column specifier (optionally in dot notation) and the values are lists with two elements; the first element must be a @ref sql_cops "column operator code", and the second element is a column operator description normally provided by using a @ref sql_cop_funcs "column operator function" as in the above example.
488 
489  @anchor select_option_superquery
490  @par Select Option "superquery"
491  <b>Superquery Example:</b>
492  @code{.py}
493 *list rows = table.selectRows("columns": ("serviceid", "service_methodid", cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid")), "superquery": ("columns": ("serviceid", "service_methodid"), "where": ("max_methodid": op_ceq("service_methodid"))));
494  @endcode
495  The \c "superquery" option allows for the rest of the query arguments to define a subquery where as the hash arguments assigned to the \c "superquery" key define the select made from the subquery. In the example above, the \c "OVER" sql windowing function is used and then rows matching the \c "max_methodid)" result value are selected.\n\n
496  The above example results in an SQL command equivalent to the following:
497  @code{.py}
498 *list rows = table.vselectRows("select serviceid,service_methodid from (select serviceid,service_methodid,max(service_methodid) over (partition by serviceid) as max_methodid from schema.service_methods) subquery where max_methodid = service_methodid");
499  @endcode
500  @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
501 
502  @anchor select_option_forupdate
503  @par Select Option "forupdate"
504  <b>For Update Example:</b>
505  @code{.py}
506 on_success ds.commit();
507 on_error ds.rollback();
508 
509 *list rows = table.selectRows("columns": ("serviceid", "service_methodid"), "forupdate": True);
510  @endcode
511  \n The \c "forupdate" option allows for the rows selected to be locked for updating; to release the locks, call commit() or rollback() on the underlying datasource object.
512  The above example results in an SQL commit equivalent to the following:
513  @code{.py}
514 *list rows = table.vselectRows("select serviceid,service_methodid from schema.service_methods for update");
515  @endcode
516 
517  @subsection sql_paging Select With Paging
518 
519  There is support for paging query results in the following methods:
520  - @ref SqlUtil::AbstractTable::getRowIterator()
521  - @ref SqlUtil::AbstractTable::getSelectSql()
522  - @ref SqlUtil::AbstractTable::select()
523  - @ref SqlUtil::AbstractTable::selectRows()
524 
525  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
526 
527  Each of these methods takes a @ref select_option_hash "select option hash argument" that allows the \c "limit" and \c "offset" options to be specified to specify the data window for the results.
528 
529  If the \c "offset" options is used, then an \c "orderby" option is required which must match some unique constraint or unique index on the table to guarantee the order of results, unless the table has a primary key, in which case the primary key will be used by default if no \c "orderby" option is supplied.
530 
531  @par Example:
532  Select 100 rows starting at row 200 (the table's primary key will be used for the \c "orderby" option by default): \n
533  @code{.py}
534 *list rows = table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
535  @endcode
536  As an illustration of the different SQL that is generated for different database types; for the above query, here is the SQL generated for Oracle:
537  @code{.py}
538 ds.vselectRows("select * from (select /*+ first_rows(100) */ a.*, rownum rnum from (select * from schema.table where type = %v order by type) a where rownum <= %v) where rnum > %v", ("user", 300, 200));
539  @endcode
540  And for PostgreSQL:
541  @code{.py}
542 ds.vselectRows("select * from public.table where type = %v order by type limit %v offset %v", ("user", 100, 200));
543  @endcode
544 
545  @subsection check_matching_rows Check For At Least One Matching Row
546 
547  Use the @ref SqlUtil::AbstractTable::findSingle() method to find at least one matching row:
548  @code{.py}
549 *hash h = table.findSingle(("account_type": "CUSTOMER"));
550 if (h)
551  printf("found 1 customer row: %y\n", l[0]);
552  @endcode
553 
554  Also it's possible to use the \c "limit" option to make an efficient check for at least one matching row as in the following example (which is functionally equivalent to the previous example):
555  @code{.py}
556 *hash h = table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
557 if (h)
558  printf("found 1 customer row: %y\n", l[0]);
559  @endcode
560 
561  @section inserting_data Inserting Data into the Database
562 
563  The following methods can be used to insert data into the database:
564  - @ref SqlUtil::AbstractTable::insert(): inserts a single row into a table without committing the transaction
565  - @ref SqlUtil::AbstractTable::insertCommit(): inserts a single row into a table and commits the transaction
566  - @ref SqlUtil::AbstractTable::insertFromSelect(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and without committing the transaction
567  - @ref SqlUtil::AbstractTable::insertFromSelectCommit(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and commits the transaction
568 
569  @see @ref sql_upsert for information about upserting or merging data
570 
571  @subsection inserting_data_explicitly Inserting Data Explicitly
572 
573  @par Example:
574  @code{.py}
575 table.insert(("id": id, "name": name, "created": now_us()));
576  @endcode
577 
578  Data can be explicitly inserted into the database with immediate values with @ref SqlUtil::AbstractTable::insert() and @ref SqlUtil::AbstractTable::insertCommit() as in the above example.
579 
580  Additionally, instead of giving a literal value to be inserted, @ref sql_iop_funcs can be used to insert values based on SQL operations used directly in the insert statement.
581 
582  @subsection inserting_data_from_select Inserting Data From a Select Statement
583 
584  @par Example:
585  @code{.py}
586 int rows = table.insertFromSelect(("id", "name", "created"), source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER"))));
587  @endcode
588 
589  Data can be inserted into the database based on the results of a select statement with @ref SqlUtil::AbstractTable::insertFromSelect() and @ref SqlUtil::AbstractTable::insertFromSelectCommit() as in the above example.
590 
591  The example above would generate a %Qore SQL command like the following:
592  @code{.py}
593 return ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER"));
594  @endcode
595 
596  The return value of these methods is the number of rows inserted. See @ref select_option_hash "select option hash" for more information about how to form the select criteria in these methods.
597 
598  @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
599 
600  To insert data from an iterator source (such as an @ref Qore::SQL::SQLStatement object), call @ref SqlUtil::AbstractTable::insertFromIterator() or @ref SqlUtil::AbstractTable::insertFromIteratorCommit() as in the following example:
601 
602  @par Example:
603  @code{.py}
604 # get the rows to be inserted
605 list l = get_table_rows();
606 # insert the data and commit after every 5000 rows
607 table.insertFromIterator(l.iterator(), ("commit_block": 5000));
608  @endcode
609 
610  The iterator given to the @ref SqlUtil::AbstractTable::insertFromIterator() or @ref SqlUtil::AbstractTable::insertFromIteratorCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
611 
612  @note the @ref SqlUtil::AbstractTable::InsertFromIteratorOptions "insert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
613 
614  @section updating_data Updating Data
615 
616  The following methods can be used to update data:
617  - @ref SqlUtil::AbstractTable::update(): updates a single row and does not commit the transaction
618  - @ref SqlUtil::AbstractTable::updateCommit(): updates a single row and commits the transaction
619 
620  @par Example:
621  @code{.py}
622 int rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
623  @endcode
624 
625  The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
626  @code{.py}
627 return ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
628  @endcode
629  And the following on MySQL:
630  @code{.py}
631 return ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
632  @endcode
633 
634  @section deleting_data Deleting Data
635 
636  The following methods can be used to dekete data:
637  - @ref SqlUtil::AbstractTable::del(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
638  - @ref SqlUtil::AbstractTable::delCommit(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
639  - @ref SqlUtil::AbstractTable::truncate(): truncates the table and does not commit the transaction
640  - @ref SqlUtil::AbstractTable::truncateCommit(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
641 
642  @par Example:
643  @code{.py}
644 int dcnt = table.del(("record_type": "OLD-CUSTOMER"));
645  @endcode
646 
647  The above example would generate a %Qore SQL command like the following:
648  @code{.py}
649 return ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
650  @endcode
651 
652  The @ref SqlUtil::AbstractTable::del() and @ref SqlUtil::AbstractTable::delCommit() methods can be used to delete data from the database.
653 
654  See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
655 
656  @section joins Joining Tables
657 
658  Joining tables is made by providing a join specification to the @ref select_option_join "join select option" in
659  a @ref select_option_hash "select option hash" as in the following example:
660  @code{.py}
661 *list rows = table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner(table2, "t2", ("id": "altid"))));
662  @endcode
663  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
664 
665  Joins on multiple tables are performed by combining the results of @ref sql_op_funcs "join functions" with the @ref plus_operator "+ operator"
666  as follows:
667  @code{.py}
668 *list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner(table3, "t3")));
669  @endcode
670  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
671  automatically detected primary key to foreign key relationship between the two tables.
672 
673  Joins are by default made with the primary table; to join with another join table, then give the alias for the table as the first
674  argument to the @ref sql_op_funcs "join function" as in the following example:
675  @code{.py}
676 *list rows = table.selectRows(("join": join_inner(table2, "t2", ("id": "altid")) + join_inner("t2", table3, "t3")));
677  @endcode
678  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and \a table2 (aliased as \c t2) is joined
679  with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
680 
681  @see @ref select_option_join "join select option"
682 
683  @section where_clauses Where Clauses
684 
685  Several methods accept a hash of conditions to build a \c "where" clause to restrict the rows that are operated on or returned; for example:
701 
702  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
703 
704  The where clause or condition hash is made of keys signifying the column names, and either a direct value meaning that the column value has to match exactly, or SQL operators can be given by using the appropriate operator function as the key value. Each member of the where hash translates to an expression that is combined with \c "AND" in the SQL query; to combine expressions with \c "OR", there are two options:
705  - use the @ref SqlUtil::wop_or() function to combine where expressions with the \c "or" operator
706  - use a list of @ref select_option_hash "select option hashes", which will combine each @ref select_option_hash "select option hash" with \c "OR" as in @ref where_list "this example".
707 
708  The where condition hash has the following format:
709  - each key gives a column name or a table/alias with column name in dot notation
710  - the values are either direct values, meaning that the equality operator (\c "=") is used, or a @ref sql_op_funcs "SQL operator function" for operators in the where clause
711 
712  @note To reference a column more than once in a where clause, prefix the column specification with a unique number and a colon as in the following example: @code{.py} hash w = ("0:created": op_ge(mindate), "1:created": op_lt(maxdate)); @endcode
713 
714  See @ref sql_op_funcs for a list of operator functions.
715 
716  @par Where Hash Example:
717  @code{.py}
718 hash w = (
719  "name": "Smith",
720  "account_type": op_like("%CUSTOMER%"),
721  "id": op_ge(500),
722 );
723  @endcode \n
724  The preceding example results in a where clause equivalent to: \c "name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
725  that bind by value is used, so, if used in a context like the following:
726  @code{.py}
727 Table t(ds, "table");
728 *hash qh = t.select(("where": w));
729  @endcode \n
730  the complete query would look instead as follows:
731  @code{.py}
732 ds.vselect("select * from table where name = %v and account_type like %v and id >= %v", ("Smith", "%CUSTOMER%", 500));
733  @endcode
734 
735  @anchor where_list
736  @par Where List Example:
737  @code{.py}
738 hash w1 = (
739  "name": "Smith",
740  "account_type": op_like("%CUSTOMER%"),
741  "id": op_ge(500),
742 );
743 hash w2 = (
744  "name": "Jones",
745  "account_type": op_like("%VENDOR%"),
746  "id": op_ge(2500),
747 );
748 Table t(ds, "table");
749 *hash qh = t.select(("where": (w1, w2)));
750  @endcode \n
751  the complete query would look instead as follows:
752  @code{.py}
753 ds.vselect("select * from table where (name = %v and account_type like %v and id >= %v) or (name = %v and account_type like %v and id >= %v)", ("Smith", "%CUSTOMER%", 500, "Jones", "%VENDOR%", 2500));
754  @endcode
755 
756  @par Code Examples:
757  Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
758  @code{.py}
759 *hash row = table.findSingle(("permission_type": op_between("US", "UX")));
760  @endcode
761  resulting in an internal SQL command that looks as follows (depending on the database):
762  @code{.py}
763 *hash row = ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
764  @endcode \n
765  Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
766  @code{.py}
767 int row_count = table.del(("name": op_like("%Smith%")));
768  @endcode
769  resulting in an internal SQL command that looks as follows:
770  @code{.py}
771 ds.vexec("delete from table where name like %v", ("%Smith%"));
772  @endcode \n
773  Find all rows where \c "id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
774  @code{.py}
775 *list rows = table.findAll(("id": op_gt(100), "created": op_gt(2013-03-01)));
776  @endcode
777  resulting in an internal SQL command that looks as follows:
778  @code{.py}
779 ds.vexec("select * from table where id > %v and created > %v", (100, 2013-03-01));
780  @endcode \n
781 
782  @section sql_upsert Upserting or Merging Data
783 
784  This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
793 
794  @subsection sql_upsert_single Upsert a Single Row
795 
796  @par Example:
797  @code{.py}
798 table.upsert(("id": id, "name": name, "account_type": account_type));
799  @endcode
800 
801  To upsert or merge a single row in the database, call @ref SqlUtil::AbstractTable::upsert() or @ref SqlUtil::AbstractTable::upsertCommit() with the
802  single row to be upserted or merged as a hash as in the preceding example.
803 
804  @subsection sql_upsert_many Upserting Many Rows Using An Upsert Closure
805 
806  To upsert or merge many rows by using an upsert closure, call @ref SqlUtil::AbstractTable::getUpsertClosure() or @ref SqlUtil::AbstractTable::getUpsertClosureWithValidation() and provide an example row as an argument to acquire a closure that will be executed on the rest of the rows as in the following example.
807 
808  @par Simple Example:
809  @code{.py}
810 # get the rows to be inserted
811 list l = get_table_rows();
812 
813 if (l) {
814  code upsert = table.getUpsertClosure(l[0]);
815 
816  on_success ds.commit();
817  on_error ds.rollback();
818 
819  # loop through the reference data rows
820  map upsert($1), l;
821 }
822  @endcode
823 
824  @par Complex Example With Callbacks:
825  @code{.py}
826 # set the upsert strategy depending on the use case
827 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
828 
829 # hash summarizing changes
830 hash sh;
831 
832 # get the rows to be inserted
833 list l = get_table_rows();
834 
835 if (l) {
836  # get the upsert closure to use based on the first row to be inserted
837  code upsert = table.getUpsertClosure(l[0], upsert_strategy);
838 
839  on_success ds.commit();
840  on_error ds.rollback();
841 
842  # loop through the reference data rows
843  foreach hash h in (l) {
844  int code = upsert(h);
845  if (code == AbstractTable::UR_Unchanged)
846  continue;
847 
848  string change = AbstractTable::UpsertResultMap{code};
849  ++sh{change};
850 
851  if (!verbose) {
852  printf(".");
853  flush();
854  }
855  else if (verbose > 1)
856  printf("*** reference data %s: %y: %s\n", table.getName(), h, change);
857  }
858 
859  # show table summary
860  if (sh)
861  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
862  else
863  printf("*** reference data %s: OK\n", table.getName());
864 }
865  @endcode
866 
867  @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
868 
869  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:
870 
871  @par Simple Example:
872  @code{.py}
873 # get the rows to be inserted
874 list l = get_table_rows();
875 table.upsertFromIterator(l.iterator());
876  @endcode
877 
878  @par Complex Example With Callbacks:
879  @code{.py}
880 # set the upsert strategy depending on the use case
881 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
882 
883 # get the rows to be inserted
884 list l = get_table_rows();
885 
886 code callback = sub (string table_name, hash row, int result) {
887  if (result == AbstractTable::UR_Unchanged)
888  return;
889  string change = AbstractTable::UpsertResultMap{result};
890  if (verbose)
891  printf("*** reference data %s: %y: %s\n", table_name, row, change);
892 };
893 
894 hash sh = table.upsertFromIterator(l.iterator(), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
895 if (sh)
896  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
897 else
898  printf("*** reference data %s: OK\n", table.getName());
899  @endcode
900 
901  The iterator given to the @ref SqlUtil::AbstractTable::upsertFromIterator() or @ref SqlUtil::AbstractTable::upsertFromIteratorCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
902 
903  @note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
904 
905  @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
906 
907  To upsert or merge many rows from a select statement, use @ref SqlUtil::AbstractTable::upsertFromSelect() or @ref SqlUtil::AbstractTable::upsertFromSelectCommit() as in the following example:
908 
909  @par Simple Example:
910  @code{.py}
911 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")));
912  @endcode
913 
914  @par Complex Example With Callbacks:
915  @code{.py}
916 # set the upsert strategy depending on the use case
917 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
918 
919 code callback = sub (string table_name, hash row, int result) {
920  if (result == AbstractTable::UR_Unchanged)
921  return;
922  string change = AbstractTable::UpsertResultMap{result};
923  if (verbose)
924  printf("*** reference data %s: %y: %s\n", table_name, row, change);
925 };
926 
927 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, False, ("info_callback": callback, "commit_block": 5000));
928 if (sh)
929  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
930 else
931  printf("*** reference data %s: OK\n", table.getName());
932  @endcode
933 
934  The source table does not have to be in the same database or even of the same database type (ie you can upsert to and from any database type supported by SqlUtil).
935 
936  @note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
937 
938  @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
939 
940  Call any of the batch upsert methods with @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c delete_others set to @ref Qore::True "True" to perform a batch upsert / merge operation on a table, and then scan the table and delete any unwanted rows. If there are no rows to be deleted, these calls have very similar performance to the batch upsert method calls without any deletions, however, if there are rows to be deleted, then the entire source table must be iterated to compare each row to valid data to delete the rows that do not belong. Therefore for large tables this can be an expensive operation.
941 
942  The only difference in the following examples and the preceding ones is that @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c delete_others is @ref Qore::True "True" in these examples.
943 
944  @par Simple Example:
945  @code{.py}
946 # get the rows to be inserted
947 list l = get_table_rows();
948 table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
949  @endcode
950 
951  @par Complex Example With Callbacks:
952  @code{.py}
953 # set the upsert strategy depending on the use case
954 int upsert_strategy = verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
955 
956 # get the rows to be inserted
957 list l = get_table_rows();
958 
959 code callback = sub (string table_name, hash row, int result) {
960  if (result == AbstractTable::UR_Unchanged)
961  return;
962  string change = AbstractTable::UpsertResultMap{result};
963  if (verbose)
964  printf("*** reference data %s: %y: %s\n", table_name, row, change);
965 };
966 
967 hash sh = table.upsertFromSelect(table2, ("where": ("account_type": "CUSTOMER")), upsert_strategy, ("delete_others": True, "info_callback": callback, "commit_block": 5000));
968 if (sh)
969  printf("*** reference data %s: %s\n", table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
970 else
971  printf("*** reference data %s: OK\n", table.getName());
972  @endcode
973 
974  @note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
975 
976  @subsection sql_upsert_strategies Upsert Strategies
977  The approach used is based on one of the following strategies (see @ref upsert_options):
978  - @ref SqlUtil::AbstractTable::UpsertAuto "AbstractTable::UpsertAuto": if the target table is empty, then @ref SqlUtil::AbstractTable::UpsertInsertFirst is used, otherwise @ref SqlUtil::AbstractTable::UpsertUpdateFirst is used; note that if a driver-specific optimized version of the upsert operation is implemented, this strategy will normally result in the best performance
979  - @ref SqlUtil::AbstractTable::UpsertInsertFirst "AbstractTable::UpsertInsertFirst": first an insert will be attempted, if it fails due to a duplicate key, then an update will be made; this strategy should be used if more inserts will be made than updates
980  - @ref SqlUtil::AbstractTable::UpsertUpdateFirst "AbstractTable::UpsertUpdateFirst": first an update will be attempted, if it fails due to missing data, then an insert is performed; this strategy should be used if more updates will be made then inserts
981  - @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
982  - @ref SqlUtil::AbstractTable::UpsertInsertOnly "AbstractTable::UpsertInsertOnly": insert if the row doesn't exist, otherwise do nothing and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
983  - @ref SqlUtil::AbstractTable::UpsertUpdateOnly "AbstractTable::UpsertUpdateOnly": update if the row exists, otherwise do nothing and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
984 
985  @note @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" is the only upsert strategy that can return @ref SqlUtil::AbstractTable::UR_Updated; the @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" strategy should be used when verbose reporting is required, particularly if it's necessary to report the actual number of changed rows.
986 */
1968 namespace SqlUtil {
1970 
1971  /* @defgroup DBFeaturesConstants DB Features Constants
1972  These constants can be used as a lookup values in AbstractDatabase::features() method.
1973  */
1975 
1978  const DB_FUNCTIONS = "functions";
1980  const DB_MVIEWS = "materialized views";
1982  const DB_PACKAGES = "packages";
1984  const DB_PROCEDURES = "procedures";
1986  const DB_SEQUENCES = "sequences";
1988  const DB_TABLES = "tables";
1990  const DB_TYPES = "named types";
1992  const DB_VIEWS = "views";
1994  const DB_SYNONYMS = "synonyms";
1996 
1997  /* @defgroup SqlTypeConstants SQL Type Constants
1998  These constants can be used for the \c "qore_type" values when creating columns to specify additional SQL column types
1999  */
2001  const VARCHAR = "string";
2003 
2005  const NUMERIC = "number";
2006 
2008  const CHAR = "char";
2009 
2011  const BLOB = "blob";
2012 
2014  const CLOB = "clob";
2016 
2021  const SZ_NONE = 0;
2023 
2025  const SZ_MAND = 1;
2026 
2028  const SZ_OPT = 2;
2029 
2031  const SZ_NUM = 3;
2033 
2038 
2041  const COP_AS = "as";
2042 
2044 
2046  const COP_CAST = "cast";
2047 
2049 
2051  const COP_PREPEND = "prepend";
2052 
2054 
2056  const COP_APPEND = "append";
2057 
2059 
2061  const COP_VALUE = "value";
2062 
2064 
2066  const COP_UPPER = "upper";
2067 
2069 
2071  const COP_LOWER = "lower";
2072 
2074 
2076  const COP_DISTINCT = "distinct";
2077 
2079 
2081  const COP_MIN = "min";
2082 
2084 
2086  const COP_MAX = "max";
2087 
2089 
2091  const COP_AVG = "avg";
2092 
2094 
2096  const COP_SUM = "sum";
2097 
2099 
2101  const COP_COUNT = "count";
2102 
2104 
2106  const COP_OVER = "over";
2107 
2109 
2111  const COP_MINUS = "minus";
2112 
2114 
2116  const COP_PLUS = "plus";
2117 
2119 
2121  const COP_DIVIDE = "divide";
2122 
2124 
2126  const COP_MULTIPLY = "multiply";
2127 
2129 
2131  const COP_YEAR = "year";
2132 
2134 
2136  const COP_YEAR_MONTH = "year_month";
2137 
2139 
2141  const COP_YEAR_DAY = "year_day";
2142 
2144 
2146  const COP_YEAR_HOUR = "year_hour";
2147 
2149 
2151  const COP_SEQ = "seq";
2152 
2154 
2156  const COP_SEQ_CURRVAL = "seq_currval";
2157 
2159 
2161  const COP_COALESCE = "coalesce";
2162 
2164 
2166  const COP_SUBSTR = "substr";
2167 
2169  const DefaultCopMap = (
2170  COP_AS: (
2171  "arg": Type::String,
2172  "withalias": True,
2173  "code": string (string cve, string arg, reference psch) {
2174  psch{arg} = cve;
2175  return sprintf("%s as %s", cve, arg);
2176  },
2177  ),
2178  COP_PREPEND: (
2179  "arg": Type::String,
2180  "sqlvalue": True,
2181  "code": string (string cve, string arg) {
2182  return sprintf("%s || %s", arg, cve);
2183  },
2184  ),
2185  COP_APPEND: (
2186  "arg": Type::String,
2187  "sqlvalue": True,
2188  "code": string (string cve, string arg) {
2189  return sprintf("%s || %s", cve, arg);
2190  },
2191  ),
2192  COP_VALUE: (
2193  "sqlvalue": True,
2194  "nocolumn": True,
2195  "code": string (*string cve, any arg) {
2196  return arg;
2197  },
2198  ),
2199  COP_UPPER: (
2200  "code": string (string cve, any arg) {
2201  return sprintf("upper(%s)", cve);
2202  },
2203  ),
2204  COP_LOWER: (
2205  "code": string (string cve, any arg) {
2206  return sprintf("lower(%s)", cve);
2207  },
2208  ),
2209  COP_DISTINCT: (
2210  "code": string (string cve, any arg) {
2211  return sprintf("distinct %s", cve);
2212  },
2213  ),
2214  COP_MIN: (
2215  "code": string (string cve, any arg) {
2216  return sprintf("min(%s)", cve);
2217  },
2218  "group": True,
2219  ),
2220  COP_MAX: (
2221  "code": string (string cve, any arg) {
2222  return sprintf("max(%s)", cve);
2223  },
2224  "group": True,
2225  ),
2226  COP_AVG: (
2227  "code": string (string cve, any arg) {
2228  return sprintf("avg(%s)", cve);
2229  },
2230  "group": True,
2231  ),
2232  COP_SUM: (
2233  "code": string (string cve, any arg) {
2234  return sprintf("sum(%s)", cve);
2235  },
2236  "group": True,
2237  ),
2238  COP_COUNT: (
2239  "nocolumn": True,
2240  "code": string (*string cve, any arg) {
2241  return sprintf("count(%s)", cve ? cve : "*");
2242  },
2243  ),
2244  COP_MINUS: (
2245  "argcolumn": True,
2246  "code": string (string arg1, string arg2) {
2247  return sprintf("%s - %s", arg1, arg2);
2248  },
2249  ),
2250  COP_PLUS: (
2251  "argcolumn": True,
2252  "code": string (string arg1, string arg2) {
2253  return sprintf("%s + %s", arg1, arg2);
2254  },
2255  ),
2256  COP_DIVIDE: (
2257  "argcolumn": True,
2258  "code": string (string arg1, string arg2) {
2259  return sprintf("%s / %s", arg1, arg2);
2260  },
2261  ),
2262  COP_MULTIPLY: (
2263  "argcolumn": True,
2264  "code": string (string arg1, string arg2) {
2265  return sprintf("%s * %s", arg1, arg2);
2266  },
2267  ),
2268  COP_SEQ: (
2269  "nocolumn": True,
2270  "code": string (*string cve, hash arg) {
2271  throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg.seq);
2272  }
2273  ),
2274  COP_SEQ_CURRVAL: (
2275  "nocolumn": True,
2276  "code": string (*string cve, hash arg) {
2277  throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg.seq);
2278  }
2279  ),
2280  COP_COALESCE: (
2281  "columnargs": True,
2282  "code": string (*string cve, hash arg) {
2283  return sprintf("coalesce(%s)", (foldl $1 + "," + $2, arg.args));
2284  }
2285  ),
2286  COP_SUBSTR: (
2287  "code": string (string cve, list args) {
2288  if (!exists args[1])
2289  return sprintf("substring(%s from %d)", cve, args[0]);
2290  return sprintf("substring(%s from %d for %d)", cve, args[0], args[1]);
2291  },
2292  ),
2293  );
2295 
2313 
2322  hash make_cop(string cop, any column, any arg);
2323 
2324 
2326 
2338  hash cop_as(any column, string arg);
2339 
2340 
2342 
2356  hash cop_cast(any column, string arg, *any arg1, *any arg2);
2357 
2358 
2360 
2370  hash cop_prepend(any column, string arg);
2371 
2372 
2374 
2384  hash cop_append(any column, string arg);
2385 
2386 
2388 
2516  hash cop_value(any arg);
2517 
2518 
2520 
2529  hash cop_upper(any column);
2530 
2531 
2533 
2542  hash cop_lower(any column);
2543 
2544 
2546 
2555  hash cop_distinct(any column);
2556 
2557 
2559 
2568  hash cop_min(any column);
2569 
2570 
2572 
2581  hash cop_max(any column);
2582 
2583 
2585 
2594  hash cop_avg(any column);
2595 
2596 
2598 
2607  hash cop_sum(any column);
2608 
2609 
2611 
2618  hash cop_count(any column = "");
2619 
2620 
2622 
2629  hash cop_over(any column, string arg);
2630 
2631 
2633 
2643  hash cop_minus(any column1, any column2);
2644 
2645 
2647 
2657  hash cop_plus(any column1, any column2);
2658 
2659 
2661 
2671  hash cop_divide(any column1, any column2);
2672 
2673 
2675 
2685  hash cop_multiply(any column1, any column2);
2686 
2687 
2689 
2698  hash cop_year(any column);
2699 
2700 
2702 
2711  hash cop_year_month(any column);
2712 
2713 
2715 
2724  hash cop_year_day(any column);
2725 
2726 
2728 
2737  hash cop_year_hour(any column);
2738 
2739 
2741 
2751  hash cop_seq(string seq, *string as);
2752 
2753 
2755 
2765  hash cop_seq_currval(string seq, *string as);
2766 
2767 
2769 
2781  hash cop_coalesce(any col1, any col2);
2782 
2783 
2785 
2796  hash cop_substr(any column, int start, *int count);
2797 
2799 
2804  const DefaultUopMap = (
2806  COP_PREPEND: True,
2807  COP_APPEND: True,
2808  COP_UPPER: True,
2809  COP_LOWER: True,
2810  COP_MINUS: (
2811  "sqlvalue": True,
2812  "code": string (string cve, any arg) {
2813  return sprintf("%s - %s", cve, arg);
2814  },
2815  ),
2816  COP_PLUS: (
2817  "sqlvalue": True,
2818  "code": string (string cve, any arg) {
2819  return sprintf("%s + %s", cve, arg);
2820  },
2821  ),
2822  COP_DIVIDE: (
2823  "sqlvalue": True,
2824  "code": string (string cve, any arg) {
2825  return sprintf("%s / %s", cve, arg);
2826  },
2827  ),
2828  COP_MULTIPLY: (
2829  "sqlvalue": True,
2830  "code": string (string cve, any arg) {
2831  return sprintf("%s * %s", cve, arg);
2832  },
2833  ),
2834  COP_SUBSTR: True,
2835  COP_SEQ: (
2836  "nocolumn": True,
2837  "code": string (*string cve, string arg) {
2838  throw "SEQUENCE-ERROR", sprintf("cannot select sequence %y because this database does not support sequences", arg);
2839  }
2840  ),
2841  COP_SEQ_CURRVAL: (
2842  "nocolumn": True,
2843  "code": string (*string cve, string arg) {
2844  throw "SEQUENCE-ERROR", sprintf("cannot select the current value of sequence %y because this database does not support sequences", arg);
2845  }
2846  ),
2847  COP_COALESCE: (
2848  "columnargs": True,
2849  "code": string (*string cve, softlist args) {
2850  return sprintf("coalesce(%s)", (foldl $1 + "," + $2, args));
2851  }
2852  ),
2853  );
2855 
2877 
2886  hash make_uop(string uop, any arg, *hash nest);
2887 
2888 
2890 
2900  hash uop_prepend(string arg, *hash nest);
2901 
2902 
2904 
2914  hash uop_append(string arg, *hash nest);
2915 
2916 
2918 
2927  hash uop_upper(*hash nest);
2928 
2929 
2931 
2940  hash uop_lower(*hash nest);
2941 
2942 
2944 
2955  hash uop_substr(int start, *int count, *hash nest);
2956 
2957 
2959 
2969  hash uop_plus (any arg, *hash nest);
2970 
2971 
2973 
2983  hash uop_minus (any arg, *hash nest);
2984 
2985 
2987 
2997  hash uop_multiply (any arg, *hash nest);
2998 
2999 
3001 
3011  hash uop_divide (any arg, *hash nest);
3012 
3013 
3015 
3024  hash uop_seq(string seq);
3025 
3026 
3028 
3037  hash uop_seq_currval(string seq);
3038 
3040 
3047 
3050  const JOP_INNER = "inner";
3051 
3053 
3055  const JOP_LEFT = "left";
3056 
3058 
3060  const JOP_RIGHT = "right";
3061 
3063  const JopMap = (
3064  JOP_INNER: "inner",
3065  JOP_LEFT: "left outer",
3066  JOP_RIGHT: "right outer",
3067  );
3069 
3079 
3083  hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
3084 
3085 
3087 
3091  hash make_jop(string jop, string table_name, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
3092 
3093 
3095 
3114  hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3115 
3116 
3118 
3137  hash join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3138 
3139 
3141 
3160  hash join_inner(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3161 
3162 
3164 
3186  hash join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3187 
3188 
3190 
3210  hash join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3211 
3212 
3214 
3236  hash join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3237 
3238 
3240 
3259  hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3260 
3261 
3263 
3282  hash join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3283 
3284 
3286 
3307  hash join_left(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3308 
3309 
3311 
3331  hash join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3332 
3333 
3335 
3355  hash join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3356 
3357 
3359 
3381  hash join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3382 
3383 
3385 
3404  hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3405 
3406 
3408 
3427  hash join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3428 
3429 
3431 
3452  hash join_right(string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3453 
3454 
3456 
3476  hash join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
3477 
3478 
3480 
3500  hash join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
3501 
3502 
3504 
3526  hash join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt);
3527 
3529 
3534 
3537  const OP_LIKE = "like";
3538 
3540 
3542  const OP_LT = "<";
3543 
3545 
3547  const OP_LE = "<=";
3548 
3550 
3552  const OP_GT = ">";
3553 
3555 
3557  const OP_GE = ">=";
3558 
3560 
3562  const OP_NE = "!=";
3563 
3565 
3567  const OP_EQ = "=";
3568 
3570 
3572  const OP_CLT = "C<";
3573 
3575 
3577  const OP_CLE = "C<=";
3578 
3580 
3582  const OP_CGT = "C>";
3583 
3585 
3587  const OP_CGE = "C>=";
3588 
3590 
3592  const OP_CNE = "C!=";
3593 
3595 
3597  const OP_CEQ = "C=";
3598 
3600 
3602  const OP_BETWEEN = "between";
3603 
3605 
3607  const OP_IN = "in";
3608 
3610 
3612  const OP_NOT = "not";
3613 
3615 
3617  const OP_SUBSTR = "substr";
3618 
3620  const OP_OR = "or";
3621 
3623  const DefaultOpMap = (
3624  OP_LIKE: (
3625  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3626  args += arg;
3627  return sprintf("%s like %v", cn);
3628  },
3629  ),
3630  OP_LT: (
3631  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3632  args += arg;
3633  return sprintf("%s < %v", cn);
3634  },
3635  ),
3636  OP_LE: (
3637  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3638  args += arg;
3639  return sprintf("%s <= %v", cn);
3640  },
3641  ),
3642  OP_GT: (
3643  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3644  args += arg;
3645  return sprintf("%s > %v", cn);
3646  },
3647  ),
3648  OP_GE: (
3649  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3650  args += arg;
3651  return sprintf("%s >= %v", cn);
3652  },
3653  ),
3654  OP_NE: (
3655  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3656  if (arg === NULL || !exists arg)
3657  return sprintf("%s is not null", cn);
3658  args += arg;
3659  return sprintf("(%s != %v or %s is null)", cn, cn);
3660  },
3661  ),
3662  OP_EQ: (
3663  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3664  if (arg === NULL || !exists arg)
3665  return sprintf("%s is null", cn);
3666  args += arg;
3667  return sprintf("%s = %v", cn);
3668  },
3669  ),
3670  OP_BETWEEN: (
3671  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3672  args += arg[0];
3673  args += arg[1];
3674  return sprintf("%s between %v and %v", cn);
3675  },
3676  ),
3677  OP_IN: (
3678  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3679  *string ins = (foldl $1 + "," + $2, (map t.getSqlValue($1), arg));
3680  return exists ins ? sprintf("%s in (%s)", cn, ins) : "1 != 1";
3681  },
3682  ),
3683  OP_NOT: (
3684  "recursive": True,
3685  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3686  return sprintf("not (%s)", cn);
3687  },
3688  ),
3689  OP_CLT: (
3690  "argcolumn": True,
3691  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3692  return sprintf("%s < %s", cn, arg);
3693  },
3694  ),
3695  OP_CLE: (
3696  "argcolumn": True,
3697  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3698  return sprintf("%s <= %s", cn, arg);
3699  },
3700  ),
3701  OP_CGT: (
3702  "argcolumn": True,
3703  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3704  return sprintf("%s > %s", cn, arg);
3705  },
3706  ),
3707  OP_CGE: (
3708  "argcolumn": True,
3709  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3710  return sprintf("%s >= %s", cn, arg);
3711  },
3712  ),
3713  OP_CNE: (
3714  "argcolumn": True,
3715  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3716  return sprintf("%s != %s", cn, arg);
3717  },
3718  ),
3719  OP_CEQ: (
3720  "argcolumn": True,
3721  "code": string (object t, string cn, string arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3722  return sprintf("%s = %s", cn, arg);
3723  },
3724  ),
3725  OP_SUBSTR: (
3726  "code": string (object t, string cn, any arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3727  args += arg[0]; // start
3728  if (!exists arg[1]);
3729 
3730  args += arg[1]; // count
3731  args += arg[2]; // text
3732  return sprintf("substring(%s from %v for %v) = %v", cn);
3733  },
3734  ),
3735  OP_OR: (
3736  "code": string (object t, string cn, list arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch) {
3737  return t.getOrClause(arg, \args, jch, join, ch, psch);
3738  },
3739  ),
3740  );
3742 
3765  hash make_op(string op, any arg);
3767 
3768 
3770 
3779  hash op_like(string str);
3780 
3781 
3783 
3794  hash op_lt(any arg);
3795 
3796 
3798 
3809  hash op_le(any arg);
3810 
3811 
3813 
3824  hash op_gt(any arg);
3825 
3826 
3828 
3839  hash op_ge(any arg);
3840 
3841 
3843 
3856  hash op_ne(any arg);
3857 
3858 
3860 
3873  hash op_eq(any arg);
3874 
3875 
3877 
3889  hash op_between(any l, any r);
3890 
3891 
3893 
3900  hash op_in();
3901 
3902 
3904 
3913  hash op_in(list args);
3914 
3915 
3917 
3924  hash op_not(hash arg);
3925 
3926 
3928 
3939  hash op_clt(string arg);
3940 
3941 
3943 
3954  hash op_cle(string arg);
3955 
3956 
3958 
3969  hash op_cgt(string arg);
3970 
3971 
3973 
3984  hash op_cge(string arg);
3985 
3986 
3988 
3999  hash op_cne(string arg);
4000 
4001 
4003 
4014  hash op_ceq(string arg);
4015 
4016 
4018 
4029  hash op_substr(int start, *int count, string text);
4030 
4031 
4033 
4043  hash op_substr(int start, string text);
4044 
4045 
4047 
4063  hash wop_or(hash h1, hash h2);
4064 
4066 
4073 
4076  const IOP_SEQ = "seq";
4077 
4079 
4081  const IOP_SEQ_CURRVAL = "seq_currval";
4082 
4084  const DefaultIopMap = {};
4086 
4092 
4100  hash make_iop(string iop, any arg);
4101 
4102 
4104 
4113  hash iop_seq(string arg);
4114 
4115 
4117 
4126  hash iop_seq_currval(string arg);
4127 
4129 
4132 
4133 public:
4134 private:
4135 
4136 public:
4137 
4138  private :
4139  *hash h;
4140 
4141 public:
4142 
4144  constructor(*hash nh);
4145 
4146 
4149 
4150 
4153 
4154 
4156 
4171  any memberGate(string k);
4172 
4173 
4175 
4181  clear();
4182 
4183 
4185  abstract any take(string k);
4186 
4188  renameKey(string old_name, string new_name);
4189 
4190 
4192  *hash getHash();
4193 
4194 
4196 
4205  bool matchKeys(hash h1);
4206 
4207 
4209 
4218  bool matchKeys(list l);
4219 
4220 
4222 
4232 
4233 
4235 
4244  bool partialMatchKeys(hash h1);
4245 
4246 
4248 
4257  bool partialMatchKeys(list l);
4258 
4259 
4261 
4271 
4272 
4274 
4283  bool val();
4284 
4285 
4287 
4294  list keys();
4295 
4296 
4298 
4305  list values();
4306 
4307 
4309 
4317 
4318 
4320 
4328 
4329 
4331 
4339 
4340 
4342  bool empty();
4343 
4344 
4346 
4353  int size();
4354 
4355 
4357 
4366  bool hasKey(string k);
4367 
4368 
4370 
4379  bool hasKeyValue(string k);
4380 
4381 
4383 
4392  *string firstKey();
4393 
4394 
4396 
4405  *string lastKey();
4406 
4407 
4409  abstract string getElementName();
4410  };
4411 
4414 
4415 public:
4416 private:
4417 
4418 public:
4419 
4420  private :
4421  softlist l;
4422 
4423 public:
4424 
4426  constructor(softlist nl);
4427 
4428 
4430 
4441  abstract any get(softint i);
4442 
4444  add(any val);
4445 
4446 
4448  any take(int i);
4449 
4450 
4452  list getList();
4453 
4454 
4456 
4465  bool val();
4466 
4467 
4469 
4477 
4478 
4480  bool empty();
4481 
4482 
4484 
4491  int size();
4492 
4493 
4495  abstract string getElementName();
4496 
4497  private checkIndex(int i);
4498 
4499  };
4500 
4503 
4504 public:
4506  constructor();
4507 
4508 
4510  constructor(AbstractDatasource ds, hash tables, *hash opt);
4511 
4512 
4514  constructor(AbstractDatasource ds);
4515 
4516 
4518  add(string k, Table val);
4519 
4520 
4522  add(string k, AbstractTable val);
4523 
4524 
4526  add(Table val);
4527 
4528 
4530  add(AbstractTable val);
4531 
4532 
4534  AbstractTable take(string k);
4535 
4536 
4538  populate(AbstractDatasource ds, hash tables, *hash opt);
4539 
4540 
4542  populate(AbstractDatasource ds);
4543 
4544 
4546 
4560  *list getDropAllForeignConstraintsOnTableSql(string name, *hash opt);
4561 
4562 
4564 
4579  AbstractTable memberGate(string k);
4580 
4581 
4583  string getElementName();
4584 
4585 
4587  *AbstractTable getIfExists(AbstractDatasource ds, string name);
4588 
4589 
4591  AbstractTable get(AbstractDatasource ds, string name);
4592 
4593 
4595 
4610  *string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts);
4611 
4612 
4614 
4625  bool tableRenamed(string old_name, string new_name, string old_sql_name);
4626 
4627 
4628  private tableRenamedIntern(string old_name, string new_name, string oldsn);
4629 
4630 
4632 
4647  *string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
4648 
4649 
4650  list getCreateList();
4651 
4652 
4653  Qore::AbstractIterator createIterator();
4654 
4655 
4657 
4665  list getDropList();
4666 
4667 
4669 
4677 
4678 
4679  private getDependencies(reference tdh, reference sdh, *reference th);
4680 
4681  };
4682 
4685 
4686 public:
4688  constructor(*hash c) ;
4689 
4690 
4692  constructor(Columns old) ;
4693 
4694 
4696  add(string k, AbstractColumn val);
4697 
4698 
4700  AbstractColumn take(string k);
4701 
4702 
4704 
4719  AbstractColumn memberGate(string k);
4720 
4721 
4723  Columns subset(softlist l);
4724 
4725 
4727  string getElementName();
4728 
4729 
4731  bool equal(Columns cols);
4732 
4733  };
4734 
4737 
4738 public:
4739  public :
4741  string name;
4742 
4744  string native_type;
4745 
4747  *string qore_type;
4748 
4750  int size;
4751 
4753  bool nullable;
4754 
4756  *string def_val;
4757 
4759  *string comment;
4760 
4761 public:
4762 
4763  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string c);
4764 
4765 
4767  string getNativeTypeString();
4768 
4769 
4771  string getCreateSql(AbstractTable t);
4772 
4773 
4775 
4784  abstract list getAddColumnSql(AbstractTable t);
4785 
4787  string getDropSql(string table_name);
4788 
4789 
4791 
4804 
4805 
4807 
4817  abstract string getRenameSql(AbstractTable t, string new_name);
4818 
4820  bool equal(AbstractColumn c);
4821 
4822 
4824  private abstract bool equalImpl(AbstractColumn c);
4825 
4827 
4839  private abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
4840  };
4841 
4844 
4845 public:
4846  public :
4848  int scale;
4849 
4850 public:
4851 
4852  constructor(softint n_scale = 0);
4853 
4854 
4856  string getNativeTypeString(string native_type, int precision);
4857 
4858  };
4859 
4862 
4863 public:
4864  constructor(*hash c) ;
4865 
4866 
4868  add(string k, AbstractIndex val);
4869 
4870 
4873 
4874 
4876  AbstractIndex take(string k);
4877 
4878 
4880  *AbstractIndex tryTake(string k);
4881 
4882 
4884 
4899  AbstractIndex memberGate(string k);
4900 
4901 
4902  string getElementName();
4903 
4904  };
4905 
4908 
4909 public:
4910  public :
4912  string name;
4913 
4915  bool unique;
4916 
4919 
4920 public:
4921 
4922  private :
4925 
4926 public:
4927 
4929  constructor(string n, bool u, hash c);
4930 
4931 
4933  string getName();
4934 
4935 
4937  bool hasColumn(string cname);
4938 
4939 
4941  abstract string getCreateSql(string table_name, *hash opt);
4942 
4944  string getDropSql(string table_name);
4945 
4946 
4948  bool equal(AbstractIndex ix);
4949 
4950 
4952  bool equalExceptName(AbstractIndex ix);
4953 
4954 
4956  abstract bool equalImpl(AbstractIndex ix);
4957 
4959  abstract string getRenameSql(string table_name, string new_name);
4960 
4963 
4964 
4967 
4968 
4971 
4972 
4974  list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt);
4975 
4976  };
4977 
4980 
4981 public:
4982  constructor(*hash c) ;
4983 
4984 
4986  add(string k, AbstractConstraint val);
4987 
4988 
4990  AbstractConstraint take(string k);
4991 
4992 
4995 
4996 
4998 
5013  AbstractConstraint memberGate(string k);
5014 
5015 
5016  string getElementName();
5017 
5018  };
5019 
5022 
5023 public:
5024 private:
5025 
5026 public:
5027 
5028  private :
5030  string name;
5031 
5032 public:
5033 
5035  constructor(string n);
5036 
5037 
5039  string getName();
5040 
5041 
5043  rename(string n);
5044 
5045 
5047  abstract string getCreateSql(string table_name, *hash opt);
5048 
5050  string getDropSql(string table_name);
5051 
5052 
5054  abstract list getRenameSql(string table_name, string new_name);
5055 
5057  string getDisableSql(string table_name);
5058 
5059 
5061  string getEnableSql(string table_name, *hash opt);
5062 
5063 
5065  bool equal(AbstractConstraint c);
5066 
5067 
5069  private abstract bool equalImpl(AbstractConstraint c);
5070 
5072  abstract bool setIndexBase(string ix);
5073 
5075  abstract clearIndex();
5076 
5078  bool hasColumn(string cname);
5079 
5080  };
5081 
5084 
5085 public:
5086  public :
5088  string src;
5089 
5090 public:
5091 
5093  constructor(string n, string n_src) ;
5094 
5095 
5097  private bool equalImpl(AbstractConstraint c);
5098 
5099 
5101  bool setIndexBase(string ix);
5102 
5103 
5105  clearIndex();
5106 
5107  };
5108 
5111 
5112 public:
5113  private :
5116 
5118  *string index;
5119 
5120 public:
5121 
5123  constructor(string n, *hash c, *string n_index) ;
5124 
5125 
5127  constructor(string n, Columns c, *string n_index) ;
5128 
5129 
5131 
5136 
5137 
5139  hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts);
5140 
5141 
5143  findMatchingIndex(*Indexes indexes);
5144 
5145 
5147 
5158 
5159 
5161  removeSourceConstraint(string tname, list cols);
5162 
5163 
5165  renameSourceConstraintTable(string old_name, string new_name);
5166 
5167 
5169  bool hasColumn(string cname);
5170 
5171 
5173  *string getIndex();
5174 
5175 
5177  private bool equalImpl(AbstractConstraint c);
5178 
5179 
5181  bool setIndexBase(string ix);
5182 
5183 
5185  clearIndex();
5186 
5187 
5189  abstract string getCreateSql(string table_name, *hash opts);
5190  };
5191 
5194 
5195 public:
5197  constructor(string n, *hash c, *string n_index) ;
5198 
5199  };
5200 
5203 
5204 public:
5205  constructor() ;
5206 
5207 
5208  constructor(string n, *hash c) ;
5209 
5210  };
5211 
5214 
5215 public:
5216  constructor(*hash c) ;
5217 
5218 
5220  add(string k, AbstractForeignConstraint val);
5221 
5222 
5224  AbstractForeignConstraint take(string k);
5225 
5226 
5229 
5230 
5232 
5248 
5249 
5251  *hash findConstraintOn(string table, softlist cols);
5252 
5253 
5255  string getElementName();
5256 
5257  };
5258 
5261 
5262 public:
5263  public :
5265  string table;
5266 
5269 
5270 public:
5271 
5273  constructor(string t, Columns c);
5274 
5275 
5277  bool equal(ForeignConstraintTarget targ);
5278 
5279  };
5280 
5283 
5284 public:
5285  public :
5288 
5289 public:
5290 
5291  constructor(string n, Columns c, ForeignConstraintTarget t) ;
5292 
5293 
5295  private bool equalImpl(AbstractConstraint con);
5296 
5297  };
5298 
5301 
5302 public:
5303  public :
5305  string name;
5306 
5309 
5312 
5315 
5316 public:
5317 
5319  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_max);
5320 
5321 
5323  abstract string getCreateSql(*hash opt);
5324 
5326  string getDropSql();
5327 
5328 
5330  abstract string getRenameSql(string new_name);
5331  };
5332 
5335 
5336 public:
5337  public :
5338  // ! potential object schema
5339  *string schema;
5340 
5342  string name;
5343 
5345  string src;
5346 
5349 
5350 public:
5351 
5353  constructor(string n_name, string n_src);
5354 
5355 
5357  abstract string getCreateSql(*hash opt);
5358 
5360  string getDropSql();
5361 
5362 
5364  abstract softlist getRenameSql(string new_name);
5365 
5366  };
5367 
5370 
5371 public:
5372  public :
5374  string name;
5375 
5377  string type;
5378 
5380  string src;
5381 
5382 public:
5383 
5385 
5389  constructor(string n, string n_type, string n_src);
5390 
5391 
5393  string getType();
5394 
5395 
5396  // FIXME: not appropriate for pgsql triggers for example
5398  string getDropSql();
5399 
5400 
5402  bool equal(AbstractFunctionBase t);
5403 
5404 
5406  private abstract bool equalImpl(AbstractFunctionBase t);
5407  };
5408 
5411 
5412 public:
5414 
5418  constructor(string n, string n_type, string n_src) ;
5419 
5420 
5422  abstract list getCreateSql(*hash opt);
5423 
5425  abstract list getRenameSql(string new_name);
5426 
5428  setName(string new_name);
5429 
5430  };
5431 
5434 
5435 public:
5436  constructor(*hash c) ;
5437 
5438 
5440  add(string k, AbstractFunction val);
5441 
5442 
5444  AbstractFunction take(string k);
5445 
5446 
5448 
5463  AbstractFunction memberGate(string k);
5464 
5465 
5466  string getElementName();
5467 
5468  };
5469 
5472 
5473 public:
5475  constructor(string n, string n_src) ;
5476 
5477 
5479  abstract list getCreateSql(string table_name, *hash opt);
5480 
5482  abstract list getRenameSql(string table_name, string new_name);
5483 
5485  abstract list getDropSql(string table_name);
5486  };
5487 
5490 
5491 public:
5492  constructor(*hash c) ;
5493 
5494 
5496  add(string k, AbstractTrigger val);
5497 
5498 
5500  AbstractTrigger take(string k);
5501 
5502 
5504 
5519  AbstractTrigger memberGate(string k);
5520 
5521 
5522  string getElementName();
5523 
5524  };
5525 
5527 
5537  class Database {
5538 
5539 public:
5540  private :
5543 
5544 public:
5545 
5547 
5558  constructor(AbstractDatasource ds, *hash opts);
5559 
5560 
5562 
5572  constructor(string ds, *hash opts);
5573 
5574 
5576 
5594  constructor(hash ds, *hash opts);
5595 
5596 
5599 
5600 
5602  any methodGate(string meth);
5603 
5604  };
5605 
5608 
5609 public:
5610  private :
5612  AbstractDatasource ds;
5614  string dsdesc;
5616  Mutex l();
5619 
5620 public:
5621 
5623 
5628  private constructor(AbstractDatasource nds, *hash nopts);
5629 
5630 
5631  static string makeDatasourceDesc(AbstractDatasource ds);
5632 
5633  private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
5634 
5635 
5636 
5637 private:
5638  static validateOptionIntern(string err, string type, reference opt, string k, string tag);
5639 public:
5640 
5641 
5643  private validateHashKeysForWhitespaces(any node);
5644 
5645 
5648 
5649 
5651  string getDriverName();
5652 
5653 
5655  string getDatasourceDesc();
5656 
5657  };
5658 
5661 
5662 public:
5663  public :
5665 
5669  "native_case": Type::Boolean,
5670  );
5671 
5673 
5676  const CacheOptions = (
5677  "table_cache": "Tables",
5678  );
5679 
5681 
5687  "info_callback": "code",
5688  "sql_callback": "code",
5689  "sql_callback_executed": Type::Boolean,
5690  );
5691 
5700  const AC_Unchanged = 0;
5702 
5704  const AC_Create = 1;
5705 
5707  const AC_Drop = 2;
5708 
5710  const AC_Rename = 3;
5711 
5713  const AC_Modify = 4;
5714 
5716  const AC_Truncate = 5;
5717 
5719  const AC_Add = 6;
5720 
5722  const AC_Recreate = 7;
5723 
5725  const AC_Insert = 8;
5726 
5728  const AC_Update = 9;
5729 
5731  const AC_Delete = 10;
5732 
5734  const AC_NotFound = 11;
5736 
5738  const ActionMap = (
5739  AC_Unchanged: "unchanged",
5740  AC_Create: "create",
5741  AC_Drop: "drop",
5742  AC_Rename: "rename",
5743  AC_Modify: "modify",
5744  AC_Truncate: "truncate",
5745  AC_Add: "add",
5746  AC_Recreate: "recreate",
5747  AC_Insert: "insert",
5748  AC_Update: "update",
5749  AC_Delete: "delete",
5750  AC_NotFound: "not found",
5751  );
5752 
5754  const ActionDescMap = (
5755  "unchanged": AC_Unchanged,
5756  "create": AC_Create,
5757  "drop": AC_Drop,
5758  "rename": AC_Rename,
5759  "modify": AC_Modify,
5760  "truncate": AC_Truncate,
5761  "add": AC_Add,
5762  "recreate": AC_Recreate,
5763  "insert": AC_Insert,
5764  "update": AC_Update,
5765  "delete": AC_Delete,
5766  "not found": AC_NotFound,
5767  );
5768 
5771  AC_Unchanged: ".",
5772  AC_Create: "C",
5773  AC_Drop: "D",
5774  AC_Rename: "N",
5775  AC_Modify: "M",
5776  AC_Truncate: "T",
5777  AC_Add: "A",
5778  AC_Recreate: "R",
5779  AC_Insert: "I",
5780  AC_Update: "U",
5781  AC_Delete: "X",
5782  AC_NotFound: ".",
5783  );
5784 
5786 
5793  "replace": Type::Boolean,
5794  "table_cache": "Tables",
5795  "data_tablespace": Type::String,
5796  "index_tablespace": Type::String,
5797  );
5798 
5800 
5803 
5805 
5808 
5810 
5823  "tables": Type::Hash,
5824  "table_map": Type::Hash,
5825 
5826  "sequences": Type::Hash,
5827  "sequence_map": Type::Hash,
5828 
5829  "functions": Type::Hash,
5830  "function_map": Type::Hash,
5831 
5832  "procedures": Type::Hash,
5833  "procedure_map": Type::Hash,
5834 
5835  //"views": Type::Hash,
5836  //"view_map": Type::Hash,
5837  );
5838 
5840 
5846  "start": Type::Int,
5847  "increment": Type::Int,
5848  "end": Type::Int,
5849  );
5850 
5853  "tables" : "softstringlist",
5854  );
5855 
5858  "tables" : "softstringlist",
5859  );
5860 
5861 public:
5862 
5863  private :
5866 
5867 public:
5868 
5870 
5875  private constructor(AbstractDatasource nds, *hash nopts) ;
5876 
5877 
5879  list features();
5880 
5881 
5882  static doOkCallback(*hash opt, int ac, string type, string name, *string table, *string info);
5883 
5884  static *string doCallback(*hash opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
5885 
5886  static list doCallback(*hash opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
5887 
5888 /*
5889  static *string doCallback(*hash opt, *string sql, string fmt) {
5890  if (!sql)
5891  return;
5892  if (opt.info_callback)
5893  opt.info_callback(vsprintf(fmt, argv));
5894  if (opt.sql_callback)
5895  opt.sql_callback(sql);
5896  return sql;
5897  }
5898 
5899  static list doCallback(*hash opt, list sql, string fmt) {
5900  if (sql) {
5901  if (opt.info_callback)
5902  opt.info_callback(vsprintf(fmt, argv));
5903  if (opt.sql_callback)
5904  map opt.sql_callback($1), sql;
5905  }
5906  return sql;
5907  }
5908 */
5909 
5911 
5922  any tryExec(string sql);
5923 
5924 
5926 
5936  any tryExecArgs(string sql, *softlist args);
5937 
5938 
5940 
5951  any tryExecRaw(string sql);
5952 
5953 
5955 
5969  list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
5970 
5971 
5973 
5986  list getDropSchemaSql(hash schema_hash, *hash opt);
5987 
5988 
5989  private list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
5990 
5991 
5992  private list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
5993 
5994 
5996 
6010  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
6011 
6012 
6013  AbstractSequence makeSequenceFromDescription(string name, *hash sh, *hash opts);
6014 
6015 
6017 
6030  AbstractTable makeTable(string name, hash desc, *hash opts);
6031 
6032 
6034 
6045  AbstractFunction makeFunction(string name, string src, *hash opts);
6046 
6047 
6049 
6060  AbstractFunction makeProcedure(string name, string src, *hash opt);
6061 
6062 
6064 
6076  bool dropFunctionIfExists(string name, *hash opt);
6077 
6078 
6080 
6092  bool dropProcedureIfExists(string name, *hash opt);
6093 
6094 
6096 
6108  bool dropSequenceIfExists(string name, *hash opt);
6109 
6110 
6112 
6124  bool dropViewIfExists(string name, *hash opt);
6125 
6126 
6128 
6140  bool dropTableIfExists(string name, *hash opt);
6141 
6142 
6144 
6156  *string getDropFunctionSqlIfExists(string name, *hash opt);
6157 
6158 
6160 
6172  *string getDropProcedureSqlIfExists(string name, *hash opt);
6173 
6174 
6176 
6188  *string getDropSequenceSqlIfExists(string name, *hash opt);
6189 
6190 
6192 
6204  *list getDropTableSqlIfExists(string name, *hash opt);
6205 
6206 
6207  doDropSql(*softlist l, string type, string name, *hash opt);
6208 
6209 
6210  bool doDrop(*softlist l, string type, string name, *hash opt);
6211 
6212 
6214 
6227 
6228 
6230 
6243 
6244 
6246 
6255  *AbstractTable getTable(string name);
6256 
6257 
6259 
6268  *AbstractSequence getSequence(string name);
6269 
6270 
6272 
6283  *AbstractFunction getFunction(string name);
6284 
6285 
6287 
6298  *AbstractFunction getProcedure(string name);
6299 
6300 
6302 
6311  *AbstractView getView(string name);
6312 
6313 
6315 
6324  int getNextSequenceValue(string name);
6325 
6326 
6328 
6337  int getCurrentSequenceValue(string name);
6338 
6339 
6341 
6350  string getSqlFromList(list l);
6351 
6352 
6354  bool supportsSequences();
6355 
6356 
6358  bool supportsTypes();
6359 
6360 
6362  bool supportsPackages();
6363 
6364 
6366  list listTables();
6367 
6368 
6371 
6372 
6374  list listFunctions();
6375 
6376 
6379 
6380 
6382  list listProcedures();
6383 
6384 
6387 
6388 
6390  list listSequences();
6391 
6392 
6395 
6396 
6398  list listViews();
6399 
6400 
6403 
6404 
6406 
6416  bool rebuildIndex(string name, *hash options);
6417 
6418 
6420 
6428  bool rebuildIndex(AbstractIndex index, *hash options);
6429 
6430 
6432 
6439  computeStatistics(*hash options);
6440 
6441 
6443 
6450  reclaimSpace(*hash options);
6451 
6452 
6453  private validateOptionsIntern(string err, hash ropt, reference opt);
6454 
6455 
6456  private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
6457 
6458 
6459  static AbstractDatabase getDatabase(AbstractDatasource nds, *hash opts);
6460 
6461  static AbstractDatabase getDatabase(string dsstr, *hash opts);
6462 
6463  static AbstractDatabase getDatabase(hash dsh, *hash opts);
6464 
6465  static checkDriverOptions(reference h, string drv);
6466 
6468  private hash getDatabaseOptions();
6469 
6470 
6472  private hash getCallbackOptions();
6473 
6474 
6476  private hash getCreationOptions();
6477 
6478 
6480  private hash getCacheOptions();
6481 
6482 
6484  private hash getAlignSchemaOptions();
6485 
6486 
6488  private hash getDropSchemaOptions();
6489 
6490 
6493 
6494 
6497 
6498 
6500  private hash getRebuildIndexOptions();
6501 
6502 
6505 
6506 
6508  private hash getReclaimSpaceOptions();
6509 
6510 
6512  private any tryExecArgsImpl(string sql, *softlist args);
6513 
6514 
6516  private any tryExecRawImpl(string sql);
6517 
6518 
6519  private abstract string getCreateSqlImpl(list l);
6520  private abstract list getAlignSqlImpl(hash schema_hash, *hash opt);
6521  private abstract list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
6522 
6523  private abstract *AbstractSequence getSequenceImpl(string name);
6524  private abstract *AbstractFunction getFunctionImpl(string name);
6525  private abstract *AbstractFunction getProcedureImpl(string name);
6526  private abstract *AbstractView getViewImpl(string name);
6527 
6528  private abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
6529  private abstract AbstractFunction makeFunctionImpl(string name, string src, *hash opts);
6530  private abstract AbstractFunction makeProcedureImpl(string name, string src, *hash opts);
6531 
6532  private abstract list featuresImpl();
6533  private abstract list listTablesImpl();
6534  private abstract list listFunctionsImpl();
6535  private abstract list listProceduresImpl();
6536  private abstract list listSequencesImpl();
6537  private abstract list listViewsImpl();
6538 
6540  private abstract int getNextSequenceValueImpl(string name);
6542  private abstract int getCurrentSequenceValueImpl(string name);
6543 
6545  private abstract bool supportsSequencesImpl();
6546  private abstract bool supportsPackagesImpl();
6547  private abstract bool supportsTypesImpl();
6548 
6549  private abstract bool rebuildIndexImpl(string name, *hash options);
6550  private abstract computeStatisticsImpl(*hash options);
6551  private abstract reclaimSpaceImpl(*hash options);
6552  };
6553 
6555 
6571  class Table {
6572 
6573 public:
6574  private :
6577 
6578 public:
6579 
6581 
6593  constructor(AbstractDatasource ds, string name, *hash opts);
6594 
6595 
6597 
6609  constructor(string ds, string name, *hash opts);
6610 
6611 
6613 
6633  constructor(hash ds, string name, *hash opts);
6634 
6635 
6637 
6645  constructor(AbstractDatasource ds, hash desc, string name, *hash opts);
6646 
6647 
6650 
6651 
6653 
6655  any methodGate(string meth);
6656 
6657 
6658  }; // class Table
6659 
6661 
6664 
6665 public:
6666  public :
6668 
6672  const TableOptions = (
6673  "native_case": Type::Boolean,
6674  "table_cache": "Tables",
6675  );
6676 
6678 
6682  const IndexOptions = (
6683  "index_tablespace": Type::String,
6684  "replace": Type::Boolean,
6685  );
6686 
6688 
6691 
6693  const CacheOptions = (
6694  "table_cache": "Tables",
6695  );
6696 
6698 
6702  "table_cache": "Tables",
6703  );
6704 
6706 
6709 
6711 
6724  const SelectOptions = (
6725  "comment": Type::String,
6726  "hint": Type::String,
6727  "columns": Type::NothingType,
6728  "where": "hash/list",
6729  "orderby": "softstringinthashlist",
6730  "desc": Type::Boolean,
6731  "limit": Type::Int,
6732  "offset": Type::Int,
6733  "join": Type::Hash,
6734  "groupby": "softstringinthashlist",
6735  "having": Type::Hash,
6736  "superquery": Type::Hash,
6737  "forupdate": Type::Boolean,
6738  );
6739 
6742  "indexes": True,
6743  "foreign_constraints": True,
6744  "triggers": True,
6745  );
6746 
6748 
6752  "omit": "softstringlist",
6753  );
6754 
6756 
6764  "column_map": Type::Hash,
6765  "index_map": Type::Hash,
6766  "constraint_map": Type::Hash,
6767  "trigger_map": Type::Hash,
6768  "db_table_cache": "Tables",
6769  );
6770 
6772 
6784  "columns": Type::Hash,
6785  "primary_key": Type::Hash,
6786  "indexes": Type::Hash,
6787  "triggers": Type::Hash,
6788  "foreign_constraints": Type::Hash,
6789  "unique_constraints": Type::Hash,
6790  //"check_constraints": Type::Hash,
6791  "table_cache": "Tables",
6792  );
6793 
6795 
6807  "qore_type": Type::String,
6808  "native_type": Type::String,
6809  "size": Type::Int,
6810  "scale": Type::Int,
6811  "default_value": Type::NothingType,
6812  "comment": Type::String,
6813  );
6814 
6816 
6820  "notnull": Type::Boolean,
6821  );
6822 
6824  const ColumnOptions = {};
6825 
6827 
6832  "sqlarg_callback": "code",
6833  "tablecode": "code",
6834  );
6835 
6837 
6847  "returning": "stringhashlist",
6848  );
6849 
6851 
6857  const UpsertOptions = (
6858  "info_callback": "code",
6859  "commit_block": Type::Int,
6860  "delete_others": Type::Boolean,
6861  "omit_update": "softstringlist",
6862  );
6863 
6865 
6870  "info_callback": "code",
6871  "commit_block": Type::Int,
6872  );
6873 
6889 
6896 
6898 
6904 
6906 
6913 
6915 
6919  const UpsertAuto = 4;
6920 
6922 
6926  const UpsertInsertOnly = 5;
6927 
6929 
6933  const UpsertUpdateOnly = 6;
6934 
6936 
6939  UpsertInsertFirst: "UpsertInsertFirst",
6940  UpsertUpdateFirst: "UpsertUpdateFirst",
6941  UpsertSelectFirst: "UpsertSelectFirst",
6942  UpsertAuto: "UpsertAuto",
6943  UpsertInsertOnly: "UpsertInsertOnly",
6944  UpsertUpdateOnly: "UpsertUpdateOnly",
6945  );
6946 
6948 
6951  "UpsertInsertFirst": UpsertInsertFirst,
6952  "UpsertUpdateFirst": UpsertUpdateFirst,
6953  "UpsertSelectFirst": UpsertSelectFirst,
6954  "UpsertAuto": UpsertAuto,
6955  "UpsertInsertOnly": UpsertInsertOnly,
6956  "UpsertUpdateOnly": UpsertUpdateOnly,
6957  );
6959 
6964  const UR_Inserted = 1;
6966 
6968  const UR_Verified = 2;
6969 
6971  const UR_Updated = 3;
6972 
6974  const UR_Unchanged = 4;
6975 
6977  const UR_Deleted = 5;
6979 
6981 
6984  UR_Inserted: "inserted",
6985  UR_Verified: "verified",
6986  UR_Updated: "updated",
6987  UR_Unchanged: "unchanged",
6988  UR_Deleted: "deleted",
6989  );
6990 
6992 
6995  "inserted": UR_Inserted,
6996  "verified": UR_Verified,
6997  "updated": UR_Updated,
6998  "unchanged": UR_Unchanged,
6999  "deleted": UR_Deleted,
7000  );
7001 
7004  UR_Inserted: "I",
7005  UR_Verified: "V",
7006  UR_Updated: "U",
7007  UR_Unchanged: ".",
7008  UR_Deleted: "X",
7009  );
7010 
7011 public:
7012 
7013  private :
7015  string name;
7031  bool inDb = False;
7033  bool manual = False;
7034 
7035 public:
7036 
7038 
7044  private constructor(AbstractDatasource nds, string nname, *hash nopts) ;
7045 
7046 
7048  copy(AbstractTable old);
7049 
7050 
7052 
7063  setDatasource(AbstractDatasource nds);
7064 
7065 
7066  private doTableOptions(*hash nopts);
7067 
7068 
7070  commit();
7071 
7072 
7074  rollback();
7075 
7076 
7078 
7087  bool inDb();
7088 
7089 
7091 
7099 
7100 
7102 
7113  dropCommit(*hash opt);
7114 
7115 
7117 
7128  drop(*hash opt);
7129 
7130 
7132  deprecated dropNoCommit(*hash opt);
7133 
7135 
7146  any tryExec(string sql);
7147 
7148 
7150 
7160  any tryExecArgs(string sql, *softlist args);
7161 
7162 
7164 
7175  any tryExecRaw(string sql);
7176 
7177 
7179 
7190  softlist getDropSql(*hash opt);
7191 
7192 
7194 
7201  truncateCommit();
7202 
7203 
7205 
7212  truncate();
7213 
7214 
7216  deprecated truncateNoCommit();
7217 
7219 
7234  string getTruncateSql(*hash opt);
7235 
7236 
7238 
7247  createCommit(*hash opt);
7248 
7249 
7251 
7262  create(*hash opt);
7263 
7264 
7266  deprecated createNoCommit(*hash opt);
7267 
7269 
7280  rename(string new_name, *reference sql, *Tables table_cache);
7281 
7282 
7283  private doRenameIntern(string new_name, *Tables table_cache);
7284 
7285 
7287 
7298  bool emptyData();
7299 
7300 
7302 
7311  bool empty();
7312 
7313 
7314  private bool emptyUnlocked();
7315 
7316 
7318 
7324  setupTable(hash desc, *hash opt);
7325 
7326 
7328 
7351  AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
7352 
7353 
7355 
7383  list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
7384 
7385 
7386  private AbstractColumn addColumnUnlocked(string cname, hash opt, bool nullable = True, *reference lsql, bool do_exec = True, bool modify_table = True);
7387 
7388 
7389  private addColumnToTableUnlocked(AbstractColumn c);
7390 
7391 
7393 
7417  AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
7418 
7419 
7421 
7447  list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
7448 
7449 
7451 
7468  AbstractColumn renameColumn(string old_name, string new_name, reference sql);
7469 
7470 
7472 
7490  string getRenameColumnSql(string old_name, string new_name, *hash opt);
7491 
7492 
7493  private AbstractColumn renameColumnIntern(AbstractColumn c, string new_name);
7494 
7495 
7496  private validateOptionsIntern(string err, hash ropt, reference opt);
7497 
7498 
7499  private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
7500 
7501 
7502  private execSql(softlist lsql);
7503 
7504 
7506 
7526  AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql);
7527 
7528 
7530 
7552  string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
7553 
7554 
7555  private setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
7556 
7557 
7558  private AbstractPrimaryKey addPrimaryKeyUnlocked(string pkname, softlist cols, *hash opt, *reference sql);
7559 
7560 
7561  private AbstractPrimaryKey addPrimaryKeyUnlockedIntern(string pkname, softlist cols, *hash opt, *reference sql);
7562 
7563 
7565 
7582 
7583 
7584  private list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(string cname, *hash opt);
7585 
7586 
7588 
7608 
7609 
7611 
7629  AbstractPrimaryKey dropPrimaryKey(*reference lsql);
7630 
7631 
7633 
7654  AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql);
7655 
7656 
7658 
7678  string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
7679 
7680 
7681  private AbstractUniqueConstraint addUniqueConstraintUnlocked(string cname, softlist cols, *hash opt, *reference sql);
7682 
7683 
7684  private AbstractUniqueConstraint addUniqueConstraintUnlockedIntern(string cname, softlist cols, *hash opt, *reference sql);
7685 
7686 
7688 
7709  AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql);
7710 
7711 
7713 
7734  string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
7735 
7736 
7737  private AbstractIndex addIndexUnlocked(string iname, bool unique, softlist cols, *hash opt, *reference sql);
7738 
7739 
7740  private AbstractIndex addIndexUnlockedIntern(string iname, bool unique, softlist cols, *hash opt, *reference sql);
7741 
7742 
7744 
7756  AbstractIndex renameIndex(string old_name, string new_name, reference sql);
7757 
7758 
7760 
7778  AbstractIndex dropIndex(string iname, *reference sql);
7779 
7780 
7782 
7801  string getDropIndexSql(string iname, *hash opt);
7802 
7803 
7805 
7827  AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
7828 
7829 
7831 
7853  string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
7854 
7855 
7856  private Columns getReferencedTableColumnsUnlocked(string table, *Tables cache, string err = "FOREIGN-CONSTRAINT-ERROR");
7857 
7858 
7859  private AbstractForeignConstraint addForeignConstraintUnlocked(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
7860 
7861 
7862  private AbstractForeignConstraint addForeignConstraintUnlockedIntern(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
7863 
7864 
7866 
7884  AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql);
7885 
7886 
7888 
7904 
7905 
7907 
7927  AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql);
7928 
7929 
7931 
7953  string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
7954 
7955 
7956  private AbstractCheckConstraint addCheckConstraintUnlocked(string cname, string src, *hash opt, *reference sql);
7957 
7958 
7959  private AbstractCheckConstraint addCheckConstraintUnlockedIntern(string cname, string src, *hash opt, *reference sql);
7960 
7961 
7963 
7975  AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
7976 
7977 
7979 
7998  string getDropConstraintSql(string cname, *hash opt);
7999 
8000 
8002 
8021  *string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref);
8022 
8023 
8024  private AbstractConstraint findDropConstraintUnlocked(string cname, reference rmv);
8025 
8026 
8028 
8046  AbstractConstraint dropConstraint(string cname, *reference sql);
8047 
8048 
8050 
8070  AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
8071 
8072 
8074 
8096  list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
8097 
8098 
8099  private AbstractTrigger addTriggerUnlocked(string tname, string src, *hash opt, *reference lsql);
8100 
8101 
8102  private AbstractTrigger addTriggerUnlockedIntern(string tname, string src, *hash opt, *reference lsql);
8103 
8104 
8106 
8124  AbstractTrigger dropTrigger(string tname, *reference sql);
8125 
8126 
8128 
8147  list getDropTriggerSql(string tname, *hash opt);
8148 
8149 
8150  private getAllConstraintsUnlocked(*hash opt);
8151 
8152 
8153  private checkUniqueConstraintName(string err, string cname);
8154 
8155 
8156  private checkUniqueConstraintNameValidateOptions(string err, string cname, hash ropt, reference opt);
8157 
8158 
8160  private validateColumnOptions(string cname, reference opt, bool nullable);
8161 
8162 
8164 
8182  AbstractColumn dropColumn(string cname, *reference lsql);
8183 
8184 
8186 
8205  list getDropColumnSql(string cname, *hash opt);
8206 
8207 
8209 
8222  *hash insertCommit(hash row);
8223 
8224 
8226  *hash insertCommit(hash row, reference sql);
8227 
8228 
8230  *hash insertCommit(hash row, hash opt);
8231 
8232 
8234  *hash insertCommit(hash row, reference sql, hash opt);
8235 
8236 
8238 
8252  *hash insert(hash row);
8253 
8254 
8256  *hash insert(hash row, reference sql);
8257 
8258 
8260  *hash insert(hash row, hash opt);
8261 
8262 
8264  *hash insert(hash row, reference sql, hash opt);
8265 
8266 
8268  deprecated *hash insertNoCommit(hash row, *reference sql, *hash opt);
8269 
8271  deprecated *hash insertNoCommit(hash row, hash opt);
8272 
8273  private *hash insertIntern(hash row, *reference sql, *hash opt);
8274 
8275 
8276  private hash getPlaceholdersAndValues(hash row);
8277 
8278 
8280 
8283  bool hasReturning();
8284 
8285 
8287 
8306  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference sql, hash opt);
8307 
8308 
8310  int insertFromSelectCommit(list cols, AbstractTable source);
8311 
8312 
8314  int insertFromSelectCommit(list cols, AbstractTable source, hash sh);
8315 
8316 
8318  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference sql);
8319 
8320 
8322  int insertFromSelectCommit(list cols, AbstractTable source, hash sh, hash opt);
8323 
8324 
8326 
8345  int insertFromSelect(list cols, AbstractTable source, hash sh, reference sql, hash opt);
8346 
8347 
8349  int insertFromSelect(list cols, AbstractTable source);
8350 
8351 
8353  int insertFromSelect(list cols, AbstractTable source, hash sh);
8354 
8355 
8357  int insertFromSelect(list cols, AbstractTable source, hash sh, reference sql);
8358 
8359 
8361  int insertFromSelect(list cols, AbstractTable source, hash sh, hash opt);
8362 
8363 
8365  deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt);
8366 
8367  private int insertFromSelectIntern(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt);
8368 
8369 
8371 
8390 
8391 
8393 
8412 
8413 
8415  deprecated int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt);
8416 
8417  private int insertFromIteratorIntern(Qore::AbstractIterator i, *hash opt);
8418 
8419 
8421 
8437  int upsertCommit(hash row, int upsert_strategy = UpsertAuto, *hash opt);
8438 
8439 
8441 
8457  int upsert(hash row, int upsert_strategy = UpsertAuto, *hash opt);
8458 
8459 
8461  deprecated int upsertNoCommit(hash row, int upsert_strategy = UpsertAuto);
8462 
8464 
8485  code getUpsertClosure(hash row, int upsert_strategy = UpsertAuto, *hash opt);
8486 
8487 
8489 
8516  code getBulkUpsertClosure(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8517 
8518 
8520 
8541  code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = UpsertAuto, *hash opt);
8542 
8543 
8545 
8578 
8579 
8581 
8614 
8615 
8617  deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8618 
8619  private *hash upsertFromIteratorIntern(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8620 
8621 
8622  private *hash doDeleteOthersIntern(hash pkh, *hash opt);
8623 
8624 
8626 
8664  *hash upsertFromSelectCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8665 
8666 
8668  *hash upsertFromSelectCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8669 
8670 
8672 
8712  *hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8713 
8714 
8716  deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8717 
8719  deprecated *hash upsertFromSelect(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8720 
8722  deprecated *hash upsertFromSelectNoCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
8723 
8725 
8736  softint rowCount();
8737 
8738 
8740 
8758  Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql, *hash opt);
8759 
8760 
8761  private Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference sql, *hash opt);
8762 
8763 
8765 
8783 
8784 
8786 
8805  *hash selectRow(*hash sh, *reference sql, *hash opt);
8806 
8807 
8809 
8827  *list selectRows(*hash sh, *reference sql, *hash opt);
8828 
8829 
8831 
8849  *hash select(*hash sh, *reference sql, *hash opt);
8850 
8851 
8853 
8871  *hash selectRow(*hash sh, *hash opt);
8872 
8873 
8875 
8892  *list selectRows(*hash sh, *hash opt);
8893 
8894 
8896 
8913  *hash select(*hash sh, *hash opt);
8914 
8915 
8917 
8935  string getSelectSql(*hash sh, *reference args);
8936 
8937 
8938  *AbstractUniqueConstraint matchAnyUnique(list cols);
8939 
8940 
8941  string getSelectSqlIntern(*hash qh, reference args, *hash opt);
8942 
8943 
8944  string getSelectSqlUnlocked(*hash qh, reference args, *hash opt);
8945 
8946 
8947  // column & table information must be retrieved before calling this function
8948  string getSelectSqlUnlockedIntern(*hash qh, string from, reference args, *hash ch, *hash opt);
8949 
8950 
8951  private string getFromIntern(string from, *hash qh);
8952 
8953 
8954  private list getGroupByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
8955 
8956 
8957  private list getOrderByListUnlocked(hash qh, *hash jch, *hash ch, *hash psch, list coll);
8958 
8959 
8960  private list getGroupOrderByListUnlocked(string key, hash qh, *hash jch, *hash ch, *hash psch, list coll);
8961 
8962 
8963  private doForUpdate(reference sql);
8964 
8965 
8966  private string getSelectSqlName(*hash qh);
8967 
8968 
8969  private string getColumnExpressionIntern(any cvc, *hash jch, bool join, *hash ch, *hash psch);
8970 
8971 
8972  private string doColumnOperatorIntern(hash cvc, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
8973 
8974 
8975  private string doColumnOperatorIntern(any cop, any arg, *string cve, hash cm, *hash jch, bool join, *hash ch, *hash psch, *reference psch_ref);
8976 
8977 
8978  private string getColumnNameIntern(string cv, *hash jch, bool join, *hash ch, *hash psch);
8979 
8980 
8982  private bool asteriskRequiresPrefix();
8983 
8984 
8985  private getSelectWhereSqlUnlocked(reference sql, reference args, *hash qh, *hash jch, bool join = False, *hash ch, *hash psch);
8986 
8987 
8988  private *string getWhereClause(*hash cond, reference args, *string cprefix, *hash jch, bool join = False);
8989 
8990 
8991  private *string getWhereClause(list cond, reference args, *string cprefix, *hash jch, bool join = False);
8992 
8993 
8994  private *string getWhereClauseUnlocked(list cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
8995 
8996 
8997  private *string getWhereClauseUnlocked(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch, *hash psch);
8998 
8999 
9000  private *list getWhereClauseIntern(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash ch, *hash psch);
9001 
9002 
9003  private string doWhereExpressionIntern(string cn, any we, reference args, *hash jch, bool join = False, *hash ch, *hash psch);
9004 
9005 
9006  string getOrClause(list arglist, reference args, *hash jch, bool join = False, *hash ch, *hash psch);
9007 
9008 
9009  string getOrClause(hash arg, reference args, *hash jch, bool join = False, *hash ch, *hash psch);
9010 
9011 
9012  private doSelectOrderBySqlUnlocked(reference sql, reference args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
9013 
9014 
9016 
9031  int delCommit(hash cond, reference sql, hash opt);
9032 
9033 
9035  int delCommit(hash cond, hash opt);
9036 
9037 
9039  int delCommit(hash cond, reference sql);
9040 
9041 
9043  int delCommit(hash cond);
9044 
9045 
9047  int delCommit();
9048 
9049 
9051 
9066  int del(hash cond, reference sql, hash opt);
9067 
9068 
9070  int del(hash cond, hash opt);
9071 
9072 
9074  int del(hash cond, reference sql);
9075 
9076 
9078  int del(hash cond);
9079 
9080 
9082  int del();
9083 
9084 
9086  deprecated int delNoCommit(*hash cond, *reference sql);
9087 
9088  private int delIntern(*hash cond, *reference sql, *hash opt);
9089 
9090 
9092 
9109  int updateCommit(hash set, hash cond, reference sql, hash opt);
9110 
9111 
9113  int updateCommit(hash set, hash cond, reference sql);
9114 
9115 
9117  int updateCommit(hash set, hash cond, hash opt);
9118 
9119 
9121  int updateCommit(hash set, hash cond);
9122 
9123 
9125  int updateCommit(hash set);
9126 
9127 
9129 
9146  int update(hash set, hash cond, reference sql, hash opt);
9147 
9148 
9150  int update(hash set, hash cond, reference sql);
9151 
9152 
9154  int update(hash set, hash cond, hash opt);
9155 
9156 
9158  int update(hash set, hash cond);
9159 
9160 
9162  int update(hash set);
9163 
9164 
9166  deprecated int updateNoCommit(hash set, *hash cond, *reference sql);
9167 
9169  deprecated int updateNoCommit(hash set, *hash cond, *hash opt);
9170 
9171  private int updateIntern(hash set, *hash cond, *reference sql, *hash opt);
9172 
9173 
9174  private string getUpdateExpression(string col, hash uh);
9175 
9176 
9177  private bool emptyDataIntern();
9178 
9179 
9180  private Columns checkUpsertRow(hash row, reference upsert_strategy);
9181 
9182 
9183  private code getUpsertInsertFirst(Columns cols, hash example_row, *hash opt);
9184 
9185 
9186  private code getUpsertUpdateFirst(Columns cols, hash example_row, *hash opt);
9187 
9188 
9189  private code getUpsertSelectFirst(Columns cols, hash example_row, *hash opt);
9190 
9191 
9192  private code getUpsertInsertOnly(Columns cols, hash example_row, *hash opt);
9193 
9194 
9195  private code getUpsertUpdateOnly(Columns cols, hash example_row, *hash opt);
9196 
9197 
9198  private Columns getUpsertColumns(reference csrc);
9199 
9200 
9201  private string getUpsertSelectSql(hash row, Columns cols, reference updc);
9202 
9203 
9204  private string getUpsertInsertSql(hash row);
9205 
9206 
9207  private string getUpsertUpdateSql(hash row, Columns cols, reference updc, *hash opt);
9208 
9209 
9210  private softbool tryUpdate(string sql, hash row, Columns cols, list updc);
9211 
9212 
9213  private checkValue(string cname, string argname, reference val, string type);
9214 
9215 
9217 
9226  string getSqlFromList(list l);
9227 
9228 
9230 
9241  string getSqlValue(any v);
9242 
9243 
9245  string getName();
9246 
9247 
9249 
9256  cache(*hash opts);
9257 
9258 
9260 
9265  clear();
9266 
9267 
9269 
9276  Columns describe();
9277 
9278 
9280 
9289 
9290 
9292 
9302 
9303 
9304  *AbstractUniqueConstraint findUniqueConstraintUnlocked(string name);
9305 
9306 
9308 
9317  Indexes getIndexes();
9318 
9319 
9322 
9323 
9326 
9327 
9329 
9339 
9340 
9342 
9360  string getRenameSql(string new_name, *hash opt);
9361 
9362 
9364 
9373  string getCreateSqlString(*hash opt);
9374 
9375 
9377 
9386  list getCreateSql(*hash opt);
9387 
9388 
9390 
9401  string getCreateTableSql(*hash opt);
9402 
9403 
9405 
9409  bool checkExistence();
9410 
9411 
9412  private *hash getCheckOmissionOptions(*softlist ol, string err);
9413 
9414 
9416 
9432 
9433 
9434  private list getAlignSqlUnlocked(AbstractTable t, *hash opt);
9435 
9436 
9437  private *AbstractColumnSupportingConstraint getSupportingConstraint(string ixname);
9438 
9439 
9440  private renameIndexUnlocked(AbstractIndex ix, string new_name);
9441 
9442 
9444 
9457  string getAlignSqlString(AbstractTable t, *hash opt);
9458 
9459 
9461 
9473  *list getCreateIndexesSql(*hash opt, bool cache = True);
9474 
9475 
9477 
9489  *string getCreatePrimaryKeySql(*hash opt, bool cache = True);
9490 
9491 
9493 
9505  *list getCreateForeignConstraintsSql(*hash opt, bool cache = True);
9506 
9507 
9509 
9523  *list getCreateConstraintsSql(*hash opt, bool cache = True);
9524 
9525 
9527 
9539  *list getCreateMiscSql(*hash opt, bool cache = True);
9540 
9541 
9543 
9557  *list getCreateTriggersSql(*hash opt, bool cache = True);
9558 
9559 
9561 
9568  *hash find(any id);
9569 
9570 
9572 
9583  *list find(list ids);
9584 
9585 
9586  private string getPrimaryKeyColumn();
9587 
9588 
9590 
9603  *hash find(hash row);
9604 
9605 
9607 
9620  *hash findSingle(*hash cond);
9621 
9622 
9624 
9637  *list findAll(*hash cond);
9638 
9639 
9641 
9645  string getDesc();
9646 
9647 
9649  string getBaseType();
9650 
9651 
9653  string getSqlName();
9654 
9655 
9657  string getColumnSqlName(string col);
9658 
9659 
9661  list getColumnSqlNames(softlist cols);
9662 
9663 
9665 
9667  bool bindEmptyStringsAsNull();
9668 
9669 
9671  abstract bool hasArrayBind();
9672 
9674 
9676  private hash getTableOptions();
9677 
9678 
9680 
9683 
9684 
9686 
9688  private hash getConstraintOptions();
9689 
9690 
9692 
9694  private hash getCacheOptions();
9695 
9696 
9698 
9700  private hash getTableCreationOptions();
9701 
9702 
9704 
9706  private hash getAlignTableOptions();
9707 
9708 
9710 
9713 
9714 
9716 
9718  private hash getColumnOptions();
9719 
9720 
9722 
9724  private hash getColumnDescOptions();
9725 
9726 
9728 
9730  private hash getTableColumnDescOptions();
9731 
9732 
9734 
9736  private hash getIndexOptions();
9737 
9738 
9740 
9742  private hash getTriggerOptions();
9743 
9744 
9746 
9748  private hash getSelectOptions();
9749 
9750 
9752 
9754  private hash getUpsertOptions();
9755 
9756 
9758 
9760  private hash getInsertOptions();
9761 
9762 
9764 
9767 
9768 
9770 
9772  private hash getSqlDataCallbackOptions();
9773 
9774 
9776 
9778  private hash getWhereOperatorMap();
9779 
9780 
9782 
9784  private hash getColumnOperatorMap();
9785 
9786 
9788 
9790  private hash getInsertOperatorMap();
9791 
9792 
9794 
9796  private hash getUpdateOperatorMap();
9797 
9798 
9800 
9802  private hash getRawUpdateOperatorMap();
9803 
9804 
9806 
9808  private *hash getPseudoColumnHash();
9809 
9810 
9811  private string getCreateTableSqlUnlocked(*hash opt);
9812 
9813 
9814  private *list getCreateIndexesSqlUnlocked(*hash opt, bool cache = True);
9815 
9816 
9817  private *string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
9818 
9819 
9820  private *list getCreateConstraintsSqlUnlocked(*hash opt, bool cache = True);
9821 
9822 
9823  private *list getCreateForeignConstraintsSqlUnlocked(*hash opt, bool cache = True);
9824 
9825 
9826  private *list getCreateMiscSqlUnlocked(*hash opt, bool cache = True);
9827 
9828 
9829  private *list getCreateTriggersSqlUnlocked(*hash opt, bool cache = True);
9830 
9831 
9832  private list getCreateSqlUnlocked(*hash opt, bool cache = True);
9833 
9834 
9835  private cacheUnlocked(*hash opt);
9836 
9837 
9838  private any execData(*hash opt, string sql, *list args);
9839 
9840 
9841  private execData(SQLStatement stmt, *hash opt, *list args);
9842 
9843 
9844  static AbstractTable getTable(AbstractDatasource nds, string nname, *hash opts);
9845 
9846  static AbstractTable getTable(string dsstr, string nname, *hash opts);
9847 
9848  static AbstractTable getTable(hash dsh, string nname, *hash opts);
9849 
9850  private getColumnsUnlocked();
9851 
9852 
9853  private getPrimaryKeyUnlocked();
9854 
9855 
9856  // also loads primary key and constraints (for unique constraints)
9857  private getIndexesUnlocked();
9858 
9859 
9860  private getForeignConstraintsUnlocked(*hash opt);
9861 
9862 
9863  private addSourceConstraint(string table_name, AbstractForeignConstraint fk);
9864 
9865 
9866  private getConstraintsUnlocked();
9867 
9868 
9869  private getTriggersUnlocked();
9870 
9871 
9873  private bool hasReturningImpl();
9874 
9875 
9876  private softlist getDropSqlImpl();
9877 
9878 
9879  private string getTruncateSqlImpl();
9880 
9881 
9883  private any tryExecArgsImpl(string sql, *softlist args);
9884 
9885 
9887  private any tryExecRawImpl(string sql);
9888 
9889 
9891  private clearImpl();
9892 
9893 
9894  private preSetupTableImpl(reference desc, *hash opt);
9895 
9896 
9897  private abstract *hash doReturningImpl(hash opt, reference sql, list args);
9898 
9899  private abstract bool emptyImpl();
9900 
9902  private abstract *string getSqlValueImpl(any v);
9903 
9905 
9908  private abstract bool checkExistenceImpl();
9909 
9911  private abstract bool supportsTablespacesImpl();
9912 
9914  private abstract bool constraintsLinkedToIndexesImpl();
9915 
9917  private abstract bool uniqueIndexCreatesConstraintImpl();
9918 
9919  private abstract setupTableImpl(hash desc, *hash opt);
9920 
9921  private abstract Columns describeImpl();
9922  private abstract AbstractPrimaryKey getPrimaryKeyImpl();
9923  private abstract Indexes getIndexesImpl();
9924  private abstract ForeignConstraints getForeignConstraintsImpl(*hash opt);
9925  private abstract Constraints getConstraintsImpl();
9926  private abstract Triggers getTriggersImpl();
9927 
9928  private abstract string getCreateTableSqlImpl(*hash opt);
9929  private abstract *list getCreateMiscSqlImpl(*hash opt, bool cache);
9930  private abstract string getCreateSqlImpl(list l);
9931  private abstract string getRenameSqlImpl(string new_name);
9932  private abstract *list getAlignSqlImpl(AbstractTable t, *hash opt);
9933 
9934  private abstract AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
9935  private abstract AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
9936  private abstract AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
9937  private abstract AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
9938  private abstract AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
9939  private abstract AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
9940 
9941  private abstract AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
9942 
9944  private abstract bool tryInsertImpl(string sql, hash row);
9945 
9947  private abstract hash getQoreTypeMapImpl();
9948 
9950  private abstract hash getTypeMapImpl();
9951 
9953  private abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch, *hash psch, list coll);
9954 
9956  private abstract doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh);
9957 
9959  private abstract copyImpl(AbstractTable old);
9960  };
9961 }
abstract string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
const ActionMap
maps from action codes to action descriptions
Definition: SqlUtil.qm.dox.h:5738
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:5030
private validateHashKeysForWhitespaces(any node)
Check input node for all hash keys - if it contains a key with whitespace in the beginning or at the ...
constructor(string n_name, number n_start=1, number n_increment=1, *softnumber n_max)
creates the object from the arguments
hash cop_avg(any column)
returns a hash for the "avg" operator; returns average column values
string getElementName()
returns "column" since this object stores column objects
softlist getDropSql(*hash opt)
returns the sql required to drop the table; reimplement in subclasses if necessary ...
bool hasColumn(string cname)
returns True if the constraint references the named column
constructor()
creates an empty object
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql)
adds an index to the table; if the table is already known to be in the database, then it is added in ...
const SelectOptions
default select options
Definition: SqlUtil.qm.dox.h:6724
string getDropSql()
returns a string that can be used to drop the function from the database
Constraints getConstraints()
returns a Constraints object describing the non-foreign constraints on the table
private hash getCacheOptions()
returns the cache options for this driver
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:5305
hash uop_lower(*hash nest)
returns a hash for the "lower" operator with the given argument; returns a column value in lower case...
const COP_SEQ
to return the next value of a sequence
Definition: SqlUtil.qm.dox.h:2151
Qore::AbstractIterator pairIterator()
Returns a HashPairIterator object for the contained hash.
const Hash
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:6919
list getAlignProcedureSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a stored procedure in the database to the st...
const String
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
hash op_cge(string arg)
returns a hash for the ">=" operator with the given argument for use in where clauses when comparing ...
const DefaultIopMap
a hash of default insert operator descriptions (currently empty, all operators are driver-dependent) ...
Definition: SqlUtil.qm.dox.h:4084
private hash getTriggerOptions()
returns the trigger options for this driver
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4413
const TableOmissionOptions
alignment omission options
Definition: SqlUtil.qm.dox.h:6741
string getDropSql()
returns a string that can be used to drop the sequence from the database
list getDropSchemaSql(hash schema_hash, *hash opt)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
copy(AbstractHashContainer old)
creates a "deep copy" of the object
hash cop_append(any column, string arg)
returns a hash for the "append" operator with the given argument
hash uop_append(string arg, *hash nest)
returns a hash for the "append" or concatenate operator with the given argument
string sprintf(string fmt,...)
constructor(*hash nh)
creates the object with the hash argument passed
int insertFromSelect(list cols, AbstractTable source, hash sh, reference sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
Qore::ListIterator iterator()
Returns a ListIterator object for the contained list.
private hash getDatabaseOptions()
override in subclasses to return driver-specific options
deprecated truncateNoCommit()
A legacy warpper for truncate()
bool hasColumn(string cname)
returns True if the constraint references the named column
const AC_Unchanged
used when an existing object matches the template and no changes are made
Definition: SqlUtil.qm.dox.h:5701
hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts)
returns lists of SQL strings to disable this constraint plus any dependent constraints and another li...
string getElementName()
must return the name of the contained element
bool equal(ForeignConstraintTarget targ)
returns True if the argument is equal to the current object, False if not
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table is already known to be in the database...
int delCommit()
SqlUtil::AbstractTable::delCommit() variant
bool dropProcedureIfExists(string name, *hash opt)
drops the given procedure if it exists; returns True if the procedure was dropped, False if not
const OP_IN
the SQL "in" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3607
deprecated createNoCommit(*hash opt)
A legacy wrapper for create()
constructor(*hash c)
creates the object from the argument
bool checkExistence()
returns True if the table exists in the database, False if not
*hash getHash()
returns the hash contained by this object
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:6663
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:2169
bool equal(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
bool hasReturning()
returns True if the current database driver supports the "returning" clause in insert statements...
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
any methodGate(string meth)
executes a method on the contained AbstractTable object
hash iop_seq(string arg)
returns a hash for retrieving the value of the given sequence in insert queries
bool equalExceptName(AbstractIndex ix)
returns True if the argument is equal to the current index with the exception of the name...
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:2002
AbstractFunction memberGate(string k)
returns the AbstractFunction object corresponding to the key given or throws a KEY-ERROR exception ...
hash uop_upper(*hash nest)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
list getAlignFunctionSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a function in the database to the function d...
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:6701
*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:6824
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:4502
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
constructor(string n)
creates the object and sets its name
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:5348
private hash getCreationOptions()
override in subclasses to return driver-specific options
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
hash op_between(any l, any r)
returns a hash for the "between" operator with the given arguments, neither of which can be NULL or N...
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
const UpsertResultLetterMap
maps upsert result codes to single letter symbols
Definition: SqlUtil.qm.dox.h:7003
const UpsertStrategyMap
hash mapping upsert strategy codes to a text description
Definition: SqlUtil.qm.dox.h:6938
hash make_iop(string iop, any arg)
returns a hash with _iop and arg keys
*hash selectRow(*hash sh, *reference sql, *hash opt)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
AbstractIndex take(string k)
removes the given key from the contained hash and returns the value
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the sequence in the database
abstract list getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the trigger in the database
dropCommit(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
const DropSchemaOptions
default generic drop schema options
Definition: SqlUtil.qm.dox.h:5807
hash uop_prepend(string arg, *hash nest)
returns a hash for the "prepend" operator with the given argument
const SchemaDescriptionOptions
default generic schema description keys
Definition: SqlUtil.qm.dox.h:5822
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:6965
constructor(string t, Columns c)
creates the object and sets the target table name and the target columns
constructor(string n_name, string n_src)
creates the object from the arguments
hash op_in()
returns a hash for the "in" operator with all arguments passed to the function; for use in where clau...
cache(*hash opts)
reads in all attributes of the table from the database
string printf(string fmt,...)
const OP_BETWEEN
the SQL "between" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3602
*AbstractColumnSupportingConstraint constraint
the AbstractColumnSupportingConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:4924
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view cannot be found ...
*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...
abstract any take(string k)
removes the given key from the contained hash and returns the value
const DatabaseOptions
database options
Definition: SqlUtil.qm.dox.h:5668
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database; if disabli...
private hash getIndexOptions()
returns the index options for this driver
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:4907
*AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk)
finds a unique constraint with the same columns as the unique constraint passed
const OP_OR
to combine SQL expressions with "or" for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3620
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
add(string k, AbstractColumn val)
adds the given value to the hash with the given key name
const COP_OVER
the SQL "over" clause
Definition: SqlUtil.qm.dox.h:2106
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:5213
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:6994
deprecated *hash insertNoCommit(hash row, *reference sql, *hash opt)
A legacy wrapper for SqlUtil::AbstractTable::insert()
const UR_Deleted
row was deleted (only possible with batch upsert methods such as AbstractTable::upsertFromIterator() ...
Definition: SqlUtil.qm.dox.h:6977
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:6869
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
list listTables()
returns a list of string table names in the database
hash op_ne(any arg)
returns a hash for the "!=" or "<>" operator with the given argument for use in where clauses when co...
constructor(string n, *hash c, *string n_index)
creates the object from the name an a hash of column information
abstract private bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns a hash keyed with the table name assigned to a hash with jop, table, jcols, cond, alias, and ta keys
bool hasColumn(string cname)
returns True if the constraint references the named column
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:3562
AbstractIndex dropIndex(string iname, *reference sql)
drops the given index from the table; if the table is known to be in the database already...
computeStatistics(*hash options)
Compute database statistics.
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table
setSupportingConstraint()
clears the supporting constraint
hash cop_sum(any column)
returns a hash for the "sum" operator; returns the total sum of a numeric column. ...
hash cop_as(any column, string arg)
returns a hash for the "as" operator with the given argument
private hash getSchemaDescriptionOptions()
override in subclasses to return driver-specific options
string getType()
returns the type of object
any methodGate(string meth)
executes a method on the contained AbstractDatabase object
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
abstract softlist getRenameSql(string new_name)
returns a list with command(s) that can be used to rename the view in the database ...
hash cop_year_month(any column)
returns a hash for the "year_month" operator with the given argument
const COP_SUM
to return the sum value
Definition: SqlUtil.qm.dox.h:2096
list getAlignSql(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from the database
private hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
private constructor(AbstractDatasource nds, string nname, *hash nopts)
creates the object; private constructor
truncateCommit()
truncates all the table data; releases the transaction lock after executing
string name
the name of the object
Definition: SqlUtil.qm.dox.h:5374
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:5260
*list getCreateIndexesSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
*string getDropFunctionSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given function if it exists or NOTHING if the named function does...
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:4747
add(string k, AbstractConstraint val)
adds the given value to the hash with the given key name
hash op_gt(any arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing c...
const COP_SEQ_CURRVAL
to return the last value of a sequence issued in the same session
Definition: SqlUtil.qm.dox.h:2156
private hash getComputeStatisticsOptions()
override in subclasses to return driver-specific options
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:4843
int upsert(hash row, int upsert_strategy=UpsertAuto, *hash opt)
update or insert the data in the table according to the hash argument; the table must have a unique k...
list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt)
returns a list of strings to drop and recreate the current index; if there are dependent constraints...
const AC_Create
used when a new object is created
Definition: SqlUtil.qm.dox.h:5704
add(string k, AbstractFunction val)
adds the given value to the hash with the given key name
const True
AbstractTrigger memberGate(string k)
returns the AbstractTrigger object corresponding to the key given or throws a KEY-ERROR exception ...
abstract private hash getQoreTypeMapImpl()
returns the qore type -> column type map
list keys()
Returns a list of key names of the contained hash.
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql)
adds a foreign constraint to the table; if the table is already known to be in the database...
hash iop_seq_currval(string arg)
returns a hash for retrieving the current value of the given sequence in insert queries ...
const JopMap
a hash of valid join operators
Definition: SqlUtil.qm.dox.h:3063
hash make_op(string op, any arg)
returns a hash with op and arg keys
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:2025
const OP_GT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3552
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:2008
hash op_clt(string arg)
returns a hash for the "<" operator with the given argument for use in where clauses when comparing t...
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:2091
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:1986
const DB_MVIEWS
Feature: materialized views / snapshots.
Definition: SqlUtil.qm.dox.h:1980
private clearImpl()
clears any driver-specific table information
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:3055
base class for sequences
Definition: SqlUtil.qm.dox.h:5300
*hash upsertFromIteratorCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
hash join_inner_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments for use when joining with a table ot...
*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 ...
hash op_cgt(string arg)
returns a hash for the ">" operator with the given argument for use in where clauses when comparing t...
private hash getColumnOperatorMap()
returns the column operator map for this object
string getElementName()
must return the name of the contained element
add(any val)
adds the given value to the list
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
abstract string getElementName()
must return the name of the contained element
Columns subset(softlist l)
returns a subset of the current columns according to the list argument
nothing flush()
bool nullable
True if the column can hold a NULL value, False if not
Definition: SqlUtil.qm.dox.h:4753
hash cop_min(any column)
returns a hash for the "min" operator; returns minimum column values
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql)
adds a primary key to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:6857
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:2076
hash uop_substr(int start, *int count, *hash nest)
returns a hash for the "substr" operator with the given arguments; returns a substring of a column va...
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:2146
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:6693
AbstractFunction makeFunction(string name, string src, *hash opts)
creates a database-specific AbstractFunction object corresponding to the arguments ...
Columns describe()
returns an object of class Columns describing the table
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
*list getDropAllForeignConstraintsOnTableSql(string name, *hash opt)
returns a list of SQL strings that can be used to drop all the foreign constraints on a particular ta...
hash uop_plus(any arg, *hash nest)
returns a hash for the "+" operator with the given arguments
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:7023
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:7029
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt)
gets a list of SQL strings to drop all constraints and indexes with the given column name; if the col...
private hash getUpdateOperatorMap()
returns the update operator map for this object
bool dropSequenceIfExists(string name, *hash opt)
drops the given sequence if it exists; returns True if the sequence was dropped, False if not ...
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
const IOP_SEQ_CURRVAL
for using the last value of a sequence issued in the current session
Definition: SqlUtil.qm.dox.h:4081
AbstractFunction take(string k)
removes the given key from the contained hash and returns the value
hash op_cne(string arg)
returns a hash for the "!=" or "<>" operator with the given argument for use in where clauses when co...
*list selectRows(*hash sh, *reference sql, *hash opt)
returns a list of hashes representing the rows in the table that match the argument hash ...
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:5607
const CacheOptions
generic cache options
Definition: SqlUtil.qm.dox.h:5676
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:6903
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
abstract private bool tryInsertImpl(string sql, hash row)
tries to insert a row, if there is a duplicate key, then it returns False, if successful, returns True
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
const AC_Modify
used when an object is modified in place
Definition: SqlUtil.qm.dox.h:5713
bool equal(Columns cols)
returns True if the argument has the same columns in the same order as the current object...
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:3592
any memberGate(string k)
returns the value of the given key in the contained hash if it exists, otherwise throws a KEY-ERROR e...
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:5537
*hash select(*hash sh, *reference sql, *hash opt)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
abstract private doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh)
processes a string for use in SQL select statements when there is a "limit" argument, but no "orderby" or "offset" arguments
constructor(AbstractDatasource ds, string name, *hash opts)
creates the Table object
private hash getSqlDataCallbackOptions()
returns the sql data operation callback options for this driver
const OP_CGT
the SQL greater than operator (>) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3582
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:5282
hash op_like(string str)
returns a hash for the "like" operator with the given argument for use in where clauses ...
SqlUtil::AbstractDatabase getDatabase()
gets the underlying AbstractDatabase
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:5287
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
*AbstractColumnSupportingConstraint getSupportingConstraint()
returns the supporting constraint, if any
deprecated *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtil::AbstractTable::upsertFromSelect() wrapper.
const False
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
constructor(string n, string n_src)
creates the object and sets its name and the check clause source
AbstractConstraint memberGate(string k)
returns the AbstractConstraint object corresponding to the key given or throws a KEY-ERROR exception ...
Mutex l()
mutex for atomic actions
deprecated dropNoCommit(*hash opt)
A legacy wrapper for drop()
abstract private copyImpl(AbstractTable old)
db-specific copy actions
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
const NothingType
hash op_lt(any arg)
returns a hash for the "<" operator with the given argument for use in where clauses when comparing c...
hash cop_coalesce(any col1, any col2)
returns a hash for the "coalesce" operator with the given column arguments; the first non-NULL column...
hash op_le(any arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
private hash getInsertFromIteratorOptions()
returns the insert from iterator options for this driver
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:4848
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy=UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing a single row that will be u...
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:5083
const AC_Drop
used when an object is dropped
Definition: SqlUtil.qm.dox.h:5707
bool equal(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
constructor(string n, bool u, hash c)
creates the object from the name, a unique flag, and a hash of column information ...
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:2101
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:3597
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:4131
the SqlUtil namespace contains all the objects in the SqlUtil module
Definition: SqlUtil.qm.dox.h:1969
hash op_substr(int start, *int count, string text)
returns a hash for the "substr" operator with the given arguments; for use in where clauses ...
bool empty()
returns True if the table has no definitions, False if not
hash cop_distinct(any column)
returns a hash for the "distinct" operator with the given argument; returns distinct column values ...
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
const ActionLetterMap
maps from action codes to action letter codes
Definition: SqlUtil.qm.dox.h:5770
string name
the table's name
Definition: SqlUtil.qm.dox.h:7015
abstract private bool supportsTablespacesImpl()
returns True if the database support tablespaces
bool supportsPackages()
returns True if the database supports packages
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:5489
AbstractTrigger dropTrigger(string tname, *reference sql)
drops the given trigger from the table; if the table is known to be in the database already...
int index(softstring str, softstring substr, softint pos=0)
string src
the source of the check clause
Definition: SqlUtil.qm.dox.h:5088
string getDatasourceDesc()
returns a descriptive string for the datasource
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:7021
private *hash getPseudoColumnHash()
returns a hash of valid pseudocolumns
addSourceConstraint(string tname, AbstractForeignConstraint fk)
adds a foreign constraint source to the unique constraint
*string getDropSequenceSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given sequence if it exists or NOTHING if the named sequence does...
hash cop_cast(any column, string arg, *any arg1, *any arg2)
returns a hash for the "cast" operator with the given argument(s)
private hash getDropSchemaOptions()
override in subclasses to return driver-specific options
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:1982
AbstractColumn take(string k)
removes the given key from the contained hash and returns the value
list listProcedures()
returns a list of string procedure names in the database
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:2066
deprecated *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
A legacy SqlUtik::AbstractTable::upsertFromIterator() wrapper.
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
code getUpsertClosure(hash row, int upsert_strategy=UpsertAuto, *hash opt)
returns a closure that can be executed given a hash argument representing a single row that will be u...
const COP_PLUS
the SQL "plus" operator
Definition: SqlUtil.qm.dox.h:2116
private hash getSelectOptions()
returns the select options for this driver
const Boolean
abstract private bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
hash cop_minus(any column1, any column2)
returns a hash for the "-" operator with the given arguments
hash cop_substr(any column, int start, *int count)
returns a hash for the "substr" operator with the given arguments; returns a substring of a column va...
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:6968
abstract private bool supportsSequencesImpl()
returns True if the database supports sequences
clear()
purges the current table definition
const OP_GE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3557
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:4861
private validateColumnOptions(string cname, reference opt, bool nullable)
validates column options
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:2031
abstract private bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
hash uop_minus(any arg, *hash nest)
returns a hash for the "-" operator with the given arguments
const TableOptions
table options
Definition: SqlUtil.qm.dox.h:6672
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
const AC_Rename
used when an object is renamed
Definition: SqlUtil.qm.dox.h:5710
abstract bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
private hash getTableColumnDescOptions()
returns the table column description options for this driver
*hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
const DB_SYNONYMS
Feature: synonyms.
Definition: SqlUtil.qm.dox.h:1994
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:4756
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
string getCreateSql(AbstractTable t)
returns an sql string that can be used to add the column to a table
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:7019
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
hash uop_seq_currval(string seq)
returns a hash for the "seq" operator with the given argument giving the sequence name whose current ...
const COP_COALESCE
to return the first non-null argument in the list
Definition: SqlUtil.qm.dox.h:2161
reclaimSpace(*hash options)
Reclaim taken but unused space in the DB.
hash cop_plus(any column1, any column2)
returns a hash for the "+" operator with the given arguments
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:7033
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:6763
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
*AbstractIndex findEqual(AbstractIndex ix)
find an index with columns equal to the index passed
bool emptyData()
returns True if the table has no data rows, False if not
bool tableRenamed(string old_name, string new_name, string old_sql_name)
updates table names and internal references for renamed tables
string getBaseType()
returns the base type of the underlying object (normally "table", some DB-specific implementations ma...
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
removeSourceConstraint(string tname, list cols)
removes a source constraint
*list getCreateForeignConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
string getNativeTypeString(string native_type, int precision)
returns the string describing the native type that can be used in SQL (for example to add the column ...
abstract bool hasArrayBind()
returns True if the underlying DB driver supports bulk DML operations
hash cop_lower(any column)
returns a hash for the "lower" operator with the given argument; returns a column value in lower case...
int updateCommit(hash set, hash cond, reference sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
hash wop_or(hash h1, hash h2)
returns a hash with a fake "_OR_" column name; the list of arguments to the function is combined such...
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:7027
string getDesc()
returns a descriptive string of the datasource (without the password) and the table name (with a poss...
*string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts)
returns an SQL string that can be used to rename the given table if it exists and the target does not...
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:1984
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:5792
abstract string getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
AbstractTable memberGate(string k)
returns the AbstractTable object corresponding to the key given or throws a KEY-ERROR exception ...
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3567
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database; if disabling constraints ...
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
bool dropViewIfExists(string name, *hash opt)
drops the given view if it exists; returns True if the view was dropped, False if not ...
bool exists(...)
int del()
SqlUtil::AbstractTable::del() variant
AbstractForeignConstraint take(string k)
removes the given key from the contained hash and returns the value
abstract private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
abstract string getElementName()
must return the name of the contained element
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:4759
hash join_left_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments for use when joining with a table other ...
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...
Qore::AbstractIterator dropIterator()
returns an iterator for a list of cached table names in the order that can be used to drop the tables...
bool val()
Returns False if the contained list is empty, True if not.
string getSelectSql(*hash sh, *reference args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
string src
the source code
Definition: SqlUtil.qm.dox.h:5345
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:4915
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
list getModifySql(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
hash cop_over(any column, string arg)
returns a hash for the "over" clause
const AC_Insert
used when data is inserted in a table
Definition: SqlUtil.qm.dox.h:5725
add(string k, Table val)
adds the given value to the hash with the given key name
constructor(AbstractDatasource ds, *hash opts)
creates the Database object
string getNativeTypeString()
returns the string describing the native type that can be used in SQL (for example to add the colunn ...
Qore::AbstractIterator iterator()
Returns a HashIterator object for the contained hash.
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifier for schema, etc)
abstract list getAddColumnSql(AbstractTable t)
returns a list of sql strings that can be used to add the column to an existing table ...
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:2136
string src
the source of the object
Definition: SqlUtil.qm.dox.h:5380
hash join_right_alias(string ta, string table_name, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments for use when joining with a table other...
string getElementName()
must return the name of the contained element
private hash getForeignConstraintOptions()
return the foreign constraint options for this driver
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:2086
AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql)
drops a foreign constraint from the table; if the table is known to be in the database already...
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:2041
string getDriverName()
returns the database driver name
hash cop_divide(any column1, any column2)
returns a hash for the "/" operator with the given arguments
hash op_ge(any arg)
returns a hash for the ">=" operator with the given argument for use in where clauses when comparing ...
abstract list getRenameSql(string table_name, string new_name)
returns a list of SQL strings that can be used to rename the constraint in the database ...
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:7017
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:1992
hash op_not(hash arg)
returns a hash for the "not" operator; for use in where clauses
const OP_LE
the SQL less than or equals (<=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3547
private hash getCacheOptions()
override in subclasses to return driver-specific options
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:2011
string name
the name of the index
Definition: SqlUtil.qm.dox.h:4912
private hash getReclaimSpaceOptions()
override in subclasses to return driver-specific options
string type(any arg)
hash cop_value(any arg)
returns a hash for the "value" (literal) operator with the given argument
AbstractConstraint dropConstraint(string cname, *reference sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
*string getCreatePrimaryKeySql(*hash opt, bool cache=True)
returns an SQL string that could be used to create the primary key on the table
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:5268
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:3577
hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
the API for a constraint with columns
Definition: SqlUtil.qm.dox.h:5110
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:1988
string getElementName()
must return the name of the contained element
createCommit(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:2014
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
bool supportsTypes()
returns True if the database supports named types
const OP_NOT
the SQL "not" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3612
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
clear()
purges the contained data
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:4918
abstract string getCreateSql(string table_name, *hash opts)
returns a string that can be used to create the constraint in the database
AbstractForeignConstraint memberGate(string k)
returns the AbstractForeignConstraint object corresponding to the key given or throws a KEY-ERROR exc...
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:6831
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:5369
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:1990
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
deprecated int updateNoCommit(hash set, *hash cond, *reference sql)
A legacy SqlUtil::AbstractTable::update() wrapper.
bool empty()
returns True if the container is empty, False if not
copy(AbstractTable old)
copies the object
private hash getInsertOptions()
returns the insert options for this driver
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:6983
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
string name
the name of the column
Definition: SqlUtil.qm.dox.h:4741
bool empty()
returns True if the container is empty, False if not
clearIndex()
clears any index base for the constraint
deprecated int delNoCommit(*hash cond, *reference sql)
A legacy SqlUtil::AbstractTable::del() wrapper.
bool bindEmptyStringsAsNull()
returns True if the DB treats empty strings as NULL, False if not; by default this method returns Fal...
private hash getAlignSchemaOptions()
override in subclasses to return driver-specific options
private hash getConstraintOptions()
returns the constraint options for this driver
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:5612
string getName()
returns the constraint name
bool same(list l)
abstract private list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
string getName()
returns the index name
base class for functions
Definition: SqlUtil.qm.dox.h:5410
private hash getTableDescriptionHashOptions()
returns the table description hash options for this driver
const COP_MULTIPLY
the SQL "multiply" operator
Definition: SqlUtil.qm.dox.h:2126
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql)
adds a unique constraint to the table; if the table is known to be in the database already...
list listSequences()
returns a list of string sequence names in the database
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:7025
int insertFromSelectCommit(list cols, AbstractTable source, hash sh, reference sql, hash opt)
inserts rows into a table based on a select statement from another table (which must be using the sam...
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:2051
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
list listFunctions()
returns a list of string function names in the database
bool partialMatchKeys(hash h1)
returns True if the hash argument has at least the same keys (in any order, can have more keys)...
AbstractSequence makeSequence(string name, number start=1, number increment=1, *softnumber end, *hash opts)
creates a database-specific AbstractSequence object corresponding to the arguments ...
const AC_Recreate
used when an object is recreated (usually dropped and recreated in place)
Definition: SqlUtil.qm.dox.h:5722
abstract clearIndex()
clears any index base for the constraint
*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:5334
bool hasKey(string k)
Returns True if the key exists in the contained hash (may or may not be assigned a value)...
bool equal(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
abstract list getRenameSql(string new_name)
returns a string that can be used to rename the function in the database
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:5618
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
AbstractTable getTable()
returns the AbstractTable object contained by this object
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:5865
*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...
AbstractFunction makeProcedure(string name, string src, *hash opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
renameKey(string old_name, string new_name)
renames the given key; maintains the key order
abstract private int getCurrentSequenceValueImpl(string name)
returns the last value issued for the given sequence in the current session
private hash getTableCreationOptions()
returns the table creation options for this driver
const InsertOptions
generic SQL insert options
Definition: SqlUtil.qm.dox.h:6846
AbstractTrigger take(string k)
removes the given key from the contained hash and returns the value
abstract private bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:6708
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
hash cop_prepend(any column, string arg)
returns a hash for the "prepend" operator with the given argument
string type
the type of object
Definition: SqlUtil.qm.dox.h:5377
const Int
AbstractIndex renameIndex(string old_name, string new_name, reference sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:2131
constructor(softlist nl)
creates the object with the list argument passed
string string(softstring str, *string enc)
const SequenceDescriptionOptions
default generic sequence description keys
Definition: SqlUtil.qm.dox.h:5845
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
abstract list getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the trigger in the database
softint rowCount()
returns the number of rows in the table
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
string getElementName()
returns "table" since this object stores AbstractTable objects
abstract private hash getTypeMapImpl()
returns the type name -> type description hash
deprecated int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt)
A legacy SqlUtil::AbstractTable::insertFromSelect() wrapper.
string getDropSql()
returns a string that can be used to drop the view from the database
hash uop_divide(any arg, *hash nest)
returns a hash for the "/" operator with the given arguments
string getElementName()
returns "foreign constraint" for the type of object encapsulated
int size
the size of the column
Definition: SqlUtil.qm.dox.h:4750
AbstractColumn renameColumn(string old_name, string new_name, reference sql)
renames an existing column; if the table is already known to be in the database, then the changes are...
constructor(string n, *hash c, *string n_index)
creates the object from the name and a hash of column information
bool dropTableIfExists(string name, *hash opt)
drops the given table if it exists; returns True if the table was dropped, False if not ...
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
string getSqlValue(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
int size()
Returns the number of keys in the contained hash.
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
Qore::AbstractIterator keyIterator()
Returns a HashKeyIterator object for the contained hash.
private hash getWhereOperatorMap()
returns the "where" operator map for this object
abstract string getRenameSql(string new_name)
returns a string that can be used to rename the sequence in the database
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:4744
const COP_VALUE
to append a constant value (SQL Literal) to use as an output column value
Definition: SqlUtil.qm.dox.h:2061
const UpsertUpdateOnly
Upsert option: update if the row exists, otherwise ignore.
Definition: SqlUtil.qm.dox.h:6933
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:4684
the base class for triggers
Definition: SqlUtil.qm.dox.h:5471
hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
hash op_eq(any arg)
returns a hash for the "=" operator with the given argument for use in where clauses when comparing c...
Qore::AbstractIterator getSourceConstraintIterator()
returns an iterator through all known source foreign constraints on the current table ...
private hash getAlignTableOptions()
returns the align table options for this driver
const OP_LT
the SQL less than (<) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3542
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:5614
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...
const AlignSchemaOptions
default generic schema description / alignment options
Definition: SqlUtil.qm.dox.h:5802
*hash findConstraintOn(string table, softlist cols)
returns either a hash of AbstractColumn information or NOTHING if no foreign constraint can be found ...
add(string k, AbstractForeignConstraint val)
adds the given value to the hash with the given key name
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:5433
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:6974
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:6971
int getNextSequenceValue(string name)
returns the next value in the given sequence
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:5542
the base class for column information
Definition: SqlUtil.qm.dox.h:4736
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:2046
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:6926
setName(string new_name)
sets the new name of the object
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
add(string k, AbstractTrigger val)
adds the given value to the hash with the given key name
const OP_CGE
the SQL greater than or equals operator (>=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3587
const AC_Truncate
used when a table is truncated
Definition: SqlUtil.qm.dox.h:5716
hash op_cle(string arg)
returns a hash for the "<=" operator with the given argument for use in where clauses when comparing ...
string getName()
returns the name of the table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:6571
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:6682
private hash getColumnOptions()
returns the column options for this driver
list values()
Returns a list of values of the contained hash.
*hash find(any id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
bool equal(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:2805
hash cop_seq(string seq, *string as)
returns a hash for the "seq" operator with the given argument giving the sequence name whose value sh...
rename(string new_name, *reference sql, *Tables table_cache)
renames the table; if the table is already known to be in the database in the database, then the changes are effected in the database also immediately; otherwise it is only updated internally
AbstractTable take(string k)
removes the given key from the contained hash and returns the value
hash make_cop(string cop, any column, any arg)
returns a hash with cop, column, and arg keys
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:2081
const UpsertSelectFirst
Upsert option: select first, if the row is unchanged, do nothing, if it doesn't exist, insert, otherwise update.
Definition: SqlUtil.qm.dox.h:6912
bool rebuildIndex(string name, *hash options)
Rebuild an index in the DB.
bool dropFunctionIfExists(string name, *hash opt)
drops the given function if it exists; returns True if the function was dropped, False if not ...
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:2141
const Closure
setupTable(hash desc, *hash opt)
creates the object from a table description hash
add(string k, AbstractIndex val)
adds the given value to the hash with the given key name
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:6895
private hash getCallbackOptions()
override in subclasses to return driver-specific options
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:5342
constructor(string n, string n_src)
creates the object and sets its name and the trigger source
*string getIndex()
returns the name of the associated index, if any
list features()
See DBFeaturesConstants.
*number max
the ending number
Definition: SqlUtil.qm.dox.h:5314
abstract private bool checkExistenceImpl()
returns True if the table exists in the DB, False if not
hash cop_upper(any column)
returns a hash for the "upper" operator with the given argument; returns a column value in upper case...
bool val()
Returns False if the contained hash has no keys, True if it does.
list getList()
returns the list contained by this object
hash uop_multiply(any arg, *hash nest)
returns a hash for the "*" operator with the given arguments
private bool asteriskRequiresPrefix()
returns True if the database requires a wildcard "*" to be prefixed with the table name when it appea...
const ColumnDescOptions
Column description options.
Definition: SqlUtil.qm.dox.h:6806
number increment
the increment
Definition: SqlUtil.qm.dox.h:5311
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
AbstractColumn memberGate(string k)
returns the AbstractColumn object corresponding to the key given or throws a KEY-ERROR exception ...
bool matchKeys(hash h1)
returns True if the hash argument has the same keys (in any order), False if not
int update(hash set, hash cond, reference sql, hash opt)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
list listViews()
returns a list of string view names in the database
*string getDropProcedureSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given procedure if it exists or NOTHING if the named procedure do...
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
const OP_LIKE
the SQL "like" operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3537
findMatchingIndex(*Indexes indexes)
find an index that matches the constraint and marks both objects as related
const CallbackOptions
generic callback options
Definition: SqlUtil.qm.dox.h:5686
const TableDescriptionHashOptions
Table description options.
Definition: SqlUtil.qm.dox.h:6783
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:2022
AbstractIndex memberGate(string k)
returns the AbstractIndex object corresponding to the key given or throws a KEY-ERROR exception ...
int size()
Returns the number of elements in the contained list.
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
list getDropList()
returns a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
const ActionDescMap
maps from action descriptions to action codes
Definition: SqlUtil.qm.dox.h:5754
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:6576
abstract private *string getSqlValueImpl(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
const OP_CLT
the SQL less than (<) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:3572
const COP_MINUS
the SQL "minus" operator
Definition: SqlUtil.qm.dox.h:2111
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
clearIndex()
clears any index base for the constraint
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:5265
hash hash(object obj)
private hash getRebuildIndexOptions()
override in subclasses to return driver-specific options
int getCurrentSequenceValue(string name)
returns the last value issued for the given sequence in the current session
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
abstract private int getNextSequenceValueImpl(string name)
returns the next value in the given sequence
private bool hasReturningImpl()
returns True if the current database driver supports the "returning" clause in insert statements...
private hash getColumnDescOptions()
returns the column description options for this driver
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
const TableCreationOptions
table creation options
Definition: SqlUtil.qm.dox.h:6751
hash cop_year_day(any column)
returns a hash for the "year_day" operator with the given argument
const AC_Delete
used when data is deleted in a table
Definition: SqlUtil.qm.dox.h:5731
*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...
const COP_SUBSTR
to extract a substring from a column
Definition: SqlUtil.qm.dox.h:2166
const ComputeStatisticsOptions
Options for computeStatistics()
Definition: SqlUtil.qm.dox.h:5852
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:3060
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:3617
hash make_uop(string uop, any arg, *hash nest)
returns a hash with uop, arg, and nest keys
int upsertCommit(hash row, int upsert_strategy=UpsertAuto, *hash opt)
update or insert the data in the table according to the hash argument; the table must have a unique k...
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:2028
const AC_Update
used when data is updated in a table
Definition: SqlUtil.qm.dox.h:5728
private hash getInsertOperatorMap()
returns the insert operator map for this object
*string getDropConstraintIfExistsSql(string tname, string cname, *hash opts)
returns an SQL string that can be used to drop an existing constraint on a table, if the table is not...
hash cop_year(any column)
returns a hash for the "year" operator with the given argument
number start
the starting number
Definition: SqlUtil.qm.dox.h:5308
const IOP_SEQ
for using the value of a sequence
Definition: SqlUtil.qm.dox.h:4076
const AC_NotFound
used when dropping object but the object is not present
Definition: SqlUtil.qm.dox.h:5734
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
populate(AbstractDatasource ds, hash tables, *hash opt)
populates the object from a hash description
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql, *hash opt)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:5660
private hash getTableOptions()
returns the table options for this driver
*list getDropTableSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given table if it exists or NOTHING if the named table does not e...
any take(int i)
removes the given element from the contained list and returns the value
hash cop_multiply(any column1, any column2)
returns a hash for the "*" operator with the given arguments
const AC_Add
used when an element is added to an existing object
Definition: SqlUtil.qm.dox.h:5719
hash cop_seq_currval(string seq, *string as)
returns a hash for the "seq_currval" operator with the given argument giving the sequence name whose ...
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
string getDropSql(string table_name)
returns a string that can be used to drop the index from the database
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
renameSourceConstraintTable(string old_name, string new_name)
renames a table in a source constraint
*AbstractForeignConstraint findEqual(AbstractForeignConstraint fk)
find an index with columns equal to the index passed
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:5118
represents a primary key
Definition: SqlUtil.qm.dox.h:5202
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:3050
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:2071
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found ...
private hash getSequenceDescriptionOptions()
override in subclasses to return driver-specific options
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
abstract private doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference 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...
const COP_DIVIDE
the SQL "divide" operator
Definition: SqlUtil.qm.dox.h:2121
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:1978
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:2005
abstract list getCreateSql(*hash opt)
returns a list of SQL strings that can be used to create the function in the database ...
abstract bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
hash op_ceq(string arg)
returns a hash for the "=" operator with the given argument for use in where clauses when comparing t...
*hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:5115
string getDropSql(string table_name)
returns a string that can be used to drop the column from the table
const UpsertStrategyDescriptionMap
hash mapping upsert strategy descriptions to upsert strategy codes
Definition: SqlUtil.qm.dox.h:6950
*string lastKey()
Returns the last key name in the contained hash or NOTHING if the contained hash has no keys...
private bool equalImpl(AbstractConstraint con)
returns True if the argument is equal to the current object, False if not
AbstractConstraint take(string k)
removes the given key from the contained hash and returns the value
*string firstKey()
Returns the first key name in the contained hash or NOTHING if the contained hash has no keys...
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...
bool supportsSequences()
returns True if the database supports sequences
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
hash cop_year_hour(any column)
returns a hash for the "year_hour" operator with the given argument
bool hasKeyValue(string k)
Returns True if the key exists in the contained hash and is assigned a value, False if not...
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:6690
*AbstractTable getIfExists(AbstractDatasource ds, string name)
gets a table from the database or from the cache if already cached; if the table does not exist...
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:3623
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:5193
rename(string n)
renames the constraint
private hash getUpsertOptions()
returns the upsert options for this driver
AbstractTable makeTable(string name, hash desc, *hash opts)
creates a database-specific AbstractTable object corresponding to the arguments
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:6819
*AbstractIndex tryTake(string k)
tries to remove the given key from the contained hash and returns the value if it exists ...
hash cop_max(any column)
returns a hash for the "max" operator; returns maximum column values
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:5021
const ReclaimSpaceOptions
Options for reclaimSpace()
Definition: SqlUtil.qm.dox.h:5857
hash cop_count(any column="")
returns a hash for the "count" operator; returns row counts
hash uop_seq(string seq)
returns a hash for the "seq" operator with the given argument giving the sequence name whose value sh...
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:4979
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:2056