Пример #1
0
 public function test_array_keep()
 {
     $array = ['A' => 1, 'B' => 2, 'C' => 3, 'D' => 4];
     $extracted = UtilArray::array_keep_keys(['A', 'B'], $array);
     $this->assertCount(2, $extracted);
     $this->assertArrayHasKey('A', $extracted);
     $this->assertArrayHasKey('B', $extracted);
     $this->assertEquals(1, $extracted['A']);
     $this->assertEquals(2, $extracted['B']);
     $extracted = UtilArray::array_keep_keys(['A', 'B'], $array, true);
     $this->assertCount(2, $extracted);
     $this->assertEquals(1, $extracted[0]);
     $this->assertEquals(2, $extracted[1]);
 }
Пример #2
0
 /**
  * @see \dbeurive\Backend\Database\EntryPoints\AbstractEntryPoint
  */
 public function execute($inExecutionConfig)
 {
     /* @var \PDO $pdo */
     $pdo = $this->getDbh();
     $result = new SqlResult();
     $fieldsValues = UtilArray::array_keep_keys(self::$__conditionFields, $inExecutionConfig, true);
     $req = $pdo->prepare($this->__sql());
     if (false === $req->execute($fieldsValues)) {
         $message = "SQL request failed:\n" . UtilString::text_linearize($sql, true, true) . "\n" . "Condition fields: " . implode(', ', self::$__conditionFields) . "\n" . "Bound to values: " . implode(', ', $fieldsValues);
         $result->setErrorMessage($message);
         return $result;
     }
     $result->setDataSets($req->fetchAll(\PDO::FETCH_ASSOC));
     return $result;
 }
Пример #3
0
 /**
  * @see \dbeurive\Backend\Database\EntryPoints\AbstractEntryPoint
  */
 public function execute($inExecutionConfig)
 {
     /* @var \PDO $pdo */
     $pdo = $this->getDbh();
     // Execute the request.
     $result = new BaseResult();
     $fieldsValues = UtilArray::array_keep_keys(self::$__insertedFields, $inExecutionConfig, true);
     $req = $pdo->prepare($this->__sql);
     if (false === $req->execute($fieldsValues)) {
         $message = "SQL request failed:\n" . UtilString::text_linearize($this->__sql, true, true) . "\n" . "Condition fields: " . implode(', ', self::$__insertedFields) . "\n" . "Bound to values: " . implode(', ', $fieldsValues);
         $result->setErrorMessage($message);
         return $result;
     }
     $result->setStatusSuccess();
     return $result;
 }