XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
DBMysql_innodb.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
4 require_once('DBMysql.class.php');
5 
16 class DBMysql_innodb extends DBMysql
17 {
18 
23  function __construct($auto_connect = TRUE)
24  {
25  $this->_setDBInfo();
26  if($auto_connect) $this->_connect();
27  }
28 
33  function create()
34  {
35  return new DBMysql_innodb;
36  }
37 
44  function _close($connection)
45  {
46  @mysql_close($connection);
47  }
48 
54  function _begin($transactionLevel = 0)
55  {
56  $connection = $this->_getConnection('master');
57 
58  if(!$transactionLevel)
59  {
60  $this->_query("START TRANSACTION", $connection);
61  }
62  else
63  {
64  $this->_query("SAVEPOINT SP" . $transactionLevel, $connection);
65  }
66  return true;
67  }
68 
74  function _rollback($transactionLevel = 0)
75  {
76  $connection = $this->_getConnection('master');
77 
78  $point = $transactionLevel - 1;
79 
80  if($point)
81  {
82  $this->_query("ROLLBACK TO SP" . $point, $connection);
83  }
84  else
85  {
86  $this->_query("ROLLBACK", $connection);
87  }
88  return true;
89  }
90 
96  function _commit()
97  {
98  $connection = $this->_getConnection('master');
99  $this->_query("commit", $connection);
100  return true;
101  }
102 
111  {
112  if(!$connection)
113  {
114  exit('XE cannot handle DB connection.');
115  }
116  // Run the query statement
117  $result = @mysql_query($query, $connection);
118  // Error Check
119  if(mysql_error($connection))
120  {
121  $this->setError(mysql_errno($connection), mysql_error($connection));
122  }
123  // Return result
124  return $result;
125  }
126 
136  function _createTable($xml_doc)
137  {
138  // xml parsing
139  $oXml = new XmlParser();
140  $xml_obj = $oXml->parse($xml_doc);
141  // Create a table schema
142  $table_name = $xml_obj->table->attrs->name;
143  if($this->isTableExists($table_name))
144  {
145  return;
146  }
147  $table_name = $this->prefix . $table_name;
148 
149  if(!is_array($xml_obj->table->column))
150  {
151  $columns[] = $xml_obj->table->column;
152  }
153  else
154  {
155  $columns = $xml_obj->table->column;
156  }
157 
158  foreach($columns as $column)
159  {
160  $name = $column->attrs->name;
161  $type = $column->attrs->type;
162  $size = $column->attrs->size;
163  $notnull = $column->attrs->notnull;
164  $primary_key = $column->attrs->primary_key;
165  $index = $column->attrs->index;
166  $unique = $column->attrs->unique;
167  $default = $column->attrs->default;
168  $auto_increment = $column->attrs->auto_increment;
169 
170  $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' : '');
171 
172  if($primary_key)
173  {
174  $primary_list[] = $name;
175  }
176  else if($unique)
177  {
178  $unique_list[$unique][] = $name;
179  }
180  else if($index)
181  {
182  $index_list[$index][] = $name;
183  }
184  }
185 
186  if(count($primary_list))
187  {
188  $column_schema[] = sprintf("primary key (%s)", '`' . implode($primary_list, '`,`') . '`');
189  }
190 
191  if(count($unique_list))
192  {
193  foreach($unique_list as $key => $val)
194  {
195  $column_schema[] = sprintf("unique %s (%s)", $key, '`' . implode($val, '`,`') . '`');
196  }
197  }
198 
199  if(count($index_list))
200  {
201  foreach($index_list as $key => $val)
202  {
203  $column_schema[] = sprintf("index %s (%s)", $key, '`' . implode($val, '`,`') . '`');
204  }
205  }
206 
207  $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");
208 
209  $output = $this->_query($schema);
210  if(!$output)
211  {
212  return false;
213  }
214  }
215 
216 }
217 
218 DBMysql_innodb::$isSupported = function_exists('mysql_connect');
219 
220 /* End of file DBMysql_innodb.class.php */
221 /* Location: ./classes/db/DBMysql_innodb.class.php */
setError($errno=0, $errstr= 'success')
Definition: DB.class.php:476
static $isSupported
Definition: DB.class.php:19
_begin($transactionLevel=0)
$output
Definition: ko.install.php:193
$query
Definition: DB.class.php:84
addQuotes($string)
__query($query, $connection)
_connect($type= 'master', $indx=0)
Definition: DB.class.php:1266
_rollback($transactionLevel=0)
_getConnection($type= 'master', $indx=NULL)
Definition: DB.class.php:1001
_query($query, $connection=NULL)
Definition: DB.class.php:1193
__construct($auto_connect=TRUE)
$result
Definition: DB.class.php:66
isTableExists($target_name)
_setDBInfo()
Definition: DB.class.php:1216
$connection
Definition: DB.class.php:85