/** * * @param string $sql * @param array $array * @return PDOStatement */ protected function getDBStatement($sql, $array = null) { if ($array) { list($sql, $array) = SQLBind::parseSQL($this->_connectionManagement, $sql, $array); $stmt = $this->_db->prepare($sql); foreach ($array as $key => $value) { $stmt->bindValue(":" . SQLBind::keyAdj($key), $value); } } else { $stmt = $this->_db->prepare($sql); } return $stmt; }
/** * Transform generic parameters [[PARAM]] in a parameter recognized by the provider name based on current DbParameter array. * * @param ConnectionManagement $connData * @param string $sql * @param array $params * @return array An array with the adjusted SQL and PARAMs */ public static function parseSQL(ConnectionManagement $connData, $sql, $params = null) { if (is_null($params)) { return $sql; } $paramSubstName = SQLBind::getParamModel($connData); foreach ($params as $key => $value) { $arg = str_replace("_", SQLBind::keyAdj($key), $paramSubstName); $count = 0; $sql = preg_replace("/(\\[\\[{$key}\\]\\]|:" . $key . "[\\s\\W]|:{$key}\$)/", $arg . ' ', $sql, -1, $count); if ($count === 0) { unset($params[$key]); } } $sql = preg_replace("/\\[\\[(.*?)\\]\\]/", "null", $sql); return array($sql, $params); }
protected function getSQLRelayCursor($sql, $array = null) { $cur = sqlrcur_alloc($this->_conn); if ($array) { list($sql, $array) = SQLBind::parseSQL($this->_connectionManagement, $sql, $array); sqlrcur_prepareQuery($cur, $sql); $bindCount = 1; foreach ($array as $key => $value) { $field = strval($bindCount++); sqlrcur_inputBind($cur, $field, $value); } $success = sqlrcur_executeQuery($cur); sqlrcon_endSession($this->_conn); } else { $success = sqlrcur_sendQuery($cur, $sql); sqlrcon_endSession($this->_conn); } if (!$success) { throw new DatasetException(sqlrcur_errorMessage($cur)); } sqlrcur_lowerCaseColumnNames($cur); return $cur; }
protected function getOci8Cursor($sql, $array = null) { list($query, $array) = SQLBind::parseSQL($this->_connectionManagement, $sql, $array); // Prepare the statement $stid = oci_parse($this->_conn, $query); if (!$stid) { $e = oci_error($this->_conn); throw new DatabaseException($e['message']); } // Bind the parameters if (is_array($array)) { foreach ($array as $key => $value) { oci_bind_by_name($stid, ":{$key}", $value); } } // Perform the logic of the query $r = oci_execute($stid, $this->_transaction); // Check if is OK; if (!$r) { $e = oci_error($stid); throw new DatabaseException($e['message']); } return $stid; }