Add the primary key to the current table
13850
public function modifyTable()
    {
        $table = $this->getTable();
        if (!$table->hasPrimaryKey() && !$table->hasBehavior('concrete_inheritance')) {
            $columnAttributes = array_merge(['primaryKey' => 'true'], $this->getParameters());
            $this->getTable()->addColumn($columnAttributes);
        }
    }
454537
def add_column(self, table, name='ID', data_type='int(11)', after_col=None, null=False, primary_key=False):
        """"""
        location = 'AFTER {0}'.format(after_col) if after_col else 'FIRST'
        null_ = 'NULL' if null else 'NOT NULL'
        comment = "COMMENT 'Column auto created by mysql-toolkit'"
        pk = 'AUTO_INCREMENT PRIMARY KEY {0}'.format(comment) if primary_key else ''
        query = 'ALTER TABLE {0} ADD COLUMN {1} {2} {3} {4} {5}'.format(wrap(table), name, data_type, null_, pk,
                                                                        location)
        self.execute(query)
        self._printer("\tAdded column '{0}' to '{1}' {2}".format(name, table, '(Primary Key)' if primary_key else ''))
        return name
1087729
private function _getPrimaryKeyFromInput($table_name, $keyed_array)
	{
		// Get the primary key
		$table_primary_key = self::_getTablePrimaryKey($table_name);

		// Find the primary key
		if (empty($keyed_array) || !array_key_exists($table_primary_key, $keyed_array))
		{
			Utility::throwException('Primary key value not found in input.');
		}

		return $keyed_array[$table_primary_key];
	}
1266218
def get_primary_key(self, table):
        """"""
        for column in self.get_schema(table):
            if len(column) > 3 and 'pri' in column[3].lower():
                return column[0]
88376
public function save() {

		if (empty(static::$table))
			$table = strtolower(substr(static::table(), strpos(static::table(), '\\')+1));
		else
			$table = static::$table;

		if (isset($this->_data[$table]) && count($this->_data[$table]) <= 0 ) {
			$post = $_POST;
			while(list($field, $value) = each($post)) {
				// Next if is Primary Keys
				// if (!empty($this->_id) && array_key_exists($field, $this->_id))
					// continue;
				
				$this->_data[$table][$field] = addslashes($value);
				$this->$field = $value;
			}
		}

		if ($table != '') {
			// Untuk menambah record
			if ($this->add == TRUE) {
				$before = $this->before();
				if (is_array($before) && count($before) > 1) {
					if (isset($before['insert'])) {
						$insert = $before['insert'];
						while(list($field, $value) = each($insert))
							$this->_data[$table][$field] = $value;
					}
				}
				$ret = self::$db->$table->insert($this->_data[$table]);
				$after = $this->after();
				if (is_array($after) && count($after) > 1) {
					if (isset($after['insert']) && is_callable($after['insert'])) {
						$insert = $after['insert'];
						$insert($this->_data[$table]);
					}
				}
			}
			// Untuk mengupdate record
			else {
				$before = $this->before();
				if (is_array($before) && count($before) > 1) {
					if (isset($before['update'])) {
						$update = $before['update'];
						while(list($field, $value) = each($update))
							$this->_data[$table][$field] = $value;
					}
				}
				$ret = self::$db->$table->update($this->_id, $this->_data[$table]);
				$after = $this->after();
				if (is_array($after) && count($after) > 1) {
					if (isset($after['update']) && is_callable($after['update'])) {
						$update = $after['update'];
						$update(array('pk'=>$this->_id, 'data'=>$this->_data[$table]));
					}
				}
			}
			
			$this->_data[$table] = array();
		}

		
		return $ret;
	}
1087123
protected function addPrimaryKey(Table $table)
    {
        $stmt = $this->dbh->query("SHOW KEYS FROM `" . $table->getName() . "`");

        // Loop through the returned results, grouping the same key_name together
        // adding each column for that key.
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            // Skip any non-primary keys.
            if ($row['Key_name'] !== 'PRIMARY') {
                continue;
            }
            $name = $row["Column_name"];
            $table->getColumn($name)->setPrimaryKey(true);
        }
    }
1336397
public function addForeignKey($name, $table, $key)
    {
        $this->addKeys[$name] = [$table, $key];
        return $this;
    }
1037083
def insert(self, row):
        
        self._check_dropped()
        res = self.engine.execute(self.table.insert(row))
        if len(res.inserted_primary_key) > 0:
            return res.inserted_primary_key[0]
636988
def refresh(self, fields=None, **kwargs):
        
        cond = self.c[self._primary_field]==self._key
        query = self.filter(cond, **kwargs)
        if not fields:
            fields = list(self.table.c)
        
        v = query.values_one(*fields)
        if not v:
            raise NotFound('Instance <{0}:{1}> can not be found'.format(self.tablename, self._key))
        
        d = self._data_prepare(v.items())
        self.update(**d)
        self.set_saved()
