Merge "rdbms: rename DB server index parameter to LoadBalancer::getMaintenanceConnect...
[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 * @suppress PhanTypeMagicVoidWithReturn
11 */
12 public function __construct( $data ) {
13 if ( $data instanceof MssqlBlob ) {
14 return $data;
15 } elseif ( $data instanceof Blob ) {
16 $this->data = $data->fetch();
17 } elseif ( is_array( $data ) && is_object( $data ) ) {
18 $this->data = serialize( $data );
19 } else {
20 $this->data = $data;
21 }
22 }
23
24 /**
25 * Returns an unquoted hex representation of a binary string
26 * for insertion into varbinary-type fields
27 * @return string
28 */
29 public function fetch() {
30 if ( $this->data === null ) {
31 return 'null';
32 }
33
34 $ret = '0x';
35 $dataLength = strlen( $this->data );
36 for ( $i = 0; $i < $dataLength; $i++ ) {
37 $ret .= bin2hex( pack( 'C', ord( $this->data[$i] ) ) );
38 }
39
40 return $ret;
41 }
42 }