Example #1
6
 /**
  * Tries to aquire a lock for job $id and returns, whether it was succesful.
  * 
  * @param integer $id 
  * @return bool
  */
 public function lock($id)
 {
     $this->lock = self::LOCKPREFIX . $id;
     if (!$this->lockStmt) {
         $q = $this->db->createSelectQuery();
         $q->select('GET_LOCK( ' . $q->bindParam($this->lock) . ', 0 )');
         $this->lockStmt = $q->prepare();
     }
     $this->lockStmt->execute();
     $result = $this->lockStmt->fetchColumn();
     if ('1' === $result) {
         return TRUE;
     }
     if ('0' === $result) {
         $this->lock = null;
         return FALSE;
     }
     throw new Exception($result);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getExchangeRate($sourceCurrencyCode, $targetCurrencyCode)
 {
     $this->statement->execute([$sourceCurrencyCode, $targetCurrencyCode]);
     $exchangeRate = $this->statement->fetchColumn();
     if ($exchangeRate === false) {
         throw CurrencyConversionException::exchangeRateNotAvailable($sourceCurrencyCode, $targetCurrencyCode);
     }
     return $exchangeRate;
 }
Example #3
0
 /** SELECT FOUND_ROWS() after query with SQL_CALC_FOUND_ROWS
  * @return int
  */
 public function found_rows()
 {
     if (is_null($this->_fr_stmt)) {
         $this->_fr_stmt = $this->prepare('SELECT FOUND_ROWS();');
     }
     $this->_fr_stmt->execute();
     $rows_count = $this->_fr_stmt->fetchColumn(0);
     $this->_fr_stmt->closeCursor();
     return $rows_count;
 }
Example #4
0
 /**
  * Get value from table row
  *
  * @param string      $sql    SQL-query
  * @param array       $params Query values
  * @param string|null $types  Placeholders types
  *
  * @return mixed
  */
 public function value($sql, array $params, $types)
 {
     $result = '';
     try {
         $this->prepare($sql, $params, $types);
         $result = $this->stmt->fetchColumn();
     } catch (\PDOException $e) {
         $this->throwExceptionWithInfo($sql, $params, $e);
     }
     return $result;
 }
 /**
  * For every tile needed, this function will be called
  *
  * Return the blob of this image
  * @param Tile $tile
  * @throws TileNotAvailableException
  * @return string Blob of this image
  */
 public function getTile(Tile $tile)
 {
     $this->tile_fetcher->bindValue(':x', $tile->x);
     $this->tile_fetcher->bindValue(':y', $tile->y);
     $this->tile_fetcher->execute();
     $tile_data = $this->tile_fetcher->fetchColumn();
     if ($tile_data === false) {
         throw new TileNotAvailableException();
     }
     return $tile_data;
 }
Example #6
0
 /**
  * 获取单个属性值
  * 由于该方法会造成安全问题,所以不建议使用。在必须使用的场合,需要程序人员对sql语句做严格验证
  * @param string $sql 预处理执行的sql
  * @param array $data 符合pdo预处理模式键值对
  * @return string
  * @deprecated since version 108
  */
 public function fetchOne($sql, $data = null)
 {
     $this->execute($sql, $data);
     $data = $this->stmt instanceof \PDOStatement ? $this->stmt->fetchColumn() : FALSE;
     $this->stmt = null;
     return $data;
 }
Example #7
0
 /**
  * Get result data.
  * @param int The row number from the result that's being retrieved. Row numbers start at 0.
  * @param int The offset of the field being retrieved.
  * @return array|false The contents of one cell from a MySQL result set on success, or false on failure.
  */
 public function query_result($row, $field = 0)
 {
     if ($row > 1) {
         $this->result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT, $row);
     }
     return $this->result->fetchColumn($field);
 }
Example #8
0
	/**
	 * Fetches ony column only
	 * 
	 * If rows have already been fetched, this method will throw an exception.
	 * Once used, you cannot use other fetch methods.
	 * 
	 * @param int $columnIndex
	 * @return mixed
	 */
	public function fetchColumn($columnIndex = 0)
	{
		$this->_index++;
		
		if (isset($this->_rows[$this->_index])) {
			return $this->_rows[$this->_index];
		}
		
		if ($this->_statement !== null) {
			if (!$this->_fetchColumnLock && count($this->_rows)) {
				throw new Atomik_Db_Query_Exception('Atomik_Db_Query_Result cannot fetch only columns when full rows have already been fetched');
			}
			
			if (($value = $this->_statement->fetchColumn($columnIndex)) === false) {
				$this->_statement = null;
				return false;
			}
			
			$this->_fetchColumnLock = true;
			$this->_rows[$this->_index] = $value;
			return $value;
		}
		
		return false;
	}
Example #9
0
 /**
  * 通过字段编号获取单条数据的单个字段值
  * 
  * 默认获取的是第一个字段
  * 
  * @param int $columnNumber
  * @throws \HuiLib\Error\Exception
  * @return array|object
  */
 public function fetchColumn($columnNumber = 0)
 {
     if ($this->innerStatment == NULL) {
         throw new \HuiLib\Error\Exception('fetchColumn须先调用Query::query');
     }
     return $this->innerStatment->fetchColumn($columnNumber);
 }
