| @@ 798-854 (lines=57) @@ | ||
| 795 | { |
|
| 796 | if (!isset($this->metaPrimaryKey[$table]) || (true == $forcenew)) { |
|
| 797 | // @codeCoverageIgnoreStart |
|
| 798 | if ($this->isDbSybase()) { |
|
| 799 | /** |
|
| 800 | * MetaPrimaryKey() in ADOdb has error(till v5.18), find PK |
|
| 801 | * manually. |
|
| 802 | * |
|
| 803 | * @link http://topic.csdn.net/t/20030117/17/1369396.html |
|
| 804 | * |
|
| 805 | * SELECT name, keycnt, |
|
| 806 | * index_col(tableName, indid, 1), -- 1st PK col |
|
| 807 | * index_col(tableName, indid, 2) -- 2nd PK col if has |
|
| 808 | * FROM sysindexes |
|
| 809 | * WHERE status & 2048 = 2048 |
|
| 810 | * AND id = object_id(tableName) |
|
| 811 | * |
|
| 812 | * keycnt is column count in PK. if PK index is not cursor |
|
| 813 | * index(by 0x10 bit in status), its keycnt - 1. |
|
| 814 | * |
|
| 815 | * Test pass for PK include 2 columns. |
|
| 816 | */ |
|
| 817 | $rs = $this->execute( |
|
| 818 | [ |
|
| 819 | 'SELECT' => [ |
|
| 820 | 'name' => 'a.name', |
|
| 821 | 'keycnt' => 'a.keycnt', |
|
| 822 | 'k1' => "index_col('$table', indid, 1)", |
|
| 823 | 'k2' => "index_col('$table', indid, 2)", |
|
| 824 | 'k3' => "index_col('$table', indid, 3)", |
|
| 825 | ], |
|
| 826 | 'FROM' => [ |
|
| 827 | 'a' => 'sysindexes', |
|
| 828 | 'b' => 'sysobjects', |
|
| 829 | ], |
|
| 830 | 'WHERE' => [ |
|
| 831 | 'a.status & 2048 = 2048 ', |
|
| 832 | "b.name = '$table'", |
|
| 833 | "a.id = b.id" |
|
| 834 | ] |
|
| 835 | ] |
|
| 836 | ); |
|
| 837 | if (true == $rs && 0 < $rs->RowCount()) { |
|
| 838 | // Got |
|
| 839 | $ar = [$rs->fields['k1']]; |
|
| 840 | if (!empty($rs->fields['k2'])) { |
|
| 841 | $ar[] = $rs->fields['k2']; |
|
| 842 | } |
|
| 843 | if (!empty($rs->fields['k3'])) { |
|
| 844 | $ar[] = $rs->fields['k3']; |
|
| 845 | } |
|
| 846 | } else { |
|
| 847 | // Table have no primary key |
|
| 848 | $ar = ''; |
|
| 849 | } |
|
| 850 | ||
| 851 | } else { |
|
| 852 | // Find using ADOdb first |
|
| 853 | $ar = $this->conn->MetaPrimaryKeys($table); |
|
| 854 | } |
|
| 855 | // @codeCoverageIgnoreEnd |
|
| 856 | ||
| 857 | ||
| @@ 719-750 (lines=32) @@ | ||
| 716 | where status & 2048 = 2048 |
|
| 717 | and id = object_id('sgqyjbqk') |
|
| 718 | */ |
|
| 719 | if ($this->IsDbSybase()) { |
|
| 720 | $rs = $this->PExecuteGenSql(array( |
|
| 721 | 'select' => array( |
|
| 722 | 'name' => 'a.name', |
|
| 723 | 'keycnt' => 'a.keycnt', |
|
| 724 | 'k1' => "index_col('$table', indid, 1)", |
|
| 725 | 'k2' => "index_col('$table', indid, 2)", |
|
| 726 | 'k3' => "index_col('$table', indid, 3)", |
|
| 727 | ), |
|
| 728 | 'from' => array( |
|
| 729 | 'a' => 'sysindexes', |
|
| 730 | 'b' => 'sysobjects', |
|
| 731 | ), |
|
| 732 | 'where' => array( |
|
| 733 | 'a.status & 2048 = 2048 ', |
|
| 734 | "b.name = '$table'", |
|
| 735 | "a.id = b.id" |
|
| 736 | ) |
|
| 737 | )); |
|
| 738 | if (true == $rs && 0 < $rs->RowCount()) { |
|
| 739 | // Got |
|
| 740 | $ar = array($rs->fields['k1']); |
|
| 741 | if (!empty($rs->fields['k2'])) |
|
| 742 | $ar[] = $rs->fields['k2']; |
|
| 743 | if (!empty($rs->fields['k3'])) |
|
| 744 | $ar[] = $rs->fields['k3']; |
|
| 745 | } |
|
| 746 | else { |
|
| 747 | // Table have no primary key |
|
| 748 | $ar = ''; |
|
| 749 | } |
|
| 750 | } |
|
| 751 | } |
|
| 752 | ||
| 753 | // Convert columns to native case |
|