400229
def key_add(self):
        """"""
        from .main import add_api_key
        add_api_key(self.key_name.get(), self.key_val.get())

        # Clear the text fields
        self.key_name.set("")
        self.key_val.set("")
819088
protected function setPrimaryKey()
    {
        // making default primary key as id
        $primaryKey = isset($this->primaryKey) && is_null($this->primaryKey) ?
            static::$defaultPrimaryKey :
            $this->primaryKey;

        $this->primaryKey = $primaryKey;
    }
34051
public TableWriteItems addPrimaryKeyToDelete(PrimaryKey primaryKey) {
        if (primaryKey != null) {
            if (primaryKeysToDelete == null)
                primaryKeysToDelete = new ArrayList<PrimaryKey>();
            checkConsistency(primaryKey);
            this.primaryKeysToDelete.add(primaryKey);
        }
        return this;
    }
428027
protected function update() {
		if (!static::$_primaryKeys) {
			throw new RuntimeException('This table has no primary keys');
		}

		$column_values = array();
		foreach ($this->getModifiedColumns() as $column) {
			$column_values[$column] = $this->$column;
		}

		// If array is empty there is nothing to update
		if (empty($column_values)) {
			return 0;
		}

		$q = static::getQuery();

		foreach (static::$_primaryKeys as $pk) {
			if ($this->$pk === null) {
				throw new RuntimeException('Cannot update with NULL primary key.');
			}
			$q->add($pk, $this->$pk);
		}

		$row_count = $this->doUpdate($column_values, $q);
		$this->resetModified();
		return $row_count;
	}
566249
private function _update($table_name, $keyed_array)
	{
		// Get the schema and primary key
		$table_schema      = self::_getTableSchema($table_name);
		$table_primary_key = self::_getTablePrimaryKey($table_name);

		// Get the columns and values
		list($parameter_columns, $parameter_values) = Validation::validateTableInput($table_name, $table_schema, $table_primary_key, $keyed_array);

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

		// List the number of parameters - Function creates an array of range 1..n and prepends '$' to each number
		$parameter_placeholders = self::_calculateInputPlaceholders($parameter_columns);

		// Construct the proper UPDATE parameters statement
		array_walk($parameter_placeholders,
			function(&$value, $key)
			{ 
				$value = $key . ' = ' . $value;
			}
		);

		// Construct the primary key requirement
		$primary_key_placeholder = '$' . (count($parameter_placeholders) + 1);
		$primary_key_value       = self::_getPrimaryKeyFromInput($table_name, $keyed_array);

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

		// Construct the UPDATE statement
		$sql = '
			UPDATE ' . $table_name . ' SET
			' . implode(', ', $parameter_placeholders) . '
			WHERE ' . $table_primary_key . ' = ' . $primary_key_placeholder . '
			RETURNING *;
		';

		// Append the primary key value to the parameter values
		$parameter_values[] = $primary_key_value;

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

		// 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];
	}
190393
def id(self):
        
        return sa.Column(sa.Integer, primary_key=True, autoincrement=True)
1318064
protected function addEntryTable()
    {
        $table = $this->createTable($this->options['entry_table_name']);

        $table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
        $table->addColumn('class_id', 'integer', array('unsigned' => true));
        $table->addColumn('object_identity_id', 'integer', array('unsigned' => true, 'notnull' => false));
        $table->addColumn('field_name', 'string', array('length' => 50, 'notnull' => false));
        $table->addColumn('ace_order', 'smallint', array('unsigned' => true));
        $table->addColumn('security_identity_id', 'integer', array('unsigned' => true));
        $table->addColumn('mask', 'integer');
        $table->addColumn('granting', 'boolean');
        $table->addColumn('granting_strategy', 'string', array('length' => 30));
        $table->addColumn('audit_success', 'boolean');
        $table->addColumn('audit_failure', 'boolean');

        $table->setPrimaryKey(array('id'));
        $table->addUniqueIndex(array('class_id', 'object_identity_id', 'field_name', 'ace_order'));
        $table->addIndex(array('class_id', 'object_identity_id', 'security_identity_id'));

        $table->addForeignKeyConstraint($this->getTable($this->options['class_table_name']), array('class_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
        $table->addForeignKeyConstraint($this->getTable($this->options['oid_table_name']), array('object_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
        $table->addForeignKeyConstraint($this->getTable($this->options['sid_table_name']), array('security_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
    }
1092848
def get_primary_key_columns(self):
        
        if not self.has_primary_key():
            raise DBALException('Table "%s" has no primary key.' % self.get_name())

        return self.get_primary_key().get_columns()