public function dispose() { if (!$this->is_disposed) { $this->statement->closeCursor(); $this->is_disposed = true; } }
/** * Free memory associated with the resultset * * @return void */ public function flush() { if ($this->result instanceof PDOStatement) { $this->result->closeCursor(); } $this->result = null; $this->col_info = null; $this->fetched_rows = array(); }
/** 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; }
public function fetch() { $this->executeQuery(); if ($this->fetchResults === null) { $this->fetchResults = $this->statement->fetchAll(PDO::FETCH_ASSOC); $this->statement->closeCursor(); } if (array_key_exists($this->currentFetchIndex, $this->fetchResults) && $this->fetchResults[$this->currentFetchIndex] !== null) { return $this->fetchResults[$this->currentFetchIndex++]; } return false; }
/** * Run a query against a database. Get a result * @param string $query The SQL to run against the database * @param array $args An associative array of query parameters * @return bool|\PDOStatement False if query fails, results in this database's fetch_class if successful * @throws \Exception */ public function query($query, $args = array()) { if (!empty($this->pdo_statement)) { $this->pdo_statement->closeCursor(); } if ($this->pdo_statement = $this->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true))) { $this->pdo_statement->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, $this->fetch_class, [$this]); if (!$this->pdo_statement->execute($args)) { throw new \Exception($this->pdo_statement->errorInfo()); } return true; } else { throw new \Exception($this->errorInfo()); } }
public function closeCursor() { if ($this->_statement instanceof \PDOStatement) { return $this->_statement->closeCursor(); } return false; }
/** * Close the statement handle **/ public function finish() { if ($this->sh && is_object($this->sh)) { $this->sh->closeCursor(); } unset($this->sh); }
/** * Closes the cursor, enabling the statement to be executed again. * * @return bool Returns true on success, false on failure. */ public function freeResult() { if ($this->resourceHandle === null) { return false; } $this->resourceHandle->closeCursor(); return true; }
/** * Frees the memory associated with a result. * Provides a fluent interface. * * @return PDOMySQL */ public function freeResult() { if (isset($this->result)) { $this->result->closeCursor(); unset($this->result); } return $this; }
/** * Execute a SQL statement. * * @param string $query the SQL statement * @param array $args values for the bound parameters * @return boolean true on success, false on failure */ public function query($query, $args = array()) { if ($this->pdo_statement != null) { $this->pdo_statement->closeCursor(); } // Allow plugins to modify the query $query = Plugins::filter('query', $query, $args); // Translate the query for the database engine $query = $this->sql_t($query, $args); // Replace braced table names in the query with their prefixed counterparts $query = self::filter_tables($query); // Allow plugins to modify the query after it has been processed $query = Plugins::filter('query_postprocess', $query, $args); if ($this->pdo_statement = $this->pdo->prepare($query)) { if ($this->fetch_mode == \PDO::FETCH_CLASS) { /* Try to get the result class autoloaded. */ if (!class_exists($this->fetch_class_name, true)) { $class_name = $this->fetch_class_name; // @todo This is a GIANT namespace kludge, replacing Model class names with no namespace that don't exist with a default prefixed class if (strpos($class_name, '\\') == false) { $class_name = '\\Habari\\' . $class_name; $this->fetch_class_name = $class_name; if (!class_exists($this->fetch_class_name, true)) { throw new \Exception('The model class that was specified for data retreival could not be loaded.'); } } } /* Ensure that the class is actually available now, otherwise segfault happens (if we haven't died earlier anyway). */ if (class_exists($this->fetch_class_name)) { $this->pdo_statement->setFetchMode(\PDO::FETCH_CLASS, $this->fetch_class_name, array()); } else { /* Die gracefully before the segfault occurs */ echo '<br><br>' . _t('Attempt to fetch in class mode with a non-included class') . '<br><br>'; return false; } } else { $this->pdo_statement->setFetchMode($this->fetch_mode); } /* If we are profiling, then time the query */ if ($this->keep_profile) { $profile = new QueryProfile($query); $profile->params = $args; $profile->start(); } if (!$this->pdo_statement->execute($args)) { $this->add_error(array('query' => $query, 'error' => $this->pdo_statement->errorInfo())); return false; } if ($this->keep_profile) { $profile->stop(); $this->profiles[] = $profile; } return true; } else { $this->add_error(array('query' => $query, 'error' => $this->pdo->errorInfo())); return false; } }
/** * Hook the result-set given into a Query class, suitable for use by SilverStripe. * @param PDOStatement $statement The internal PDOStatement containing the results */ public function __construct(PDOStatement $statement) { $this->statement = $statement; // Since no more than one PDOStatement for any one connection can be safely // traversed, each statement simply requests all rows at once for safety. // This could be re-engineered to call fetchAll on an as-needed basis $this->results = $statement->fetchAll(PDO::FETCH_ASSOC); $statement->closeCursor(); }
protected function reset() { if ($this->stmt != null) { $this->stmt->closeCursor(); } $this->stmt = null; $this->resultSet = null; $this->updateCount = -1; }
/** * Closes the cursor, allowing the statement to be executed again. * * @return bool * @throws Zend_Db_Statement_Exception */ public function closeCursor() { try { return $this->_stmt->closeCursor(); } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage()); } }
/** * Close the connection */ public function close() { // see: http://php.net/manual/en/pdo.connections.php#114822 if (isset($this->query)) { $this->query->closeCursor(); } $this->query = null; $this->connection = null; }
public function beginTransaction() { if ($this->transactionNestingLevel == 0 && !$this->db->inTransaction()) { if ($this->stmt) { $this->stmt->closeCursor(); } $this->db->beginTransaction(); } $this->transactionNestingLevel++; }
public function formatOne(PDOStatement $stmt) { $this->checkInit(); $result = null; while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $result = $this->getAllObjectsFromRow($row); } $stmt->closeCursor(); return $result; }
protected function cleanupResults() { $this->rows->closeCursor(); /** * Cleanup variable to free memory */ $this->gcHelper->cleanVariable($this->rows); $this->rows = null; $this->gcHelper->cleanup(); }
/** * Generate PDO error * * @param string $sql * @param \PDOStatement $statement * @return \PDOException */ protected function error($sql, \PDOStatement $statement = null) { $error = $this->pdo->errorInfo(); if (!$error[1] and $statement) { $error = $statement->errorInfo(); $statement->closeCursor(); unset($statement); } $code = is_int($error[0]) ? $error[0] : null; return new \PDOException('[' . $error[0] . '] ' . $error[2] . ', in query (' . $sql . ')', $code); }
public function formatOne(PDOStatement $stmt) { $this->checkInit(); $result = null; while ($row = $stmt->fetch(PDO::FETCH_NUM)) { if (false !== ($rowArray = $this->getStructuredArrayFromRow($row))) { $result = $rowArray; } } $stmt->closeCursor(); return $result; }
/** * Return the first row returned by a sql call * * @abstract * @param string $sql The sql to execute * @param int $returnType optional The type of data returned (default to PDO::FETCH_ASSOC) * * @return mixed[] The results */ public function getRow($sql, $returnType = \PDO::FETCH_ASSOC) { if ($this->query($sql)) { if ($this->lastPdoStatement !== false) { $record = $this->lastPdoStatement->fetch($returnType, \PDO::FETCH_ORI_FIRST); //we need to close off the query in order to allow for more query to be executed $this->lastPdoStatement->closeCursor(); return $record; } } return false; }
public function formatOne(PDOStatement $stmt) { $this->checkInit(); $result = null; while ($row = $stmt->fetch(PDO::FETCH_NUM)) { if ($object =& $this->getStructuredArrayFromRow($row)) { $result =& $object; } } $this->currentObjects = array(); $this->alreadyHydratedObjects = array(); $stmt->closeCursor(); return $result; }
/** * Polls the queue for a message. The message gets assigned the current pid. * * @param integer $pid The current process id. * * @return Message|null The assigned message, or null if the queue is empty. * * @throws \RuntimeException If an unexpected error occurs. */ public function poll($pid) { $this->executeStatement($this->assignMessageStatement, [$pid]); if ($this->assignMessageStatement->rowCount() == 0) { return null; } $this->executeStatement($this->loadMessageStatement, [$pid]); $data = $this->loadMessageStatement->fetch(\PDO::FETCH_ASSOC); $this->loadMessageStatement->closeCursor(); if ($data === false) { throw new \RuntimeException('Could not find the message just assigned.'); } $id = $data[self::ID_COLUMN_ALIAS]; unset($data[self::ID_COLUMN_ALIAS]); return new Message($id, $pid, $data); }
/** * @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; }
private function fetchOrCreatePlayerId($name) { static $playerIdCache = array(); if (isset($playerIdCache[$name])) { return $playerIdCache[$name]; } $this->fetchPlayerStmt->execute(array('name' => $name)); $playerId = $this->fetchPlayerStmt->fetch(PDO::FETCH_COLUMN); $this->fetchPlayerStmt->closeCursor(); if (!$playerId) { $this->insertPlayerStmt->execute(array('name' => $name)); $playerId = $this->db->lastInsertId(); $this->insertPlayerStmt->closeCursor(); } $playerIdCache[$name] = $playerId; return $playerIdCache[$name]; }
/** * */ public function rewindOriginal() { $this->index = 0; if (!empty($this->stmt)) { $this->stmt->closeCursor(); } $this->stmt = $this->criteria->prepare(); $tstart = microtime(true); if ($this->stmt && $this->stmt->execute()) { $this->xpdo->queryTime += microtime(true) - $tstart; $this->xpdo->executedQueries++; $this->fetch(); } elseif ($this->stmt) { $this->xpdo->queryTime += microtime(true) - $tstart; $this->xpdo->executedQueries++; } }
/** * @inheritDoc */ public function fetch() { $data = $this->pdoStatement ? $this->pdoStatement->fetch() : NULL; if (!$data) { $this->pdoStatement->closeCursor(); return FALSE; } $row = new Row(); foreach ($this->normalizeRow($data) as $key => $value) { $row->{$key} = $value; } if ($this->result === NULL && count($data) !== $this->pdoStatement->columnCount()) { trigger_error('Found duplicate columns in database result set.', E_USER_NOTICE); } $this->resultKey++; return $this->result = $row; }
/** * Adds an bunch of URLs to the url-cache * * @param array $urls A numeric array containing the URLs as PHPCrawlerURLDescriptor-objects */ public function addURLs($urls) { PHPCrawlerBenchmark::start("adding_urls_to_sqlitecache"); $this->PDO->exec("BEGIN EXCLUSIVE TRANSACTION;"); $cnt = count($urls); for ($x = 0; $x < $cnt; $x++) { if ($urls[$x] != null) { $this->addURL($urls[$x]); } } $this->PDO->exec("COMMIT;"); $this->PreparedInsertStatement->closeCursor(); if ($this->db_analyzed == false) { $this->PDO->exec("ANALYZE;"); $this->db_analyzed = true; } PHPCrawlerBenchmark::stop("adding_urls_to_sqlitecache"); }
/** * Performs a query, then returns a resultset * * @param string $action[optional] The crud action performed (select, insert, update, delete, create, alter) * * @return Resultset */ public function performQuery($action = '') { try { $values = $this->getCriteria() instanceof Criteria ? $this->getCriteria()->getValues() : array(); \TBGLogging::log('executing PDO query (' . Core::getSQLCount() . ') - ' . ($this->getCriteria() instanceof Criteria ? $this->getCriteria()->action : 'unknown'), 'B2DB'); $time = explode(' ', microtime()); $pretime = $time[1] + $time[0]; $res = $this->statement->execute($values); if (!$res) { $error = $this->statement->errorInfo(); if (Core::isDebugMode()) { $time = explode(' ', microtime()); $posttime = $time[1] + $time[0]; Core::sqlHit($this->printSQL(), implode(', ', $values), $posttime - $pretime); } throw new Exception($error[2], $this->printSQL()); } if (Core::isDebugMode()) { \TBGLogging::log('done', 'B2DB'); } if ($this->getCriteria() instanceof Criteria && $this->getCriteria()->action == 'insert') { if (Core::getDBtype() == 'mysql') { $this->insert_id = Core::getDBLink()->lastInsertId(); } elseif (Core::getDBtype() == 'pgsql') { \TBGLogging::log('sequence: ' . Core::getTablePrefix() . $this->getCriteria()->getTable()->getB2DBName() . '_id_seq', 'b2db'); $this->insert_id = Core::getDBLink()->lastInsertId(Core::getTablePrefix() . $this->getCriteria()->getTable()->getB2DBName() . '_id_seq'); \TBGLogging::log('id is: ' . $this->insert_id, 'b2db'); } } $action = $this->getCriteria() instanceof Criteria ? $this->getCriteria()->action : ''; $retval = new Resultset($this); if (Core::isDebugMode()) { $time = explode(' ', microtime()); $posttime = $time[1] + $time[0]; Core::sqlHit($this->printSQL(), implode(', ', $values), $posttime - $pretime); } if (!$this->getCriteria() || $this->getCriteria()->action != 'select') { $this->statement->closeCursor(); } return $retval; } catch (\Exception $e) { throw $e; } }
/** * The returned array will contain objects of the default type or * objects that inherit from the default. * * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function populateObjects(PDOStatement $stmt) { $typePosition = Ezer_PropelStepInstancePeer::translateFieldName(Ezer_PropelStepInstancePeer::TYPE, BasePeer::TYPE_COLNAME, BasePeer::TYPE_NUM); $results = array(); // populate the object(s) while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key = Ezer_PropelStepInstancePeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj = Ezer_PropelStepInstancePeer::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj->hydrate($row, 0, true); // rehydrate $results[] = $obj; } else { $type = $row[$typePosition]; $obj = self::newStep($type); $obj->hydrate($row); $results[] = $obj; Ezer_PropelStepInstancePeer::addInstanceToPool($obj, $key); } // if key exists } $stmt->closeCursor(); return $results; }
/** * The returned array will contain objects of the default type or * objects that inherit from the default. * * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function populateObjects(PDOStatement $stmt) { $results = array(); // set the class once to avoid overhead in the loop $cls = ExamCommentDigPeer::getOMClass(); $cls = substr('.' . $cls, strrpos('.' . $cls, '.') + 1); // populate the object(s) while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key = ExamCommentDigPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj = ExamCommentDigPeer::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj->hydrate($row, 0, true); // rehydrate $results[] = $obj; } else { $obj = new $cls(); $obj->hydrate($row); $results[] = $obj; ExamCommentDigPeer::addInstanceToPool($obj, $key); } // if key exists } $stmt->closeCursor(); return $results; }