Ejemplo n.º 1
0
 /**
  * Delete and Insert database row.
  * @param $row array Row in table.
  * @param $table string Table name.
  * @return void
  */
 public static function updateRow($row, $table)
 {
     $fields = array_keys($row);
     $values = array_values($row);
     $pressholders = str_repeat("?,", count($fields) - 1);
     $insertSQL = "INSERT INTO " . $table . "(" . implode(',', $fields) . ") VALUES (" . $pressholders . "?)";
     $deleteSQL = "DELETE FROM " . $table . " WHERE " . current($fields) . " = ?";
     $db = Database::getInstance();
     $db->prepare($deleteSQL)->execute([current($values)]);
     $db->prepare($insertSQL)->execute($values);
     echo '→ MODIFY: (' . $table . ') ' . implode(', ', $values) . "\n";
 }
Ejemplo n.º 2
0
 /**
  * Execute.
  * @param $databaseFilePath Database file path.
  * @param $target replace target string.
  * @param $replace replaced string.
  * @return void
  */
 public function execute($databaseFilePath, $target, $replace)
 {
     Database::load($databaseFilePath);
     $tables = Model::findAllTableStructure();
     foreach ($tables as $table) {
         $rows = Model::findAll($table);
         foreach ($rows as &$row) {
             if ($this->replaceIfHit($row, $target, $replace)) {
                 Model::updateRow($row, $table);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public static function setUpBeforeClass()
 {
     copy(__DIR__ . '/resources/model.sqlite', __DIR__ . '/resources/model.sqlite.test');
     Database::reload(__DIR__ . '/resources/model.sqlite.test');
 }
Ejemplo n.º 4
0
 public function testGetInstance()
 {
     Closure::bind(function () {
         $this->assertNotNull(Database::$instance, Database::getInstance());
     }, $this, '\\Hikouki\\Stigma\\Database')->__invoke();
 }