Gets a representation of a BLOB/LONGVARBINARY value suitable for use in a SQL statement.

@param mixed $blob Blob object or string data.

@return string
516698
protected function getBlobSql($blob)
    {
        // they took magic __toString() out of PHP5.0.0; this sucks
        if (is_object($blob)) {
            return $this->getPlatform()->quote($blob->__toString());
        } else {
            return $this->getPlatform()->quote($blob);
        }
    }
356175
public function getStoreValue($data = null)
    {

        // If Overrite Value
        if (isset($this->value) && $this->overwriteValue) {
            return $this->value;
        }

        // If user have user input value
        if ($data != null && isset($data[$this->getName()])) {

            // Process the value by FieldType
            // For example, HTML5's datetime-local is unable insert into the database directly. So the DateTimeLocal have to convert it to the proper format.
            return $this->fieldType->beforeStoreValue($data[$this->getName()]);
        }

        return $this->value;
    }
1129544
public function handle($blob) {
    try {
      $reqMessage = $this->decode(StdMessage::NAME, $blob);
    }
    catch (InvalidMessageException $e) {
      $this->log->debug('Received invalid message', array(
        'exception' => $e,
      ));
      $resp = new InsecureMessage(array(
        'is_error' => 1,
        'error_message' => 'Invalid message coding',
        array(
          $e->getMessage(),
          $e->getTraceAsString(),
        ),
      ));
      return $resp->setCode(400);
    }

    $cxn = $this->cxnStore->getByCxnId($reqMessage->getCxnId());
    $validation = Cxn::getValidationMessages($cxn);
    if (!empty($validation)) {
      $this->log->error('Invalid cxn ({cxnId})', array(
        'cxnId' => $reqMessage->getCxnId(),
        'messages' => $validation,
      ));
      // $cxn is not valid, so we can't encode it use it for encoding.
      $resp = new InsecureMessage(array(
        'is_error' => 1,
        'error_message' => 'Invalid cxn details: ' . implode(', ', array_keys($validation)),
      ));
      return $resp->setCode(400);
    }

    try {
      list ($entity, $action, $params, $appCert) = $reqMessage->getData();
      if ($this->certValidator) {
        $this->certValidator->validateCert($appCert);
        $appCertObj = X509Util::loadCert($appCert);
        $cn = $appCertObj->getDNProp('CN');
        if (count($cn) != 1 || $cn[0] !== $cxn['appId']) {
          throw new InvalidMessageException('Invalid message: Submitted certificate does not matched expected appId');
        }
      }
      $respData = call_user_func($this->router, $cxn, $entity, $action, $params);
      $this->log->info('Processed API call ({entity}.{action})', array(
        'entity' => $entity,
        'action' => $action,
      ));
    }
    catch (\Exception $e) {
      $this->log->error('Error executing API call', array(
        'request' => $reqMessage->getData(),
        'exception' => $e,
      ));
      $respData = array(
        'is_error' => 1,
        'error_message' => $e->getMessage(),
      );
    }

    return new StdMessage($reqMessage->getCxnId(), $cxn['secret'], $respData);
  }
