Qore SqlUtil Module Reference  1.1
 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.9 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-12-30 v1.1: David Nichols <david@qore.org>
38  + see release notes below or in doxygen docs
39 
40  * 2013-10-04 v1.0: David Nichols <david@qore.org>
41  + the initial version of the SqlUtil module
42 */
43  ...
291  @endcode
292  @warning Oracle: using different comments in the same SQL can lead to new optimizer statement hard parsing.
293 
294  @anchor select_option_hint
295  @par Select Option "hint"
296  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).
297 
298  <b>Hint Example:</b>
299  @code
300 $table.selectRows( ("hint" : "full(t1)") );
301  @endcode
302  will produce select statement like this:
303  @code
304 select /*+ full(a) */ ...
305  @endcode
306  The string is taken as is and it's up to user to handle correct aliases in join functions etc.
307  @note Hints are platform dependent. Curently only Oracle and some versions of PostgreSQL hints are supported in Sqlutil module.
308  @warning Use hints only when you know what you are doing.
309 
310  @anchor select_option_columns
311  @par Select Option "columns"
312  <b>Columns Example:</b>
313  @code
314 my list $columns = ("id", "name", "started", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"));
315 my *list $rows = $table.selectRows(("columns": $columns, "where": ("type": "user")));
316  @endcode
317  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
318  This option takes a list, each element of the list can be one of the following.\n\n
319  <b>A Simple String Giving a Column Name</b>\n
320  ex: \c "name"
321  @code
322 my *list $rows = $table.selectRows(("columns": ("id", "name", "started")));
323  @endcode \n
324  <b>A String in Dot Notation</b>\n
325  This format is for use with @ref select_option_join "joins"; ex: \c "q.name"
326  @code
327 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner($table2, "t2", ("id": "altid"))));
328  @endcode \n
329  <b>A Column Operation Specified by a Column Operator Function</b>\n
330  ex: <tt>cop_as("column_name", "column_alias")</tt> \n
331  See @ref sql_cop_funcs "column operator function" for more information on column operator functions
332  @code
333 my *list $rows = $table.selectRows(("columns": ("id", cop_as("warnings", "warning_count"), cop_as("errors", "error_count"))));
334  @endcode
335  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
336  <b>The Value \c "*", Meaning All Columns</b>\n
337  ex: \c "*"
338  @code
339 my *list $rows = $table.selectRows(("columns": "*"));
340  @endcode
341  This is the default if no \c "columns" key is included in the @ref select_option_hash "select option hash" \n\n
342  <b>An \c "*" in Dot Notation</b>\n
343  ex: \c "q.*"
344  @code
345 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.*"), "join": join_inner($table2, "t2", ("id": "altid"))));
346  @endcode
347 
348  @anchor select_option_where
349  @par Select Option "where"
350  <b>Where Example:</b>
351  @code
352 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
353  @endcode
354  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.
355 
356  @anchor select_option_orderby
357  @par Select Option "orderby"
358  <b>Orderby Example:</b>
359  @code
360 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date"));
361  @endcode
362  This option is a list of the following values:
363  - a simple string giving a column name; ex: \c "name"
364  - 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"
365  @note
366  - By using the @ref select_option_offset "offset option" the results will be automatically ordered according to the primary key of the table
367 
368  @anchor select_option_desc
369  @par Select Option "desc"
370  <b>Desc Example:</b>
371  @code
372 my *list $rows = $table.selectRows(("where": ("account_type": "CUSTOMER"), "orderby": "created_date", "desc": True));
373  @endcode
374  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
375  Otherwise, ordered results are returned in ascending order by default.
376 
377  @anchor select_option_limit
378  @par Select Option "limit"
379  <b>Limit Example:</b>
380  @code
381 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
382  @endcode
383  This option will limit the number of rows returned.
384  @note
385  - This option is required if the @ref select_option_offset "offset option" is non-zero
386  - 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
387 
388  @anchor select_option_offset
389  @par Select Option "offset"
390  <b>Offset Example:</b>
391  @code
392 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
393  @endcode
394  This option specifies the row number offset for the rows returned where the first row is at offset zero.
395  @note
396  - 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.
397  - Additionally, this option requires the presence of the @ref select_option_limit "limit option", or an exception will be thrown.
398  @see @ref sql_paging
399 
400  @anchor select_option_join
401  @par Select Option "join"
402  <b>Join Example:</b>
403  @code
404 my *list $rows = $table.selectRows(("columns": ("name", "version", "id", cop_as("st.value", "source"), cop_as("st.value", "offset")),
405  "join": join_left($function_instance_tags, "st", NOTHING, ("st.tag": "_source"))
406  + join_left($function_instance_tags, "lt", NOTHING, ("st.tag": "_offset"))));
407  @endcode
408  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).
409  @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
410 
411  @see @ref joins for more examples
412 
413  @anchor select_option_groupby
414  @par Select Option "groupby"
415  <b>Groupby Example:</b>
416  @code
417 my *list $rows = $table.selectRows(("columns": (cop_as(cop_max("service_type"), "type"), cop_count()), "groupby": "service_type"));
418  @endcode
419  The \c "groupby" option allows for aggregate SQL column operator functions to be used (ex: @ref cop_max(), cop_min()) in select statements.
420  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"
421  key are strings giving column names, optionally in dot notation.
422 
423  @anchor select_option_having
424  @par Select Option "having"
425  <b>Having Example:</b>
426  @code
427 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)))));
428  @endcode
429  The \c "having" option allows for query results with aggregate SQL column operator functions to be filtered by user-defined criteria.
430  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.
431 
432  @anchor select_option_superquery
433  @par Select Option "superquery"
434  <b>Superquery Example:</b>
435  @code
436 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"))));
437  @endcode
438  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
439  The above example results in an SQL command equivalent to the following:
440  @code
441 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");
442  @endcode
443  @note that MySQL does not support SQL windowing functions so the above example would fail on MySQL.
444 
445  @subsection sql_paging Select With Paging
446 
447  There is support for paging query results in the following methods:
448  - @ref SqlUtil::Table::getRowIterator()
449  - @ref SqlUtil::Table::getSelectSql()
450  - @ref SqlUtil::Table::select()
451  - @ref SqlUtil::Table::selectRows()
452 
453  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
454 
455  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.
456 
457  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.
458 
459  @par Example:
460  Select 100 rows starting at row 200 (the table's primary key will be used for the \c "orderby" option by default): \n
461  @code
462 my *list $rows = $table.selectRows(("where": ("type": "user"), "limit": 100, "offset": 200));
463  @endcode
464  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:
465  @code
466 $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));
467  @endcode
468  And for PostgreSQL:
469  @code
470 $ds.vselectRows("select * from public.table where type = %v order by type limit %v offset %v", ("user", 100, 200));
471  @endcode
472 
473  @subsection check_matching_rows Check For At Least One Matching Row
474 
475  Use the @ref SqlUtil::Table::findSingle() method to find at least one matching row:
476  @code
477 my *hash $h = $table.findSingle(("account_type": "CUSTOMER"));
478 if ($h)
479  printf("found 1 customer row: %y\n", $l[0]);
480  @endcode
481 
482  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):
483  @code
484 my *hash $h = $table.selectRow(("where": ("account_type": "CUSTOMER"), "limit": 1));
485 if ($h)
486  printf("found 1 customer row: %y\n", $l[0]);
487  @endcode
488 
489  @section inserting_data Inserting Data into the Database
490 
491  The following methods can be used to insert data into the database:
492  - @ref SqlUtil::Table::insert(): inserts a single row into a table and commits the transaction
493  - @ref SqlUtil::Table::insertNoCommit(): inserts a single row into a table without committing the transaction
494  - @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
495  - @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
496 
497  @see @ref sql_upsert for information about upserting or merging data
498 
499  @subsection inserting_data_explicitly Inserting Data Explicitly
500 
501  @par Example:
502  @code
503 $table.insert(("id": $id, "name": $name, "created": now_us()));
504  @endcode
505 
506  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.
507 
508  @subsection inserting_data_from_select Inserting Data From a Select Statement
509 
510  @par Example:
511  @code
512 my int $rows = $table.insertFromSelect(("id", "name", "created"), $source_table, (("columns": ("cid", "fullname", "created"), "where": ("type": "CUSTOMER"))));
513  @endcode
514 
515  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.
516 
517  The example above would generate a %Qore SQL command like the following:
518  @code
519 return $ds.vexec("insert into schema.table (id,name,created) select cid,fullname,created from schema.source_table where type = %v", ("CUSTOMER"));
520  @endcode
521 
522  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.
523 
524  @subsection inserting_data_from_iterator Inserting Data from an Iterator Source
525 
526  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:
527 
528  @par Example:
529  @code
530 # get the rows to be inserted
531 my list $l = get_table_rows();
532 # insert the data and commit after every 5000 rows
533 $table.insertFromIterator($l.iterator(), ("commit_block": 5000));
534  @endcode
535 
536  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".
537 
538  @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
539 
540  @section updating_data Updating Data
541 
542  The following methods can be used to update data:
543  - @ref SqlUtil::Table::update(): updates a single row and commits the transaction
544  - @ref SqlUtil::Table::updateNoCommit(): updates a single row and does not commit the transaction
545 
546  @par Example:
547  @code
548 my int $rows_updated = t.update(("permission_type": uop_append("-migrated", uop_lower())));
549  @endcode
550 
551  The example above generates a %Qore SQL command like the following on Oracle and PostgreSQL for example:
552  @code
553 return $ds.vexec("update schema.table set permission_type = lower(permission_type) || '-migrated');
554  @endcode
555  And the following on MySQL:
556  @code
557 return $ds.vexec("update schema.table set permission_type = concat(lower(permission_type), '-migrated'));
558  @endcode
559 
560  @section deleting_data Deleting Data
561 
562  The following methods can be used to dekete data:
563  - @ref SqlUtil::Table::del(): updates the table based on a @ref where_clauses "where clause" and commits the transaction
564  - @ref SqlUtil::Table::delNoCommit(): updates the table based on a @ref where_clauses "where clause" and does not commit the transaction
565  - @ref SqlUtil::Table::truncate(): truncates the table and commits the transaction releasing the transaction lock on the underlying datasource object
566  - @ref SqlUtil::Table::truncateNoCommit(): truncates the table and does not commit the transaction
567 
568  @par Example:
569  @code
570 my int $dcnt = $table.del(("record_type": "OLD-CUSTOMER"));
571  @endcode
572 
573  The above example would generate a %Qore SQL command like the following:
574  @code
575 return $ds.vexec("delete from schema.table where record_type = %v", ("OLD-CUSTOMER"));
576  @endcode
577 
578  The @ref SqlUtil::Table::del() and @ref SqlUtil::Table::delNoCommit() methods can be used to delete data from the database.
579 
580  See @ref where_clauses for information about specifying the criteria for the rows to be deleted.
581 
582  @section joins Joining Tables
583 
584  Joining tables is made by providing a join specification to the @ref select_option_join "join select option" in
585  a @ref select_option_hash "select option hash" as in the following example:
586  @code
587 my *list $rows = $table.selectRows(("columns": ("table.id", "t2.customer_name"), "join": join_inner($table2, "t2", ("id": "altid"))));
588  @endcode
589  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt>.
590 
591  Joins on multiple tables are performed by combining the results of @ref sql_op_funcs "join functions" with the @ref plus_operator "+ operator"
592  as follows:
593  @code
594 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner($table3, "t3")));
595  @endcode
596  In the above example, \a table is joined with \a table2 on <tt>table.id = table2.altid</tt> and with \a table3 on an
597  automatically detected primary key to foreign key relationship between the two tables.
598 
599  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
600  argument to the @ref sql_op_funcs "join function" as in the following example:
601  @code
602 my *list $rows = $table.selectRows(("join": join_inner($table2, "t2", ("id": "altid")) + join_inner("t2", $table3, "t3")));
603  @endcode
604  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
605  with \a table3 (aliased as \c t3) on an automatically detected primary key to foreign key relationship between the two tables.
606 
607  @see @ref select_option_join "join select option"
608 
609  @section where_clauses Where Clauses
610 
611  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:
612  - @ref SqlUtil::Table::del()
613  - @ref SqlUtil::Table::delNoCommit()
614  - @ref SqlUtil::Table::findAll()
615  - @ref SqlUtil::Table::findSingle()
616  - @ref SqlUtil::Table::getRowIterator()
617  - @ref SqlUtil::Table::getSelectSql()
618  - @ref SqlUtil::Table::insertFromSelect()
619  - @ref SqlUtil::Table::insertFromSelectNoCommit()
620  - @ref SqlUtil::Table::select()
621  - @ref SqlUtil::Table::selectRow()
622  - @ref SqlUtil::Table::selectRows()
623  - @ref SqlUtil::Table::update()
624  - @ref SqlUtil::Table::updateNoCommit()
625  - @ref SqlUtil::Table::upsertFromSelect()
626  - @ref SqlUtil::Table::upsertFromSelectNoCommit()
627 
628  @note the above list also applies to the corresponding @ref SqlUtil::AbstractTable methods
629 
630  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".
631 
632  The where condition hash has the following format:
633  - each key gives a column name or a table/alias with column name in dot notation
634  - 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
635 
636  @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
637 
638  See @ref sql_op_funcs for a list of operator functions.
639 
640  @par Where Hash Example:
641  @code
642 my hash $w = (
643  "name": "Smith",
644  "account_type": op_like("%CUSTOMER%"),
645  "id": op_ge(500),
646 );
647  @endcode \n
648  The preceding example results in a where clause equivalent to: \c "name = 'Smith' and type like '%CUSTOMER%' and id >= 500", except
649  that bind by value is used, so, if used in a context like the following:
650  @code
651 my Table $t($ds, "table");
652 my *hash $qh = $t.select(("where": $w));
653  @endcode \n
654  the complete query would look instead as follows:
655  @code
656 $ds.vselect("select * from table where name = %v and account_type like %v and id >= %v", ("Smith", "%CUSTOMER%", 500));
657  @endcode
658 
659  @anchor where_list
660  @par Where List Example:
661  @code
662 my hash $w1 = (
663  "name": "Smith",
664  "account_type": op_like("%CUSTOMER%"),
665  "id": op_ge(500),
666 );
667 my hash $w2 = (
668  "name": "Jones",
669  "account_type": op_like("%VENDOR%"),
670  "id": op_ge(2500),
671 );
672 my Table $t($ds, "table");
673 my *hash $qh = $t.select(("where": ($w1, $w2)));
674  @endcode \n
675  the complete query would look instead as follows:
676  @code
677 $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));
678  @endcode
679 
680  @par Code Examples:
681  Find a single row in the table where the \c "permission_type" column is a value between \c "US" and \c "UX":\n
682  @code
683 my *hash $row = $table.findSingle(("permission_type": op_between("US", "UX")));
684  @endcode
685  resulting in an internal SQL command that looks as follows (depending on the database):
686  @code
687 my *hash $row = $ds.vselectRow("select * from table where permission_type between %v and %v limit %v", ("US", "UX", 1));
688  @endcode \n
689  Delete all rows in the table where the \c "name" column is like \c "%Smith%":\n
690  @code
691 my int $row_count = $table.del(("name": op_like("%Smith%")));
692  @endcode
693  resulting in an internal SQL command that looks as follows:
694  @code
695 $ds.vexec("delete from table where name like %v", ("%Smith%"));
696  @endcode \n
697  Find all rows where \c "id" is greater than \c 100 and \c "created" is after \c 2013-03-01:\n
698  @code
699 my *list $rows = $table.findAll(("id": op_gt(100), "created": op_gt(2013-03-01)));
700  @endcode
701  resulting in an internal SQL command that looks as follows:
702  @code
703 $ds.vexec("select * from table where id > %v and created > %v", (100, 2013-03-01));
704  @endcode \n
705 
706  @section sql_upsert Upserting or Merging Data
707 
708  This module offers a high-level api for "upserting" or merging data from one table into another table through the following methods:
709  - @ref SqlUtil::Table::upsert()
710  - @ref SqlUtil::Table::upsertNoCommit()
711  - @ref SqlUtil::Table::getUpsertClosure()
712  - @ref SqlUtil::Table::getUpsertClosureWithValidation()
713  - @ref SqlUtil::Table::upsertFromIterator()
714  - @ref SqlUtil::Table::upsertFromIteratorNoCommit()
715  - @ref SqlUtil::Table::upsertFromSelect()
716  - @ref SqlUtil::Table::upsertFromSelectNoCommit()
717 
718  @subsection sql_upsert_single Upsert a Single Row
719 
720  @par Example:
721  @code
722 $table.upsert(("id": $id, "name": $name, "account_type": $account_type));
723  @endcode
724 
725  To upsert or merge a single row in the database, call @ref SqlUtil::Table::upsert() or @ref SqlUtil::Table::upsertNoCommit() with the
726  single row to be upserted or merged as a hash as in the preceding example.
727 
728  @subsection sql_upsert_many Upserting Many Rows Using An Upsert Closure
729 
730  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.
731 
732  @par Simple Example:
733  @code
734 # get the rows to be inserted
735 my list $l = get_table_rows();
736 
737 if ($l) {
738  my code $upsert = $table.getUpsertClosure($l[0]);
739 
740  on_success $ds.commit();
741  on_error $ds.rollback();
742 
743  # loop through the reference data rows
744  map $upsert($1), $l;
745 }
746  @endcode
747 
748  @par Complex Example With Callbacks:
749  @code
750 # set the upsert strategy depending on the use case
751 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
752 
753 # hash summarizing changes
754 my hash $sh;
755 
756 # get the rows to be inserted
757 my list $l = get_table_rows();
758 
759 if ($l) {
760  # get the upsert closure to use based on the first row to be inserted
761  my code $upsert = $table.getUpsertClosure($l[0], $upsert_strategy);
762 
763  on_success $ds.commit();
764  on_error $ds.rollback();
765 
766  # loop through the reference data rows
767  foreach my hash $h in ($l) {
768  my int $code = $upsert($h);
769  if ($code == AbstractTable::UR_Unchanged)
770  continue;
771 
772  my string $change = AbstractTable::UpsertResultMap{$code};
773  ++$sh{$change};
774 
775  if (!$verbose) {
776  printf(".");
777  flush();
778  }
779  else if ($verbose > 1)
780  printf("*** reference data %s: %y: %s\n", $table.getName(), $h, $change);
781  }
782 
783  # show table summary
784  if ($sh)
785  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
786  else
787  printf("*** reference data %s: OK\n", $table.getName());
788 }
789  @endcode
790 
791  @subsection sql_upsert_from_iterator Upserting Many Rows from an Iterator Source
792 
793  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:
794 
795  @par Simple Example:
796  @code
797 # get the rows to be inserted
798 my list $l = get_table_rows();
799 $table.upsertFromIterator($l.iterator());
800  @endcode
801 
802  @par Complex Example With Callbacks:
803  @code
804 # set the upsert strategy depending on the use case
805 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
806 
807 # get the rows to be inserted
808 my list $l = get_table_rows();
809 
810 my code $callback = sub (string $table_name, hash $row, int $result) {
811  if ($result == AbstractTable::UR_Unchanged)
812  return;
813  my string $change = AbstractTable::UpsertResultMap{$result};
814  if ($verbose)
815  printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
816 };
817 
818 my hash $sh = $table.upsertFromIterator($l.iterator(), $upsert_strategy, False, ("info_callback": $callback, "commit_block": 5000));
819 if ($sh)
820  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
821 else
822  printf("*** reference data %s: OK\n", $table.getName());
823  @endcode
824 
825  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".
826 
827  @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
828 
829  @subsection sql_upsert_from_select Upserting Many Rows from a Select Statement
830 
831  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:
832 
833  @par Simple Example:
834  @code
835 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")));
836  @endcode
837 
838  @par Complex Example With Callbacks:
839  @code
840 # set the upsert strategy depending on the use case
841 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
842 
843 my code $callback = sub (string $table_name, hash $row, int $result) {
844  if ($result == AbstractTable::UR_Unchanged)
845  return;
846  my string $change = AbstractTable::UpsertResultMap{$result};
847  if ($verbose)
848  printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
849 };
850 
851 my hash $sh = $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), $upsert_strategy, False, ("info_callback": $callback, "commit_block": 5000));
852 if ($sh)
853  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
854 else
855  printf("*** reference data %s: OK\n", $table.getName());
856  @endcode
857 
858  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).
859 
860  @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
861 
862  @subsection sql_upsert_with_delete Upserting Many Rows and Deleting Unwanted Rows
863 
864  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.
865 
866  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.
867 
868  @par Simple Example:
869  @code
870 # get the rows to be inserted
871 my list $l = get_table_rows();
872 $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), AbstractTable::UpsertAuto, ("delete_others": True, "commit_block": 5000));
873  @endcode
874 
875  @par Complex Example With Callbacks:
876  @code
877 # set the upsert strategy depending on the use case
878 my int $upsert_strategy = $verbose ? AbstractTable::UpsertSelectFirst : AbstractTable::UpsertAuto;
879 
880 # get the rows to be inserted
881 my list $l = get_table_rows();
882 
883 my code $callback = sub (string $table_name, hash $row, int $result) {
884  if ($result == AbstractTable::UR_Unchanged)
885  return;
886  my string $change = AbstractTable::UpsertResultMap{$result};
887  if ($verbose)
888  printf("*** reference data %s: %y: %s\n", $table_name, $row, $change);
889 };
890 
891 my hash $sh = $table.upsertFromSelect($table2, ("where": ("account_type": "CUSTOMER")), $upsert_strategy, ("delete_others": True, "info_callback": $callback, "commit_block": 5000));
892 if ($sh)
893  printf("*** reference data %s: %s\n", $table.getName(), (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), $sh.pairIterator())));
894 else
895  printf("*** reference data %s: OK\n", $table.getName());
896  @endcode
897 
898  @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
899 
900  @subsection sql_upsert_strategies Upsert Strategies
901  The approach used is based on one of the following strategies (see @ref upsert_options):
902  - @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
903  - @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
904  - @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
905  - @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
906  - @ref SqlUtil::AbstractTable::UpsertInsertOnly "AbstractTable::UpsertInsertOnly": insert if the row doesn't exist, otherwise do nothing and @ref upsert_results "upsert result" @ref SqlUtil::AbstractTable::UR_Unchanged is returned
907 
908  @note @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" is the only upsert strategy that can return @ref SqlUtil::AbstractTable::UR_Updated; the @ref SqlUtil::AbstractTable::UpsertSelectFirst "AbstractTable::UpsertSelectFirst" strategy should be used when verbose reporting is required, particularly if it's necessary to report the actual number of changed rows.
909 */
1589 namespace SqlUtil {
1591 
1592  /* @defgroup DBFeaturesConstants DB Features Constants
1593  These constants can be used as a lookup values in AbstractDatabase::features() method.
1594  */
1596 
1599  const DB_FUNCTIONS = "functions";
1601  const DB_MVIEWS = "materialized views";
1603  const DB_PACKAGES = "packages";
1605  const DB_PROCEDURES = "procedures";
1607  const DB_SEQUENCES = "sequences";
1609  const DB_TABLES = "tables";
1611  const DB_TYPES = "named types";
1613  const DB_VIEWS = "views";
1614 
1616 
1617  /* @defgroup SqlTypeConstants SQL Type Constants
1618  These constants can be used for the \c "qore_type" values when creating columns to specify additional SQL column types
1619  */
1621  const VARCHAR = "string";
1623 
1625  const NUMERIC = "number";
1626 
1628  const CHAR = "char";
1629 
1631  const BLOB = "blob";
1632 
1634  const CLOB = "clob";
1636 
1641  const SZ_NONE = 0;
1643 
1645  const SZ_MAND = 1;
1646 
1648  const SZ_OPT = 2;
1649 
1651  const SZ_NUM = 3;
1653 
1658 
1661  const COP_AS = "as";
1662 
1664 
1666  const COP_PREPEND = "prepend";
1667 
1669 
1671  const COP_APPEND = "append";
1672 
1674 
1676  const COP_VALUE = "value";
1677 
1679 
1681  const COP_UPPER = "upper";
1682 
1684 
1686  const COP_LOWER = "lower";
1687 
1689 
1691  const COP_DISTINCT = "distinct";
1692 
1694 
1696  const COP_MIN = "min";
1697 
1699 
1701  const COP_MAX = "max";
1702 
1704 
1706  const COP_AVG = "avg";
1707 
1709 
1711  const COP_COUNT = "count";
1712 
1714 
1716  const COP_OVER = "over";
1717 
1719 
1721  const COP_MINUS = "minus";
1722 
1724 
1726  const COP_PLUS = "plus";
1727 
1729 
1731  const COP_DIVIDE = "divide";
1732 
1734 
1736  const COP_MULTIPLY = "multiply";
1737 
1739 
1741  const COP_YEAR = "year";
1742 
1744 
1746  const COP_YEAR_MONTH = "year_month";
1747 
1749 
1751  const COP_YEAR_DAY = "year_day";
1752 
1754 
1756  const COP_YEAR_HOUR = "year_hour";
1757 
1759  const DefaultCopMap = (
1760  COP_AS: (
1761  "arg": Type::String,
1762  "code": string (string cve, string arg) {
1763  return sprintf("%s as %s", cve, arg);
1764  },
1765  ),
1766  COP_PREPEND: (
1767  "arg": Type::String,
1768  "sqlvalue": True,
1769  "code": string (string cve, string arg) {
1770  return sprintf("%s||%s", arg, cve);
1771  },
1772  ),
1773  COP_APPEND: (
1774  "arg": Type::String,
1775  "sqlvalue": True,
1776  "code": string (string cve, string arg) {
1777  return sprintf("%s||%s", cve, arg);
1778  },
1779  ),
1780  COP_VALUE: (
1781  "sqlvalue": True,
1782  "nocolumn": True,
1783  "code": string (*string cve, any arg) {
1784  return arg;
1785  },
1786  ),
1787  COP_UPPER: (
1788  "code": string (string cve, any arg) {
1789  return sprintf("upper(%s)", cve);
1790  },
1791  ),
1792  COP_LOWER: (
1793  "code": string (string cve, any arg) {
1794  return sprintf("lower(%s)", cve);
1795  },
1796  ),
1797  COP_DISTINCT: (
1798  "code": string (string cve, any arg) {
1799  return sprintf("distinct %s", cve);
1800  },
1801  ),
1802  COP_MIN: (
1803  "code": string (string cve, any arg) {
1804  return sprintf("min(%s)", cve);
1805  },
1806  "group": True,
1807  ),
1808  COP_MAX: (
1809  "code": string (string cve, any arg) {
1810  return sprintf("max(%s)", cve);
1811  },
1812  "group": True,
1813  ),
1814  COP_AVG: (
1815  "code": string (string cve, any arg) {
1816  return sprintf("avg(%s)", cve);
1817  },
1818  "group": True,
1819  ),
1820  COP_COUNT: (
1821  "nocolumn": True,
1822  "code": string (*string cve, any arg) {
1823  return sprintf("count(%s)", cve ? cve : "1");
1824  },
1825  ),
1826  COP_MINUS: (
1827  "argcolumn": True,
1828  "code": string (string arg1, string arg2) {
1829  return sprintf("%s - %s", arg1, arg2);
1830  },
1831  ),
1832  COP_PLUS: (
1833  "argcolumn": True,
1834  "code": string (string arg1, string arg2) {
1835  return sprintf("%s + %s", arg1, arg2);
1836  },
1837  ),
1838  COP_DIVIDE: (
1839  "argcolumn": True,
1840  "code": string (string arg1, string arg2) {
1841  return sprintf("%s / %s", arg1, arg2);
1842  },
1843  ),
1844  COP_MULTIPLY: (
1845  "argcolumn": True,
1846  "code": string (string arg1, string arg2) {
1847  return sprintf("%s * %s", arg1, arg2);
1848  },
1849  ),
1850  );
1852 
1869 
1878  hash make_cop(string cop, any column, any arg);
1879 
1880 
1882 
1892  hash cop_as(any column, string arg);
1893 
1894 
1896 
1906  hash cop_prepend(any column, string arg);
1907 
1908 
1910 
1920  hash cop_append(any column, string arg);
1921 
1922 
1924 
1933  hash cop_value(any arg);
1934 
1935 
1937 
1946  hash cop_upper(any column);
1947 
1948 
1950 
1959  hash cop_lower(any column);
1960 
1961 
1963 
1972  hash cop_distinct(any column);
1973 
1974 
1976 
1985  hash cop_min(any column);
1986 
1987 
1989 
1998  hash cop_max(any column);
1999 
2000 
2002 
2011  hash cop_avg(any column);
2012 
2013 
2015 
2022  hash cop_count(string column = "");
2023 
2024 
2026 
2033  hash cop_over(any column, string arg);
2034 
2035 
2037 
2048  hash cop_minus(any column1, any column2);
2049 
2050 
2052 
2063  hash cop_plus(any column1, any column2);
2064 
2065 
2067 
2078  hash cop_divide(any column1, any column2);
2079 
2080 
2082 
2093  hash cop_multiply(any column1, any column2);
2094 
2095 
2097 
2106  hash cop_year(any column);
2107 
2108 
2110 
2119  hash cop_year_month(any column);
2120 
2121 
2123 
2132  hash cop_year_day(any column);
2133 
2134 
2136 
2145  hash cop_year_hour(any column);
2146 
2148 
2152  const DefaultUopMap = (
2154  COP_PREPEND: True,
2155  COP_APPEND: True,
2156  COP_UPPER: True,
2157  COP_LOWER: True,
2158  );
2160 
2175 
2184  hash make_uop(string uop, any arg, *hash nest);
2185 
2186 
2188 
2198  hash uop_prepend(string arg, *hash nest);
2199 
2200 
2202 
2212  hash uop_append(string arg, *hash nest);
2213 
2214 
2216 
2225  hash uop_upper(*hash nest);
2226 
2227 
2229 
2238  hash uop_lower(*hash nest);
2239 
2241 
2248 
2251  const JOP_INNER = "inner";
2252 
2254 
2256  const JOP_LEFT = "left";
2257 
2259 
2261  const JOP_RIGHT = "right";
2262 
2264  const JopMap = (
2265  JOP_INNER: "inner",
2266  JOP_LEFT: "left outer",
2267  JOP_RIGHT: "right outer",
2268  );
2270 
2280 
2284  hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt);
2285 
2286 
2288 
2307  hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2308 
2309 
2311 
2330  hash join_inner(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2331 
2332 
2334 
2354  hash join_inner(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2355 
2356 
2358 
2378  hash join_inner(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2379 
2380 
2382 
2401  hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2402 
2403 
2405 
2424  hash join_left(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2425 
2426 
2428 
2448  hash join_left(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2449 
2450 
2452 
2472  hash join_left(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2473 
2474 
2476 
2495  hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2496 
2497 
2499 
2518  hash join_right(Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2519 
2520 
2522 
2542  hash join_right(string ta, AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt);
2543 
2544 
2546 
2566  hash join_right(string ta, Table table, *string alias, *hash jcols, *hash cond, *hash opt);
2567 
2569 
2574 
2577  const OP_LIKE = "like";
2578 
2580 
2582  const OP_LT = "<";
2583 
2585 
2587  const OP_LE = "<=";
2588 
2590 
2592  const OP_GT = ">";
2593 
2595 
2597  const OP_GE = ">=";
2598 
2600 
2602  const OP_NE = "!=";
2603 
2605 
2607  const OP_EQ = "=";
2608 
2610 
2612  const OP_CLT = "C<";
2613 
2615 
2617  const OP_CLE = "C<=";
2618 
2620 
2622  const OP_CGT = "C>";
2623 
2625 
2627  const OP_CGE = "C>=";
2628 
2630 
2632  const OP_CNE = "C!=";
2633 
2635 
2637  const OP_CEQ = "C=";
2638 
2640 
2642  const OP_BETWEEN = "between";
2643 
2645 
2647  const OP_IN = "in";
2648 
2650 
2652  const OP_NOT = "not";
2653 
2655  const DefaultOpMap = (
2656  OP_LIKE: (
2657  "code": string (object t, string cn, any arg, reference args) {
2658  args += arg;
2659  return sprintf("%s like %v", cn);
2660  },
2661  ),
2662  OP_LT: (
2663  "code": string (object t, string cn, any arg, reference args) {
2664  args += arg;
2665  return sprintf("%s < %v", cn);
2666  },
2667  ),
2668  OP_LE: (
2669  "code": string (object t, string cn, any arg, reference args) {
2670  args += arg;
2671  return sprintf("%s <= %v", cn);
2672  },
2673  ),
2674  OP_GT: (
2675  "code": string (object t, string cn, any arg, reference args) {
2676  args += arg;
2677  return sprintf("%s > %v", cn);
2678  },
2679  ),
2680  OP_GE: (
2681  "code": string (object t, string cn, any arg, reference args) {
2682  args += arg;
2683  return sprintf("%s >= %v", cn);
2684  },
2685  ),
2686  OP_NE: (
2687  "code": string (object t, string cn, any arg, reference args) {
2688  if (arg === NULL || !exists arg)
2689  return sprintf("%s is not null", cn);
2690  args += arg;
2691  return sprintf("%s != %v", cn);
2692  },
2693  ),
2694  OP_EQ: (
2695  "code": string (object t, string cn, any arg, reference args) {
2696  if (arg === NULL || !exists arg)
2697  return sprintf("%s is null", cn);
2698  args += arg;
2699  return sprintf("%s = %v", cn);
2700  },
2701  ),
2702  OP_BETWEEN: (
2703  "code": string (object t, string cn, any arg, reference args) {
2704  args += arg[0];
2705  args += arg[1];
2706  return sprintf("%s between %v and %v", cn);
2707  },
2708  ),
2709  OP_IN: (
2710  "code": string (object t, string cn, any arg, reference args) {
2711  *string ins = (foldl $1 + "," + $2, (map t.getSqlValue($1), arg));
2712  return ins ? sprintf("%s in (%s)", cn, ins) : "1 != 1";
2713  },
2714  ),
2715  OP_NOT: (
2716  "recursive": True,
2717  "code": string (object t, string cn, any arg, reference args) {
2718  return sprintf("not (%s)", cn);
2719  },
2720  ),
2721  OP_CLT: (
2722  "argcolumn": True,
2723  "code": string (object t, string cn, any arg, reference args) {
2724  return sprintf("%s < %s", cn, arg);
2725  },
2726  ),
2727  OP_CLE: (
2728  "argcolumn": True,
2729  "code": string (object t, string cn, any arg, reference args) {
2730  return sprintf("%s <= %s", cn, arg);
2731  },
2732  ),
2733  OP_CGT: (
2734  "argcolumn": True,
2735  "code": string (object t, string cn, any arg, reference args) {
2736  return sprintf("%s > %s", cn, arg);
2737  },
2738  ),
2739  OP_CGE: (
2740  "argcolumn": True,
2741  "code": string (object t, string cn, any arg, reference args) {
2742  return sprintf("%s >= %s", cn, arg);
2743  },
2744  ),
2745  OP_CNE: (
2746  "argcolumn": True,
2747  "code": string (object t, string cn, any arg, reference args) {
2748  return sprintf("%s != %s", cn, arg);
2749  },
2750  ),
2751  OP_CEQ: (
2752  "argcolumn": True,
2753  "code": string (object t, string cn, string arg, reference args) {
2754  return sprintf("%s = %s", cn, arg);
2755  },
2756  ),
2757  );
2759 
2780  hash make_op(string op, any arg);
2782 
2783 
2785 
2794  hash op_like(string str);
2795 
2796 
2798 
2809  hash op_lt(any arg);
2810 
2811 
2813 
2824  hash op_le(any arg);
2825 
2826 
2828 
2839  hash op_gt(any arg);
2840 
2841 
2843 
2854  hash op_ge(any arg);
2855 
2856 
2858 
2869  hash op_ne(any arg);
2870 
2871 
2873 
2884  hash op_eq(any arg);
2885 
2886 
2888 
2900  hash op_between(any l, any r);
2901 
2902 
2904 
2911  hash op_in();
2912 
2913 
2915 
2924  hash op_in(list args);
2925 
2926 
2928 
2935  hash op_not(hash arg);
2936 
2937 
2939 
2950  hash op_clt(string arg);
2951 
2952 
2954 
2965  hash op_cle(string arg);
2966 
2967 
2969 
2980  hash op_cgt(string arg);
2981 
2982 
2984 
2995  hash op_cge(string arg);
2996 
2997 
2999 
3010  hash op_cne(string arg);
3011 
3012 
3014 
3025  hash op_ceq(string arg);
3026 
3028 
3031 
3032 public:
3033 private:
3034 
3035 public:
3036 
3037  private :
3038  *hash h;
3039 
3040 public:
3041 
3043  constructor(*hash nh);
3044 
3045 
3048 
3049 
3051 
3066  any memberGate(string k);
3067 
3068 
3070 
3076  clear();
3077 
3078 
3080  abstract any take(string k);
3081 
3083  renameKey(string old_name, string new_name);
3084 
3085 
3087  *hash getHash();
3088 
3089 
3091 
3100  bool matchKeys(hash h1);
3101 
3102 
3104 
3113  bool matchKeys(list l);
3114 
3115 
3117 
3127 
3128 
3130 
3139  bool partialMatchKeys(hash h1);
3140 
3141 
3143 
3152  bool partialMatchKeys(list l);
3153 
3154 
3156 
3166 
3167 
3169 
3178  bool val();
3179 
3180 
3182 
3189  list keys();
3190 
3191 
3193 
3200  list values();
3201 
3202 
3204 
3212 
3213 
3215 
3223 
3224 
3226 
3234 
3235 
3237  bool empty();
3238 
3239 
3241 
3248  int size();
3249 
3250 
3252 
3261  bool hasKey(string k);
3262 
3263 
3265 
3274  bool hasKeyValue(string k);
3275 
3276 
3278 
3287  *string firstKey();
3288 
3289 
3291 
3300  *string lastKey();
3301 
3302 
3304  abstract string getElementName();
3305  };
3306 
3309 
3310 public:
3311 private:
3312 
3313 public:
3314 
3315  private :
3316  softlist l;
3317 
3318 public:
3319 
3321  constructor(softlist nl);
3322 
3323 
3325 
3336  abstract any get(softint i);
3337 
3339  add(any val);
3340 
3341 
3343  any take(int i);
3344 
3345 
3347  list getList();
3348 
3349 
3351 
3360  bool val();
3361 
3362 
3364 
3372 
3373 
3375  bool empty();
3376 
3377 
3379 
3386  int size();
3387 
3388 
3390  abstract string getElementName();
3391 
3392  private checkIndex(int i);
3393 
3394  };
3395 
3398 
3399 public:
3401  constructor();
3402 
3403 
3405  constructor(AbstractDatasource ds, hash tables, *hash opt);
3406 
3407 
3409  constructor(AbstractDatasource ds);
3410 
3411 
3413  add(string k, Table val);
3414 
3415 
3417  add(string k, AbstractTable val);
3418 
3419 
3421  add(Table val);
3422 
3423 
3425  add(AbstractTable val);
3426 
3427 
3429  AbstractTable take(string k);
3430 
3431 
3433  populate(AbstractDatasource ds, hash tables, *hash opt);
3434 
3435 
3437  populate(AbstractDatasource ds);
3438 
3439 
3441 
3455  *list getDropAllForeignConstraintsOnTableSql(string name, *hash opt);
3456 
3457 
3459 
3474  AbstractTable memberGate(string k);
3475 
3476 
3478  string getElementName();
3479 
3480 
3482  *AbstractTable getIfExists(AbstractDatasource ds, string name);
3483 
3484 
3486  AbstractTable get(AbstractDatasource ds, string name);
3487 
3488 
3490 
3505  *string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts);
3506 
3507 
3509 
3520  bool tableRenamed(string old_name, string new_name, string old_sql_name);
3521 
3522 
3523  private tableRenamedIntern(string old_name, string new_name, string oldsn);
3524 
3525 
3527 
3542  *string getDropConstraintIfExistsSql(string tname, string cname, *hash opts);
3543 
3544 
3545  list getCreateList();
3546 
3547 
3548  Qore::AbstractIterator createIterator();
3549 
3550 
3552 
3560  list getDropList();
3561 
3562 
3564 
3572 
3573 
3574  private getDependencies(reference tdh, reference sdh, *reference th);
3575 
3576  };
3577 
3580 
3581 public:
3582  constructor(*hash c);
3583 
3584 
3586  add(string k, AbstractColumn val);
3587 
3588 
3590  AbstractColumn take(string k);
3591 
3592 
3594 
3609  AbstractColumn memberGate(string k);
3610 
3611 
3613  Columns subset(softlist l);
3614 
3615 
3617  string getElementName();
3618 
3619 
3621  bool equal(Columns cols);
3622 
3623  };
3624 
3627 
3628 public:
3629  public :
3631  string name;
3632 
3634  string native_type;
3635 
3637  *string qore_type;
3638 
3640  int size;
3641 
3643  bool nullable;
3644 
3646  *string def_val;
3647 
3649  *string comment;
3650 
3651 public:
3652 
3653  constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string c);
3654 
3655 
3657  string getNativeTypeString();
3658 
3659 
3661  string getCreateSql();
3662 
3663 
3665 
3674  abstract list getCreateSql(AbstractTable t);
3675 
3677  string getDropSql(string table_name);
3678 
3679 
3681 
3694 
3695 
3697 
3707  abstract string getRenameSql(AbstractTable t, string new_name);
3708 
3710  bool equal(AbstractColumn c);
3711 
3712 
3714  private abstract bool equalImpl(AbstractColumn c);
3715 
3717 
3729  private abstract list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt);
3730  };
3731 
3734 
3735 public:
3736  public :
3738  int scale;
3739 
3740 public:
3741 
3742  constructor(softint n_scale = 0);
3743 
3744 
3746  string getNativeTypeString(string native_type, int precision);
3747 
3748  };
3749 
3752 
3753 public:
3754  constructor(*hash c);
3755 
3756 
3758  add(string k, AbstractIndex val);
3759 
3760 
3763 
3764 
3766  AbstractIndex take(string k);
3767 
3768 
3770 
3785  AbstractIndex memberGate(string k);
3786 
3787 
3788  string getElementName();
3789 
3790  };
3791 
3794 
3795 public:
3796  public :
3798  string name;
3799 
3801  bool unique;
3802 
3805 
3806 public:
3807 
3808  private :
3811 
3812 public:
3813 
3815  constructor(string n, bool u, hash c);
3816 
3817 
3819  string getName();
3820 
3821 
3823  bool hasColumn(string cname);
3824 
3825 
3827  abstract string getCreateSql(string table_name, *hash opt);
3828 
3830  string getDropSql(string table_name);
3831 
3832 
3834  bool equal(AbstractIndex ix);
3835 
3836 
3838  bool equalExceptName(AbstractIndex ix);
3839 
3840 
3842  abstract bool equalImpl(AbstractIndex ix);
3843 
3845  abstract string getRenameSql(string table_name, string new_name);
3846 
3849 
3850 
3853 
3854 
3857 
3858 
3860  list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt);
3861 
3862  };
3863 
3866 
3867 public:
3868  constructor(*hash c);
3869 
3870 
3872  add(string k, AbstractConstraint val);
3873 
3874 
3876  AbstractConstraint take(string k);
3877 
3878 
3881 
3882 
3884 
3899  AbstractConstraint memberGate(string k);
3900 
3901 
3902  string getElementName();
3903 
3904  };
3905 
3908 
3909 public:
3910 private:
3911 
3912 public:
3913 
3914  private :
3916  string name;
3917 
3918 public:
3919 
3921  constructor(string n);
3922 
3923 
3925  string getName();
3926 
3927 
3929  rename(string n);
3930 
3931 
3933  abstract string getCreateSql(string table_name, *hash opt);
3934 
3936  string getDropSql(string table_name);
3937 
3938 
3940  abstract list getRenameSql(string table_name, string new_name);
3941 
3943  string getDisableSql(string table_name);
3944 
3945 
3947  string getEnableSql(string table_name, *hash opt);
3948 
3949 
3951  bool equal(AbstractConstraint c);
3952 
3953 
3955  private abstract bool equalImpl(AbstractConstraint c);
3956 
3958  abstract bool setIndexBase(string ix);
3959 
3961  abstract clearIndex();
3962 
3964  bool hasColumn(string cname);
3965 
3966  };
3967 
3970 
3971 public:
3972  public :
3974  string src;
3975 
3976 public:
3977 
3979  constructor(string n, string n_src);
3980 
3981 
3983  private bool equalImpl(AbstractConstraint c);
3984 
3985 
3987  bool setIndexBase(string ix);
3988 
3989 
3991  clearIndex();
3992 
3993  };
3994 
3997 
3998 public:
3999  private :
4002 
4004  *string index;
4005 
4006 public:
4007 
4009  constructor(string n, *hash c, *string n_index);
4010 
4011 
4013  abstract string getCreateSql(string table_name, *hash opts);
4014 
4016  private bool equalImpl(AbstractConstraint c);
4017 
4018 
4020 
4025 
4026 
4028  hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts);
4029 
4030 
4032  findMatchingIndex(*Indexes indexes);
4033 
4034 
4036 
4047 
4048 
4050  removeSourceConstraint(string tname, list cols);
4051 
4052 
4054  renameSourceConstraintTable(string old_name, string new_name);
4055 
4056 
4058  bool hasColumn(string cname);
4059 
4060 
4062  *string getIndex();
4063 
4064  };
4065 
4068 
4069 public:
4070  constructor();
4071 
4072 
4073  constructor(string n, *hash c);
4074 
4075  };
4076 
4079 
4080 public:
4081  constructor(*hash c);
4082 
4083 
4085  add(string k, AbstractForeignConstraint val);
4086 
4087 
4089  AbstractForeignConstraint take(string k);
4090 
4091 
4094 
4095 
4097 
4113 
4114 
4116  *hash findConstraintOn(string table, softlist cols);
4117 
4118 
4120  string getElementName();
4121 
4122  };
4123 
4126 
4127 public:
4128  public :
4130  string table;
4131 
4134 
4135 public:
4136 
4138  constructor(string t, Columns c);
4139 
4140 
4142  bool equal(ForeignConstraintTarget targ);
4143 
4144  };
4145 
4148 
4149 public:
4150  public :
4153 
4156 
4157 public:
4158 
4159  constructor(string n, Columns c, ForeignConstraintTarget t);
4160 
4161 
4163  private bool equalImpl(AbstractConstraint con);
4164 
4165 
4167  bool hasColumn(string cname);
4168 
4169 
4171  bool setIndexBase(string ix);
4172 
4173 
4175  clearIndex();
4176 
4177  };
4178 
4181 
4182 public:
4183  public :
4185  string name;
4186 
4189 
4192 
4195 
4196 public:
4197 
4199  constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_max);
4200 
4201 
4203  abstract string getCreateSql(*hash opt);
4204 
4206  string getDropSql();
4207 
4208 
4210  abstract string getRenameSql(string new_name);
4211  };
4212 
4215 
4216 public:
4217  public :
4218  // ! potential object schema
4219  *string schema;
4220 
4222  string name;
4223 
4225  string src;
4226 
4229 
4230 public:
4231 
4233  constructor(string n_name, string n_src);
4234 
4235 
4237  abstract string getCreateSql(*hash opt);
4238 
4240  string getDropSql();
4241 
4242 
4244  abstract softlist getRenameSql(string new_name);
4245 
4246  };
4247 
4250 
4251 public:
4252  public :
4254  string name;
4255 
4257  string type;
4258 
4260  string src;
4261 
4262 public:
4263 
4265 
4269  constructor(string n, string n_type, string n_src);
4270 
4271 
4273  string getType();
4274 
4275 
4276  // FIXME: not appropriate for pgsql triggers for example
4278  string getDropSql();
4279 
4280 
4282  bool equal(AbstractFunctionBase t);
4283 
4284 
4286  private abstract bool equalImpl(AbstractFunctionBase t);
4287  };
4288 
4291 
4292 public:
4294 
4298  constructor(string n, string n_type, string n_src);
4299 
4300 
4302  abstract list getCreateSql(*hash opt);
4303 
4305  abstract list getRenameSql(string new_name);
4306 
4308  setName(string new_name);
4309 
4310  };
4311 
4314 
4315 public:
4316  constructor(*hash c);
4317 
4318 
4320  add(string k, AbstractFunction val);
4321 
4322 
4324  AbstractFunction take(string k);
4325 
4326 
4328 
4343  AbstractFunction memberGate(string k);
4344 
4345 
4346  string getElementName();
4347 
4348  };
4349 
4352 
4353 public:
4355  constructor(string n, string n_src);
4356 
4357 
4359  abstract list getCreateSql(string table_name, *hash opt);
4360 
4362  abstract list getRenameSql(string table_name, string new_name);
4363 
4365  abstract list getDropSql(string table_name);
4366  };
4367 
4370 
4371 public:
4372  constructor(*hash c);
4373 
4374 
4376  add(string k, AbstractTrigger val);
4377 
4378 
4380  AbstractTrigger take(string k);
4381 
4382 
4384 
4399  AbstractTrigger memberGate(string k);
4400 
4401 
4402  string getElementName();
4403 
4404  };
4405 
4407 
4417  class Database {
4418 
4419 public:
4420  private :
4423 
4424 public:
4425 
4427 
4438  constructor(AbstractDatasource ds, *hash opts);
4439 
4440 
4442 
4452  constructor(string ds, *hash opts);
4453 
4454 
4456 
4474  constructor(hash ds, *hash opts);
4475 
4476 
4478 
4489  any tryExec(string sql);
4490 
4491 
4493 
4503  any tryExecArgs(string sql, *softlist args);
4504 
4505 
4507 
4518  any tryExecRaw(string sql);
4519 
4520 
4522 
4536  list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
4537 
4538 
4540 
4553  list getDropSchemaSql(hash schema_hash, *hash opt);
4554 
4555 
4558 
4559 
4561  any methodGate(string meth);
4562 
4563 
4565 
4579  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
4580 
4581 
4583 
4596  AbstractTable makeTable(string name, hash desc, *hash opts);
4597 
4598 
4600 
4611  AbstractFunction makeFunction(string name, string src, *hash opt);
4612 
4613 
4615 
4626  AbstractFunction makeProcedure(string name, string src, *hash opt);
4627 
4628 
4630 
4642  bool dropFunctionIfExists(string name, *hash opt);
4643 
4644 
4646 
4658  bool dropProcedureIfExists(string name, *hash opt);
4659 
4660 
4662 
4674  bool dropSequenceIfExists(string name, *hash opt);
4675 
4676 
4678 
4690  bool dropTableIfExists(string name, *hash opt);
4691 
4692 
4694 
4707 
4708 
4710 
4723 
4724 
4726 
4735  *AbstractTable getTable(string name);
4736 
4737 
4739 
4748  *AbstractSequence getSequence(string name);
4749 
4750 
4752 
4763  *AbstractFunction getFunction(string name);
4764 
4765 
4767 
4778  *AbstractFunction getProcedure(string name);
4779 
4780 
4782 
4791  *AbstractView getView(string name);
4792 
4793 
4795 
4804  int getNextSequenceValue(string name);
4805 
4806 
4808 
4817  string getSqlFromList(list l);
4818 
4819 
4821  bool supportsSequences();
4822 
4823 
4825  list listTables();
4826 
4827 
4830 
4831 
4833  list listFunctions();
4834 
4835 
4838 
4839 
4841  list listProcedures();
4842 
4843 
4846 
4847 
4849  list listSequences();
4850 
4851 
4854 
4855 
4857  list listViews();
4858 
4859 
4862 
4863  };
4864 
4867 
4868 public:
4869  private :
4871  AbstractDatasource ds;
4873  string dsdesc;
4875  Mutex l();
4878 
4879 public:
4880 
4882 
4887  private constructor(AbstractDatasource nds, *hash nopts);
4888 
4889 
4890  private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
4891 
4892 
4893 
4894 private:
4895  static validateOptionIntern(string err, string type, reference opt, string k, string tag);
4896 public:
4897 
4898 
4901 
4902 
4904  string getDriverName();
4905 
4906 
4908  string getDatasourceDesc();
4909 
4910  };
4911 
4914 
4915 public:
4916  public :
4918 
4922  "native_case": Type::Boolean,
4923  );
4924 
4926 
4929  const CacheOptions = (
4930  "table_cache": "Tables",
4931  );
4932 
4934 
4940  "info_callback": "code",
4941  "sql_callback": "code",
4942  "sql_callback_executed": Type::Boolean,
4943  );
4944 
4953  const AC_Unchanged = 0;
4955 
4957  const AC_Create = 1;
4958 
4960  const AC_Drop = 2;
4961 
4963  const AC_Rename = 3;
4964 
4966  const AC_Modify = 4;
4967 
4969  const AC_Truncate = 5;
4970 
4972  const AC_Add = 6;
4973 
4975  const AC_Recreate = 7;
4976 
4978  const AC_Insert = 8;
4979 
4981  const AC_Update = 9;
4982 
4984  const AC_Delete = 10;
4985 
4987  const AC_NotFound = 11;
4989 
4991  const ActionMap = (
4992  AC_Unchanged: "unchanged",
4993  AC_Create: "create",
4994  AC_Drop: "drop",
4995  AC_Rename: "rename",
4996  AC_Modify: "modify",
4997  AC_Truncate: "truncate",
4998  AC_Add: "add",
4999  AC_Recreate: "recreate",
5000  AC_Insert: "insert",
5001  AC_Update: "update",
5002  AC_Delete: "delete",
5003  AC_NotFound: "not found",
5004  );
5005 
5007  const ActionDescMap = (
5008  "unchanged": AC_Unchanged,
5009  "create": AC_Create,
5010  "drop": AC_Drop,
5011  "rename": AC_Rename,
5012  "modify": AC_Modify,
5013  "truncate": AC_Truncate,
5014  "add": AC_Add,
5015  "recreate": AC_Recreate,
5016  "insert": AC_Insert,
5017  "update": AC_Update,
5018  "delete": AC_Delete,
5019  "not found": AC_NotFound,
5020  );
5021 
5024  AC_Unchanged: ".",
5025  AC_Create: "C",
5026  AC_Drop: "D",
5027  AC_Rename: "N",
5028  AC_Modify: "M",
5029  AC_Truncate: "T",
5030  AC_Add: "A",
5031  AC_Recreate: "R",
5032  AC_Insert: "I",
5033  AC_Update: "U",
5034  AC_Delete: "X",
5035  AC_NotFound: ".",
5036  );
5037 
5039 
5046  "replace": Type::Boolean,
5047  "table_cache": "Tables",
5048  "data_tablespace": Type::String,
5049  "index_tablespace": Type::String,
5050  );
5051 
5053 
5056 
5058 
5061 
5063 
5076  "tables": Type::Hash,
5077  "table_map": Type::Hash,
5078 
5079  "sequences": Type::Hash,
5080  "sequence_map": Type::Hash,
5081 
5082  "functions": Type::Hash,
5083  "function_map": Type::Hash,
5084 
5085  "procedures": Type::Hash,
5086  "procedure_map": Type::Hash,
5087 
5088  //"views": Type::Hash,
5089  //"view_map": Type::Hash,
5090  );
5091 
5093 
5099  "start": Type::Int,
5100  "increment": Type::Int,
5101  "end": Type::Int,
5102  );
5103 
5104 public:
5105 
5106  private :
5109 
5110 public:
5111 
5113 
5118  private constructor(AbstractDatasource nds, *hash nopts);
5119 
5120 
5122  list features();
5123 
5124 
5125  static doOkCallback(*hash opt, int ac, string type, string name, *string table, *string info);
5126 
5127  static *string doCallback(*hash opt, *string sql, int ac, string type, string name, *string table, *string new_name, *string info);
5128 
5129  static list doCallback(*hash opt, list sql, int ac, string type, string name, *string table, *string new_name, *string info);
5130 
5131 /*
5132  static *string doCallback(*hash opt, *string sql, string fmt) {
5133  if (!sql)
5134  return;
5135  if (opt.info_callback)
5136  opt.info_callback(vsprintf(fmt, argv));
5137  if (opt.sql_callback)
5138  opt.sql_callback(sql);
5139  return sql;
5140  }
5141 
5142  static list doCallback(*hash opt, list sql, string fmt) {
5143  if (sql) {
5144  if (opt.info_callback)
5145  opt.info_callback(vsprintf(fmt, argv));
5146  if (opt.sql_callback)
5147  map opt.sql_callback($1), sql;
5148  }
5149  return sql;
5150  }
5151 */
5152 
5154 
5165  any tryExec(string sql);
5166 
5167 
5169 
5179  any tryExecArgs(string sql, *softlist args);
5180 
5181 
5183 
5194  any tryExecRaw(string sql);
5195 
5196 
5198 
5212  list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache);
5213 
5214 
5216 
5229  list getDropSchemaSql(hash schema_hash, *hash opt);
5230 
5231 
5232  private list dropSqlUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
5233 
5234 
5235  private list alignCodeUnlocked(string type, hash schema_hash, code get, code make, *hash opt, string make_arg_type);
5236 
5237 
5239 
5253  AbstractSequence makeSequence(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
5254 
5255 
5256  AbstractSequence makeSequenceFromDescription(string name, *hash sh, *hash opts);
5257 
5258 
5260 
5273  AbstractTable makeTable(string name, hash desc, *hash opts);
5274 
5275 
5277 
5288  AbstractFunction makeFunction(string name, string src, *hash opts);
5289 
5290 
5292 
5303  AbstractFunction makeProcedure(string name, string src, *hash opt);
5304 
5305 
5307 
5319  bool dropFunctionIfExists(string name, *hash opt);
5320 
5321 
5323 
5335  bool dropProcedureIfExists(string name, *hash opt);
5336 
5337 
5339 
5351  bool dropSequenceIfExists(string name, *hash opt);
5352 
5353 
5355 
5367  bool dropViewIfExists(string name, *hash opt);
5368 
5369 
5371 
5383  bool dropTableIfExists(string name, *hash opt);
5384 
5385 
5387 
5399  *string getDropFunctionSqlIfExists(string name, *hash opt);
5400 
5401 
5403 
5415  *string getDropProcedureSqlIfExists(string name, *hash opt);
5416 
5417 
5419 
5431  *string getDropSequenceSqlIfExists(string name, *hash opt);
5432 
5433 
5435 
5447  *list getDropTableSqlIfExists(string name, *hash opt);
5448 
5449 
5450  doDropSql(*softlist l, string type, string name, *hash opt);
5451 
5452 
5453  bool doDrop(*softlist l, string type, string name, *hash opt);
5454 
5455 
5457 
5470 
5471 
5473 
5486 
5487 
5489 
5498  *AbstractTable getTable(string name);
5499 
5500 
5502 
5511  *AbstractSequence getSequence(string name);
5512 
5513 
5515 
5526  *AbstractFunction getFunction(string name);
5527 
5528 
5530 
5541  *AbstractFunction getProcedure(string name);
5542 
5543 
5545 
5554  *AbstractView getView(string name);
5555 
5556 
5558 
5567  int getNextSequenceValue(string name);
5568 
5569 
5571 
5580  string getSqlFromList(list l);
5581 
5582 
5584  bool supportsSequences();
5585 
5586 
5588  bool supportsTypes();
5589 
5590 
5592  bool supportsPackages();
5593 
5594 
5596  list listTables();
5597 
5598 
5601 
5602 
5604  list listFunctions();
5605 
5606 
5609 
5610 
5612  list listProcedures();
5613 
5614 
5617 
5618 
5620  list listSequences();
5621 
5622 
5625 
5626 
5628  list listViews();
5629 
5630 
5633 
5634 
5635  private validateOptionsIntern(string err, hash ropt, reference opt);
5636 
5637 
5638  private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
5639 
5640 
5641  static AbstractDatabase getDatabase(AbstractDatasource nds, *hash opts);
5642 
5643  static AbstractDatabase getDatabase(string dsstr, *hash opts);
5644 
5645  static AbstractDatabase getDatabase(hash dsh, *hash opts);
5646 
5647  static checkDriverOptions(reference h, string drv);
5648 
5650  private hash getDatabaseOptions();
5651 
5652 
5654  private hash getCallbackOptions();
5655 
5656 
5658  private hash getCreationOptions();
5659 
5660 
5662  private hash getCacheOptions();
5663 
5664 
5666  private hash getAlignSchemaOptions();
5667 
5668 
5670  private hash getDropSchemaOptions();
5671 
5672 
5675 
5676 
5679 
5680 
5682  private any tryExecArgsImpl(string sql, *softlist args);
5683 
5684 
5686  private any tryExecRawImpl(string sql);
5687 
5688 
5689  private abstract string getCreateSqlImpl(list l);
5690  private abstract list getAlignSqlImpl(hash schema_hash, *hash opt);
5691  private abstract list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
5692 
5693  private abstract *AbstractSequence getSequenceImpl(string name);
5694  private abstract *AbstractFunction getFunctionImpl(string name);
5695  private abstract *AbstractFunction getProcedureImpl(string name);
5696  private abstract *AbstractView getViewImpl(string name);
5697 
5698  private abstract AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
5699  private abstract AbstractFunction makeFunctionImpl(string name, string src, *hash opts);
5700  private abstract AbstractFunction makeProcedureImpl(string name, string src, *hash opts);
5701 
5702  private abstract list featuresImpl();
5703  private abstract list listTablesImpl();
5704  private abstract list listFunctionsImpl();
5705  private abstract list listProceduresImpl();
5706  private abstract list listSequencesImpl();
5707  private abstract list listViewsImpl();
5708 
5710  private abstract int getNextSequenceValueImpl(string name);
5711 
5713  private abstract bool supportsSequencesImpl();
5714  private abstract bool supportsPackagesImpl();
5715  private abstract bool supportsTypesImpl();
5716  };
5717 
5719 
5729  class Table {
5730 
5731 public:
5732  private :
5735 
5736 public:
5737 
5739 
5751  constructor(AbstractDatasource ds, string name, *hash opts);
5752 
5753 
5755 
5767  constructor(string ds, string name, *hash opts);
5768 
5769 
5771 
5791  constructor(hash ds, string name, *hash opts);
5792 
5793 
5795 
5803  constructor(AbstractDatasource ds, hash desc, string name, *hash opts);
5804 
5805 
5807 
5818  setDatasource(AbstractDatasource nds);
5819 
5820 
5822  commit();
5823 
5824 
5826  rollback();
5827 
5828 
5830  string getName();
5831 
5832 
5835 
5836 
5839 
5840 
5842  any methodGate(string meth);
5843 
5844 
5846 
5853  bool inDb();
5854 
5855 
5857 
5863  setupTable(hash desc, *hash opt);
5864 
5865 
5867 
5875 
5876 
5878 
5889  drop(*hash opt);
5890 
5891 
5893 
5904  dropNoCommit(*hash opt);
5905 
5906 
5908 
5919  any tryExec(string sql);
5920 
5921 
5923 
5933  any tryExecArgs(string sql, *softlist args);
5934 
5935 
5937 
5948  any tryExecRaw(string sql);
5949 
5950 
5952 
5959  truncate();
5960 
5961 
5963 
5970  truncateNoCommit();
5971 
5972 
5974 
5989  string getTruncateSql(*hash opt);
5990 
5991 
5993 
6004  create(*hash opt);
6005 
6006 
6008 
6017  createNoCommit(*hash opt);
6018 
6019 
6021 
6032  rename(string new_name, *reference sql, *Tables table_cache);
6033 
6034 
6036 
6047  bool emptyData();
6048 
6049 
6051 
6060  bool empty();
6061 
6062 
6064 
6088  AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
6089 
6090 
6092 
6120  list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
6121 
6122 
6124 
6150  AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
6151 
6152 
6154 
6180  list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
6181 
6182 
6184 
6200  AbstractColumn renameColumn(string old_name, string new_name, reference sql);
6201 
6202 
6204 
6222  string getRenameColumnSql(string old_name, string new_name, *hash opt);
6223 
6224 
6226 
6247  AbstractPrimaryKey addPrimaryKey(string cname, softlist cols, *hash opt, *reference sql);
6248 
6249 
6251 
6273  string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
6274 
6275 
6277 
6295  AbstractPrimaryKey dropPrimaryKey(*reference lsql);
6296 
6297 
6299 
6319 
6320 
6322 
6345  AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql);
6346 
6347 
6349 
6369  string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
6370 
6371 
6373 
6395  AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql);
6396 
6397 
6399 
6420  string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
6421 
6422 
6424 
6436  AbstractIndex renameIndex(string old_name, string new_name, reference sql);
6437 
6438 
6440 
6459  string getDropIndexSql(string iname, *hash opt);
6460 
6461 
6463 
6482  string getDropConstraintSql(string cname, *hash opt);
6483 
6484 
6486 
6505  *string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref);
6506 
6507 
6509 
6527  AbstractIndex dropIndex(string iname, *reference sql);
6528 
6529 
6531 
6554  AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
6555 
6556 
6558 
6580  string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
6581 
6582 
6584 
6602  AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql);
6603 
6604 
6606 
6622 
6623 
6625 
6645  AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql);
6646 
6647 
6649 
6671  string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
6672 
6673 
6675 
6687  AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
6688 
6689 
6691 
6709  AbstractConstraint dropConstraint(string cname, *reference sql);
6710 
6711 
6713 
6733  AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
6734 
6735 
6737 
6759  list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
6760 
6761 
6763 
6781  AbstractTrigger dropTrigger(string tname, *reference sql);
6782 
6783 
6785 
6804  list getDropTriggerSql(string tname, *hash opt);
6805 
6806 
6808 
6819  string getSqlValue(any v);
6820 
6821 
6823 
6839  AbstractColumn dropColumn(string cname, *reference lsql);
6840 
6841 
6843 
6862  list getDropColumnSql(string cname, *hash opt);
6863 
6864 
6866 
6876  insert(hash row, *reference sql);
6877 
6878 
6880 
6890  insertNoCommit(hash row, *reference sql);
6891 
6892 
6894 
6904  insert(hash row, *hash opt);
6905 
6906 
6908 
6918  insertNoCommit(hash row, *hash opt);
6919 
6920 
6922 
6940  int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql);
6941 
6942 
6944 
6962  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql);
6963 
6964 
6966 
6984  int insertFromSelect(list cols, AbstractTable source, *hash sh, *hash opt);
6985 
6986 
6988 
7006  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *hash opt);
7007 
7008 
7010 
7029 
7030 
7032 
7051 
7052 
7054 
7074  int upsert(hash row, int upsert_strategy = AbstractTable::UpsertAuto);
7075 
7076 
7078 
7098  int upsertNoCommit(hash row, int upsert_strategy = AbstractTable::UpsertAuto);
7099 
7100 
7102 
7127  code getUpsertClosure(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto);
7128 
7129 
7131 
7156  code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = AbstractTable::UpsertAuto);
7157 
7158 
7160 
7190 
7191 
7193 
7223 
7224 
7226 
7263  *hash upsertFromSelect(AbstractTable src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7264 
7265 
7267 
7306  *hash upsertFromSelectNoCommit(AbstractTable src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7307 
7308 
7310 
7347  *hash upsertFromSelect(Table src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7348 
7349 
7351 
7390  *hash upsertFromSelectNoCommit(Table src, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
7391 
7392 
7394 
7405  softint rowCount();
7406 
7407 
7409 
7426  Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql);
7427 
7428 
7430 
7448 
7449 
7451 
7467  *hash selectRow(*hash sh, *reference sql);
7468 
7469 
7471 
7486  *list selectRows(*hash sh, *reference sql);
7487 
7488 
7490 
7505  *hash select(*hash sh, *reference sql);
7506 
7507 
7509 
7525  *hash selectRow(*hash sh, *hash opt);
7526 
7527 
7529 
7544  *list selectRows(*hash sh, *hash opt);
7545 
7546 
7548 
7563  *hash select(*hash sh, *hash opt);
7564 
7565 
7567 
7585  string getSelectSql(*hash sh, *reference args);
7586 
7587 
7589 
7603  int del(*hash cond, *reference sql);
7604 
7605 
7607 
7621  int delNoCommit(*hash cond, *reference sql);
7622 
7623 
7625 
7641  int update(hash set, *hash cond, *reference sql);
7642 
7643 
7645 
7661  int updateNoCommit(hash set, *hash cond, *reference sql);
7662 
7663 
7665 
7679  int del(*hash cond, *hash opt);
7680 
7681 
7683 
7697  int delNoCommit(*hash cond, *hash opt);
7698 
7699 
7701 
7717  int update(hash set, *hash cond, *hash opt);
7718 
7719 
7721 
7737  int updateNoCommit(hash set, *hash cond, *hash opt);
7738 
7739 
7741 
7750  string getSqlFromList(list l);
7751 
7752 
7754 
7772  string getRenameSql(string new_name, *hash opt);
7773 
7774 
7776 
7787  string getCreateSqlString(*hash opt);
7788 
7789 
7791 
7800  list getCreateSql(*hash opt);
7801 
7802 
7804 
7815  string getCreateTableSql(*hash opt);
7816 
7817 
7819 
7830  *list getCreateIndexesSql(*hash opt);
7831 
7832 
7834 
7845  *string getCreatePrimaryKeySql(*hash opt);
7846 
7847 
7849 
7861 
7862 
7864 
7878 
7879 
7881 
7892  *list getCreateMiscSql(*hash opt);
7893 
7894 
7896 
7908 
7909 
7911 
7924  list getAlignSql(AbstractTable table, *hash opt);
7925 
7926 
7928 
7941  list getAlignSql(Table table, *hash opt);
7942 
7943 
7945 
7958  string getAlignSqlString(AbstractTable table, *hash opt);
7959 
7960 
7962 
7975  string getAlignSqlString(Table table, *hash opt);
7976 
7977 
7979 
7990  *hash find(any id);
7991 
7992 
7994 
8005  *list find(list ids);
8006 
8007 
8009 
8020  *hash find(hash row);
8021 
8022 
8024 
8039  *hash findSingle(*hash cond);
8040 
8041 
8043 
8056  *list findAll(*hash cond);
8057 
8058 
8060 
8067  cache(*hash opts);
8068 
8069 
8071 
8077  clear();
8078 
8079 
8081 
8088  Columns describe();
8089 
8090 
8092 
8102 
8103 
8105 
8115 
8116 
8118 
8127  Indexes getIndexes();
8128 
8129 
8131 
8141 
8142 
8145 
8146 
8149 
8150 
8152  string getDriverName();
8153 
8154  };
8155 
8158 
8159 public:
8160  public :
8162 
8166  const TableOptions = (
8167  "native_case": Type::Boolean,
8168  "table_cache": "Tables",
8169  );
8170 
8172 
8176  const IndexOptions = (
8177  "index_tablespace": Type::String,
8178  "replace": Type::Boolean,
8179  );
8180 
8182 
8185 
8187  const CacheOptions = (
8188  "table_cache": "Tables",
8189  );
8190 
8192 
8196  "table_cache": "Tables",
8197  );
8198 
8200 
8203 
8205 
8217  const SelectOptions = (
8218  "comment": Type::String,
8219  "hint": Type::String,
8220  "columns": Type::NothingType,
8221  "where": "hash/list",
8222  "orderby": "softstringhashlist",
8223  "desc": Type::Boolean,
8224  "limit": Type::Int,
8225  "offset": Type::Int,
8226  "join": Type::Hash,
8227  "groupby": "softstringhashlist",
8228  "having": Type::Hash,
8229  "superquery": Type::Hash,
8230  );
8231 
8234  "indexes": True,
8235  "foreign_constraints": True,
8236  "triggers": True,
8237  );
8238 
8240 
8244  "omit": "softstringlist",
8245  );
8246 
8248 
8256  "column_map": Type::Hash,
8257  "index_map": Type::Hash,
8258  "constraint_map": Type::Hash,
8259  "trigger_map": Type::Hash,
8260  "db_table_cache": "Tables",
8261  );
8262 
8264 
8276  "columns": Type::Hash,
8277  "primary_key": Type::Hash,
8278  "indexes": Type::Hash,
8279  "triggers": Type::Hash,
8280  "foreign_constraints": Type::Hash,
8281  "unique_constraints": Type::Hash,
8282  //"check_constraints": Type::Hash,
8283  "table_cache": "Tables",
8284  );
8285 
8287 
8299  "qore_type": Type::String,
8300  "native_type": Type::String,
8301  "size": Type::Int,
8302  "scale": Type::Int,
8303  "default_value": Type::NothingType,
8304  "comment": Type::String,
8305  );
8306 
8308 
8312  "notnull": Type::Boolean,
8313  );
8314 
8316  const ColumnOptions = hash();
8317 
8319 
8323  "sqlarg_callback": "code",
8324  );
8325 
8327 
8332  const UpsertOptions = (
8333  "info_callback": "code",
8334  "commit_block": Type::Int,
8335  "delete_others": Type::Boolean,
8336  );
8337 
8339 
8344  "info_callback": "code",
8345  "commit_block": Type::Int,
8346  );
8347 
8362 
8369 
8371 
8377 
8379 
8386 
8388 
8392  const UpsertAuto = 4;
8393 
8395 
8399  const UpsertInsertOnly = 5;
8401 
8406  const UR_Inserted = 1;
8408 
8410  const UR_Verified = 2;
8411 
8413  const UR_Updated = 3;
8414 
8416  const UR_Unchanged = 4;
8417 
8419  const UR_Deleted = 5;
8421 
8423 
8426  UR_Inserted: "inserted",
8427  UR_Verified: "verified",
8428  UR_Updated: "updated",
8429  UR_Unchanged: "unchanged",
8430  UR_Deleted: "deleted",
8431  );
8432 
8434 
8437  "inserted": UR_Inserted,
8438  "verified": UR_Verified,
8439  "updated": UR_Updated,
8440  "unchanged": UR_Unchanged,
8441  "deleted": UR_Deleted,
8442  );
8443 
8446  UR_Inserted: "I",
8447  UR_Verified: "V",
8448  UR_Updated: "U",
8449  UR_Unchanged: ".",
8450  UR_Deleted: "X",
8451  );
8452 
8453 public:
8454 
8455  private :
8457  string name;
8473  bool inDb = False;
8475  bool manual = False;
8476 
8477 public:
8478 
8480 
8486  private constructor(AbstractDatasource nds, string nname, *hash nopts);
8487 
8488 
8490  copy(AbstractTable old);
8491 
8492 
8494 
8505  setDatasource(AbstractDatasource nds);
8506 
8507 
8508  private doTableOptions(*hash nopts);
8509 
8510 
8512  commit();
8513 
8514 
8516  rollback();
8517 
8518 
8520 
8527  bool inDb();
8528 
8529 
8531 
8539 
8540 
8542 
8553  drop(*hash opt);
8554 
8555 
8557 
8568  any tryExec(string sql);
8569 
8570 
8572 
8582  any tryExecArgs(string sql, *softlist args);
8583 
8584 
8586 
8597  any tryExecRaw(string sql);
8598 
8599 
8601 
8612  dropNoCommit(*hash opt);
8613 
8614 
8616 
8626  softlist getDropSql(*hash opt);
8627 
8628 
8630 
8637  truncate();
8638 
8639 
8641 
8648  truncateNoCommit();
8649 
8650 
8652 
8667  string getTruncateSql(*hash opt);
8668 
8669 
8671 
8680  create(*hash opt);
8681 
8682 
8684 
8695  createNoCommit(*hash opt);
8696 
8697 
8699 
8710  rename(string new_name, *reference sql, *Tables table_cache);
8711 
8712 
8713  private doRenameIntern(string new_name, *Tables table_cache);
8714 
8715 
8717 
8728  bool emptyData();
8729 
8730 
8732 
8741  bool empty();
8742 
8743 
8744  private bool emptyUnlocked();
8745 
8746 
8748 
8754  setupTable(hash desc, *hash opt);
8755 
8756 
8758 
8781  AbstractColumn addColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8782 
8783 
8785 
8813  list getAddColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8814 
8815 
8816  private AbstractColumn addColumnUnlocked(string cname, hash opt, bool nullable = True, *reference lsql, bool do_exec = True, bool modify_table = True);
8817 
8818 
8819  private addColumnToTableUnlocked(AbstractColumn c);
8820 
8821 
8823 
8847  AbstractColumn modifyColumn(string cname, hash opt, bool nullable = True, *reference lsql);
8848 
8849 
8851 
8877  list getModifyColumnSql(string cname, hash copt, bool nullable = True, *hash opt);
8878 
8879 
8881 
8898  AbstractColumn renameColumn(string old_name, string new_name, reference sql);
8899 
8900 
8902 
8920  string getRenameColumnSql(string old_name, string new_name, *hash opt);
8921 
8922 
8923  private AbstractColumn renameColumnIntern(AbstractColumn c, string new_name);
8924 
8925 
8926  private validateOptionsIntern(string err, hash ropt, reference opt);
8927 
8928 
8929  private validateOptionsIntern(string err, hash ropt, reference opt, string tag);
8930 
8931 
8932  private execSql(softlist lsql);
8933 
8934 
8936 
8956  AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql);
8957 
8958 
8960 
8982  string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt);
8983 
8984 
8985  private setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
8986 
8987 
8988  private AbstractPrimaryKey addPrimaryKeyUnlocked(string pkname, softlist cols, *hash opt, *reference sql);
8989 
8990 
8991  private AbstractPrimaryKey addPrimaryKeyUnlockedIntern(string pkname, softlist cols, *hash opt, *reference sql);
8992 
8993 
8995 
9012 
9013 
9014  private list getDropAllConstraintsAndIndexesOnColumnSqlUnlocked(string cname, *hash opt);
9015 
9016 
9018 
9038 
9039 
9041 
9059  AbstractPrimaryKey dropPrimaryKey(*reference lsql);
9060 
9061 
9063 
9084  AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql);
9085 
9086 
9088 
9108  string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt);
9109 
9110 
9111  private AbstractUniqueConstraint addUniqueConstraintUnlocked(string cname, softlist cols, *hash opt, *reference sql);
9112 
9113 
9114  private AbstractUniqueConstraint addUniqueConstraintUnlockedIntern(string cname, softlist cols, *hash opt, *reference sql);
9115 
9116 
9118 
9139  AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql);
9140 
9141 
9143 
9164  string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt);
9165 
9166 
9167  private AbstractIndex addIndexUnlocked(string iname, bool unique, softlist cols, *hash opt, *reference sql);
9168 
9169 
9170  private AbstractIndex addIndexUnlockedIntern(string iname, bool unique, softlist cols, *hash opt, *reference sql);
9171 
9172 
9174 
9186  AbstractIndex renameIndex(string old_name, string new_name, reference sql);
9187 
9188 
9190 
9208  AbstractIndex dropIndex(string iname, *reference sql);
9209 
9210 
9212 
9231  string getDropIndexSql(string iname, *hash opt);
9232 
9233 
9235 
9257  AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
9258 
9259 
9261 
9283  string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt);
9284 
9285 
9286  private Columns getReferencedTableColumnsUnlocked(string table, *Tables cache, string err = "FOREIGN-CONSTRAINT-ERROR");
9287 
9288 
9289  private AbstractForeignConstraint addForeignConstraintUnlocked(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
9290 
9291 
9292  private AbstractForeignConstraint addForeignConstraintUnlockedIntern(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql);
9293 
9294 
9296 
9314  AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql);
9315 
9316 
9318 
9334 
9335 
9337 
9357  AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql);
9358 
9359 
9361 
9383  string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt);
9384 
9385 
9386  private AbstractCheckConstraint addCheckConstraintUnlocked(string cname, string src, *hash opt, *reference sql);
9387 
9388 
9389  private AbstractCheckConstraint addCheckConstraintUnlockedIntern(string cname, string src, *hash opt, *reference sql);
9390 
9391 
9393 
9405  AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql);
9406 
9407 
9409 
9428  string getDropConstraintSql(string cname, *hash opt);
9429 
9430 
9432 
9451  *string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref);
9452 
9453 
9454  private AbstractConstraint findDropConstraintUnlocked(string cname, reference rmv);
9455 
9456 
9458 
9476  AbstractConstraint dropConstraint(string cname, *reference sql);
9477 
9478 
9480 
9500  AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql);
9501 
9502 
9504 
9526  list getAddTriggerSql(string tname, string src, *hash topt, *hash opt);
9527 
9528 
9529  private AbstractTrigger addTriggerUnlocked(string tname, string src, *hash opt, *reference lsql);
9530 
9531 
9532  private AbstractTrigger addTriggerUnlockedIntern(string tname, string src, *hash opt, *reference lsql);
9533 
9534 
9536 
9554  AbstractTrigger dropTrigger(string tname, *reference sql);
9555 
9556 
9558 
9577  list getDropTriggerSql(string tname, *hash opt);
9578 
9579 
9580  private getAllConstraintsUnlocked(*hash opt);
9581 
9582 
9583  private checkUniqueConstraintName(string err, string cname);
9584 
9585 
9586  private checkUniqueConstraintNameValidateOptions(string err, string cname, hash ropt, reference opt);
9587 
9588 
9590  private validateColumnOptions(string cname, reference opt, bool nullable);
9591 
9592 
9594 
9612  AbstractColumn dropColumn(string cname, *reference lsql);
9613 
9614 
9616 
9635  list getDropColumnSql(string cname, *hash opt);
9636 
9637 
9639 
9649  insert(hash row, *reference sql);
9650 
9651 
9653 
9663  insertNoCommit(hash row, *reference sql);
9664 
9665 
9666  private insertNoCommitIntern(hash row, *reference sql, *hash opt);
9667 
9668 
9670 
9680  insert(hash row, *hash opt);
9681 
9682 
9684 
9694  insertNoCommit(hash row, *hash opt);
9695 
9696 
9698 
9716  int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql);
9717 
9718 
9720 
9738  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql);
9739 
9740 
9741  private int insertFromSelectNoCommitIntern(list cols, AbstractTable source, *hash sh, *reference sql, *hash opt);
9742 
9743 
9745 
9763  int insertFromSelect(list cols, AbstractTable source, *hash sh, *hash opt);
9764 
9765 
9767 
9785  int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *hash opt);
9786 
9787 
9789 
9808 
9809 
9811 
9830 
9831 
9832  private int insertFromIteratorNoCommitIntern(Qore::AbstractIterator i, *hash opt);
9833 
9834 
9836 
9851  int upsert(hash row, int upsert_strategy = UpsertAuto);
9852 
9853 
9855 
9870  int upsertNoCommit(hash row, int upsert_strategy = UpsertAuto);
9871 
9872 
9874 
9894  code getUpsertClosure(hash example_row, int upsert_strategy = UpsertAuto);
9895 
9896 
9898 
9918  code getUpsertClosureWithValidation(hash example_row, int upsert_strategy = UpsertAuto);
9919 
9920 
9922 
9955 
9956 
9958 
9991 
9992 
9993  private *hash upsertFromIteratorNoCommitIntern(Qore::AbstractIterator i, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
9994 
9995 
9996  private *hash doDeleteOthersIntern(hash pkh, *hash opt);
9997 
9998 
10000 
10038  *hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10039 
10040 
10042 
10082  *hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10083 
10084 
10086 
10124  *hash upsertFromSelect(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10125 
10126 
10128 
10168  *hash upsertFromSelectNoCommit(Table t, *hash sh, int upsert_strategy = AbstractTable::UpsertAuto, *hash opt);
10169 
10170 
10172 
10183  softint rowCount();
10184 
10185 
10187 
10204  Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql);
10205 
10206 
10207  private Qore::SQL::SQLStatement getRowIteratorIntern(*hash sh, *reference sql, *hash opt);
10208 
10209 
10211 
10229 
10230 
10232 
10248  *hash selectRow(*hash sh, *reference sql);
10249 
10250 
10252 
10267  *list selectRows(*hash sh, *reference sql);
10268 
10269 
10271 
10286  *hash select(*hash sh, *reference sql);
10287 
10288 
10290 
10306  *hash selectRow(*hash sh, *hash opt);
10307 
10308 
10310 
10325  *list selectRows(*hash sh, *hash opt);
10326 
10327 
10329 
10344  *hash select(*hash sh, *hash opt);
10345 
10346 
10348 
10366  string getSelectSql(*hash sh, *reference args);
10367 
10368 
10369  *AbstractUniqueConstraint matchAnyUnique(list cols);
10370 
10371 
10372  string getSelectSqlIntern(*hash qh, reference args);
10373 
10374 
10375  string getSelectSqlUnlocked(*hash qh, reference args);
10376 
10377 
10378  string getSelectSqlUnlockedIntern(*hash qh, string from, reference args, *hash ch);
10379 
10380 
10381  private string getSelectSqlName(*hash qh);
10382 
10383 
10384  private string getColumnExpressionIntern(any cvc, *hash jch, bool join, *hash ch);
10385 
10386 
10387  private string doColumnOperatorIntern(hash cvc, *hash jch, bool join, *hash ch);
10388 
10389 
10390  private string doColumnOperatorIntern(any cop, any arg, *string cve, hash cm, *hash jch, bool join, *hash ch);
10391 
10392 
10393  private string getColumnNameIntern(string cv, *hash jch, bool join, *hash ch);
10394 
10395 
10396  private getSelectWhereSqlUnlocked(reference sql, reference args, *hash qh, *hash jch, bool join = False, *hash ch);
10397 
10398 
10399  private *string getWhereClause(*hash cond, reference args, *string cprefix, *hash jch, bool join = False);
10400 
10401 
10402  private *string getWhereClause(list cond, reference args, *string cprefix, *hash jch, bool join = False);
10403 
10404 
10405  private *string getWhereClauseUnlocked(list cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch);
10406 
10407 
10408  private *string getWhereClauseUnlocked(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash pch);
10409 
10410 
10411  private *list getWhereClauseIntern(*hash cond, reference args, *string cprefix, *hash jch, bool join = False, *hash ch);
10412 
10413 
10414  private string doWhereExpressionIntern(string cn, any we, reference args, *hash jch, bool join = False, *hash ch);
10415 
10416 
10417  private list getOrderByListUnlocked(*hash qh, *hash jch, *hash ch);
10418 
10419 
10420  private doSelectOrderBySqlUnlocked(reference sql, reference args, *hash qh, *hash jch, *hash ch);
10421 
10422 
10424 
10438  int del(*hash cond, *reference sql);
10439 
10440 
10442 
10456  int delNoCommit(*hash cond, *reference sql);
10457 
10458 
10459  private int delNoCommitIntern(*hash cond, *reference sql, *hash opt);
10460 
10461 
10463 
10479  int update(hash set, *hash cond, *reference sql);
10480 
10481 
10483 
10499  int updateNoCommit(hash set, *hash cond, *reference sql);
10500 
10501 
10502  private int updateNoCommitIntern(hash set, *hash cond, *reference sql, *hash opt);
10503 
10504 
10506 
10520  int del(*hash cond, *hash opt);
10521 
10522 
10524 
10538  int delNoCommit(*hash cond, *hash opt);
10539 
10540 
10542 
10558  int update(hash set, *hash cond, *hash opt);
10559 
10560 
10562 
10578  int updateNoCommit(hash set, *hash cond, *hash opt);
10579 
10580 
10581  private string getUpdateExpression(string col, hash uh);
10582 
10583 
10584  private bool emptyDataUnlocked();
10585 
10586 
10587  private code getUpsertClosureUnlocked(hash row, int upsert_strategy = UpsertAuto);
10588 
10589 
10590  private code getUpsertInsertFirst(Columns cols, hash example_row);
10591 
10592 
10593  private code getUpsertUpdateFirst(Columns cols, hash example_row);
10594 
10595 
10596  private code getUpsertSelectFirst(Columns cols, hash example_row);
10597 
10598 
10599  private code getUpsertInsertOnly(Columns cols, hash example_row);
10600 
10601 
10602  private Columns getUpsertColumns(reference csrc);
10603 
10604 
10605  private string getUpsertSelectSql(hash row, Columns cols, reference updc);
10606 
10607 
10608  private string getUpsertInsertSql(hash row);
10609 
10610 
10611  private string getUpsertUpdateSql(hash row, Columns cols, reference updc);
10612 
10613 
10614  private softbool tryUpdate(string sql, hash row, Columns cols, list updc);
10615 
10616 
10617  private checkValue(string cname, string argname, reference val, string type);
10618 
10619 
10621 
10630  string getSqlFromList(list l);
10631 
10632 
10634 
10645  string getSqlValue(any v);
10646 
10647 
10649  string getName();
10650 
10651 
10653 
10660  cache(*hash opts);
10661 
10662 
10664 
10669  clear();
10670 
10671 
10673 
10680  Columns describe();
10681 
10682 
10684 
10693 
10694 
10696 
10706 
10707 
10708  *AbstractUniqueConstraint findUniqueConstraintUnlocked(string name);
10709 
10710 
10712 
10721  Indexes getIndexes();
10722 
10723 
10726 
10727 
10730 
10731 
10733 
10743 
10744 
10746 
10764  string getRenameSql(string new_name, *hash opt);
10765 
10766 
10768 
10777  string getCreateSqlString(*hash opt);
10778 
10779 
10781 
10790  list getCreateSql(*hash opt);
10791 
10792 
10794 
10805  string getCreateTableSql(*hash opt);
10806 
10807 
10809  bool checkExistence();
10810 
10811 
10812  private *hash getCheckOmissionOptions(*softlist ol, string err);
10813 
10814 
10816 
10832 
10833 
10834  private list getAlignSqlUnlocked(AbstractTable t, *hash opt);
10835 
10836 
10837  private renameIndexUnlocked(AbstractIndex ix, string new_name);
10838 
10839 
10841 
10854  string getAlignSqlString(AbstractTable t, *hash opt);
10855 
10856 
10858 
10870  *list getCreateIndexesSql(*hash opt, bool cache = True);
10871 
10872 
10874 
10886  *string getCreatePrimaryKeySql(*hash opt, bool cache = True);
10887 
10888 
10890 
10903 
10904 
10906 
10920  *list getCreateConstraintsSql(*hash opt, bool cache = True);
10921 
10922 
10924 
10936  *list getCreateMiscSql(*hash opt, bool cache = True);
10937 
10938 
10940 
10954  *list getCreateTriggersSql(*hash opt, bool cache = True);
10955 
10956 
10958 
10965  *hash find(any id);
10966 
10967 
10969 
10980  *list find(list ids);
10981 
10982 
10983  private string getPrimaryKeyColumn();
10984 
10985 
10987 
11000  *hash find(hash row);
11001 
11002 
11004 
11017  *hash findSingle(*hash cond);
11018 
11019 
11021 
11034  *list findAll(*hash cond);
11035 
11036 
11038  string getSqlName();
11039 
11040 
11042 
11044  private hash getTableOptions();
11045 
11046 
11048 
11051 
11052 
11054 
11056  private hash getConstraintOptions();
11057 
11058 
11060 
11062  private hash getCacheOptions();
11063 
11064 
11066 
11068  private hash getTableCreationOptions();
11069 
11070 
11072 
11074  private hash getAlignTableOptions();
11075 
11076 
11078 
11081 
11082 
11084 
11086  private hash getColumnOptions();
11087 
11088 
11090 
11092  private hash getColumnDescOptions();
11093 
11094 
11096 
11098  private hash getTableColumnDescOptions();
11099 
11100 
11102 
11104  private hash getIndexOptions();
11105 
11106 
11108 
11110  private hash getTriggerOptions();
11111 
11112 
11114 
11116  private hash getSelectOptions();
11117 
11118 
11120 
11122  private hash getUpsertOptions();
11123 
11124 
11126 
11128  private hash getInsertOptions();
11129 
11130 
11132 
11134  private hash getSqlDataCallbackOptions();
11135 
11136 
11138 
11140  private hash getWhereOperatorMap();
11141 
11142 
11144 
11146  private hash getColumnOperatorMap();
11147 
11148 
11150 
11152  private hash getUpdateOperatorMap();
11153 
11154 
11155  private string getCreateTableSqlUnlocked(*hash opt);
11156 
11157 
11158  private *list getCreateIndexesSqlUnlocked(*hash opt, bool cache = True);
11159 
11160 
11161  private *string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
11162 
11163 
11164  private *list getCreateConstraintsSqlUnlocked(*hash opt, bool cache = True);
11165 
11166 
11167  private *list getCreateForeignConstraintsSqlUnlocked(*hash opt, bool cache = True);
11168 
11169 
11170  private *list getCreateMiscSqlUnlocked(*hash opt, bool cache = True);
11171 
11172 
11173  private *list getCreateTriggersSqlUnlocked(*hash opt, bool cache = True);
11174 
11175 
11176  private list getCreateSqlUnlocked(*hash opt, bool cache = True);
11177 
11178 
11179  private cacheUnlocked(*hash opt);
11180 
11181 
11182  private any execData(*hash opt, string sql, *list args);
11183 
11184 
11185  private execData(SQLStatement stmt, *hash opt, *list args);
11186 
11187 
11188  static AbstractTable getTable(AbstractDatasource nds, string nname, *hash opts);
11189 
11190  static AbstractTable getTable(string dsstr, string nname, *hash opts);
11191 
11192  static AbstractTable getTable(hash dsh, string nname, *hash opts);
11193 
11194  private getColumnsUnlocked();
11195 
11196 
11197  private getPrimaryKeyUnlocked();
11198 
11199 
11200  // also loads primary key and constraints (for unique constraints)
11201  private getIndexesUnlocked();
11202 
11203 
11204  private getForeignConstraintsUnlocked(*hash opt);
11205 
11206 
11207  private addSourceConstraint(string table_name, AbstractForeignConstraint fk);
11208 
11209 
11210  private getConstraintsUnlocked();
11211 
11212 
11213  private getTriggersUnlocked();
11214 
11215 
11216  private softlist getDropSqlImpl();
11217 
11218 
11219  private string getTruncateSqlImpl();
11220 
11221 
11223  private any tryExecArgsImpl(string sql, *softlist args);
11224 
11225 
11227  private any tryExecRawImpl(string sql);
11228 
11229 
11231  private clearImpl();
11232 
11233 
11234  private preSetupTableImpl(reference desc, *hash opt);
11235 
11236 
11237  private abstract bool emptyImpl();
11238 
11240  private abstract *string getSqlValueImpl(any v);
11241 
11243 
11246  private abstract bool checkExistenceImpl();
11247 
11249  private abstract bool supportsTablespacesImpl();
11250 
11252  private abstract bool constraintsLinkedToIndexesImpl();
11253 
11255  private abstract bool uniqueIndexCreatesConstraintImpl();
11256 
11257  private abstract setupTableImpl(hash desc, *hash opt);
11258 
11259  private abstract Columns describeImpl();
11260  private abstract AbstractPrimaryKey getPrimaryKeyImpl();
11261  private abstract Indexes getIndexesImpl();
11262  private abstract ForeignConstraints getForeignConstraintsImpl(*hash opt);
11263  private abstract Constraints getConstraintsImpl();
11264  private abstract Triggers getTriggersImpl();
11265 
11266  private abstract string getCreateTableSqlImpl(*hash opt);
11267  private abstract *list getCreateMiscSqlImpl(*hash opt, bool cache);
11268  private abstract string getCreateSqlImpl(list l);
11269  private abstract string getRenameSqlImpl(string new_name);
11270  private abstract *list getAlignSqlImpl(AbstractTable t, *hash opt);
11271 
11272  private abstract AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
11273  private abstract AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
11274  private abstract AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
11275  private abstract AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
11276  private abstract AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
11277  private abstract AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
11278 
11279  private abstract AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
11280 
11282  private abstract bool tryInsertImpl(string sql, hash row);
11283 
11285  private abstract hash getQoreTypeMapImpl();
11286 
11288  private abstract hash getTypeMapImpl();
11289 
11291  private abstract doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch);
11292 
11294  private abstract doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh);
11295 
11297  private abstract copyImpl(AbstractTable old);
11298  };
11299 
11300 /*
11301  public class Sqlite3Table inherits AbstractTable {
11302 
11303  public {
11304  const Sqlite3TypeMap = (
11305  "INTEGER": ("qore": "integer",),
11306  "NUMERIC": ("qore": "number",),
11307  "TEXT": ("qore": "string",),
11308  "BLOB": ("qore": "binary",),
11309  "NONE": ("qore": "any",),
11310  "REAL": ("qore": "float",),
11311  );
11312 
11313  const QoreTypeMap = (
11314  "integer": "INTEGER",
11315  "float": "NUMBER",
11316  "number": "NUMBER",
11317  "string": "VARCHAR2",
11318  #"date": "TIMESTAMP",
11319  "binary": "BLOB",
11320  );
11321  }
11322 
11323  constructor(AbstractDatasource nds, string nname, *hash opts) : AbstractTable(nds, nname, opts) {
11324  }
11325 
11326  private hash describeImpl() {
11327  hash rv;
11328 
11329  # NOTE: sqlite3's pragmas cannot use %v binding
11330 
11331  # table info - PK is part of the table description
11332  hash tableInfo = ds.select("pragma table_info(%s)", name);
11333  context(tableInfo) {
11334  rv.columns{%name} = (
11335  "native_type" : %type,
11336  "qore_type" : Sqlite3TypeMap{%type}.qore,
11337  "size" : NOTHING,
11338  "nullable" : %notnull == 1 ? NOTHING : "YES",
11339  );
11340  if (%pk)
11341  rv.primary_key{%name} = True;
11342  }
11343 
11344  # get index description
11345  hash indexes = ds.select("pragma index_list(%s)", name);
11346  context(indexes) {
11347  rv.indexes{%name}.unique = %unique == 0 ? False : True;
11348  hash indexColumns = ds.select("pragma index_info(%s)", %name);
11349  string columnName = %name;
11350  context (indexColumns) {
11351  rv.indexes{columnName}.columns{%name} = True;
11352  }
11353  }
11354 
11355  # TODO/FIXME: FKs
11356 
11357  return rv;
11358  }
11359  }
11360 */
11361 }
11362 
abstract string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
const ActionMap
maps from action codes to action descriptions
Definition: SqlUtil.qm.dox.h:4991
list getAlignSql(AbstractTable table, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
string name
the name of the constraint
Definition: SqlUtil.qm.dox.h:3916
string getRenameColumnSql(string old_name, string new_name, *hash opt)
gets an SQL string that can be used to rename an existing column in the table
constructor(string n_name, number n_start=1, number n_increment=1, *softnumber n_max)
creates the object from the arguments
int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
hash cop_avg(any column)
returns a hash for the &quot;avg&quot; operator; returns average column values
string getElementName()
returns &quot;column&quot; since this object stores column objects
softlist getDropSql(*hash opt)
returns the sql required to drop the table; reimplement in subclasses if necessary ...
bool hasColumn(string cname)
returns True if the constraint references the named column
constructor()
creates an empty object
*string index
the index supporting the constraint
Definition: SqlUtil.qm.dox.h:4004
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql)
adds an index to the table; if the table is already known to be in the database, then it is added in ...
createNoCommit(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
const SelectOptions
default select options
Definition: SqlUtil.qm.dox.h:8217
string getDropSql()
returns a string that can be used to drop the function from the database
Constraints getConstraints()
returns a Constraints object describing the non-foreign constraints on the table
private hash getCacheOptions()
returns the cache options for this driver
*hash find(any id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:4185
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...
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
Qore::AbstractIterator pairIterator()
Returns a HashPairIterator object for the contained hash.
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
const Hash
const UpsertAuto
Upsert option: if the target table is empty, use UpsertInsertFirst, otherwise use UpsertUpdateFirst...
Definition: SqlUtil.qm.dox.h:8392
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
list getAlignProcedureSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a stored procedure in the database to the st...
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
const String
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
hash op_cge(string arg)
returns a hash for the &quot;&gt;=&quot; operator with the given argument for use in where clauses when comparing ...
int updateNoCommit(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
private hash getTriggerOptions()
returns the trigger options for this driver
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:3308
*list getCreateTriggersSql(*hash opt)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
const TableOmissionOptions
alignment omission options
Definition: SqlUtil.qm.dox.h:8233
string getDropSql()
returns a string that can be used to drop the sequence from the database
list getDropSchemaSql(hash schema_hash, *hash opt)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
copy(AbstractHashContainer old)
creates a &quot;deep copy&quot; of the object
hash cop_append(any column, string arg)
returns a hash for the &quot;append&quot; operator with the given argument
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,...)
constructor(*hash nh)
creates the object with the hash argument passed
Qore::ListIterator iterator()
Returns a ListIterator object for the contained list.
private hash getDatabaseOptions()
override in subclasses to return driver-specific options
const AC_Unchanged
used when an existing object matches the template and no changes are made
Definition: SqlUtil.qm.dox.h:4954
string getElementName()
must return the name of the contained element
bool equal(ForeignConstraintTarget targ)
returns True if the argument is equal to the current object, False if not
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table is already known to be in the database...
bool dropProcedureIfExists(string name, *hash opt)
drops the given procedure if it exists; returns True if the procedure was dropped, False if not
const OP_IN
the SQL &quot;in&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2647
bool checkExistence()
returns True if the table exists in the database, False if not
*hash getHash()
returns the hash contained by this object
the base abstract class for the table implementation
Definition: SqlUtil.qm.dox.h:8157
const DefaultCopMap
a hash of default column operator descriptions
Definition: SqlUtil.qm.dox.h:1759
bool equal(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
any methodGate(string meth)
executes a method on the contained AbstractTable object
bool equalExceptName(AbstractIndex ix)
returns True if the argument is equal to the current index with the exception of the name...
const VARCHAR
specifies a VARCHAR column (equivalent to Qore::Type::String)
Definition: SqlUtil.qm.dox.h:1622
AbstractFunction memberGate(string k)
returns the AbstractFunction object corresponding to the key given or throws a KEY-ERROR exception ...
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
hash uop_upper(*hash nest)
returns a hash for the &quot;upper&quot; operator with the given argument; returns a column value in upper case...
list getAlignFunctionSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a function in the database to the function d...
const ForeignConstraintOptions
default foreign constraint options
Definition: SqlUtil.qm.dox.h:8195
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
int delNoCommit(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; no transactio...
const ColumnOptions
Column options; this is currently empty and can be extended in database-specific modules.
Definition: SqlUtil.qm.dox.h:8316
the table container class stores a collection of tables in a schema
Definition: SqlUtil.qm.dox.h:3397
*list getCreateForeignConstraintsSql(*hash opt)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
constructor(string n)
creates the object and sets its name
bool updatable
Flag showing if is the view updatable with DML commands.
Definition: SqlUtil.qm.dox.h:4228
private hash getCreationOptions()
override in subclasses to return driver-specific options
drop(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
string getAddPrimaryKeySql(string pkname, softlist cols, *hash pkopt, *hash opt)
returns the SQL that can be used to add a primary key to the table
hash op_between(any l, any r)
returns a hash for the &quot;between&quot; operator with the given arguments, neither of which can be NULL or N...
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
const UpsertResultLetterMap
maps upsert result codes to single letter symbols
Definition: SqlUtil.qm.dox.h:8445
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
date now_us()
AbstractIndex take(string k)
removes the given key from the contained hash and returns the value
int update(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
abstract string getCreateSql(*hash opt)
returns a string that can be used to create the sequence in the database
abstract list getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the trigger in the database
const DropSchemaOptions
default generic drop schema options
Definition: SqlUtil.qm.dox.h:5060
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
hash uop_prepend(string arg, *hash nest)
returns a hash for the &quot;prepend&quot; operator with the given argument
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
const SchemaDescriptionOptions
default generic schema description keys
Definition: SqlUtil.qm.dox.h:5075
const UR_Inserted
row was inserted
Definition: SqlUtil.qm.dox.h:8407
constructor(string t, Columns c)
creates the object and sets the target table name and the target columns
constructor(string n_name, string n_src)
creates the object from the arguments
string getDriverName()
returns the database driver name
hash op_in()
returns a hash for the &quot;in&quot; operator with all arguments passed to the function; for use in where clau...
cache(*hash opts)
reads in all attributes of the table from the database
string printf(string fmt,...)
const OP_BETWEEN
the SQL &quot;between&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2642
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view cannot be found ...
int upsert(hash row, int upsert_strategy=UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
abstract any take(string k)
removes the given key from the contained hash and returns the value
const DatabaseOptions
database options
Definition: SqlUtil.qm.dox.h:4921
string getDisableSql(string table_name)
returns a string that can be used to temporarily disable the constraint from the database; if disabli...
private hash getIndexOptions()
returns the index options for this driver
the abstract base class for index information
Definition: SqlUtil.qm.dox.h:3793
*AbstractUniqueConstraint findEqualUniqueConstraint(AbstractUniqueConstraint uk)
finds a unique constraint with the same columns as the unique constraint passed
hash sourceConstraints
a hash of ForeignConstraintSources, keyed by table name, the value is a hash of foreign constraints k...
Definition: SqlUtil.qm.dox.h:4001
*AbstractUniqueConstraint getSupportingConstraint()
returns the supporting constraint, if any
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
*hash upsertFromSelectNoCommit(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
add(string k, AbstractColumn val)
adds the given value to the hash with the given key name
const COP_OVER
the SQL &quot;over&quot; clause
Definition: SqlUtil.qm.dox.h:1716
foreign constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:4078
const UpsertResultDescriptionMap
hash mapping upsert descriptions to codes
Definition: SqlUtil.qm.dox.h:8436
Columns columns
an object of class Columns giving the source table that make up the constraint
Definition: SqlUtil.qm.dox.h:4152
const UR_Deleted
row was deleted (only possible with batch upsert methods such as Table::upsertFromIterator() where up...
Definition: SqlUtil.qm.dox.h:8419
list listTables()
returns a list of string table names in the database
bool dropProcedureIfExists(string name, *hash opt)
drops the given procedure if it exists; returns True if the procedure was dropped, False if not
hash op_ne(any arg)
returns a hash for the &quot;!=&quot; or &quot;&lt;&gt;&quot; operator with the given argument for use in where clauses when co...
bool dropFunctionIfExists(string name, *hash opt)
drops the given function if it exists; returns True if the function was dropped, False if not ...
constructor(string n, *hash c, *string n_index)
creates the object from the name an a hash of column information
abstract private bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
hash make_jop(string jop, AbstractTable table, *string alias, *hash jcols, *hash cond, *string ta, *hash opt)
returns a hash keyed with the table name assigned to a hash with jop, table, jcols, cond, alias, and ta keys
clearIndex()
clears any index base for the constraint
AbstractForeignConstraint removeForeignConstraint(string cname)
removes the named foreign constraint from the table; no SQL is executed in any case, only the named foreign constraint is removed from the table definition
bool hasColumn(string cname)
returns True if the constraint references the named column
const OP_NE
the SQL not equals operator (!= or &lt;&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2602
AbstractIndex dropIndex(string iname, *reference sql)
drops the given index from the table; if the table is known to be in the database already...
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table
list listSequences()
returns a list of string sequence names in the database
setSupportingConstraint()
clears the supporting constraint
hash cop_as(any column, string arg)
returns a hash for the &quot;as&quot; operator with the given argument
private hash getSchemaDescriptionOptions()
override in subclasses to return driver-specific options
string getType()
returns the type of object
any methodGate(string meth)
executes a method on the contained AbstractDatabase object
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
abstract softlist getRenameSql(string new_name)
returns a list with command(s) that can be used to rename the view in the database ...
hash cop_year_month(any column)
returns a hash for the &quot;year_month&quot; operator with the given argument
list getAlignSql(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns a list of SQL strings required to align the structure a...
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from the database
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
private constructor(AbstractDatasource nds, string nname, *hash nopts)
creates the object; private constructor
truncate()
truncates all the table data; releases the transaction lock after executing
string name
the name of the object
Definition: SqlUtil.qm.dox.h:4254
string getAlignSqlString(AbstractTable t, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
AbstractColumn dropColumn(string cname, *reference lsql)
drops a column from the table; if the table is known to be in the database already, then it is also dropped from the database immediately; otherwise it is only removed internally
a class describing a foreign constraint target
Definition: SqlUtil.qm.dox.h:4125
string getAlignSqlString(AbstractTable table, *hash opt)
accepts an AbstractTable argument and returns an SQL string that could be executed to align the struc...
*list getCreateIndexesSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
*string getDropFunctionSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given function if it exists or NOTHING if the named function does...
*string qore_type
the equivalent qore type name of the column if known
Definition: SqlUtil.qm.dox.h:3637
add(string k, AbstractConstraint val)
adds the given value to the hash with the given key name
hash op_gt(any arg)
returns a hash for the &quot;&gt;&quot; operator with the given argument for use in where clauses when comparing c...
Constraints getConstraints()
returns a Constraints object describing non-foreign constraints on the table
the base class to use to extend AbstractColumn to implement numeric columns
Definition: SqlUtil.qm.dox.h:3733
AbstractIndex renameIndex(string old_name, string new_name, reference sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
list getRecreateSql(AbstractDatasource ds, string table_name, *hash opt)
returns a list of strings to drop and recreate the current index; if there are dependent constraints...
const AC_Create
used when a new object is created
Definition: SqlUtil.qm.dox.h:4957
add(string k, AbstractFunction val)
adds the given value to the hash with the given key name
const True
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
AbstractTrigger memberGate(string k)
returns the AbstractTrigger object corresponding to the key given or throws a KEY-ERROR exception ...
list listViews()
returns a list of string view names in the database
softint rowCount()
returns the number of rows in the table
*string getCreatePrimaryKeySql(*hash opt)
returns an SQL string that could be used to create the primary key on the table
abstract private hash getQoreTypeMapImpl()
returns the qore type -&gt; column type map
list keys()
Returns a list of key names of the contained hash.
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql)
adds a foreign constraint to the table; if the table is already known to be in the database...
const JopMap
a hash of valid column operators
Definition: SqlUtil.qm.dox.h:2264
hash make_op(string op, any arg)
returns a hash with op and arg keys
const SZ_MAND
the data type takes a mandatory size parameter
Definition: SqlUtil.qm.dox.h:1645
const OP_GT
the SQL greater than operator (&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2592
const CHAR
specifies a CHAR column
Definition: SqlUtil.qm.dox.h:1628
hash op_clt(string arg)
returns a hash for the &quot;&lt;&quot; operator with the given argument for use in where clauses when comparing t...
const COP_AVG
to return the average value
Definition: SqlUtil.qm.dox.h:1706
const DB_SEQUENCES
Feature: sequences.
Definition: SqlUtil.qm.dox.h:1607
const DB_MVIEWS
Feature: materialized views/snapshots.
Definition: SqlUtil.qm.dox.h:1601
int del(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; the transacti...
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
private clearImpl()
clears any driver-specific table information
const JOP_LEFT
for left outer joins
Definition: SqlUtil.qm.dox.h:2256
base class for sequences
Definition: SqlUtil.qm.dox.h:4180
*list getCreateTriggersSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create triggers on the table or NOTHING if there ...
list listFunctions()
returns a list of string function names in the database
hash op_cgt(string arg)
returns a hash for the &quot;&gt;&quot; operator with the given argument for use in where clauses when comparing t...
private hash getColumnOperatorMap()
returns the column operator map for this object
string getElementName()
must return the name of the contained element
add(any val)
adds the given value to the list
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
abstract string getElementName()
must return the name of the contained element
int updateNoCommit(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; no tr...
Columns subset(softlist l)
returns a subset of the current columns according to the list argument
nothing flush()
bool nullable
True if the column can hold a NULL value, False if not
Definition: SqlUtil.qm.dox.h:3643
hash cop_min(any column)
returns a hash for the &quot;min&quot; operator; returns minimum column values
AbstractPrimaryKey addPrimaryKey(string pkname, softlist cols, *hash opt, *reference sql)
adds a primary key to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
const UpsertOptions
default upsert option keys
Definition: SqlUtil.qm.dox.h:8332
number number(softnumber n)
const COP_DISTINCT
to return distinct values
Definition: SqlUtil.qm.dox.h:1691
const COP_YEAR_HOUR
to return a date value with year to hextern information
Definition: SqlUtil.qm.dox.h:1756
const CacheOptions
default cache options
Definition: SqlUtil.qm.dox.h:8187
AbstractFunction makeFunction(string name, string src, *hash opts)
creates a database-specific AbstractFunction object corresponding to the arguments ...
Columns describe()
returns an object of class Columns describing the table
list getAddTriggerSql(string tname, string src, *hash topt, *hash opt)
returns a list of SQL strings that can be used to add a trigger to the table
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found ...
*list getDropAllForeignConstraintsOnTableSql(string name, *hash opt)
returns a list of SQL strings that can be used to drop all the foreign constraints on a particular ta...
int update(hash set, *hash cond, *reference sql)
updates rows in the table matching an optional condition and returns the count of rows updated; the t...
ForeignConstraints foreignConstraints
foreign constraints description
Definition: SqlUtil.qm.dox.h:8465
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:8471
*AbstractUniqueConstraint constraint
the AbstractUniqueConstraint that this index supports, if any
Definition: SqlUtil.qm.dox.h:3810
string getTruncateSql(*hash opt)
gets the SQL that can be used to truncate the table
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
list getDropAllConstraintsAndIndexesOnColumnSql(string cname, *hash opt)
gets a list of SQL strings to drop all constraints and indexes with the given column name; if the col...
private hash getUpdateOperatorMap()
returns the update operator map for this object
bool dropSequenceIfExists(string name, *hash opt)
drops the given sequence if it exists; returns True if the sequence was dropped, False if not ...
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
string getSelectSql(*hash sh, *reference args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
AbstractFunction take(string k)
removes the given key from the contained hash and returns the value
hash op_cne(string arg)
returns a hash for the &quot;!=&quot; or &quot;&lt;&gt;&quot; operator with the given argument for use in where clauses when co...
create(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql)
adds a trigger to the table; if the table is already known to be in the database, then it is added in...
const List
base class for abstract SqlUtil classes
Definition: SqlUtil.qm.dox.h:4866
const CacheOptions
generic cache options
Definition: SqlUtil.qm.dox.h:4929
const UpsertUpdateFirst
Upsert option: update first, if the update fails, then insert.
Definition: SqlUtil.qm.dox.h:8376
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
abstract private bool tryInsertImpl(string sql, hash row)
tries to insert a row, if there is a duplicate key, then it returns False, if successful, returns True
int del(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; the transacti...
list getAddColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
returns a list of SQL strings that can be use to add a column to the table
const NULL
const AC_Modify
used when an object is modified in place
Definition: SqlUtil.qm.dox.h:4966
bool equal(Columns cols)
returns True if the argument has the same columns in the same order as the current object...
*hash upsertFromSelectNoCommit(AbstractTable src, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
create(*hash opt)
creates the table in the database; releases the transaction lock after creating the table ...
const OP_CNE
the SQL not equals operator (!= or &lt;&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2632
any memberGate(string k)
returns the value of the given key in the contained hash if it exists, otherwise throws a KEY-ERROR e...
represents a database; this class embeds an AbstractDatabase object that is created automatically in ...
Definition: SqlUtil.qm.dox.h:4417
int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
abstract private doSelectLimitOnlyUnlockedImpl(reference sql, reference args, *hash qh)
processes a string for use in SQL select statements when there is a &quot;limit&quot; argument, but no &quot;orderby&quot; or &quot;offset&quot; arguments
constructor(AbstractDatasource ds, string name, *hash opts)
creates the Table object
private hash getSqlDataCallbackOptions()
returns the sql data operation callback options for this driver
const OP_CGT
the SQL greater than operator (&gt;) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2622
bool dropSequenceIfExists(string name, *hash opt)
drops the given sequence if it exists; returns True if the sequence was dropped, False if not ...
the base class for foreign key constraint information
Definition: SqlUtil.qm.dox.h:4147
hash op_like(string str)
returns a hash for the &quot;like&quot; operator with the given argument for use in where clauses ...
ForeignConstraintTarget target
a ForeignConstraintTarget object to describe the target table and columns
Definition: SqlUtil.qm.dox.h:4155
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
const False
bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
constructor(string n, string n_src)
creates the object and sets its name and the check clause source
AbstractConstraint memberGate(string k)
returns the AbstractConstraint object corresponding to the key given or throws a KEY-ERROR exception ...
Mutex l()
mutex for atomic actions
abstract private copyImpl(AbstractTable old)
db-specific copy actions
string getAddUniqueConstraintSql(string cname, softlist cols, *hash ukopt, *hash opt)
returns an SQL string that can be used to add a unique constraint to the table
const NothingType
hash op_lt(any arg)
returns a hash for the &quot;&lt;&quot; operator with the given argument for use in where clauses when comparing c...
abstract string getCreateSql(string table_name, *hash opts)
returns a string that can be used to create the constraint in the database
hash op_le(any arg)
returns a hash for the &quot;&lt;=&quot; operator with the given argument for use in where clauses when comparing ...
*AbstractView getView(string name)
returns an AbstractView argument for the given view name or NOTHING if the view
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
int scale
the scale for numeric columns
Definition: SqlUtil.qm.dox.h:3738
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
abstract class for check constraints
Definition: SqlUtil.qm.dox.h:3969
AbstractConstraint renameConstraint(string old_name, string new_name, reference lsql)
renames an existing constraint; this can be any constraint on the table, a primary key...
bool emptyData()
returns True if the table has no data rows, False if not
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
const AC_Drop
used when an object is dropped
Definition: SqlUtil.qm.dox.h:4960
bool equal(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
constructor(string n, bool u, hash c)
creates the object from the name, a unique flag, and a hash of column information ...
const COP_COUNT
to return the row count
Definition: SqlUtil.qm.dox.h:1711
createNoCommit(*hash opt)
creates the table with all associated properties (indexes, constraints, etc) without any transaction ...
list list(...)
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
int getNextSequenceValue(string name)
returns the next value in the given sequence
const OP_CEQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2637
abstract container class that throws an exception if an unknown key is accessed
Definition: SqlUtil.qm.dox.h:3030
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
bool empty()
returns True if the table has no definitions, False if not
hash cop_distinct(any column)
returns a hash for the &quot;distinct&quot; operator with the given argument; returns distinct column values ...
Qore::ListIterator sequenceIterator()
returns an iterator listing the string sequence names in the database
const ActionLetterMap
maps from action codes to action letter codes
Definition: SqlUtil.qm.dox.h:5023
string name
the table&#39;s name
Definition: SqlUtil.qm.dox.h:8457
abstract private bool supportsTablespacesImpl()
returns True if the database support tablespaces
bool supportsPackages()
returns True if the database supports packages
string getAddIndexSql(string iname, bool unique, softlist cols, *hash ixopt, *hash opt)
returns an SQL string that can be used to add an index to the table
trigger container class that throws an exception if an unknown trigger is accessed ...
Definition: SqlUtil.qm.dox.h:4369
renameSourceConstraintTable(string old_name, string new_name)
renames a table in a source constraint
AbstractTrigger dropTrigger(string tname, *reference sql)
drops the given trigger from the table; if the table is known to be in the database already...
const DefaultUopMap
a hash of valid update operators
Definition: SqlUtil.qm.dox.h:2153
int index(softstring str, softstring substr, softint pos=0)
string src
the source of the check clause
Definition: SqlUtil.qm.dox.h:3974
string getDatasourceDesc()
returns a descriptive string for the datasource
Indexes indexes
index descriptions
Definition: SqlUtil.qm.dox.h:8463
*string getDropSequenceSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given sequence if it exists or NOTHING if the named sequence does...
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
private hash getDropSchemaOptions()
override in subclasses to return driver-specific options
const DB_PACKAGES
Feature: packages.
Definition: SqlUtil.qm.dox.h:1603
AbstractColumn take(string k)
removes the given key from the contained hash and returns the value
*hash upsertFromSelect(AbstractTable src, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
list listProcedures()
returns a list of string procedure names in the database
const COP_UPPER
to return column value in upper case
Definition: SqlUtil.qm.dox.h:1681
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
const COP_PLUS
the SQL &quot;minus&quot; operator
Definition: SqlUtil.qm.dox.h:1726
private hash getSelectOptions()
returns the select options for this driver
const Boolean
abstract private bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
hash cop_minus(any column1, any column2)
returns a hash for the &quot;-&quot; operator with the given arguments
cache(*hash opts)
reads in all attributes of the table from the database
const UR_Verified
row was updated unconditionally (not returned with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8410
abstract private bool supportsSequencesImpl()
returns True if the database supports sequences
clear()
purges the current table definition
const OP_GE
the SQL greater than or equals operator (&gt;=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2597
index container class that throws an exception if an unknown index is accessed
Definition: SqlUtil.qm.dox.h:3751
private validateColumnOptions(string cname, reference opt, bool nullable)
validates column options
const SZ_NUM
the data type is numeric so takes an optional precision and scale
Definition: SqlUtil.qm.dox.h:1651
abstract private bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql)
adds a unique constraint to the table; if the table is known to be in the database already...
const TableOptions
table options
Definition: SqlUtil.qm.dox.h:8166
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
const AC_Rename
used when an object is renamed
Definition: SqlUtil.qm.dox.h:4963
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
abstract bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
private hash getTableColumnDescOptions()
returns the table column description options for this driver
string getCreateSql()
returns an sql string that can be used to add the column to a table
*hash upsertFromSelect(AbstractTable t, *hash sh, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given foreign table and select option hash into the curre...
list getAlignSql(hash schema_hash, *hash opt, *Tables table_cache)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
*string def_val
default value for column
Definition: SqlUtil.qm.dox.h:3646
int insertFromIterator(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
AbstractPrimaryKey primaryKey
primary key description
Definition: SqlUtil.qm.dox.h:8461
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
insertNoCommit(hash row, *reference sql)
inserts a row into the table without any transaction management; a transaction will be in progress af...
AbstractPrimaryKey addPrimaryKey(string cname, softlist cols, *hash opt, *reference sql)
adds a primary key to the table; if the table already exists, then it is added in the database also i...
hash cop_plus(any column1, any column2)
returns a hash for the &quot;+&quot; operator with the given arguments
string getAddCheckConstraintSql(string cname, string src, *hash copt, *hash opt)
returns an SQL string that can be used to add a check constraint to the table
bool manual
manual edits
Definition: SqlUtil.qm.dox.h:8475
const AlignTableOptions
table alignment options
Definition: SqlUtil.qm.dox.h:8255
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
*AbstractIndex findEqual(AbstractIndex ix)
find an index with columns equal to the index passed
bool emptyData()
returns True if the table has no data rows, False if not
bool tableRenamed(string old_name, string new_name, string old_sql_name)
updates table names and internal references for renamed tables
removeSourceConstraint(string tname, list cols)
removes a source constraint
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
AbstractColumn addColumn(string cname, hash opt, bool nullable=True, *reference lsql)
adds a column to the table; if the table already exists, then it is added in the database also immedi...
int upsertNoCommit(hash row, int upsert_strategy=AbstractTable::UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
*list getCreateForeignConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create foreign constraints on the table or NOTHIN...
string getNativeTypeString(string native_type, int precision)
returns the string describing the native type that can be used in SQL (for example to add the column ...
hash getDisableReenableSql(AbstractDatasource ds, string table_name, *hash opts)
returns lists of SQL strings to disable this constraint plus any dependent constraints and another li...
hash cop_lower(any column)
returns a hash for the &quot;lower&quot; operator with the given argument; returns a column value in lower case...
Triggers triggers
trigger descriptions
Definition: SqlUtil.qm.dox.h:8469
*string getRenameTableIfExistsSql(string old_name, string new_name, *hash opts)
returns an SQL string that can be used to rename the given table if it exists and the target does not...
Columns describe()
returns an object of class Columns describing the Table
const DB_PROCEDURES
Feature: procedures.
Definition: SqlUtil.qm.dox.h:1605
const CreationOptions
default generic creation options
Definition: SqlUtil.qm.dox.h:5045
abstract string getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
AbstractTable memberGate(string k)
returns the AbstractTable object corresponding to the key given or throws a KEY-ERROR exception ...
const OP_EQ
the SQL equals operator (=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2607
string getEnableSql(string table_name, *hash opt)
returns a string that can be used to enable the constraint in the database; if disabling constraints ...
*AbstractSequence getSequence(string name)
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be...
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
AbstractPrimaryKey getPrimaryKey()
returns an object of class AbstractPrimaryKey describing the primary key of the table ...
bool dropViewIfExists(string name, *hash opt)
drops the given view if it exists; returns True if the view was dropped, False if not ...
bool exists(...)
AbstractForeignConstraint take(string k)
removes the given key from the contained hash and returns the value
abstract private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
abstract string getElementName()
must return the name of the contained element
*string comment
comment on the column
Definition: SqlUtil.qm.dox.h:3649
Qore::AbstractIterator dropIterator()
returns an iterator for a list of cached table names in the order that can be used to drop the tables...
Qore::AbstractIterator getSourceConstraintIterator()
returns an iterator through all known source foreign constraints on the current table ...
list getAlignFunctionSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a function in the database to the function d...
AbstractIndex dropIndex(string iname, *reference sql)
drops the index from the table; if the table is known to be in the database already, then it is also dropped from the database immediately; otherwise it is only removed internally
string getName()
returns the name of the table
code getUpsertClosure(hash example_row, int upsert_strategy=AbstractTable::UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
bool val()
Returns False if the contained list is empty, True if not.
string getSelectSql(*hash sh, *reference args)
returns the SQL string to be executed corresponding to the argument hash with an output parameter for...
string src
the source code
Definition: SqlUtil.qm.dox.h:4225
bool unique
True if the index is a unique index, False if not
Definition: SqlUtil.qm.dox.h:3801
string getDropIndexSql(string iname, *hash opt)
gets the SQL that can be used to drop an index from the table
list getModifySql(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
hash cop_over(any column, string arg)
returns a hash for the &quot;over&quot; clause
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
const AC_Insert
used when data is inserted in a table
Definition: SqlUtil.qm.dox.h:4978
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
add(string k, Table val)
adds the given value to the hash with the given key name
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
constructor(AbstractDatasource ds, *hash opts)
creates the Database object
string getNativeTypeString()
returns the string describing the native type that can be used in SQL (for example to add the colunn ...
Qore::AbstractIterator iterator()
Returns a HashIterator object for the contained hash.
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
Qore::ListIterator tableIterator()
returns an iterator listing the string table names in the database
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
list getCreateSql(*hash opt)
returns a list of SQL strings that could be used to create the table and all known properties of the ...
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifiers for schema, etc)
const COP_YEAR_MONTH
to return a date value with year to month information
Definition: SqlUtil.qm.dox.h:1746
string src
the source of the object
Definition: SqlUtil.qm.dox.h:4260
private bool equalImpl(AbstractConstraint c)
returns True if the argument is equal to the current object, False if not
string getElementName()
must return the name of the contained element
private hash getForeignConstraintOptions()
return the foreign constraint options for this driver
const COP_MAX
to return the maximum value
Definition: SqlUtil.qm.dox.h:1701
AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql)
drops a foreign constraint from the table; if the table is known to be in the database already...
insert(hash row, *reference sql)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
const COP_AS
to rename a column on output
Definition: SqlUtil.qm.dox.h:1661
string getDriverName()
returns the database driver name
hash cop_divide(any column1, any column2)
returns a hash for the &quot;/&quot; operator with the given arguments
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 ...
abstract list getRenameSql(string table_name, string new_name)
returns a list of SQL strings that can be used to rename the constraint in the database ...
Columns columns
column description object
Definition: SqlUtil.qm.dox.h:8459
int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
private constructor(AbstractDatasource nds, *hash nopts)
creates the object; private constructor
*AbstractFunction getFunction(string name)
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be...
const DB_VIEWS
Feature: views.
Definition: SqlUtil.qm.dox.h:1613
hash op_not(hash arg)
returns a hash for the &quot;not&quot; operator; for use in where clauses
Qore::ListIterator procedureIterator()
returns an iterator listing the string procedure names in the database
AbstractForeignConstraint addForeignConstraint(string cname, softlist cols, string table, *softlist tcols, *hash opt, *reference sql)
adds an foreign constraint to the table; if the table is already known to be in the database...
const OP_LE
the SQL less than or equals (&lt;=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2587
private hash getCacheOptions()
override in subclasses to return driver-specific options
const BLOB
specifies a large variable-length binary column (ie BLOB or BYTEA, etc)
Definition: SqlUtil.qm.dox.h:1631
string name
the name of the index
Definition: SqlUtil.qm.dox.h:3798
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)
hash cop_value(any arg)
returns a hash for the &quot;value&quot; operator with the given argument
AbstractConstraint dropConstraint(string cname, *reference sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
*string getCreatePrimaryKeySql(*hash opt, bool cache=True)
returns an SQL string that could be used to create the primary key on the table
Columns columns
columns in the target table
Definition: SqlUtil.qm.dox.h:4133
drop(*hash opt)
drops the table from the database; releases the transaction lock after dropping the table ...
const OP_CLE
the SQL less than or equals (&lt;=) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2617
hash join_left(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for left outer joins with the given arguments
AbstractColumn addColumn(string cname, hash opt, bool nullable=True, *reference lsql)
adds a column to the table; if the table is already known to be in the database, then it is added in ...
AbstractColumn modifyColumn(string cname, hash opt, bool nullable=True, *reference lsql)
modifies an existing column in the table; if the table already exists, then the changes are effected ...
const DB_TABLES
Feature: tables.
Definition: SqlUtil.qm.dox.h:1609
list getAlignProcedureSql(AbstractFunction f, *hash opt)
returns a list of SQL strings that can be used to update a stored procedure in the database to the st...
string getElementName()
must return the name of the contained element
*hash select(*hash sh, *reference sql)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
const CLOB
specifies a large variable-length character column (ie CLOB or TEXT, etc)
Definition: SqlUtil.qm.dox.h:1634
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
bool supportsTypes()
returns True if the database supports named types
const OP_NOT
the SQL &quot;not&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2652
AbstractColumn renameColumn(string old_name, string new_name, reference sql)
renames an existing column; if the table already exists, then the changes are effected in the databas...
string getRenameSql(string new_name, *hash opt)
returns an SQL string that could be used to rename the table in the database
clear()
purges the contained data
Columns columns
an object of class Columns representing the columns in the index
Definition: SqlUtil.qm.dox.h:3804
*list getCreateConstraintsSql(*hash opt)
returns a list of SQL strings that could be used to create non-foreign constraints on the table or NO...
AbstractForeignConstraint memberGate(string k)
returns the AbstractForeignConstraint object corresponding to the key given or throws a KEY-ERROR exc...
const SqlDataCallbackOptions
generic SQL data operation callbacks
Definition: SqlUtil.qm.dox.h:8322
base class for function or objects with code
Definition: SqlUtil.qm.dox.h:4249
const DB_TYPES
Feature: named types.
Definition: SqlUtil.qm.dox.h:1611
addSourceConstraint(string tname, AbstractForeignConstraint fk)
adds a foreign constraint source to the unique constraint
string getRenameColumnSql(string old_name, string new_name, *hash opt)
gets an SQL string that can be used to rename an existing column in the table
AbstractTable makeTable(string name, hash desc, *hash opts)
creates a database-specific AbstractTable object corresponding to the arguments
bool empty()
returns True if the container is empty, False if not
copy(AbstractTable old)
copies the object
private hash getInsertOptions()
returns the insert options for this driver
Qore::ListIterator viewIterator()
returns an iterator listing the string view names in the database
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
AbstractFunction makeFunction(string name, string src, *hash opt)
creates a database-specific AbstractFunction object corresponding to the arguments ...
const UpsertResultMap
hash mapping upsert results to a description
Definition: SqlUtil.qm.dox.h:8425
findMatchingIndex(*Indexes indexes)
find an index that matches the constraint and marks both objects as related
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
string name
the name of the column
Definition: SqlUtil.qm.dox.h:3631
bool empty()
returns True if the container is empty, False if not
bool supportsSequences()
returns True if the database supports sequences
private hash getAlignSchemaOptions()
override in subclasses to return driver-specific options
string string(softstring str)
private hash getConstraintOptions()
returns the constraint options for this driver
AbstractDatasource ds
the connection to the database server
Definition: SqlUtil.qm.dox.h:4871
string getName()
returns the constraint name
insert(hash row, *reference sql)
inserts a row into the table; the transaction is committed if successful, if an error occurs...
*list getCreateMiscSql(*hash opt)
returns a list of SQL strings that could be used to create other table attributes (such as comments...
abstract private list getModifySqlImpl(AbstractTable t, AbstractColumn c, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition; if the col...
string getName()
returns the index name
base class for functions
Definition: SqlUtil.qm.dox.h:4290
private hash getTableDescriptionHashOptions()
returns the table description hash options for this driver
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
const COP_MULTIPLY
the SQL &quot;multiply&quot; operator
Definition: SqlUtil.qm.dox.h:1736
AbstractUniqueConstraint addUniqueConstraint(string cname, softlist cols, *hash opt, *reference sql)
adds a unique constraint to the table; if the table is known to be in the database already...
list listSequences()
returns a list of string sequence names in the database
Constraints constraints
constraint descriptions
Definition: SqlUtil.qm.dox.h:8467
const COP_PREPEND
to prepend a string to a column on output
Definition: SqlUtil.qm.dox.h:1666
list getDropSchemaSql(hash schema_hash, *hash opt)
accepts a hash argument describing a database schema and returns a list of SQL strings that can be us...
hash cop_count(string column="")
returns a hash for the &quot;count&quot; operator; returns row counts
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
list listFunctions()
returns a list of string function names in the database
bool partialMatchKeys(hash h1)
returns True if the hash argument has at least the same keys (in any order, can have more keys)...
AbstractSequence makeSequence(string name, number start=1, number increment=1, *softnumber end, *hash opts)
creates a database-specific AbstractSequence object corresponding to the arguments ...
const AC_Recreate
used when an object is recreated (usually dropped and recreated in place)
Definition: SqlUtil.qm.dox.h:4975
*string getIndex()
returns the name of the associated index, if any
abstract clearIndex()
clears any index base for the constraint
base class for views
Definition: SqlUtil.qm.dox.h:4214
bool dropTableIfExists(string name, *hash opt)
drops the given table if it exists; returns True if the table was dropped, False if not ...
bool hasKey(string k)
Returns True if the key exists in the contained hash (may or may not be assigned a value)...
bool equal(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
abstract list getRenameSql(string new_name)
returns a string that can be used to rename the function in the database
*hash opts
option hash
Definition: SqlUtil.qm.dox.h:4877
string getCreateSqlString(*hash opt)
returns an SQL string that could be used to create the table and all known properties of the table ...
AbstractTable getTable()
returns the AbstractTable object contained by this object
bool native_case
native case option
Definition: SqlUtil.qm.dox.h:5108
*list getCreateConstraintsSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create non-foreign constraints on the table or NO...
list getAddColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
returns a list of SQL strings that can be use to add a column to the table
AbstractFunction makeProcedure(string name, string src, *hash opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
renameKey(string old_name, string new_name)
renames the given key; maintains the key order
*hash selectRow(*hash sh, *reference sql)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
private hash getTableCreationOptions()
returns the table creation options for this driver
const InsertOptions
default insert option keys
Definition: SqlUtil.qm.dox.h:8343
Qore::SQL::AbstractDatasource getDatasource()
gets the underlying AbstractDatasource
AbstractTrigger take(string k)
removes the given key from the contained hash and returns the value
abstract private bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
any tryExecRaw(string sql)
executes some SQL so that if an error occurs the current transaction state is not lost ...
*hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
insertNoCommit(hash row, *reference sql)
inserts a row into the table without any transaction management; a transaction will be in progress af...
const TriggerOptions
default trigger options
Definition: SqlUtil.qm.dox.h:8202
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
hash cop_prepend(any column, string arg)
returns a hash for the &quot;prepend&quot; operator with the given argument
AbstractForeignConstraint dropForeignConstraint(string cname, *reference sql)
drops the foreign constraint from the table; if the table is known to be in the database already...
string type
the type of object
Definition: SqlUtil.qm.dox.h:4257
setupTable(hash desc, *hash opt)
creates the object from a table description hash
const Int
AbstractIndex renameIndex(string old_name, string new_name, reference sql)
renames an existing index; if the table is already known to be in the database, then the changes are ...
abstract private doSelectOrderByWithOffsetSqlUnlockedImpl(reference sql, reference args, *hash qh, *hash jch, *hash ch)
processes a string for use in SQL select statements when there is an &quot;order by&quot; and &quot;offset&quot; argument...
*list findAll(*hash cond)
finds all rows in the table with the given column values; a list of hashes is returned representing t...
const COP_YEAR
to return a date value with year information only
Definition: SqlUtil.qm.dox.h:1741
constructor(softlist nl)
creates the object with the list argument passed
bool hasColumn(string cname)
returns True if the constraint references the named column
Triggers getTriggers()
returns an object of class Triggers describing the triggers on the table
const SequenceDescriptionOptions
default generic sequence description keys
Definition: SqlUtil.qm.dox.h:5098
AbstractCheckConstraint addCheckConstraint(string cname, string src, *hash opt, *reference sql)
adds a check constraint to the table; if the table is already known to be in the database, then it is added in the database also immediately; otherwise it is only added internally and can be created when create() is called for example
abstract list getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the trigger in the database
*list getCreateIndexesSql(*hash opt)
returns a list of SQL strings that could be used to create indexes on the table or NOTHING if there a...
softint rowCount()
returns the number of rows in the table
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
string getElementName()
returns &quot;table&quot; since this object stores AbstractTable objects
list getDropPrimaryKeySql(*hash opt)
gets a list of SQL strings that can be used to drop the primary key from the table ...
abstract private hash getTypeMapImpl()
returns the type name -&gt; type description hash
string getDropSql()
returns a string that can be used to drop the view from the database
dropNoCommit(*hash opt)
drops the table from the database without any transaction management
string getElementName()
returns &quot;foreign constraint&quot; for the type of object encapsulated
int size
the size of the column
Definition: SqlUtil.qm.dox.h:3640
AbstractColumn renameColumn(string old_name, string new_name, reference sql)
renames an existing column; if the table is already known to be in the database, then the changes are...
string getSqlFromList(list l)
returns an SQL string corresponding to the list of commands in the argument
bool dropTableIfExists(string name, *hash opt)
drops the given table if it exists; returns True if the table was dropped, False if not ...
list listProcedures()
returns a list of string procedure names in the database
list getModifyColumnSql(string cname, hash copt, bool nullable=True, *hash opt)
gets a list of SQL strings that can be used to modify an existing column in the table ...
string getSqlValue(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
int size()
Returns the number of keys in the contained hash.
private any tryExecRawImpl(string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
Qore::AbstractIterator keyIterator()
Returns a HashKeyIterator object for the contained hash.
private hash getWhereOperatorMap()
returns the &quot;where&quot; operator map for this object
*hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
any tryExecArgs(string sql, *softlist args)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
abstract string getRenameSql(string new_name)
returns a string that can be used to rename the sequence in the database
string native_type
the native type name of the column
Definition: SqlUtil.qm.dox.h:3634
const COP_VALUE
to append a constant value to use as an output column value
Definition: SqlUtil.qm.dox.h:1676
truncateNoCommit()
truncates all the table data without any transaction management
column container class that throws an exception if an unknown column is accessed
Definition: SqlUtil.qm.dox.h:3579
the base class for triggers
Definition: SqlUtil.qm.dox.h:4351
hash join_right(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for right outer joins with the given arguments
hash op_eq(any arg)
returns a hash for the &quot;=&quot; operator with the given argument for use in where clauses when comparing c...
private hash getAlignTableOptions()
returns the align table options for this driver
int insertFromSelect(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
const OP_LT
the SQL less than (&lt;) operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2582
string dsdesc
datasource description
Definition: SqlUtil.qm.dox.h:4873
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
setDatasource(AbstractDatasource nds)
changes the datasource for the table; if the inDb flag is True, then it is set to False by calling th...
bool empty()
returns True if the table has no definitions, False if not
const AlignSchemaOptions
default generic schema description / alignment options
Definition: SqlUtil.qm.dox.h:5055
*hash findConstraintOn(string table, softlist cols)
returns either a hash of AbstractColumn information or NOTHING if no foreign constraint can be found ...
add(string k, AbstractForeignConstraint val)
adds the given value to the hash with the given key name
function container class that throws an exception if an unknown function is accessed ...
Definition: SqlUtil.qm.dox.h:4313
Indexes getIndexes()
returns an object of class Indexes describing the indexes on the table
const UR_Unchanged
row was unchanged (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8416
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
rename(string new_name, *reference sql, *Tables table_cache)
renames the table; if the table already exists in the database, then the changes are effected in the ...
const UR_Updated
row was updated because it was different (only possible with UpsertSelectFirst)
Definition: SqlUtil.qm.dox.h:8413
int getNextSequenceValue(string name)
returns the next value in the given sequence
AbstractDatabase db
the embedded AbstractDatabase object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:4422
the base class for column information
Definition: SqlUtil.qm.dox.h:3626
truncate()
truncates all the table data; releases the transaction lock after executing
bool hasColumn(string cname)
returns True if the constraint references the named column
const UpsertInsertOnly
Upsert option: insert if the row does not exist, otherwise ignore.
Definition: SqlUtil.qm.dox.h:8399
setName(string new_name)
sets the new name of the object
hash join_inner(AbstractTable table, *string alias, *hash jcols, *hash cond, *hash opt)
returns a hash for standard inner joins with the given arguments
AbstractPrimaryKey dropPrimaryKey(*reference lsql)
drops the primary key from the table; if the table is known to be in the database already...
add(string k, AbstractTrigger val)
adds the given value to the hash with the given key name
const OP_CGE
the SQL greater than or equals operator (&gt;=) for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2627
const AC_Truncate
used when a table is truncated
Definition: SqlUtil.qm.dox.h:4969
hash op_cle(string arg)
returns a hash for the &quot;&lt;=&quot; operator with the given argument for use in where clauses when comparing ...
string getName()
returns the name of the table
represents a database table; this class embeds an AbstractTable object that is created automatically ...
Definition: SqlUtil.qm.dox.h:5729
const IndexOptions
default index options
Definition: SqlUtil.qm.dox.h:8176
private hash getColumnOptions()
returns the column options for this driver
list values()
Returns a list of values of the contained hash.
AbstractConstraint dropConstraint(string cname, *reference sql)
drops a constraint from the table; this can be any constraint on the table, a primary key...
*hash find(any id)
finds a row in the table with the given primary key value; if no row matches the primary key value pa...
bool equal(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
rename(string new_name, *reference sql, *Tables table_cache)
renames the table; if the table is already known to be in the database in the database, then the changes are effected in the database also immediately; otherwise it is only updated internally
AbstractTable take(string k)
removes the given key from the contained hash and returns the value
hash make_cop(string cop, any column, any arg)
returns a hash with cop, column, and arg keys
const COP_MIN
to return the minimum value
Definition: SqlUtil.qm.dox.h:1696
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:8385
bool dropFunctionIfExists(string name, *hash opt)
drops the given function if it exists; returns True if the function was dropped, False if not ...
const COP_YEAR_DAY
to return a date value with year to day information
Definition: SqlUtil.qm.dox.h:1751
dropNoCommit(*hash opt)
drops the table from the database without any transaction management
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy=AbstractTable::UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
const Closure
setupTable(hash desc, *hash opt)
creates the object from a table description hash
add(string k, AbstractIndex val)
adds the given value to the hash with the given key name
AbstractFunction makeProcedure(string name, string src, *hash opt)
creates a database-specific AbstractFunction object for a stored procedure corresponding to the argum...
const UpsertInsertFirst
Upsert option: insert first, if the insert fails, then update.
Definition: SqlUtil.qm.dox.h:8368
private hash getCallbackOptions()
override in subclasses to return driver-specific options
*hash selectRow(*hash sh, *reference sql)
returns a hash representing the row in the table that matches the argument hash; if more than one row...
AbstractIndex addIndex(string iname, bool unique, softlist cols, *hash opt, *reference sql)
adds an index to the table; if the table already exists, then it is added in the database also immedi...
string name
the name of the sequence
Definition: SqlUtil.qm.dox.h:4222
*hash findSingle(*hash cond)
finds a single row in the table that match the row condition passed; multiple rows may match...
constructor(string n, string n_src)
creates the object and sets its name and the trigger source
list features()
See DBFeaturesConstants.
*number max
the ending number
Definition: SqlUtil.qm.dox.h:4194
abstract private bool checkExistenceImpl()
returns True if the table exists in the DB, False if not
hash cop_upper(any column)
returns a hash for the &quot;upper&quot; operator with the given argument; returns a column value in upper case...
code getUpsertClosure(hash example_row, int upsert_strategy=UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
bool val()
Returns False if the contained hash has no keys, True if it does.
string getAddForeignConstraintSql(string cname, softlist cols, string table, *softlist tcols, *hash fkopt, *hash opt)
returns an SQL string that can be used to add a foreign constraint to the table
*list selectRows(*hash sh, *reference sql)
returns a list of hashes representing the rows in the table that match the argument hash ...
list getList()
returns the list contained by this object
Qore::SQL::SQLStatement getRowIterator(*hash sh, *reference sql)
returns an SQLStatement object that will iterate the results of a select statement matching the argum...
const ColumnDescOptions
Column description options.
Definition: SqlUtil.qm.dox.h:8298
number increment
the increment
Definition: SqlUtil.qm.dox.h:4191
*string getDropConstraintIfExistsSql(string cname, *hash opt, *reference cref)
gets the SQL that can be used to drop a constraint from the table if it exists, otherwise returns NOT...
AbstractColumn memberGate(string k)
returns the AbstractColumn object corresponding to the key given or throws a KEY-ERROR exception ...
bool matchKeys(hash h1)
returns True if the hash argument has the same keys (in any order), False if not
list listViews()
returns a list of string view names in the database
*string getDropProcedureSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given procedure if it exists or NOTHING if the named procedure do...
bool inDb()
returns True if the table has been read from or created in the database, False if not ...
const OP_LIKE
the SQL &quot;like&quot; operator for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2577
rollback()
rolls back the current transaction on the underlying Qore::SQL::AbstractDatasource ...
const CallbackOptions
generic callback options
Definition: SqlUtil.qm.dox.h:4939
const TableDescriptionHashOptions
Table description options.
Definition: SqlUtil.qm.dox.h:8275
const SZ_NONE
the data type does not take a size parameter
Definition: SqlUtil.qm.dox.h:1642
AbstractIndex memberGate(string k)
returns the AbstractIndex object corresponding to the key given or throws a KEY-ERROR exception ...
int size()
Returns the number of elements in the contained list.
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
list getDropList()
returns a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies
AbstractTrigger addTrigger(string tname, string src, *hash opt, *reference lsql)
adds a trigger to the table; if the table is already known to be in the database, then it is added in...
const ActionDescMap
maps from action descriptions to action codes
Definition: SqlUtil.qm.dox.h:5007
AbstractTable t
the embedded AbstractTable object that actually provides the functionality for this class ...
Definition: SqlUtil.qm.dox.h:5734
code getUpsertClosureWithValidation(hash example_row, int upsert_strategy=UpsertAuto)
returns a closure that can be executed given a hash argument representing a single row that will be u...
abstract private *string getSqlValueImpl(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
const OP_CLT
the SQL less than (&lt;) operator for use in Where Clauses when comparing two columns ...
Definition: SqlUtil.qm.dox.h:2612
const COP_MINUS
the SQL &quot;minus&quot; operator
Definition: SqlUtil.qm.dox.h:1721
*AbstractFunction getProcedure(string name)
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored pro...
clear()
purges the current table definition
constructor(string n, string n_type, string n_src)
creates the object from the arguments passed
clearIndex()
clears any index base for the constraint
string table
the name of the target table
Definition: SqlUtil.qm.dox.h:4130
hash hash(object obj)
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
abstract private int getNextSequenceValueImpl(string name)
returns the next value in the given sequence
commit()
commits the current transaction on the underlying Qore::SQL::AbstractDatasource
private hash getColumnDescOptions()
returns the column description options for this driver
*AbstractUniqueConstraint findUniqueConstraint(string name)
returns the given AbstractUniqueConstraint object if defined for the table (also includes the primary...
const TableCreationOptions
table creation options
Definition: SqlUtil.qm.dox.h:8243
hash cop_year_day(any column)
returns a hash for the &quot;year_day&quot; operator with the given argument
const AC_Delete
used when data is deleted in a table
Definition: SqlUtil.qm.dox.h:4984
Qore::ListIterator functionIterator()
returns an iterator listing the string function names in the database
list listTables()
returns a list of string table names in the database
*list getCreateMiscSql(*hash opt, bool cache=True)
returns a list of SQL strings that could be used to create other table attributes (such as comments...
abstract string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
const JOP_RIGHT
for right outer joins
Definition: SqlUtil.qm.dox.h:2261
AbstractTrigger dropTrigger(string tname, *reference sql)
drops the given trigger from the table; if the table is known to be in the database already...
hash make_uop(string uop, any arg, *hash nest)
returns a hash with uop, arg, and nest keys
const SZ_OPT
the data type takes an optional size parameter
Definition: SqlUtil.qm.dox.h:1648
const AC_Update
used when data is updated in a table
Definition: SqlUtil.qm.dox.h:4981
int insertFromIteratorNoCommit(Qore::AbstractIterator i, *hash opt)
this method inserts data from the given iterator argument (whose getValue() method must return a hash...
*string getDropConstraintIfExistsSql(string tname, string cname, *hash opts)
returns an SQL string that can be used to drop an existing constraint on a table, if the table is not...
AbstractSequence makeSequence(string name, number start=1, number increment=1, *softnumber end, *hash opts)
creates a database-specific AbstractSequence object corresponding to the arguments ...
hash cop_year(any column)
returns a hash for the &quot;year&quot; operator with the given argument
number start
the starting number
Definition: SqlUtil.qm.dox.h:4188
const AC_NotFound
used when dropping object but the object is not present
Definition: SqlUtil.qm.dox.h:4987
list getDropTriggerSql(string tname, *hash opt)
returns SQL that can be used to drop the given trigger from the table
populate(AbstractDatasource ds, hash tables, *hash opt)
populates the object from a hash description
the base abstract class for the database implementation
Definition: SqlUtil.qm.dox.h:4913
int insertFromSelectNoCommit(list cols, AbstractTable source, *hash sh, *reference sql)
inserts rows into a table based on a select statement from another table (which must be using the sam...
private hash getTableOptions()
returns the table options for this driver
*list getDropTableSqlIfExists(string name, *hash opt)
returns the SQL require to drop the given table if it exists or NOTHING if the named table does not e...
int upsert(hash row, int upsert_strategy=AbstractTable::UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
Qore::AbstractIterator getUniqueConstraintIterator()
returns an iterator for all unique constraints on the table (including the primary key if any) ...
any take(int i)
removes the given element from the contained list and returns the value
hash cop_multiply(any column1, any column2)
returns a hash for the &quot;*&quot; operator with the given arguments
*hash select(*hash sh, *reference sql)
returns a hash of lists representing the columns and rows in the table that match the argument hahs ...
const AC_Add
used when an element is added to an existing object
Definition: SqlUtil.qm.dox.h:4972
truncateNoCommit()
truncates all the table data without any transaction management
string getCreateTableSql(*hash opt)
returns an SQL string that could be used to create the basic table structure without indexes and cons...
string getDropSql(string table_name)
returns a string that can be used to drop the index from the database
string getDropConstraintSql(string cname, *hash opt)
gets the SQL that can be used to drop a constraint from the table; this can be any constraint on the ...
*AbstractForeignConstraint findEqual(AbstractForeignConstraint fk)
find an index with columns equal to the index passed
ForeignConstraints getForeignConstraints(*hash opt)
returns a ForeignConstraints object describing the foreign constraints that the table has on other ta...
represents a primary key
Definition: SqlUtil.qm.dox.h:4067
const JOP_INNER
for standard inner joins
Definition: SqlUtil.qm.dox.h:2251
const COP_LOWER
to return column value in lower case
Definition: SqlUtil.qm.dox.h:1686
*AbstractTable getTable(string name)
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found ...
private hash getSequenceDescriptionOptions()
override in subclasses to return driver-specific options
private any tryExecArgsImpl(string sql, *softlist args)
tries to execute a command so that if an error occurs the current transaction status is not lost ...
list getDropColumnSql(string cname, *hash opt)
returns the SQL that can be used to drop a column from the table
const COP_DIVIDE
the SQL &quot;divide&quot; operator
Definition: SqlUtil.qm.dox.h:1731
string join(string str,...)
const DB_FUNCTIONS
Features constants.
Definition: SqlUtil.qm.dox.h:1599
const NUMERIC
specifies a numeric column (equivalent to Qore::Type::Number)
Definition: SqlUtil.qm.dox.h:1625
abstract list getCreateSql(*hash opt)
returns a list of SQL strings that can be used to create the function in the database ...
abstract bool setIndexBase(string ix)
returns True if the object supports an index property and is set, False if not
hash op_ceq(string arg)
returns a hash for the &quot;=&quot; operator with the given argument for use in where clauses when comparing t...
*list selectRows(*hash sh, *reference sql)
returns a list of hashes representing the rows in the table that match the argument hash ...
string getDropSql(string table_name)
returns a string that can be used to drop the column from the table
*string lastKey()
Returns the last key name in the contained hash or NOTHING if the contained hash has no keys...
int delNoCommit(*hash cond, *reference sql)
deletes rows in the table matching the condition and returns the count of rows deleted; no transactio...
private bool equalImpl(AbstractConstraint con)
returns True if the argument is equal to the current object, False if not
AbstractConstraint take(string k)
removes the given key from the contained hash and returns the value
*string firstKey()
Returns the first key name in the contained hash or NOTHING if the contained hash has no keys...
*hash upsertFromIterator(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
bool supportsSequences()
returns True if the database supports sequences
*hash upsertFromIteratorNoCommit(Qore::AbstractIterator i, int upsert_strategy=AbstractTable::UpsertAuto, *hash opt)
this method upserts or merges data from the given iterator argument (whose getValue() method must ret...
any tryExec(string sql)
executes some SQL with optional arguments so that if an error occurs the current transaction state is...
hash cop_year_hour(any column)
returns a hash for the &quot;year_hour&quot; operator with the given argument
bool hasKeyValue(string k)
Returns True if the key exists in the contained hash and is assigned a value, False if not...
const ConstraintOptions
default constraint options
Definition: SqlUtil.qm.dox.h:8184
*AbstractTable getIfExists(AbstractDatasource ds, string name)
gets a table from the database or from the cache if already cached; if the table does not exist...
const DefaultOpMap
a hash of valid operators for use in Where Clauses
Definition: SqlUtil.qm.dox.h:2655
represents a unique column constraint
Definition: SqlUtil.qm.dox.h:3996
rename(string n)
renames the constraint
private hash getUpsertOptions()
returns the upsert options for this driver
AbstractTable makeTable(string name, hash desc, *hash opts)
creates a database-specific AbstractTable object corresponding to the arguments
const AdditionalColumnDescOptions
additional column description keys valid when describing columns in a table description hash ...
Definition: SqlUtil.qm.dox.h:8311
hash cop_max(any column)
returns a hash for the &quot;max&quot; operator; returns maximum column values
abstract base class for constraints
Definition: SqlUtil.qm.dox.h:3907
string getSqlValue(any v)
returns a string for use in SQL queries representing the DB-specific value of the argument ...
AbstractForeignConstraint removeForeignConstraint(string cname)
removes the named foreign constraint from the table; no SQL is executed in any case, only the named foreign constraint is removed from the table definition
int upsertNoCommit(hash row, int upsert_strategy=UpsertAuto)
update or insert the data in the table according to the hash argument; the table must have a unique k...
constraint container class that throws an exception if an unknown constraint is accessed ...
Definition: SqlUtil.qm.dox.h:3865
const COP_APPEND
to append a string to a column on output
Definition: SqlUtil.qm.dox.h:1671