Qore SqlUtil Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
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 2013 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.8 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
37  * 2013-10-04 v1.0: David Nichols <david@qore.org>
38  + the initial version of the SqlUtil module
39 */
40  ...
282  @endcode
283  @warning Oracle: using different comments in the same SQL can lead to new optimizer statement hard parsing.
284 
285  @anchor select_option_hint
286  @par Select Option "hint"
287  In database query operations, various SQL implementations use hints as additions to the SQL standard that instruct the database engine on how to execute the query. For example, a hint may tell the engine to use as little memory as possible (even if the query will run slowly), or to use or not to use an index (even if the query optimizer would decide otherwise).
288 
289  <b>Hint Example:</b>
290  @code
291 $table.selectRows( ("hint" : "full(t1)") );
292  @endcode
293  will produce select statement like this:
294  @code
295 select /*+ full(a) */ ...
296  @endcode
297  The string is taken as is and it's up to user to handle correct aliases in join functions etc.
298  @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
299  @warning Use hints only when you know what you are doing.
300 
301  @anchor select_option_columns
302  @par Select Option "columns"
303  <b>Columns Example:</b>
304  @code
305 my list $columns = ("id", "name", "started", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"));
306 my *list $rows = $table.selectRows(("columns": $columns, "where": ("type": "user")));
307  @endcode
308  By default, all columns are returned from a query; to limit the columns returned, or to perform column operations on the columns returned, use the \c "columns" option of the @ref select_option_hash "select option hash". \n\n
309  This option takes a list, each element of the list can be one of the following.\n\n
310  <b>A Simple String Giving a Column Name</b>\n
311  ex: \c "name"
312  @code
313 my *list $rows = $table.selectRows(("columns": ("id", "name", "started")));
314  @endcode \n
315  <b>A String in Dot Notation</b>\n
316  This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
317  @code
318 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner($table2, "t2", ("id": "altid"))));
319  @endcode \n
320  <b>A Column Operation Specified by a Column Operator Function</b>\n
321  ex: <tt>cop_as("column_name", "column_alias")</tt> \n
322  See @ref sql_cop_funcs "column operator function" for more information on column operator functions
323  @code
324 my *list $rows = $table.selectRows(("columns": ("id", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"))));
325  @endcode
326  For @ref sql_cop_funcs "column operator functions" taking a column name, either a string name or a name in dot notation is acceptable\n\n
327  <b>The Value \c "*", Meaning All Columns</b>\n
328  ex: \c "*"
329  @code
330 my *list $rows = $table.selectRows(("columns": "*"));
331  @endcode
332  This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
333  <b>An \c "*" in Dot Notation</b>\n
334  ex: \c "q.*"
335  @code
336 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.*"), "join": join_inner($table2, "t2", ("id": "altid"))));
337  @endcode
338 
339  @anchor select_option_where
340  @par Select Option "where"
341  <b>Where Example:</b>
342  @code
343 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
344  @endcode
345  The hash value assigned to this key describes how the \c "where" clause in the query is built. Because the \c "where" clause logic is common to many SQL methods, this topic is covered in a separate section. See @ref where_clauses for a detailed description of the value of this key.
346 
347  @anchor select_option_orderby
348  @par Select Option "orderby"
349  <b>Orderby Example:</b>
350  @code
351 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date"));
352  @endcode
353  This option is a list of the following values:
354  - a simple string giving a column name; ex: \c "name"
355  - a string giving a table or table alias and a column name in dot notation (for use with @ref select_option_join "joins"); ex: \c "q.name"
356  @note
357  - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
358 
359  @anchor select_option_desc
360  @par Select Option "desc"
361  <b>Desc Example:</b>
362  @code
363 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date", "desc": True));
364  @endcode
365  If the value of this key is @ref Qore::True "True" and results are ordered (either due to the @ref select_option_orderby "orderby option" or due to implicit ordering by the primary key due to the use of the @ref select_option_offset "offset option"), then results will be sorted in descending order.\n\n
366  Otherwise, ordered results are returned in ascending order by default.
367 
368  @anchor select_option_limit
369  @par Select Option "limit"
370  <b>Limit Example:</b>
371  @code
372 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
373  @endcode
374  This option will limit the number of rows returned.
375  @note
376  - This option is required if the @ref select_option_offset "offset option" is non-zero
377  - If this option is present and an @ref select_option_orderby "orderby option" is also present, then at least a subset of the @ref select_option_orderby "orderby" columns must correspond to a unique key of the table or an exception is raised
378 
379  @anchor select_option_offset
380  @par Select Option "offset"
381  <b>Offset Example:</b>
382  @code
383 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
384  @endcode
385  This option specifies the row number offset for the rows returned where the first row is at offset zero.
386  @note
387  - If this option is present, then either an @ref select_option_orderby "orderby option" must be present of which at least a subset of the @ref select_option_orderby "orderby" columns must correspond to a unique key of the table, or, if no @ref select_option_orderby "orderby option" is used, then the table must have a primary key which is used for the ordering instead.
388  - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
389  @see @ref sql_paging
390 
391  @anchor select_option_join
392  @par Select Option "join"
393  <b>Join Example:</b>
394  @code
395 my *list $rows = $table.selectRows(("columns": ("name", "version", "id", cop_as("st.value", "source"), cop_as("st.value", "offset")),
396  "join": join_left($function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
397  + join_left($function_instance_tags, "lt", NOTHING, ("st.tag": "_offset"))));
398  @endcode
399  To join multiple tables in a single query, use the \c "join" option. The \c "join" hash key should be assigned to a join description hash as returned by one of the @ref sql_jop_funcs or combined join description hash created by concatenating such values (see an example of this above).
400  @note the join columns do not need to be specified in the case that a foreign key in one table exists to the primary key of the other table; in this case this information is assumed for the join automatically
401 
402  @see @ref joins for more examples
403 
404  @anchor select_option_groupby
405  @par Select Option "groupby"
406  <b>Groupby Example:</b>
407  @code
408 my *list $rows = $table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type"));
409  @endcode
410  The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
411  The \c "groupby" hash key should be assigned to a list of column specifiers or a single column specifier. Column specifies for the \c "groupby"
412  key are strings giving column names, optionally in dot notation.
413 
414  @anchor select_option_having
415  @par Select Option "having"
416  <b>Having Example:</b>
417  @code
418 my *list $rows = $table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type", "having": ("service_type": (COP_COUNT, op_ge(100)))));
419  @endcode
420  The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
421  The \c "having" hash key should be assigned to a hash where each key is a column specifier (optionally in dot notation) and the values are lists with two elements; the first element must be a @ref sql_cops "column operator code", and the second element is a column operator description normally provided by using a @ref sql_cop_funcs "column operator function" as in the above example.
422 
423  @anchor select_option_superquery
424  @par Select Option "superquery"
425  <b>Superquery Example:</b>
426  @code
427 my *list $rows = $table.selectRows("columns": ("serviceid", "service_methodid", cop_as(cop_over(cop_max("service_methodid"), "serviceid"), "max_methodid")), "superquery": ("columns": ("serviceid", "service_methodid"), "where": ("max_methodid": op_ceq("service_methodid"))));
428  @endcode
429  The \c "superquery" option allows for the rest of the query arguments to define a subquery where as the hash arguments assigned to the \c "superquery" key define the select made from the subquery. In the example above, the \c "OVER" sql windowing function is used and then rows matching the \c "max_methodid)" result value are selected.\n\n
430  The above example results in an SQL command equivalent to the following:
431  @code
432 my *list $rows = $table.vselectRows("select serviceid,service_methodid from (select serviceid,service_methodid,max(service_methodid) over (partition by serviceid) as max_methodid from schema.service_methods) subquery where max_methodid = service_methodid");
433  @endcode
434  @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
435 
436  @subsection sql_paging Select With Paging
437 
438  There is support for paging query results in the following methods:
439  - @ref SqlUtil::Table::getRowIterator()
440  - @ref SqlUtil::Table::getSelectSql()
441  - @ref SqlUtil::Table::select()
442  - @ref SqlUtil::Table::selectRows()
443 
444  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
445 
446  Each of these methods takes a @ref select_option_hash "select option hash argument" that allows the \c "limit" and \c "offset" options to be specified to specify the data window for the results.
447 
448  If the \c "offset" options is used, then an \c "orderby" option is required which must match some unique constraint or unique index on the table to guarantee the order of results, unless the table has a primary key, in which case the primary key will be used by default if no \c "orderby" option is supplied.
449 
450  @par Example:
451  Select 100 rows starting at row 200 (the table's primary key will be used for the \c "orderby" option by default): \n
452  @code
453 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
454  @endcode
455  As an illustration of the different SQL that is generated for different database types; for the above query, here is the SQL generated for Oracle:
456  @code
457 $ds.vselectRows("select * from (select /*+ first_rows(100) */ a.*, rownum rnum from (select * from schema.table where type = %v order by type) a where rownum <= %v) where rnum > %v", ("user", 300, 200));
458  @endcode
459  And for PostgreSQL:
460  @code
461 $ds.vselectRows("select * from public.table where type = %v order by type limit %v offset %v", ("user", 100, 200));
462  @endcode
463 
464  @subsection check_matching_rows Check For At Least One Matching Row
465 
466  Use the @ref SqlUtil::Table::findSingle() method to find at least one matching row:
467  @code
468 my *hash $h = $table.findSingle(("account_type": "CUSTOMER"));
469 if ($h)
470  printf("found 1 customer row: %y\n", $l[0]);
471  @endcode
472 
473  Also it's possible to use the \c "limit" option to make an efficient check for at least one matching row as in the following example (which is functionally equivalent to the previous example):
474  @code
475 my *hash $h = $table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
476 if ($h)
477  printf("found 1 customer row: %y\n", $l[0]);
478  @endcode
479 
480  @section inserting_data Inserting Data into the Database
481 
482  The following methods can be used to insert data into the database:
483  - @ref SqlUtil::Table::insert(): inserts a single row into a table and commits the transaction
484  - @ref SqlUtil::Table::insertNoCommit(): inserts a single row into a table without committing the transaction
485  - @ref SqlUtil::Table::insertFromSelect(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and commits the transaction
486  - @ref SqlUtil::Table::insertFromSelectNoCommit(): inserts data in a table based on a select statement created from the @ref select_option_hash "select option hash" argument and without committing the transaction
487 
488  @see @ref sql_upsert for information about upserting or merging data
489 
490  @subsection inserting_data_explicitly Inserting Data Explicitly
491 
492  @par Example:
493  @code
494 $table.insert(("id": $id, "name": $name, "created": now_us()));
495  @endcode
496 
497  Data can be explicitly inserted into the database with immediate values with @ref SqlUtil::Table::insert() and @ref SqlUtil::Table::insertNoCommit() as in the above example.
498 
499  @subsection inserting_data_from_select Inserting Data From a Select Statement
500 
501  @par Example:
502  @code
503 my int $rows = $table.insertFromSelect(("id", "name", "created"), $source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER"))));
504  @endcode
505 
506  Data can be inserted into the database based on the results of a select statement with @ref SqlUtil::Table::insertFromSelect() and @ref SqlUtil::Table::insertFromSelectNoCommit() as in the above example.
507 
508  The example above would generate a %Qore SQL command like the following:
509  @code
510 return $ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER"));
511  @endcode
512 
513  The return value of these methods is the number of rows inserted. See @ref select_option_hash "select option hash" for more information about how to form the select criteria in these methods.
514 
515  @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
516 
517  To insert data from an iterator source (such as an @ref Qore::SQL::SQLStatement object), call @ref SqlUtil::Table::insertFromIterator() or @ref SqlUtil::Table::insertFromIteratorNoCommit() as in the following example:
518 
519  @par Example:
520  @code
521 # get the rows to be inserted
522 my list $l = get_table_rows();
523 # insert the data and commit after every 5000 rows
524 $table.insertFromIterator($l.iterator(), ("commit_block": 5000));
525  @endcode
526 
527  The iterator given to the @ref SqlUtil::Table::insertFromIterator() or @ref SqlUtil::Table::insertFromIteratorNoCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
528 
529  @note the @ref SqlUtil::AbstractTable::InsertOptions "insert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
530 
531  @section updating_data Updating Data
532 
533  The following methods can be used to update data:
534  - @ref SqlUtil::Table::update(): updates a single row and commits the transaction
535  - @ref SqlUtil::Table::updateNoCommit(): updates a single row and does not commit the transaction
536 
537  @par Example:
538  @code
539 my int $rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
540  @endcode
541 
542  The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
543  @code
544 return $ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
545  @endcode
546  And the following on MySQL:
547  @code
548 return $ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
549  @endcode
550 
551  @section deleting_data Deleting Data
552 
553  The following methods can be used to dekete data:
554  - @ref SqlUtil::Table::del(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
555  - @ref SqlUtil::Table::delNoCommit(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
556  - @ref SqlUtil::Table::truncate(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
557  - @ref SqlUtil::Table::truncateNoCommit(): truncates the table and does not commit the transaction
558 
559  @par Example:
560  @code
561 my int $dcnt = $table.del(("record_type": "OLD-CUSTOMER"));
562  @endcode
563 
564  The above example would generate a %Qore SQL command like the following:
565  @code
566 return $ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
567  @endcode
568 
569  The @ref SqlUtil::Table::del() and @ref SqlUtil::Table::delNoCommit() methods can be used to delete data from the database.
570 
571  See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
572 
573  @section joins Joining Tables
574 
575  Joining tables is made by providing a join specification to the @ref select_option_join "join select option" in
576  a @ref select_option_hash "select option hash" as in the following example:
577  @code
578 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner($table2, "t2", ("id": "altid"))));
579  @endcode
580  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
581 
582  Joins on multiple tables are performed by combining the results of @ref sql_op_funcs "join functions" with the @ref plus_operator "+ operator"
583  as follows:
584  @code
585 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner($table3, "t3")));
586  @endcode
587  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
588  automatically detected primary key to foreign key relationship between the two tables.
589 
590  Joins are by default made with the primary table; to join with another join table, then give the alias for the table as the first
591  argument to the @ref sql_op_funcs "join function" as in the following example:
592  @code
593 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner("t2", $table3, "t3")));
594  @endcode
595  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and \a table2 (aliased as \c t2) is joined
596  with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
597 
598  @see @ref select_option_join "join select option"
599 
600  @section where_clauses Where Clauses
601 
602  Several methods accept a hash of conditions to build a \c "where" clause to restrict the rows that are operated on or returned; for example:
603  - @ref SqlUtil::Table::del()
604  - @ref SqlUtil::Table::delNoCommit()
605  - @ref SqlUtil::Table::findAll()
606  - @ref SqlUtil::Table::findSingle()
607  - @ref SqlUtil::Table::getRowIterator()
608  - @ref SqlUtil::Table::getSelectSql()
609  - @ref SqlUtil::Table::insertFromSelect()
610  - @ref SqlUtil::Table::insertFromSelectNoCommit()
611  - @ref SqlUtil::Table::select()
612  - @ref SqlUtil::Table::selectRow()
613  - @ref SqlUtil::Table::selectRows()
614  - @ref SqlUtil::Table::update()
615  - @ref SqlUtil::Table::updateNoCommit()
616  - @ref SqlUtil::Table::upsertFromSelect()
617  - @ref SqlUtil::Table::upsertFromSelectNoCommit()
618 
619  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
620 
621  The where clause or condition hash is made of keys signifying the column names, and either a direct value meaning that the column value has to match exactly, or SQL operators can be given by using the appropriate operator function as the key value. Each member of the where hash translates to an expression that is combined with \c "AND" in the SQL query; to combine expressions with \c "OR", then use a list of @ref select_option_hash "select option hashes", which will combine each @ref select_option_hash "select option hash" with \c "OR" as in @ref where_list "this example".
622 
623  The where condition hash has the following format:
624  - each key gives a column name or a table/alias with column name in dot notation
625  - the values are either direct values, meaning that the equality operator (\c "=") is used, or a @ref sql_op_funcs "SQL operator function" for operators in the where clause
626 
627  @note To reference a column more than once in a where clause, prefix the column specification with a unique number and a colon as in the following example: @code my hash $w = ("0:created": op_ge($mindate), "1:created": op_lt($maxdate)); @endcode
628 
629  See @ref sql_op_funcs for a list of operator functions.
630 
631  @par Where Hash Example:
632  @code
633 my hash $w = (
634  "name": "Smith",
635  "account_type": op_like("%CUSTOMER%"),
636  "id": op_ge(500),
637 );
638  @endcode \n
639  The preceding example results in a where clause equivalent to: \c "name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
640  that bind by value is used, so, if used in a context like the following:
641  @code
642 my Table $t($ds, "table");
643 my *hash $qh = $t.select(("where": $w));
644  @endcode \n
645  the complete query would look instead as follows:
646  @code
647 $ds.vselect("select * from table where name = %v and account_type like %v and id >= %v", ("Smith", "%CUSTOMER%", 500));
648  @endcode
649 
650  @anchor where_list
651  @par Where List Example:
652  @code
653 my hash $w1 = (
654  "name": "Smith",
655  "account_type": op_like("%CUSTOMER%"),
656  "id": op_ge(500),
657 );
658 my hash $w2 = (
659  "name": "Jones",
660  "account_type": op_like("%VENDOR%"),
661  "id": op_ge(2500),
662 );
663 my Table $t($ds, "table");
664 my *hash $qh = $t.select(("where": ($w1, $w2)));
665  @endcode \n
666  the complete query would look instead as follows:
667  @code
668 $ds.vselect("select * from table where (name = %v and account_type like %v and id >= %v) or (name = %v and account_type like %v and id >= %v)", ("Smith", "%CUSTOMER%", 500, "Jones", "%VENDOR%", 2500));
669  @endcode
670 
671  @par Code Examples:
672  Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
673  @code
674 my *hash $row = $table.findSingle(("permission_type": op_between("US", "UX")));
675  @endcode
676  resulting in an internal SQL command that looks as follows (depending on the database):
677  @code
678 my *hash $row = $ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
679  @endcode \n
680  Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
681  @code
682 my int $row_count = $table.del(("name": op_like("%Smith%")));
683  @endcode
684  resulting in an internal SQL command that looks as follows:
685  @code
686 $ds.vexec("delete from table where name like %v", ("%Smith%"));
687  @endcode \n
688  Find all rows where \c "id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
689  @code
690 my *list $rows = $table.findAll(("id": op_gt(100), "created": op_gt(2013-03-01)));
691  @endcode
692  resulting in an internal SQL command that looks as follows:
693  @code
694 $ds.vexec("select * from table where id > %v and created > %v", (100, 2013-03-01));
695  @endcode \n
696 
697  @section sql_upsert Upserting or Merging Data
698 
699  This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
700  - @ref SqlUtil::Table::upsert()
701  - @ref SqlUtil::Table::upsertNoCommit()
702  - @ref SqlUtil::Table::getUpsertClosure()
703  - @ref SqlUtil::Table::getUpsertClosureWithValidation()
704  - @ref SqlUtil::Table::upsertFromIterator()
705  - @ref SqlUtil::Table::upsertFromIteratorNoCommit()
706  - @ref SqlUtil::Table::upsertFromSelect()
707  - @ref SqlUtil::Table::upsertFromSelectNoCommit()
708 
709  @subsection sql_upsert_single Upsert a Single Row
710 
711  @par Example:
712  @code
713 $table.upsert(("id": $id, "name": $name, "account_type": $account_type));
714  @endcode
715 
716  To upsert or merge a single row in the database, call @ref SqlUtil::Table::upsert() or @ref SqlUtil::Table::upsertNoCommit() with the
717  single row to be upserted or merged as a hash as in the preceding example.
718 
719  @subsection sql_upsert_many Upserting Many Rows Using An Upsert Closure
720 
721  To upsert or merge many rows by using an upsert closure, call @ref SqlUtil::Table::getUpsertClosure() or @ref SqlUtil::Table::getUpsertClosureWithValidation() and provide an example row as an argument to acquire a closure that will be executed on the rest of the rows as in the following example.
722 
723  @par Simple Example:
724  @code
725 # get the rows to be inserted
726 my list $l = get_table_rows();
727 
728 if ($l) {
729  my code $upsert = $table.getUpsertClosure($l[0]);
730 
731  on_success $ds.commit();
732  on_error $ds.rollback();
733 
734  # loop through the reference data rows
735  map $upsert($1), $l;
736 }
737  @endcode
738 
739  @par Complex Example With Callbacks:
740  @code
741 # set the upsert strategy depending on the use case
742 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
743 
744 # hash summarizing changes
745 my hash $sh;
746 
747 # get the rows to be inserted
748 my list $l = get_table_rows();
749 
750 if ($l) {
751  # get the upsert closure to use based on the first row to be inserted
752  my code $upsert = $table.getUpsertClosure($l[0], $upsert_strategy);
753 
754  on_success $ds.commit();
755  on_error $ds.rollback();
756 
757  # loop through the reference data rows
758  foreach my hash $h in ($l) {
759  my int $code = $upsert($h);
760  if ($code == AbstractTable::UR_Unchanged)
761  continue;
762 
763  my string $change = AbstractTable::UpsertResultMap{$code};
764  ++$sh{$change};
765 
766  if (!$verbose) {
767  printf(".");
768  flush();
769  }
770  else if ($verbose > 1)
771  printf("*** reference data %s: %y: %s\n", $table.getName(), $h, $change);
772  }
773 
774  # show table summary
775  if ($sh)
776  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
777  else
778  printf("*** reference data %s: OK\n", $table.getName());
779 }
780  @endcode
781 
782  @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
783 
784  To upsert or merge many rows from an iterator source (such as an @ref Qore::SQL::SQLStatement object), call @ref SqlUtil::Table::upsertFromIterator() or @ref SqlUtil::Table::upsertFromIteratorNoCommit() as in the following example:
785 
786  @par Simple Example:
787  @code
788 # get the rows to be inserted
789 my list $l = get_table_rows();
790 $table.upsertFromIterator($l.iterator());
791  @endcode
792 
793  @par Complex Example With Callbacks:
794  @code
795 # set the upsert strategy depending on the use case
796 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
797 
798 # get the rows to be inserted
799 my list $l = get_table_rows();
800 
801 my code $callback = sub (string $table_name, hash $row, int $result) {
802  if ($result == AbstractTable::UR_Unchanged)
803  return;
804  my string $change = AbstractTable::UpsertResultMap{$result};
805  if ($verbose)
806  printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
807 };
808 
809 my hash $sh = $table.upsertFromIterator($l.iterator(), $upsert_strategy, False, ("info_callback": $callback, "commit_block": 5000));
810 if ($sh)
811  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
812 else
813  printf("*** reference data %s: OK\n", $table.getName());
814  @endcode
815 
816  The iterator given to the @ref SqlUtil::Table::upsertFromIterator() or @ref SqlUtil::Table::upsertFromIteratorNoCommit() methods can be any iterator whose @ref Qore::AbstractIterator::getValue() "getValue()" method returns a @ref hash_type "hash".
817 
818  @note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
819 
820  @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
821 
822  To upsert or merge many rows from a select statement, use @ref SqlUtil::Table::upsertFromSelect() or @ref SqlUtil::Table::upsertFromSelectNoCommit() as in the following example:
823 
824  @par Simple Example:
825  @code
826 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")));
827  @endcode
828 
829  @par Complex Example With Callbacks:
830  @code
831 # set the upsert strategy depending on the use case
832 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
833 
834 my code $callback = sub (string $table_name, hash $row, int $result) {
835  if ($result == AbstractTable::UR_Unchanged)
836  return;
837  my string $change = AbstractTable::UpsertResultMap{$result};
838  if ($verbose)
839  printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
840 };
841 
842 my hash $sh = $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), $upsert_strategy, False, ("info_callback": $callback, "commit_block": 5000));
843 if ($sh)
844  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
845 else
846  printf("*** reference data %s: OK\n", $table.getName());
847  @endcode
848 
849  The source table does not have to be in the same database or even of the same database type (ie you can upsert to and from any database type supported by SqlUtil).
850 
851  @note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
852 
853  @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
854 
855  Call any of the batch upsert methods with @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c delete_others set to @ref Qore::True "True" to perform a batch upsert / merge operation on a table, and then scan the table and delete any unwanted rows. If there are no rows to be deleted, these calls have very similar performance to the batch upsert method calls without any deletions, however, if there are rows to be deleted, then the entire source table must be iterated to compare each row to valid data to delete the rows that do not belong. Therefore for large tables this can be an expensive operation.
856 
857  The only difference in the following examples and the preceding ones is that @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c delete_others is @ref Qore::True "True" in these examples.
858 
859  @par Simple Example:
860  @code
861 # get the rows to be inserted
862 my list $l = get_table_rows();
863 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
864  @endcode
865 
866  @par Complex Example With Callbacks:
867  @code
868 # set the upsert strategy depending on the use case
869 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
870 
871 # get the rows to be inserted
872 my list $l = get_table_rows();
873 
874 my code $callback = sub (string $table_name, hash $row, int $result) {
875  if ($result == AbstractTable::UR_Unchanged)
876  return;
877  my string $change = AbstractTable::UpsertResultMap{$result};
878  if ($verbose)
879  printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
880 };
881 
882 my hash $sh = $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), $upsert_strategy, ("delete_others": True, "info_callback": $callback, "commit_block": 5000));
883 if ($sh)
884  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
885 else
886  printf("*** reference data %s: OK\n", $table.getName());
887  @endcode
888 
889  @note the @ref SqlUtil::AbstractTable::UpsertOptions "upsert option" \c "commit_block" can be used to insert a large amount of data in pieces in order to avoid overwhelming the database server's rollback cache
890 
891  @subsection sql_upsert_strategies Upsert Strategies
892  The approach used is based on one of the following strategies (see @ref upsert_options):
893  - @ref SqlUtil::AbstractTable::UpsertAuto "AbstractTable::UpsertAuto": if the target table is empty, then @ref SqlUtil::AbstractTable::UpsertInsertFirst is used, otherwise @ref SqlUtil::AbstractTable::UpsertUpdateFirst is used
894  - @ref SqlUtil::AbstractTable::UpsertInsertFirst "AbstractTable::UpsertInsertFirst": first an insert will be attempted, if it fails due to a duplicate key, then an update will be made; this strategy should be used if more inserts will be made than updates
895  - @ref SqlUtil::AbstractTable::UpsertUpdateFirst "AbstractTable::UpsertUpdateFirst": first an update will be attempted, if it fails due to missing data, then an insert is performed; this strategy should be used if more updates will be made then inserts
896  - @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
897 
898  @note @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" is the only upsert strategy that can return @ref SqlUtil::AbstractTable::UR_Unchanged and @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.
899 */
1579 namespace SqlUtil {
1581 
1582  /* @defgroup DBFeaturesConstants DB Features Constants
1583  These constants can be used as a lookup values in AbstractDatabase::features() method.
1584  */
1586 
1589  const DB_FUNCTIONS = "functions";
1591  const DB_MVIEWS = "materialized views";
1593  const DB_PACKAGES = "packages";
1595  const DB_PROCEDURES = "procedures";
1597  const DB_SEQUENCES = "sequences";
1599  const DB_TABLES = "tables";
1601  const DB_TYPES = "named types";
1603  const DB_VIEWS = "views";
1604 
1606 
1607  /* @defgroup SqlTypeConstants SQL Type Constants
1608  These constants can be used for the \c "qore_type" values when creating columns to specify additional SQL column types
1609  */
1611  const VARCHAR = "string";
1613 
1615  const NUMERIC = "number";
1616 
1618  const CHAR = "char";
1619 
1621  const BLOB = "blob";
1622 
1624  const CLOB = "clob";
1626 
1631  const SZ_NONE = 0;
1633 
1635  const SZ_MAND = 1;
1636 
1638  const SZ_OPT = 2;
1639 
1641  const SZ_NUM = 3;
1643 
1648 /** @see cop_as()
1650  */
1651  const COP_AS = "as";
1652 
1654 /** @see cop_prepend()
1655  */
1656  const COP_PREPEND = "prepend";
1657 
1659 /** @see cop_append()
1660  */
1661  const COP_APPEND = "append";
1662 
1664 /** @see cop_value()
1665  */
1666  const COP_VALUE = "value";
1667 
1669 /** @see cop_upper()
1670  */
1671  const COP_UPPER = "upper";
1672 
1674 /** @see cop_lower()
1675  */
1676  const COP_LOWER = "lower";
1677 
1679 /** @see cop_distinct
1680  */
1681  const COP_DISTINCT = "distinct";
1682 
1684 /** @see cop_min
1685  */
1686  const COP_MIN = "min";
1687 
1689 /** @see cop_max
1690  */
1691  const COP_MAX = "max";
1692 
1694 /** @see cop_avg
1695  */
1696  const COP_AVG = "avg";
1697 
1699 /** @see cop_count
1700  */
1701  const COP_COUNT = "count";
1702 
1704 /** @see cop_over()
1705  */
1706  const COP_OVER = "over";
1707 
1709 /** @see cop_minus()
1710  */
1711  const COP_MINUS = "minus";
1712 
1714 /** @see cop_plus()
1715  */
1716  const COP_PLUS = "plus";
1717 
1719 /** @see cop_divide()
1720  */
1721  const COP_DIVIDE = "divide";
1722 
1724 /** @see cop_multiply()
1725  */
1726  const COP_MULTIPLY = "multiply";
1727 
1729 /** @see cop_year()
1730  */
1731  const COP_YEAR = "year";
1732 
1734 /** @see cop_year_month()
1735  */
1736  const COP_YEAR_MONTH = "year_month";
1737 
1739 /** @see cop_year_day()
1740  */
1741  const COP_YEAR_DAY = "year_day";
1742 
1744 /** @see cop_year_hour()
1745  */
1746  const COP_YEAR_HOUR = "year_hour";
1747 
1749  const DefaultCopMap = (
1750  COP_AS: (
1751  "arg": Type::String,
1752  "code": string (string cve, string arg) {
1753  return sprintf("%s as %s", cve, arg);
1754  },
1755  ),
1756  COP_PREPEND: (
1757  "arg": Type::String,
1758  "sqlvalue": True,
1759  "code": string (string cve, string arg) {
1760  return sprintf("%s||%s", arg, cve);
1761  },
1762  ),
1763  COP_APPEND: (
1764  "arg": Type::String,
1765  "sqlvalue": True,
1766  "code": string (string cve, string arg) {
1767  return sprintf("%s||%s", cve, arg);
1768  },
1769  ),
1770  COP_VALUE: (
1771  "sqlvalue": True,
1772  "nocolumn": True,
1773  "code": string (*string cve, any arg) {
1774  return arg;
1775  },
1776  ),
1777  COP_UPPER: (
1778  "code": string (string cve, any arg) {
1779  return sprintf("upper(%s)", cve);
1780  },
1781  ),
1782  COP_LOWER: (
1783  "code": string (string cve, any arg) {
1784  return sprintf("lower(%s)", cve);
1785  },
1786  ),
1787  COP_DISTINCT: (
1788  "code": string (string cve, any arg) {
1789  return sprintf("distinct %s", cve);
1790  },
1791  ),
1792  COP_MIN: (
1793  "code": string (string cve, any arg) {
1794  return sprintf("min(%s)", cve);
1795  },
1796  "group": True,
1797  ),
1798  COP_MAX: (
1799  "code": string (string cve, any arg) {
1800  return sprintf("max(%s)", cve);
1801  },
1802  "group": True,
1803  ),
1804  COP_AVG: (
1805  "code": string (string cve, any arg) {
1806  return sprintf("avg(%s)", cve);
1807  },
1808  "group": True,
1809  ),
1810  COP_COUNT: (
1811  "nocolumn": True,
1812  "code": string (*string cve, any arg) {
1813  return sprintf("count(%s)", cve ? cve : "1");
1814  },
1815  ),
1816  COP_MINUS: (
1817  "argcolumn": True,
1818  "code": string (string arg1, string arg2) {
1819  return sprintf("%s - %s", arg1, arg2);
1820  },
1821  ),
1822  COP_PLUS: (
1823  "argcolumn": True,
1824  "code": string (string arg1, string arg2) {
1825  return sprintf("%s + %s", arg1, arg2);
1826  },
1827  ),
1828  COP_DIVIDE: (
1829  "argcolumn": True,
1830  "code": string (string arg1, string arg2) {
1831  return sprintf("%s / %s", arg1, arg2);
1832  },
1833  ),
1834  COP_MULTIPLY: (
1835  "argcolumn": True,
1836  "code": string (string arg1, string arg2) {
1837  return sprintf("%s * %s", arg1, arg2);
1838  },
1839  ),
1840  );
1842 
1859 /** @param cop the column operator (one of @ref sql_cops)
1861  @param column the column name
1862  @param arg the argument to the operator
1863 
1864  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1865 
1866  @note Normally this function is not called directly, but rather by the other column operator functions
1867  */
1868  hash make_cop(string cop, any column, any arg);
1869 
1870 
1872 /** @par Example:
1873  @code
1874 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_as("errors", "error_count")), "where": ("type": "user")));
1875  @endcode
1876 
1877  @param column the column specification for the column (string name or dot notation for use in joins)
1878  @param arg the new name of the output column
1879 
1880  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1881  */
1882  hash cop_as(any column, string arg);
1883 
1884 
1886 /** @par Example:
1887  @code
1888 my *list $rows = $table.selectRows(("columns": ("id", cop_prepend("name", "migrated-")), "where": ("type": "user")));
1889  @endcode
1890 
1891  @param column the column specification for the column (string name or dot notation for use in joins)
1892  @param arg the text to prepend to the row values in the output column
1893 
1894  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1895  */
1896  hash cop_prepend(any column, string arg);
1897 
1898 
1900 /** @par Example:
1901  @code
1902 my *list $rows = $table.selectRows(("columns": ("id", cop_append("name", "-migrated")), "where": ("type": "user")));
1903  @endcode
1904 
1905  @param column the column specification for the column (string name or dot notation for use in joins)
1906  @param arg the text to append (ie concatenate) to the row values in the output column
1907 
1908  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1909  */
1910  hash cop_append(any column, string arg);
1911 
1912 
1914 /** @par Example:
1915  @code
1916 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_value(100)), "where": ("type": "user")));
1917  @endcode
1918 
1919  @param arg the value to be returned in the column
1920 
1921  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1922  */
1923  hash cop_value(any arg);
1924 
1925 
1927 /** @par Example:
1928  @code
1929 my *list $rows = $table.selectRows(("columns": ("id", cop_upper("name")), "where": ("type": "user")));
1930  @endcode
1931 
1932  @param column the column specification for the column (string name or dot notation for use in joins)
1933 
1934  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1935  */
1936  hash cop_upper(any column);
1937 
1938 
1940 /** @par Example:
1941  @code
1942 my *list $rows = $table.selectRows(("columns": ("id", cop_lower("name")), "where": ("type": "user")));
1943  @endcode
1944 
1945  @param column the column specification for the column (string name or dot notation for use in joins)
1946 
1947  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1948  */
1949  hash cop_lower(any column);
1950 
1951 
1953 /** @par Example:
1954  @code
1955 my *list $rows = $table.selectRows(("columns": ("id", cop_distinct("name")), "where": ("type": "user")));
1956  @endcode
1957 
1958  @param column the column specification for the column (string name or dot notation for use in joins)
1959 
1960  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1961  */
1962  hash cop_distinct(any column);
1963 
1964 
1966 /** @par Example:
1967  @code
1968 my *list $rows = $table.selectRows(("columns": (cop_min("id")), "where": ("type": "user")));
1969  @endcode
1970 
1971  @param column the column specification for the column (string name or dot notation for use in joins)
1972 
1973  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1974  */
1975  hash cop_min(any column);
1976 
1977 
1979 /** @par Example:
1980  @code
1981 my *list $rows = $table.selectRows(("columns": (cop_max("id")), "where": ("type": "user")));
1982  @endcode
1983 
1984  @param column the column specification for the column (string name or dot notation for use in joins)
1985 
1986  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
1987  */
1988  hash cop_max(any column);
1989 
1990 
1992 /** @par Example:
1993  @code
1994 my *list $rows = $table.selectRows(("columns": (cop_avg("quantity")), "where": ("order_type": "wholesale")));
1995  @endcode
1996 
1997  @param column the column specification for the column (string name or dot notation for use in joins)
1998 
1999  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2000  */
2001  hash cop_avg(any column);
2002 
2003 
2005 /** @par Example:
2006  @code
2007 my *list $rows = $table.selectRows(("columns": ("account_type", cop_count()), "where": ("type": "user"), "groupby": "account_type"));
2008  @endcode
2009 
2010  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2011  */
2012  hash cop_count(string column = "");
2013 
2014 
2016 /** @par Example:
2017  @code
2018 my *list $rows = $table.selectRows(("columns": ("account_type", cop_count(), cop_as(cop_over(cop_max("qty"), "account_id"), "max_qty_per_account")), "where": ("type": "user"), "groupby": "account_type"));
2019  @endcode
2020 
2021  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2022  */
2023  hash cop_over(any column, string arg);
2024 
2025 
2027 /** @par Example:
2028  @code
2029 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_minus("complete_count", "error_count")), "where": ("type": "user")));
2030  @endcode
2031 
2032  @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2033  @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2034  @param arg the new name of the output column
2035 
2036  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2037  */
2038  hash cop_minus(any column1, any column2);
2039 
2040 
2042 /** @par Example:
2043  @code
2044 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_plus("complete_count", "error_count")), "where": ("type": "user")));
2045  @endcode
2046 
2047  @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2048  @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2049  @param arg the new name of the output column
2050 
2051  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2052  */
2053  hash cop_plus(any column1, any column2);
2054 
2055 
2057 /** @par Example:
2058  @code
2059 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_divide("complete_count", "error_count")), "where": ("type": "user")));
2060  @endcode
2061 
2062  @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2063  @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2064  @param arg the new name of the output column
2065 
2066  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2067  */
2068  hash cop_divide(any column1, any column2);
2069 
2070 
2072 /** @par Example:
2073  @code
2074 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_multiply("complete_count", "error_count")), "where": ("type": "user")));
2075  @endcode
2076 
2077  @param column1 the column specification for the first argument (string name or dot notation for use in joins)
2078  @param column2 the column specification for the second argument (string name or dot notation for use in joins)
2079  @param arg the new name of the output column
2080 
2081  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2082  */
2083  hash cop_multiply(any column1, any column2);
2084 
2085 
2087 /** @par Example:
2088  @code
2089 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year("error_time")), "where": ("type": "user")));
2090  @endcode
2091 
2092  @param column the column specification for the column (string name or dot notation for use in joins)
2093 
2094  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2095  */
2096  hash cop_year(any column);
2097 
2098 
2100 /** @par Example:
2101  @code
2102 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year_month("error_time")), "where": ("type": "user")));
2103  @endcode
2104 
2105  @param column the column specification for the column (string name or dot notation for use in joins)
2106 
2107  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2108  */
2109  hash cop_year_month(any column);
2110 
2111 
2113 /** @par Example:
2114  @code
2115 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year_day("error_time")), "where": ("type": "user")));
2116  @endcode
2117 
2118  @param column the column specification for the column (string name or dot notation for use in joins)
2119 
2120  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2121  */
2122  hash cop_year_day(any column);
2123 
2124 
2126 /** @par Example:
2127  @code
2128 my *list $rows = $table.selectRows(("columns": ("id", "name", cop_year_hour("error_time")), "where": ("type": "user")));
2129  @endcode
2130 
2131  @param column the column specification for the column (string name or dot notation for use in joins)
2132 
2133  @return a column operator description hash corresponding to the arguments for use in the @ref select_option_columns "columns" argument of a @ref select_option_hash "select option hash"
2134  */
2135  hash cop_year_hour(any column);
2136 
2138 
2142  const DefaultUopMap = (
2144  COP_PREPEND: True,
2145  COP_APPEND: True,
2146  COP_UPPER: True,
2147  COP_LOWER: True,
2148  );
2150 
2165 /** @param uop the update operator (one of @ref sql_uops)
2167  @param arg the argument to the operator
2168  @param nest any nested operation to the operator
2169 
2170  @return an update operator description hash corresponding to the arguments for use in update statements
2171 
2172  @note Normally this function is not called directly, but rather by the other update operator functions
2173  */
2174  hash make_uop(string uop, any arg, *hash nest);
2175 
2176 
2178 /** @par Example:
2179  @code
2180 my int $rows_updated = t.update(("permission_type": uop_prepend("migrated-", uop_lower())));
2181  @endcode
2182 
2183  @param arg the text to prepend to the row values in the output column
2184  @param nest any nested operation to the operator
2185 
2186  @return an update operator description hash corresponding to the arguments for use in update statements
2187  */
2188  hash uop_prepend(string arg, *hash nest);
2189 
2190 
2192 /** @par Example:
2193  @code
2194 my int $rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
2195  @endcode
2196 
2197  @param arg the text to prepend to the row values in the output column
2198  @param nest any nested operation to the operator
2199 
2200  @return an update operator description hash corresponding to the arguments for use in update statements
2201  */
2202  hash uop_append(string arg, *hash nest);
2203 
2204 
2206 /** @par Example:
2207  @code
2208 my int $rows_updated = t.update(("permission_type": uop_upper()));
2209  @endcode
2210 
2211  @param nest any nested operation to the operator
2212 
2213  @return an update operator description hash corresponding to the arguments for use in update statements
2214  */
2215  hash uop_upper(*hash nest);
2216 
2217 
2219 /** @par Example:
2220  @code
2221 my int $rows_updated = t.update(("permission_type": uop_lower()));
2222  @endcode
2223 
2224  @param nest any nested operation to the operator
2225 
2226  @return an update operator description hash corresponding to the arguments for use in update statements
2227  */
2228  hash uop_lower(*hash nest);
2229 
2231 
2238 /** @see join_inner()
2240  */
2241  const JOP_INNER = "inner";
2242 
2244 /** @see join_left()
2245  */
2246  const JOP_LEFT = "left";
2247 
2249 /** @see join_right()
2250  */
2251  const JOP_RIGHT = "right";
2252 
2254  const JopMap = (
2255  JOP_INNER: "inner",
2256  JOP_LEFT: "left outer",
2257  JOP_RIGHT: "right outer",
2258  );
2260 
2270 
2274  hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
2275 
2276 
2278 /** @par Example With Explicit Join Columns:
2279  @code
2280 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid"))));
2281  @endcode
2282 
2283  @par Example With Implicit Join Columns:
2284  (using an automatically detected foreign key to primary key constraint)
2285  @code
2286 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2287  @endcode
2288 
2289  @param table the table to join with
2290  @param alias the alias for \a table in the query
2291  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2292  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2293  @param opt optional join options (for example, to specify a partition for the join if supported)
2294 
2295  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2296  */
2297  hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2298 
2299 
2301 /** @par Example With Explicit Join Columns:
2302  @code
2303 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid"))));
2304  @endcode
2305 
2306  @par Example With Implicit Join Columns:
2307  (using an automatically detected foreign key to primary key constraint)
2308  @code
2309 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2310  @endcode
2311 
2312  @param table the table to join with
2313  @param alias the alias for \a table in the query
2314  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2315  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2316  @param opt optional join options (for example, to specify a partition for the join if supported)
2317 
2318  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2319  */
2320  hash join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2321 
2322 
2324 /** @par Example With Explicit Join Columns:
2325  @code
2326 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner("t2", $table3)));
2327  @endcode
2328 
2329  @par Example With Implicit Join Columns:
2330  (using an automatically detected foreign key to primary key constraint)
2331  @code
2332 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2333  @endcode
2334 
2335  @param ta the table name or alias of the other table to join with when not joining with the primary table
2336  @param table the table to join with
2337  @param alias the alias for \a table in the query
2338  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2339  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2340  @param opt optional join options (for example, to specify a partition for the join if supported)
2341 
2342  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2343  */
2344  hash join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2345 
2346 
2348 /** @par Example With Explicit Join Columns:
2349  @code
2350 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner("t2", $table3)));
2351  @endcode
2352 
2353  @par Example With Implicit Join Columns:
2354  (using an automatically detected foreign key to primary key constraint)
2355  @code
2356 my *list $rows = $table.selectRows(("join": join_inner($table2)));
2357  @endcode
2358 
2359  @param ta the table name or alias of the other table to join with when not joining with the primary table
2360  @param table the table to join with
2361  @param alias the alias for \a table in the query
2362  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2363  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2364  @param opt optional join options (for example, to specify a partition for the join if supported)
2365 
2366  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2367  */
2368  hash join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2369 
2370 
2372 /** @par Example With Explicit Join Columns:
2373  @code
2374 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2375  @endcode
2376 
2377  @par Example With Implicit Join Columns:
2378  (using an automatically detected foreign key to primary key constraint)
2379  @code
2380 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2381  @endcode
2382 
2383  @param table the table to join with
2384  @param alias the alias for \a table in the query
2385  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2386  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2387  @param opt optional join options (for example, to specify a partition for the join if supported)
2388 
2389  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2390  */
2391  hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2392 
2393 
2395 /** @par Example With Explicit Join Columns:
2396  @code
2397 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2398  @endcode
2399 
2400  @par Example With Implicit Join Columns:
2401  (using an automatically detected foreign key to primary key constraint)
2402  @code
2403 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2404  @endcode
2405 
2406  @param table the table to join with
2407  @param alias the alias for \a table in the query
2408  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2409  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2410  @param opt optional join options (for example, to specify a partition for the join if supported)
2411 
2412  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2413  */
2414  hash join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2415 
2416 
2418 /** @par Example With Explicit Join Columns:
2419  @code
2420 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2421  @endcode
2422 
2423  @par Example With Implicit Join Columns:
2424  (using an automatically detected foreign key to primary key constraint)
2425  @code
2426 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2427  @endcode
2428 
2429  @param ta the table name or alias of the other table to join with when not joining with the primary table
2430  @param table the table to join with
2431  @param alias the alias for \a table in the query
2432  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2433  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2434  @param opt optional join options (for example, to specify a partition for the join if supported)
2435 
2436  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2437  */
2438  hash join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2439 
2440 
2442 /** @par Example With Explicit Join Columns:
2443  @code
2444 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2445  @endcode
2446 
2447  @par Example With Implicit Join Columns:
2448  (using an automatically detected foreign key to primary key constraint)
2449  @code
2450 my *list $rows = $table.selectRows(("join": join_left($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_left("t2", $table3, "t3")));
2451  @endcode
2452 
2453  @param ta the table name or alias of the other table to join with when not joining with the primary table
2454  @param table the table to join with
2455  @param alias the alias for \a table in the query
2456  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2457  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2458  @param opt optional join options (for example, to specify a partition for the join if supported)
2459 
2460  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2461  */
2462  hash join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2463 
2464 
2466 /** @par Example With Explicit Join Columns:
2467  @code
2468 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2469  @endcode
2470 
2471  @par Example With Implicit Join Columns:
2472  (using an automatically detected foreign key to primary key constraint)
2473  @code
2474 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2475  @endcode
2476 
2477  @param table the table to join with
2478  @param alias the alias for \a table in the query
2479  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2480  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2481  @param opt optional join options (for example, to specify a partition for the join if supported)
2482 
2483  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2484  */
2485  hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2486 
2487 
2489 /** @par Example With Explicit Join Columns:
2490  @code
2491 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%")))));
2492  @endcode
2493 
2494  @par Example With Implicit Join Columns:
2495  (using an automatically detected foreign key to primary key constraint)
2496  @code
2497 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%")))));
2498  @endcode
2499 
2500  @param table the table to join with
2501  @param alias the alias for \a table in the query
2502  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2503  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2504  @param opt optional join options (for example, to specify a partition for the join if supported)
2505 
2506  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2507  */
2508  hash join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2509 
2510 
2512 /** @par Example With Explicit Join Columns:
2513  @code
2514 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2515  @endcode
2516 
2517  @par Example With Implicit Join Columns:
2518  (using an automatically detected foreign key to primary key constraint)
2519  @code
2520 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2521  @endcode
2522 
2523  @param ta the table name or alias of the other table to join with when not joining with the primary table
2524  @param table the table to join with
2525  @param alias the alias for \a table in the query
2526  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2527  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2528  @param opt optional join options (for example, to specify a partition for the join if supported)
2529 
2530  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2531  */
2532  hash join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2533 
2534 
2536 /** @par Example With Explicit Join Columns:
2537  @code
2538 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", ("id": "altid"), ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2539  @endcode
2540 
2541  @par Example With Implicit Join Columns:
2542  (using an automatically detected foreign key to primary key constraint)
2543  @code
2544 my *list $rows = $table.selectRows(("join": join_right($table2, "t2", NOTHING, ("tag", op_like("offset%"))) + join_right("t2", $table3, "t3")));
2545  @endcode
2546 
2547  @param ta the table name or alias of the other table to join with when not joining with the primary table
2548  @param table the table to join with
2549  @param alias the alias for \a table in the query
2550  @param jcols the columns to use for the join, the keys will be columns in the source table and the values are columns in the \a table argument; if this argument is @ref nothing, then if there is any foreign key in one table pointing to the primary key of the other table, then this information is automatically assumed as the join condition; a foreign constraint in the current table to the primary key in \a table will be used first if it exists
2551  @param cond additional conditions for the join clause for the \a table argument; see @ref where_clauses for more information
2552  @param opt optional join options (for example, to specify a partition for the join if supported)
2553 
2554  @return a join description hash corresponding to the arguments for use in the @ref select_option_join "join" argument of a @ref select_option_hash "select option hash"
2555  */
2556  hash join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2557 
2559 
2564 /** @see op_like()
2566  */
2567  const OP_LIKE = "like";
2568 
2570 /** @see op_lt()
2571  */
2572  const OP_LT = "<";
2573 
2575 /** @see op_le()
2576  */
2577  const OP_LE = "<=";
2578 
2580 /** @see op_gt()
2581  */
2582  const OP_GT = ">";
2583 
2585 /** @see op_ge()
2586  */
2587  const OP_GE = ">=";
2588 
2590 /** @see op_ne()
2591  */
2592  const OP_NE = "!=";
2593 
2595 /** @see op_eq()
2596  */
2597  const OP_EQ = "=";
2598 
2600 /** @see op_clt()
2601  */
2602  const OP_CLT = "C<";
2603 
2605 /** @see op_cle()
2606  */
2607  const OP_CLE = "C<=";
2608 
2610 /** @see op_cgt()
2611  */
2612  const OP_CGT = "C>";
2613 
2615 /** @see op_cge()
2616  */
2617  const OP_CGE = "C>=";
2618 
2620 /** @see op_cne()
2621  */
2622  const OP_CNE = "C!=";
2623 
2625 /** @see op_ceq()
2626  */
2627  const OP_CEQ = "C=";
2628 
2630 /** @see op_between()
2631  */
2632  const OP_BETWEEN = "between";
2633 
2635 /** @see op_in()
2636  */
2637  const OP_IN = "in";
2638 
2640 /** @see op_not()
2641  */
2642  const OP_NOT = "not";
2643 
2645  const DefaultOpMap = (
2646  OP_LIKE: (
2647  "code": string (object t, string cn, any arg, reference args) {
2648  args += arg;
2649  return sprintf("%s like %v", cn);
2650  },
2651  ),
2652  OP_LT: (
2653  "code": string (object t, string cn, any arg, reference args) {
2654  args += arg;
2655  return sprintf("%s < %v", cn);
2656  },
2657  ),
2658  OP_LE: (
2659  "code": string (object t, string cn, any arg, reference args) {
2660  args += arg;
2661  return sprintf("%s <= %v", cn);
2662  },
2663  ),
2664  OP_GT: (
2665  "code": string (object t, string cn, any arg, reference args) {
2666  args += arg;
2667  return sprintf("%s > %v", cn);
2668  },
2669  ),
2670  OP_GE: (
2671  "code": string (object t, string cn, any arg, reference args) {
2672  args += arg;
2673  return sprintf("%s >= %v", cn);
2674  },
2675  ),
2676  OP_NE: (
2677  "code": string (object t, string cn, any arg, reference args) {
2678  if (arg === NULL || !exists arg)
2679  return sprintf("%s is not null", cn);
2680  args += arg;
2681  return sprintf("%s != %v", cn);
2682  },
2683  ),
2684  OP_EQ: (
2685  "code": string (object t, string cn, any arg, reference args) {
2686  if (arg === NULL || !exists arg)
2687  return sprintf("%s is null", cn);
2688  args += arg;
2689  return sprintf("%s = %v", cn);
2690  },
2691  ),
2692  OP_BETWEEN: (
2693  "code": string (object t, string cn, any arg, reference args) {
2694  args += arg[0];
2695  args += arg[1];
2696  return sprintf("%s between %v and %v", cn);
2697  },
2698  ),
2699  OP_IN: (
2700  "code": string (object t, string cn, any arg, reference args) {
2701  *string ins = (foldl $1 + "," + $2, (map t.getSqlValue($1), arg));
2702  return ins ? sprintf("%s in (%s)", cn, ins) : "1 != 1";
2703  },
2704  ),
2705  OP_NOT: (
2706  "recursive": True,
2707  "code": string (object t, string cn, any arg, reference args) {
2708  return sprintf("not (%s)", cn);
2709  },
2710  ),
2711  OP_CLT: (
2712  "argcolumn": True,
2713  "code": string (object t, string cn, any arg, reference args) {
2714  return sprintf("%s < %s", cn, arg);
2715  },
2716  ),
2717  OP_CLE: (
2718  "argcolumn": True,
2719  "code": string (object t, string cn, any arg, reference args) {
2720  return sprintf("%s <= %s", cn, arg);
2721  },
2722  ),
2723  OP_CGT: (
2724  "argcolumn": True,
2725  "code": string (object t, string cn, any arg, reference args) {
2726  return sprintf("%s > %s", cn, arg);
2727  },
2728  ),
2729  OP_CGE: (
2730  "argcolumn": True,
2731  "code": string (object t, string cn, any arg, reference args) {
2732  return sprintf("%s >= %s", cn, arg);
2733  },
2734  ),
2735  OP_CNE: (
2736  "argcolumn": True,
2737  "code": string (object t, string cn, any arg, reference args) {
2738  return sprintf("%s != %s", cn, arg);
2739  },
2740  ),
2741  OP_CEQ: (
2742  "argcolumn": True,
2743  "code": string (object t, string cn, string arg, reference args) {
2744  return sprintf("%s = %s", cn, arg);
2745  },
2746  ),
2747  );
2749 
2770  hash make_op(string op, any arg);
2772 
2773 
2775 /** @par Example:
2776  @code
2777 my *list $rows = $table.selectRows(("where": ("name": op_like("%smith%"))));
2778  @endcode
2779 
2780  @param str the argument for the operator
2781 
2782  @return a where operation description hash for use in @ref where_clauses "where clauses"
2783  */
2784  hash op_like(string str);
2785 
2786 
2788 /** @par Example:
2789  @code
2790 my *list $rows = $table.selectRows(("where": ("name": op_lt("Zebra"))));
2791  @endcode
2792 
2793  @param arg the argument for the operator
2794 
2795  @return a where operation description hash for use in @ref where_clauses "where clauses"
2796 
2797  @see op_clt() for a function to be used when comparing two column values
2798  */
2799  hash op_lt(any arg);
2800 
2801 
2803 /** @par Example:
2804  @code
2805 my *list $rows = $table.selectRows(("where": ("name": op_le("Zebra"))));
2806  @endcode
2807 
2808  @param arg the argument for the operator
2809 
2810  @return a where operation description hash for use in @ref where_clauses "where clauses"
2811 
2812  @see op_cle() for a function to be used when comparing two column values
2813  */
2814  hash op_le(any arg);
2815 
2816 
2818 /** @par Example:
2819  @code
2820 my *list $rows = $table.selectRows(("where": ("name": op_gt("Apple"))));
2821  @endcode
2822 
2823  @param arg the argument for the operator
2824 
2825  @return a where operation description hash for use in @ref where_clauses "where clauses"
2826 
2827  @see op_cgt() for a function to be used when comparing two column values
2828  */
2829  hash op_gt(any arg);
2830 
2831 
2833 /** @par Example:
2834  @code
2835 my *list $rows = $table.selectRows(("where": ("name": op_ge("Apple"))));
2836  @endcode
2837 
2838  @param arg the argument for the operator
2839 
2840  @return a where operation description hash for use in @ref where_clauses "where clauses"
2841 
2842  @see op_cge() for a function to be used when comparing two column values
2843  */
2844  hash op_ge(any arg);
2845 
2846 
2848 /** @par Example:
2849  @code
2850 my *list $rows = $table.selectRows(("where": ("name": op_ne("Smith"))));
2851  @endcode
2852 
2853  @param arg the argument for the operator
2854 
2855  @return a where operation description hash for use in @ref where_clauses "where clauses"
2856 
2857  @see op_cne() for a function to be used when comparing two column values
2858  */
2859  hash op_ne(any arg);
2860 
2861 
2863 /** @par Example:
2864  @code
2865 my *list $rows = $table.selectRows(("where": ("name": op_eq("Smith"))));
2866  @endcode
2867 
2868  @param arg the argument for the operator
2869 
2870  @return a where operation description hash for use in @ref where_clauses "where clauses"
2871 
2872  @see op_ceq() for a function to be used when comparing two column values
2873  */
2874  hash op_eq(any arg);
2875 
2876 
2878 /** @par Example:
2879  @code
2880 my *list $rows = $table.selectRows(("where": ("name": op_between("US", "UX"))));
2881  @endcode
2882 
2883  @param l the lower bound for the \c "between" operator
2884  @param r the upper bound for the \c "between" operator
2885 
2886  @return a where operation description hash for use in @ref where_clauses "where clauses"
2887 
2888  @throw BETWEEN-ERROR one or both of the required arguments are @ref null or @ref nothing
2889  */
2890  hash op_between(any l, any r);
2891 
2892 
2894 /** @par Example:
2895  @code
2896 my *list $rows = $table.selectRows(("where": ("name": op_in(200, 300, 500, 9))));
2897  @endcode
2898 
2899  @return a where operation description hash for use in @ref where_clauses "where clauses"
2900  */
2901  hash op_in();
2902 
2903 
2905 /** @par Example:
2906  @code
2907 my *list $rows = $table.selectRows(("where": ("name": op_in($idlist))));
2908  @endcode
2909 
2910  @param args a list of values for the \c "in" operator
2911 
2912  @return a where operation description hash for use in @ref where_clauses "where clauses"
2913  */
2914  hash op_in(list args);
2915 
2916 
2918 /** @par Example:
2919  @code
2920 my *list $rows = $table.selectRows(("where": ("name": opt_not(op_in(200, 300, 500, 9))))_;
2921  @endcode
2922 
2923  @return a where operation description hash for use in @ref where_clauses "where clauses"
2924  */
2925  hash op_not(hash arg);
2926 
2927 
2929 /** @par Example:
2930  @code
2931 my *list $rows = $table.selectRows(("where": ("name": op_clt("other_name"))));
2932  @endcode
2933 
2934  @param arg the name of the column to compare against
2935 
2936  @return a where operation description hash for use in @ref where_clauses "where clauses"
2937 
2938  @see op_lt() for a function to be used when comparing a column against an immediate value
2939  */
2940  hash op_clt(string arg);
2941 
2942 
2944 /** @par Example:
2945  @code
2946 my *list $rows = $table.selectRows(("where": ("name": op_cle("other_name"))));
2947  @endcode
2948 
2949  @param arg the name of the column to compare against
2950 
2951  @return a where operation description hash for use in @ref where_clauses "where clauses"
2952 
2953  @see op_le() for a function to be used when comparing a column against an immediate value
2954  */
2955  hash op_cle(string arg);
2956 
2957 
2959 /** @par Example:
2960  @code
2961 my *list $rows = $table.selectRows(("where": ("name": op_cgt("other_name"))));
2962  @endcode
2963 
2964  @param arg the name of the column to compare against
2965 
2966  @return a where operation description hash for use in @ref where_clauses "where clauses"
2967 
2968  @see op_gt() for a function to be used when comparing a column against an immediate value
2969  */
2970  hash op_cgt(string arg);
2971 
2972 
2974 /** @par Example:
2975  @code
2976 my *list $rows = $table.selectRows(("where": ("name": op_cge("other_name"))));
2977  @endcode
2978 
2979  @param arg the name of the column to compare against
2980 
2981  @return a where operation description hash for use in @ref where_clauses "where clauses"
2982 
2983  @see op_ge() for a function to be used when comparing a column against an immediate value
2984  */
2985  hash op_cge(string arg);
2986 
2987 
2989 /** @par Example:
2990  @code
2991 my *list $rows = $table.selectRows(("where": ("name": op_cne("other_name"))));
2992  @endcode
2993 
2994  @param arg the name of the column to compare against
2995 
2996  @return a where operation description hash for use in @ref where_clauses "where clauses"
2997 
2998  @see op_ne() for a function to be used when comparing a column against an immediate value
2999  */
3000  hash op_cne(string arg);
3001 
3002 
3004 /** @par Example:
3005  @code
3006 my *list $rows = $table.selectRows(("where": ("name": op_ceq("other_name"))));
3007  @endcode
3008 
3009  @param arg the name of the column to compare against
3010 
3011  @return a where operation description hash for use in @ref where_clauses "where clauses"
3012 
3013  @see op_eq() for a function to be used when comparing a column against an immediate value
3014  */
3015  hash op_ceq(string arg);
3016 
3018 
3020  class AbstractHashContainer {
3021 
3022 public:
3023 private:
3024 
3025 public:
3026 
3027  private :
3028  *hash h;
3029 
3030 public:
3031 
3033  constructor(*hash nh);
3034 
3035 
3037  copy(AbstractHashContainer old);
3038 
3039 
3041 /** @par Example:
3042  @code
3043 my any $v = $c.name;
3044  @endcode
3045 
3046  @param k the name of the key to access
3047 
3048  @return the value of the given key in the contained hash if it exists
3049 
3050  @throw KEY-ERROR the given key does not exist in the contained hash
3051 
3052  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3053 
3054  @see @ref memberGate_methods
3055  */
3056  any memberGate(string k);
3057 
3058 
3060 /** @par Example:
3061  @code
3062 $c.clear();
3063  @endcode
3064 
3065  */
3066  clear();
3067 
3068 
3070  abstract any take(string k);
3071 
3073  renameKey(string old_name, string new_name);
3074 
3075 
3077  *hash getHash();
3078 
3079 
3081 /** @par Example:
3082  @code
3083 my bool $b = $c.matchKeys($h);
3084  @endcode
3085 
3086  @param h1 the hash to compare
3087 
3088  @return @ref Qore::True "True" if the hash argument has the same keys (in any order), @ref Qore::False "False" if not
3089  */
3090  bool matchKeys(hash h1);
3091 
3092 
3094 /** @par Example:
3095  @code
3096 my bool $b = $c.matchKeys($l);
3097  @endcode
3098 
3099  @param l the hash to compare
3100 
3101  @return @ref Qore::True "True" if the list argument has the same list of key strings as the keys in the object (in any order), @ref Qore::False "False" if not
3102  */
3103  bool matchKeys(list l);
3104 
3105 
3107 /** @par Example:
3108  @code
3109 my bool $b = $c.matchKeys($c1);
3110  @endcode
3111 
3112  @param c the container to compare
3113 
3114  @return @ref Qore::True "True" if the container argument has the same keys (in any order), @ref Qore::False "False" if not
3115  */
3116  bool matchKeys(AbstractHashContainer c);
3117 
3118 
3120 /** @par Example:
3121  @code
3122 my bool $b = $c.partialMatchKeys($h);
3123  @endcode
3124 
3125  @param h1 the hash to compare
3126 
3127  @return @ref Qore::True "True" if the hash argument has at least the same keys (in any order, can have more keys), @ref Qore::False "False" if not
3128  */
3129  bool partialMatchKeys(hash h1);
3130 
3131 
3133 /** @par Example:
3134  @code
3135 my bool $b = $c.partialMatchKeys($l);
3136  @endcode
3137 
3138  @param l the list of strings to compare
3139 
3140  @return @ref Qore::True "True" if the list argument has at least the same keys (in any order, can have more keys), @ref Qore::False "False" if not
3141  */
3142  bool partialMatchKeys(list l);
3143 
3144 
3146 /** @par Example:
3147  @code
3148 my bool $b = $c.partialMatchKeys($c1);
3149  @endcode
3150 
3151  @param c the container to compare
3152 
3153  @return @ref Qore::True "True" if the container argument has at least the same keys (in any order, can have more keys), @ref Qore::False "False" if not
3154  */
3155  bool partialMatchKeys(AbstractHashContainer c);
3156 
3157 
3159 /** @par Example:
3160  @code
3161 my bool $b = $h.val();
3162  @endcode
3163 
3164  The opposite of empty()
3165 
3166  @return @ref Qore::False "False" if the contained hash has no keys, @ref Qore::True "True" if it does
3167  */
3168  bool val();
3169 
3170 
3172 /** @par Example:
3173  @code
3174 my list $l = $h.keys();
3175  @endcode
3176 
3177  @return a list of key names of the contained hash
3178  */
3179  list keys();
3180 
3181 
3183 /** @par Example:
3184  @code
3185 my list $l = $h.values();
3186  @endcode
3187 
3188  @return a list of values of the contained hash
3189  */
3190  list values();
3191 
3192 
3194 /** @par Example:
3195  @code
3196 map printf("+ %y\n", $1.value), $h.iterator();
3197  @endcode
3198 
3199  @return a @ref Qore::HashIterator "HashIterator" object for the contained hash
3200  */
3201  Qore::AbstractIterator iterator();
3202 
3203 
3205 /** @par Example:
3206  @code
3207 map printf("+ %s\n", $1), $h.keyIterator();
3208  @endcode
3209 
3210  @return a @ref Qore::HashKeyIterator "HashKeyIterator" object for the contained hash
3211  */
3212  Qore::AbstractIterator keyIterator();
3213 
3214 
3216 /** @par Example:
3217  @code
3218 map printf("+ %s: %y\n", $1.key, $1.value), $h.pairIterator();
3219  @endcode
3220 
3221  @return a @ref Qore::HashPairIterator "HashPairIterator" object for the contained hash
3222  */
3223  Qore::AbstractIterator pairIterator();
3224 
3225 
3227  bool empty();
3228 
3229 
3231 /** @par Example:
3232  @code
3233 my int $num = $h.size();
3234  @endcode
3235 
3236  @return the number of keys in the contained hash
3237  */
3238  int size();
3239 
3240 
3242 /** @par Example:
3243  @code
3244 my bool $b = $h.hasKey($key);
3245  @endcode
3246 
3247  @param k the key name to check
3248 
3249  @return @ref Qore::True "True" if the key exists in the contained hash (may or may not be assigned a value), @ref Qore::False "False" if not
3250  */
3251  bool hasKey(string k);
3252 
3253 
3255 /** @par Example:
3256  @code
3257 my bool $b = $h.hasKeyValue($key);
3258  @endcode
3259 
3260  @param k the key name to check
3261 
3262  @return @ref Qore::True "True" if the key exists in the contained hash and is assigned a value, @ref Qore::False "False" if not
3263  */
3264  bool hasKeyValue(string k);
3265 
3266 
3268 /** @par Example:
3269  @code
3270 my *string $n = $h.firstKey();
3271  @endcode
3272 
3273  @return the first key name in the contained hash or @ref nothing if the contained hash has no keys
3274 
3275  @see lastKey()
3276  */
3277  *string firstKey();
3278 
3279 
3281 /** @par Example:
3282  @code
3283 my *string $n = $h.lastKey();
3284  @endcode
3285 
3286  @return the last key name in the contained hash or @ref nothing if the contained hash has no keys
3287 
3288  @see firstKey()
3289  */
3290  *string lastKey();
3291 
3292 
3294  abstract string getElementName();
3295  };
3296 
3298  class AbstractListContainer {
3299 
3300 public:
3301 private:
3302 
3303 public:
3304 
3305  private :
3306  softlist l;
3307 
3308 public:
3309 
3311  constructor(softlist nl);
3312 
3313 
3315 /** @par Example:
3316  @code
3317 my any $v = $c.get(2);
3318  @endcode
3319 
3320  @param i the index of the element to access
3321 
3322  @return the value of the given index in the contained list if it exists
3323 
3324  @throw ELEMENT-ERROR the given element does not exist in the contained list
3325  */
3326  abstract any get(softint i);
3327 
3329  add(any val);
3330 
3331 
3333  any take(int i);
3334 
3335 
3337  list getList();
3338 
3339 
3341 /** @par Example:
3342  @code
3343 my bool $b = $l.val();
3344  @endcode
3345 
3346  The opposite of empty()
3347 
3348  @return @ref Qore::False "False" if the contained list is empty, @ref Qore::True "True" if not
3349  */
3350  bool val();
3351 
3352 
3354 /** @par Example:
3355  @code
3356 map printf("+ %s: %y\n", $1), $h.iterator();
3357  @endcode
3358 
3359  @return a @ref Qore::HashIterator "HashIterator" object for the contained hash
3360  */
3361  Qore::ListIterator iterator();
3362 
3363 
3365  bool empty();
3366 
3367 
3369 /** @par Example:
3370  @code
3371 my int $num = $l.size();
3372  @endcode
3373 
3374  @return the number of elements in the contained list
3375  */
3376  int size();
3377 
3378 
3380  abstract string getElementName();
3381 
3382 
3383 private:
3384  checkIndex(int i);
3385 public:
3386 
3387  };
3388 
3390 class Tables : public AbstractHashContainer {
3391 
3392 public:
3394  constructor();
3395 
3396 
3398  constructor(AbstractDatasource ds, hash tables, *hash opt);
3399 
3400 
3402  constructor(AbstractDatasource ds);
3403 
3404 
3406  add(string k, Table val);
3407 
3408 
3410  add(string k, AbstractTable val);
3411 
3412 
3414  add(Table val);
3415 
3416 
3418  add(AbstractTable val);
3419 
3420 
3422  AbstractTable take(string k);
3423 
3424 
3426  populate(AbstractDatasource ds, hash tables, *hash opt);
3427 
3428 
3430  populate(AbstractDatasource ds);
3431 
3432 
3434 /** @par Example:
3435  @code
3436 my *list $l = $tables.getDropAllForeignConstraintsOnTableSql($name);
3437  @endcode
3438 
3439  Make sure that all relevant tables are cached before calling this method; if the table is not cached, then @ref nothing is returned
3440 
3441  @param name the name of the table to find all the foreigjn constraints for
3442  @param opt a hash of options for the SQL strings; see @ref AbstractDatabase::DropSchemaOptions for common options; each driver can support additional driver-specific options
3443 
3444  @return a list of SQL strings that can be used to drop all the foreign constraints on a particular table
3445 
3446  @throw OPTION-ERROR invalid or unsupported option passed
3447  */
3448  *list getDropAllForeignConstraintsOnTableSql(string name, *hash opt);
3449 
3450 
3452 /** @par Example:
3453  @code
3454 my AbstractTable $t = $tables.table_name;
3455  @endcode
3456 
3457  @param k the name of the key to access
3458 
3459  @return the value of the given key in the contained hash if it exists
3460 
3461  @throw KEY-ERROR the given key does not exist in the contained hash
3462 
3463  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3464 
3465  @see @ref memberGate_methods
3466  */
3467  AbstractTable memberGate(string k);
3468 
3469 
3471  string getElementName();
3472 
3473 
3475  *AbstractTable getIfExists(AbstractDatasource ds, string name);
3476 
3477 
3479  AbstractTable get(AbstractDatasource ds, string name);
3480 
3481 
3483 /** @par Example:
3484  @code
3485 my *string $sql = $tables.getRenameTableIfExistsSql($old_name, $new_name);
3486  @endcode
3487 
3488  If the @ref sql_callback_executed "sql_callback_executed option key" is @ref Qore::True "True", this
3489  method also takes care of renaming internal foreign constraint references and source constraint references
3490  from unique keys for the renamed table (see @ref sql_callback_executed for more information).
3491 
3492  @param old_name the current name of the table
3493  @param new_name the new name of the table
3494  @param opts optional callback options; see @ref AbstractDatabase::CallbackOptions for more info
3495 
3496  @return an SQL string that can be used to rename the given table if it exists and the target does not exist, otherwise returns @ref nothing
3497  */
3498  *string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts);
3499 
3500 
3502 /** @par Example:
3503  @code
3504 $tables.tableRenamed($old, $new);
3505  @endcode
3506 
3507  @param old_name the current name of the table
3508  @param new_name the new name of the table
3509  @param old_sql_name the old full SQL name of the table (ie the value returned by @ref SqlUtil::AbstractTable::getSqlName())
3510 
3511  @return @ref Qore::True "True" if the table was renamed internally, @ref Qore::False "False" if not
3512  */
3513  bool tableRenamed(string old_name, string new_name, string old_sql_name);
3514 
3515 
3516 
3517 private:
3518  tableRenamedIntern(string old_name, string new_name, string oldsn);
3519 public:
3520 
3521 
3523 /** @par Example:
3524  @code
3525 my *string $sql = $tables.getDropConstraintIfExistsSql("table", "pk_table");
3526  @endcode
3527 
3528  If the @ref sql_callback_executed "sql_callback_executed option key" is @ref Qore::True "True" and
3529  if the constraint to be dropped is a foreign constraint, then if any unique constraint is linked
3530  to this foreign constraint, the link is removed (see @ref sql_callback_executed for more information).
3531 
3532  @param tname the name of the table
3533  @param cname the name of the constraint to drop if it exists
3534  @param opts optional callback options; see @ref AbstractDatabase::CallbackOptions for more info
3535 
3536  @return an SQL string that can be used to drop an existing constraint on a table, if the table is not already cached or the constraint does not exist, then @ref nothing is returned
3537  */
3538  *string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
3539 
3540 
3541  list getCreateList();
3542 
3543 
3544  Qore::AbstractIterator createIterator();
3545 
3546 
3548 /** @par Example:
3549  @code
3550 my list $l = $tables.getDropList();
3551 map $1.drop(), $l;
3552  @endcode
3553 
3554  @return a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
3555  */
3556  list getDropList();
3557 
3558 
3560 /** @par Example:
3561  @code
3562 map $1.drop(), $tables.getDropIterator();
3563  @endcode
3564 
3565  @return an iterator for a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
3566  */
3567  Qore::AbstractIterator dropIterator();
3568 
3569 
3570 
3571 private:
3572  getDependencies(reference tdh, reference sdh, *reference th);
3573 public:
3574 
3575  };
3576 
3578 class Columns : public AbstractHashContainer {
3579 
3580 public:
3581  constructor(*hash c);
3582 
3583 
3585  add(string k, AbstractColumn val);
3586 
3587 
3589  AbstractColumn take(string k);
3590 
3591 
3593 /** @par Example:
3594  @code
3595 my AbstractColumn $c = $cols.id;
3596  @endcode
3597 
3598  @param k the name of the key to access
3599 
3600  @return the value of the given key in the contained hash if it exists
3601 
3602  @throw KEY-ERROR the given key does not exist in the contained hash
3603 
3604  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3605 
3606  @see @ref memberGate_methods
3607  */
3608  AbstractColumn memberGate(string k);
3609 
3610 
3612  Columns subset(softlist l);
3613 
3614 
3616  string getElementName();
3617 
3618 
3620  bool equal(Columns cols);
3621 
3622  };
3623 
3625  class AbstractColumn {
3626 
3627 public:
3628  public :
3630  string name;
3631 
3633  string native_type;
3634 
3636  *string qore_type;
3637 
3639  int size;
3640 
3642  bool nullable;
3643 
3645  *string def_val;
3646 
3648  *string comment;
3649 
3650 public:
3651 
3652  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string c);
3653 
3654 
3656  string getNativeTypeString();
3657 
3658 
3660  string getCreateSql();
3661 
3662 
3664 /** @par Example:
3665  @code
3666 my list $l = $col.getCreateSql($t);
3667  @endcode
3668 
3669  @param t the AbstractTable object to modify
3670 
3671  @return a list of sql strings that can be used to add the column to an existing table
3672  */
3673  abstract list getCreateSql(AbstractTable t);
3674 
3676  string getDropSql(string table_name);
3677 
3678 
3680 /** @par Example:
3681  @code
3682 my list $l = $col.getModifySql($t, $newcol);
3683  @endcode
3684 
3685  The column names are assumed to be equal.
3686 
3687  @param t the AbstractTable object to modify
3688  @param c the new column definition
3689 
3690  @return a list of sql strings that can be used to modify the column to the new definition; if the column definitions are identical then an empty list is returned
3691  */
3692  list getModifySql(AbstractTable t, AbstractColumn c, *hash opt);
3693 
3694 
3696 /** @par Example:
3697  @code
3698 my string $str = $col.getRenameSql($t, "new_name");
3699  @endcode
3700 
3701  @param t the AbstractTable object to modify
3702  @param new_name the new name for the column
3703 
3704  @return a string that can be used to rename the column
3705  */
3706  abstract string getRenameSql(AbstractTable t, string new_name);
3707 
3709  bool equal(AbstractColumn c);
3710 
3711 
3713 
3714 private:
3715  abstract bool equalImpl(AbstractColumn c);
3716 public:
3717 
3719 /** @par Example:
3720  @code
3721 my list $l = $col.getModifySql($t, $newcol);
3722  @endcode
3723 
3724  The column names are assumed to be equal.
3725 
3726  @param t the AbstractTable object to modify
3727  @param c the new column definition
3728 
3729  @return a list of sql strings that can be used to modify the column to the new definition; if the column definitions are identical then an empty list is returned
3730  */
3731 
3732 private:
3733  abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
3734 public:
3735  };
3736 
3738  class NumericColumnInfo {
3739 
3740 public:
3741  public :
3743  int scale;
3744 
3745 public:
3746 
3747  constructor(softint n_scale = 0);
3748 
3749 
3751  string getNativeTypeString(string native_type, int precision);
3752 
3753  };
3754 
3756 class Indexes : public AbstractHashContainer {
3757 
3758 public:
3759  constructor(*hash c);
3760 
3761 
3763  add(string k, AbstractIndex val);
3764 
3765 
3767  *AbstractIndex findEqual(AbstractIndex ix);
3768 
3769 
3771  AbstractIndex take(string k);
3772 
3773 
3775 /** @par Example:
3776  @code
3777 my AbstractIndex $ix = $indexes.pk_jobs;
3778  @endcode
3779 
3780  @param k the name of the key to access
3781 
3782  @return the value of the given key in the contained hash if it exists
3783 
3784  @throw KEY-ERROR the given key does not exist in the contained hash
3785 
3786  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3787 
3788  @see @ref memberGate_methods
3789  */
3790  AbstractIndex memberGate(string k);
3791 
3792 
3793  string getElementName();
3794 
3795  };
3796 
3798  class AbstractIndex {
3799 
3800 public:
3801  public :
3803  string name;
3804 
3806  bool unique;
3807 
3809  Columns columns;
3810 
3811 public:
3812 
3813  private :
3815  *AbstractUniqueConstraint constraint;
3816 
3817 public:
3818 
3820  constructor(string n, bool u, hash c);
3821 
3822 
3824  string getName();
3825 
3826 
3828  bool hasColumn(string cname);
3829 
3830 
3832  abstract string getCreateSql(string table_name, *hash opt);
3833 
3835  string getDropSql(string table_name);
3836 
3837 
3839  bool equal(AbstractIndex ix);
3840 
3841 
3843  bool equalExceptName(AbstractIndex ix);
3844 
3845 
3847  abstract bool equalImpl(AbstractIndex ix);
3848 
3850  abstract string getRenameSql(string table_name, string new_name);
3851 
3853  setSupportingConstraint(AbstractUniqueConstraint c);
3854 
3855 
3857  setSupportingConstraint();
3858 
3859 
3861  *AbstractUniqueConstraint getSupportingConstraint();
3862 
3863 
3865  list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt);
3866 
3867  };
3868 
3870 class Constraints : public AbstractHashContainer {
3871 
3872 public:
3873  constructor(*hash c);
3874 
3875 
3877  add(string k, AbstractConstraint val);
3878 
3879 
3881  AbstractConstraint take(string k);
3882 
3883 
3885  *AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk);
3886 
3887 
3889 /** @par Example:
3890  @code
3891 my AbstractConstraint $ix = $constraints.uk_jobs;
3892  @endcode
3893 
3894  @param k the name of the key to access
3895 
3896  @return the value of the given key in the contained hash if it exists
3897 
3898  @throw KEY-ERROR the given key does not exist in the contained hash
3899 
3900  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
3901 
3902  @see @ref memberGate_methods
3903  */
3904  AbstractConstraint memberGate(string k);
3905 
3906 
3907  string getElementName();
3908 
3909  };
3910 
3912  class AbstractConstraint {
3913 
3914 public:
3915 private:
3916 
3917 public:
3918 
3919  private :
3921  string name;
3922 
3923 public:
3924 
3926  constructor(string n);
3927 
3928 
3930  string getName();
3931 
3932 
3934  rename(string n);
3935 
3936 
3938  abstract string getCreateSql(string table_name, *hash opt);
3939 
3941  string getDropSql(string table_name);
3942 
3943 
3945  abstract list getRenameSql(string table_name, string new_name);
3946 
3948  string getDisableSql(string table_name);
3949 
3950 
3952  string getEnableSql(string table_name, *hash opt);
3953 
3954 
3956  bool equal(AbstractConstraint c);
3957 
3958 
3960 
3961 private:
3962  abstract bool equalImpl(AbstractConstraint c);
3963 public:
3964 
3966  abstract bool setIndexBase(string ix);
3967 
3969  abstract clearIndex();
3970 
3972  bool hasColumn(string cname);
3973 
3974  };
3975 
3977 class AbstractCheckConstraint : public AbstractConstraint {
3978 
3979 public:
3980  public :
3982  string src;
3983 
3984 public:
3985 
3987  constructor(string n, string n_src);
3988 
3989 
3991 
3992 private:
3993  bool equalImpl(AbstractConstraint c);
3994 public:
3995 
3996 
3998  bool setIndexBase(string ix);
3999 
4000 
4002  clearIndex();
4003 
4004  };
4005 
4007 class AbstractUniqueConstraint : public AbstractConstraint,public Columns {
4008 
4009 public:
4010  private :
4012  hash sourceConstraints;
4013 
4015  *string index;
4016 
4017 public:
4018 
4020  constructor(string n, *hash c, *string n_index);
4021 
4022 
4024  abstract string getCreateSql(string table_name, *hash opts);
4025 
4027 
4028 private:
4029  bool equalImpl(AbstractConstraint c);
4030 public:
4031 
4032 
4034 /** each element is a hash with the following keys:
4035  - \c fk: the AbstractForeignConstraint object
4036  - \c table: the table name
4037  */
4038  Qore::AbstractIterator getSourceConstraintIterator();
4039 
4040 
4042  hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts);
4043 
4044 
4046  findMatchingIndex(*Indexes indexes);
4047 
4048 
4050 /** @par Example:
4051  @code
4052 $uk.addSourceConstraint($table_name, constraint_name);
4053  @endcode
4054 
4055  @param tname the name of the source table
4056  @param fk the source constraint
4057 
4058  @throw SOURCE-CONSTRAINT-ERROR a different source constraint with the given name already exists
4059  */
4060  addSourceConstraint(string tname, AbstractForeignConstraint fk);
4061 
4062 
4064  removeSourceConstraint(string tname, list cols);
4065 
4066 
4068  renameSourceConstraintTable(string old_name, string new_name);
4069 
4070 
4072  bool hasColumn(string cname);
4073 
4074  };
4075 
4077 class AbstractPrimaryKey : public AbstractUniqueConstraint {
4078 
4079 public:
4080  constructor();
4081 
4082 
4083  constructor(string n, *hash c);
4084 
4085  };
4086 
4088 class ForeignConstraints : public AbstractHashContainer {
4089 
4090 public:
4091  constructor(*hash c);
4092 
4093 
4095  add(string k, AbstractForeignConstraint val);
4096 
4097 
4099  AbstractForeignConstraint take(string k);
4100 
4101 
4103  *AbstractForeignConstraint findEqual(AbstractForeignConstraint fk);
4104 
4105 
4107 /** @par Example:
4108  @code
4109 my AbstractForeignConstraint $ix = $fcs.fk_jobs_job_defs;
4110  @endcode
4111 
4112  @param k the name of the key to access
4113 
4114  @return the value of the given key in the contained hash if it exists
4115 
4116  @throw KEY-ERROR the given key does not exist in the contained hash
4117 
4118  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
4119 
4120  @see @ref memberGate_methods
4121  */
4122  AbstractForeignConstraint memberGate(string k);
4123 
4124 
4126  *hash findConstraintOn(string table, softlist cols);
4127 
4128 
4130  string getElementName();
4131 
4132  };
4133 
4135  class ForeignConstraintTarget {
4136 
4137 public:
4138  public :
4140  string table;
4141 
4143  Columns columns;
4144 
4145 public:
4146 
4148  constructor(string t, Columns c);
4149 
4150 
4152  bool equal(ForeignConstraintTarget targ);
4153 
4154  };
4155 
4157 class AbstractForeignConstraint : public AbstractConstraint {
4158 
4159 public:
4160  public :
4162  Columns columns;
4163 
4165  ForeignConstraintTarget target;
4166 
4167 public:
4168 
4169  constructor(string n, Columns c, ForeignConstraintTarget t);
4170 
4171 
4173 
4174 private:
4175  bool equalImpl(AbstractConstraint con);
4176 public:
4177 
4178 
4180  bool hasColumn(string cname);
4181 
4182 
4184  bool setIndexBase(string ix);
4185 
4186 
4188  clearIndex();
4189 
4190  };
4191 
4193  class AbstractSequence {
4194 
4195 public:
4196  public :
4198  string name;
4199 
4201  number start;
4202 
4204  number increment;
4205 
4207  *number max;
4208 
4209 public:
4210 
4212  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_max);
4213 
4214 
4216  abstract string getCreateSql(*hash opt);
4217 
4219  string getDropSql();
4220 
4221 
4223  abstract string getRenameSql(string new_name);
4224  };
4225 
4227  class AbstractFunctionBase {
4228 
4229 public:
4230  public :
4232  string name;
4233 
4235  string type;
4236 
4238  string src;
4239 
4240 public:
4241 
4243 /** @param n the name of the object
4244  @param n_type the type of object
4245  @param n_src the source of the object
4246  */
4247  constructor(string n, string n_type, string n_src);
4248 
4249 
4251  string getType();
4252 
4253 
4254  // FIXME: not appropriate for pgsql triggers for example
4256  string getDropSql();
4257 
4258 
4260  bool equal(AbstractFunctionBase t);
4261 
4262 
4264 
4265 private:
4266  abstract bool equalImpl(AbstractFunctionBase t);
4267 public:
4268  };
4269 
4271 class AbstractFunction : public AbstractFunctionBase {
4272 
4273 public:
4275 /** @param n the name of the object
4276  @param n_type the type of object
4277  @param n_src the source of the object
4278  */
4279  constructor(string n, string n_type, string n_src);
4280 
4281 
4283  abstract list getCreateSql(*hash opt);
4284 
4286  abstract list getRenameSql(string new_name);
4287 
4289  setName(string new_name);
4290 
4291  };
4292 
4294 class Functions : public AbstractHashContainer {
4295 
4296 public:
4297  constructor(*hash c);
4298 
4299 
4301  add(string k, AbstractFunction val);
4302 
4303 
4305  AbstractFunction take(string k);
4306 
4307 
4309 /** @par Example:
4310  @code
4311 my AbstractFunction $f = $funcs.func1;
4312  @endcode
4313 
4314  @param k the name of the key to access
4315 
4316  @return the value of the given key in the contained hash if it exists
4317 
4318  @throw KEY-ERROR the given key does not exist in the contained hash
4319 
4320  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
4321 
4322  @see @ref memberGate_methods
4323  */
4324  AbstractFunction memberGate(string k);
4325 
4326 
4327  string getElementName();
4328 
4329  };
4330 
4332 class AbstractTrigger : public AbstractFunctionBase {
4333 
4334 public:
4336  constructor(string n, string n_src);
4337 
4338 
4340  abstract list getCreateSql(string table_name, *hash opt);
4341 
4343  abstract list getRenameSql(string table_name, string new_name);
4344 
4346  abstract list getDropSql(string table_name);
4347  };
4348 
4350 class Triggers : public AbstractHashContainer {
4351 
4352 public:
4353  constructor(*hash c);
4354 
4355 
4357  add(string k, AbstractTrigger val);
4358 
4359 
4361  AbstractTrigger take(string k);
4362 
4363 
4365 /** @par Example:
4366  @code
4367 my AbstractTrigger $trig = $trigs.job_trig;
4368  @endcode
4369 
4370  @param k the name of the key to access
4371 
4372  @return the value of the given key in the contained hash if it exists
4373 
4374  @throw KEY-ERROR the given key does not exist in the contained hash
4375 
4376  @note this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
4377 
4378  @see @ref memberGate_methods
4379  */
4380  AbstractTrigger memberGate(string k);
4381 
4382 
4383  string getElementName();
4384 
4385  };
4386 
4388 /** Driver-specific modules that provide the AbstractDatabase implementation embedded in this class are loaded on demand based on the driver's name.
4389  The driver-specific module's name is generated based on the db-driver's name with the first letter capitalized then with \c "SqlUtil" appended.
4390 
4391  For example:
4392  - \c "oracle": <a href="../../OracleSqlUtil/html/index.html">OracleSqlUtil</a>
4393  - \c "pgsql": <a href="../../PgsqlSqlUtil/html/index.html">PgsqlSqlUtil</a>
4394  - \c "mysql": <a href="../../MysqlSqlUtil/html/index.html">MysqlSqlUtil</a>
4395 
4396  etc.
4397  */
4398  class Database {
4399 
4400 public:
4401  private :
4404 
4405 public:
4406 
4408 
4419  constructor(AbstractDatasource ds, *hash opts);
4420 
4421 
4423 
4433  constructor(string ds, *hash opts);
4434 
4435 
4437 
4455  constructor(hash ds, *hash opts);
4456 
4457 
4459 
4470  any tryExec(string sql);
4471 
4472 
4474 
4484  any tryExecArgs(string sql, *softlist args);
4485 
4486 
4488 
4499  any tryExecRaw(string sql);
4500 
4501 
4503 
4517  list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
4518 
4519 
4521 
4534  list getDropSchemaSql(hash schema_hash, *hash opt);
4535 
4536 
4538  Qore::SQL::AbstractDatasource getDatasource();
4539 
4540 
4542  any methodGate(string meth);
4543 
4544 
4546 
4560  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
4561 
4562 
4564 
4577  AbstractTable makeTable(string name, hash desc, *hash opts);
4578 
4579 
4581 
4592  AbstractFunction makeFunction(string name, string src, *hash opt);
4593 
4594 
4596 
4607  AbstractFunction makeProcedure(string name, string src, *hash opt);
4608 
4609 
4611 
4623  bool dropFunctionIfExists(string name, *hash opt);
4624 
4625 
4627 
4639  bool dropProcedureIfExists(string name, *hash opt);
4640 
4641 
4643 
4655  bool dropSequenceIfExists(string name, *hash opt);
4656 
4657 
4659 
4671  bool dropTableIfExists(string name, *hash opt);
4672 
4673 
4675 
4687  list getAlignFunctionSql(AbstractFunction f, *hash opt);
4688 
4689 
4691 
4703  list getAlignProcedureSql(AbstractFunction f, *hash opt);
4704 
4705 
4707 
4716  *AbstractTable getTable(string name);
4717 
4718 
4720 
4729  *AbstractSequence getSequence(string name);
4730 
4731 
4733 
4744  *AbstractFunction getFunction(string name);
4745 
4746 
4748 
4759  *AbstractFunction getProcedure(string name);
4760 
4761 
4763 
4772  int getNextSequenceValue(string name);
4773 
4774 
4776 
4785  string getSqlFromList(list l);
4786 
4787 
4789  bool supportsSequences();
4790 
4791 
4793  list listTables();
4794 
4795 
4797  Qore::ListIterator tableIterator();
4798 
4799 
4801  list listFunctions();
4802 
4803 
4805  Qore::ListIterator functionIterator();
4806 
4807 
4809  list listProcedures();
4810 
4811 
4813  Qore::ListIterator procedureIterator();
4814 
4815 
4817  list listSequences();
4818 
4819 
4821  Qore::ListIterator sequenceIterator();
4822 
4823 
4825  list listViews();
4826 
4827 
4829  Qore::ListIterator viewIterator();
4830 
4831  };
4832 
4835 
4836 public:
4837  private :
4839  AbstractDatasource ds;
4841  string dsdesc;
4843  Mutex l();
4846 
4847 public:
4848 
4850 
4856 private:
4857  constructor(AbstractDatasource nds, *hash nopts);
4858 public:
4859 
4860 
4861 
4862 private:
4863  validateOptionsIntern(string err, hash ropt, reference opt, string tag);
4864 public:
4865 
4866 
4867 
4868 private:
4869  static validateOptionIntern(string err, string type, reference opt, string k, string tag);
4870 public:
4871 
4872 
4874  Qore::SQL::AbstractDatasource getDatasource();
4875 
4876 
4878  string getDriverName();
4879 
4880 
4882  string getDatasourceDesc();
4883 
4884  };
4885 
4888 
4889 public:
4890  public :
4892 
4895  const DatabaseOptions = (
4896  "native_case": Type::Boolean,
4897  );
4898 
4900 
4903  const CacheOptions = (
4904  "table_cache": "Tables",
4905  );
4906 
4908 
4913  const CallbackOptions = (
4914  "info_callback": "code",
4915  "sql_callback": "code",
4916  "sql_callback_executed": Type::Boolean,
4917  );
4918 
4927  const AC_Unchanged = 0;
4929 
4931  const AC_Create = 1;
4932 
4934  const AC_Drop = 2;
4935 
4937  const AC_Rename = 3;
4938 
4940  const AC_Modify = 4;
4941 
4943  const AC_Truncate = 5;
4944 
4946  const AC_Add = 6;
4947 
4949  const AC_Recreate = 7;
4950 
4952  const AC_Insert = 8;
4953 
4955  const AC_Update = 9;
4956 
4958  const AC_Delete = 10;
4959 
4961  const AC_NotFound = 11;
4963 
4965  const ActionMap = (
4966  AC_Unchanged: "unchanged",
4967  AC_Create: "create",
4968  AC_Drop: "drop",
4969  AC_Rename: "rename",
4970  AC_Modify: "modify",
4971  AC_Truncate: "truncate",
4972  AC_Add: "add",
4973  AC_Recreate: "recreate",
4974  AC_Insert: "insert",
4975  AC_Update: "update",
4976  AC_Delete: "delete",
4977  AC_NotFound: "not found",
4978  );
4979 
4981  const ActionDescMap = (
4982  "unchanged": AC_Unchanged,
4983  "create": AC_Create,
4984  "drop": AC_Drop,
4985  "rename": AC_Rename,
4986  "modify": AC_Modify,
4987  "truncate": AC_Truncate,
4988  "add": AC_Add,
4989  "recreate": AC_Recreate,
4990  "insert": AC_Insert,
4991  "update": AC_Update,
4992  "delete": AC_Delete,
4993  "not found": AC_NotFound,
4994  );
4995 
4997  const ActionLetterMap = (
4998  AC_Unchanged: ".",
4999  AC_Create: "C",
5000  AC_Drop: "D",
5001  AC_Rename: "N",
5002  AC_Modify: "M",
5003  AC_Truncate: "T",
5004  AC_Add: "A",
5005  AC_Recreate: "R",
5006  AC_Insert: "I",
5007  AC_Update: "U",
5008  AC_Delete: "X",
5009  AC_NotFound: ".",
5010  );
5011 
5013 
5019  const CreationOptions = CallbackOptions + (
5020  "replace": Type::Boolean,
5021  "table_cache": "Tables",
5022  "data_tablespace": Type::String,
5023  "index_tablespace": Type::String,
5024  );
5025 
5027 
5029  const AlignSchemaOptions = CreationOptions;
5030 
5032 
5034  const DropSchemaOptions = CallbackOptions;
5035 
5037 
5049  const SchemaDescriptionOptions = (
5050  "tables": Type::Hash,
5051  "table_map": Type::Hash,
5052 
5053  "sequences": Type::Hash,
5054  "sequence_map": Type::Hash,
5055 
5056  "functions": Type::Hash,
5057  "function_map": Type::Hash,
5058 
5059  "procedures": Type::Hash,
5060  "procedure_map": Type::Hash,
5061 
5062  //"views": Type::Hash,
5063  //"view_map": Type::Hash,
5064  );
5065 
5067 
5072  const SequenceDescriptionOptions = (
5073  "start": Type::Int,
5074  "increment": Type::Int,
5075  "end": Type::Int,
5076  );
5077 
5078 public:
5079 
5080  private :
5082  bool native_case = False;
5083 
5084 public:
5085 
5087 
5093 private:
5094  constructor(AbstractDatasource nds, *hash nopts);
5095 public:
5096 
5097 
5099  list features();
5100 
5101 
5102  static doOkCallback(*hash opt, int ac, string type, string name, *string table, *string info);
5103 
5104  static *string doCallback(*hash opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
5105 
5106  static list doCallback(*hash opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
5107 
5108 /*
5109  static *string doCallback(*hash opt, *string sql, string fmt) {
5110  if (!sql)
5111  return;
5112  if (opt.info_callback)
5113  opt.info_callback(vsprintf(fmt, argv));
5114  if (opt.sql_callback)
5115  opt.sql_callback(sql);
5116  return sql;
5117  }
5118 
5119  static list doCallback(*hash opt, list sql, string fmt) {
5120  if (sql) {
5121  if (opt.info_callback)
5122  opt.info_callback(vsprintf(fmt, argv));
5123  if (opt.sql_callback)
5124  map opt.sql_callback($1), sql;
5125  }
5126  return sql;
5127  }
5128 */
5129 
5131 
5142  any tryExec(string sql);
5143 
5144 
5146 
5156  any tryExecArgs(string sql, *softlist args);
5157 
5158 
5160 
5171  any tryExecRaw(string sql);
5172 
5173 
5175 
5189  list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
5190 
5191 
5193 
5206  list getDropSchemaSql(hash schema_hash, *hash opt);
5207 
5208 
5209 
5210 private:
5211  list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
5212 public:
5213 
5214 
5215 
5216 private:
5217  list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
5218 public:
5219 
5220 
5222 
5236  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
5237 
5238 
5239  AbstractSequence makeSequenceFromDescription(string name, *hash sh, *hash opts);
5240 
5241 
5243 
5256  AbstractTable makeTable(string name, hash desc, *hash opts);
5257 
5258 
5260 
5271  AbstractFunction makeFunction(string name, string src, *hash opts);
5272 
5273 
5275 
5286  AbstractFunction makeProcedure(string name, string src, *hash opt);
5287 
5288 
5290 
5302  bool dropFunctionIfExists(string name, *hash opt);
5303 
5304 
5306 
5318  bool dropProcedureIfExists(string name, *hash opt);
5319 
5320 
5322 
5334  bool dropSequenceIfExists(string name, *hash opt);
5335 
5336 
5338 
5350  bool dropTableIfExists(string name, *hash opt);
5351 
5352 
5354 
5366  *string getDropFunctionSqlIfExists(string name, *hash opt);
5367 
5368 
5370 
5382  *string getDropProcedureSqlIfExists(string name, *hash opt);
5383 
5384 
5386 
5398  *string getDropSequenceSqlIfExists(string name, *hash opt);
5399 
5400 
5402 
5414  *list getDropTableSqlIfExists(string name, *hash opt);
5415 
5416 
5417  doDropSql(*softlist l, string type, string name, *hash opt);
5418 
5419 
5420  bool doDrop(*softlist l, string type, string name, *hash opt);
5421 
5422 
5424 
5436  list getAlignFunctionSql(AbstractFunction f, *hash opt);
5437 
5438 
5440 
5452  list getAlignProcedureSql(AbstractFunction f, *hash opt);
5453 
5454 
5456 
5465  *AbstractTable getTable(string name);
5466 
5467 
5469 
5478  *AbstractSequence getSequence(string name);
5479 
5480 
5482 
5493  *AbstractFunction getFunction(string name);
5494 
5495 
5497 
5508  *AbstractFunction getProcedure(string name);
5509 
5510 
5512 
5521  int getNextSequenceValue(string name);
5522 
5523 
5525 
5534  string getSqlFromList(list l);
5535 
5536 
5538  bool supportsSequences();
5539 
5540 
5542  bool supportsTypes();
5543 
5544 
5546  bool supportsPackages();
5547 
5548 
5550  list listTables();
5551 
5552 
5554  Qore::ListIterator tableIterator();
5555 
5556 
5558  list listFunctions();
5559 
5560 
5562  Qore::ListIterator functionIterator();
5563 
5564 
5566  list listProcedures();
5567 
5568 
5570  Qore::ListIterator procedureIterator();
5571 
5572 
5574  list listSequences();
5575 
5576 
5578  Qore::ListIterator sequenceIterator();
5579 
5580 
5582  list listViews();
5583 
5584 
5586  Qore::ListIterator viewIterator();
5587 
5588 
5589 
5590 private:
5591  validateOptionsIntern(string err, hash ropt, reference opt);
5592 public:
5593 
5594 
5595 
5596 private:
5597  validateOptionsIntern(string err, hash ropt, reference opt, string tag);
5598 public:
5599 
5600 
5601  static AbstractDatabase getDatabase(AbstractDatasource nds, *hash opts);
5602 
5603  static AbstractDatabase getDatabase(string dsstr, *hash opts);
5604 
5605  static AbstractDatabase getDatabase(hash dsh, *hash opts);
5606 
5607  static checkDriverOptions(reference h, string drv);
5608 
5610 
5611 private:
5612  hash getDatabaseOptions();
5613 public:
5614 
5615 
5617 
5618 private:
5619  hash getCallbackOptions();
5620 public:
5621 
5622 
5624 
5625 private:
5626  hash getCreationOptions();
5627 public:
5628 
5629 
5631 
5632 private:
5633  hash getCacheOptions();
5634 public:
5635 
5636 
5638 
5639 private:
5640  hash getAlignSchemaOptions();
5641 public:
5642 
5643 
5645 
5646 private:
5647  hash getDropSchemaOptions();
5648 public:
5649 
5650 
5652 
5653 private:
5654  hash getSchemaDescriptionOptions();
5655 public:
5656 
5657 
5659 
5660 private:
5661  hash getSequenceDescriptionOptions();
5662 public:
5663 
5664 
5666 
5667 private:
5668  any tryExecArgsImpl(string sql, *softlist args);
5669 public:
5670 
5671 
5673 
5674 private:
5675  any tryExecRawImpl(string sql);
5676 public:
5677 
5678 
5679 
5680 private:
5681  abstract string getCreateSqlImpl(list l);
5682 public:
5683 
5684 private:
5685  abstract list getAlignSqlImpl(hash schema_hash, *hash opt);
5686 public:
5687 
5688 private:
5689  abstract list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
5690 public:
5691 
5692 
5693 private:
5694  abstract *AbstractSequence getSequenceImpl(string name);
5695 public:
5696 
5697 private:
5698  abstract *AbstractFunction getFunctionImpl(string name);
5699 public:
5700 
5701 private:
5702  abstract *AbstractFunction getProcedureImpl(string name);
5703 public:
5704 
5705 
5706 private:
5707  abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
5708 public:
5709 
5710 private:
5711  abstract AbstractFunction makeFunctionImpl(string name, string src, *hash opts);
5712 public:
5713 
5714 private:
5715  abstract AbstractFunction makeProcedureImpl(string name, string src, *hash opts);
5716 public:
5717 
5718 
5719 private:
5720  abstract list featuresImpl();
5721 public:
5722 
5723 private:
5724  abstract list listTablesImpl();
5725 public:
5726 
5727 private:
5728  abstract list listFunctionsImpl();
5729 public:
5730 
5731 private:
5732  abstract list listProceduresImpl();
5733 public:
5734 
5735 private:
5736  abstract list listSequencesImpl();
5737 public:
5738 
5739 private:
5740  abstract list listViewsImpl();
5741 public:
5742 
5744 
5745 private:
5746  abstract int getNextSequenceValueImpl(string name);
5747 public:
5748 
5750 
5751 private:
5752  abstract bool supportsSequencesImpl();
5753 public:
5754 
5755 private:
5756  abstract bool supportsPackagesImpl();
5757 public:
5758 
5759 private:
5760  abstract bool supportsTypesImpl();
5761 public:
5762  };
5763 
5765 
5775  class Table {
5776 
5777 public:
5778  private :
5781 
5782 public:
5783 
5785 
5797  constructor(AbstractDatasource ds, string name, *hash opts);
5798 
5799 
5801 
5813  constructor(string ds, string name, *hash opts);
5814 
5815 
5817 
5837  constructor(hash ds, string name, *hash opts);
5838 
5839 
5841 
5849  constructor(AbstractDatasource ds, hash desc, string name, *hash opts);
5850 
5851 
5853 
5864  setDatasource(AbstractDatasource nds);
5865 
5866 
5868  commit();
5869 
5870 
5872  rollback();
5873 
5874 
5876  string getName();
5877 
5878 
5880  Qore::SQL::AbstractDatasource getDatasource();
5881 
5882 
5884  AbstractTable getTable();
5885 
5886 
5888  any methodGate(string meth);
5889 
5890 
5892 
5899  bool inDb();
5900 
5901 
5903 
5909  setupTable(hash desc, *hash opt);
5910 
5911 
5913 
5920  Qore::AbstractIterator getUniqueConstraintIterator();
5921 
5922 
5924 
5935  drop(*hash opt);
5936 
5937 
5939 
5950  dropNoCommit(*hash opt);
5951 
5952 
5954 
5965  any tryExec(string sql);
5966 
5967 
5969 
5979  any tryExecArgs(string sql, *softlist args);
5980 
5981 
5983 
5994  any tryExecRaw(string sql);
5995 
5996 
5998 
6005  truncate();
6006 
6007 
6009 
6016  truncateNoCommit();
6017 
6018 
6020 
6035  string getTruncateSql(*hash opt);
6036 
6037 
6039 
6050  create(*hash opt);
6051 
6052 
6054 
6063  createNoCommit(*hash opt);
6064 
6065 
6067 
6078  rename(string new_name, *reference sql, *Tables table_cache);
6079 
6080 
6082 
6093  bool emptyData();
6094 
6095 
6097 
6106  bool empty();
6107 
6108 
6110 
6134  AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
6135 
6136 
6138 
6166  list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
6167 
6168 
6170 
6196  AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
6197 
6198 
6200 
6226  list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
6227 
6228 
6230 
6246  AbstractColumn renameColumn(string old_name, string new_name, reference sql);
6247 
6248 
6250 
6268  string getRenameColumnSql(string old_name, string new_name, *hash opt);
6269 
6270 
6272 
6293  AbstractPrimaryKey addPrimaryKey(string cname, softlist cols, *hash opt, *reference sql);
6294 
6295 
6297 
6319  string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
6320 
6321 
6323 
6341  AbstractPrimaryKey dropPrimaryKey(*reference lsql);
6342 
6343 
6345 
6364  list getDropPrimaryKeySql(*hash opt);
6365 
6366 
6368 
6391  AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql);
6392 
6393 
6395 
6415  string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
6416 
6417 
6419 
6441  AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql);
6442 
6443 
6445 
6466  string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
6467 
6468 
6470 
6482  AbstractIndex renameIndex(string old_name, string new_name, reference sql);
6483 
6484 
6486 
6505  string getDropIndexSql(string iname, *hash opt);
6506 
6507 
6509 
6528  string getDropConstraintSql(string cname, *hash opt);
6529 
6530 
6532 
6551  *string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref);
6552 
6553 
6555 
6573  AbstractIndex dropIndex(string iname, *reference sql);
6574 
6575 
6577 
6600  AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
6601 
6602 
6604 
6626  string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
6627 
6628 
6630 
6648  AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql);
6649 
6650 
6652 
6667  AbstractForeignConstraint removeForeignConstraint(string cname);
6668 
6669 
6671 
6691  AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql);
6692 
6693 
6695 
6717  string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
6718 
6719 
6721 
6733  AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
6734 
6735 
6737 
6755  AbstractConstraint dropConstraint(string cname, *reference sql);
6756 
6757 
6759 
6779  AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
6780 
6781 
6783 
6805  list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
6806 
6807 
6809 
6827  AbstractTrigger dropTrigger(string tname, *reference sql);
6828 
6829 
6831 
6850  list getDropTriggerSql(string tname, *hash opt);
6851 
6852 
6854 
6865  string getSqlValue(any v);
6866 
6867 
6869 
6885  AbstractColumn dropColumn(string cname, *reference lsql);
6886 
6887 
6889 
6908  list getDropColumnSql(string cname, *hash opt);
6909 
6910 
6912 
6922  insert(hash row, *reference sql);
6923 
6924 
6926 
6936  insertNoCommit(hash row, *reference sql);
6937 
6938 
6940 
6950  insert(hash row, *hash opt);
6951 
6952 
6954 
6964  insertNoCommit(hash row, *hash opt);
6965 
6966 
6968 
6986  int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql);
6987 
6988 
6990 
7008  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql);
7009 
7010 
7012 
7030  int insertFromSelect(list cols, AbstractTable source, *hash sh, *hash opt);
7031 
7032 
7034 
7052  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *hash opt);
7053 
7054 
7056 
7074  int insertFromIterator(Qore::AbstractIterator i, *hash opt);
7075 
7076 
7078 
7096  int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt);
7097 
7098 
7100 
7120  int upsert(hash row, int upsert_strategy = AbstractTable::UpsertAuto);
7121 
7122 
7124 
7144  int upsertNoCommit(hash row, int upsert_strategy = AbstractTable::UpsertAuto);
7145 
7146 
7148 
7173  code getUpsertClosure(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto);
7174 
7175 
7177 
7202  code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto);
7203 
7204 
7206 
7235  *hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7236 
7237 
7239 
7268  *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7269 
7270 
7272 
7309  *hash upsertFromSelect(AbstractTable src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7310 
7311 
7313 
7352  *hash upsertFromSelectNoCommit(AbstractTable src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7353 
7354 
7356 
7393  *hash upsertFromSelect(Table src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7394 
7395 
7397 
7436  *hash upsertFromSelectNoCommit(Table src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7437 
7438 
7440 
7451  softint rowCount();
7452 
7453 
7455 
7472  Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql);
7473 
7474 
7476 
7493  Qore::SQL::SQLStatement getRowIterator(*hash sh, *hash opt);
7494 
7495 
7497 
7513  *hash selectRow(*hash sh, *reference sql);
7514 
7515 
7517 
7532  *list selectRows(*hash sh, *reference sql);
7533 
7534 
7536 
7551  *hash select(*hash sh, *reference sql);
7552 
7553 
7555 
7571  *hash selectRow(*hash sh, *hash opt);
7572 
7573 
7575 
7590  *list selectRows(*hash sh, *hash opt);
7591 
7592 
7594 
7609  *hash select(*hash sh, *hash opt);
7610 
7611 
7613 
7631  string getSelectSql(*hash sh, *reference args);
7632 
7633 
7635 
7649  int del(*hash cond, *reference sql);
7650 
7651 
7653 
7667  int delNoCommit(*hash cond, *reference sql);
7668 
7669 
7671 
7687  int update(hash set, *hash cond, *reference sql);
7688 
7689 
7691 
7707  int updateNoCommit(hash set, *hash cond, *reference sql);
7708 
7709 
7711 
7725  int del(*hash cond, *hash opt);
7726 
7727 
7729 
7743  int delNoCommit(*hash cond, *hash opt);
7744 
7745 
7747 
7763  int update(hash set, *hash cond, *hash opt);
7764 
7765 
7767 
7783  int updateNoCommit(hash set, *hash cond, *hash opt);
7784 
7785 
7787 
7796  string getSqlFromList(list l);
7797 
7798 
7800 
7818  string getRenameSql(string new_name, *hash opt);
7819 
7820 
7822 
7833  string getCreateSqlString(*hash opt);
7834 
7835 
7837 
7846  list getCreateSql(*hash opt);
7847 
7848 
7850 
7861  string getCreateTableSql(*hash opt);
7862 
7863 
7865 
7876  *list getCreateIndexesSql(*hash opt);
7877 
7878 
7880 
7891  *string getCreatePrimaryKeySql(*hash opt);
7892 
7893 
7895 
7906  *list getCreateForeignConstraintsSql(*hash opt);
7907 
7908 
7910 
7923  *list getCreateConstraintsSql(*hash opt);
7924 
7925 
7927 
7938  *list getCreateMiscSql(*hash opt);
7939 
7940 
7942 
7953  *list getCreateTriggersSql(*hash opt);
7954 
7955 
7957 
7970  list getAlignSql(AbstractTable table, *hash opt);
7971 
7972 
7974 
7987  list getAlignSql(Table table, *hash opt);
7988 
7989 
7991 
8004  string getAlignSqlString(AbstractTable table, *hash opt);
8005 
8006 
8008 
8021  string getAlignSqlString(Table table, *hash opt);
8022 
8023 
8025 
8036  *hash find(any id);
8037 
8038 
8040 
8051  *list find(list ids);
8052 
8053 
8055 
8066  *hash find(hash row);
8067 
8068 
8070 
8085  *hash findSingle(*hash cond);
8086 
8087 
8089 
8102  *list findAll(*hash cond);
8103 
8104 
8106 
8113  cache(*hash opts);
8114 
8115 
8117 
8123  clear();
8124 
8125 
8127 
8134  Columns describe();
8135 
8136 
8138 
8147  AbstractPrimaryKey getPrimaryKey();
8148 
8149 
8151 
8160  *AbstractUniqueConstraint findUniqueConstraint(string name);
8161 
8162 
8164 
8173  Indexes getIndexes();
8174 
8175 
8177 
8186  Triggers getTriggers();
8187 
8188 
8190  ForeignConstraints getForeignConstraints(*hash opt);
8191 
8192 
8194  Constraints getConstraints();
8195 
8196 
8198  string getDriverName();
8199 
8200  };
8201 
8204 
8205 public:
8206  public :
8208 
8212  const TableOptions = (
8213  "native_case": Type::Boolean,
8214  "table_cache": "Tables",
8215  );
8216 
8218 
8222  const IndexOptions = (
8223  "index_tablespace": Type::String,
8224  "replace": Type::Boolean,
8225  );
8226 
8228 
8230  const ConstraintOptions = IndexOptions;
8231 
8233  const CacheOptions = (
8234  "table_cache": "Tables",
8235  );
8236 
8238 
8241  const ForeignConstraintOptions = ConstraintOptions + (
8242  "table_cache": "Tables",
8243  );
8244 
8246 
8248  const TriggerOptions = AbstractDatabase::CreationOptions;
8249 
8251 
8263  const SelectOptions = (
8264  "comment": Type::String,
8265  "hint": Type::String,
8266  "columns": Type::NothingType,
8267  "where": "hash/list",
8268  "orderby": "softstringhashlist",
8269  "desc": Type::Boolean,
8270  "limit": Type::Int,
8271  "offset": Type::Int,
8272  "join": Type::Hash,
8273  "groupby": "softstringhashlist",
8274  "having": Type::Hash,
8275  "superquery": Type::Hash,
8276  );
8277 
8279  const TableOmissionOptions = (
8280  "indexes": True,
8281  "foreign_constraints": True,
8282  "triggers": True,
8283  );
8284 
8286 
8289  const TableCreationOptions = IndexOptions + AbstractDatabase::CreationOptions + (
8290  "omit": "softstringlist",
8291  );
8292 
8294 
8301  const AlignTableOptions = TableCreationOptions + (
8302  "column_map": Type::Hash,
8303  "index_map": Type::Hash,
8304  "constraint_map": Type::Hash,
8305  "trigger_map": Type::Hash,
8306  "db_table_cache": "Tables",
8307  );
8308 
8310 
8321  const TableDescriptionHashOptions = (
8322  "columns": Type::Hash,
8323  "primary_key": Type::Hash,
8324  "indexes": Type::Hash,
8325  "triggers": Type::Hash,
8326  "foreign_constraints": Type::Hash,
8327  "unique_constraints": Type::Hash,
8328  //"check_constraints": Type::Hash,
8329  "table_cache": "Tables",
8330  );
8331 
8333 
8344  const ColumnDescOptions = (
8345  "qore_type": Type::String,
8346  "native_type": Type::String,
8347  "size": Type::Int,
8348  "scale": Type::Int,
8349  "default_value": Type::NothingType,
8350  "comment": Type::String,
8351  );
8352 
8354 
8357  const AdditionalColumnDescOptions = (
8358  "notnull": Type::Boolean,
8359  );
8360 
8362  const ColumnOptions = hash();
8363 
8365 
8368  const SqlDataCallbackOptions = (
8369  "sqlarg_callback": "code",
8370  );
8371 
8373 
8378  const UpsertOptions = (
8379  "info_callback": "code",
8380  "commit_block": Type::Int,
8381  "delete_others": Type::Boolean,
8382  );
8383 
8385 
8389  const InsertOptions = SqlDataCallbackOptions + (
8390  "info_callback": "code",
8391  "commit_block": Type::Int,
8392  );
8393 
8408 
8414  const UpsertInsertFirst = 1;
8415 
8417 
8422  const UpsertUpdateFirst = 2;
8423 
8425 
8431  const UpsertSelectFirst = 3;
8432 
8434 
8438  const UpsertAuto = 4;
8440 
8445  const UR_Inserted = 1;
8447 
8449  const UR_Verified = 2;
8450 
8452  const UR_Updated = 3;
8453 
8455  const UR_Unchanged = 4;
8456 
8458  const UR_Deleted = 5;
8460 
8462 
8464  const UpsertResultMap = (
8465  UR_Inserted: "inserted",
8466  UR_Verified: "verified",
8467  UR_Updated: "updated",
8468  UR_Unchanged: "unchanged",
8469  UR_Deleted: "deleted",
8470  );
8471 
8473 
8475  const UpsertResultDescriptionMap = (
8476  "inserted": UR_Inserted,
8477  "verified": UR_Verified,
8478  "updated": UR_Updated,
8479  "unchanged": UR_Unchanged,
8480  "deleted": UR_Deleted,
8481  );
8482 
8484  const UpsertResultLetterMap = (
8485  UR_Inserted: "I",
8486  UR_Verified: "V",
8487  UR_Updated: "U",
8488  UR_Unchanged: ".",
8489  UR_Deleted: "X",
8490  );
8491 
8492 public:
8493 
8494  private :
8496  string name;
8510  bool native_case = False;
8512  bool inDb = False;
8514  bool manual = False;
8515 
8516 public:
8517 
8519 
8526 private:
8527  constructor(AbstractDatasource nds, string nname, *hash nopts);
8528 public:
8529 
8530 
8532  copy(AbstractTable old);
8533 
8534 
8536 
8547  setDatasource(AbstractDatasource nds);
8548 
8549 
8550 
8551 private:
8552  doTableOptions(*hash nopts);
8553 public:
8554 
8555 
8557  commit();
8558 
8559 
8561  rollback();
8562 
8563 
8565 
8572  bool inDb();
8573 
8574 
8576 
8583  Qore::AbstractIterator getUniqueConstraintIterator();
8584 
8585 
8587 
8598  drop(*hash opt);
8599 
8600 
8602 
8613  any tryExec(string sql);
8614 
8615 
8617 
8627  any tryExecArgs(string sql, *softlist args);
8628 
8629 
8631 
8642  any tryExecRaw(string sql);
8643 
8644 
8646 
8657  dropNoCommit(*hash opt);
8658 
8659 
8661 
8671  softlist getDropSql(*hash opt);
8672 
8673 
8675 
8682  truncate();
8683 
8684 
8686 
8693  truncateNoCommit();
8694 
8695 
8697 
8712  string getTruncateSql(*hash opt);
8713 
8714 
8716 
8725  create(*hash opt);
8726 
8727 
8729 
8740  createNoCommit(*hash opt);
8741 
8742 
8744 
8755  rename(string new_name, *reference sql, *Tables table_cache);
8756 
8757 
8758 
8759 private:
8760  doRenameIntern(string new_name, *Tables table_cache);
8761 public:
8762 
8763 
8765 
8776  bool emptyData();
8777 
8778 
8780 
8789  bool empty();
8790 
8791 
8792 
8793 private:
8794  bool emptyUnlocked();
8795 public:
8796 
8797 
8799 
8805  setupTable(hash desc, *hash opt);
8806 
8807 
8809 
8832  AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8833 
8834 
8836 
8864  list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8865 
8866 
8867 
8868 private:
8869  AbstractColumn addColumnUnlocked(string cname, hash opt, bool nullable = True, *reference lsql, bool do_exec = True, bool modify_table = True);
8870 public:
8871 
8872 
8873 
8874 private:
8875  addColumnToTableUnlocked(AbstractColumn c);
8876 public:
8877 
8878 
8880 
8904  AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8905 
8906 
8908 
8934  list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8935 
8936 
8938 
8955  AbstractColumn renameColumn(string old_name, string new_name, reference sql);
8956 
8957 
8959 
8977  string getRenameColumnSql(string old_name, string new_name, *hash opt);
8978 
8979 
8980 
8981 private:
8982  AbstractColumn renameColumnIntern(AbstractColumn c, string new_name);
8983 public:
8984 
8985 
8986 
8987 private:
8988  validateOptionsIntern(string err, hash ropt, reference opt);
8989 public:
8990 
8991 
8992 
8993 private:
8994  validateOptionsIntern(string err, hash ropt, reference opt, string tag);
8995 public:
8996 
8997 
8998 
8999 private:
9000  execSql(softlist lsql);
9001 public:
9002 
9003 
9005 
9025  AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql);
9026 
9027 
9029 
9051  string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
9052 
9053 
9054 
9055 private:
9056  setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
9057 public:
9058 
9059 
9060 
9061 private:
9062  AbstractPrimaryKey addPrimaryKeyUnlocked(string pkname, softlist cols, *hash opt, *reference sql);
9063 public:
9064 
9065 
9066 
9067 private:
9068  AbstractPrimaryKey addPrimaryKeyUnlockedIntern(string pkname, softlist cols, *hash opt, *reference sql);
9069 public:
9070 
9071 
9073 
9089  list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt);
9090 
9091 
9092 
9093 private:
9094  list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(string cname, *hash opt);
9095 public:
9096 
9097 
9099 
9118  list getDropPrimaryKeySql(*hash opt);
9119 
9120 
9122 
9140  AbstractPrimaryKey dropPrimaryKey(*reference lsql);
9141 
9142 
9144 
9165  AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql);
9166 
9167 
9169 
9189  string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
9190 
9191 
9192 
9193 private:
9194  AbstractUniqueConstraint addUniqueConstraintUnlocked(string cname, softlist cols, *hash opt, *reference sql);
9195 public:
9196 
9197 
9198 
9199 private:
9200  AbstractUniqueConstraint addUniqueConstraintUnlockedIntern(string cname, softlist cols, *hash opt, *reference sql);
9201 public:
9202 
9203 
9205 
9226  AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql);
9227 
9228 
9230 
9251  string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
9252 
9253 
9254 
9255 private:
9256  AbstractIndex addIndexUnlocked(string iname, bool unique, softlist cols, *hash opt, *reference sql);
9257 public:
9258 
9259 
9260 
9261 private:
9262  AbstractIndex addIndexUnlockedIntern(string iname, bool unique, softlist cols, *hash opt, *reference sql);
9263 public:
9264 
9265 
9267 
9279  AbstractIndex renameIndex(string old_name, string new_name, reference sql);
9280 
9281 
9283 
9301  AbstractIndex dropIndex(string iname, *reference sql);
9302 
9303 
9305 
9324  string getDropIndexSql(string iname, *hash opt);
9325 
9326 
9328 
9350  AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
9351 
9352 
9354 
9376  string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
9377 
9378 
9379  private Columns getReferencedTableColumnsUnlocked(string table, *Tables cache, string err = "FOREIGN-CONSTRAINT-ERROR");
9380 
9381 
9382 
9383 private:
9384  AbstractForeignConstraint addForeignConstraintUnlocked(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
9385 public:
9386 
9387 
9388 
9389 private:
9390  AbstractForeignConstraint addForeignConstraintUnlockedIntern(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
9391 public:
9392 
9393 
9395 
9413  AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql);
9414 
9415 
9417 
9432  AbstractForeignConstraint removeForeignConstraint(string cname);
9433 
9434 
9436 
9456  AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql);
9457 
9458 
9460 
9482  string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
9483 
9484 
9485 
9486 private:
9487  AbstractCheckConstraint addCheckConstraintUnlocked(string cname, string src, *hash opt, *reference sql);
9488 public:
9489 
9490 
9491 
9492 private:
9493  AbstractCheckConstraint addCheckConstraintUnlockedIntern(string cname, string src, *hash opt, *reference sql);
9494 public:
9495 
9496 
9498 
9510  AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
9511 
9512 
9514 
9533  string getDropConstraintSql(string cname, *hash opt);
9534 
9535 
9537 
9556  *string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref);
9557 
9558 
9559 
9560 private:
9561  AbstractConstraint findDropConstraintUnlocked(string cname, reference rmv);
9562 public:
9563 
9564 
9566 
9584  AbstractConstraint dropConstraint(string cname, *reference sql);
9585 
9586 
9588 
9608  AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
9609 
9610 
9612 
9634  list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
9635 
9636 
9637 
9638 private:
9639  AbstractTrigger addTriggerUnlocked(string tname, string src, *hash opt, *reference lsql);
9640 public:
9641 
9642 
9643 
9644 private:
9645  AbstractTrigger addTriggerUnlockedIntern(string tname, string src, *hash opt, *reference lsql);
9646 public:
9647 
9648 
9650 
9668  AbstractTrigger dropTrigger(string tname, *reference sql);
9669 
9670 
9672 
9691  list getDropTriggerSql(string tname, *hash opt);
9692 
9693 
9694 
9695 private:
9696  getAllConstraintsUnlocked(*hash opt);
9697 public:
9698 
9699 
9700 
9701 private:
9702  checkUniqueConstraintName(string err, string cname);
9703 public:
9704 
9705 
9706 
9707 private:
9708  checkUniqueConstraintNameValidateOptions(string err, string cname, hash ropt, reference opt);
9709 public:
9710 
9711 
9713 
9714 private:
9715  validateColumnOptions(string cname, reference opt, bool nullable);
9716 public:
9717 
9718 
9720 
9738  AbstractColumn dropColumn(string cname, *reference lsql);
9739 
9740 
9742 
9761  list getDropColumnSql(string cname, *hash opt);
9762 
9763 
9765 
9775  insert(hash row, *reference sql);
9776 
9777 
9779 
9789  insertNoCommit(hash row, *reference sql);
9790 
9791 
9792 
9793 private:
9794  insertNoCommitIntern(hash row, *reference sql, *hash opt);
9795 public:
9796 
9797 
9799 
9809  insert(hash row, *hash opt);
9810 
9811 
9813 
9823  insertNoCommit(hash row, *hash opt);
9824 
9825 
9827 
9845  int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql);
9846 
9847 
9849 
9867  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql);
9868 
9869 
9870 
9871 private:
9872  int insertFromSelectNoCommitIntern(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt);
9873 public:
9874 
9875 
9877 
9895  int insertFromSelect(list cols, AbstractTable source, *hash sh, *hash opt);
9896 
9897 
9899 
9917  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *hash opt);
9918 
9919 
9921 
9939  int insertFromIterator(Qore::AbstractIterator i, *hash opt);
9940 
9941 
9943 
9961  int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt);
9962 
9963 
9964 
9965 private:
9966  int insertFromIteratorNoCommitIntern(Qore::AbstractIterator i, *hash opt);
9967 public:
9968 
9969 
9971 
9986  int upsert(hash row, int upsert_strategy = UpsertAuto);
9987 
9988 
9990 
10005  int upsertNoCommit(hash row, int upsert_strategy = UpsertAuto);
10006 
10007 
10009 
10029  code getUpsertClosure(hash example_row, int upsert_strategy = UpsertAuto);
10030 
10031 
10033 
10053  code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = UpsertAuto);
10054 
10055 
10057 
10089  *hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10090 
10091 
10093 
10125  *hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10126 
10127 
10128 
10129 private:
10130  *hash upsertFromIteratorNoCommitIntern(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10131 public:
10132 
10133 
10134 
10135 private:
10136  *hash doDeleteOthersIntern(hash pkh, *hash opt);
10137 public:
10138 
10139 
10141 
10179  *hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10180 
10181 
10183 
10223  *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10224 
10225 
10227 
10265  *hash upsertFromSelect(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10266 
10267 
10269 
10309  *hash upsertFromSelectNoCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10310 
10311 
10313 
10324  softint rowCount();
10325 
10326 
10328 
10345  Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql);
10346 
10347 
10348 
10349 private:
10350  Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference sql, *hash opt);
10351 public:
10352 
10353 
10355 
10372  Qore::SQL::SQLStatement getRowIterator(*hash sh, *hash opt);
10373 
10374 
10376 
10392  *hash selectRow(*hash sh, *reference sql);
10393 
10394 
10396 
10411  *list selectRows(*hash sh, *reference sql);
10412 
10413 
10415 
10430  *hash select(*hash sh, *reference sql);
10431 
10432 
10434 
10450  *hash selectRow(*hash sh, *hash opt);
10451 
10452 
10454 
10469  *list selectRows(*hash sh, *hash opt);
10470 
10471 
10473 
10488  *hash select(*hash sh, *hash opt);
10489 
10490 
10492 
10510  string getSelectSql(*hash sh, *reference args);
10511 
10512 
10513  *AbstractUniqueConstraint matchAnyUnique(list cols);
10514 
10515 
10516  string getSelectSqlIntern(*hash qh, reference args);
10517 
10518 
10519  string getSelectSqlUnlocked(*hash qh, reference args);
10520 
10521 
10522  string getSelectSqlUnlockedIntern(*hash qh, string from, reference args, *hash ch);
10523 
10524 
10525 
10526 private:
10527  string getSelectSqlName(*hash qh);
10528 public:
10529 
10530 
10531 
10532 private:
10533  string getColumnExpressionIntern(any cvc, *hash jch, bool join, *hash ch);
10534 public:
10535 
10536 
10537 
10538 private:
10539  string doColumnOperatorIntern(hash cvc, *hash jch, bool join, *hash ch);
10540 public:
10541 
10542 
10543 
10544 private:
10545  string doColumnOperatorIntern(any cop, any arg, *string cve, hash cm, *hash jch, bool join, *hash ch);
10546 public:
10547 
10548 
10549 
10550 private:
10551  string getColumnNameIntern(string cv, *hash jch, bool join, *hash ch);
10552 public:
10553 
10554 
10555 
10556 private:
10557  getSelectWhereSqlUnlocked(reference sql, reference args, *hash qh, *hash jch, bool join = False, *hash ch);
10558 public:
10559 
10560 
10561 
10562 private:
10563  *string getWhereClause(*hash cond, reference args, *string cprefix, *hash jch, bool join = False);
10564 public:
10565 
10566 
10567 
10568 private:
10569  *string getWhereClause(list cond, reference args, *string cprefix, *hash jch, bool join = False);
10570 public:
10571 
10572 
10573 
10574 private:
10575  *string getWhereClauseUnlocked(list cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch);
10576 public:
10577 
10578 
10579 
10580 private:
10581  *string getWhereClauseUnlocked(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch);
10582 public:
10583 
10584 
10585 
10586 private:
10587  *list getWhereClauseIntern(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash ch);
10588 public:
10589 
10590 
10591 
10592 private:
10593  string doWhereExpressionIntern(string cn, any we, reference args, *hash jch, bool join = False, *hash ch);
10594 public:
10595 
10596 
10597 
10598 private:
10599  list getOrderByListUnlocked(*hash qh, *hash jch, *hash ch);
10600 public:
10601 
10602 
10603 
10604 private:
10605  doSelectOrderBySqlUnlocked(reference sql, reference args, *hash qh, *hash jch, *hash ch);
10606 public:
10607 
10608 
10610 
10624  int del(*hash cond, *reference sql);
10625 
10626 
10628 
10642  int delNoCommit(*hash cond, *reference sql);
10643 
10644 
10645 
10646 private:
10647  int delNoCommitIntern(*hash cond, *reference sql, *hash opt);
10648 public:
10649 
10650 
10652 
10668  int update(hash set, *hash cond, *reference sql);
10669 
10670 
10672 
10688  int updateNoCommit(hash set, *hash cond, *reference sql);
10689 
10690 
10691 
10692 private:
10693  int updateNoCommitIntern(hash set, *hash cond, *reference sql, *hash opt);
10694 public:
10695 
10696 
10698 
10712  int del(*hash cond, *hash opt);
10713 
10714 
10716 
10730  int delNoCommit(*hash cond, *hash opt);
10731 
10732 
10734 
10750  int update(hash set, *hash cond, *hash opt);
10751 
10752 
10754 
10770  int updateNoCommit(hash set, *hash cond, *hash opt);
10771 
10772 
10773 
10774 private:
10775  string getUpdateExpression(string col, hash uh);
10776 public:
10777 
10778 
10779 
10780 private:
10781  bool emptyDataUnlocked();
10782 public:
10783 
10784 
10785 
10786 private:
10787  code getUpsertClosureUnlocked(hash row, int upsert_strategy = UpsertAuto);
10788 public:
10789 
10790 
10791 
10792 private:
10793  code getUpsertInsertFirst(Columns cols, hash example_row);
10794 public:
10795 
10796 
10797 
10798 private:
10799  code getUpsertUpdateFirst(Columns cols, hash example_row);
10800 public:
10801 
10802 
10803 
10804 private:
10805  code getUpsertSelectFirst(Columns cols, hash example_row);
10806 public:
10807 
10808 
10809 
10810 private:
10811  Columns getUpsertColumns(reference csrc);
10812 public:
10813 
10814 
10815 
10816 private:
10817  string getUpsertSelectSql(hash row, Columns cols, reference updc);
10818 public:
10819 
10820 
10821 
10822 private:
10823  string getUpsertInsertSql(hash row);
10824 public:
10825 
10826 
10827 
10828 private:
10829  string getUpsertUpdateSql(hash row, Columns cols, reference updc);
10830 public:
10831 
10832 
10833 
10834 private:
10835  softbool tryUpdate(string sql, hash row, Columns cols, list updc);
10836 public:
10837 
10838 
10839 
10840 private:
10841  checkValue(string cname, string argname, reference val, string type);
10842 public:
10843 
10844 
10846 
10855  string getSqlFromList(list l);
10856 
10857 
10859 
10870  string getSqlValue(any v);
10871 
10872 
10874  string getName();
10875 
10876 
10878 
10885  cache(*hash opts);
10886 
10887 
10889 
10894  clear();
10895 
10896 
10898 
10905  Columns describe();
10906 
10907 
10909 
10917  AbstractPrimaryKey getPrimaryKey();
10918 
10919 
10921 
10930  *AbstractUniqueConstraint findUniqueConstraint(string name);
10931 
10932 
10933  *AbstractUniqueConstraint findUniqueConstraintUnlocked(string name);
10934 
10935 
10937 
10946  Indexes getIndexes();
10947 
10948 
10950  ForeignConstraints getForeignConstraints(*hash opt);
10951 
10952 
10954  Constraints getConstraints();
10955 
10956 
10958 
10967  Triggers getTriggers();
10968 
10969 
10971 
10989  string getRenameSql(string new_name, *hash opt);
10990 
10991 
10993 
11002  string getCreateSqlString(*hash opt);
11003 
11004 
11006 
11015  list getCreateSql(*hash opt);
11016 
11017 
11019 
11030  string getCreateTableSql(*hash opt);
11031 
11032 
11034  bool checkExistence();
11035 
11036 
11037 
11038 private:
11039  *hash getCheckOmissionOptions(*softlist ol, string err);
11040 public:
11041 
11042 
11044 
11059  list getAlignSql(AbstractTable t, *hash opt);
11060 
11061 
11062 
11063 private:
11064  list getAlignSqlUnlocked(AbstractTable t, *hash opt);
11065 public:
11066 
11067 
11068 
11069 private:
11070  renameIndexUnlocked(AbstractIndex ix, string new_name);
11071 public:
11072 
11073 
11075 
11088  string getAlignSqlString(AbstractTable t, *hash opt);
11089 
11090 
11092 
11104  *list getCreateIndexesSql(*hash opt, bool cache = True);
11105 
11106 
11108 
11120  *string getCreatePrimaryKeySql(*hash opt, bool cache = True);
11121 
11122 
11124 
11136  *list getCreateForeignConstraintsSql(*hash opt, bool cache = True);
11137 
11138 
11140 
11154  *list getCreateConstraintsSql(*hash opt, bool cache = True);
11155 
11156 
11158 
11170  *list getCreateMiscSql(*hash opt, bool cache = True);
11171 
11172 
11174 
11188  *list getCreateTriggersSql(*hash opt, bool cache = True);
11189 
11190 
11192 
11199  *hash find(any id);
11200 
11201 
11203 
11214  *list find(list ids);
11215 
11216 
11217 
11218 private:
11219  string getPrimaryKeyColumn();
11220 public:
11221 
11222 
11224 
11237  *hash find(hash row);
11238 
11239 
11241 
11254  *hash findSingle(*hash cond);
11255 
11256 
11258 
11271  *list findAll(*hash cond);
11272 
11273 
11275  string getSqlName();
11276 
11277 
11279 
11282 private:
11283  hash getTableOptions();
11284 public:
11285 
11286 
11288 
11291 private:
11292  hash getForeignConstraintOptions();
11293 public:
11294 
11295 
11297 
11300 private:
11301  hash getConstraintOptions();
11302 public:
11303 
11304 
11306 
11309 private:
11310  hash getCacheOptions();
11311 public:
11312 
11313 
11315 
11318 private:
11319  hash getTableCreationOptions();
11320 public:
11321 
11322 
11324 
11327 private:
11328  hash getAlignTableOptions();
11329 public:
11330 
11331 
11333 
11336 private:
11337  hash getTableDescriptionHashOptions();
11338 public:
11339 
11340 
11342 
11345 private:
11346  hash getColumnOptions();
11347 public:
11348 
11349 
11351 
11354 private:
11355  hash getColumnDescOptions();
11356 public:
11357 
11358 
11360 
11363 private:
11364  hash getTableColumnDescOptions();
11365 public:
11366 
11367 
11369 
11372 private:
11373  hash getIndexOptions();
11374 public:
11375 
11376 
11378 
11381 private:
11382  hash getTriggerOptions();
11383 public:
11384 
11385 
11387 
11390 private:
11391  hash getSelectOptions();
11392 public:
11393 
11394 
11396 
11399 private:
11400  hash getUpsertOptions();
11401 public:
11402 
11403 
11405 
11408 private:
11409  hash getInsertOptions();
11410 public:
11411 
11412 
11414 
11417 private:
11418  hash getSqlDataCallbackOptions();
11419 public:
11420 
11421 
11423 
11426 private:
11427  hash getWhereOperatorMap();
11428 public:
11429 
11430 
11432 
11435 private:
11436  hash getColumnOperatorMap();
11437 public:
11438 
11439 
11441 
11444 private:
11445  hash getUpdateOperatorMap();
11446 public:
11447 
11448 
11449 
11450 private:
11451  string getCreateTableSqlUnlocked(*hash opt);
11452 public:
11453 
11454 
11455 
11456 private:
11457  *list getCreateIndexesSqlUnlocked(*hash opt, bool cache = True);
11458 public:
11459 
11460 
11461 
11462 private:
11463  *string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
11464 public:
11465 
11466 
11467 
11468 private:
11469  *list getCreateConstraintsSqlUnlocked(*hash opt, bool cache = True);
11470 public:
11471 
11472 
11473 
11474 private:
11475  *list getCreateForeignConstraintsSqlUnlocked(*hash opt, bool cache = True);
11476 public:
11477 
11478 
11479 
11480 private:
11481  *list getCreateMiscSqlUnlocked(*hash opt, bool cache = True);
11482 public:
11483 
11484 
11485 
11486 private:
11487  *list getCreateTriggersSqlUnlocked(*hash opt, bool cache = True);
11488 public:
11489 
11490 
11491 
11492 private:
11493  list getCreateSqlUnlocked(*hash opt, bool cache = True);
11494 public:
11495 
11496 
11497 
11498 private:
11499  cacheUnlocked(*hash opt);
11500 public:
11501 
11502 
11503 
11504 private:
11505  any execData(*hash opt, string sql, *list args);
11506 public:
11507 
11508 
11509 
11510 private:
11511  execData(SQLStatement stmt, *hash opt, *list args);
11512 public:
11513 
11514 
11515  static AbstractTable getTable(AbstractDatasource nds, string nname, *hash opts);
11516 
11517  static AbstractTable getTable(string dsstr, string nname, *hash opts);
11518 
11519  static AbstractTable getTable(hash dsh, string nname, *hash opts);
11520 
11521 
11522 private:
11523  getColumnsUnlocked();
11524 public:
11525 
11526 
11527 
11528 private:
11529  getPrimaryKeyUnlocked();
11530 public:
11531 
11532 
11533  // also loads primary key and constraints (for unique constraints)
11534 
11535 private:
11536  getIndexesUnlocked();
11537 public:
11538 
11539 
11540 
11541 private:
11542  getForeignConstraintsUnlocked(*hash opt);
11543 public:
11544 
11545 
11546 
11547 private:
11548  addSourceConstraint(string table_name, AbstractForeignConstraint fk);
11549 public:
11550 
11551 
11552 
11553 private:
11554  getConstraintsUnlocked();
11555 public:
11556 
11557 
11558 
11559 private:
11560  getTriggersUnlocked();
11561 public:
11562 
11563 
11564 
11565 private:
11566  softlist getDropSqlImpl();
11567 public:
11568 
11569 
11570 
11571 private:
11572  string getTruncateSqlImpl();
11573 public:
11574 
11575 
11577 
11578 private:
11579  any tryExecArgsImpl(string sql, *softlist args);
11580 public:
11581 
11582 
11584 
11585 private:
11586  any tryExecRawImpl(string sql);
11587 public:
11588 
11589 
11591 
11592 private:
11593  clearImpl();
11594 public:
11595 
11596 
11597 
11598 private:
11599  preSetupTableImpl(reference desc, *hash opt);
11600 public:
11601 
11602 
11603 
11604 private:
11605  abstract bool emptyImpl();
11606 public:
11607 
11609 
11610 private:
11611  abstract *string getSqlValueImpl(any v);
11612 public:
11613 
11615 
11619 private:
11620  abstract bool checkExistenceImpl();
11621 public:
11622 
11624 
11625 private:
11626  abstract bool supportsTablespacesImpl();
11627 public:
11628 
11630 
11631 private:
11632  abstract bool constraintsLinkedToIndexesImpl();
11633 public:
11634 
11636 
11637 private:
11638  abstract bool uniqueIndexCreatesConstraintImpl();
11639 public:
11640 
11641 
11642 private:
11643  abstract setupTableImpl(hash desc, *hash opt);
11644 public:
11645 
11646 
11647 private:
11648  abstract Columns describeImpl();
11649 public:
11650 
11651 private:
11652  abstract AbstractPrimaryKey getPrimaryKeyImpl();
11653 public:
11654 
11655 private:
11656  abstract Indexes getIndexesImpl();
11657 public:
11658 
11659 private:
11660  abstract ForeignConstraints getForeignConstraintsImpl(*hash opt);
11661 public:
11662 
11663 private:
11664  abstract Constraints getConstraintsImpl();
11665 public:
11666 
11667 private:
11668  abstract Triggers getTriggersImpl();
11669 public:
11670 
11671 
11672 private:
11673  abstract string getCreateTableSqlImpl(*hash opt);
11674 public:
11675 
11676 private:
11677  abstract *list getCreateMiscSqlImpl(*hash opt, bool cache);
11678 public:
11679 
11680 private:
11681  abstract string getCreateSqlImpl(list l);
11682 public:
11683 
11684 private:
11685  abstract string getRenameSqlImpl(string new_name);
11686 public:
11687 
11688 private:
11689  abstract *list getAlignSqlImpl(AbstractTable t, *hash opt);
11690 public:
11691 
11692 
11693 private:
11694  abstract AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
11695 public:
11696 
11697 private:
11698  abstract AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
11699 public:
11700 
11701 private:
11702  abstract AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
11703 public:
11704 
11705 private:
11706  abstract AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
11707 public:
11708 
11709 private:
11710  abstract AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
11711 public:
11712 
11713 private:
11714  abstract AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
11715 public:
11716 
11717 
11718 private:
11719  abstract AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
11720 public:
11721 
11723 
11724 private:
11725  abstract bool tryInsertImpl(string sql, hash row);
11726 public:
11727 
11729 
11730 private:
11731  abstract hash getQoreTypeMapImpl();
11732 public:
11733 
11735 
11736 private:
11737  abstract hash getTypeMapImpl();
11738 public:
11739 
11741 
11742 private:
11743  abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch);
11744 public:
11745 
11747 
11748 private:
11749  abstract doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh);
11750 public:
11751 
11753 
11754 private:
11755  abstract copyImpl(AbstractTable old);
11756 public:
11757  };
11758 
11759 /*
11760  public class Sqlite3Table inherits AbstractTable {
11761 
11762  public {
11763  const Sqlite3TypeMap = (
11764  "INTEGER": ("qore": "integer",),
11765  "NUMERIC": ("qore": "number",),
11766  "TEXT": ("qore": "string",),
11767  "BLOB": ("qore": "binary",),
11768  "NONE": ("qore": "any",),
11769  "REAL": ("qore": "float",),
11770  );
11771 
11772  const QoreTypeMap = (
11773  "integer": "INTEGER",
11774  "float": "NUMBER",
11775  "number": "NUMBER",
11776  "string": "VARCHAR2",
11777  #"date": "TIMESTAMP",
11778  "binary": "BLOB",
11779  );
11780  }
11781 
11782  constructor(AbstractDatasource nds, string nname, *hash opts) : AbstractTable(nds, nname, opts) {
11783  }
11784 
11785  private hash describeImpl() {
11786  hash rv;
11787 
11788  # NOTE: sqlite3's pragmas cannot use %v binding
11789 
11790  # table info - PK is part of the table description
11791  hash tableInfo = ds.select("pragma table_info(%s)", name);
11792  context(tableInfo) {
11793  rv.columns{%name} = (
11794  "native_type" : %type,
11795  "qore_type" : Sqlite3TypeMap{%type}.qore,
11796  "size" : NOTHING,
11797  "nullable" : %notnull == 1 ? NOTHING : "YES",
11798  );
11799  if (%pk)
11800  rv.primary_key{%name} = True;
11801  }
11802 
11803  # get index description
11804  hash indexes = ds.select("pragma index_list(%s)", name);
11805  context(indexes) {
11806  rv.indexes{%name}.unique = %unique == 0 ? False : True;
11807  hash indexColumns = ds.select("pragma index_info(%s)", %name);
11808  string columnName = %name;
11809  context (indexColumns) {
11810  rv.indexes{columnName}.columns{%name} = True;
11811  }
11812  }
11813 
11814  # TODO/FIXME: FKs
11815 
11816  return rv;
11817  }
11818  }
11819 */
11820 }
11821 
nothing rename(string old_path, string new_path)
hash uop_lower(*hash nest)
returns a hash for the &quot;lower&quot; operator with the given argument; returns a column value in lower case...
const Hash
const String
hash uop_append(string arg, *hash nest)
returns a hash for the &quot;append&quot; or concatenate operator with the given argument
string sprintf(string fmt,...)
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:8203
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:3390
hash op_between(any l, any r)
returns a hash for the &quot;between&quot; operator with the given arguments, neither of which can be NULL or N...
date now_us()
string printf(string fmt,...)
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:3798
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:4088
hash op_gt(any arg)
returns a hash for the &quot;&gt;&quot; operator with the given argument for use in where clauses when comparing c...
const True
base class for sequences
Definition: SqlUtil.qm.dox.h:4193
nothing flush()
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:8378
number number(softnumber n)
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:8504
const List
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:4834
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:8422
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:4398
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:4157
hash op_like(string str)
returns a hash for the &quot;like&quot; operator with the given argument for use in where clauses ...
const False
const NothingType
hash op_lt(any arg)
returns a hash for the &quot;&lt;&quot; operator with the given argument for use in where clauses when comparing c...
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:3977
list list(...)
string name
the table&#39;s name
Definition: SqlUtil.qm.dox.h:8496
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:4350
int index(softstring str, softstring substr, softint pos=0)
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:8502
const Boolean
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:3756
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:8500
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:8508
hash op_ge(any arg)
returns a hash for the &quot;&gt;=&quot; operator with the given argument for use in where clauses when comparing ...
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:8498
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
string type(any arg)
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:4839
base class for functions
Definition: SqlUtil.qm.dox.h:4271
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:8506
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:4845
*hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
const Int
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:3578
the base class for triggers
Definition: SqlUtil.qm.dox.h:4332
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:4841
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8455
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8452
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:4403
the base class for column information
Definition: SqlUtil.qm.dox.h:3625
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:5775
const UpsertSelectFirst
Upsert option: select first, if the row is unchanged, do nothing, if it doesn&#39;t exist, insert, otherwise update.
Definition: SqlUtil.qm.dox.h:8431
const Closure
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:5780
hash hash(object obj)
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:4887
represents a primary key
Definition: SqlUtil.qm.dox.h:4077
string join(string str,...)
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:4007
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:3912
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:3870