| @@ 789-800 (lines=12) @@ | ||
| 786 | * @param string $cond Condition, can be where, having etc, raw sql string. |
|
| 787 | * @return int -1: error/N >= 0: number of rows |
|
| 788 | */ |
|
| 789 | public function GetRowCount ($tbl, $cond = '') { |
|
| 790 | $rs = $this->PExecute($this->GenSql(array( |
|
| 791 | 'SELECT' => array('c' => 'count(1)'), |
|
| 792 | 'FROM' => $tbl, |
|
| 793 | )) . ' ' . $cond); |
|
| 794 | if (false == $rs || 0 != $this->ErrorNo() |
|
| 795 | || 0 == $rs->RowCount()) |
|
| 796 | // Execute error |
|
| 797 | return -1; |
|
| 798 | else |
|
| 799 | return $rs->fields['c']; |
|
| 800 | } // end of func GetRowCount |
|
| 801 | ||
| 802 | ||
| 803 | /** |
|
| @@ 1026-1046 (lines=21) @@ | ||
| 1023 | * @param string $condition Raw sql, can be WHERE, HAVING etc |
|
| 1024 | * @return int |
|
| 1025 | */ |
|
| 1026 | public function getRowCount($table, $condition = '') |
|
| 1027 | { |
|
| 1028 | $sqlCfg = [ |
|
| 1029 | 'SELECT' => ['c' => 'COUNT(1)'], |
|
| 1030 | 'FROM' => $table, |
|
| 1031 | ]; |
|
| 1032 | $rs = $this->executePrepare( |
|
| 1033 | $this->getSqlGenerator()->get($sqlCfg) |
|
| 1034 | . ' ' . $condition |
|
| 1035 | ); |
|
| 1036 | if (false == $rs || 0 != $this->conn->ErrorNo() |
|
| 1037 | || 0 == $rs->RowCount() |
|
| 1038 | ) { |
|
| 1039 | // Execute error, rare happen |
|
| 1040 | // @codeCoverageIgnoreStart |
|
| 1041 | return -1; |
|
| 1042 | // @codeCoverageIgnoreEnd |
|
| 1043 | } else { |
|
| 1044 | return $rs->fields['c']; |
|
| 1045 | } |
|
| 1046 | } |
|
| 1047 | ||
| 1048 | ||
| 1049 | /** |
|