コード例 #1
0
ファイル: Default.php プロジェクト: Bananamoon/aimeos-core
 /**
  * Adds a new item object.
  *
  * @param MShop_Locale_Item_Site_Interface $item Item which should be inserted
  * @param integer $parentId ID of the parent item where the item should be inserted into
  * @param integer $refId ID of the item where the item should be inserted before (null to append)
  */
 public function insertItem(MShop_Locale_Item_Site_Interface $item, $parentId = null, $refId = null)
 {
     $context = $this->_getContext();
     $dbm = $context->getDatabaseManager();
     $dbname = $this->_getResourceName();
     $conn = $dbm->acquire($dbname);
     try {
         $date = date('Y-m-d H:i:s');
         /** mshop/locale/manager/site/default/item/insert
          * Inserts a new currency record into the database table
          *
          * The SQL statement must be a string suitable for being used as
          * prepared statement. It must include question marks for binding
          * the values from the log item to the statement before they are
          * sent to the database server. The number of question marks must
          * be the same as the number of columns listed in the INSERT
          * statement. The order of the columns must correspond to the
          * order in the saveItems() method, so the correct values are
          * bound to the columns.
          *
          * The SQL statement should conform to the ANSI standard to be
          * compatible with most relational database systems. This also
          * includes using double quotes for table and column names.
          *
          * @param string SQL statement for inserting records
          * @since 2014.03
          * @category Developer
          * @see mshop/locale/manager/site/default/item/update
          * @see mshop/locale/manager/site/default/item/delete
          * @see mshop/locale/manager/site/default/item/search
          * @see mshop/locale/manager/site/default/item/count
          * @see mshop/locale/manager/site/default/item/newid
          */
         $path = 'mshop/locale/manager/site/default/item/insert';
         $stmt = $this->_getCachedStatement($conn, $path);
         $stmt->bind(1, $item->getCode());
         $stmt->bind(2, $item->getLabel());
         $stmt->bind(3, json_encode($item->getConfig()));
         $stmt->bind(4, $item->getStatus(), MW_DB_Statement_Abstract::PARAM_INT);
         $stmt->bind(5, 0, MW_DB_Statement_Abstract::PARAM_INT);
         $stmt->bind(6, $context->getEditor());
         $stmt->bind(7, $date);
         // mtime
         $stmt->bind(8, $date);
         // ctime
         $stmt->execute()->finish();
         /** mshop/locale/manager/site/default/item/newid
          * Retrieves the ID generated by the database when inserting a new record
          *
          * As soon as a new record is inserted into the database table,
          * the database server generates a new and unique identifier for
          * that record. This ID can be used for retrieving, updating and
          * deleting that specific record from the table again.
          *
          * For MySQL:
          *  SELECT LAST_INSERT_ID()
          * For PostgreSQL:
          *  SELECT currval('seq_matt_id')
          * For SQL Server:
          *  SELECT SCOPE_IDENTITY()
          * For Oracle:
          *  SELECT "seq_matt_id".CURRVAL FROM DUAL
          *
          * There's no way to retrive the new ID by a SQL statements that
          * fits for most database servers as they implement their own
          * specific way.
          *
          * @param string SQL statement for retrieving the last inserted record ID
          * @since 2014.03
          * @category Developer
          * @see mshop/locale/manager/site/default/item/insert
          * @see mshop/locale/manager/site/default/item/update
          * @see mshop/locale/manager/site/default/item/delete
          * @see mshop/locale/manager/site/default/item/search
          * @see mshop/locale/manager/site/default/item/count
          */
         $path = 'mshop/locale/manager/default/item/newid';
         $item->setId($this->_newId($conn, $context->getConfig()->get($path, $path)));
         $dbm->release($conn, $dbname);
     } catch (Exception $e) {
         $dbm->release($conn, $dbname);
         throw $e;
     }
 }
コード例 #2
0
ファイル: Default.php プロジェクト: arcavias/arcavias-core
 /**
  * Adds a new item object.
  *
  * @param MShop_Locale_Item_Site_Interface $item Item which should be inserted
  * @param integer $parentId ID of the parent item where the item should be inserted into
  * @param integer $refId ID of the item where the item should be inserted before (null to append)
  */
 public function insertItem(MShop_Locale_Item_Site_Interface $item, $parentId = null, $refId = null)
 {
     $context = $this->_getContext();
     $dbm = $context->getDatabaseManager();
     $dbname = $this->_getResourceName();
     $conn = $dbm->acquire($dbname);
     try {
         $curdate = date('Y-m-d H:i:s');
         $path = 'mshop/locale/manager/site/default/item/insert';
         $stmt = $this->_getCachedStatement($conn, $path);
         $stmt->bind(1, $item->getCode(), MW_DB_Statement_Abstract::PARAM_STR);
         $stmt->bind(2, $item->getLabel(), MW_DB_Statement_Abstract::PARAM_STR);
         $stmt->bind(3, json_encode($item->getConfig()), MW_DB_Statement_Abstract::PARAM_STR);
         $stmt->bind(4, $item->getStatus(), MW_DB_Statement_Abstract::PARAM_INT);
         $stmt->bind(5, 0, MW_DB_Statement_Abstract::PARAM_INT);
         $stmt->bind(6, $context->getEditor());
         $stmt->bind(7, $curdate);
         // mtime
         $stmt->bind(8, $curdate);
         // ctime
         $stmt->execute()->finish();
         $path = 'mshop/locale/manager/default/item/newid';
         $item->setId($this->_newId($conn, $context->getConfig()->get($path, $path)));
         $dbm->release($conn, $dbname);
     } catch (Exception $e) {
         $dbm->release($conn, $dbname);
         throw $e;
     }
 }