/** * @throws GeneratorException * @return Dialect */ public function dialectAdapter() { $dialect = DialectFactory::create(); $dialectShortName = $this->objectShortClassName($dialect); $selfClassPath = $this->thisNamespace(); $generatorDialect = "{$selfClassPath}\\Dialect\\{$dialectShortName}"; if (!class_exists($generatorDialect)) { throw new GeneratorException("Model generator for '{$dialectShortName}' does not exists."); } return new $generatorDialect($this->tableName); }
public function execute() { if (empty($this->_models)) { return; } $this->_callBeforeSaveCallbacks(); $metaInstance = Arrays::first($this->_models); $columns = $metaInstance->getFieldsWithoutPrimaryKey(); $primaryKey = $metaInstance->getIdName(); $table = $metaInstance->getTableName(); $sql = DialectFactory::create()->batchInsert($table, $primaryKey, $columns, count($this->_models)); $params = $this->_prepareParams($primaryKey); $ids = Arrays::flatten(Db::getInstance()->query($sql, $params)->fetchAll(PDO::FETCH_NUM)); $this->_assignPrimaryKeys($primaryKey, $ids); $this->_callAfterSaveCallbacks(); }
public function tableOrSubQuery() { if ($this->_query->table instanceof Query) { return '(' . DialectFactory::create()->buildQuery($this->_query->table) . ')'; } return $this->_query->table; }
public static function getException($errorInfo, $querySql) { $exceptionClassName = DialectFactory::create()->getExceptionForError($errorInfo); return new $exceptionClassName(sprintf("Exception: query: %s failed: %s (%s)", $querySql, self::errorMessageFromErrorInfo($errorInfo), self::_errorCodesFromErrorInfo($errorInfo))); }
public function __construct($db, $query) { $this->_db = $db; $this->_query = $query; $this->_adapter = DialectFactory::create(); }
public function toSql($fieldName) { $dialect = DialectFactory::create(); $regexpMatcher = $dialect->regexpMatcher(); return $fieldName . ' ' . $regexpMatcher . ' ?'; }
public function toSql() { $sql = DialectFactory::create()->buildQuery($this->query); return $this->negate ? "NOT EXISTS ({$sql})" : "EXISTS ({$sql})"; }