Create tables with prefix (#38 #214 #196)

This commit is contained in:
Tobias Reich 2014-08-29 23:08:18 +02:00
parent af37f5c138
commit 9f11875e39
6 changed files with 30 additions and 15 deletions

View File

@ -2,7 +2,7 @@
# Version 2.5
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `lychee_albums` (
CREATE TABLE IF NOT EXISTS `?` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`description` varchar(1000) DEFAULT '',

View File

@ -2,7 +2,7 @@
# Version 2.5
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `lychee_log` (
CREATE TABLE IF NOT EXISTS `?` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time` int(11) NOT NULL,
`type` varchar(11) NOT NULL,

View File

@ -2,7 +2,7 @@
# Version 2.5
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `lychee_photos` (
CREATE TABLE IF NOT EXISTS `?` (
`id` bigint(14) NOT NULL,
`title` varchar(50) NOT NULL,
`description` varchar(1000) DEFAULT '',

View File

@ -2,7 +2,7 @@
# Version 2.5
# ------------------------------------------------------------
INSERT INTO `lychee_settings` (`key`, `value`)
INSERT INTO `?` (`key`, `value`)
VALUES
('version',''),
('username',''),

View File

@ -2,7 +2,7 @@
# Version 2.5
# ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `lychee_settings` (
CREATE TABLE IF NOT EXISTS `?` (
`key` varchar(50) NOT NULL DEFAULT '',
`value` varchar(200) DEFAULT ''
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

View File

@ -29,7 +29,8 @@ class Database extends Module {
if (!Database::createDatabase($database, $name)) exit('Error: Could not create database!');
# Check tables
if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings, lychee_log LIMIT 0;'))
$query = Database::prepare($database, 'SELECT * FROM ?, ?, ?, ? LIMIT 0', [LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS, LYCHEE_TABLE_SETTINGS, LYCHEE_TABLE_LOG]);
if (!$database->query($query))
if (!Database::createTables($database)) exit('Error: Could not create tables!');
return $database;
@ -140,30 +141,36 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
Module::dependencies(isset($database));
# Create log
if (!$database->query('SELECT * FROM lychee_log LIMIT 0;')) {
$exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_LOG]);
if (!$database->query($exist)) {
# Read file
$file = __DIR__ . '/../database/log_table.sql';
$query = @file_get_contents($file);
# Create table
if (!isset($query)||$query===false) return false;
# Create table
$query = Database::prepare($database, $query, [LYCHEE_TABLE_LOG]);
if (!$database->query($query)) return false;
}
# Create settings
if (!$database->query('SELECT * FROM lychee_settings LIMIT 0;')) {
$exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_SETTINGS]);
if (!$database->query($exist)) {
# Read file
$file = __DIR__ . '/../database/settings_table.sql';
$query = @file_get_contents($file);
# Create table
if (!isset($query)||$query===false) {
Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_settings');
return false;
}
# Create table
$query = Database::prepare($database, $query, [LYCHEE_TABLE_SETTINGS]);
if (!$database->query($query)) {
Log::error($database, __METHOD__, __LINE__, $database->error);
return false;
@ -173,11 +180,13 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
$file = __DIR__ . '/../database/settings_content.sql';
$query = @file_get_contents($file);
# Add content
if (!isset($query)||$query===false) {
Log::error($database, __METHOD__, __LINE__, 'Could not load content-query for lychee_settings');
return false;
}
# Add content
$query = Database::prepare($database, $query, [LYCHEE_TABLE_SETTINGS]);
if (!$database->query($query)) {
Log::error($database, __METHOD__, __LINE__, $database->error);
return false;
@ -186,17 +195,20 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
}
# Create albums
if (!$database->query('SELECT * FROM lychee_albums LIMIT 0;')) {
$exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_ALBUMS]);
if (!$database->query($exist)) {
# Read file
$file = __DIR__ . '/../database/albums_table.sql';
$query = @file_get_contents($file);
# Create table
if (!isset($query)||$query===false) {
Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_albums');
return false;
}
# Create table
$query = Database::prepare($database, $query, [LYCHEE_TABLE_ALBUMS]);
if (!$database->query($query)) {
Log::error($database, __METHOD__, __LINE__, $database->error);
return false;
@ -205,17 +217,20 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
}
# Create photos
if (!$database->query('SELECT * FROM lychee_photos LIMIT 0;')) {
$exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_PHOTOS]);
if (!$database->query($exist)) {
# Read file
$file = __DIR__ . '/../database/photos_table.sql';
$query = @file_get_contents($file);
# Create table
if (!isset($query)||$query===false) {
Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_photos');
return false;
}
# Create table
$query = Database::prepare($database, $query, [LYCHEE_TABLE_PHOTOS]);
if (!$database->query($query)) {
Log::error($database, __METHOD__, __LINE__, $database->error);
return false;