示例#1
0
 /**
  * Добавление поля node.xml2 для хранения дерева.
  * @mcms_message ru.molinos.cms.install
  */
 public static function on_install(Context $ctx)
 {
     $t = new TableInfo($ctx->db, 'node');
     if (!$t->columnExists('xmltree')) {
         $t->columnSet('xmltree', array('type' => 'longblob'));
         $t->commit();
     }
 }
示例#2
0
 public function testTableInfoAddColumn()
 {
     $db = get_test_context()->db;
     $t = new TableInfo($db, self::tbl);
     $t->columnSet('value', array('type' => 'text'));
     $t->commit();
     $t = new TableInfo($db, self::tbl);
     $this->assertEquals(2, $t->columnCount());
 }
示例#3
0
 /**
  * Проверяет структуру таблицы.
  */
 public static function check($tableName, array $columns)
 {
     Logger::log("checking({$tableName}): " . implode(', ', array_keys($columns)) . '.');
     $t = new TableInfo(Context::last()->db, $tableName);
     foreach ($columns as $k => $v) {
         // FIXME: на переходном этапе конвертируем структуру, вообще надо её понимать сразу правильно.
         switch ($v['type']) {
             case 'decimal':
                 $v['type'] = $v['type'] . '(' . $v['length'] . ',' . $v['precision'];
                 break;
             case 'bool':
                 $v['type'] = 'tinyint(1)';
                 break;
             case 'char':
             case 'varchar':
                 $v['type'] = $v['type'] . '(' . $v['length'] . ')';
                 break;
             case 'text':
                 $v['type'] = 'mediumtext';
                 break;
             case 'blob':
                 $v['type'] = 'mediumblob';
                 break;
         }
         if (!empty($v['primary'])) {
             $v['key'] = 'pri';
         } elseif (!empty($v['indexed'])) {
             $v['key'] = 'mul';
         }
         $t->columnSet($k, $v);
     }
     $t->commit();
 }