1288667
public static function blob2blob($file_id)
    {
        global $CFG, $PDOX;

        if ( isset($CFG->dataroot) && strlen($CFG->dataroot) > 0 ) return;

        // Need to deal with the post 2018-02 situation where we don't even
        // have a content column in blob_file
        try {
            $stmt = $PDOX->prepare("SELECT file_sha256
                FROM {$CFG->dbprefix}blob_file
                WHERE blob_id IS NULL AND path IS NULL AND content IS NOT NULL AND file_id = :ID");
            $stmt->execute(array(':ID' => $file_id));
            $row = $stmt->fetch(\PDO::FETCH_ASSOC);
            if ( ! $row ) return false;
        } catch(\Exception $e) { // No column for old blobs
            // error_log("Content column is not present in blob_file");
            return false;
        }

        $file_sha256 = $row['file_sha256'];

        // Do we already have it in blob_blob?
        $stmt = $PDOX->prepare("SELECT blob_id FROM {$CFG->dbprefix}blob_blob WHERE blob_sha256 = :SHA");
        $stmt->execute(array(":SHA" => $file_sha256));
        $row = $stmt->fetch(\PDO::FETCH_ASSOC);
        if ( $row ) {
            $blob_id = $row['blob_id'];
            $stmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
                SET content=NULL, blob_id=:BID WHERE file_id = :ID");
            $stmt->execute(array(':BID' => $blob_id, ':ID' => $file_id));
            error_log("Migration fid=$file_id to existing blob_blob row $blob_id sha=$file_sha256");
            return true;
        }
        // error_log("No row for $file_sha256");

        $lob = false;
        $stmt = $PDOX->prepare("SELECT content FROM {$CFG->dbprefix}blob_file WHERE file_id = :ID");
        $stmt->execute(array(":ID" => $file_id));
        $stmt->bindColumn(1, $lob, \PDO::PARAM_LOB);
        $stmt->fetch(\PDO::FETCH_BOUND);

        if ( ! is_string($lob) ) {
            $retval = "Error: LOB is not string fid=$file_id sha=$file_sha256";
            error_log($retval);
            return $retval;
        }
        // error_log("Lob size=".strlen($lob));

        $stmt = $PDOX->prepare("INSERT INTO {$CFG->dbprefix}blob_blob
            (blob_sha256, content, created_at)
            VALUES (?, ?, NOW())");
        $stmt->bindParam(1, $file_sha256);
        $stmt->bindParam(2, $lob, \PDO::PARAM_STR);
        // $stmt->bindParam(2, $fp, \PDO::PARAM_LOB);
        $PDOX->beginTransaction();
        $stmt->execute();
        $blob_id = 0+$PDOX->lastInsertId();
        $PDOX->commit();

        // Check if it made it...
        $stmt = $PDOX->prepare("SELECT blob_id FROM {$CFG->dbprefix}blob_blob WHERE blob_sha256 = :SHA");
        $stmt->execute(array(":SHA" => $file_sha256));
        $row = $stmt->fetch(\PDO::FETCH_ASSOC);
        if ( $row ) {
            $blob_id = $row['blob_id'];
            $stmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
                SET content=NULL, blob_id=:BID WHERE file_id = :ID");
            $stmt->execute(array(':BID' => $blob_id, ':ID' => $file_id));
            error_log("Migration fid=$file_id to new blob_blob row $blob_id sha=$file_sha256");
            return true;
        }

        // Bummer if this happens - doubtful but worth double checking.
        $retval = "Error: Could not find new blob_id=$blob_id for file_id=$file_id sha=$file_sha256";
        error_log($retval);
        return $retval;
    }
1243774
public static function glob_to_regex($glob)
  {
    $first_byte = true;
    $escaping = false;
    $in_curlies = 0;
    $regex = '';
    for ($i = 0; $i < strlen($glob); $i++)
    {
      $car = $glob[$i];
      if ($first_byte)
      {
        if (self::$strict_leading_dot && $car != '.')
        {
          $regex .= '(?=[^\.])';
        }

        $first_byte = false;
      }

      if ($car == '/')
      {
        $first_byte = true;
      }

      if ($car == '.' || $car == '(' || $car == ')' || $car == '|' || $car == '+' || $car == '^' || $car == '$')
      {
        $regex .= "\\$car";
      }
      else if ($car == '*')
      {
        $regex .= ($escaping ? "\\*" : (self::$strict_wildcard_slash ? "[^/]*" : ".*"));
      }
      else if ($car == '?')
      {
        $regex .= ($escaping ? "\\?" : (self::$strict_wildcard_slash ? "[^/]" : "."));
      }
      else if ($car == '{')
      {
        $regex .= ($escaping ? "\\{" : "(");
        if (!$escaping) ++$in_curlies;
      }
      else if ($car == '}' && $in_curlies)
      {
        $regex .= ($escaping ? "}" : ")");
        if (!$escaping) --$in_curlies;
      }
      else if ($car == ',' && $in_curlies)
      {
        $regex .= ($escaping ? "," : "|");
      }
      else if ($car == "\\")
      {
        if ($escaping)
        {
          $regex .= "\\\\";
          $escaping = false;
        }
        else
        {
          $escaping = true;
        }

        continue;
      }
      else
      {
        $regex .= $car;
        $escaping = false;
      }
      $escaping = false;
    }

    return "#^$regex$#";
  }
165515
@Override
    public byte[] getBinaryValue(Base64Variant b64variant) throws IOException {
        Object n = currentNode();
        if (n instanceof byte[]) {
            return (byte[]) n;
        } else if (n instanceof org.bson.types.ObjectId) {
            return ((org.bson.types.ObjectId) n).toByteArray();
        }
        return null;
    }

    @Override
    public Object getEmbeddedObject() throws IOException, JsonParseException {
        return currentNode();
    }

    /*
   /**********************************************************
   /* Internal methods
   /**********************************************************
    */

    protected Object currentNode() {
        if (closed || nodeCursor == null) {
            return null;
        }
        return nodeCursor.currentNode();
    }
975609
public String getSQLType(boolean bIncludeLength, Map<String, Object> properties) 
    {
        String strType = (String)properties.get(DBSQLTypes.BOOLEAN);
        if (strType == null)
            strType = DBSQLTypes.BYTE;      // The default SQL Type (Byte)
        return strType;
    }
376536
public static function formatDataSizeFromBytes(int $b): string
    {
        $unit = '';
        foreach (['B', 'KB', 'MB', 'GB', 'TB'] as $unit) {
            if ($b < 1024) break;
            $b = round($b / 1024, 1);
        }

        return $b . ' ' . $unit;
    }
854998
protected function getColumnSQL(\SimpleXMLElement $field)
	{
		// TODO Incorporate into parent class and use $this.
		$blobs = array('text', 'smalltext', 'mediumtext', 'largetext');

		$fName = (string) $field['Field'];
		$fType = (string) $field['Type'];
		$fNull = (string) $field['Null'];
		$fDefault = (isset($field['Default']) && $field['Default'] != 'NULL' ) ?
					preg_match('/^[0-9]$/', $field['Default']) ? $field['Default'] : $this->db->quote((string) $field['Default'])
					: null;

		// Note, nextval() as default value means that type field is serial.
		if (strpos($fDefault, 'nextval') !== false)
		{
			$sql = $this->db->quoteName($fName) . ' SERIAL';
		}
		else
		{
			$sql = $this->db->quoteName($fName) . ' ' . $fType;

			if ($fNull == 'NO')
			{
				if (in_array($fType, $blobs) || $fDefault === null)
				{
					$sql .= ' NOT NULL';
				}
				else
				{
					$sql .= ' NOT NULL DEFAULT ' . $fDefault;
				}
			}
			else
			{
				if ($fDefault !== null)
				{
					$sql .= ' DEFAULT ' . $fDefault;
				}
			}
		}

		return $sql;
	}
599172
public static Object convertBlob(Object blob, String value) throws SQLException {
        return convertBlob(blob, value.getBytes());
    }
475816
public Blob getBlob(int arg0) throws SQLException {
        try {
            Blob blob = rsetImpl.getBlob(arg0); 
            if (blob != null && freeResourcesOnClose)
                blobs.add(blob); 
            return blob; 
        } catch (SQLException ex) {
            FFDCFilter.processException(ex, "com.ibm.ws.rsadapter.jdbc.WSJdbcResultSet.getBlob", "754", this);
            throw WSJdbcUtil.mapException(this, ex);
        } catch (NullPointerException nullX) {
            // No FFDC code needed; we might be closed.
            throw runtimeXIfNotClosed(nullX);
        }
    }
354776
function read($inByte = null)
    {
        if ($this->getSegmentLimit() == -1)
            return $this->_t__wrap_stream->read($inByte);


        $inByte = ($inByte === null)
            ? (
                ($this->getBuffer() === null) ? $this->getSize() : $this->getBuffer()

            ) : $inByte;

        $remain = $this->getSegmentLimit() - $this->getCurrOffset();
        if ($remain > 0)
            return $this->_t__wrap_stream->read(min($remain, $inByte));

        return '';
    }
404166
public function parseBinaryString()
    {
        $this->uniqueTable = array();
        $this->countObjects = 0;
        $this->stringSize = 0;
        $this->intSize = 0;
        $this->miscSize = 0;
        $this->objectRefs = 0;

        $this->writtenObjectCount = 0;
        $this->objectTable = array();
        $this->objectRefSize = 0;

        $this->offsets = array();

        // first, we read the trailer: 32 byte from the end
        $buff = substr($this->content, -32);

        if (strlen($buff) < 32) {
            throw new PListException('Error in PList format: content is less than at least necessary 32 bytes!');
        }

        $infos = unpack("x6/Coffset_size/Cobject_ref_size/x4/Nnumber_of_objects/x4/Ntop_object/x4/Ntable_offset", $buff);

        // after that, get the offset table
        $coded_offset_table = substr($this->content, $infos['table_offset'], $infos['number_of_objects'] * $infos['offset_size']);
        if (strlen($coded_offset_table) != $infos['number_of_objects'] * $infos['offset_size']) {
            throw IOException::readError("");
        }
        $this->countObjects = $infos['number_of_objects'];

        // decode offset table
        $formats = array("","C*","n*",null,"N*");
        if ($infos['offset_size'] == 3) {
            /* since PHP does not support parenthesis in pack/unpack expressions,
               "(H6)*" does not work and we have to work round this by repeating the
               expression as often as it fits in the string
             */
            $this->offsets = array(null);
            while ($coded_offset_table) {
                $str = unpack("H6", $coded_offset_table);
                $this->offsets[] = hexdec($str[1]);
                $coded_offset_table = substr($coded_offset_table, 3);
            }
        } else {
            $this->offsets = unpack($formats[$infos['offset_size']], $coded_offset_table);
        }

        $this->uniqueTable = array();
        $this->objectRefSize = $infos['object_ref_size'];

        $top = $this->readBinaryObjectAt($infos['top_object']+1);
        $this->add($top);
    }
1236835
public function getImgDataBase64($string, $size = 128, $color = '', $bg = '')
    {
        return sprintf('data:%s;base64,%s', $this->_instance->mineType, base64_encode($this->getImgData($string, $size, $color, $bg)));
    }
19912
public function get_sql( $sql ) {

		global $wpdb;

		if ( empty( $sql ) ) {
			$sql = $this->sql;
		}

		/**
		 * Allow SQL query to be manipulated.
		 *
		 * @param string   $sql       SQL Query string.
		 * @param PodsData $pods_data PodsData object.
		 *
		 * @since 2.7.0
		 */
		$sql = apply_filters( 'pods_data_get_sql', $sql, $this );

		$sql = str_replace( array( '@wp_users', '@wp_' ), array( $wpdb->users, $wpdb->prefix ), $sql );

		$sql = str_replace( '{prefix}', '@wp_', $sql );
		$sql = str_replace( '{/prefix/}', '{prefix}', $sql );

		return $sql;
	}
323745
public function getPDOParamType($phpType)
    {
        switch ($phpType) {
            case 'boolean':
                return PDO::PARAM_BOOL;
            case 'NULL':
                return PDO::PARAM_NULL;
            case 'integer':
                return PDO::PARAM_INT;
            case 'object': // Allowed if the object or resource has a __toString method
            case 'resource':
            case 'float': // Not actually returnable from get_type
            case 'double':
            case 'string':
                return PDO::PARAM_STR;
            case 'blob':
                return PDO::PARAM_LOB;
            case 'array':
            case 'unknown type':
            default:
                throw new InvalidArgumentException("Cannot bind parameter as it is an unsupported type ($phpType)");
        }
    }
181480
public function handle($blob) {
    try {
      $reqData = $this->decode(RegistrationMessage::NAME, $blob);
    }
    catch (InvalidMessageException $e) {
      $this->log->warning('Received invalid message', array(
        'exception' => $e,
      ));
      $resp = new InsecureMessage(array(
        'is_error' => 1,
        'error_message' => 'Invalid message coding',
        array(
          $e->getMessage(),
          $e->getTraceAsString(),
        ),
      ));
      return $resp->setCode(400);
    }

    $this->log->debug('Received registration request', array(
      'reqData' => $reqData,
    ));
    $cxn = $reqData['cxn'];
    $validation = Cxn::getValidationMessages($cxn);
    if (!empty($validation)) {
      // $cxn is not valid, so we can't use it for encoding.
      $resp = new InsecureMessage(array(
        'is_error' => 1,
        'error_message' => 'Invalid cxn details: ' . implode(', ', array_keys($validation)),
      ));
      return $resp->setCode(400);
    }

    $respData = $this->call($reqData);
    $this->log->debug('Responding', array($cxn['cxnId'], $cxn['secret'], $respData));
    return new StdMessage($cxn['cxnId'], $cxn['secret'], $respData);
  }