Example #10
0
 /**
  * Получить все записи результата
  *
  * @return mixed
  */
 public function getCount()
 {
     $this->selectColumns(array('count' => 'count(*)'))->execute();
     $rez = (int) $this->_srcQueryObj->fetchColumn();
     $this->clearParamsQuery();
     return $rez;
 }
Example #11
0
 /**
  * @return string|null
  */
 public function findColumn()
 {
     if ($this->execute()) {
         return $this->statement->fetchColumn();
     }
     return null;
 }
Example #12
0
 /**
  * Returns a column from all rows of the resultset.
  *
  * @param int $columnNumber   The number of the column in the row (zero indexed).
  *
  * @return array   A simple 1 dimension array which stores the required columns value from every row.
  */
 public function fetchColumnAll($columnNumber = 0)
 {
     $result = array();
     while (($columnValue = $this->statement->fetchColumn($columnNumber)) !== false) {
         $result[] = $columnValue;
     }
     return $result;
 }
 /**
  * 从下一行记录中获得下标是$index的值,如果获取失败则返回false
  * 
  * @param int $index 列下标
  * @return string|bool
  */
 public function fetchColumn($index = 0)
 {
     $result = $this->_statement->fetchColumn($index);
     if (WIND_DEBUG & 2) {
         Wind::getApp()->getComponent('windLogger')->info("[component.db.WindResultSet.fetchColumn] \r\n\tResult:" . WindString::varToString($result));
     }
     return $result;
 }
Example #14
0
 /**
  * Returns a single column from a row in the current pdo select
  * statement. The pointer is then advanced to the next row. Returns null
  * when reaching the end of the result stack.
  *
  * The default column returned is the first. The column number may be changed
  * to return a different column result.
  *
  * @param integer $column
  * @return string
  */
 public function fetchColumn($column = 0)
 {
     $this->checkStatement();
     $result = $this->pdo_statement->fetchColumn($column);
     if (empty($result)) {
         $this->clearStatement();
     }
     return $result;
 }
Example #15
0
 /**
  * Returns a single column from the next row of a result set.
  *
  * @param int $col OPTIONAL Position of the column to fetch.
  * @return string
  * @throws Zend_Db_Statement_Exception
  */
 public function fetchColumn($col = 0)
 {
     try {
         return $this->_stmt->fetchColumn($col);
     } catch (PDOException $e) {
         require_once 'Zend/Db/Statement/Exception.php';
         throw new Zend_Db_Statement_Exception($e->getMessage());
     }
 }
Example #16
0
 /**
  * Fetch one value and close the cursor.  e.g. SELECT MAX(foo) FROM bar
  *
  * Execute the query, if necessary.  Typically when there are no parameters.
  *
  * @return string|null
  */
 public function fetchOne()
 {
     if (!$this->executed) {
         $this->execute();
     }
     $value = $this->pdo_statement->fetchColumn();
     $this->closeCursor();
     return $value === false ? null : $value;
 }
Example #17
0
 /**
  * Return the value from a single column of the current result row.
  *
  * @param int $col 0-indexed number of the column to return.
  * @return mixed
  */
 public function fetchColumn($col = 0)
 {
     if (!is_int($col)) {
         settype($col, 'int');
     }
     try {
         return $this->_stmt->fetchColumn($col);
     } catch (PDOException $e) {
         throw new DBALite_Exception("Error fetching column {$col} from current row", $e);
     }
 }
 /**
  * Returns the mapping value for the shopware id
  *
  * @param $shopwareID $plentyID
  * @throws PlentymarketsMappingExceptionNotExistant
  * @return integer
  */
 public function getByShopwareID($shopwareID)
 {
     if (array_key_exists($shopwareID, $this->cacheByShopwareID)) {
         return $this->cacheByShopwareID[$shopwareID];
     }
     $this->StatementGetByShopwareID->execute(array($shopwareID));
     $plentyID = $this->StatementGetByShopwareID->fetchColumn(0);
     if ($plentyID === false) {
         throw new PlentymarketsMappingExceptionNotExistant(get_class($this) . '-shopwareId:' . $shopwareID);
     }
     $this->setCache($shopwareID, $plentyID);
     return $plentyID;
 }
Example #19
0
 /**
  * Unlock
  *
  * @return boolean
  */
 public function unlock()
 {
     if ($this->isLocked) {
         if (!$this->stmtReleaseLock instanceof \PDOStatement) {
             $pdo = $this->getConnection();
             $this->stmtReleaseLock = $pdo->prepare('SELECT RELEASE_LOCK(?)');
         }
         $this->isLocked = false;
         $this->stmtReleaseLock->execute(array($this->name));
         return $this->stmtReleaseLock->fetchColumn() == 1;
     }
     return false;
 }
