\BEAR_Query_Count

Countクエリー

通常のSELECTの代わりにCOUNTクエリーを行います。 onInit()内でBEAR_Queryの代わりにBEAR_Query_Countをインジェクトして使用します。

Summary

Methods
Properties
Constants
__construct()
select()
insert()
update()
delete()
quote()
isError()
onInject()
setConfig()
getConfig()
setService()
No public properties found
No constants found
_sort()
_countQuery()
_exception()
$_config
N/A
_selectRow()
_rewriteCountQuery()
No private properties found
N/A

Properties

$_config

$_config : array

Class config

Type

array

Methods

__construct()

__construct(array  $config) 

Universal constructor

設定を_configプロパティに代入します。

Parameters

array $config

ユーザー設定値

select()

select(string  $query, array  $params = array()) : integer

セレクト

通常のselect文の他にDB結果の一部だけをSELECTする機能と、HTMLページングの機能が合わさった
メソッドです。getAll()メソッドの引数に加えて一画面に表示するデータ数を
引数に指示するとページング(スライス)されたデータ結果と
エージェントに合わせたリンクHTML文字列が返ります。
$valuesが配列 $values)>ならWHERE $key1 = $id1 AND $key2 = $id2 ..と条件を作ってselectします。
リソース内で受け取った$valuesを条件にSELETするときに使います。

$paramsが空だと通常のSQL、連想配列が入っていると$queryをpreparedステートメート文として期待して実行します。

Parameters

string $query

クエリー

array $params

パラメータ

Returns

integer —

カウント数

insert()

insert(array  $values, null  $table = null, null  $types = null) : mixed|\mixeds

インサート

Parameters

array $values
null $table
null $types

Returns

mixed|\mixeds

update()

update(array  $values, string  $where, null  $table = null, null  $types = null) : mixed

アップデート

Parameters

array $values
string $where
null $table
null $types

Returns

mixed

delete()

delete(  $where, null  $table = null) : mixed

デリート

Parameters

$where
null $table

Returns

mixed

quote()

quote(  $value,   $type) : mixed

クオート

Parameters

$value
$type

Returns

mixed

isError()

isError(mixed  $result) : mixed

エラー?

Parameters

mixed $result

DB結果

Returns

mixed

onInject()

onInject() : void

Inject

設定にしたがってサービスをインジェクトします。

setConfig()

setConfig(mixed  $config, mixed  $values = null) : self

Set config

Parameters

mixed $config

(string) 設定キー | (array) 設定配列

mixed $values

(string) $configの時の設定値

Returns

self

getConfig()

getConfig(string  $key = null) : mixed

Get config

Parameters

string $key

設定キー、指定なければ全ての設定を取得

Returns

mixed

setService()

setService(string  $name, mixed  $service) : void

Set service

Parameters

string $name

サービスキー

mixed $service

サービス

_sort()

_sort(string  $sql) : string

ソート

クエリーからsort文を作成します。

exmaple 1.
?_sort=id

ORDER BY ID

example 2.
?_sort=id,-flg

ORDER BY ID, FLG DESC

Parameters

string $sql

DWL

Returns

string

_countQuery()

_countQuery(string  $query, array  $params = array()) : integer

カウントクエリー

Parameters

string $query
array $params

Returns

integer

_exception()

_exception(string  $msg, array  $config = array()) : \BEAR_Exception

例外の作成

Parameters

string $msg

例外メッセージ

array $config

例外config

Returns

\BEAR_Exception

_selectRow()

_selectRow(  $db, string  $query, array  $params, array  $values, mixed  $id) : mixed

Rowセレクト

$values配列に$idをキーにした変数があれば(単数、複数)それを=の条件としてwhereを作成してクエリーをRow取得する

example.

$values = array('id'=>5)
$id = 'id';

だと"WHERE id = '5'"のクエリーが生成される

$values = array('id'=>5, 'delete_flg'=>1)
$id = array('id', 'delete_flg');

だと"WHERE id = '5' AND delete_flg = '1'"のクエリーが生成される

                                    

Parameters

$db
string $query
array $params
array $values
mixed $id

Returns

mixed

_rewriteCountQuery()

_rewriteCountQuery(string  $query) : string

カウントクエリーを生成する

SQL文から"SELECT COUNT(*)" を付加したカウントクエリーを生成して返します。
COUNT文を含まないSQLからセレクト結果の個数を知るためCOUNTのクエリーを使用するのに用います
DBページャーで内部的にも使用されています。

Example 1. SQLからCOUNT()を取得

$count_query = $this->getCountSQL($query)); $total_items = $this->getOne($count_query, $params);

Parameters

string $query

クエリー

Returns

string —

書き換えられたクエリー | false(失敗