Generate the SQL statement for creating a primary key.

@param  Table    $table
@param  Fluent   $command
@return string
773820
public function primary(Table $table, Fluent $command)
		{
			return $this->key($table, $command->name(null), 'PRIMARY KEY');
		}
100469
public function createCommand($db = null)
    {
        if ($this->primaryModel !== null) {
            // lazy loading
            if (is_array($this->via)) {
                // via relation
                /* @var $viaQuery ActiveQuery */
                list($viaName, $viaQuery) = $this->via;
                if ($viaQuery->multiple) {
                    $viaModels = $viaQuery->all();
                    $this->primaryModel->populateRelation($viaName, $viaModels);
                } else {
                    $model = $viaQuery->one();
                    $this->primaryModel->populateRelation($viaName, $model);
                    $viaModels = $model === null ? [] : [$model];
                }
                $this->filterByModels($viaModels);
            } else {
                $this->filterByModels([$this->primaryModel]);
            }
        }

        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;
        if ($db === null) {
            $db = $modelClass::getDb();
        }

        if ($this->type === null) {
            $this->type = $modelClass::type();
        }
        if ($this->index === null) {
            $this->index = $modelClass::index();
            $this->type = $modelClass::type();
        }
        $commandConfig = $db->getQueryBuilder()->build($this);

        return $db->createCommand($commandConfig);
    }
949149
protected function getCreateTable($output, $table, $tableName, $forceSave = false)
    {
        $output[] = $this->getTableVariable($table, $tableName);

        $alternatePrimaryKeys = $this->getAlternatePrimaryKeys($table);
        if (empty($alternatePrimaryKeys) || $forceSave) {
            $output[] = sprintf("%s\$table->save();", $this->ind2);
        }

        return $output;
    }
720139
public function getPrimaryKey($table){
		$def = $this->fetch($this->runQuery("SELECT indexdef FROM pg_indexes WHERE indexname = '{$table}_pkey'"));
		if(!$def)
			return false;
		$def = reset($def);
		if(preg_match("~{$table}_pkey\s+ON\s+{$table}.*\((\w+).*\)~i", $def, $matches))
			return $matches[1];
		return false;
	}
483680
private function generateForeignKey($table)
    {
        if (empty($table->foreignKeys)) {
            return;
        }
        $definition = "// fk: $table->name\n";

        foreach ($table->foreignKeys as $fk) {
            $refTable = '';
            $refColumns = '';
            $columns = '';

            foreach ($fk as $k => $v) {
                if (0 === $k) {
                    $refTable = $v;
                } else {
                    $columns = $k;
                    $refColumns = $v;
                }
            }
            $definition .= sprintf("\$this->addForeignKey('%s', '{{%%%s}}', '%s', '{{%%%s}}', '%s');\n",
                'fk_'.$table->name.'_'.$columns, $table->name, $columns, $refTable, $refColumns);
        }
        return "$definition\n";
    }
752911
public function createCommand($sql = null, $params = [])
    {
        $command = new Command([
            'db' => $this,
            'sql' => $sql,
        ]);

        return $command->bindValues($params);
    }
708780
public function getPrimaryKey($table)
    {
        if (! $table) {
            return '';
        }

        $sql = "SELECT cols.column_name
            FROM all_constraints cons, all_cons_columns cols
            WHERE upper(cols.table_name) = upper('{$table}')
                AND cons.constraint_type = 'P'
                AND cons.constraint_name = cols.constraint_name
                AND cons.owner = cols.owner
                AND cols.position = 1
                AND cons.owner = (select user from dual)
            ORDER BY cols.table_name, cols.position";
        $data = $this->connection->selectOne($sql);

        if ($data) {
            return $data->column_name;
        }

        return '';
    }
727042
protected function query_insert_id ( $tableName, $primaryKey = null )
    {
        $sequenceName = $tableName;
        if ($primaryKey) {
            $sequenceName .= "_$primaryKey";
        }
        $sequenceName .= '_seq';

        $sql = "
            SELECT
                CURRVAL('%s')
                ";
        $args = array($sql, $sequenceName);
        $sql = $this->sql_printf($args);
        if (!($res = pg_query($this->conn, $sql))) {
            return 0;
        }
        $val = pg_fetch_row($res, 0);
        if ($val && isset($val[0])) {
            $val = $val[0];
        }

        pg_free_result($res);
        return $val;
    }
780959
public function getPrimaryKey($tableAlias = '')
    {
        $output = '';

        if (!empty($tableAlias)) {
            $output .= '`' . $tableAlias . '`.';
        }

        $output .= '`'.static::ID_COLUMN.'`';

        return $output;
    }
