Intelligently quotes/escapes based on the provided type. If an object
is passed with a toSql() method, that is used, otherwise the php type
is used to infer what needs escaping.
@return string
327024
public function sqlValue($mixed)
    {
        if(is_object($mixed) && method_exists($mixed, 'toSql')) {
            return $mixed->toSql($this);
        }

        return $this->quote($this->escape($mixed));
    }
135632
public function getFldTypeForPhp()
    {
        $type = 'mixed';
        switch ($this->getFldType()) {
            case FFCST::TYPE_INTEGER:
            case FFCST::TYPE_BIGINT:
                $type = 'int';
                break;
            case FFCST::TYPE_DATETIME:
            case FFCST::TYPE_MD5:
            case FFCST::TYPE_STRING:
                $type = 'string';
                break;
            case FFCST::TYPE_BOOLEAN:
                $type = 'bool';
                break;
        }
        return $type;
    }
361571
public function escapeString($s, $EMPTY_NULL = false) {
		if ((!is_string($s)) && (!is_numeric($s))) {
			$s = '';
		}
		if (($EMPTY_NULL) && (empty($s))) {
			return 'NULL';
		}
		return '"' . $this->mysqli->real_escape_string($s) . '"';
	}
865326
public function toString()
	{
		// Build the actual query
		if (is_object($this->statement))
		{
			$query = $this->interpolate($this->statement->queryString, $this->bindings);
		}
		else
		{
			$query = $this->statement;
		}

		return $query;
	}
423843
function quote($val,$type=\PDO::PARAM_STR) {
		return $this->engine=='odbc'?
			(is_string($val)?
				\Base::instance()->stringify(str_replace('\'','\'\'',$val)):
				$val):
			$this->pdo->quote($val,$type);
	}
95877
protected function escape($value)
    {
        if ($value === null) {
            return 'NULL';
        }

        if (is_integer($value) || is_float($value)) {
            return $value;
        }

        return $this->pdo->quote($value);
    }
911416
public function escape_string($str)
    {
        // Prepare one MySQL client connect
        $isFromPool = $this->prepareDB();

        $str = $this->db->real_escape_string($str);

        if ($isFromPool) {
            DBPool::init($this->db_config)->back($this->db);
        } else {
            DBPool::init($this->db_config)->in($this->db);
        }

        return $str;
    }
867328
public function toString()
    {
        $query = '';

        if ($this->sql) {
            return $this->sql;
        }

        switch ($this->type) {
            case 'element':
                $query .= (string) $this->element;
                break;

            case 'select':
                $query .= (string) $this->select;
                $query .= (string) $this->from;

                if ($this->join) {
                    // Special case for joins
                    foreach ($this->join as $join) {
                        $query .= (string) $join;
                    }
                }

                if ($this->where) {
                    $query .= (string) $this->where;
                }

                if ($this->group) {
                    $query .= (string) $this->group;
                }

                if ($this->having) {
                    $query .= (string) $this->having;
                }

                if ($this->order) {
                    $query .= (string) $this->order;
                }

                break;

            case 'union':
                $query .= (string) $this->union;
                break;

            case 'delete':
                $query .= (string) $this->delete;
                $query .= (string) $this->from;

                if ($this->join) {
                    // Special case for joins
                    foreach ($this->join as $join) {
                        $query .= (string) $join;
                    }
                }

                if ($this->where) {
                    $query .= (string) $this->where;
                }

                break;

            case 'update':
                $query .= (string) $this->update;

                if ($this->join) {
                    // Special case for joins
                    foreach ($this->join as $join) {
                        $query .= (string) $join;
                    }
                }

                $query .= (string) $this->set;

                if ($this->where) {
                    $query .= (string) $this->where;
                }

                break;

            case 'insert':
                $query .= (string) $this->insert;

                // Set method
                if ($this->set) {
                    $query .= (string) $this->set;
                } elseif ($this->values) {
                    // Columns-Values method
                    if ($this->columns) {
                        $query .= (string) $this->columns;
                    }

                    $elements = $this->values->getElements();

                    if (!($elements[0] instanceof $this)) {
                        $query .= ' VALUES ';
                    }

                    $query .= (string) $this->values;
                }

                break;

            case 'call':
                $query .= (string) $this->call;
                break;

            case 'exec':
                $query .= (string) $this->exec;
                break;
        }

        // Process Limit
        $query = $this->processLimit($query, $this->limit, $this->offset);

        if ($this->suffix) {
            $query .= ' ' . (string) $this->suffix;
        }

        if ($this->type === 'select' && $this->alias !== null) {
            $query = sprintf('(%s) AS %s', $query, $this->alias);
        }

        return $query;
    }
394932
public function quote($value)
    {
        // If a PDO database connection is set, use it to quote the value using
        // the underlying database. Otherwise, quote it manually.
        if ($pdo = $this->getPdo()) {
            return $pdo->quote($value);
        }

        if (\is_numeric($value)) {
            return $value;
        }

        if (null === $value) {
            return 'NULL';
        }

        return "'" . \addslashes($value) . "'";
    }
