Zend/Db/Sqlの変更点
- 追加された行はこの色です。
- 削除された行はこの色です。
- 移動:バックアップ
- 最新のバージョン:2014-04-09 16:00:45
- バージョン:(Rev:QRl0wKWZn9)2014-04-09 15:27:26
| Old | New | 差分 | |
|---|---|---|---|
| 1 | 1 | #contents | |
| 2 | 2 | *Insert [#briuNCF] | |
| 3 | 3 | Zend\Db\Sql\Sqlクラスのinsertメソッドから呼び出される。 | |
| 4 | - | ||
| 4 | + | ||
| 5 | 5 | **基本的な利用方法 [#EMRsbFQ] | |
| 6 | 6 | #sh(php){{ | |
| 7 | 7 | $sql = new Zend\Db\Sql\Sql($adapter); | |
| 13 | 13 | INSERT INTO `test` (`id`, `name`) VALUES ('1', 'hoge') | |
| 14 | 14 | ** コンストラクタ [#ulEBVHO] | |
| 15 | 15 | :引数|string|TableIdentifier $table | |
| 16 | - | ||
| 16 | + | ||
| 17 | 17 | テーブル名を指定する、intoメソッドが優先される | |
| 18 | 18 | #sh(php){$insert=$sql->insert("test");} | |
| 19 | - | ||
| 19 | + | ||
| 20 | 20 | ** intoメソッド [#5bfgHXP] | |
| 21 | 21 | :引数|string|TableIdentifier $table | |
| 22 | - | ||
| 22 | + | ||
| 23 | 23 | テーブル名を指定する | |
| 24 | 24 | #sh(php){$insert->into("test");} | |
| 25 | - | ||
| 25 | + | ||
| 26 | 26 | ** columns [#6tEUBn8] | |
| 27 | 27 | :引数|array $columns | |
| 28 | - | ||
| 28 | + | ||
| 29 | 29 | カラム名を指定する。 | |
| 30 | 30 | &color(#FF0000){''Zend 2.3現在、columnsメソッドより後にvaluesメソッドを呼び出し、かつ第二引数にself::VALUES_SETを設定するか第二引数を省略した場合、columns設定値が消失する''}; | |
| 31 | 31 | #sh(php){{ | |
| 32 | 32 | $insert->columns(array("id", "name", "value")); | |
| 33 | 33 | }} | |
| 34 | - | ||
| 34 | + | ||
| 35 | 35 | ** values [#o66wZrF] | |
| 36 | 36 | :引数|array|Select $values | |
| 37 | 37 | string $flag VALUES_MERGE|VALUES_SET を指定、デフォルトはVALUES_SET | |
| 38 | - | ||
| 38 | + | ||
| 39 | 39 | Insertする値の設定を行う | |
| 40 | 40 | #sh(php){{ | |
| 41 | 41 | $insert->values(array("id"=>"1","name"=>"hoge")); | |
| 42 | 42 | }} | |
| 43 | - | ||
| 44 | - | ||
| 43 | + | ||
| 44 | + | ||
| 45 | 45 | ** select [#KMCZP0n] | |
| 46 | 46 | :引数|Select $select | |
| 47 | - | ||
| 47 | + | ||
| 48 | 48 | valuesメソッドが呼び出される。以下と全く同じである。 | |
| 49 | 49 | #sh(php){$insert->values($select);} | |
| 50 | - | ||
| 51 | - | ||
| 50 | + | ||
| 51 | + | ||
| 52 | 52 | ** getRawState [#sXaDmpJ] | |
| 53 | 53 | :引数|string $key | |
| 54 | - | ||
| 54 | + | ||
| 55 | 55 | table名、columns設定値、values設定値を返す。 | |
| 56 | 56 | #sh(php){{ | |
| 57 | 57 | // テーブル情報を返す | |
| 63 | 63 | // 上記のすべてを連想配列で返す | |
| 64 | 64 | $insert->getRawState(); | |
| 65 | 65 | }} | |
| 66 | - | ||
| 66 | + | ||
| 67 | 67 | * Select [#8hdU3yM] | |
| 68 | 68 | Zend\Db\Sql\Sqlクラスのselectメソッドから呼び出される。 | |
| 69 | 69 | **基本的な利用方法 [#5ljzdHF] | |
| 79 | 79 | SELECT `test`.`rev_id` AS `id`, `test`.`rev_name` AS `name`, `test`.`rev_value` AS `value` FROM `test` WHERE `name` = 'yamada' AND value > 100 LIMIT 1 | |
| 80 | 80 | ** コンストラクタ [#U0lUGlM] | |
| 81 | 81 | :引数|null|string|array|TableIdentifier $table | |
| 82 | - | ||
| 82 | + | ||
| 83 | 83 | テーブル名を指定する | |
| 84 | 84 | ここで指定するとread onlyになり、fromから指定できなくなる | |
| 85 | - | ||
| 85 | + | ||
| 86 | 86 | ** from [#vHKbmez] | |
| 87 | 87 | :引数|string|array|TableIdentifier $table | |
| 88 | - | ||
| 88 | + | ||
| 89 | 89 | テーブル名を指定する | |
| 90 | 90 | コンストラクタで指定した場合、指定できない | |
| 91 | - | ||
| 91 | + | ||
| 92 | 92 | ** quantifier [#wh64NXe] | |
| 93 | 93 | :引数|string|Expression $quantifier DISTINCT|ALL | |
| 94 | - | ||
| 94 | + | ||
| 95 | 95 | DISTINCT属性を設定するか。 | |
| 96 | - | ||
| 96 | + | ||
| 97 | 97 | ** columns [#StzSgn0] | |
| 98 | 98 | :引数|array $columns | |
| 99 | - | ||
| 99 | + | ||
| 100 | 100 | selectするカラム名を指定する | |
| 101 | 101 | 連想配列の場合、''key値がエイリアス名''になる。 | |
| 102 | 102 | #sh(php){$select->columns(array("*"));} | |
| 105 | 105 | `test`.`id` AS `id`, `test`.`name` AS `name`, `test`.`value` AS `value` | |
| 106 | 106 | #sh(php){$select->columns(array("id"=>"rev_id", "name"=>"rev_name", "value"=>"rev_value"));} | |
| 107 | 107 | `test`.`rev_id` AS `id`, `test`.`rev_name` AS `name`, `test`.`rev_value` AS `value` | |
| 108 | - | ||
| 108 | + | ||
| 109 | 109 | ** join [#slAKJ1d] | |
| 110 | 110 | :引数|string|array $name | |
| 111 | 111 | string $on | |
| 112 | 112 | string|array $columns | |
| 113 | 113 | string $type JOIN_*の中から一つ | |
| 114 | - | ||
| 114 | + | ||
| 115 | 115 | 結合設定 | |
| 116 | 116 | JOIN_INNER、JOIN_OUTER、JOIN_LEFT、JOIN_RIGHTの4種類が指定可能 | |
| 117 | 117 | #sh(php){$select->join("test2", "test.id = test2.id", Zend\Db\Sql\Select::SQL_STAR, Zend\Db\Sql\Select::JOIN_LEFT);} | |
| 118 | 118 | `test2`.* FROM `test` LEFT JOIN `test2` ON `test`.`id` = `test2`.`id` | |
| 119 | 119 | #sh(php){$select->join("test2", "test.id = test2.id", array("id", "name", "age"), Zend\Db\Sql\Select::JOIN_LEFT);} | |
| 120 | 120 | `test2`.`id` AS `id`, `test2`.`name` AS `name`, `test2`.`age` AS `age` FROM `test` LEFT JOIN `test2` ON `test`.`id` = `test2`.`id` | |
| 121 | - | ||
| 121 | + | ||
| 122 | 122 | ** where [#LrEKQK5] | |
| 123 | 123 | :引数|Where|\Closure|string|array|Predicate\PredicateInterface $predicate | |
| 124 | 124 | string $combination Predicate\PredicateSetで定義されている OP_* の中から一つ | |
| 128 | 128 | WHERE `id` = '1' AND `name` = 'yamada' | |
| 129 | 129 | #sh(php){$select->where(array("id"=>1, "name"=>"yamada"), Zend\Db\Sql\Predicate\PredicateSet::OP_OR);} | |
| 130 | 130 | WHERE `id` = '1' OR `name` = 'yamada' | |
| 131 | - | Predicate\Predicate | |
| 131 | + | Predicate\PredicateInterface | |
| 132 | 132 | #sh(php){{ | |
| 133 | 133 | $nest = $select->where->nest(); | |
| 134 | - | $nest->equalTo("name", "yamada"); | |
| 135 | - | $nest->OR->equalTo("age", "20"); | |
| 134 | + | $nest->equalTo("name", "yamada"); | |
| 135 | + | $nest->OR->equalTo("age", "20"); | |
| 136 | 136 | $nest->unnest(); | |
| 137 | 137 | }} | |
| 138 | 138 | WHERE (`name` = 'yamada' OR `age` = '20') | |
| 139 | 139 | #sh(php){{ | |
| 140 | 140 | $nest = $select->where->nest(); | |
| 141 | 141 | $nest2_1 = $nest->nest(); | |
| 142 | - | $nest2_1->equalTo("name", "yamada"); | |
| 143 | - | $nest2_1->OR->equalTo("name", "tanaka"); | |
| 142 | + | $nest2_1->equalTo("name", "yamada"); | |
| 143 | + | $nest2_1->OR->equalTo("name", "tanaka"); | |
| 144 | 144 | $nest2_1->unnest(); | |
| 145 | - | $nest2_2 = $nest->AND->nest(); | |
| 146 | - | $nest2_2->equalTo("age", "10"); | |
| 147 | - | $nest2_2->OR->equalTo("age", "20"); | |
| 145 | + | $nest2_2 = $nest->AND->nest(); | |
| 146 | + | $nest2_2->equalTo("age", "10"); | |
| 147 | + | $nest2_2->OR->equalTo("age", "20"); | |
| 148 | 148 | $nest2_2->unnest(); | |
| 149 | 149 | $nest->unnest(); | |
| 150 | 150 | }} | |
| 151 | 151 | WHERE ((`name` = 'yamada' OR `name` = 'tanaka') AND (`age` = '10' OR `age` = '20')) | |
| 152 | + | #sh(php){$select->where->NEST->equalTo("name", "yamada")->OR->equalTo("age", "20")->UNNEST;} | |
| 153 | + | WHERE (`name` = 'yamada' OR `age` = '20') | |
| 154 | + | #sh(php){{ | |
| 155 | + | $select->where->NEST | |
| 156 | + | ->NEST | |
| 157 | + | ->equalTo("name", "yamada") | |
| 158 | + | ->OR->equalTo("name", "tanaka") | |
| 159 | + | ->UNNEST | |
| 160 | + | ->AND->NEST | |
| 161 | + | ->equalTo("age", "10") | |
| 162 | + | ->OR->equalTo("age", "20") | |
| 163 | + | ->UNNEST | |
| 164 | + | ->UNNEST; | |
| 165 | + | }} | |
| 166 | + | WHERE ((`name` = 'yamada' OR `name` = 'tanaka') AND (`age` = '10' OR `age` = '20')) | |
| 152 | 167 | ** group [#8OTtXtP] | |
| 153 | 168 | :|引数|string|array | |
| 154 | - | ||
| 169 | + | ||
| 155 | 170 | グループ設定 | |
| 156 | 171 | #sh(php){$select->group("name");} | |
| 157 | 172 | GROUP BY `name` | |
| 158 | - | ||
| 173 | + | ||
| 159 | 174 | ** having [#aDnoqCD] | |
| 160 | 175 | :引数|Where|\Closure|string|array $predicate | |
| 161 | 176 | string $combination One of the OP_* constants from Predicate\PredicateSet | |
| 162 | - | ||
| 177 | + | ||
| 163 | 178 | #sh(php){$select->having(array("age"=>10, "weight"=>20));} | |
| 164 | 179 | HAVING `age` = '10' AND `weight` = '20' | |
| 165 | - | ||
| 180 | + | ||
| 166 | 181 | ** order [#LBspsa8] | |
| 167 | 182 | :引数|string|array $order | |
| 168 | - | ||
| 183 | + | ||
| 169 | 184 | オーダー設定 | |
| 170 | 185 | #sh(php){$select->order("name DESC");} | |
| 171 | 186 | ORDER BY `name` DESC | |
| 172 | 187 | #sh(php){$select->order("name ASC");} | |
| 173 | 188 | ORDER BY `name` ASC | |
| 174 | - | ||
| 189 | + | ||
| 175 | 190 | ** limit [#jolzJvg] | |
| 176 | 191 | :引数|int $limit | |
| 177 | - | ||
| 192 | + | ||
| 178 | 193 | Limit設定 | |
| 179 | 194 | #sh(php){$select->limit(1);} | |
| 180 | 195 | LIMIT 1 | |
| 181 | - | ||
| 196 | + | ||
| 182 | 197 | ** offset [#zD1URqW] | |
| 183 | 198 | :引数|int $offset | |
| 184 | - | ||
| 199 | + | ||
| 185 | 200 | Offset設定 | |
| 186 | 201 | #sh(php){$select->offset(3);} | |
| 187 | 202 | OFFSET 3 | |
| 189 | 204 | :引数|Select $select | |
| 190 | 205 | string $type | |
| 191 | 206 | string $modifier | |
| 192 | - | ||
| 207 | + | ||
| 193 | 208 | * Delete [#FY0yK4i] | |
| 194 | 209 | Zend\Db\Sql\Sqlクラスのdeleteメソッドから呼び出される。 | |
| 195 | 210 | **基本的な利用方法 [#lBWhe9H] | |
| 196 | - | ** コンストラクタ [#qNzPl6x] | |
| 197 | - | ||
| 211 | + | ** コンストラクタ [#AiHrSi5] | |
| 212 | + | :引数|null|string|TableIdentifier $table | |
| 213 | + | ||
| 214 | + | テーブル名を指定する、fromメソッドが優先される | |
| 215 | + | ||
| 216 | + | ** from [#8EVuCLJ] | |
| 217 | + | :引数|string|TableIdentifier $table | |
| 218 | + | ||
| 219 | + | テーブル名を指定する | |
| 220 | + | ||
| 221 | + | **where [#F1VAe0W] | |
| 222 | + | [[selectメソッドのwhere>Zend/Db/Sql#LrEKQK5]]を参照のこと。 | |
| 223 | + | ||
| 198 | 224 | * Update [#wj5CLPO] | |
| 199 | 225 | Zend\Db\Sql\Sqlクラスのupdateメソッドから呼び出される。 | |
| 200 | 226 | **基本的な利用方法 [#nmLH3Nz] | |
| 201 | 227 | ** コンストラクタ [#IEdT5sD] | |
| 228 | + | :引数|null|string|TableIdentifier $table | |
| 229 | + | ||
| 230 | + | テーブル名を指定 | |
| 231 | + | ||
| 232 | + | **table [#2Kz2hCu] | |
| 233 | + | :引数|string|TableIdentifier $table | |
| 234 | + | ||
| 235 | + | テーブル名を指定 | |
| 236 | + | ||
| 237 | + | **set [#EgjEkNU] | |
| 238 | + | :引数|array $values 連想配列 | |
| 239 | + | string $flag VALUES_*の値 | |
| 240 | + | ||
| 241 | + | **where [#ufoF0Ek] | |
| 242 | + | [[selectメソッドのwhere>Zend/Db/Sql#LrEKQK5]]を参照のこと。 | |