public function saveSchema($table)
 {
     $schemaFile = $this->getSchemaFile($table);
     $tableDDL = $this->database->get_var("show create table `{$table}`", 1);
     if (!$tableDDL) {
         return;
     }
     $tableDDL = str_replace("CREATE TABLE `{$this->database->prefix}", 'CREATE TABLE IF NOT EXISTS `' . Storage::PREFIX_PLACEHOLDER, $tableDDL);
     $tableDDL = preg_replace('/( AUTO_INCREMENT=[0-9]+)/', '', $tableDDL);
     FileSystem::mkdir($this->directory);
     file_put_contents($schemaFile, $tableDDL);
 }
 private function existsInDatabase($vpid)
 {
     if ($this->entityInfo->hasNaturalVpid) {
         $vpidColumnName = $this->entityInfo->vpidColumnName;
         $query = $this->database->prepare("SELECT `{$vpidColumnName}` FROM `{$this->prefixedTableName}` WHERE `{$vpidColumnName}` = %s", $vpid);
     } else {
         $query = "SELECT id FROM {$this->database->vp_id} WHERE `table` = \"{$this->tableName}\" AND vp_id = UNHEX('{$vpid}')";
     }
     return (bool) $this->database->get_var($query);
 }
 private function fillParentId($metaEntityName, $entityInfo, $id)
 {
     $parentReference = $entityInfo->parentReference;
     $parent = $entityInfo->references[$parentReference];
     $vpIdTable = $this->database->vp_id;
     $entityTable = $this->dbSchemaInfo->getPrefixedTableName($metaEntityName);
     $parentTable = $this->dbSchemaInfo->getTableName($parent);
     $idColumnName = $this->dbSchemaInfo->getEntityInfo($metaEntityName)->idColumnName;
     return $this->database->get_var("SELECT HEX(vp_id) FROM {$vpIdTable}\n             WHERE `table` = '{$parentTable}'\n             AND ID = (SELECT {$parentReference} FROM {$entityTable} WHERE {$idColumnName} = '{$id}')");
 }
 private function countEntities()
 {
     $entities = $this->schema->getAllEntityNames();
     $totalEntitiesCount = 0;
     foreach ($entities as $entity) {
         $table = $this->schema->getPrefixedTableName($entity);
         $totalEntitiesCount += $this->database->get_var("SELECT COUNT(*) FROM {$table}");
     }
     return $totalEntitiesCount;
 }
 public function getIdForVpid($vpid)
 {
     return intval($this->database->get_var("SELECT id FROM {$this->database->vp_id} WHERE vp_id = UNHEX('{$vpid}')"));
 }