예제 #1
0
파일: DataTypeTest.php 프로젝트: cebe/chive
 /**
  * tests whether the method BaseType returns the correct values
  */
 public function testBaseType()
 {
     $types = array('bit(1)' => 'bit', 'tinyint(2)' => 'tinyint', 'bool' => 'bool', 'smallint(4)' => 'smallint', 'mediumint(8)' => 'mediumint', 'int(10)' => 'int', 'bigint(16)' => 'bigint', 'float(1)' => 'float', 'float' => 'float', 'float(1,1)' => 'float', 'double(14,4)' => 'double', 'decimal(3,5)' => 'decimal', 'char' => 'char', 'varchar(10)' => 'varchar', 'tinytext' => 'tinytext', 'text' => 'text', 'mediumtext' => 'mediumtext', 'longtext' => 'longtext', 'tinyblob' => 'tinyblob', 'blob' => 'blob', 'mediumblob' => 'mediumblob', 'longblob' => 'longblob', 'binary' => 'binary', 'varbinary' => 'varbinary', 'enum(1,2,3)' => 'enum', 'enum(\'1\',\'2\')' => 'enum', 'set(1,2,3)' => 'set', 'set(\'1\',\'2\')' => 'set', 'date' => 'date', 'date(YYYY-MM-DD)' => 'date', 'datetime(YYYY-MM-DD HH:MM:SS)' => 'datetime', 'datetime' => 'datetime', 'timestamp' => 'timestamp', 'time(HH:MM:SS)' => 'time', 'time' => 'time', 'year' => 'year');
     foreach ($types as $type => $expected) {
         $this->assertEquals($expected, DataType::getBaseType($type));
     }
 }
예제 #2
0
파일: formBody.php 프로젝트: cebe/chive
    ?>
	<tr>
		<?php 
    $columnName = CHtml::encode($column->name);
    ?>
		<td style="font-weight: bold;"><?php 
    echo $columnName;
    ?>
</td>
		<td><?php 
    echo strlen($column->dbType) > 50 ? substr($column->dbType, 0, 50) . "..." : $column->dbType;
    ?>
</td>
		<td>
			<?php 
    if (!in_array(DataType::getBaseType($column->dbType), array('set', 'enum'))) {
        ?>
			<?php 
        echo CHtml::dropDownList($columnName . '[function]', '', $functions);
        ?>
			<?php 
    }
    ?>
		</td>
		<td class="center">
			<?php 
    echo $column->allowNull ? CHtml::checkBox($columnName . '[null]', is_null($row->getAttribute($columnName))) : '';
    ?>
		</td>
		<td>
			<?php 
예제 #3
0
파일: SqlExporter.php 프로젝트: cebe/chive
 /**
  * Exports all rows of the given array and writes the dump to the output buffer.
  *
  * @param	array					array with identifiers of rows
  */
 private function exportRowData()
 {
     $db = Yii::app()->db;
     $pdo = $db->getPdoInstance();
     // Columns
     $cols = Column::model()->findAllByAttributes(array('TABLE_NAME' => $this->table, 'TABLE_SCHEMA' => $this->schema));
     $blobCols = array();
     // Create insert statement
     if ($this->settings['completeInserts']) {
         $columns = array();
         $i = 0;
         foreach ($cols as $col) {
             $columns[] = $db->quoteColumnName($col->COLUMN_NAME);
             if (in_array(DataType::getBaseType($col->DATA_TYPE), array('smallblob', 'blob', 'mediumblob', 'longblob'))) {
                 $blobCols[] = $i;
             }
             $i++;
         }
         $columns = ' (' . implode(', ', $columns) . ')';
     } else {
         $columns = '';
     }
     $insert = $this->settings['insertCommand'] . ($this->settings['delayedInserts'] ? ' DELAYED' : '') . ($this->settings['ignoreInserts'] ? ' IGNORE' : '') . ' INTO ' . $db->quoteTableName($this->table) . $columns . ' VALUES';
     // Find all rows
     $rowCount = count($this->rows);
     // Settings
     $hexBlobs = $this->settings['hexBlobs'];
     $rowsPerInsert = (int) $this->settings['rowsPerInsert'];
     // Cycle rows
     $i = 0;
     $k = 1;
     foreach ($this->rows as $row) {
         // Add comment
         if ($i == 0) {
             $this->comment('Data for table ' . $db->quoteTableName($this->table));
             echo "\n\n";
             echo $insert;
         }
         $attributes = $row->getAttributes();
         SqlUtil::FixRow($attributes);
         // Escape all contents
         foreach ($attributes as $key => $value) {
             if ($value === null) {
                 $attributes[$key] = 'NULL';
             } elseif ($hexBlobs && in_array($key, $blobCols) && $value) {
                 $attributes[$key] = '0x' . bin2hex($value);
             } else {
                 $attributes[$key] = $pdo->quote($value);
             }
         }
         // Add this row
         echo "\n  (", implode(', ', $attributes), ')';
         if ($i == $rowCount - 1) {
             echo ";\n\n";
         } elseif ($k == $rowsPerInsert) {
             echo ";\n\n", $insert;
             $k = 0;
         } else {
             echo ',';
         }
         $i++;
         $k++;
     }
 }
예제 #4
0
파일: CsvExporter.php 프로젝트: cebe/chive
 /**
  * Exports all rows of the given array and writes the dump to the output buffer.
  *
  * @param	array					array with identifiers of rows
  */
 private function exportRowData()
 {
     $db = Yii::app()->db;
     $pdo = $db->getPdoInstance();
     // Columns
     $cols = Column::model()->findAllByAttributes(array('TABLE_NAME' => $this->table, 'TABLE_SCHEMA' => $this->schema));
     $blobCols = array();
     $columns = array();
     $i = 0;
     foreach ($cols as $col) {
         $columns[] = $db->quoteColumnName($col->COLUMN_NAME);
         if (in_array(DataType::getBaseType($col->DATA_TYPE), array('smallblob', 'blob', 'mediumblob', 'longblob'))) {
             $blobCols[] = $i;
         }
         $i++;
     }
     $columns = implode($this->settings['fieldTerminator'], $columns);
     $insert = "";
     // Find all rows
     $rowCount = count($this->rows);
     // Settings
     $hexBlobs = $this->settings['hexBlobs'];
     $rowsPerInsert = (int) $this->settings['rowsPerInsert'];
     // Cycle rows
     $i = 0;
     $k = 1;
     foreach ($this->rows as $row) {
         if ($i == 0 && $this->settings['fieldsFirstRow']) {
             echo $columns;
         }
         $attributes = $row->getAttributes();
         SqlUtil::FixRow($attributes);
         // Escape all contents
         foreach ($attributes as $key => $value) {
             if ($value === null) {
                 $attributes[$key] = 'NULL';
             } elseif ($hexBlobs && in_array($key, $blobCols) && $value) {
                 $attributes[$key] = '0x' . bin2hex($value);
             } else {
                 $attributes[$key] = $this->settings['fieldEncloseString'] . addcslashes($value, $this->settings['fieldEncloseString']) . $this->settings['fieldEncloseString'];
             }
         }
         echo "\n", implode($this->settings['fieldTerminator'], $attributes);
         if ($i == $rowCount - 1) {
             echo "\n\n";
         }
         $i++;
         $k++;
     }
 }
예제 #5
0
파일: Column.php 프로젝트: cebe/chive
 public function getDataType()
 {
     return DataType::getBaseType($this->DATA_TYPE);
 }