- Timestamp:
- 2013/08/02 13:22:57 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/MDB2/Driver/Manager/pgsql.php
r20764 r23022 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: pgsql.php ,v 1.87 2008/11/29 14:09:59 afz Exp$45 // $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $ 46 46 47 47 require_once 'MDB2/Driver/Manager/Common.php'; … … 69 69 function createDatabase($name, $options = array()) 70 70 { 71 $db = &$this->getDBInstance();72 if ( PEAR::isError($db)) {71 $db = $this->getDBInstance(); 72 if (MDB2::isError($db)) { 73 73 return $db; 74 74 } … … 96 96 function alterDatabase($name, $options = array()) 97 97 { 98 $db = &$this->getDBInstance();99 if ( PEAR::isError($db)) {100 return $db; 101 } 102 103 $query = ' ALTER DATABASE '. $db->quoteIdentifier($name, true);98 $db = $this->getDBInstance(); 99 if (MDB2::isError($db)) { 100 return $db; 101 } 102 103 $query = ''; 104 104 if (!empty($options['name'])) { 105 105 $query .= ' RENAME TO ' . $options['name']; … … 108 108 $query .= ' OWNER TO ' . $options['owner']; 109 109 } 110 111 if (empty($query)) { 112 return MDB2_OK; 113 } 114 115 $query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true) . $query; 110 116 return $db->standaloneQuery($query, null, true); 111 117 } … … 123 129 function dropDatabase($name) 124 130 { 125 $db = &$this->getDBInstance();126 if ( PEAR::isError($db)) {131 $db = $this->getDBInstance(); 132 if (MDB2::isError($db)) { 127 133 return $db; 128 134 } … … 182 188 function truncateTable($name) 183 189 { 184 $db = &$this->getDBInstance();185 if ( PEAR::isError($db)) {190 $db = $this->getDBInstance(); 191 if (MDB2::isError($db)) { 186 192 return $db; 187 193 } 188 194 189 195 $name = $db->quoteIdentifier($name, true); 190 return $db->exec("TRUNCATE TABLE $name"); 196 $result = $db->exec("TRUNCATE TABLE $name"); 197 if (MDB2::isError($result)) { 198 return $result; 199 } 200 return MDB2_OK; 191 201 } 192 202 … … 210 220 function vacuum($table = null, $options = array()) 211 221 { 212 $db = &$this->getDBInstance();213 if ( PEAR::isError($db)) {222 $db = $this->getDBInstance(); 223 if (MDB2::isError($db)) { 214 224 return $db; 215 225 } … … 229 239 $query .= ' '.$db->quoteIdentifier($table, true); 230 240 } 231 return $db->exec($query); 241 $result = $db->exec($query); 242 if (MDB2::isError($result)) { 243 return $result; 244 } 245 return MDB2_OK; 232 246 } 233 247 … … 327 341 function alterTable($name, $changes, $check) 328 342 { 329 $db = &$this->getDBInstance();330 if ( PEAR::isError($db)) {343 $db = $this->getDBInstance(); 344 if (MDB2::isError($db)) { 331 345 return $db; 332 346 } … … 357 371 $query = 'DROP ' . $field_name; 358 372 $result = $db->exec("ALTER TABLE $name $query"); 359 if ( PEAR::isError($result)) {373 if (MDB2::isError($result)) { 360 374 return $result; 361 375 } … … 367 381 $field_name = $db->quoteIdentifier($field_name, true); 368 382 $result = $db->exec("ALTER TABLE $name RENAME COLUMN $field_name TO ".$db->quoteIdentifier($field['name'], true)); 369 if ( PEAR::isError($result)) {383 if (MDB2::isError($result)) { 370 384 return $result; 371 385 } … … 377 391 $query = 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field); 378 392 $result = $db->exec("ALTER TABLE $name $query"); 379 if ( PEAR::isError($result)) {393 if (MDB2::isError($result)) { 380 394 return $result; 381 395 } … … 388 402 if (!empty($field['definition']['type'])) { 389 403 $server_info = $db->getServerVersion(); 390 if ( PEAR::isError($server_info)) {404 if (MDB2::isError($server_info)) { 391 405 return $server_info; 392 406 } … … 399 413 $query = "ALTER $field_name TYPE $type USING CAST($field_name AS $type)"; 400 414 $result = $db->exec("ALTER TABLE $name $query"); 401 if ( PEAR::isError($result)) {415 if (MDB2::isError($result)) { 402 416 return $result; 403 417 } … … 406 420 $query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']); 407 421 $result = $db->exec("ALTER TABLE $name $query"); 408 if ( PEAR::isError($result)) {422 if (MDB2::isError($result)) { 409 423 return $result; 410 424 } 411 425 } 412 if ( !empty($field['definition']['notnull'])) {426 if (array_key_exists('notnull', $field['definition'])) { 413 427 $query = "ALTER $field_name ".($field['definition']['notnull'] ? 'SET' : 'DROP').' NOT NULL'; 414 428 $result = $db->exec("ALTER TABLE $name $query"); 415 if ( PEAR::isError($result)) {429 if (MDB2::isError($result)) { 416 430 return $result; 417 431 } … … 423 437 $change_name = $db->quoteIdentifier($changes['name'], true); 424 438 $result = $db->exec("ALTER TABLE $name RENAME TO ".$change_name); 425 if ( PEAR::isError($result)) {439 if (MDB2::isError($result)) { 426 440 return $result; 427 441 } … … 442 456 function listDatabases() 443 457 { 444 $db = &$this->getDBInstance();445 if ( PEAR::isError($db)) {458 $db = $this->getDBInstance(); 459 if (MDB2::isError($db)) { 446 460 return $db; 447 461 } … … 455 469 $result = $result2->fetchCol(); 456 470 $result2->free(); 457 if ( PEAR::isError($result)) {471 if (MDB2::isError($result)) { 458 472 return $result; 459 473 } … … 475 489 function listUsers() 476 490 { 477 $db = &$this->getDBInstance();478 if ( PEAR::isError($db)) {491 $db = $this->getDBInstance(); 492 if (MDB2::isError($db)) { 479 493 return $db; 480 494 } … … 502 516 function listViews() 503 517 { 504 $db = &$this->getDBInstance();505 if ( PEAR::isError($db)) {518 $db = $this->getDBInstance(); 519 if (MDB2::isError($db)) { 506 520 return $db; 507 521 } … … 512 526 AND viewname !~ '^pg_'"; 513 527 $result = $db->queryCol($query); 514 if ( PEAR::isError($result)) {528 if (MDB2::isError($result)) { 515 529 return $result; 516 530 } … … 533 547 function listTableViews($table) 534 548 { 535 $db = &$this->getDBInstance();536 if ( PEAR::isError($db)) {549 $db = $this->getDBInstance(); 550 if (MDB2::isError($db)) { 537 551 return $db; 538 552 } … … 541 555 $query.= ' WHERE tablename ='.$db->quote($table, 'text'); 542 556 $result = $db->queryCol($query); 543 if ( PEAR::isError($result)) {557 if (MDB2::isError($result)) { 544 558 return $result; 545 559 } … … 561 575 function listFunctions() 562 576 { 563 $db = &$this->getDBInstance();564 if ( PEAR::isError($db)) {577 $db = $this->getDBInstance(); 578 if (MDB2::isError($db)) { 565 579 return $db; 566 580 } … … 579 593 (SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"; 580 594 $result = $db->queryCol($query); 581 if ( PEAR::isError($result)) {595 if (MDB2::isError($result)) { 582 596 return $result; 583 597 } … … 600 614 function listTableTriggers($table = null) 601 615 { 602 $db = &$this->getDBInstance();603 if ( PEAR::isError($db)) {616 $db = $this->getDBInstance(); 617 if (MDB2::isError($db)) { 604 618 return $db; 605 619 } … … 609 623 pg_class tbl 610 624 WHERE trg.tgrelid = tbl.oid'; 611 if ( !is_null($table)) {625 if (null !== $table) { 612 626 $table = $db->quote(strtoupper($table), 'text'); 613 $query .= " AND tbl.relname= $table";627 $query .= " AND UPPER(tbl.relname) = $table"; 614 628 } 615 629 $result = $db->queryCol($query); 616 if ( PEAR::isError($result)) {630 if (MDB2::isError($result)) { 617 631 return $result; 618 632 } … … 634 648 function listTables() 635 649 { 636 $db = &$this->getDBInstance();637 if ( PEAR::isError($db)) {650 $db = $this->getDBInstance(); 651 if (MDB2::isError($db)) { 638 652 return $db; 639 653 } … … 660 674 . " AND c.relname !~ '^pg_'"; 661 675 $result = $db->queryCol($query); 662 if ( PEAR::isError($result)) {676 if (MDB2::isError($result)) { 663 677 return $result; 664 678 } … … 681 695 function listTableFields($table) 682 696 { 683 $db = &$this->getDBInstance();684 if ( PEAR::isError($db)) {697 $db = $this->getDBInstance(); 698 if (MDB2::isError($db)) { 685 699 return $db; 686 700 } … … 694 708 $db->setLimit(1); 695 709 $result2 = $db->query("SELECT * FROM $table"); 696 if ( PEAR::isError($result2)) {710 if (MDB2::isError($result2)) { 697 711 return $result2; 698 712 } 699 713 $result = $result2->getColumnNames(); 700 714 $result2->free(); 701 if ( PEAR::isError($result)) {715 if (MDB2::isError($result)) { 702 716 return $result; 703 717 } … … 717 731 function listTableIndexes($table) 718 732 { 719 $db = &$this->getDBInstance();720 if ( PEAR::isError($db)) {733 $db = $this->getDBInstance(); 734 if (MDB2::isError($db)) { 721 735 return $db; 722 736 } … … 737 751 $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)"; 738 752 $indexes = $db->queryCol($query, 'text'); 739 if ( PEAR::isError($indexes)) {753 if (MDB2::isError($indexes)) { 740 754 return $indexes; 741 755 } … … 770 784 function dropConstraint($table, $name, $primary = false) 771 785 { 772 $db = &$this->getDBInstance();773 if ( PEAR::isError($db)) {786 $db = $this->getDBInstance(); 787 if (MDB2::isError($db)) { 774 788 return $db; 775 789 } … … 790 804 AND relname = '. $db->quote($table, 'text'); 791 805 $unique = $db->queryCol($query, 'text'); 792 if ( PEAR::isError($unique) || empty($unique)) {806 if (MDB2::isError($unique) || empty($unique)) { 793 807 // not an UNIQUE index, maybe a CONSTRAINT 794 808 return parent::dropConstraint($table, $name, $primary); … … 796 810 797 811 if (in_array($name, $unique)) { 798 return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true)); 812 $result = $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true)); 813 if (MDB2::isError($result)) { 814 return $result; 815 } 816 return MDB2_OK; 799 817 } 800 818 $idxname = $db->getIndexName($name); 801 819 if (in_array($idxname, $unique)) { 802 return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true)); 820 $result = $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true)); 821 if (MDB2::isError($result)) { 822 return $result; 823 } 824 return MDB2_OK; 803 825 } 804 826 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, … … 818 840 function listTableConstraints($table) 819 841 { 820 $db = &$this->getDBInstance();821 if ( PEAR::isError($db)) {842 $db = $this->getDBInstance(); 843 if (MDB2::isError($db)) { 822 844 return $db; 823 845 } … … 850 872 $query .= ')'; 851 873 $constraints = $db->queryCol($query); 852 if ( PEAR::isError($constraints)) {874 if (MDB2::isError($constraints)) { 853 875 return $constraints; 854 876 } … … 883 905 function createSequence($seq_name, $start = 1) 884 906 { 885 $db = &$this->getDBInstance();886 if ( PEAR::isError($db)) {907 $db = $this->getDBInstance(); 908 if (MDB2::isError($db)) { 887 909 return $db; 888 910 } 889 911 890 912 $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); 891 return$db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".913 $result = $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1". 892 914 ($start < 1 ? " MINVALUE $start" : '')." START $start"); 915 if (MDB2::isError($result)) { 916 return $result; 917 } 918 return MDB2_OK; 893 919 } 894 920 … … 905 931 function dropSequence($seq_name) 906 932 { 907 $db = &$this->getDBInstance();908 if ( PEAR::isError($db)) {933 $db = $this->getDBInstance(); 934 if (MDB2::isError($db)) { 909 935 return $db; 910 936 } 911 937 912 938 $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); 913 return $db->exec("DROP SEQUENCE $sequence_name"); 939 $result = $db->exec("DROP SEQUENCE $sequence_name"); 940 if (MDB2::isError($result)) { 941 return $result; 942 } 943 return MDB2_OK; 914 944 } 915 945 … … 925 955 function listSequences() 926 956 { 927 $db = &$this->getDBInstance();928 if ( PEAR::isError($db)) {957 $db = $this->getDBInstance(); 958 if (MDB2::isError($db)) { 929 959 return $db; 930 960 } … … 933 963 $query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"; 934 964 $table_names = $db->queryCol($query); 935 if ( PEAR::isError($table_names)) {965 if (MDB2::isError($table_names)) { 936 966 return $table_names; 937 967 }
Note: See TracChangeset
for help on using the changeset viewer.
