Public Member Functions |
| _unique (&$array, $desired=null) |
| __clone () |
| __toString () |
| template ($template) |
| paramBase ($param_base) |
| dsql () |
| escape ($val) |
| consume ($dsql, $tick=true) |
| setCustom ($template, $value) |
| del ($args) |
| reset () |
| expr ($expr, $params=array()) |
| orExpr () |
| getField ($fld) |
| table ($table=undefined, $alias=undefined) |
| render_table () |
| render_from () |
| render_table_noalias () |
| field ($field, $table=null, $alias=null) |
| render_field () |
| where ($field, $cond=undefined, $value=undefined, $kind='where') |
| having ($field, $cond=undefined, $value=undefined) |
| _render_where ($kind) |
| render_where () |
| render_orwhere () |
| render_having () |
| join ($foreign_table, $master_field=null, $join_kind=null, $_foreign_alias=null) |
| render_join () |
| group ($option) |
| render_group () |
| order ($order, $desc=null) |
| render_order () |
| option ($option) |
| render_options () |
| option_insert ($option) |
| render_options_insert () |
| args ($args) |
| render_args () |
| ignore () |
| hasOption ($option) |
| hasInsertOption ($option) |
| limit ($cnt, $shift=0) |
| render_limit () |
| set ($field, $value=undefined) |
| render_set () |
| render_set_fields () |
| render_set_values () |
| bt ($s) |
| _setArray ($values, $name, $parse_commas=true) |
| SQLTemplate ($mode) |
| call ($fx, $args=null) |
| fx ($fx, $args=null) |
| render_fx () |
| sum ($arg=null) |
| count ($arg=null) |
| execute () |
| select () |
| insert () |
| insertAll ($array) |
| update () |
| replace () |
| delete () |
| truncate () |
| do_select () |
| do_insert () |
| do_update () |
| do_replace () |
| get () |
| getOne () |
| getRow () |
| getHash () |
| fetch ($mode=PDO::FETCH_ASSOC) |
| fetchAll () |
| do_getOne () |
| do_getAllHash () |
| do_getAll () |
| getAll () |
| do_getRow () |
| do_getHash () |
| calc_found_rows () |
| foundRows () |
| rewind () |
| next () |
| current () |
| key () |
| valid () |
| debug () |
| render () |
| _render () |
Data Fields |
| $args = array() |
| $params = array() |
| $extra_params = array() |
| $stmt = null |
| $template = null |
| $mode = null |
| $main_table = null |
| $default_field = '*' |
| $default_exception = 'Exception_DB' |
| $debug = false |
| $param_base = 'a' |
| $sql_templates |
| $bt = '`' |
| $data = false |
| $_iterating = false |
Detailed Description
Member Function Documentation
_setArray |
( |
$ |
values, |
|
|
$ |
name, |
|
|
$ |
parse_commas = true |
|
) |
| |
_unique |
( |
&$ |
array, |
|
|
$ |
desired = null |
|
) |
| |
This funcion given the associative $array and desired new key will return the best matching key which is not yet in the arary. For example if you have array('foo'=>x,'bar'=>x) and $desired is 'foo' function will return 'foo_2'. If 'foo_2' key also exists in that array, then 'foo_3' is returned and so on.
Reimplemented from AbstractObject.
Sets flag to hint SQL (if supported) to prepare total number of columns. Use foundRows() to read this afterwards
Reimplemented in DB_dsql_mysql.
call |
( |
$ |
fx, |
|
|
$ |
args = null |
|
) |
| |
Switches to call mode. Use with args()
Recursively renders sub-query or expression, combining parameters
Will set a flag which will output query (echo) as it is being rendered.
Removes definition for argument. $q->del('where')
Create new dsql object which can then be used as sub-query.
Converts value into parameter and returns reference. Use only during query rendering.
expr |
( |
$ |
expr, |
|
|
$ |
params = array() |
|
) |
| |
Returns new dynamic query and initializes it to use specific template.
fetch |
( |
$ |
mode = PDO::FETCH_ASSOC | ) |
|
Will execute the query (if it's not executed already) and return first row
field |
( |
$ |
field, |
|
|
$ |
table = null , |
|
|
$ |
alias = null |
|
) |
| |
Adds new column to resulting select by querying $field. Examples: $q->field('name'); Second argument specifies table for regular fields $q->field('name','user'); $q->field('name','user')->field('line1','address'); Array as a first argument will specify mulitple fields, same as calling field() multiple times $q->field(array('name','surname')); Associative array will assume that "key" holds the alias. Value may be object. $q->field(array('alias'=>'name','alias2'=>surname')); $q->field(array('alias'=>$q->expr(..), 'alias2'=>$q->dsql()->.. )); You may use array with aliases together with table specifier. $q->field(array('alias'=>'name','alias2'=>surname'),'user'); You can specify $q->expr() for calculated fields. Alias is mandatory. $q->field( $q->expr('2+2'),'alias'); // must always use alias You can use $q->dsql() for subqueries. Alias is mandatory. $q->field( $q->dsql()->table('x')... , 'alias'); // must always use alias
After fetching data, call this to find out how many rows there were in total. Call calc_found_rows() for better performance
fx |
( |
$ |
fx, |
|
|
$ |
args = null |
|
) |
| |
Will execute DSQL query and return all results inside array of hashes
Return expression containing a properly escaped field. Use make subquery condition reference parent query
Will execute DSQL query and return first row as hash (column=>value)
Will execute DSQL query and return first column of a first row
Will execute DSQL query and return first row as array (not hash)
Check if option was defined
Executes insert query. Returns ID of new record.
Inserts multiple rows of data. Uses ignore option.
join |
( |
$ |
foreign_table, |
|
|
$ |
master_field = null , |
|
|
$ |
join_kind = null , |
|
|
$ |
_foreign_alias = null |
|
) |
| |
limit |
( |
$ |
cnt, |
|
|
$ |
shift = 0 |
|
) |
| |
order |
( |
$ |
order, |
|
|
$ |
desc = null |
|
) |
| |
Shortcut to produce expression which concatinates "where" clauses with "OR" operator
Change prefix for parametric values. Useful if you are combining multiple queries.
Converts query into string format. This will contain parametric references
Conditionally returns "from", only if table is specified
Returns template component [table]
Returns template component [table_noalias]
Removes all definitions. Start from scratch
Defines a custom template variable.
Switches to select mode (which is default) for this query
Reimplemented in DB_dsql_pgsql.
Explicitly sets template to your query. Remember to change $this->mode if you switch this
Adds condition to your query Examples: $q->where('id',1); Second argument specifies table for regular fields $q->where('id>','1'); $q->where('id','>',1); You may use expressions $q->where($q->expr('a=b')); $q->where('date>',$q->expr('now()')); $q->where($q->expr('length(password)'),'>',5); Finally, subqueries can also be used $q->where('foo',$q->dsql()->table('foo')->field('name')); To specify OR conditions $q->where($q->orExpr()->where('a',1)->where('b',1)); you can also use the shortcut: $q->where(array('a is null','b is null'));
Field Documentation
Data accumulated by calling Definition methods, which is then used when rendering
Backticks will be added around all fields. Set this to '' if you prefer cleaner queries
Reimplemented in DB_dsql_pgsql.
call $q->debug() to turn on debugging.
If no fields are defined, this field is used
Manually-specified params
Used to determine main table.
prefix for all parameteric variables: a, a_2, a_3, etc
List of PDO parametical arguments for a query. Used only during rendering.
Initial value:array(
'select'=>"select [options] [field] [from] [table] [join] [where] [group] [having] [order] [limit]",
'insert'=>"insert [options_insert] into [table_noalias] ([set_fields]) values ([set_values])",
'replace'=>"replace [options_replace] into [table_noalias] ([set_fields]) values ([set_value])",
'update'=>"update [table_noalias] set [set] [where]",
'delete'=>"delete from [table_noalias] [where]",
'truncate'=>'truncate table [table_noalias]'
)
PDO Statement, if query is prepared. Used by iterator
Expression to use when converting to string
The documentation for this class was generated from the following file:
- /Users/rw/Sites/atk42/atk4/lib/DB/dsql.php