Exemple #1
0
 /**
  * @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);
 }
Exemple #2
0
 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();
 }
Exemple #3
0
 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)));
 }
Exemple #5
0
 public function __construct($db, $query)
 {
     $this->_db = $db;
     $this->_query = $query;
     $this->_adapter = DialectFactory::create();
 }
Exemple #6
0
 public function toSql($fieldName)
 {
     $dialect = DialectFactory::create();
     $regexpMatcher = $dialect->regexpMatcher();
     return $fieldName . ' ' . $regexpMatcher . ' ?';
 }
Exemple #7
0
 public function toSql()
 {
     $sql = DialectFactory::create()->buildQuery($this->query);
     return $this->negate ? "NOT EXISTS ({$sql})" : "EXISTS ({$sql})";
 }