Note: This method may not return a meaningful or consistent result across different drivers,
because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY
columns or sequences.
/** * @param string $tableName * @param array $rows */ protected function insertTableRows($tableName, array $rows) { foreach ($rows as $rowKey => $values) { $this->connection->insert($tableName, $this->parser->parse($values)); $this->parser->addReference($rowKey, $this->connection->lastInsertId()); } }
/** * Saves the pool to the database. * * @param \MusicBox\Entity\Like $pool */ public function save($pool) { $poolData = array('address_id' => $pool->getAddress()->getId(), 'access_info' => $pool->getAccessInfo()); if ($pool->getId()) { $this->db->update('pools', $poolData, array('pool_id' => $pool->getId())); $newFile = $this->handleFileUpload($item); if ($newFile) { $poolData['image'] = $pool->getImage(); } } else { // The pool is new, note the creation timestamp. $poolData['created_at'] = time(); $this->db->insert('pools', $poolData); // Get the id of the newly created pool and set it on the entity. $id = $this->db->lastInsertId(); $pool->setId($id); // If a new image was uploaded, update the pool with the new // filename. $newFile = $this->handleFileUpload($pool); if ($newFile) { $newData = array('image' => $pool->getImage()); $this->db->update('pools', $newData, array('pool_id' => $id)); } } }
/** * @inheritdoc */ public function addJobToQueue(Queue $queue, Job &$job) { $qb = $this->connection->createQueryBuilder(); $qb->insert($this->getQueueTableName())->values([$this->columns['__CLASS__'] => ':class', $this->columns[JobReflector::PROPERTY_QUEUE] => ':queue', $this->columns[JobReflector::PROPERTY_CREATED] => ':created', $this->columns[JobReflector::PROPERTY_SCHEDULE] => ':schedule', $this->columns[JobReflector::PROPERTY_FAILED] => ':failed', $this->columns[JobReflector::PROPERTY_FINISHED] => ':finished', $this->columns[JobReflector::PROPERTY_RESULT] => ':result', $this->columns[JobReflector::PROPERTY_PROGRESS] => ':progress', $this->columns[JobReflector::PROPERTY_LAST_ATTEMPT] => ':lastAttempt', $this->columns[JobReflector::PROPERTY_TIMEOUT] => ':timeout', $this->columns[JobReflector::PROPERTY_RETRY_COUNT] => ':retryCount', $this->columns[JobReflector::PROPERTY_RETRY] => ':retry', $this->columns[JobReflector::PROPERTY_VERSION] => ':version', $this->columns[JobReflector::PROPERTY_PARAMETERS] => ':parameters'])->setParameters(['class' => get_class($job), 'queue' => $queue->getName(), 'created' => (new DateTimeImmutable())->format('Y-m-d H:i:s'), 'schedule' => JobReflector::getSchedule($job) ? JobReflector::getSchedule($job)->format('Y-m-d H:i:s') : (new DateTimeImmutable())->format('Y-m-d H:i:s'), 'failed' => false, 'finished' => null, 'result' => null, 'progress' => null, 'lastAttempt' => null, 'timeout' => null, 'retryCount' => 0, 'retry' => false, 'version' => JobReflector::getVersion($job), 'parameters' => json_encode(JobReflector::getParameters($job))]); $qb->execute(); return $this->connection->lastInsertId('job_seq'); }
public function save(Order $order) { $data = $order->jsonSerialize(); unset($data['id']); $this->connection->insert($this->getTableName(), $data); $order->setId($this->connection->lastInsertId()); }
/** * Saves the artist to the database. * * @param \MusicBox\Entity\Artist $artist */ public function save($artist) { $artistData = array('name' => $artist->getName(), 'short_biography' => $artist->getShortBiography(), 'biography' => $artist->getBiography(), 'soundcloud_url' => $artist->getSoundCloudUrl(), 'image' => $artist->getImage()); if ($artist->getId()) { // If a new image was uploaded, make sure the filename gets set. $newFile = $this->handleFileUpload($artist); if ($newFile) { $artistData['image'] = $artist->getImage(); } $this->db->update('artists', $artistData, array('artist_id' => $artist->getId())); } else { // The artist is new, note the creation timestamp. $artistData['created_at'] = time(); $this->db->insert('artists', $artistData); // Get the id of the newly created artist and set it on the entity. $id = $this->db->lastInsertId(); $artist->setId($id); // If a new image was uploaded, update the artist with the new // filename. $newFile = $this->handleFileUpload($artist); if ($newFile) { $newData = array('image' => $artist->getImage()); $this->db->update('artists', $newData, array('artist_id' => $id)); } } }
protected function doStart($parentId) { $this->conn->beginTransaction(); $platform = $this->conn->getDatabasePlatform(); $variables = $this->variables; $executionNextPollDate = null; if (isset($variables['batchWaitInterval'])) { if (!$variables['batchWaitInterval'] instanceof \DateInterval) { throw new \ezcWorkflowExecutionException("Specified batch waiting interval has to be instance of DateInterval!"); } $executionNextPollDate = new \DateTime("now"); $executionNextPollDate->add($variables['batchWaitInterval']); $executionNextPollDate = $executionNextPollDate->format($platform->getDateTimeFormatString()); } $serializer = $this->options->getSerializer(); $now = new \DateTime("now"); $data = array('workflow_id' => (int) $this->workflow->id, 'execution_parent' => $parentId, 'execution_started' => $now->format($platform->getDateTimeFormatString()), 'execution_variables' => $serializer->serialize($variables), 'execution_waiting_for' => $serializer->serialize($this->waitingFor), 'execution_threads' => $serializer->serialize($this->threads), 'execution_next_thread_id' => (int) $this->nextThreadId, 'execution_next_poll_date' => $executionNextPollDate); if ($platform->prefersSequences()) { $data['execution_id'] = (int) $this->conn->fetchColumn($platform->getSequenceNextValSQL($this->options->executionSequence())); $this->id = $data['execution_id']; } $this->conn->insert($this->options->executionTable(), $data); // execution_id if (!$platform->prefersSequences()) { $this->id = (int) $this->conn->lastInsertId(); } }
/** * {@inheritdoc} */ public function save(StudyInterface $study) { $qb = $this->connection->createQueryBuilder(); if ($study->getId() === null) { $qb->insert('vbee_study')->values(['name' => '?', 'description' => '?', 'graduation' => '?', 'startDate' => '?', 'endDate' => '?', 'personId' => '?'])->setParameter(0, $study->getName())->setParameter(1, $study->getDescription())->setParameter(2, $study->getGraduation())->setParameter(3, $study->getStartDate()->format('Y-m-d'))->setParameter(4, $study->getEndDate()->format('Y-m-d'))->setParameter(5, $study->getPerson()->getId())->execute(); $study->setId($this->connection->lastInsertId()); } else { $qb->update('vbee_study')->set('name', '?')->set('description', '?')->set('graduation', '?')->set('startDate', '?')->set('endDate', '?')->set('personId', '?')->where('id = ?')->setParameter(0, $study->getName())->setParameter(1, $study->getDescription())->setParameter(2, $study->getGraduation())->setParameter(3, $study->getStartDate()->format('Y-m-d'))->setParameter(4, $study->getEndDate()->format('Y-m-d'))->setParameter(5, $study->getPerson()->getId())->setParameter(6, $study->getId())->execute(); } return $study; }
public function create($values) { $query = $this->db->createQueryBuilder()->insert('articles'); // Append parameters to insert to the query foreach ($values as $key => $value) { $query = $query->setValue($key, ':' . $key)->setParameter(':' . $key, $value); } $query->execute(); // @TODO: Check if this works in MariaDB return $this->db->lastInsertId('articles_id_seq'); }
public function save($user) { $userData = array('name' => $user->getName(), 'email' => $user->getEmail(), 'password' => $user->getPassword(), 'joinTime' => $user->getJoinTime(), 'registerIp' => $user->getRegisterIp(), 'sharedKey' => $user->getSharedKey(), 'integration' => $user->getIntegration(), 'shareKey' => $user->getShareKey()); $this->db->insert('user', $userData); $id = $this->db->lastInsertId(); $user->setId($id); }
/** * Saves the user to the database. * * @param \MusicBox\Entity\User $user */ public function save($user) { $userData = array('username' => $user->getUsername(), 'mail' => $user->getMail(), 'role' => $user->getRole()); // If the password was changed, re-encrypt it. if (strlen($user->getPassword()) != 88) { $userData['salt'] = uniqid(mt_rand()); $userData['password'] = $this->encoder->encodePassword($user->getPassword(), $userData['salt']); } if ($user->getId()) { // If a new image was uploaded, make sure the filename gets set. $newFile = $this->handleFileUpload($user); if ($newFile) { $userData['image'] = $user->getImage(); } $this->db->update('users', $userData, array('user_id' => $user->getId())); } else { // The user is new, note the creation timestamp. $userData['created_at'] = time(); $this->db->insert('users', $userData); // Get the id of the newly created user and set it on the entity. $id = $this->db->lastInsertId(); $user->setId($id); // If a new image was uploaded, update the user with the new // filename. $newFile = $this->handleFileUpload($user); if ($newFile) { $newData = array('image' => $user->getImage()); $this->db->update('users', $newData, array('user_id' => $id)); } } }
public function create(CacheRecord $cacheRecord) { $this->db->insert($this->entityTable, $cacheRecord->toArray()); if ($this->db->lastInsertId() <= 0) { throw new InvalidArgumentException("The insert failed."); } return $this->db->lastInsertId(); }
/** * Tests whether autoincrement works * * @return boolean true if autoincrement works, false otherwise */ protected function checkAutoincrement() { $this->connection->executeUpdate('INSERT INTO ' . $this->tableName . ' ("text") VALUES ("test")'); $insertId = $this->connection->lastInsertId(); $this->connection->executeUpdate('DELETE FROM ' . $this->tableName . ' WHERE "someid" = ?', array($insertId)); // insert again $this->connection->executeUpdate('INSERT INTO ' . $this->tableName . ' ("text") VALUES ("test2")'); $newInsertId = $this->connection->lastInsertId(); return $insertId !== $newInsertId; }
public function persistObject($object) { $data = $this->preparePersistChangeSet($object); $this->connection->insert($this->getTableName(), $data); $class = $this->objectManager->getClassMetadata(get_class($object)); if (!isset($data[$class->identifier[0]])) { $data[$class->identifier[0]] = $this->connection->lastInsertId(); } return $data; }
/** * {@inheritdoc} */ public function save(PersonInterface $person) { $qb = $this->connection->createQueryBuilder(); if ($person->getId() === null) { $qb->insert('vbee_person')->values(['birthDate' => '?', 'description' => '?', 'email' => '?', 'familyName' => '?', 'gender' => '?', 'givenName' => '?', 'jobTitle' => '?', 'nationality' => '?', 'telephone' => '?'])->setParameter(0, $person->getBirthDate()->format('Y-m-d'))->setParameter(1, $person->getDescription())->setParameter(2, $person->getEmail())->setParameter(3, $person->getFamilyName())->setParameter(4, $person->getGender())->setParameter(5, $person->getGivenName())->setParameter(6, $person->getJobTitle())->setParameter(7, $person->getNationality())->setParameter(8, $person->getTelephone())->execute(); $person->setId($this->connection->lastInsertId()); } else { $qb->update('vbee_person')->set('birthDate', '?')->set('description', '?')->set('email', '?')->set('familyName', '?')->set('gender', '?')->set('givenName', '?')->set('jobTitle', '?')->set('nationality', '?')->set('telephone', '?')->where('id = ?')->setParameter(0, $person->getBirthDate()->format('Y-m-d'))->setParameter(1, $person->getDescription())->setParameter(2, $person->getEmail())->setParameter(3, $person->getFamilyName())->setParameter(4, $person->getGender())->setParameter(5, $person->getGivenName())->setParameter(6, $person->getJobTitle())->setParameter(7, $person->getNationality())->setParameter(8, $person->getTelephone())->setParameter(9, $person->getId())->execute(); } return $person; }
/** * Saves the like to the database. * * @param Like $like * * @return Like $like */ public function save($like) { $likeData = array('restaurant_id' => $like->getRestaurant(), 'user_id' => $like->getUser()); if ($like->getId()) { $this->db->update('likes', $likeData, array('id' => $like->getId())); } else { $this->db->insert('likes', $likeData); $last = $this->db->lastInsertId(); return $this->find($last); } }
/** * Saves the menu to the database. * * @param Menu $menu * * @return Menu $menu */ public function save($menu) { $menuData = array('nom' => $menu->getNom(), 'prix' => $menu->getPrix(), 'restaurant_id' => $menu->getRestaurant(), 'primary_id' => $menu->getProduit(), 'boisson' => $menu->getBoisson(), 'dessert' => $menu->getDessert()); if ($menu->getId()) { $this->db->update('menus', $menuData, array('id' => $menu->getId())); } else { $this->db->insert('menus', $menuData); $last = $this->db->lastInsertId(); return $this->find($last); } }
/** * {@inheritdoc} */ public function save(OrganizationInterface $organization) { $qb = $this->connection->createQueryBuilder(); if ($organization->getId() === null) { $qb->insert('vbee_organization')->values(['address' => '?', 'description' => '?', 'email' => '?', 'location' => '?', 'name' => '?', 'numberOfEmployees' => '?', 'telephone' => '?'])->setParameter(0, $organization->getAddress())->setParameter(1, $organization->getDescription())->setParameter(2, $organization->getEmail())->setParameter(3, $organization->getLocation())->setParameter(4, $organization->getName())->setParameter(5, $organization->getNumberOfEmployees())->setParameter(6, $organization->getTelephone())->execute(); $organization->setId($this->connection->lastInsertId()); } else { $qb->update('vbee_organization')->set('address', '?')->set('description', '?')->set('email', '?')->set('location', '?')->set('name', '?')->set('numberOfEmployees', '?')->set('telephone', '?')->where('id = ?')->setParameter(0, $organization->getAddress())->setParameter(1, $organization->getDescription())->setParameter(2, $organization->getEmail())->setParameter(3, $organization->getLocation())->setParameter(4, $organization->getName())->setParameter(5, $organization->getNumberOfEmployees())->setParameter(6, $organization->getTelephone())->setParameter(7, $organization->getId())->execute(); } return $organization; }
/** * Saves the restaurant to the database. * * @param Restaurant $restaurant * * @return Restaurant $restaurant */ public function save($restaurant) { $restaurantData = array('nom' => $restaurant->getNom(), 'adresse' => $restaurant->getAdresse(), 'cp' => $restaurant->getCp(), 'ville' => $restaurant->getVille(), 'ouverture' => $restaurant->getOuverture(), 'fermeture' => $restaurant->getFermeture(), 'likes' => $restaurant->getLikes()); if ($restaurant->getId()) { $this->db->update('restaurants', $restaurantData, array('id' => $restaurant->getId())); } else { $this->db->insert('restaurants', $restaurantData); $last = $this->db->lastInsertId(); return $this->find($last); } }
/** * {@inheritdoc} */ public function save(ExperienceInterface $experience) { $qb = $this->connection->createQueryBuilder(); if ($experience->getId() === null) { $qb->insert('vbee_experience')->values(['type' => '?', 'startDate' => '?', 'endDate' => '?', 'personId' => '?', 'organizationId' => '?'])->setParameter(0, $experience->getType())->setParameter(1, $experience->getStartDate()->format('Y-m-d'))->setParameter(2, $experience->getEndDate()->format('Y-m-d'))->setParameter(3, $experience->getPerson()->getId())->setParameter(4, $experience->getOrganization()->getId())->execute(); $experience->setId($this->connection->lastInsertId()); } else { $qb->update('vbee_experience')->set('type', '?')->set('startDate', '?')->set('endDate', '?')->set('personId', '?')->set('organizationId', '?')->where('id = ?')->setParameter(0, $experience->getType())->setParameter(1, $experience->getStartDate()->format('Y-m-d'))->setParameter(2, $experience->getEndDate()->format('Y-m-d'))->setParameter(3, $experience->getPerson()->getId())->setParameter(4, $experience->getOrganization()->getId())->setParameter(5, $experience->getId())->execute(); } return $experience; }
/** * Saves the produit to the database. * * @param Produit $produit * * @return Produit $produit */ public function save($produit) { $produitData = array('nom' => $produit->getNom(), 'prix' => $produit->getPrix(), 'type' => $produit->getType(), 'image' => $produit->getImage(), 'restaurant' => $produit->getRestaurant()); if ($produit->getId()) { $this->db->update('produits', $produitData, array('id' => $produit->getId())); } else { $this->db->insert('produits', $produitData); $last = $this->db->lastInsertId(); return $this->find($last); } }
public function create($user) { try { $rows = $this->conn->insert('users', ['username' => $user['username'], 'age' => $user['age']]); if ($rows) { return $this->find($this->conn->lastInsertId()); } else { throw new \InvalidArgumentException("Could not create user: {$user['username']}"); } } catch (\PDOException $e) { throw new \InvalidArgumentException($e->getMessage()); } }
/** * Saves the user to the database. * * @param User $user * * @return User $user */ public function save($user) { $userData = array('username' => $user->getUsername(), 'password' => $user->getPassword(), 'roles' => $user->getRoles()); if ($user->getId()) { // If a new image was uploaded, make sure the filename gets set. $this->db->update('users', $userData, array('id' => $user->getId())); } else { $userData['password'] = $this->encoder->encodePassword($userData['password'], ''); $this->db->insert('users', $userData); $last = $this->db->lastInsertId(); return $this->find($last); } }
public function save($cardKeyClass) { $cardKeyClassData = array('title' => $cardKeyClass->getTitle(), 'intro' => $cardKeyClass->getIntro(), 'isVipOrInt' => $cardKeyClass->getIsVipOrInt(), 'number' => $cardKeyClass->getNumber()); if ($cardKeyClass->getId()) { $result = $this->db->update('cardKeyClass', $cardKeyClassData, array('id' => $cardKeyClass->getId())); } else { $this->db->insert('cardKeyClass', $cardKeyClassData); $id = $this->db->lastInsertId(); $cardKeyClass->setId($id); $result = $id; } return $result; }
public function save($goodsClass) { $goodsClassData = array('title' => $goodsClass->getTitle(), 'orderBy' => $goodsClass->getOrderBy()); if ($goodsClass->getId()) { $result = $this->db->update('goodsClass', $goodsClassData, array('id' => $goodsClass->getId())); } else { $this->db->insert('goodsClass', $goodsClassData); $id = $this->db->lastInsertId(); $goodsClass->setId($id); $result = $id; } return $result; }
/** * Save the teammate * @param object $teammate * @return object */ public function save($teammate) { $teammateData = array('firstname' => $teammate->getFirstname(), 'lastname' => $teammate->getLastname(), 'email' => $teammate->getEmail(), 'phone' => $teammate->getPhone(), 'image' => $teammate->getImage()); if ($teammate->getId()) { $this->db->update('teammate', $teammateData, array('id' => $teammate->getId())); } else { $this->db->insert('teammate', $teammateData); // Get the id of the newly created artist and set it on the entity. $id = $this->db->lastInsertId(); $teammate->setId($id); } return $teammate; }
/** * Saves the like to the database. * * @param \MusicBox\Entity\Like $like */ public function save($like) { $likeData = array('artist_id' => $like->getArtist()->getId(), 'user_id' => $like->getUser()->getId()); if ($like->getId()) { $this->db->update('likes', $likeData, array('like_id' => $like->getId())); } else { // The like is new, note the creation timestamp. $likeData['created_at'] = time(); $this->db->insert('likes', $likeData); // Get the id of the newly created like and set it on the entity. $id = $this->db->lastInsertId(); $like->setId($id); } }
/** * Saves the group to the database. * * @param \MusicBox\Entity\Like $group */ public function save($group) { $groupData = array('artist_id' => $group->getArtist()->getId(), 'user_id' => $group->getUser()->getId()); if ($group->getId()) { $this->db->update('groups', $groupData, array('group_id' => $group->getId())); } else { // The group is new, note the creation timestamp. $groupData['created_at'] = time(); $this->db->insert('groups', $groupData); // Get the id of the newly created group and set it on the entity. $id = $this->db->lastInsertId(); $group->setId($id); } }
/** * Saves the comment to the database. * * @param \MusicBox\Entity\Comment $comment */ public function save($comment) { $commentData = array('artist_id' => $comment->getArtist()->getId(), 'user_id' => $comment->getUser()->getId(), 'comment' => $comment->getComment(), 'published' => $comment->getPublished()); if ($comment->getId()) { $this->db->update('comments', $commentData, array('comment_id' => $comment->getId())); } else { // The comment is new, note the creation timestamp. $commentData['created_at'] = time(); $this->db->insert('comments', $commentData); // Get the id of the newly created comment and set it on the entity. $id = $this->db->lastInsertId(); $comment->setId($id); } }
public function create($message) { try { $message = $this->addDefaults($message); $rows = $this->conn->insert('messages', ['message' => $message['message'], 'author' => $message['author'], 'parent' => $message['parent']]); if ($rows) { return $this->find($this->conn->lastInsertId()); } else { throw new \InvalidArgumentException("Could not create message."); } } catch (\PDOException $e) { throw new \InvalidArgumentException($e->getMessage()); } }
/** * Saves the lesson to the database. * * @param \MusicBox\Entity\Like $lesson */ public function save($lesson) { $lessonData = array('user_id' => $lesson->getUser()->getId()); if ($lesson->getId()) { $this->db->update('lessons', $lessonData, array('lesson_id' => $lesson->getId())); } else { // The lesson is new, note the creation timestamp. $lessonData['created_at'] = time(); $this->db->insert('lessons', $lessonData); // Get the id of the newly created lesson and set it on the entity. $id = $this->db->lastInsertId(); $lesson->setId($id); } }