mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-21 12:19:56 +09:00
merge from 1.7.3.5(r13153:r13167)
git-svn-id: http://xe-core.googlecode.com/svn/trunk@13168 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
cc47d2b247
commit
2d3f149b5a
2042 changed files with 129266 additions and 126243 deletions
|
|
@ -1,162 +1,218 @@
|
|||
<?php
|
||||
require_once('DBMysql.class.php');
|
||||
|
||||
require_once('DBMysql.class.php');
|
||||
|
||||
/**
|
||||
* Class to use MySQL innoDB DBMS
|
||||
* mysql innodb handling class
|
||||
*
|
||||
* Does not use prepared statements, since mysql driver does not support them
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db
|
||||
* @version 0.1
|
||||
*/
|
||||
class DBMysql_innodb extends DBMysql
|
||||
{
|
||||
|
||||
/**
|
||||
* Class to use MySQL innoDB DBMS
|
||||
* mysql innodb handling class
|
||||
*
|
||||
* Does not use prepared statements, since mysql driver does not support them
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/db
|
||||
* @version 0.1
|
||||
**/
|
||||
class DBMysql_innodb extends DBMysql {
|
||||
* Constructor
|
||||
* @return void
|
||||
*/
|
||||
function DBMysql_innodb()
|
||||
{
|
||||
$this->_setDBInfo();
|
||||
$this->_connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @return void
|
||||
**/
|
||||
function DBMysql_innodb() {
|
||||
$this->_setDBInfo();
|
||||
$this->_connect();
|
||||
}
|
||||
/**
|
||||
* Create an instance of this class
|
||||
* @return DBMysql_innodb return DBMysql_innodb object instance
|
||||
*/
|
||||
function create()
|
||||
{
|
||||
return new DBMysql_innodb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of this class
|
||||
* @return DBMysql_innodb return DBMysql_innodb object instance
|
||||
*/
|
||||
function create()
|
||||
/**
|
||||
* DB disconnection
|
||||
* this method is private
|
||||
* @param resource $connection
|
||||
* @return void
|
||||
*/
|
||||
function _close($connection)
|
||||
{
|
||||
$this->_query("commit", $connection);
|
||||
@mysql_close($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* DB transaction start
|
||||
* this method is private
|
||||
* @return boolean
|
||||
*/
|
||||
function _begin($transactionLevel)
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
|
||||
if(!$transactionLevel)
|
||||
{
|
||||
return new DBMysql_innodb;
|
||||
$this->_query("START TRANSACTION", $connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_query("SAVEPOINT SP" . $transactionLevel, $connection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* DB transaction rollback
|
||||
* this method is private
|
||||
* @return boolean
|
||||
*/
|
||||
function _rollback($transactionLevel)
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
|
||||
$point = $transactionLevel - 1;
|
||||
|
||||
if($point)
|
||||
{
|
||||
$this->_query("ROLLBACK TO SP" . $point, $connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_query("ROLLBACK", $connection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* DB transaction commit
|
||||
* this method is private
|
||||
* @return boolean
|
||||
*/
|
||||
function _commit()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
$this->_query("commit", $connection);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
* this method is private
|
||||
* @param string $query
|
||||
* @param resource $connection
|
||||
* @return resource
|
||||
*/
|
||||
function __query($query, $connection)
|
||||
{
|
||||
if(!$connection)
|
||||
{
|
||||
exit('XE cannot handle DB connection.');
|
||||
}
|
||||
// Run the query statement
|
||||
$result = @mysql_query($query, $connection);
|
||||
// Error Check
|
||||
if(mysql_error($connection))
|
||||
{
|
||||
$this->setError(mysql_errno($connection), mysql_error($connection));
|
||||
}
|
||||
// Return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create table by using the schema xml
|
||||
*
|
||||
* type : number, varchar, tinytext, text, bigtext, char, date, \n
|
||||
* opt : notnull, default, size\n
|
||||
* index : primary key, index, unique\n
|
||||
* @param string $xml_doc xml schema contents
|
||||
* @return void|object
|
||||
*/
|
||||
function _createTable($xml_doc)
|
||||
{
|
||||
// xml parsing
|
||||
$oXml = new XmlParser();
|
||||
$xml_obj = $oXml->parse($xml_doc);
|
||||
// Create a table schema
|
||||
$table_name = $xml_obj->table->attrs->name;
|
||||
if($this->isTableExists($table_name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$table_name = $this->prefix . $table_name;
|
||||
|
||||
if(!is_array($xml_obj->table->column))
|
||||
{
|
||||
$columns[] = $xml_obj->table->column;
|
||||
}
|
||||
else
|
||||
{
|
||||
$columns = $xml_obj->table->column;
|
||||
}
|
||||
|
||||
/**
|
||||
* DB disconnection
|
||||
* this method is private
|
||||
* @param resource $connection
|
||||
* @return void
|
||||
*/
|
||||
function _close($connection) {
|
||||
$this->_query("commit", $connection);
|
||||
@mysql_close($connection);
|
||||
}
|
||||
foreach($columns as $column)
|
||||
{
|
||||
$name = $column->attrs->name;
|
||||
$type = $column->attrs->type;
|
||||
$size = $column->attrs->size;
|
||||
$notnull = $column->attrs->notnull;
|
||||
$primary_key = $column->attrs->primary_key;
|
||||
$index = $column->attrs->index;
|
||||
$unique = $column->attrs->unique;
|
||||
$default = $column->attrs->default;
|
||||
$auto_increment = $column->attrs->auto_increment;
|
||||
|
||||
/**
|
||||
* DB transaction start
|
||||
* this method is private
|
||||
* @return boolean
|
||||
*/
|
||||
function _begin() {
|
||||
$connection = $this->_getConnection('master');
|
||||
$this->_query("begin", $connection);
|
||||
return true;
|
||||
}
|
||||
$column_schema[] = sprintf('`%s` %s%s %s %s %s', $name, $this->column_type[$type], $size ? '(' . $size . ')' : '', isset($default) ? "default '" . $default . "'" : '', $notnull ? 'not null' : '', $auto_increment ? 'auto_increment' : '');
|
||||
|
||||
/**
|
||||
* DB transaction rollback
|
||||
* this method is private
|
||||
* @return boolean
|
||||
*/
|
||||
function _rollback() {
|
||||
$connection = $this->_getConnection('master');
|
||||
$this->_query("rollback", $connection);
|
||||
return true;
|
||||
}
|
||||
if($primary_key)
|
||||
{
|
||||
$primary_list[] = $name;
|
||||
}
|
||||
else if($unique)
|
||||
{
|
||||
$unique_list[$unique][] = $name;
|
||||
}
|
||||
else if($index)
|
||||
{
|
||||
$index_list[$index][] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DB transaction commit
|
||||
* this method is private
|
||||
* @return boolean
|
||||
*/
|
||||
function _commit() {
|
||||
$connection = $this->_getConnection('master');
|
||||
$this->_query("commit", $connection);
|
||||
return true;
|
||||
}
|
||||
if(count($primary_list))
|
||||
{
|
||||
$column_schema[] = sprintf("primary key (%s)", '`' . implode($primary_list, '`,`') . '`');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
* this method is private
|
||||
* @param string $query
|
||||
* @param resource $connection
|
||||
* @return resource
|
||||
*/
|
||||
function __query($query, $connection) {
|
||||
// Run the query statement
|
||||
$result = @mysql_query($query, $connection);
|
||||
// Error Check
|
||||
if(mysql_error($connection)) $this->setError(mysql_errno($connection), mysql_error($connection));
|
||||
// Return result
|
||||
return $result;
|
||||
}
|
||||
if(count($unique_list))
|
||||
{
|
||||
foreach($unique_list as $key => $val)
|
||||
{
|
||||
$column_schema[] = sprintf("unique %s (%s)", $key, '`' . implode($val, '`,`') . '`');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create table by using the schema xml
|
||||
*
|
||||
* type : number, varchar, tinytext, text, bigtext, char, date, \n
|
||||
* opt : notnull, default, size\n
|
||||
* index : primary key, index, unique\n
|
||||
* @param string $xml_doc xml schema contents
|
||||
* @return void|object
|
||||
*/
|
||||
function _createTable($xml_doc) {
|
||||
// xml parsing
|
||||
$oXml = new XmlParser();
|
||||
$xml_obj = $oXml->parse($xml_doc);
|
||||
// Create a table schema
|
||||
$table_name = $xml_obj->table->attrs->name;
|
||||
if($this->isTableExists($table_name)) return;
|
||||
$table_name = $this->prefix.$table_name;
|
||||
if(count($index_list))
|
||||
{
|
||||
foreach($index_list as $key => $val)
|
||||
{
|
||||
$column_schema[] = sprintf("index %s (%s)", $key, '`' . implode($val, '`,`') . '`');
|
||||
}
|
||||
}
|
||||
|
||||
if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column;
|
||||
else $columns = $xml_obj->table->column;
|
||||
$schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema, ",\n"), "ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci");
|
||||
|
||||
foreach($columns as $column) {
|
||||
$name = $column->attrs->name;
|
||||
$type = $column->attrs->type;
|
||||
$size = $column->attrs->size;
|
||||
$notnull = $column->attrs->notnull;
|
||||
$primary_key = $column->attrs->primary_key;
|
||||
$index = $column->attrs->index;
|
||||
$unique = $column->attrs->unique;
|
||||
$default = $column->attrs->default;
|
||||
$auto_increment = $column->attrs->auto_increment;
|
||||
$output = $this->_query($schema);
|
||||
if(!$output)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$column_schema[] = sprintf('`%s` %s%s %s %s %s',
|
||||
$name,
|
||||
$this->column_type[$type],
|
||||
$size?'('.$size.')':'',
|
||||
isset($default)?"default '".$default."'":'',
|
||||
$notnull?'not null':'',
|
||||
$auto_increment?'auto_increment':''
|
||||
);
|
||||
|
||||
if($primary_key) $primary_list[] = $name;
|
||||
else if($unique) $unique_list[$unique][] = $name;
|
||||
else if($index) $index_list[$index][] = $name;
|
||||
}
|
||||
|
||||
if(count($primary_list)) {
|
||||
$column_schema[] = sprintf("primary key (%s)", '`'.implode($primary_list,'`,`').'`');
|
||||
}
|
||||
|
||||
if(count($unique_list)) {
|
||||
foreach($unique_list as $key => $val) {
|
||||
$column_schema[] = sprintf("unique %s (%s)", $key, '`'.implode($val,'`,`').'`');
|
||||
}
|
||||
}
|
||||
|
||||
if(count($index_list)) {
|
||||
foreach($index_list as $key => $val) {
|
||||
$column_schema[] = sprintf("index %s (%s)", $key, '`'.implode($val,'`,`').'`');
|
||||
}
|
||||
}
|
||||
|
||||
$schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema,",\n"), "ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci");
|
||||
|
||||
$output = $this->_query($schema);
|
||||
if(!$output) return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
/* End of file DBMysql_innodb.class.php */
|
||||
/* Location: ./classes/db/DBMysql_innodb.class.php */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue