/usr/share/php/propel/adapter/DBSQLSRV.php is in php-propel-runtime 1.6.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | <?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* This is used to connect to a MSSQL database using pdo_sqlsrv driver.
*
* @author Benjamin Runnels
* @version $Revision$
* @package propel.runtime.adapter
*/
class DBSQLSRV extends DBMSSQL
{
/**
* @see parent::initConnection()
*
* @param PDO $con
* @param array $settings
*/
public function initConnection(PDO $con, array $settings)
{
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$con->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
parent::initConnection($con, $settings);
}
/**
* @see parent::setCharset()
*
* @param PDO $con
* @param string $charset
*
* @throws PropelException
*/
public function setCharset(PDO $con, $charset)
{
switch (strtolower($charset)) {
case 'utf-8':
$con->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8);
break;
case 'system':
$con->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
break;
default:
throw new PropelException('only utf-8 or system encoding are supported by the pdo_sqlsrv driver');
}
}
/**
* @see parent::cleanupSQL()
*
* @param string $sql
* @param array $params
* @param Criteria $values
* @param DatabaseMap $dbMap
*/
public function cleanupSQL(&$sql, array &$params, Criteria $values, DatabaseMap $dbMap)
{
$i = 1;
foreach ($params as $param) {
$tableName = $param['table'];
$columnName = $param['column'];
$value = $param['value'];
// this is to workaround for a bug with pdo_sqlsrv inserting or updating blobs with null values
// http://social.msdn.microsoft.com/Forums/en-US/sqldriverforphp/thread/5a755bdd-41e9-45cb-9166-c9da4475bb94
if (null !== $tableName) {
$cMap = $dbMap->getTable($tableName)->getColumn($columnName);
if ($value === null && $cMap->isLob()) {
$sql = str_replace(":p$i", "CONVERT(VARBINARY(MAX), :p$i)", $sql);
}
}
$i++;
}
}
/**
* @see DBAdapter::bindValue()
*
* @param PDOStatement $stmt
* @param string $parameter
* @param mixed $value
* @param ColumnMap $cMap
* @param null|integer $position
*
* @return boolean
*/
public function bindValue(PDOStatement $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
{
if ($cMap->isTemporal()) {
$value = $this->formatTemporalValue($value, $cMap);
} elseif (is_resource($value) && $cMap->isLob()) {
// we always need to make sure that the stream is rewound, otherwise nothing will
// get written to database.
rewind($value);
// pdo_sqlsrv must have bind binaries using bindParam so that the PDO::SQLSRV_ENCODING_BINARY
// driver option can be utilized. This requires a unique blob parameter because the bindParam
// value is passed by reference and if we didn't do this then the referenced parameter value
// would change on the next loop
$blob = "blob".$position;
$$blob = $value;
return $stmt->bindParam($parameter, ${$blob}, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
}
return $stmt->bindValue($parameter, $value, $cMap->getPdoType());
}
}
|