本文整理汇总了PHP中BasePeer::doInsert方法的典型用法代码示例。如果您正苦于以下问题:PHP BasePeer::doInsert方法的具体用法?PHP BasePeer::doInsert怎么用?PHP BasePeer::doInsert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BasePeer
的用法示例。
在下文中一共展示了BasePeer::doInsert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDoInsert
public function testDoInsert()
{
try {
$c = new Criteria();
$c->setPrimaryTableName(BookPeer::TABLE_NAME);
$c->add(BookPeer::AUTHOR_ID, 'lkhlkhj');
BasePeer::doInsert($c, Propel::getConnection());
} catch (PropelException $e) {
$this->assertContains('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
示例2: insert
protected function insert($connection = null)
{
if (!isset($connection)) {
$connection = QubitTransactionFilter::getConnection(QubitOaiHarvest::DATABASE_NAME);
}
$offset = 0;
foreach ($this->tables as $table) {
$criteria = new Criteria();
foreach ($table->getColumns() as $column) {
if (!array_key_exists($column->getPhpName(), $this->values)) {
if ('createdAt' == $column->getPhpName() || 'updatedAt' == $column->getPhpName()) {
$this->values[$column->getPhpName()] = new DateTime();
}
if ('sourceCulture' == $column->getPhpName()) {
$this->values['sourceCulture'] = sfPropel::getDefaultCulture();
}
}
if (array_key_exists($column->getPhpName(), $this->values)) {
if (null !== ($param = $this->param($column))) {
$criteria->add($column->getFullyQualifiedName(), $param);
}
}
$offset++;
}
if (null !== ($id = BasePeer::doInsert($criteria, $connection))) {
// Guess that the first primary key of the first table is auto
// incremented
if ($this->tables[0] == $table) {
$columns = $table->getPrimaryKeyColumns();
$this->values[$columns[0]->getPhpName()] = $this->keys[$columns[0]->getPhpName()] = $id;
}
}
}
return $this;
}
示例3: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$criteria = $this->buildCriteria();
$pk = BasePeer::doInsert($criteria, $con);
$affectedRows = 1;
$this->setNew(false);
} else {
$affectedRows = ReservationItemRightsPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例4: doInsert
/**
* Performs an INSERT on the database, given a SubscriberGroupMembership or Criteria object.
*
* @param mixed $values Criteria or SubscriberGroupMembership object containing data that is used to create the INSERT statement.
* @param PropelPDO $con the PropelPDO connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, PropelPDO $con = null)
{
if ($con === null) {
$con = Propel::getConnection(SubscriberGroupMembershipPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
// rename for clarity
} else {
$criteria = $values->buildCriteria();
// build Criteria from SubscriberGroupMembership object
}
// Set the correct dbName
$criteria->setDbName(SubscriberGroupMembershipPeer::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->beginTransaction();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (Exception $e) {
$con->rollBack();
throw $e;
}
return $pk;
}
示例5: doInsert
/**
* Method perform an INSERT on the database, given a MetadataProfile or Criteria object.
*
* @param mixed $values Criteria or MetadataProfile object containing data that is used to create the INSERT statement.
* @param PropelPDO $con the PropelPDO connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, PropelPDO $con = null)
{
if ($con === null) {
$con = Propel::getConnection(MetadataProfilePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
// rename for clarity
} else {
$criteria = $values->buildCriteria();
// build Criteria from MetadataProfile object
}
if ($criteria->containsKey(MetadataProfilePeer::ID) && $criteria->keyContainsValue(MetadataProfilePeer::ID)) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . MetadataProfilePeer::ID . ')');
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->beginTransaction();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $pk;
}
示例6: doInsert
/**
* Method perform an INSERT on the database, given a ExamCommentDig or Criteria object.
*
* @param mixed $values Criteria or ExamCommentDig object containing data that is used to create the INSERT statement.
* @param PropelPDO $con the PropelPDO connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, PropelPDO $con = null)
{
foreach (sfMixer::getCallables('BaseExamCommentDigPeer:doInsert:pre') as $callable) {
$ret = call_user_func($callable, 'BaseExamCommentDigPeer', $values, $con);
if (false !== $ret) {
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(ExamCommentDigPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
// rename for clarity
} else {
$criteria = $values->buildCriteria();
// build Criteria from ExamCommentDig object
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->beginTransaction();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
foreach (sfMixer::getCallables('BaseExamCommentDigPeer:doInsert:post') as $callable) {
call_user_func($callable, 'BaseExamCommentDigPeer', $values, $con, $pk);
}
return $pk;
}
示例7: doInsert
/**
* Method perform an INSERT on the database, given a UserStatEquip or Criteria object.
*
* @param mixed $values Criteria or UserStatEquip object containing data that is used to create the INSERT statement.
* @param PropelPDO $con the PropelPDO connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, PropelPDO $con = null)
{
foreach (sfMixer::getCallables('BaseUserStatEquipPeer:doInsert:pre') as $callable) {
$ret = call_user_func($callable, 'BaseUserStatEquipPeer', $values, $con);
if (false !== $ret) {
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(UserStatEquipPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
// rename for clarity
} else {
$criteria = $values->buildCriteria();
// build Criteria from UserStatEquip object
}
if ($criteria->containsKey(UserStatEquipPeer::USER_STAT_EQUIP_ID) && $criteria->keyContainsValue(UserStatEquipPeer::USER_STAT_EQUIP_ID)) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . UserStatEquipPeer::USER_STAT_EQUIP_ID . ')');
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->beginTransaction();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
foreach (sfMixer::getCallables('BaseUserStatEquipPeer:doInsert:post') as $callable) {
call_user_func($callable, 'BaseUserStatEquipPeer', $values, $con, $pk);
}
return $pk;
}
示例8: doInsert
/**
* Method perform an INSERT on the database, given a PcBlogComment or Criteria object.
*
* @param mixed $values Criteria or PcBlogComment object containing data that is used to create the INSERT statement.
* @param PropelPDO $con the PropelPDO connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, PropelPDO $con = null)
{
// symfony_behaviors behavior
foreach (sfMixer::getCallables('BasePcBlogCommentPeer:doInsert:pre') as $sf_hook) {
if (false !== ($sf_hook_retval = call_user_func($sf_hook, 'BasePcBlogCommentPeer', $values, $con))) {
return $sf_hook_retval;
}
}
if ($con === null) {
$con = Propel::getConnection(PcBlogCommentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
// rename for clarity
} else {
$criteria = $values->buildCriteria();
// build Criteria from PcBlogComment object
}
if ($criteria->containsKey(PcBlogCommentPeer::ID) && $criteria->keyContainsValue(PcBlogCommentPeer::ID)) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . PcBlogCommentPeer::ID . ')');
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->beginTransaction();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
// symfony_behaviors behavior
foreach (sfMixer::getCallables('BasePcBlogCommentPeer:doInsert:post') as $sf_hook) {
call_user_func($sf_hook, 'BasePcBlogCommentPeer', $values, $con, $pk);
}
return $pk;
}
示例9: doInsert
public static function doInsert($values, PropelPDO $con = null)
{
if ($con === null) {
$con = Propel::getConnection(RelAnioActividadDocentePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
} else {
$criteria = $values->buildCriteria();
}
$criteria->setDbName(self::DATABASE_NAME);
try {
$con->beginTransaction();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $pk;
}
示例10: doInsert
/**
* Method perform an INSERT on the database, given a SchemaPropertyElementHistory or Criteria object.
*
* @param mixed $values Criteria or SchemaPropertyElementHistory object containing data that is used to create the INSERT statement.
* @param Connection $con the connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($values, $con = null)
{
foreach (sfMixer::getCallables('BaseSchemaPropertyElementHistoryPeer:doInsert:pre') as $callable) {
$ret = call_user_func($callable, 'BaseSchemaPropertyElementHistoryPeer', $values, $con);
if (false !== $ret) {
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
// rename for clarity
} else {
$criteria = $values->buildCriteria();
// build Criteria from SchemaPropertyElementHistory object
}
$criteria->remove(SchemaPropertyElementHistoryPeer::ID);
// remove pkey col since this table uses auto-increment
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->begin();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
foreach (sfMixer::getCallables('BaseSchemaPropertyElementHistoryPeer:doInsert:post') as $callable) {
call_user_func($callable, 'BaseSchemaPropertyElementHistoryPeer', $values, $con, $pk);
}
return $pk;
}
示例11: doInsert
public static function doInsert($values, PropelPDO $con = null)
{
foreach (sfMixer::getCallables('BaseProductPeer:doInsert:pre') as $callable) {
$ret = call_user_func($callable, 'BaseProductPeer', $values, $con);
if (false !== $ret) {
return $ret;
}
}
if ($con === null) {
$con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
$criteria = clone $values;
} else {
$criteria = $values->buildCriteria();
}
if ($criteria->containsKey(ProductPeer::ID) && $criteria->keyContainsValue(ProductPeer::ID)) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . ProductPeer::ID . ')');
}
$criteria->setDbName(self::DATABASE_NAME);
try {
$con->beginTransaction();
$pk = BasePeer::doInsert($criteria, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
foreach (sfMixer::getCallables('BaseProductPeer:doInsert:post') as $callable) {
call_user_func($callable, 'BaseProductPeer', $values, $con, $pk);
}
return $pk;
}
示例12: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0; // initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$criteria = $this->buildCriteria();
$pk = BasePeer::doInsert($criteria, $con);
$affectedRows = 1;
$this->setNew(false);
} else {
$affectedRows = ResponsableEleveAdressePeer::doUpdate($this, $con);
}
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
}
if ($this->collResponsableEleves !== null) {
foreach ($this->collResponsableEleves as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->collAbsenceEleveNotifications !== null) {
foreach ($this->collAbsenceEleveNotifications as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
} // doSave()
示例13: showImport
//.........这里部分代码省略.........
if (count($nonExistent)) {
throw new Exception('Unknown column in column list: ' . join(', ', $nonExistent));
}
// Open csv file
$fileInfo = $form->file->getFileInfo();
$fp = fopen($fileInfo['file']['tmp_name'], "r");
if (!$fp) {
throw new Exception('Unable to open file');
}
// Wrap in transaction
$deleted = 0;
$updated = 0;
$inserted = 0;
$con = Propel::getConnection(PropelQuery::from($modelClass)->getDbName());
$con->beginTransaction();
try {
// Replace will empty the table
if ($mode === self::IMPORT_REPLACE) {
$deleted = PropelQuery::from($modelClass)->deleteAll();
}
// Read csv lines
while (($data = fgetcsv($fp, 0, $delimiter, $enclosure, $escape)) !== false) {
if (count($data) !== count($columns)) {
throw new Exception('Invalid column count ' . count($data) . ', expected ' . count($columns));
}
if ($skipFirst) {
$skipFirst = false;
continue;
}
$data = array_combine($columns, $data);
$pkData = array();
// Check for null values and collect primary key
foreach ($data as $k => $v) {
if ($v === $nullValue) {
$data[$k] = $v = null;
}
if (in_array($k, $pks)) {
$pkData[$k] = $v;
}
}
$obj = null;
if ($mode === self::IMPORT_UPDATE || $mode === self::IMPORT_UPDATE_OR_INSERT) {
// attempt to find existing object using pk
if (count($pkData) === count($pks)) {
$obj = new $modelClass();
$obj->fromArray($pkData, BasePeer::TYPE_FIELDNAME);
$obj = PropelQuery::from($modelClass)->findPk($obj->getPrimaryKey());
}
if (!$obj && $mode === self::IMPORT_UPDATE_OR_INSERT) {
// not found, create new
$obj = new $modelClass();
}
} else {
// REPLACE, APPEND
$obj = new $modelClass();
}
// Remove unused columns
foreach ($data as $k => $v) {
if (!in_array($k, $useColumns)) {
unset($data[$k]);
}
}
if ($obj) {
// Unset primary key columns in data when appending
if ($mode === self::IMPORT_APPEND) {
foreach ($pks as $pk) {
if (array_key_exists($pk, $data)) {
unset($data[$pk]);
}
}
}
$obj->fromArray($data, BasePeer::TYPE_FIELDNAME);
if ($obj->isNew()) {
// allows insert of custom primary key
BasePeer::doInsert($obj->buildCriteria(), $con);
++$inserted;
} else {
$updated += $obj->save();
}
}
}
$con->commit();
} catch (Exception $e) {
$con->rollBack();
throw $e;
}
if ($deleted) {
$this->addMessage('Deleted: ' . $deleted);
}
if ($inserted) {
$this->addMessage('Inserted: ' . $inserted);
}
if ($updated) {
$this->addMessage('Updated: ' . $updated);
}
$this->addMessage('All done.', self::MSG_SUCCESS);
} else {
$this->addMainContent($form);
}
}
示例14: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
if ($this->isNew()) {
$this->modifiedColumns[] = OpenidAssociationPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$criteria = $this->buildCriteria();
if ($criteria->keyContainsValue(OpenidAssociationPeer::ID)) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . OpenidAssociationPeer::ID . ')');
}
$pk = BasePeer::doInsert($criteria, $con);
$affectedRows = 1;
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows = OpenidAssociationPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例15: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aGroup !== null) {
if ($this->aGroup->isModified() || $this->aGroup->isNew()) {
$affectedRows += $this->aGroup->save($con);
}
$this->setGroup($this->aGroup);
}
if ($this->aUser !== null) {
if ($this->aUser->isModified() || $this->aUser->isNew()) {
$affectedRows += $this->aUser->save($con);
}
$this->setUser($this->aUser);
}
if ($this->isNew()) {
$this->modifiedColumns[] = DirectoryPermissionPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$criteria = $this->buildCriteria();
if ($criteria->keyContainsValue(DirectoryPermissionPeer::ID)) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . DirectoryPermissionPeer::ID . ')');
}
$pk = BasePeer::doInsert($criteria, $con);
$affectedRows += 1;
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += DirectoryPermissionPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}