- self::createView($name, $structure, $verbose, $action);
- }
- }
-
- /**
- * Prints view structure
- *
- * @param string $basePath Base path
- * @return void
- */
- public static function printStructure(string $basePath)
- {
- $database = self::definition($basePath, false);
-
- foreach ($database as $name => $structure) {
- echo "--\n";
- echo "-- VIEW $name\n";
- echo "--\n";
- self::createView($name, $structure, true, false);
-
- echo "\n";
- }
- }
-
- /**
- * Creates view
- *
- * @param string $name Name of view
- * @param array $structure Structure of view
- * @param bool $verbose Whether to show SQL statements
- * @param bool $action Whether to execute SQL statements
- * @return bool Whether execution went fine
- */
- private static function createView(string $name, array $structure, bool $verbose, bool $action): bool
- {
- $r = true;
-
- $sql_rows = [];
- foreach ($structure['fields'] as $fieldname => $origin) {
- if (is_string($origin)) {
- $sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`";
- } elseif (is_array($origin) && (sizeof($origin) == 2)) {
- $sql_rows[] = "`" . DBA::escape($origin[0]) . "`.`" . DBA::escape($origin[1]) . "` AS `" . DBA::escape($fieldname) . "`";
+ if (self::isView($name)) {
+ DBA::e(sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name)));
+ } elseif (self::isTable($name)) {
+ DBA::e(sprintf("DROP TABLE IF EXISTS `%s`", DBA::escape($name)));