385622
public function buildInsertBatchSQL($table = null, $data = array())
	{
		$keys = array_keys($data[0]);
		$values = array();
		foreach($data as $item)
		{
			$params = array();
			foreach($keys as $key)
			{
				$paramName = ':' . $this->getParamName();
				$this->bindValue($paramName, $item[$key]);
				$params[] = $paramName;
			}
			$values[] = '(' . implode(',', $params) . ')';
		}
		$this->operationOption['params'] = array();
		return 'insert into ' . $this->parseTable($table) . ' (' . implode(',',array_map(array($this,'parseKeyword'),$keys)) . ') values ' . implode(',', $values) . $this->parseLock();
	}
528538
public function createTable( $table ) {
		$table = $this->safeTable($table);
		$sql = "CREATE TABLE $table ( id INTEGER PRIMARY KEY AUTOINCREMENT ) ";
		$this->adapter->exec( $sql );
	}
1151224
public function getPrimaryKey($table)
	{
		$keys = $this->getTableKeys($table);
		$key  = false;

		if ($keys && count($keys) > 0)
		{
			foreach ($keys as $k)
			{
				if ($k->Key_name == 'PRIMARY')
				{
					$key = $k->Column_name;
				}
			}
		}

		return $key;
	}
742584
public function compileCreate(BaseBlueprint $blueprint, Fluent $command)
    {
        $sql = parent::compileCreate($blueprint, $command);

        if (isset($blueprint->inherits)) {
            $sql .= ' INHERITS ("'.$blueprint->inherits.'")';
        }
        return $sql;
    }
252981
public function createCommand($sql = null, $params = [])
    {
        /** @var Command $command */
        $command = new $this->commandClass([
            'db' => $this,
            'sql' => $sql,
        ]);

        return $command->bindValues($params);
    }
65681
protected function generateCreateTableSql( $tableName, ezcDbSchemaTable $tableDefinition )
    {
        $this->context['skip_primary'] = false;
        parent::generateCreateTableSql( $tableName, $tableDefinition );
    }
881705
public function getQueryStatements($table){
		// field declaration
		$query = array();
		array_push($query, $this->name . ' ' . $this->type);
		if($this->nullable == false)
			array_push($query, ' NOT NULL');
		else array_push($query, ' NULL');
		if(isset($this->default_value)){
			$value = $this->default_value;
			if($this->type == 'BOOL')
				$value = ($this->default_value)?1:0;
			array_push($query, " DEFAULT '$value'");
		}
		if($this->auto_increments && $this->type == 'INT')
			array_push($query, ' AUTO_INCREMENT');
		// constraints
		if($this->primary)
			array_push($query, ",\n\t" . 'CONSTRAINT PK_' . $this->name . ' PRIMARY KEY (' . $this->name . ')');
		if($this->unique)
			array_push($query, ",\n\t" . 'CONSTRAINT UC_' . $this->name . ' UNIQUE KEY (' . $this->name . ')');
		if($this->foreign)
			array_push($query, ",\n\tCONSTRAINT FK_$table" . $this->foreign_class . '_' . $this->name .
				' FOREIGN KEY (' . $this->name . ") REFERENCES " . $this->foreign_class . " (" . $this->foreign_property . ')');

		return implode($query);
	}
1032012
private function _select($table_name, $columns, $primary_key_value)
	{
		// Get the schema and primary key
		$table_schema      = self::_getTableSchema($table_name);
		$table_primary_key = self::_getTablePrimaryKey($table_name);

		// Get the columns
		$parameter_columns = Validation::validateTableColumns($table_name, $table_schema, $columns);

		// Escape the column names
		$parameter_columns = self::_escapeColumnNames($parameter_columns);

		// Construct the primary key requirement
		$primary_key_value = intval($primary_key_value);

		// Clean the table name
		$table_name = self::_getCleanTableName($table_name);

		// Construct the SELECT sql
		$sql = '
			SELECT ' . implode(', ', $parameter_columns) . '
			FROM ' . $table_name . '
			WHERE ' . $table_primary_key . ' = $1;
		';

		// Sanitize and run the query
		$rows = Utility::pgQueryParams($sql, array($primary_key_value));

		// Validate result, check that primary key is set
		if (empty($rows) || !array_key_exists('0', $rows) || !array_key_exists($table_primary_key, $rows[0]))
		{
			Utility::throwException('Record not found for ' . $table_name . ' with a primary key value of ' . $primary_key_value);
		}

		// Return the only record
		return $rows[0];
	}