Returns last primary key

@param string $table Optional table name override
@return integer
510529
final public function getLastPk($table = null)
    {
        if ($table === null) {
            $this->validateShortcutData();
            $table = static::getTableName();
        }

        return $this->db->select()
                        ->max($this->getPk())
                        ->from($table)
                        ->queryScalar();
    }
730606
private function get_columns( $table ) {
		global $wpdb;

		$table_sql    = $this->esc_sql_ident( $table );
		$primary_keys = $text_columns = $all_columns = array();

		foreach ( $wpdb->get_results( "DESCRIBE $table_sql" ) as $col ) {
			if ( 'PRI' === $col->Key ) {
				$primary_keys[] = $col->Field;
			}

			if ( $this->is_text_col( $col->Type ) ) {
				$text_columns[] = $col->Field;
			}

			$all_columns[] = $col->Field;
		}

		return array( $primary_keys, $text_columns, $all_columns );
	}
614945
public function getTableSize($table) {
        $table = $this->getPrefix() . $table;
        $sql   = "show table status from " . $this->config['table'];
        $data  = $this->query($sql);
        foreach ($data as $v) {
            if ($v['Name'] == $table) {
                return $v['Data_length'] + $v['Index_length'];
            }
        }
        return 0;
    }
1278727
public static function last( $table, $key = null, $handler = null ) 
	{
		return Query::select( $table )->last( $key, $handler );
	}
508086
public function getTableName($table) {
        if (preg_match('#^`?\{[^\}]+\}.*$#', $table)) {
            return $this->sanitize(str_replace(['{', '}'], [$this->tablePrefix, ''], $table));
        } else {
            return $this->sanitize($table);
        }
    }
1069240
public function getSequenceName(Table $table)
    {
        $result = null;
        if ($table->getIdMethod() == IdMethod::NATIVE) {
            $idMethodParams = $table->getIdMethodParameters();
            if (empty($idMethodParams)) {
                $result = null;
                // We're going to ignore a check for max length (mainly
                // because I'm not sure how Postgres would handle this w/ SERIAL anyway)
                foreach ($table->getColumns() as $col) {
                    if ($col->isAutoIncrement()) {
                        $result = $table->getName() . '_' . $col->getName() . '_seq';
                        break; // there's only one auto-increment column allowed
                    }
                }
            } else {
                $result = $idMethodParams[0]->getValue();
            }
        }

        return $result;
    }
533701
function getSequence( $table ) {

        if ( isset( $this->sequences[ $table ] ) ) {

            return $this->sequences[ $table ];

        }

        $primary = $this->getPrimary( $table );

        if ( is_array( $primary ) ) return null;

        $table = $this->rewriteTable( $table );

        return $table . '_' . $primary . '_seq';

    }
640220
public function tableName($table=null)
	{
		if(null === $table)
		{
			return $this->prefix . $this->table;
		}
		else
		{
			return $this->prefix . $table;
		}
	}
98294
public function getLastInsertID() {
		if (count($this->rows) > 0) {
			$end = end($this->rows);
			if ($end->toRow() && $end->toRow()->getPrimary()) {
				return (int) $end->toRow()->getPrimary();
			} else if ($end->toRow() === NULL) {
				return NULL;
			} else {
				throw new RepositoryException("Table \"" . self::TABLE . "\" does not have a primary key.");
			}
		} else {
			return NULL;
		}
	}
49912
public function getPrimaryKey($table)
    {
        $db = $this->showKeys()->from($table)
                               ->whereEquals('Key_name', new RawBinding('PRIMARY'));

        return $db->query('Column_name');
    }
572526
public function get_unique_primary($table): ?string
  {
    if ( ($keys = $this->get_keys($table)) &&
      isset($keys['keys']['PRIMARY']) &&
      (\count($keys['keys']['PRIMARY']['columns']) === 1) ){
      return $keys['keys']['PRIMARY']['columns'][0];
    }
    return null;
  }
700514
public function PrimaryKeyRange($Table) {
      $Model = $this->CreateModel($Table);
      
      $Data = $this->SQL
         ->Select($Model->PrimaryKey, 'min', 'MinValue')
         ->Select($Model->PrimaryKey, 'max', 'MaxValue')
         ->From($Table)
         ->Get()->FirstRow(DATASET_TYPE_ARRAY);
      
      if ($Data)
         return array($Data['MinValue'], $Data['MaxValue']);
      else
         return array(0, 0);
   }
208662
public function getTableKeys($table)
	{
		$keys = array();

		$fieldCasing = $this->connection->getAttribute(\PDO::ATTR_CASE);

		$this->connection->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_UPPER);

		$table = strtoupper($table);

		$this->setQuery('pragma table_info( ' . $table . ')');
		$rows = $this->loadObjectList();

		foreach ($rows as $column)
		{
			if ($column->PK == 1)
			{
				$keys[$column->NAME] = $column;
			}
		}

		$this->connection->setAttribute(\PDO::ATTR_CASE, $fieldCasing);

		return $keys;
	}
386312
public function getTableIndexes( $table )
    {
        $query = "SELECT * FROM information_schema.statistics WHERE table_schema =
                 ? AND table_name = ?";

        $params = [ $this->name, $table ];

        $statement = $this->database->prepare( $query );
        $statement->execute( $params );

        $results = $statement->fetchAll();

        $indexes = [ ];

        if ( !empty( $results ) )
        {
            $name = NULL;

            $i = 0;

            foreach ( $results as $result )
            {
                if ( !in_array( $result[ 'INDEX_NAME' ], $indexes ) )
                {
                    $indexes[ ] = $result[ 'INDEX_NAME' ];
                }
            }
        }

        return $indexes;
    }
869888
public function getPrimaryKey($table, $resultSet = null){
		if($resultSet instanceof PDOStatement){
			$i = 0;
			while($col = $resultSet->getColumnMeta($i++)){
				if(in_array('primary_key', $col['flags']))
					$primaryKey = $col['name'];
			}
		}
		if(isset($primaryKey))
			return $primaryKey;
		throw new ImplementationException;
	}
150012
public function getPrimaryKey($table){
		$key = '';
		$pos = strpos($table, '.');
		if($pos !== false)
			$table = substr($table, $pos + 1);
		if(isset($this->tblData[$table]))
			$sql = $this->tblData[$table];
		else{
			$q = $this->runQuery("SELECT sql FROM sqlite_master WHERE tbl_name='$table'");
			$r = $this->fetch($q);
			if($r === false)
				return '';
			$this->tblData[$table] = $sql = $r['sql'];
		}

		$sql = explode("\n", $sql);
		foreach($sql as $field){
			$field = trim($field);
			if(stripos($field, 'PRIMARY KEY') !== false && $key === '')
				$key = preg_replace('~^"(\w+)".*$~i', '$1', $field);
		}
		return $key;
	}
987455
public function getTableInfo($table)
    {
        if (!$this->tableExists($table)) {
            return null;
        }
        
        $rtable = static::buildRealTableName($table, true);
        $key = 'db/tableinfo/' . $rtable;
        $data = static::getCache()->get($key);
        
        if (!$data) {
            $data = ['table_name' => $table];
            $data['fields'] = $this->getColumns($table);
            $pk = [];
            foreach ($data['fields'] as $key => $val) {
                if($val['is_primary']) {
                    $pk[] = $key;
                }
            }
            $data['primary_key'] = $pk ? $pk[0] : null;
            
            static::getCache()->set($key, $data);
        }
        
        return $data;
    }