r63387 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63386‎ | r63387 | r63388 >
Date:12:32, 8 March 2010
Author:demon
Status:deferred
Tags:
Comment:
Split Schema subclasses into their own files, rename from TypeSchema to SchemaType
Modified paths:
  • /branches/new-installer/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/new-installer/phase3/includes/db/SchemaBuilder.php (modified) (history)
  • /branches/new-installer/phase3/includes/db/SchemaMysql.php (added) (history)
  • /branches/new-installer/phase3/includes/db/SchemaOracle.php (added) (history)
  • /branches/new-installer/phase3/includes/db/SchemaSqlite.php (added) (history)

Diff [purge]

Index: branches/new-installer/phase3/includes/db/SchemaBuilder.php
@@ -67,7 +67,7 @@
6868 * @return SchemaBuilder subclass
6969 */
7070 public static function newFromType( $type ) {
71 - $class = ucfirst( strtolower( $type ) ) . 'Schema';
 71+ $class = 'Schema' . ucfirst( strtolower( $type ) );
7272 if ( !class_exists( $class ) ) {
7373 throw new Exception( "No such database class $class" );
7474 } else {
@@ -162,412 +162,3 @@
163163 */
164164 protected function adjustTablesForDatabase() {}
165165 }
166 -
167 -class MysqlSchema extends SchemaBuilder {
168 -
169 - public function getType() {
170 - return 'mysql';
171 - }
172 -
173 - protected function adjustTablesForDatabase() {
174 - $this->tables['searchindex'] = array(
175 - 'prefix' => 'si',
176 - 'fields' => array(
177 - 'page' => array(
178 - 'type' => 'int',
179 - 'signed' => false,
180 - 'null' => false,
181 - ),
182 - 'title' => array(
183 - 'type' => 'varchar',
184 - 'length' => 255,
185 - 'null' => false,
186 - 'default' => '',
187 - ),
188 - 'text' => array(
189 - 'type' => 'text',
190 - 'length' => 'medium',
191 - 'null' => false,
192 - ),
193 - ),
194 - 'indexes' => array(
195 - 'si_page' => array(
196 - 'UNIQUE', 'page',
197 - ),
198 - 'si_title' => array(
199 - 'FULLTEXT', 'title',
200 - ),
201 - 'si_text' => array(
202 - 'FULLTEXT', 'text',
203 - ),
204 - ),
205 - 'options' => array(
206 - 'engine' => 'MyISAM',
207 - ),
208 - );
209 -
210 - $this->tables['revision']['options'] = array(
211 - 'max_rows' => 10000000,
212 - 'avg_row_length' => 1024,
213 - );
214 -
215 - $this->tables['text']['options'] = array(
216 - 'max_rows' => 10000000,
217 - 'avg_row_length' => 10240,
218 - );
219 -
220 - $this->tables['hitcounter']['options'] = array(
221 - 'max_rows' => 25000,
222 - 'engine' => 'HEAP',
223 - );
224 - }
225 -
226 - /**
227 - * @see SchemaBuilder::createTable()
228 - */
229 - protected function createTable( $name, $def ) {
230 - $prefix = $def['prefix'] ? $def['prefix'] . '_' : '';
231 - $tblName = $this->tblPrefix . $name;
232 - $opts = isset( $def['options'] ) ? $def['options'] : array();
233 - $sql = "CREATE TABLE `$tblName` (";
234 - foreach( $def['fields'] as $field => $attribs ) {
235 - $sql .= "\n\t{$prefix}{$field} " . $this->getFieldDefinition( $attribs );
236 - }
237 - $sql = rtrim( $sql, ',' );
238 - $sql .= "\n) " . $this->getTableOptions( $opts ) . ";\n";
239 - if( isset( $def['indexes'] ) ) {
240 - foreach( $def['indexes'] as $idx => $idxDef ) {
241 - if( $idxDef[0] === 'UNIQUE' ) {
242 - array_shift( $idxDef );
243 - $sql .= "CREATE UNIQUE INDEX ";
244 - } elseif( $idxDef[0] == 'FULLTEXT' ) {
245 - array_shift( $idxDef );
246 - $sql .= "CREATE FULLTEXT INDEX ";
247 - } else {
248 - $sql .= "CREATE INDEX ";
249 - }
250 - $sql .= "{$this->tblPrefix}{$idx} ON $tblName (";
251 - foreach( $idxDef as $col ) {
252 - $sql .= "{$prefix}{$col}, ";
253 - }
254 - $sql = rtrim( $sql, ', ' );
255 - $sql .= ");\n";
256 - }
257 - }
258 - return $sql . "\n";
259 - }
260 -
261 - /**
262 - * Given an abstract field definition, return a MySQL-specific definition.
263 - * @param $attribs Array An abstract table definition
264 - * @return String
265 - */
266 - private function getFieldDefinition( $attribs ) {
267 - if( !isset( $attribs['type'] ) ) {
268 - $this->isOk = false;
269 - throw new Exception( "No type specified for field" );
270 - }
271 - $fieldType = $attribs['type'];
272 - $def = '';
273 - switch( $fieldType ) {
274 - case 'int':
275 - $def = 'int';
276 - if( isset( $attribs['length'] ) ) {
277 - $def = $attribs['length'] . $def;
278 - }
279 - break;
280 - case 'varchar':
281 - $def = 'varchar(' . $attribs['length'] . ')';
282 - break;
283 - case 'char':
284 - $def = 'char(' . $attribs['length'] . ')';
285 - break;
286 - case 'datetime':
287 - $def = 'binary(14)';
288 - break;
289 - case 'text':
290 - $def = 'text';
291 - if( isset( $attribs['length'] ) ) {
292 - $def = $attribs['length'] . $def;
293 - }
294 - break;
295 - case 'blob':
296 - $def = 'blob';
297 - if( isset( $attribs['length'] ) ) {
298 - $def = $attribs['length'] . $def;
299 - }
300 - break;
301 - case 'binary':
302 - $def = 'binary(' . $attribs['length'] . ')';
303 - break;
304 - case 'varbinary':
305 - $def = 'varbinary(' . $attribs['length'] . ')';
306 - break;
307 - case 'bool':
308 - $def = 'bool';
309 - break;
310 - case 'enum':
311 - $def = 'ENUM("' . implode( '", "', $attribs['values'] );
312 - $def = rtrim( $def, ', "' ) . '")';
313 - break;
314 - case 'float':
315 - $def = 'float';
316 - break;
317 - case 'real':
318 - $def = 'real';
319 - break;
320 - default:
321 - $this->isOk = false;
322 - }
323 - if( isset( $attribs['signed'] ) ) {
324 - $def .= $attribs['signed'] ? ' signed' : ' unsigned';
325 - }
326 - if( isset( $attribs['binary'] ) && $attribs['binary'] ) {
327 - $def = $def . ' binary';
328 - }
329 - if( isset( $attribs['null'] ) ) {
330 - $def .= $attribs['null'] ? ' NULL' : ' NOT NULL';
331 - }
332 - // Use array_key_exists() since 'default' might be set to null
333 - if( array_key_exists( 'default', $attribs ) ) {
334 - if( $attribs['default'] === null ) {
335 - $def .= ' default NULL';
336 - } else {
337 - $def .= " default '" . $attribs['default'] . "'";
338 - }
339 - }
340 - if( isset( $attribs['primary-key'] ) && $attribs['primary-key'] ) {
341 - $def .= " PRIMARY KEY";
342 - }
343 - if( isset( $attribs['auto-increment'] ) && $attribs['auto-increment'] ) {
344 - $def .= " AUTO_INCREMENT";
345 - }
346 - return $def . ",";
347 - }
348 -
349 - private function getTableOptions( $opts ) {
350 - $opts = array_merge( $this->tblOptions, $opts );
351 - $ret = array();
352 - foreach( $opts as $name => $value ) {
353 - $ret[] = strtoupper( $name ) . "=$value";
354 - }
355 - return implode( ', ', $ret );
356 - }
357 -
358 - protected function updateTable( $name, $definition, $db ) {
359 - return '';
360 - }
361 -}
362 -
363 -class SqliteSchema extends SchemaBuilder {
364 - static $typeMapping = array(
365 - 'int' => 'INTEGER',
366 - 'varchar' => 'TEXT',
367 - 'datetime' => 'TEXT',
368 - 'text' => 'TEXT',
369 - 'blob' => 'BLOB',
370 - 'binary' => 'BLOB',
371 - 'varbinary' => 'BLOB',
372 - 'bool' => 'INTEGER',
373 - 'enum' => 'BLOB',
374 - 'float' => 'REAL',
375 - 'real' => 'REAL',
376 - 'char' => 'TEXT',
377 - 'none' => '',
378 - );
379 -
380 - public function getType() {
381 - return 'sqlite';
382 - }
383 -
384 - /**
385 - * @todo: update updatelog with fts3
386 - */
387 - protected function adjustTablesForDatabase() {
388 - $db = new DatabaseSqliteStandalone( ':memory:' );
389 - if ( $db->getFulltextSearchModule() == 'FTS3' ) {
390 - $this->tables['searchindex'] = array(
391 - 'prefix' => 'si',
392 - 'virtual' => 'FTS3',
393 - 'fields' => array(
394 - 'title' => array(
395 - 'type' => 'none',
396 - ),
397 - 'text' => array(
398 - 'type' => 'none',
399 - ),
400 - )
401 - );
402 - } else {
403 - $this->tables['searchindex'] = array(
404 - 'prefix' => 'si',
405 - 'fields' => array(
406 - 'title' => array(
407 - 'type' => 'text',
408 - ),
409 - 'text' => array(
410 - 'type' => 'text',
411 - ),
412 - )
413 - );
414 - $this->tablesToDelete = array_merge( $this->tablesToDelete,
415 - array( 'searchindex_content', 'searchindex_segdir', 'searchindex_segments' )
416 - );
417 - }
418 - $db->close();
419 - }
420 -
421 - protected function createTable( $name, $def ) {
422 - $prefix = $def['prefix'] ? $def['prefix'] . '_' : '';
423 - $tblName = $this->tblPrefix . $name;
424 - $virtual = isset ( $def['virtual'] ) ? $def['virtual'] : false;
425 - if ( $virtual ) {
426 - $sql = "CREATE VIRTUAL TABLE `$tblName` USING $virtual (";
427 - } else {
428 - $sql = "CREATE TABLE `$tblName` (";
429 - }
430 - foreach( $def['fields'] as $field => $attribs ) {
431 - $sql .= "\n\t{$prefix}{$field} " . $this->getFieldDefinition( $attribs );
432 - }
433 - $sql = rtrim( $sql, ',' );
434 - $sql .= "\n);\n";
435 - if( isset( $def['indexes'] ) ) {
436 - foreach( $def['indexes'] as $idx => $idxDef ) {
437 - if( $idxDef[0] === 'UNIQUE' ) {
438 - array_shift( $idxDef );
439 - $sql .= "CREATE UNIQUE INDEX ";
440 - } elseif( $idxDef[0] == 'FULLTEXT' ) {
441 - continue; // no thanks
442 - } else {
443 - $sql .= "CREATE INDEX ";
444 - }
445 - $sql .= "{$this->tblPrefix}{$idx} ON $tblName (";
446 - foreach( $idxDef as $col ) {
447 - $sql .= "{$prefix}{$col}, ";
448 - }
449 - $sql = rtrim( $sql, ', ' );
450 - $sql .= ");\n";
451 - }
452 - }
453 - return $sql . "\n";
454 - }
455 -
456 - /**
457 - * Given an abstract field definition, return a MySQL-specific definition.
458 - * @param $attribs Array An abstract table definition
459 - * @return String
460 - */
461 - private function getFieldDefinition( $attribs ) {
462 - $type = $attribs['type'];
463 - if ( !isset( self::$typeMapping[$type] ) ) {
464 - throw new MWException( "Unknown type $type" );
465 - }
466 - $def = self::$typeMapping[$type];
467 - if( isset( $attribs['null'] ) ) {
468 - $def .= $attribs['null'] ? ' NULL' : ' NOT NULL';
469 - }
470 - // Use array_key_exists() since 'default' might be set to null
471 - if( array_key_exists( 'default', $attribs ) ) {
472 - if( $attribs['default'] === null ) {
473 - $def .= ' default NULL';
474 - } else {
475 - $def .= " DEFAULT '" . $attribs['default'] . "'";
476 - }
477 - } if( isset( $attribs['primary-key'] ) && $attribs['primary-key'] ) {
478 - $def .= ' PRIMARY KEY';
479 - }
480 - if( isset( $attribs['auto-increment'] ) && $attribs['auto-increment'] ) {
481 - $def .= ' AUTOINCREMENT';
482 - }
483 - return $def . ',';
484 - }
485 -
486 - protected function updateTable( $name, $definition, $db ) {
487 - return '';
488 - }
489 -}
490 -
491 -class OracleSchema extends SchemaBuilder {
492 -
493 - public function getType() {
494 - return 'oracle';
495 - }
496 -
497 - protected function adjustTablesForDatabase() {
498 - $this->tables['searchindex'] = array(
499 - 'prefix' => 'si',
500 - 'fields' => array(
501 - 'page' => array(
502 - 'type' => 'int',
503 - 'null' => false,
504 - ),
505 - 'title' => array(
506 - 'type' => 'varchar',
507 - 'length' => 255,
508 - 'null' => false,
509 - 'default' => '',
510 - ),
511 - 'text' => array(
512 - 'type' => 'text',
513 - 'null' => false,
514 - ),
515 - ),
516 - 'indexes' => array(
517 - 'si_page' => array(
518 - 'UNIQUE', 'page',
519 - ),
520 - 'si_title' => array(
521 - 'CTXSYS.CONTEXT', 'title',
522 - ),
523 - 'si_text' => array(
524 - 'CTXSYS.CONTEXT', 'text',
525 - ),
526 - ),
527 - );
528 - }
529 -
530 - protected function createTable( $name, $def ) {
531 - $prefix = $def['prefix'] ? $def['prefix'] . '_' : '';
532 - $tblName = $this->tblPrefix . $name;
533 -
534 - $sql = "CREATE TABLE $tblName (";
535 - foreach( $def['fields'] as $field => $attribs ) {
536 - $sql .= "\n\t{$prefix}{$field} " . $this->getFieldDefinition( $attribs );
537 - }
538 - $sql = rtrim( $sql, ',' );
539 - $sql .= ");\n";
540 -
541 - $idx_i = 0;
542 - $idx_u = 0;
543 - if( isset( $def['indexes'] ) ) {
544 - foreach( $def['indexes'] as $idx => $idxDef ) {
545 - $idxType = '';
546 - if (isset($idxDef[1])) {
547 - $idxType = array_shift( $idxDef );
548 - }
549 -
550 - if( $idxType === 'UNIQUE' ) {
551 - $sql .= "CREATE UNIQUE INDEX {$tblName}_u".
552 - str_pad(++$idx_u, 2, "0", STR_PAD_LEFT).
553 - " ON {$tblName} (";
554 - } elseif ($idxType !== '') {
555 - $sql .= "CREATE INDEX {$this->tblPrefix}{$idx} ON {$tblName} (";
556 - } else {
557 - $sql .= "CREATE INDEX {$tblName}_u".
558 - str_pad(++$idx_i, 2, "0", STR_PAD_LEFT).
559 - " ON {$tblName} (";
560 - }
561 -
562 - foreach( $idxDef as $col ) {
563 - $sql .= "{$prefix}{$col}, ";
564 - }
565 - $sql = rtrim( $sql, ', ' );
566 - $sql .= ");\n";
567 - }
568 - }
569 - return $sql . "\n";
570 - }
571 -
572 - protected function updateTable( $name, $definition, $db ) {}
573 -
574 -}
Index: branches/new-installer/phase3/includes/db/SchemaSqlite.php
@@ -0,0 +1,129 @@
 2+<?php
 3+
 4+class SchemaSqlite extends SchemaBuilder {
 5+ static $typeMapping = array(
 6+ 'int' => 'INTEGER',
 7+ 'varchar' => 'TEXT',
 8+ 'datetime' => 'TEXT',
 9+ 'text' => 'TEXT',
 10+ 'blob' => 'BLOB',
 11+ 'binary' => 'BLOB',
 12+ 'varbinary' => 'BLOB',
 13+ 'bool' => 'INTEGER',
 14+ 'enum' => 'BLOB',
 15+ 'float' => 'REAL',
 16+ 'real' => 'REAL',
 17+ 'char' => 'TEXT',
 18+ 'none' => '',
 19+ );
 20+
 21+ public function getType() {
 22+ return 'sqlite';
 23+ }
 24+
 25+ /**
 26+ * @todo: update updatelog with fts3
 27+ */
 28+ protected function adjustTablesForDatabase() {
 29+ $db = new DatabaseSqliteStandalone( ':memory:' );
 30+ if ( $db->getFulltextSearchModule() == 'FTS3' ) {
 31+ $this->tables['searchindex'] = array(
 32+ 'prefix' => 'si',
 33+ 'virtual' => 'FTS3',
 34+ 'fields' => array(
 35+ 'title' => array(
 36+ 'type' => 'none',
 37+ ),
 38+ 'text' => array(
 39+ 'type' => 'none',
 40+ ),
 41+ )
 42+ );
 43+ } else {
 44+ $this->tables['searchindex'] = array(
 45+ 'prefix' => 'si',
 46+ 'fields' => array(
 47+ 'title' => array(
 48+ 'type' => 'text',
 49+ ),
 50+ 'text' => array(
 51+ 'type' => 'text',
 52+ ),
 53+ )
 54+ );
 55+ $this->tablesToDelete = array_merge( $this->tablesToDelete,
 56+ array( 'searchindex_content', 'searchindex_segdir', 'searchindex_segments' )
 57+ );
 58+ }
 59+ $db->close();
 60+ }
 61+
 62+ protected function createTable( $name, $def ) {
 63+ $prefix = $def['prefix'] ? $def['prefix'] . '_' : '';
 64+ $tblName = $this->tblPrefix . $name;
 65+ $virtual = isset ( $def['virtual'] ) ? $def['virtual'] : false;
 66+ if ( $virtual ) {
 67+ $sql = "CREATE VIRTUAL TABLE `$tblName` USING $virtual (";
 68+ } else {
 69+ $sql = "CREATE TABLE `$tblName` (";
 70+ }
 71+ foreach( $def['fields'] as $field => $attribs ) {
 72+ $sql .= "\n\t{$prefix}{$field} " . $this->getFieldDefinition( $attribs );
 73+ }
 74+ $sql = rtrim( $sql, ',' );
 75+ $sql .= "\n);\n";
 76+ if( isset( $def['indexes'] ) ) {
 77+ foreach( $def['indexes'] as $idx => $idxDef ) {
 78+ if( $idxDef[0] === 'UNIQUE' ) {
 79+ array_shift( $idxDef );
 80+ $sql .= "CREATE UNIQUE INDEX ";
 81+ } elseif( $idxDef[0] == 'FULLTEXT' ) {
 82+ continue; // no thanks
 83+ } else {
 84+ $sql .= "CREATE INDEX ";
 85+ }
 86+ $sql .= "{$this->tblPrefix}{$idx} ON $tblName (";
 87+ foreach( $idxDef as $col ) {
 88+ $sql .= "{$prefix}{$col}, ";
 89+ }
 90+ $sql = rtrim( $sql, ', ' );
 91+ $sql .= ");\n";
 92+ }
 93+ }
 94+ return $sql . "\n";
 95+ }
 96+
 97+ /**
 98+ * Given an abstract field definition, return a MySQL-specific definition.
 99+ * @param $attribs Array An abstract table definition
 100+ * @return String
 101+ */
 102+ private function getFieldDefinition( $attribs ) {
 103+ $type = $attribs['type'];
 104+ if ( !isset( self::$typeMapping[$type] ) ) {
 105+ throw new MWException( "Unknown type $type" );
 106+ }
 107+ $def = self::$typeMapping[$type];
 108+ if( isset( $attribs['null'] ) ) {
 109+ $def .= $attribs['null'] ? ' NULL' : ' NOT NULL';
 110+ }
 111+ // Use array_key_exists() since 'default' might be set to null
 112+ if( array_key_exists( 'default', $attribs ) ) {
 113+ if( $attribs['default'] === null ) {
 114+ $def .= ' default NULL';
 115+ } else {
 116+ $def .= " DEFAULT '" . $attribs['default'] . "'";
 117+ }
 118+ } if( isset( $attribs['primary-key'] ) && $attribs['primary-key'] ) {
 119+ $def .= ' PRIMARY KEY';
 120+ }
 121+ if( isset( $attribs['auto-increment'] ) && $attribs['auto-increment'] ) {
 122+ $def .= ' AUTOINCREMENT';
 123+ }
 124+ return $def . ',';
 125+ }
 126+
 127+ protected function updateTable( $name, $definition, $db ) {
 128+ return '';
 129+ }
 130+}
Property changes on: branches/new-installer/phase3/includes/db/SchemaSqlite.php
___________________________________________________________________
Name: svn:eol-style
1131 + native
Index: branches/new-installer/phase3/includes/db/SchemaMysql.php
@@ -0,0 +1,197 @@
 2+<?php
 3+
 4+class SchemaMysql extends SchemaBuilder {
 5+
 6+ public function getType() {
 7+ return 'mysql';
 8+ }
 9+
 10+ protected function adjustTablesForDatabase() {
 11+ $this->tables['searchindex'] = array(
 12+ 'prefix' => 'si',
 13+ 'fields' => array(
 14+ 'page' => array(
 15+ 'type' => 'int',
 16+ 'signed' => false,
 17+ 'null' => false,
 18+ ),
 19+ 'title' => array(
 20+ 'type' => 'varchar',
 21+ 'length' => 255,
 22+ 'null' => false,
 23+ 'default' => '',
 24+ ),
 25+ 'text' => array(
 26+ 'type' => 'text',
 27+ 'length' => 'medium',
 28+ 'null' => false,
 29+ ),
 30+ ),
 31+ 'indexes' => array(
 32+ 'si_page' => array(
 33+ 'UNIQUE', 'page',
 34+ ),
 35+ 'si_title' => array(
 36+ 'FULLTEXT', 'title',
 37+ ),
 38+ 'si_text' => array(
 39+ 'FULLTEXT', 'text',
 40+ ),
 41+ ),
 42+ 'options' => array(
 43+ 'engine' => 'MyISAM',
 44+ ),
 45+ );
 46+
 47+ $this->tables['revision']['options'] = array(
 48+ 'max_rows' => 10000000,
 49+ 'avg_row_length' => 1024,
 50+ );
 51+
 52+ $this->tables['text']['options'] = array(
 53+ 'max_rows' => 10000000,
 54+ 'avg_row_length' => 10240,
 55+ );
 56+
 57+ $this->tables['hitcounter']['options'] = array(
 58+ 'max_rows' => 25000,
 59+ 'engine' => 'HEAP',
 60+ );
 61+ }
 62+
 63+ /**
 64+ * @see SchemaBuilder::createTable()
 65+ */
 66+ protected function createTable( $name, $def ) {
 67+ $prefix = $def['prefix'] ? $def['prefix'] . '_' : '';
 68+ $tblName = $this->tblPrefix . $name;
 69+ $opts = isset( $def['options'] ) ? $def['options'] : array();
 70+ $sql = "CREATE TABLE `$tblName` (";
 71+ foreach( $def['fields'] as $field => $attribs ) {
 72+ $sql .= "\n\t{$prefix}{$field} " . $this->getFieldDefinition( $attribs );
 73+ }
 74+ $sql = rtrim( $sql, ',' );
 75+ $sql .= "\n) " . $this->getTableOptions( $opts ) . ";\n";
 76+ if( isset( $def['indexes'] ) ) {
 77+ foreach( $def['indexes'] as $idx => $idxDef ) {
 78+ if( $idxDef[0] === 'UNIQUE' ) {
 79+ array_shift( $idxDef );
 80+ $sql .= "CREATE UNIQUE INDEX ";
 81+ } elseif( $idxDef[0] == 'FULLTEXT' ) {
 82+ array_shift( $idxDef );
 83+ $sql .= "CREATE FULLTEXT INDEX ";
 84+ } else {
 85+ $sql .= "CREATE INDEX ";
 86+ }
 87+ $sql .= "{$this->tblPrefix}{$idx} ON $tblName (";
 88+ foreach( $idxDef as $col ) {
 89+ $sql .= "{$prefix}{$col}, ";
 90+ }
 91+ $sql = rtrim( $sql, ', ' );
 92+ $sql .= ");\n";
 93+ }
 94+ }
 95+ return $sql . "\n";
 96+ }
 97+
 98+ /**
 99+ * Given an abstract field definition, return a MySQL-specific definition.
 100+ * @param $attribs Array An abstract table definition
 101+ * @return String
 102+ */
 103+ private function getFieldDefinition( $attribs ) {
 104+ if( !isset( $attribs['type'] ) ) {
 105+ $this->isOk = false;
 106+ throw new Exception( "No type specified for field" );
 107+ }
 108+ $fieldType = $attribs['type'];
 109+ $def = '';
 110+ switch( $fieldType ) {
 111+ case 'int':
 112+ $def = 'int';
 113+ if( isset( $attribs['length'] ) ) {
 114+ $def = $attribs['length'] . $def;
 115+ }
 116+ break;
 117+ case 'varchar':
 118+ $def = 'varchar(' . $attribs['length'] . ')';
 119+ break;
 120+ case 'char':
 121+ $def = 'char(' . $attribs['length'] . ')';
 122+ break;
 123+ case 'datetime':
 124+ $def = 'binary(14)';
 125+ break;
 126+ case 'text':
 127+ $def = 'text';
 128+ if( isset( $attribs['length'] ) ) {
 129+ $def = $attribs['length'] . $def;
 130+ }
 131+ break;
 132+ case 'blob':
 133+ $def = 'blob';
 134+ if( isset( $attribs['length'] ) ) {
 135+ $def = $attribs['length'] . $def;
 136+ }
 137+ break;
 138+ case 'binary':
 139+ $def = 'binary(' . $attribs['length'] . ')';
 140+ break;
 141+ case 'varbinary':
 142+ $def = 'varbinary(' . $attribs['length'] . ')';
 143+ break;
 144+ case 'bool':
 145+ $def = 'bool';
 146+ break;
 147+ case 'enum':
 148+ $def = 'ENUM("' . implode( '", "', $attribs['values'] );
 149+ $def = rtrim( $def, ', "' ) . '")';
 150+ break;
 151+ case 'float':
 152+ $def = 'float';
 153+ break;
 154+ case 'real':
 155+ $def = 'real';
 156+ break;
 157+ default:
 158+ $this->isOk = false;
 159+ }
 160+ if( isset( $attribs['signed'] ) ) {
 161+ $def .= $attribs['signed'] ? ' signed' : ' unsigned';
 162+ }
 163+ if( isset( $attribs['binary'] ) && $attribs['binary'] ) {
 164+ $def = $def . ' binary';
 165+ }
 166+ if( isset( $attribs['null'] ) ) {
 167+ $def .= $attribs['null'] ? ' NULL' : ' NOT NULL';
 168+ }
 169+ // Use array_key_exists() since 'default' might be set to null
 170+ if( array_key_exists( 'default', $attribs ) ) {
 171+ if( $attribs['default'] === null ) {
 172+ $def .= ' default NULL';
 173+ } else {
 174+ $def .= " default '" . $attribs['default'] . "'";
 175+ }
 176+ }
 177+ if( isset( $attribs['primary-key'] ) && $attribs['primary-key'] ) {
 178+ $def .= " PRIMARY KEY";
 179+ }
 180+ if( isset( $attribs['auto-increment'] ) && $attribs['auto-increment'] ) {
 181+ $def .= " AUTO_INCREMENT";
 182+ }
 183+ return $def . ",";
 184+ }
 185+
 186+ private function getTableOptions( $opts ) {
 187+ $opts = array_merge( $this->tblOptions, $opts );
 188+ $ret = array();
 189+ foreach( $opts as $name => $value ) {
 190+ $ret[] = strtoupper( $name ) . "=$value";
 191+ }
 192+ return implode( ', ', $ret );
 193+ }
 194+
 195+ protected function updateTable( $name, $definition, $db ) {
 196+ return '';
 197+ }
 198+}
Property changes on: branches/new-installer/phase3/includes/db/SchemaMysql.php
___________________________________________________________________
Name: svn:eol-style
1199 + native
Index: branches/new-installer/phase3/includes/db/SchemaOracle.php
@@ -0,0 +1,86 @@
 2+<?php
 3+
 4+class SchemaOracle extends SchemaBuilder {
 5+
 6+ public function getType() {
 7+ return 'oracle';
 8+ }
 9+
 10+ protected function adjustTablesForDatabase() {
 11+ $this->tables['searchindex'] = array(
 12+ 'prefix' => 'si',
 13+ 'fields' => array(
 14+ 'page' => array(
 15+ 'type' => 'int',
 16+ 'null' => false,
 17+ ),
 18+ 'title' => array(
 19+ 'type' => 'varchar',
 20+ 'length' => 255,
 21+ 'null' => false,
 22+ 'default' => '',
 23+ ),
 24+ 'text' => array(
 25+ 'type' => 'text',
 26+ 'null' => false,
 27+ ),
 28+ ),
 29+ 'indexes' => array(
 30+ 'si_page' => array(
 31+ 'UNIQUE', 'page',
 32+ ),
 33+ 'si_title' => array(
 34+ 'CTXSYS.CONTEXT', 'title',
 35+ ),
 36+ 'si_text' => array(
 37+ 'CTXSYS.CONTEXT', 'text',
 38+ ),
 39+ ),
 40+ );
 41+ }
 42+
 43+ protected function createTable( $name, $def ) {
 44+$prefix = $def['prefix'] ? $def['prefix'] . '_' : '';
 45+$tblName = $this->tblPrefix . $name;
 46+
 47+$sql = "CREATE TABLE $tblName (";
 48+foreach( $def['fields'] as $field => $attribs ) {
 49+$sql .= "\n\t{$prefix}{$field} " . $this->getFieldDefinition( $attribs );
 50+}
 51+$sql = rtrim( $sql, ',' );
 52+$sql .= ");\n";
 53+
 54+ $idx_i = 0;
 55+ $idx_u = 0;
 56+if( isset( $def['indexes'] ) ) {
 57+foreach( $def['indexes'] as $idx => $idxDef ) {
 58+$idxType = '';
 59+if (isset($idxDef[1])) {
 60+ $idxType = array_shift( $idxDef );
 61+ }
 62+
 63+if( $idxType === 'UNIQUE' ) {
 64+$sql .= "CREATE UNIQUE INDEX {$tblName}_u".
 65+ str_pad(++$idx_u, 2, "0", STR_PAD_LEFT).
 66+ " ON {$tblName} (";
 67+} elseif ($idxType !== '') {
 68+$sql .= "CREATE INDEX {$this->tblPrefix}{$idx} ON {$tblName} (";
 69+} else {
 70+$sql .= "CREATE INDEX {$tblName}_u".
 71+ str_pad(++$idx_i, 2, "0", STR_PAD_LEFT).
 72+ " ON {$tblName} (";
 73+ }
 74+
 75+foreach( $idxDef as $col ) {
 76+$sql .= "{$prefix}{$col}, ";
 77+}
 78+$sql = rtrim( $sql, ', ' );
 79+$sql .= ");\n";
 80+}
 81+}
 82+return $sql . "\n";
 83+}
 84+
 85+ protected function updateTable( $name, $definition, $db ) {}
 86+
 87+}
Property changes on: branches/new-installer/phase3/includes/db/SchemaOracle.php
___________________________________________________________________
Name: svn:eol-style
188 + native
Index: branches/new-installer/phase3/includes/AutoLoader.php
@@ -380,6 +380,9 @@
381381 'ResultWrapper' => 'includes/db/Database.php',
382382 'Schema' => 'includes/db/Schema.php',
383383 'SchemaBuilder' => 'includes/db/SchemaBuilder.php',
 384+ 'SchemaMysql' => 'includes/db/SchemaMysql.php',
 385+ 'SchemaOracle' => 'includes/db/SchemaOracle.php',
 386+ 'SchemaSqlite' => 'includes/db/SchemaSqlite.php',
384387 'SQLiteField' => 'includes/db/DatabaseSqlite.php',
385388 'DatabaseIbm_db2' => 'includes/db/DatabaseIbm_db2.php',
386389 'IBM_DB2Field' => 'includes/db/DatabaseIbm_db2.php',

Status & tagging log