[ Index ] |
|
Code source de dotProject 2.1 RC1 |
1 <?php 2 3 /*{{{ Copyright 2003,2004 Adam Donnison <adam@saki.com.au> 4 5 This file is part of the collected works of Adam Donnison. 6 7 This is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 }}}*/ 21 22 if (! defined('DP_BASE_DIR')) { 23 die('This file should not be called directly'); 24 } 25 26 require_once DP_BASE_DIR."/lib/adodb/adodb.inc.php"; 27 28 define('QUERY_STYLE_ASSOC', ADODB_FETCH_ASSOC); 29 define('QUERY_STYLE_NUM' , ADODB_FETCH_NUM); 30 define('QUERY_STYLE_BOTH', ADODB_FETCH_BOTH); 31 32 /** {{{1 class DBQuery 33 * Container for creating prefix-safe queries. Allows build up of 34 * a select statement by adding components one at a time. 35 * 36 * @version $Id: query.class.php,v 1.23.2.5 2007/01/31 09:36:52 ajdonnison Exp $ 37 * @package dotProject 38 * @access public 39 * @author Adam Donnison <adam@saki.com.au> 40 * @license GPL version 2 or later. 41 * @copyright (c) 2003 Adam Donnison 42 */ 43 class DBQuery { 44 var $query; 45 var $table_list; 46 var $where; 47 var $order_by; 48 var $group_by; 49 var $limit; 50 var $offset; 51 var $join; 52 var $type; 53 var $update_list; 54 var $value_list; 55 var $create_table; 56 var $create_definition; 57 var $_table_prefix; 58 var $_query_id = null; 59 var $_old_style = null; 60 61 function DBQuery($prefix = null) 62 { 63 global $dPconfig; 64 65 if (isset($prefix)) 66 $this->_table_prefix = $prefix; 67 else if (isset($dPconfig['dbprefix'])) 68 $this->_table_prefix = $dPconfig['dbprefix']; 69 else 70 $this->_table_prefix = ""; 71 72 $this->clear(); 73 } 74 75 76 function clear() 77 { 78 global $ADODB_FETCH_MODE; 79 if (isset($this->_old_style)) { 80 $ADODB_FETCH_MODE = $this->_old_style; 81 $this->_old_style = null; 82 } 83 $this->type = 'select'; 84 $this->query = null; 85 $this->table_list = null; 86 $this->where = null; 87 $this->order_by = null; 88 $this->group_by = null; 89 $this->limit = null; 90 $this->offset = -1; 91 $this->join = null; 92 $this->value_list = null; 93 $this->update_list = null; 94 $this->create_table = null; 95 $this->create_definition = null; 96 if ($this->_query_id) 97 $this->_query_id->Close(); 98 $this->_query_id = null; 99 } 100 101 function clearQuery() 102 { 103 if ($this->_query_id) 104 $this->_query_id->Close(); 105 $this->_query_id = null; 106 } 107 108 /** 109 * Add a hash item to an array. 110 * 111 * @access private 112 * @param string $varname Name of variable to add/create 113 * @param mixed $name Data to add 114 * @param string $id Index to use in array. 115 */ 116 function addMap($varname, $name, $id) 117 { 118 if (!isset($this->$varname)) 119 $this->$varname = array(); 120 if (isset($id)) 121 $this->{$varname}[$id] = $name; 122 else 123 $this->{$varname}[] = $name; 124 } 125 126 /** 127 * Adds a table to the query. A table is normally addressed by an 128 * alias. If you don't supply the alias chances are your code will 129 * break. You can add as many tables as are needed for the query. 130 * E.g. addTable('something', 'a') will result in an SQL statement 131 * of {PREFIX}table as a. 132 * Where {PREFIX} is the system defined table prefix. 133 * 134 * @param string $name Name of table, without prefix. 135 * @parem string $id Alias for use in query/where/group clauses. 136 */ 137 function addTable($name, $id = null) 138 { 139 $this->addMap('table_list', $name, $id); 140 } 141 142 /** 143 * Add a clause to an array. Checks to see variable exists first. 144 * then pushes the new data onto the end of the array. 145 */ 146 function addClause($clause, $value, $check_array = true) 147 { 148 dprint(__FILE__, __LINE__, 8, "Adding '$value' to $clause clause"); 149 if (!isset($this->$clause)) 150 $this->$clause = array(); 151 if ($check_array && is_array($value)) { 152 foreach ($value as $v) { 153 array_push($this->$clause, $v); 154 } 155 } else { 156 array_push($this->$clause, $value); 157 } 158 } 159 160 /** 161 * Add the actual select part of the query. E.g. '*', or 'a.*' 162 * or 'a.field, b.field', etc. You can call this multiple times 163 * and it will correctly format a combined query. 164 * 165 * @param string $query Query string to use. 166 */ 167 function addQuery($query) 168 { 169 $this->addClause('query', $query); 170 } 171 172 function addInsert($field, $value, $set = false, $func = false) 173 { 174 if ($set) 175 { 176 if (is_array($field)) 177 $fields = $field; 178 else 179 $fields = explode(',', $field); 180 181 if (is_array($value)) 182 $values = $value; 183 else 184 $values = explode(',', $value); 185 186 for($i = 0; $i < count($fields); $i++) 187 $this->addMap('value_list', $this->quote($values[$i]), $fields[$i]); 188 } 189 else if (!$func) 190 $this->addMap('value_list', $this->quote($value), $field); 191 else 192 $this->addMap('value_list', $value, $field); 193 $this->type = 'insert'; 194 } 195 196 // implemented addReplace() on top of addInsert() 197 198 function addReplace($field, $value, $set = false, $func = false) 199 { 200 $this->addInsert($field, $value, $set, $func); 201 $this->type = 'replace'; 202 } 203 204 205 function addUpdate($field, $value, $set = false) 206 { 207 if ($set) 208 { 209 if (is_array($field)) 210 $fields = $field; 211 else 212 $fields = explode(',', $field); 213 214 if (is_array($value)) 215 $values = $value; 216 else 217 $values = explode(',', $value); 218 219 for($i = 0; $i < count($fields); $i++) 220 $this->addMap('update_list', $values[$i], $fields[$i]); 221 } 222 else 223 $this->addMap('update_list', $value, $field); 224 $this->type = 'update'; 225 } 226 227 function createTable($table) 228 { 229 $this->type = 'createPermanent'; 230 $this->create_table = $table; 231 } 232 233 function createTemp($table) 234 { 235 $this->type = 'create'; 236 $this->create_table = $table; 237 } 238 239 function dropTable($table) 240 { 241 $this->type = 'drop'; 242 $this->create_table = $table; 243 } 244 245 function dropTemp($table) 246 { 247 $this->type = 'drop'; 248 $this->create_table = $table; 249 } 250 251 function alterTable($table) 252 { 253 $this->create_table = $table; 254 $this->type = 'alter'; 255 } 256 257 function addField($name, $type) 258 { 259 if (! is_array($this->create_definition)) 260 $this->create_definition = array(); 261 $this->create_definition[] = array('action' => 'ADD', 262 'type' => '', 263 'spec' => $name . ' ' . $type); 264 } 265 266 function dropField($name) 267 { 268 if (! is_array($this->create_definition)) 269 $this->create_definition = array(); 270 $this->create_definition[] = array('action' => 'DROP', 271 'type' => '', 272 'spec' => $name); 273 } 274 275 function addIndex($name, $type) 276 { 277 if (! is_array($this->create_definition)) 278 $this->create_definition = array(); 279 $this->create_definition[] = array('action' => 'ADD', 280 'type' => 'INDEX', 281 'spec' => $name . ' ' . $type); 282 } 283 284 function dropIndex($name) 285 { 286 if (! is_array($this->create_definition)) 287 $this->create_definition = array(); 288 $this->create_definition[] = array('action' => 'DROP', 289 'type' => 'INDEX', 290 'spec' => $name); 291 } 292 293 function dropPrimary() 294 { 295 if (! is_array($this->create_definition)) 296 $this->create_definition = array(); 297 $this->create_definition[] = array('action' => 'DROP', 298 'type' => 'PRIMARY KEY', 299 'spec' => ''); 300 } 301 302 function createDefinition($def) 303 { 304 $this->create_definition = $def; 305 } 306 307 function setDelete($table) 308 { 309 $this->type = 'delete'; 310 $this->addMap('table_list', $table, null); 311 } 312 313 /** 314 * Add where sub-clauses. The where clause can be built up one 315 * part at a time and the resultant query will put in the 'and' 316 * between each component. 317 * 318 * Make sure you use table aliases. 319 * 320 * @param string $query Where subclause to use 321 */ 322 function addWhere($query) 323 { 324 if (isset($query)) 325 $this->addClause('where', $query); 326 } 327 328 /** 329 * Add a join condition to the query. This only implements 330 * left join, however most other joins are either synonymns or 331 * can be emulated with where clauses. 332 * 333 * @param string $table Name of table (without prefix) 334 * @param string $alias Alias to use instead of table name (required). 335 * @param mixed $join Join condition (e.g. 'a.id = b.other_id') 336 * or array of join fieldnames, e.g. array('id', 'name); 337 * Both are correctly converted into a join clause. 338 */ 339 function addJoin($table, $alias, $join, $type = 'left') 340 { 341 $var = array ( 'table' => $table, 342 'alias' => $alias, 343 'condition' => $join, 344 'type' => $type ); 345 346 $this->addClause('join', $var, false); 347 } 348 349 function leftJoin($table, $alias, $join) 350 { 351 $this->addJoin($table, $alias, $join, 'left'); 352 } 353 354 function rightJoin($table, $alias, $join) 355 { 356 $this->addJoin($table, $alias, $join, 'right'); 357 } 358 359 function innerJoin($table, $alias, $join) 360 { 361 $this->addJoin($table, $alias, $join, 'inner'); 362 } 363 364 /** 365 * Add an order by clause. Again, only the fieldname is required, and 366 * it should include an alias if a table has been added. 367 * May be called multiple times. 368 * 369 * @param string $order Order by field. 370 */ 371 function addOrder($order) 372 { 373 if (isset($order)) 374 $this->addClause('order_by', $order); 375 } 376 377 /** 378 * Add a group by clause. Only the fieldname is required. 379 * May be called multiple times. Use table aliases as required. 380 * 381 * @param string $group Field name to group by. 382 */ 383 function addGroup($group) 384 { 385 $this->addClause('group_by', $group); 386 } 387 388 /** 389 * Set a limit on the query. This is done in a database-independent 390 * fashion. 391 * 392 * @param integer $limit Number of rows to limit. 393 * @param integer $start First row to start extraction. 394 */ 395 function setLimit($limit, $start = -1) 396 { 397 $this->limit = $limit; 398 $this->offset = $start; 399 } 400 401 /** 402 * Prepare a query for execution via db_exec. 403 * 404 */ 405 function prepare($clear = false) 406 { 407 switch ($this->type) { 408 case 'select': 409 $q = $this->prepareSelect(); 410 break; 411 case 'update': 412 $q = $this->prepareUpdate(); 413 break; 414 case 'insert': 415 $q = $this->prepareInsert(); 416 break; 417 case 'replace': 418 $q = $this->prepareReplace(); 419 break; 420 case 'delete': 421 $q = $this->prepareDelete(); 422 break; 423 case 'create': // Create a temporary table 424 $s = $this->prepareSelect(); 425 $q = 'CREATE TEMPORARY TABLE ' . $this->_table_prefix . $this->create_table; 426 if (!empty($this->create_definition)) 427 $q .= ' ' . $this->create_definition; 428 $q .= ' ' . $s; 429 break; 430 case 'alter': 431 $q = $this->prepareAlter(); 432 break; 433 case 'createPermanent': // Create a temporary table 434 $s = $this->prepareSelect(); 435 $q = 'CREATE TABLE ' . $this->_table_prefix . $this->create_table; 436 if (!empty($this->create_definition)) 437 $q .= ' ' . $this->create_definition; 438 $q .= ' ' . $s; 439 break; 440 case 'drop': 441 $q = 'DROP TABLE IF EXISTS ' . $this->_table_prefix . $this->create_table; 442 break; 443 } 444 if ($clear) 445 $this->clear(); 446 return $q; 447 dprint(__FILE__, __LINE__, 2, $q); 448 } 449 450 function prepareSelect() 451 { 452 $q = 'SELECT '; 453 if (isset($this->query)) { 454 if (is_array($this->query)) { 455 $inselect = false; 456 $q .= implode(',', $this->query); 457 } else { 458 $q .= $this->query; 459 } 460 } else { 461 $q .= '*'; 462 } 463 $q .= ' FROM '; 464 if (isset($this->table_list)) { 465 if (is_array($this->table_list)) { 466 $q .= '( '; // Required for MySQL 5 compatability. 467 $intable = false; 468 foreach ($this->table_list as $table_id => $table) { 469 if ($intable) 470 $q .= ","; 471 else 472 $intable = true; 473 $q .= '`' . $this->_table_prefix . $table . '`'; 474 if (! is_numeric($table_id)) 475 $q .= " as $table_id"; 476 } 477 $q .= ' )'; // MySQL 5 compat. 478 } else { 479 $q .= $this->_table_prefix . $this->table_list; 480 } 481 } else { 482 return false; 483 } 484 $q .= $this->make_join($this->join); 485 $q .= $this->make_where_clause($this->where); 486 $q .= $this->make_group_clause($this->group_by); 487 $q .= $this->make_order_clause($this->order_by); 488 return $q; 489 } 490 491 function prepareUpdate() 492 { 493 // You can only update one table, so we get the table detail 494 $q = 'UPDATE '; 495 if (isset($this->table_list)) { 496 if (is_array($this->table_list)) { 497 reset($this->table_list); 498 // Grab the first record 499 list($key, $table) = each ($this->table_list); 500 } else { 501 $table = $this->table_list; 502 } 503 } else { 504 return false; 505 } 506 $q .= '`' . $this->_table_prefix . $table . '`'; 507 508 $q .= ' SET '; 509 $sets = ''; 510 foreach( $this->update_list as $field => $value) { 511 if ($sets) 512 $sets .= ", "; 513 $sets .= "`$field` = " . $this->quote($value); 514 } 515 $q .= $sets; 516 $q .= $this->make_where_clause($this->where); 517 return $q; 518 } 519 520 function prepareInsert() 521 { 522 $q = 'INSERT INTO '; 523 if (isset($this->table_list)) { 524 if (is_array($this->table_list)) { 525 reset($this->table_list); 526 // Grab the first record 527 list($key, $table) = each ($this->table_list); 528 } else { 529 $table = $this->table_list; 530 } 531 } else { 532 return false; 533 } 534 $q .= '`' . $this->_table_prefix . $table . '`'; 535 536 $fieldlist = ''; 537 $valuelist = ''; 538 foreach( $this->value_list as $field => $value) { 539 if ($fieldlist) 540 $fieldlist .= ","; 541 if ($valuelist) 542 $valuelist .= ","; 543 $fieldlist .= '`' . trim($field) . '`'; 544 $valuelist .= $value; 545 } 546 $q .= "($fieldlist) values ($valuelist)"; 547 return $q; 548 } 549 550 function prepareReplace() 551 { 552 $q = 'REPLACE INTO '; 553 if (isset($this->table_list)) { 554 if (is_array($this->table_list)) { 555 reset($this->table_list); 556 // Grab the first record 557 list($key, $table) = each ($this->table_list); 558 } else { 559 $table = $this->table_list; 560 } 561 } else { 562 return false; 563 } 564 $q .= '`' . $this->_table_prefix . $table . '`'; 565 566 $fieldlist = ''; 567 $valuelist = ''; 568 foreach( $this->value_list as $field => $value) { 569 if ($fieldlist) 570 $fieldlist .= ","; 571 if ($valuelist) 572 $valuelist .= ","; 573 $fieldlist .= '`' . trim($field) . '`'; 574 $valuelist .= $value; 575 } 576 $q .= "($fieldlist) values ($valuelist)"; 577 return $q; 578 } 579 580 function prepareDelete() 581 { 582 $q = 'DELETE FROM '; 583 if (isset($this->table_list)) { 584 if (is_array($this->table_list)) { 585 // Grab the first record 586 list($key, $table) = each ($this->table_list); 587 } else { 588 $table = $this->table_list; 589 } 590 } else { 591 return false; 592 } 593 $q .= '`' . $this->_table_prefix . $table . '`'; 594 $q .= $this->make_where_clause($this->where); 595 return $q; 596 } 597 598 //TODO: add ALTER DROP/CHANGE/MODIFY/IMPORT/DISCARD/... 599 //definitions: http://dev.mysql.com/doc/mysql/en/alter-table.html 600 function prepareAlter() 601 { 602 $q = 'ALTER TABLE `' . $this->_table_prefix . $this->create_table . '` '; 603 if (isset($this->create_definition)) { 604 if (is_array($this->create_definition)) { 605 $first = true; 606 foreach ($this->create_definition as $def) { 607 if ($first) 608 $first = false; 609 else 610 $q .= ', '; 611 $q .= $def['action'] . ' ' . $def['type'] . ' ' . $def['spec']; 612 } 613 } else { 614 $q .= 'ADD ' . $this->create_definition; 615 } 616 } 617 618 return $q; 619 } 620 621 /** 622 * Execute the query and return a handle. Supplants the db_exec query 623 */ 624 function &exec($style = ADODB_FETCH_BOTH, $debug = false) 625 { 626 global $db; 627 global $ADODB_FETCH_MODE; 628 629 if (! isset($this->_old_style)) 630 $this->_old_style = $ADODB_FETCH_MODE; 631 $ADODB_FETCH_MODE = $style; 632 $this->clearQuery(); 633 if ($q = $this->prepare()) { 634 dprint(__FILE__, __LINE__, 7, "executing query($q)"); 635 if ($debug) { 636 // Before running the query, explain the query and return the details. 637 $qid = $db->Execute('EXPLAIN ' . $q); 638 if ($qid) { 639 $res = array(); 640 while ($row = $this->fetchRow()) { 641 $res[] = $row; 642 } 643 dprint(__FILE__, __LINE__, 0, "QUERY DEBUG: " . var_export($res, true)); 644 $qid->Close(); 645 } 646 } 647 if (isset($this->limit)) { 648 $this->_query_id = $db->SelectLimit($q, $this->limit, $this->offset); 649 } else { 650 $this->_query_id = $db->Execute($q); 651 } 652 if (! $this->_query_id) { 653 $error = $db->ErrorMsg(); 654 dprint(__FILE__, __LINE__, 0, "query failed($q) - error was: " . $error); 655 return $this->_query_id; 656 } 657 return $this->_query_id; 658 } else { 659 return $this->_query_id; 660 } 661 } 662 663 function fetchRow() 664 { 665 if (! $this->_query_id) { 666 return false; 667 } 668 return $this->_query_id->FetchRow(); 669 } 670 671 /** 672 * loadList - replaces dbLoadList on 673 */ 674 function loadList($maxrows = null) 675 { 676 global $db; 677 global $AppUI; 678 679 if (! $this->exec(ADODB_FETCH_ASSOC)) { 680 $AppUI->setMsg($db->ErrorMsg(), UI_MSG_ERROR); 681 $this->clear(); 682 return false; 683 } 684 685 $list = array(); 686 $cnt = 0; 687 while ($hash = $this->fetchRow()) { 688 $list[] = $hash; 689 if ($maxrows && $maxrows == $cnt++) 690 break; 691 } 692 $this->clear(); 693 return $list; 694 } 695 696 function loadHashList($index = null) { 697 global $db; 698 699 if (! $this->exec(ADODB_FETCH_ASSOC)) { 700 exit ($db->ErrorMsg()); 701 } 702 $hashlist = array(); 703 $keys = null; 704 while ($hash = $this->fetchRow()) { 705 if ($index) { 706 $hashlist[$hash[$index]] = $hash; 707 } else { 708 // If we are using fetch mode of ASSOC, then we don't 709 // have an array index we can use, so we need to get one 710 if (! $keys) 711 $keys = array_keys($hash); 712 $hashlist[$hash[$keys[0]]] = $hash[$keys[1]]; 713 } 714 } 715 $this->clear(); 716 return $hashlist; 717 } 718 719 function loadHash() 720 { 721 global $db; 722 if (! $this->exec(ADODB_FETCH_ASSOC)) { 723 exit ($this->db->ErrorMsg()); 724 } 725 $hash = $this->fetchRow(); 726 $this->clear(); 727 return $hash; 728 } 729 730 function loadArrayList($index = 0) { 731 global $db; 732 733 if (! $this->exec(ADODB_FETCH_NUM)) { 734 exit ($db->ErrorMsg()); 735 } 736 $hashlist = array(); 737 $keys = null; 738 while ($hash = $this->fetchRow()) { 739 $hashlist[$hash[$index]] = $hash; 740 } 741 $this->clear(); 742 return $hashlist; 743 } 744 745 function loadColumn() { 746 global $db; 747 if (! $this->exec(ADODB_FETCH_NUM)) { 748 die ($db->ErrorMsg()); 749 } 750 $result = array(); 751 while ($row = $this->fetchRow()) { 752 $result[] = $row[0]; 753 } 754 $this->clear(); 755 return $result; 756 } 757 758 function loadObject( &$object, $bindAll=false , $strip = true) { 759 if (! $this->exec(ADODB_FETCH_NUM)) { 760 die ($this->_db->ErrorMsg()); 761 } 762 if ($object != null) { 763 $hash = $this->fetchRow(); 764 $this->clear(); 765 if( !$hash ) { 766 return false; 767 } 768 $this->bindHashToObject( $hash, $object, null, $strip, $bindAll ); 769 return true; 770 } else { 771 if ($object = $this->_query_id->FetchNextObject(false)) { 772 $this->clear(); 773 return true; 774 } else { 775 $object = null; 776 return false; 777 } 778 } 779 } 780 781 /** 782 * Using an XML string, build or update a table. 783 */ 784 function execXML($xml, $mode = 'REPLACE') { 785 global $db, $AppUI; 786 787 include_once DP_BASE_DIR.'/lib/adodb/adodb-xmlschema.inc.php'; 788 $schema = new adoSchema($db); 789 $schema->setUpgradeMode($mode); 790 if (isset($this->_table_prefix) && $this->_table_prefix) { 791 $schema->setPrefix($this->_table_prefix, false); 792 } 793 $schema->ContinueOnError(true); 794 if (($sql = $scheme->ParseSchemaString($xml)) == false) { 795 $AppUI->setMsg(array('Error in XML Schema', 'Error', $db->ErrorMsg()), UI_MSG_ERR); 796 return false; 797 } 798 if ($schema->ExecuteSchema($sql, true)) 799 return true; 800 else 801 return false; 802 } 803 804 /** {{{2 function loadResult 805 * Load a single column result from a single row 806 */ 807 function loadResult() 808 { 809 global $AppUI; 810 811 $result = false; 812 813 if (! $this->exec(ADODB_FETCH_NUM)) { 814 $AppUI->setMsg($db->ErrorMsg(), UI_MSG_ERROR); 815 } else if ($data = $this->fetchRow()) { 816 $result = $data[0]; 817 } 818 $this->clear(); 819 return $result; 820 } 821 //2}}} 822 823 /** {{{2 function make_where_clause 824 * Create a where clause based upon supplied field. 825 * 826 * @param mixed $clause Either string or array of subclauses. 827 * @return string 828 */ 829 function make_where_clause($where_clause) 830 { 831 $result = ''; 832 if (! isset($where_clause)) 833 return $result; 834 if (is_array($where_clause)) { 835 if (count($where_clause)) { 836 $started = false; 837 $result = ' WHERE ' . implode(' AND ', $where_clause); 838 } 839 } else if (strlen($where_clause) > 0) { 840 $result = " where $where_clause"; 841 } 842 return $result; 843 } 844 //2}}} 845 846 /** {{{2 function make_order_clause 847 * Create an order by clause based upon supplied field. 848 * 849 * @param mixed $clause Either string or array of subclauses. 850 * @return string 851 */ 852 function make_order_clause($order_clause) 853 { 854 $result = ""; 855 if (! isset($order_clause)) 856 return $result; 857 858 if (is_array($order_clause)) { 859 $started = false; 860 $result = ' ORDER BY ' . implode(',', $order_clause); 861 } else if (strlen($order_clause) > 0) { 862 $result = " ORDER BY $order_clause"; 863 } 864 return $result; 865 } 866 //2}}} 867 868 //{{{2 function make_group_clause 869 function make_group_clause($group_clause) 870 { 871 $result = ""; 872 if (! isset($group_clause)) 873 return $result; 874 875 if (is_array($group_clause)) { 876 $started = false; 877 $result = ' GROUP BY ' . implode(',', $group_clause); 878 } else if (strlen($group_clause) > 0) { 879 $result = " GROUP BY $group_clause"; 880 } 881 return $result; 882 } 883 //2}}} 884 885 //{{{2 function make_join 886 function make_join($join_clause) 887 { 888 $result = ""; 889 if (! isset($join_clause)) 890 return $result; 891 if (is_array($join_clause)) { 892 foreach ($join_clause as $join) { 893 $result .= ' ' . strtoupper($join['type']) . ' JOIN `' . $this->_table_prefix . $join['table'] . '`'; 894 if ($join['alias']) 895 $result .= ' AS ' . $join['alias']; 896 if (is_array($join['condition'])) { 897 $result .= ' USING (' . implode(',', $join['condition']) . ')'; 898 } else { 899 $result .= ' ON ' . $join['condition']; 900 } 901 } 902 } else { 903 $result .= ' LEFT JOIN `' . $this->_table_prefix . $join_clause . '`'; 904 } 905 return $result; 906 } 907 //2}}} 908 909 function quote($string) 910 { 911 global $db; 912 return $db->qstr($string, get_magic_quotes_runtime()); 913 } 914 } 915 //1}}} 916 917 // vim600: fdm=marker sw=2 ts=8 ai: 918 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 18 19:46:52 2007 | par Balluche grâce à PHPXref 0.7 |