/** * Returns the fragment SQL string * * @param rdbms.DBConnection conn * @return string * @throws rdbms.SQLStateException */ public function asSql(\rdbms\DBConnection $conn) { $s = ''; foreach ($this->projections as $e) { $s .= 0 != strlen($e['alias']) ? $conn->prepare(', %c as %l', $e['projection']->asSql($conn), $e['alias']) : $conn->prepare(', %c', $e['projection']->asSql($conn)); } return substr($s, 1); }
/** * Connect * * @param bool reconnect default FALSE * @return bool success * @throws rdbms.SQLConnectException */ public function connect($reconnect = false) { if (is_resource($this->handle)) { return true; } // Already connected if (!$reconnect && false === $this->handle) { return false; } // Previously failed connecting $this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECT, $reconnect)); if ($this->flags & DB_PERSISTENT) { $this->handle = mssql_pconnect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword()); } else { $this->handle = mssql_connect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword()); } if (!is_resource($this->handle)) { $e = new \rdbms\SQLConnectException(trim(mssql_get_last_message()), $this->dsn); \xp::gc(__FILE__); throw $e; } \xp::gc(__FILE__); $this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECTED, $reconnect)); return parent::connect(); }
/** * Connect * * @param bool reconnect default FALSE * @return bool success * @throws rdbms.SQLConnectException */ public function connect($reconnect = false) { if ($this->handle->connected) { return true; } // Already connected if (!$reconnect && null === $this->handle->connected) { return false; } // Previously failed connecting $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect)); try { $this->handle->connect($this->dsn->getUser(), $this->dsn->getPassword(), $this->dsn->getProperty('charset', null)); $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect)); } catch (\io\IOException $e) { $this->handle->connected = null; $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect)); $message = ''; do { $message .= $e->getMessage() . ': '; } while ($e = $e->getCause()); throw new SQLConnectException(substr($message, 0, -2), $this->dsn); } return parent::connect(); }
/** * Constructor * * @param rdbms.DSN dsn */ public function __construct($dsn) { parent::__construct($dsn); $this->formatter = new StatementFormatter($this, new InterBaseDialect()); }
/** * Returns the fragment SQL * * @param rdbms.DBConnection conn * @param rdbms.Peer peer * @return string * @throws rdbms.SQLStateException */ public function asSql(\rdbms\DBConnection $conn, \rdbms\Peer $peer) { return $conn->prepare('not (%c)', $this->criterion->asSql($conn, $peer)); }
/** * Constructor * * @param rdbms.DSN dsn */ public function __construct($dsn) { parent::__construct($dsn); $this->formatter = new StatementFormatter($this, new MockDialect()); $this->clearResultSets(); }
/** * Connect * * @param bool reconnect default FALSE * @return bool success * @throws rdbms.SQLConnectException */ public function connect($reconnect = false) { if ($this->handle->connected) { return true; } // Already connected if (!$reconnect && null === $this->handle->connected) { return false; } // Previously failed connecting $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect)); try { $this->handle->connect($this->dsn->getUser(), $this->dsn->getPassword()); $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect)); } catch (IOException $e) { $this->handle->connected = null; $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect)); throw new SQLConnectException($e->getMessage(), $this->dsn); } try { // Figure out sql_mode and update formatter's escaperules accordingly // - See: http://bugs.mysql.com/bug.php?id=10214 // - Possible values: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html // "modes is a list of different modes separated by comma (,) characters." $query = $this->handle->consume($this->handle->query("show variables like 'sql_mode'")); $modes = array_flip(explode(',', $query[0][1])); } catch (IOException $e) { // Ignore } // NO_BACKSLASH_ESCAPES: Disable the use of the backslash character // (\) as an escape character within strings. With this mode enabled, // backslash becomes any ordinary character like any other. // (Implemented in MySQL 5.0.1) isset($modes['NO_BACKSLASH_ESCAPES']) && $this->formatter->dialect->setEscapeRules(['"' => '""']); return parent::connect(); }
/** * Connect * * @param bool reconnect default FALSE * @return bool success * @throws rdbms.SQLConnectException */ public function connect($reconnect = false) { if (is_resource($this->handle)) { return true; } // Already connected if (!$reconnect && false === $this->handle) { return false; } // Previously failed connecting // Connect via local sockets if "." is passed. This will not work on // Windows with the mysqlnd extension (see PHP bug #48082: "mysql_connect // does not work with named pipes"). For mysqlnd, we default to mysqlx // anyways, so this works transparently. $host = $this->dsn->getHost(); $ini = null; if ('.' === $host) { $sock = $this->dsn->getProperty('socket', null); if (0 === strncasecmp(PHP_OS, 'Win', 3)) { $connect = '.'; if (null !== $sock) { $ini = ini_set('mysql.default_socket'); ini_set('mysql.default_socket', substr($sock, 9)); // 9 = strlen("\\\\.\\pipe\\") } } else { $connect = null === $sock ? 'localhost' : ':' . $sock; } } else { if ('localhost' === $host) { $connect = '127.0.0.1:' . $this->dsn->getPort(3306); // Force TCP/IP } else { $connect = $host . ':' . $this->dsn->getPort(3306); } } $this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECT, $reconnect)); if ($this->flags & DB_PERSISTENT) { $this->handle = mysql_pconnect($connect, $this->dsn->getUser(), $this->dsn->getPassword()); } else { $this->handle = mysql_connect($connect, $this->dsn->getUser(), $this->dsn->getPassword(), $this->flags & DB_NEWLINK); } $this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECTED, $reconnect)); $ini && ini_set('mysql.default_socket', $ini); if (!is_resource($this->handle)) { $e = new \rdbms\SQLConnectException('#' . mysql_errno() . ': ' . mysql_error(), $this->dsn); \xp::gc(__FILE__); throw $e; } mysql_query('set names utf8mb4', $this->handle); // Figure out sql_mode and update formatter's escaperules accordingly // - See: http://bugs.mysql.com/bug.php?id=10214 // - Possible values: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html // "modes is a list of different modes separated by comma (,) characters." $modes = array_flip(explode(',', current(mysql_fetch_row(mysql_query("show variables like 'sql_mode'", $this->handle))))); // NO_BACKSLASH_ESCAPES: Disable the use of the backslash character // (\) as an escape character within strings. With this mode enabled, // backslash becomes any ordinary character like any other. // (Implemented in MySQL 5.0.1) isset($modes['NO_BACKSLASH_ESCAPES']) && $this->formatter->dialect->setEscapeRules(['"' => '""']); return parent::connect(); }
/** * get the SELECT query * * @param rdbms.DBConnection conn * @param rdbms.Peer peer * @param rdbms.join.Joinprocessor jp optional * @return rdbms.ResultSet */ public function getSelectQueryString(DBConnection $conn, Peer $peer, $jp = null) { if ($this->isJoin()) { $jp->setFetchmodes($this->fetchmode); } return $conn->prepare('select %c from %c %c', $this->projections($conn, $peer, $jp), $this->isJoin() ? $jp->getJoinString() : $peer->table, $this->toSQL($conn, $peer, $jp)); }
/** * Returns the fragment SQL * * @param rdbms.DBConnection conn * @param rdbms.Peer peer * @return string * @throws rdbms.SQLStateException */ public function asSql(DBConnection $conn) { return $conn->prepare($this->command, $this->field); }
/** * Constructor * * @param rdbms.DSN dsn */ public function __construct($dsn) { parent::__construct($dsn); $this->formatter = new StatementFormatter($this, new PostgreSQLDialect()); }
/** * Returns the fragment SQL * * @param rdbms.DBConnection conn * @param rdbms.Peer peer * @return string */ public function asSql(DBConnection $conn, Peer $peer) { $lhs = $this->lhs instanceof SQLFragment ? $this->lhs : $peer->column($this->lhs); return $conn->prepare('%c ' . str_replace('?', $lhs->getType(), $this->op), $lhs, $this->value); }
/** * Returns the fragment SQL * * @param rdbms.DBConnection conn * @param rdbms.Peer peer * @return string * @throws rdbms.SQLStateException */ public function asSql(\rdbms\DBConnection $conn, \rdbms\Peer $peer) { $lhs = $this->lhs instanceof \rdbms\SQLFragment ? $this->lhs : $peer->column($this->lhs); return $conn->prepare('%c between ' . $lhs->getType() . ' and ' . $lhs->getType(), $lhs, $this->lo, $this->hi); }