public function initialize(PDO $pdo, ReflectionMethod $method, HermitAnnote $annote)
 {
     $meta = HermitDatabaseMetaFactory::get($pdo);
     $table = $annote->getTable();
     $info = $meta->getTableInfo($table);
     $primaryKeys = $info->getPrimaryKeys();
     $sql = 'DELETE';
     $sql .= ' ';
     $sql .= 'FROM';
     $sql .= ' ';
     $sql .= $table;
     $sql .= ' ';
     $sql .= 'WHERE';
     $sql .= ' ';
     $begin = false;
     foreach ($primaryKeys as $pk) {
         $begin = true;
         $sql .= ' ';
         $sql .= $pk . '=';
         $sql .= ' ';
         $sql .= '/*' . $pk . '*/';
         $sql .= '"' . $pk . '"';
         $sql .= ' ';
         $sql .= 'AND';
     }
     if ($begin) {
         $sql = substr($sql, 0, -3);
     }
     $this->sql = $sql;
 }
 public function initialize(PDO $pdo, ReflectionMethod $method, HermitAnnote $annote)
 {
     $meta = HermitDatabaseMetaFactory::get($pdo);
     $table = $annote->getTable();
     $info = $meta->getTableInfo($table);
     $columns = $info->getColumns();
     $insert = 'INSERT INTO';
     $insert .= ' ';
     $insert .= $table;
     $insert .= ' (';
     $insert .= join(', ', $columns);
     $insert .= ') VALUES (';
     $begin = false;
     foreach ($columns as $column) {
         $begin = true;
         $insert .= '/*' . $column . '*/';
         $insert .= '"' . $column . '"';
         $insert .= ',';
     }
     if ($begin) {
         $insert = substr($insert, 0, -1);
     }
     $insert .= ')';
     $this->insert = $insert;
 }
 public function initialize(PDO $pdo, ReflectionMethod $method, HermitAnnote $annote)
 {
     $procedureName = $annote->getProcedure($method);
     $dbMeta = HermitDatabaseMetaFactory::get($pdo);
     $info = $dbMeta->getProcedureInfo($procedureName);
     $this->setupSql = self::generateSetupSql($info);
     $this->sql = self::generateCallSql($info);
 }
 public static function create(HermitAnnote $annote, ReflectionMethod $method)
 {
     $value = $annote->getValueType($method);
     if (null === $value) {
         return new HermitNopValueType($annote, $method, null);
     }
     foreach (self::$valueTypes as $type) {
         if (call_user_func(array($type, 'accept'), $value)) {
             return new $type($annote, $method, $value);
         }
     }
     return new HermitNopValueType($annote, $method, $value);
 }
 public function initialize(PDO $pdo, ReflectionMethod $method, HermitAnnote $annote)
 {
     $meta = HermitDatabaseMetaFactory::get($pdo);
     $table = $annote->getTable();
     $info = $meta->getTableInfo($table);
     $columns = $info->getColumns();
     $select = 'SELECT';
     $select .= ' ';
     $select .= join(', ', $columns);
     $select .= ' ';
     $select .= 'FROM';
     $select .= ' ';
     $select .= $table;
     $this->select = $select;
 }
Example #6
0
 protected function __construct(HermitContext $ctx, ReflectionClass $reflector, $target)
 {
     $this->context = $ctx;
     $this->target = $target;
     $this->annote = HermitAnnote::create($reflector);
     $this->commandFactory = new HermitSqlCommandFactory($ctx, $reflector);
 }
 public function execute(HermitStatement $stmt, HermitValueType $type)
 {
     if ($stmt->columnCount() < 1) {
         $stmt->closeCursor();
         unset($stmt);
         return null;
     }
     //
     // check single result
     //
     if ($this->annote->isSingleProcedureResult($this->method)) {
         $resultset = HermitResultSetFactory::create($this->method);
         return $resultset->execute($stmt, $type);
     }
     $resultset = HermitResultSetFactory::create($this->method);
     $results = array();
     do {
         $results[] = $resultset->execute($stmt, $type);
     } while ($stmt->nextRowset());
     $stmt->closeCursor();
     unset($stmt);
     return $results;
 }
Example #8
0
 public function match($matches)
 {
     if (count($matches) < 4) {
         throw new RuntimeException('sql comment was fail: ' . join(',', $matches));
     }
     list($all, $key, $name, $defaultValue) = $matches;
     if ($this->hasParameter($name)) {
         return $this->replace($key, $name, $defaultValue);
     }
     $annote = HermitAnnote::create($this->targetClass);
     $columns = $annote->getColumns();
     $columnsLower = array_map('strtolower', $columns);
     if (in_array(strtolower($name), $columnsLower)) {
         return $this->replace($key, $name, $defaultValue);
     }
     return $defaultValue;
 }
 public function __construct(HermitContext $ctx, ReflectionClass $reflector)
 {
     $this->context = $ctx;
     $this->annote = HermitAnnote::create($reflector);
     $this->reflector = $reflector;
 }