Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -197,25 +197,29 @@ |
198 | 198 | } |
199 | 199 | |
200 | 200 | function freeResult( $res ) { |
201 | | - if ( $res instanceof ResultWrapper ) |
| 201 | + if ( $res instanceof ResultWrapper ) { |
202 | 202 | $res->result = null; |
203 | | - else |
| 203 | + } else { |
204 | 204 | $res = null; |
| 205 | + } |
205 | 206 | } |
206 | 207 | |
207 | 208 | function fetchObject( $res ) { |
208 | | - if ( $res instanceof ResultWrapper ) |
| 209 | + if ( $res instanceof ResultWrapper ) { |
209 | 210 | $r =& $res->result; |
210 | | - else |
| 211 | + } else { |
211 | 212 | $r =& $res; |
| 213 | + } |
212 | 214 | |
213 | 215 | $cur = current( $r ); |
214 | 216 | if ( is_array( $cur ) ) { |
215 | 217 | next( $r ); |
216 | 218 | $obj = new stdClass; |
217 | | - foreach ( $cur as $k => $v ) |
218 | | - if ( !is_numeric( $k ) ) |
| 219 | + foreach ( $cur as $k => $v ) { |
| 220 | + if ( !is_numeric( $k ) ) { |
219 | 221 | $obj->$k = $v; |
| 222 | + } |
| 223 | + } |
220 | 224 | |
221 | 225 | return $obj; |
222 | 226 | } |
— | — | @@ -223,11 +227,11 @@ |
224 | 228 | } |
225 | 229 | |
226 | 230 | function fetchRow( $res ) { |
227 | | - if ( $res instanceof ResultWrapper ) |
| 231 | + if ( $res instanceof ResultWrapper ) { |
228 | 232 | $r =& $res->result; |
229 | | - else |
| 233 | + } else { |
230 | 234 | $r =& $res; |
231 | | - |
| 235 | + } |
232 | 236 | $cur = current( $r ); |
233 | 237 | if ( is_array( $cur ) ) { |
234 | 238 | next( $r ); |
— | — | @@ -280,19 +284,23 @@ |
281 | 285 | } |
282 | 286 | |
283 | 287 | function dataSeek( $res, $row ) { |
284 | | - if ( $res instanceof ResultWrapper ) |
| 288 | + if ( $res instanceof ResultWrapper ) { |
285 | 289 | $r =& $res->result; |
286 | | - else |
| 290 | + } else { |
287 | 291 | $r =& $res; |
| 292 | + } |
288 | 293 | reset( $r ); |
289 | | - if ( $row > 0 ) |
290 | | - for ( $i = 0; $i < $row; $i++ ) |
| 294 | + if ( $row > 0 ) { |
| 295 | + for ( $i = 0; $i < $row; $i++ ) { |
291 | 296 | next( $r ); |
| 297 | + } |
| 298 | + } |
292 | 299 | } |
293 | 300 | |
294 | 301 | function lastError() { |
295 | | - if ( !is_object( $this->mConn ) ) |
| 302 | + if ( !is_object( $this->mConn ) ) { |
296 | 303 | return "Cannot return last error, no db connection"; |
| 304 | + } |
297 | 305 | $e = $this->mConn->errorInfo(); |
298 | 306 | return isset( $e[2] ) ? $e[2] : ''; |
299 | 307 | } |
— | — | @@ -355,9 +363,11 @@ |
356 | 364 | * Filter the options used in SELECT statements |
357 | 365 | */ |
358 | 366 | function makeSelectOptions( $options ) { |
359 | | - foreach ( $options as $k => $v ) |
360 | | - if ( is_numeric( $k ) && $v == 'FOR UPDATE' ) |
| 367 | + foreach ( $options as $k => $v ) { |
| 368 | + if ( is_numeric( $k ) && $v == 'FOR UPDATE' ) { |
361 | 369 | $options[$k] = ''; |
| 370 | + } |
| 371 | + } |
362 | 372 | return parent::makeSelectOptions( $options ); |
363 | 373 | } |
364 | 374 | |
— | — | @@ -365,20 +375,28 @@ |
366 | 376 | * Based on generic method (parent) with some prior SQLite-sepcific adjustments |
367 | 377 | */ |
368 | 378 | function insert( $table, $a, $fname = 'DatabaseSqlite::insert', $options = array() ) { |
369 | | - if ( !count( $a ) ) return true; |
370 | | - if ( !is_array( $options ) ) $options = array( $options ); |
| 379 | + if ( !count( $a ) ) { |
| 380 | + return true; |
| 381 | + } |
| 382 | + if ( !is_array( $options ) ) { |
| 383 | + $options = array( $options ); |
| 384 | + } |
371 | 385 | |
372 | 386 | # SQLite uses OR IGNORE not just IGNORE |
373 | | - foreach ( $options as $k => $v ) |
374 | | - if ( $v == 'IGNORE' ) |
| 387 | + foreach ( $options as $k => $v ) { |
| 388 | + if ( $v == 'IGNORE' ) { |
375 | 389 | $options[$k] = 'OR IGNORE'; |
| 390 | + } |
| 391 | + } |
376 | 392 | |
377 | 393 | # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts |
378 | 394 | if ( isset( $a[0] ) && is_array( $a[0] ) ) { |
379 | 395 | $ret = true; |
380 | | - foreach ( $a as $k => $v ) |
381 | | - if ( !parent::insert( $table, $v, "$fname/multi-row", $options ) ) |
| 396 | + foreach ( $a as $k => $v ) { |
| 397 | + if ( !parent::insert( $table, $v, "$fname/multi-row", $options ) ) { |
382 | 398 | $ret = false; |
| 399 | + } |
| 400 | + } |
383 | 401 | } else { |
384 | 402 | $ret = parent::insert( $table, $a, "$fname/single-row", $options ); |
385 | 403 | } |
— | — | @@ -392,9 +410,11 @@ |
393 | 411 | # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries |
394 | 412 | if ( isset( $rows[0] ) && is_array( $rows[0] ) ) { |
395 | 413 | $ret = true; |
396 | | - foreach ( $rows as $k => $v ) |
397 | | - if ( !parent::replace( $table, $uniqueIndexes, $v, "$fname/multi-row" ) ) |
| 414 | + foreach ( $rows as $k => $v ) { |
| 415 | + if ( !parent::replace( $table, $uniqueIndexes, $v, "$fname/multi-row" ) ) { |
398 | 416 | $ret = false; |
| 417 | + } |
| 418 | + } |
399 | 419 | } else { |
400 | 420 | $ret = parent::replace( $table, $uniqueIndexes, $rows, "$fname/single-row" ); |
401 | 421 | } |