删除 表中记录

@param string $table
@param mixed $cond

@return int
540214
public function del($table, $cond=null)
	{
		$ds = $this->ds();
		$cond = SqlHelper::parse_cond($ds, $cond);
		$table = SqlHelper::qtable($table);
		
		$sql = "DELETE FROM {$table} " . (empty($cond) ? '' : "WHERE {$cond}");
		
		$result = Sql::write($ds, Sql::MODE_WRITE_DELETE, [
				$sql
			]);
		return $result;
	}
509615
public function getAutoIncrement($table)
	{
		$create = $this->getTableCreate($table);

		preg_match('/AUTO_INCREMENT=([0-9]*)/', $create[$table], $matches);

		return (isset($matches[1])) ? $matches[1] : false;
	}
28215
private function sql_handle_col( $col, $table ) {
		global $wpdb;

		$table_sql = $this->esc_sql_ident( $table );
		$col_sql   = $this->esc_sql_ident( $col );

		$count = $wpdb->query( $wpdb->prepare( "UPDATE $table_sql SET $col_sql = REPLACE($col_sql, %s, %s);", $this->old, $this->new ) );

		return $count;
	}
336733
public function incr_field($table, $field, $incr = 1, $cond=null)
    {
    	return Sql::assistant( $this->ds )->incr_field($table, $field, $incr, $cond);
    }
800121
public function incr_field($table, $field, $incr = 1, $cond=null)
    {
    	$incr = (int)$incr;
        if ($incr == 0) return false;
        
        $ds = $this->ds();
        $field = SqlHelper::qfield($field, $table);
        $cond = SqlHelper::parse_cond($ds,$cond);
        $sql = "UPDATE {$table} SET {$field} = {$field} + {$incr} " . (empty($cond) ? '' : "WHERE {$cond}");

        $result = Sql::write($ds, Sql::MODE_WRITE_UPDATE, [
				$sql
			]);
		return $result;
    }
883321
protected function sort($data,$cond) {
		$cols=\Base::instance()->split($cond);
		uasort(
			$data,
			function($val1,$val2) use($cols) {
				foreach ($cols as $col) {
					$parts=explode(' ',$col,2);
					$order=empty($parts[1])?
						SORT_ASC:
						constant($parts[1]);
					$col=$parts[0];
					if (!array_key_exists($col,$val1))
						$val1[$col]=NULL;
					if (!array_key_exists($col,$val2))
						$val2[$col]=NULL;
					list($v1,$v2)=[$val1[$col],$val2[$col]];
					if ($out=strnatcmp($v1,$v2)*
						(($order==SORT_ASC)*2-1))
						return $out;
				}
				return 0;
			}
		);
		return $data;
	}
622227
protected function findConstraints($table)
	{
		$sql=<<<EOD
		SELECT D.constraint_type as CONSTRAINT_TYPE, C.COLUMN_NAME, C.position, D.r_constraint_name,
                E.table_name as table_ref, f.column_name as column_ref,
            	C.table_name
        FROM ALL_CONS_COLUMNS C
        inner join ALL_constraints D on D.OWNER = C.OWNER and D.constraint_name = C.constraint_name
        left join ALL_constraints E on E.OWNER = D.r_OWNER and E.constraint_name = D.r_constraint_name
        left join ALL_cons_columns F on F.OWNER = E.OWNER and F.constraint_name = E.constraint_name and F.position = c.position
        WHERE C.OWNER = '{$table->schemaName}'
           and C.table_name = '{$table->name}'
           and D.constraint_type <> 'P'
        order by d.constraint_name, c.position
EOD;
		$command=$this->getDbConnection()->createCommand($sql);
		foreach($command->queryAll() as $row)
		{
			if($row['CONSTRAINT_TYPE']==='R')   // foreign key
			{
				$name = $row["COLUMN_NAME"];
				$table->foreignKeys[$name]=array($row["TABLE_REF"], $row["COLUMN_REF"]);
				if(isset($table->columns[$name]))
					$table->columns[$name]->isForeignKey=true;
			}

		}
	}
995374
public function _elseif($cond)
    {
        if (!$this->conditionalProxy) {
            throw new LogicException(__METHOD__ .' must be called after _if()');
        }

        return $this->conditionalProxy->_elseif($cond);
    }