Example #20
0
 /**
  * Checks if the login attempt is ready to be processed, and updates the
  * last_checked timestamp to keep the attempt alive.
  *
  * @return bool
  */
 private function isReady()
 {
     if (!$this->readyCheckStatement) {
         $sql = "SELECT id FROM login_attempt_queue\r\n                    WHERE\r\n                        last_checked > NOW() - INTERVAL ? MICROSECOND AND\r\n                        username = ?\r\n                    ORDER BY id ASC\r\n                    LIMIT 1";
         $this->readyCheckStatement = $this->pdo->prepare($sql);
     }
     $this->readyCheckStatement->execute(array(self::ATTEMPT_EXPIRATION_TIMEOUT * 1000, $this->username));
     $result = (int) $this->readyCheckStatement->fetchColumn();
     if (!$this->checkUpdateStatement) {
         $sql = "UPDATE login_attempt_queue\r\n                    SET last_checked = CURRENT_TIMESTAMP\r\n                    WHERE id = ? LIMIT 1";
         $this->checkUpdateStatement = $this->pdo->prepare($sql);
     }
     $this->checkUpdateStatement->execute(array($this->attemptID));
     return $result === $this->attemptID;
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 public function fetchNextColumn($column)
 {
     if ($this->stmt === NULL) {
         return false;
     }
     $transform = !empty($this->computed[$column]) || !empty($this->transformed[$column]);
     if (!$transform && is_integer($column)) {
         return $this->stmt->fetchColumn($column);
     }
     $style = is_integer($column) ? DB::FETCH_NUM : DB::FETCH_ASSOC;
     if (false === ($row = $this->fetchNextRow($style))) {
         return false;
     }
     return $row[$column];
 }
 /**
  * @param cfhCompile_Class_Interface $class
  * @return Integer
  */
 protected function getClassId(cfhCompile_Class_Interface $class)
 {
     $fileId = $this->getFileId($class);
     $this->stmtClassSelect->bindValue(':class_name', $class->getName(), PDO::PARAM_STR);
     $this->stmtClassSelect->bindValue(':file_id', $fileId, PDO::PARAM_INT);
     $this->stmtClassSelect->execute();
     $id = $this->stmtClassSelect->fetchColumn();
     $this->stmtClassSelect->closeCursor();
     if (!$id) {
         $this->stmtClassInsert->bindValue(':class_name', $class->getName(), PDO::PARAM_STR);
         $this->stmtClassInsert->bindValue(':file_id', $fileId, PDO::PARAM_INT);
         $this->stmtClassInsert->execute();
         $id = $this->dbh->lastInsertId();
     }
     return $id;
 }
Example #23
0
 /**
  * Fetch the first column of a specific row
  *
  * @param \PDOStatement $statement
  * @param int $row
  * @return mixed
  */
 public function fetchFirstColumn($statement, $row = 0)
 {
     //seek
     for ($i = 0; $i < $row; $i++) {
         $statement->fetchColumn();
     }
     //returns false when an error occurs
     return $statement->fetchColumn();
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function fetchColumn($columnIndex = 0)
 {
     try {
         return parent::fetchColumn($columnIndex);
     } catch (\PDOException $exception) {
         throw new PDOException($exception);
     }
 }
 public function getRow()
 {
     return $this->statement->fetchColumn(0);
 }
Example #26
0
 public static function get_field(\PDOStatement $stmt, $fieldIndex = 0, $getAsType = null)
 {
     $value = $stmt->fetchColumn($fieldIndex);
     // NOTE: AFAIK, there's no way to get any field to come out as anything but a string. So for now, we'll assume string.
     // TODO:get_field() - test to see what happens when asking for a non-convertable value
     switch ($getAsType) {
         case self::PHPTYPE_INT:
             return (int) $value;
         case self::PHPTYPE_FLOAT:
             return (double) $value;
         case self::PHPTYPE_DATETIME:
             // TODO:get_field() - test this especially.
             return date_create($value) || new DateTime();
         case self::PHPTYPE_STRING(self::ENC_BINARY):
             return base64_encode($value);
         case self::PHPTYPE_STRING(self::ENC_CHAR):
             return "{$value}";
         case self::PHPTYPE_STREAM(self::ENC_BINARY):
             $value = base64_encode($value);
             return fopen("data://base64,{$value}", 'r+');
         case self::PHPTYPE_STREAM(self::ENC_CHAR):
             return fopen("data://text/plain,{$value}", 'r+');
         case self::PHPTYPE_NULL:
             return null;
         default:
     }
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function fetchColumn($columnIndex = 0)
 {
     return parent::fetchColumn($columnIndex);
 }
Example #28
0
 /**
  * Overwrite. Fixes HHVM strict issue.
  */
 public function fetchColumn($column_number = 0)
 {
     return parent::fetchColumn($column_number);
 }
Example #29
0
 /**
  * Provide a simple fetchOne.
  * fetch single column from the next row
  * @param int $colnum the column number to fetch
  */
 public function fetchOne($colnum = 0)
 {
     return $this->statement->fetchColumn($colnum);
 }
 /**
  * 获取单列返回
  *
  * @access public
  * @param int $column_num 列号
  * @return string $column 数据列
  */
 public function fetch_column($column_num = 0)
 {
     return parent::fetchColumn($column_num);
 }