Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / includes / libs / rdbms / encasing / MssqlBlob.php
1 <?php
2
3 namespace Wikimedia\Rdbms;
4
5 class MssqlBlob extends Blob {
6 /** @noinspection PhpMissingParentConstructorInspection */
7
8 /**
9 * @param string $data
10 */
11 public function __construct( $data ) {
12 if ( $data instanceof MssqlBlob ) {
13 return $data;
14 } elseif ( $data instanceof Blob ) {
15 $this->data = $data->fetch();
16 } elseif ( is_array( $data ) && is_object( $data ) ) {
17 $this->data = serialize( $data );
18 } else {
19 $this->data = $data;
20 }
21 }
22
23 /**
24 * Returns an unquoted hex representation of a binary string
25 * for insertion into varbinary-type fields
26 * @return string
27 */
28 public function fetch() {
29 if ( $this->data === null ) {
30 return 'null';
31 }
32
33 $ret = '0x';
34 $dataLength = strlen( $this->data );
35 for ( $i = 0; $i < $dataLength; $i++ ) {
36 $ret .= bin2hex( pack( 'C', ord( $this->data[$i] ) ) );
37 }
38
39 return $ret;
40 }
41 }