|
hash | SqlUtil::cop_append (any column, string arg) |
| returns a hash for the "append" operator with the given argument More...
|
|
hash | SqlUtil::cop_as (any column, string arg) |
| returns a hash for the "as" operator with the given argument More...
|
|
hash | SqlUtil::cop_avg (any column) |
| returns a hash for the "avg" operator; returns average column values More...
|
|
hash | SqlUtil::cop_cast (any column, string arg, *any arg1, *any arg2) |
| returns a hash for the "cast" operator with the given argument(s) More...
|
|
hash | SqlUtil::cop_coalesce (any col1, any col2) |
| returns a hash for the "coalesce" operator with the given column arguments; the first non-NULL column value will be returned More...
|
|
hash | SqlUtil::cop_count (any column="") |
| returns a hash for the "count" operator; returns row counts More...
|
|
hash | SqlUtil::cop_distinct (any column) |
| returns a hash for the "distinct" operator with the given argument; returns distinct column values More...
|
|
hash | SqlUtil::cop_divide (any column1, any column2) |
| returns a hash for the "/" operator with the given arguments More...
|
|
hash | SqlUtil::cop_lower (any column) |
| returns a hash for the "lower" operator with the given argument; returns a column value in lower case More...
|
|
hash | SqlUtil::cop_max (any column) |
| returns a hash for the "max" operator; returns maximum column values More...
|
|
hash | SqlUtil::cop_min (any column) |
| returns a hash for the "min" operator; returns minimum column values More...
|
|
hash | SqlUtil::cop_minus (any column1, any column2) |
| returns a hash for the "-" operator with the given arguments More...
|
|
hash | SqlUtil::cop_multiply (any column1, any column2) |
| returns a hash for the "*" operator with the given arguments More...
|
|
hash | SqlUtil::cop_over (any column, string arg) |
| returns a hash for the "over" clause More...
|
|
hash | SqlUtil::cop_plus (any column1, any column2) |
| returns a hash for the "+" operator with the given arguments More...
|
|
hash | SqlUtil::cop_prepend (any column, string arg) |
| returns a hash for the "prepend" operator with the given argument More...
|
|
hash | SqlUtil::cop_seq (string seq, *string as) |
| returns a hash for the "seq" operator with the given argument giving the sequence name whose value should be returned More...
|
|
hash | SqlUtil::cop_seq_currval (string seq, *string as) |
| returns a hash for the "seq_currval" operator with the given argument giving the sequence name whose current value should be returned More...
|
|
hash | SqlUtil::cop_substr (any column, int start, *int count) |
| returns a hash for the "substr" operator with the given arguments; returns a substring of a column value More...
|
|
hash | SqlUtil::cop_sum (any column) |
| returns a hash for the "sum" operator; returns the total sum of a numeric column. More...
|
|
hash | SqlUtil::cop_upper (any column) |
| returns a hash for the "upper" operator with the given argument; returns a column value in upper case More...
|
|
hash | SqlUtil::cop_value (any arg) |
| returns a hash for the "value" (literal) operator with the given argument More...
|
|
hash | SqlUtil::cop_year (any column) |
| returns a hash for the "year" operator with the given argument More...
|
|
hash | SqlUtil::cop_year_day (any column) |
| returns a hash for the "year_day" operator with the given argument More...
|
|
hash | SqlUtil::cop_year_hour (any column) |
| returns a hash for the "year_hour" operator with the given argument More...
|
|
hash | SqlUtil::cop_year_month (any column) |
| returns a hash for the "year_month" operator with the given argument More...
|
|
hash | SqlUtil::make_cop (string cop, any column, any arg) |
| returns a hash with cop , column , and arg keys More...
|
|
hash SqlUtil::cop_value |
( |
any |
arg | ) |
|
returns a hash for the "value"
(literal) operator with the given argument
- Example:
1 *list rows = table.selectRows((
"columns": (
"id",
"name",
cop_value(100)),
"where": (
"type":
"user")));
- Parameters
-
arg | the value to be returned in the column |
- Returns
- a column operator description hash corresponding to the arguments for use in the columns argument of a select option hash
SQL literals can be useful in some cases - as dummy values for select statements where there is exact columns required, unions, expected values for arc.insertFromIterator
(src.getRowIterator(sh)) "insert as select", etc.
The term literal refers to a fixed data value. For example, 123, 'foobar' etc.
Mapping of Qore values to literals:
Qore Type | SQL Type | Qore Example | SQL interpretation |
Integer | NUMBER as it is | 123 | 123 |
Float | NUMBER as it is | 12.3 | 12.3 |
Numeric | NUMBER as it is | 1.2n | 1.2 |
Date | String representation of the date using DB native implementation like TO_TIMESTAMP for Oracle. | now() | to_timestamp ('20150421104825000000', 'YYYYMMDDHH24MISSFF6') |
Bool | Internal representation of the bool value using DB native implementation | True | 1 |
String | Standard and escaped string literal. No additional literal methods like Oracle's nq{foobar} are supported now | "foo bar" | 'foo bar' |
NULL | Direct null literal | NULL | null |
NOTHING | Direct null literal | NOTHING | null |
- Note
- Passing an existing SQL function name as a value to the op_value does not result in function call. The string value is escaped as it is. Example: sysdate becomes 'sysdate'. See example below.
The most useful SqlUtil::cop_value usage is with cooperation of SqlUtil::cop_as which allows nice and human readable column name aliases.
- Warning
- Using SqlUtil::cop_value without SqlUtil::cop_as can result in errors depending on the DB backend. For example Oracle's use of
cop_value(1), cop_value(True)
ends with ORA-00918: column ambiguously defined
because both values are interpreted as 1 in the resulting SQL.
Example
4 DatasourcePool ds(
"oracle:pvanek_omq/omq@xbox(al32utf8)");
22 on_exit {
printf(
"sql: %s\n", sql); }
23 printf(
"%N\n", t.selectRow(sh, \sql));
30 as_date : 2015-04-21 10:56:57.000000 Tue +02:00 (CEST)
32 as_function_call :
"sysdate"
36 sql: select 1
as as_int,1.2
as as_float,3.2
as as_numeric,to_timestamp(
'20150421105657000000',
'YYYYMMDDHH24MISSFF6')
as as_date,
'foo bar' as as_string,
'sysdate' as as_function_call,1
as as_bool,null
as as_null,null
as as_nothing
from pvanek_omq.workflows fetch next %v rows only