746014
function GetFlexType()
	{
		$rt = $this->Type;
		switch ($this->Type)
		{
			case "int":
				$rt = "int";
				break;
			case "smallint":
				$rt = "int";
				break;
			case "tinyint":
				$rt = $this->MaxSize > 1 ? "int" : "Boolean";
				break;
			case "varchar":
				$rt = "String";
				break;
			case "text":
				$rt = "String";
				break;
			case "tinytext":
				$rt = "String";
				break;
			case "datetime":
				$rt = "Date";
				break;
			case "mediumint":
				$rt = "int";
				break;
			case "bigint":
				$rt = "int";
				break;
			case "decimal":
				$rt = "Number";
				break;
			case "float":
				$rt = "Number";
				break;
			default;
				break;
		}

		return $rt;
	}
239675
private function getSqlInterfaceFunction()
    {

        if( count($this->keyProperties) !== 1 ) {

            $content = "    throw new \LogicException('Normality can\\'t (yet) handle tables without a primary key or multi-column primary keys.\\n".
                "Please extend the generator or overload {$this->pgClass->getEntityName()}->parse().');";

        } else {

            $primaryKey = $this->keyProperties[0];
            $dataType = $this->dataTypes[$primaryKey];

            // if datatype inheritied we don't need to do anything
            if( $dataType->isInherited() ) {
                return array();
            }

            // we're doing something
            $content = '';

            $this->class->addImplements( "SqlInterface");
            $this->class->addUses( 'Bond\Sql\QuoteInterface' );
            $this->class->addUses( 'Bond\Sql\SqlInterface' );

            if( $dataType->getType() === 'int' ) {

                // can this property be a entity?
                if( $dataType->isEntity() ) {
                    $content .= <<<PHP
    if( is_object( \$this->data['{$primaryKey}'] ) and \$this->data['{$primaryKey}'] instanceof SqlInterface ) {
        return \$this->data['{$primaryKey}']->parse( \$quoting );
    }\n
PHP
;
                }

                // cast integer datatype to int if not null
                $content .= <<<PHP
    return \$this->data['{$primaryKey}'] !== null ? (string) (int) \$this->data['{$primaryKey}'] : 'NULL';
PHP
;

            } else {

                $content .= <<<PHP
    return \$quoting->quote( \$this->data['{$primaryKey}'] );
PHP
;

            }

        }

        $fn = new Sformatf( <<<'PHP'
/**
 * Impementation of interface \Bond\Pg\Query->Validate()
 * @return scalar
 */
public function parse( QuoteInterface $quoting )
{
%s
}

PHP
            , $content
        );

        $this->class->classComponents[] = new FunctionDeclaration( "parse", $fn );

    }
827270
public function sql(): string
    {
        if (empty($this->parts)) {
            return '1';
        }
        return (string) \array_reduce(
            $this->parts,
            function (string $sql, array $part): string {
                /** @var string|self $condition */
                $condition = $part['condition'];

                if ($this->isGroup($condition)) {
                    // (...)
                    if (\is_string($condition)) {
                        $statement = '(' . $condition . ')';
                    } else {
                        $statement = '(' . $condition->sql() . ')';
                    }
                } else {
                    // foo = ?
                    $statement = $condition;
                }
                /** @var string $statement */
                $statement = (string) $statement;
                $part['type'] = (string) $part['type'];

                if ($sql) {
                    switch ($part['type']) {
                        case 'AND':
                        case 'OR':
                            $statement = $part['type'] . ' ' . $statement;
                            break;
                        default:
                            throw new RuntimeException(
                                \sprintf('Invalid joiner %s', $part['type'])
                            );
                    }
                }

                return \trim($sql . ' ' . $statement);
            },
            ''
        );
    }
748381
public function getPHP() {

        $result = '';

        // The type
        $unique = $this->getUnique();
        if (!empty($unique)) {
            $result .= 'XMLDB_INDEX_UNIQUE, ';
        } else {
            $result .= 'XMLDB_INDEX_NOTUNIQUE, ';
        }
        // The fields
        $indexfields = $this->getFields();
        if (!empty($indexfields)) {
            $result .= "['".  implode("', '", $indexfields) . "']";
        } else {
            $result .= 'null';
        }
        // Hints
        $hints = $this->getHints();
        if (!empty($hints)) {
            $result .= ", ['".  implode("', '", $hints) . "']";
        }

        // Return result
        return $result;
    }
1732
public function quote($string, $parameter_type = \PDO::PARAM_STR): string {
        return $this->connection->quote($string, $parameter_type);
    }
253698
public function escape($VAL)
    {
        // save data
        if (is_numeric($VAL)) {
            if (floatval($VAL) == intval($VAL)) {
                $VAL = intval($VAL);
                settype($VAL, 'integer');
            } else {
                $VAL = floatval($VAL);
                settype($VAL, 'float');
            }
        } else {
            // \PDO::quote() also adds colon before and after the string, so we
            //  have to remove it to keep it compatible with old style.
            $VAL = substr($this->sql->quote(strval($VAL), \PDO::PARAM_STR), 1, -1);
        }

        return $VAL;
    }
1029065
public function quote($value)
    {
        $PdoConnection = $this->getPdoConnection();
        
        // If a PDO database connection is set, use it to quote the value using
        // the underlying database. Otherwise, quote it manually.
        if ($PdoConnection) {
            return $PdoConnection->quote($value);
        } elseif (is_null($value)) {
            return "NULL";
        } else {
            return "'" . addslashes($value) . "'";
        }
    }
289455
public function getSQLType()
    {
        $class = get_class($this);
        $start = strrpos($class, '\\') + 1;
        $len   = strlen($class) - $start - 4;

        return substr($class, strrpos($class, '\\') + 1, $len);
    }