430632
public function update($table, array $row, $cond=null)
	{
		return Sql::assistant( $this->ds )->update($table, $row, $cond);
	}
650914
public function GetCount($Table = '', $Where = FALSE) {
      if($Table != '') {
         //$this->MapAliases($Table);
         $this->From($Table);
      }

      if ($Where !== FALSE)
         $this->Where($Where);

      $this->Select('*', 'count', 'RowCount'); // count * slow on innodb
      $Sql = $this->GetSelect();
      $Result = $this->Query($Sql);

      $CountData = $Result->FirstRow();
      return $CountData->RowCount;
   }
463601
public function count($con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $criteria->setDbName($this->getDbName()); // Set the correct dbName
        $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count

        // We need to set the primary table name, since in the case that there are no WHERE columns
        // it will be impossible for the BasePeer::createSelectSql() method to determine which
        // tables go into the FROM clause.
        $criteria->setPrimaryTableName(constant($this->modelPeerName . '::TABLE_NAME'));

        $stmt = $criteria->doCount($con);
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $count = (int) $row[0];
        } else {
            $count = 0; // no rows returned; we infer that means 0 matches.
        }
        $stmt->closeCursor();

        return $count;
    }
719631
public function count($table = '', $where = '')
    {
        // if table name not pass
        if (!empty($table)) {
            if (empty($where)) {
                $this->sql = "SELECT COUNT(*) AS NUMROWS FROM `$table`;"; // create count query
            } else {
                $this->sql = "SELECT COUNT(*) AS NUMROWS FROM `$table` WHERE $where;";  // create count query
            }

            // pdo prepare statement
            $this->STH = $this->prepare($this->sql);

            try {
                if ($this->STH->execute()) {
                    // fetch array result
                    $this->results = $this->STH->fetch();
                    // close pdo
                    $this->STH->closeCursor();
                    // return number of count
                    return $this->results['NUMROWS'];
                } else {
                    self::error($this->STH->errorInfo());
                }
            } catch (\PDOException $e) {
                // get pdo error and pass on error method
                self::error($e->getMessage() . ': ' . __LINE__);
            }
        } else {
            self::error('Table name not found..');
        }
    }
184343
static function unionCond($cond1, $cond2, $or = false)
    {
        foreach ($cond2 as $key => $param){
            if (!isset($cond1[$key])){
                $cond1[$key] = $param;
            }else
            if ($key == 'order'){
                $cond1[$key] = array_merge($cond1[$key], $param);
            }else
            if ($key == 'where'){
                $cond1[$key] = self::unionCondWhere($cond1[$key], $param, $or);
            }
        }
        return $cond1;
    }
669888
protected function _hasJoin_sql($key, $table, $cond, &$filter, &$options) {
		$relConf = $this->fieldConf[$key]['belongs-to-one'];
		$relModel = is_array($relConf)?$relConf[0]:$relConf;
		$rel = $this->getRelInstance($relModel,null,$key);
		$fkey = is_array($this->fieldConf[$key]['belongs-to-one']) ?
			$this->fieldConf[$key]['belongs-to-one'][1] : $rel->primary;
		$alias = $table.'__'.$key;
		$query = $this->_sql_left_join($key,$this->table,$fkey,[$table,$alias]);
		$this->_sql_mergeRelCondition($cond,$alias,$filter,$options);
		return $query;
	}
981
public function count(string $table, $wheres)
    {
        list($where, $bindings) = $this->handleWheres($wheres);
        $sql = "SELECT COUNT(*) AS total FROM {$table} WHERE {$where}";

        $result = $this->fetchObject($sql, $bindings);

        return $result ? (int)$result->total : 0;
    }
839888
public function searchAll(array $cond = array(), $order = false): array
    {
        $options = array(
            'order' => $order,
            'count' => 0,
            'offset' => 0
        );

        $result = $this->search($cond, $options);

        return $result->getAllResults();
    }
1075881
public function max($table, $inc = null)
    {
        return $this->select($table, ['MAX(id)'])[0]['MAX(id)'] + (isset($inc) ? $inc : 0);
    }