SQL
SQL
- Full name:
\Hazaar\DBI\Table\SQL
- Parent class:
\Hazaar\DBI\Table
Properties
keywords
private static string[] $keywords
- This property is static.
sql
private string $sql
Methods
__construct
public __construct(\Hazaar\DBI\Adapter $dbi, string $sql): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$dbi | \Hazaar\DBI\Adapter | |
$sql | string |
parse
public parse(string $sql): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$sql | string |
processSELECT
public processSELECT(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processFROM
public processFROM(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processWHERE
public processWHERE(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processGROUP_BY
public processGROUP_BY(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processHAVING
public processHAVING(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
parseUNION
public parseUNION(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processINTERSECT
public processINTERSECT(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processEXCEPT
public processEXCEPT(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processORDER_BY
public processORDER_BY(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processLIMIT
public processLIMIT(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processOFFSET
public processOFFSET(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
processFETCH
public processFETCH(string $line): void
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string |
splitWordBoundaries
private splitWordBoundaries(string $string, string[] $keywords, ?int& $start_pos = null): array<string,array<int,string>>
Parameters:
Parameter | Type | Description |
---|---|---|
$string | string | |
$keywords | string[] | |
$start_pos | ?int |
parseCondition
private parseCondition(string $line, bool $use_refs = false): string[]
Parameters:
Parameter | Type | Description |
---|---|---|
$line | string | |
$use_refs | bool |
Inherited methods
__construct
public __construct(\Hazaar\DBI\Adapter $adapter, ?string $tableName = null, ?string $alias = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$adapter | \Hazaar\DBI\Adapter | |
$tableName | ?string | |
$alias | ?string |
__toString
public __toString(): string
find
Search for records on a table with the provided search criteria.
public find(mixed $criteria = [], mixed $fields = []): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria to find records for |
$fields | mixed | a field definition |
findOne
Find a single row using the provided criteria, fields and order and return is as an array.
public findOne(mixed $criteria = [], mixed $fields = [], array<string,int>|string $order = null): null|array|false
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria |
$fields | mixed | a field definition array |
$order | array<string,int>|string | A valid order definition |
findOneRow
Find a single row using the provided criteria, fields and order and return is as an array.
public findOneRow(mixed $criteria = [], mixed $fields = [], array<string,int>|string $order = null): null|\Hazaar\DBI\Row
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria |
$fields | mixed | a field definition array |
$order | array<string,int>|string | A valid order definition |
exists
Check if rows exist in the database.
public exists(mixed $criteria = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria to check for existing rows |
toString
Return the current selection as a valid SQL string.
public toString(bool $terminate_with_colon = false, bool $untable = false): string
Parameters:
Parameter | Type | Description |
---|---|---|
$terminate_with_colon | bool | |
$untable | bool |
execute
Execute the current selection.
public execute(): \Hazaar\DBI\Result
prepare
Prepare a statement for execution and returns a new \Hazaar\Result object.
public prepare(mixed $criteria = [], mixed $fields = [], ?string $name = null): \Hazaar\DBI\Result
The criteria can contain zero or more names (:name) or question mark (?) parameter markers for which real values will be substituted when the statement is executed. Both named and question mark parameter markers cannot be used within the same statement template; only one or the other parameter style. Use these parameters to bind any user-input, do not include the user-input directly in the query.
You must include a unique parameter marker for each value you wish to pass in to the statement when you call \Hazaar\Result::execute(). You cannot use a named parameter marker of the same name more than once in a prepared statement.
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the query selection criteria |
$fields | mixed | the field selection |
$name | ?string |
fields
Defined the current field selection definition.
public fields(): \Hazaar\DBI\Table
select
Alias for Hazaar\DBI\Table::fields().
public select(): \Hazaar\DBI\Table
distinct
Selects only distinct rows that match based on the specified expressions.
public distinct(): \Hazaar\DBI\Table
where
Defines a WHERE selection criteria.
public where(mixed $criteria): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed |
group
public group(): \Hazaar\DBI\Table
having
public having(): \Hazaar\DBI\Table
window
public window(string $name, string $partitionBy, array<string,int>|string $orderBy = null): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | |
$partitionBy | string | |
$orderBy | array<string,int>|string |
join
Join a table to the current query using the provided join criteria.
public join(string $references, array|string $on = null, string $alias = null, string $type = 'INNER'): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$references | string | the table to join to the query |
$on | array|string | The join criteria. This is mostly just a standard query selection criteria. |
$alias | string | an alias to use for the joined table |
$type | string | the join type such as INNER, OUTER, LEFT, RIGHT, etc |
innerJoin
public innerJoin(string $references, array $on = null, ?string $alias = null): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | array | |
$alias | ?string |
leftJoin
public leftJoin(string $references, array $on = null, ?string $alias = null): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | array | |
$alias | ?string |
rightJoin
public rightJoin(string $references, array $on = null, ?string $alias = null): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | array | |
$alias | ?string |
fullJoin
public fullJoin(string $references, array|string $on = null, ?string $alias = null): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | array|string | |
$alias | ?string |
sort
public sort(array<string,int>|string $fieldDef, int $sortFlags = SORT_ASC): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$fieldDef | array<string,int>|string | |
$sortFlags | int |
limit
public limit(?int $limit = null): int|\Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$limit | ?int |
offset
public offset(?int $offset = null): int|\Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$offset | ?int |
insert
Insert a record into a database table.
public insert(mixed $fields, mixed $returning = null, array|string $updateColumns = null, array $updateWhere = null): array|false|int
Using $updateColumns it's possible to perform an "upsert". An upsert is an INSERT, that when it fails, columns can be updated in the existing row.
Parameters:
Parameter | Type | Description |
---|---|---|
$fields | mixed | the fields to be inserted |
$returning | mixed | a column to return when the row is inserted (usually the primary key) |
$updateColumns | array|string | the names of the columns to be updated if the row exists |
$updateWhere | array | Not used yet |
update
public update(mixed $criteria, mixed $fields, mixed $returning = null): array|false|int
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed | |
$fields | mixed | |
$returning | mixed |
delete
public delete(mixed $criteria): false|int
Parameters:
Parameter | Type | Description |
---|---|---|
$criteria | mixed |
deleteAll
public deleteAll(): false|int
row
public row(int $offset): null|\Hazaar\DBI\Row
Parameters:
Parameter | Type | Description |
---|---|---|
$offset | int |
rows
public rows(): \Hazaar\DBI\Row[]|false
fetch
public fetch(int $cursorOrientation = PDO::FETCH_ORI_NEXT, int $offset, bool $clobberDupNamedCols = false): array
Parameters:
Parameter | Type | Description |
---|---|---|
$cursorOrientation | int | |
$offset | int | |
$clobberDupNamedCols | bool |
fetchColumn
public fetchColumn(int $column): array
Parameters:
Parameter | Type | Description |
---|---|---|
$column | int |
fetchAll
public fetchAll(mixed $fetchArgument = null, bool $clobberDupNamedCols = false): array
Parameters:
Parameter | Type | Description |
---|---|---|
$fetchArgument | mixed | |
$clobberDupNamedCols | bool |
fetchAllColumn
public fetchAllColumn(string $columnName, mixed $fetchArgument = null, bool $clobberDupNamedCols = false): array
Parameters:
Parameter | Type | Description |
---|---|---|
$columnName | string | |
$fetchArgument | mixed | |
$clobberDupNamedCols | bool |
reset
public reset(): \Hazaar\DBI\Row
current
public current(): \Hazaar\DBI\Row
key
public key(): null|int|string
next
public next(): void
rewind
public rewind(): void
valid
public valid(): bool
count
public count(): int
getResult
public getResult(): \Hazaar\DBI\Result
collate
Collates a result into a simple key/value array.
public collate(string $indexColumn, string $valueColumn = null, string $groupColumn = null): array<string,mixed>
This is useful for generating SELECT lists directly from a resultset.
Parameters:
Parameter | Type | Description |
---|---|---|
$indexColumn | string | the column to use as the array index |
$valueColumn | string | the column to use as the array value |
$groupColumn | string | optional column name to group items by |
truncate
Truncate the table.
public truncate(bool $only = false, bool $restartIdentity = false, bool $cascade = false): bool
Truncating a table quickly removes all rows from a set of tables. It has the same effect as Hazaar\DBI\Table::deleteAll() on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM operation. This is most useful on large tables.
Parameters:
Parameter | Type | Description |
---|---|---|
$only | bool | Only the named table is truncated. If FALSE, the table and all its descendant tables (if any) are truncated. |
$restartIdentity | bool | Automatically restart sequences owned by columns of the truncated table(s). The default is to no restart. |
$cascade | bool | If TRUE, automatically truncate all tables that have foreign-key references to any of the named tables, or to any tables added to the group due to CASCADE. If FALSE, Refuse to truncate if any of the tables have foreign-key references from tables that are not listed in the command. FALSE is the default. |
listUsedTables
List all tables that will be accessed in this table query.
public listUsedTables(): array<int,string>
Returns an array of table names of all tables used in this query, including joins.
from
Add a table or function to the FROM table reference.
public from(string $table, ?string $alias = null): \Hazaar\DBI\Table
PostgreSQL combines table references using a cross-join.
See: here for examples.
Parameters:
Parameter | Type | Description |
---|---|---|
$table | string | |
$alias | ?string |
union
Append a table query using a UNION.
public union(\Hazaar\DBI\Table $query): \Hazaar\DBI\Table
This will return results from both queries combined together.
Parameters:
Parameter | Type | Description |
---|---|---|
$query | \Hazaar\DBI\Table |
intersect
Append a table query using an INTERSECT.
public intersect(\Hazaar\DBI\Table $query): \Hazaar\DBI\Table
This will return only results that exist in both queries.
Parameters:
Parameter | Type | Description |
---|---|---|
$query | \Hazaar\DBI\Table |
except
Append a table query using an EXCEPT.
public except(\Hazaar\DBI\Table $query): \Hazaar\DBI\Table
This will return results from the first query except if they appear in the second.
Parameters:
Parameter | Type | Description |
---|---|---|
$query | \Hazaar\DBI\Table |
errorInfo
public errorInfo(): array
prepareFrom
private prepareFrom(): string
tables
private tables(): string[]
prepareOrder
private prepareOrder(array|string $orderDefinition): string
Parameters:
Parameter | Type | Description |
---|---|---|
$orderDefinition | array|string |
Automatically generated on 2024-11-14