Exemplo n.º 1
0
function setNewPrimaryKeys($db, $table, $newKeys, $indexSizes)
{
    $sqlSetNewPrimaryKeys = "ALTER TABLE `" . $db . "`.`" . $table . "`";
    //wenn es Primaerschluessel gibt, diese loeschen
    $existingKeys = getPrimaryKeys($db, $table);
    if (count($existingKeys) > 0) {
        $sqlSetNewPrimaryKeys .= " DROP PRIMARY KEY";
    }
    //wenn min. 1 Schluessel im Array, sonst nur loeschen
    if (count($newKeys) > 0) {
        if (count($existingKeys) > 0) {
            $sqlSetNewPrimaryKeys .= ", ";
        }
        $sqlSetNewPrimaryKeys .= " ADD PRIMARY KEY (";
        foreach ($newKeys as $id => $name) {
            if ($id > 0) {
                $sqlSetNewPrimaryKeys .= ", ";
            }
            $sqlSetNewPrimaryKeys .= "`" . $name . "`";
            if ($indexSizes[$id]) {
                $sqlSetNewPrimaryKeys .= " (" . $indexSizes[$id] . ")";
            }
        }
        $sqlSetNewPrimaryKeys .= ")";
    }
    $sqlSetNewPrimaryKeys .= ";";
    $res = MSD_query($sqlSetNewPrimaryKeys);
    return $res;
}
Exemplo n.º 2
0
 //kopf
 echo '<table class="bdr"><tr class="thead"><th>' . $lang['L_PRIMARYKEY_FIELD'] . '</th></tr>';
 //body
 $sqlFelder = "DESCRIBE `" . $databases['Name'][$dbid] . "`.`" . $_GET['tablename'] . "`;";
 $res = MSD_query($sqlFelder);
 $num = mysql_numrows($res);
 if ($num == 0) {
     echo '<tr><td>' . $lang['L_SQL_TABLENOINDEXES'] . '</td></tr>';
 } else {
     //alle Felder holen
     $feldArray = array();
     while ($row = mysql_fetch_array($res)) {
         $feldArray[$row['Field']] = $row['Type'];
     }
     //Primaerschluessel holen, um automatisch vorzuselektieren
     $primaryKeys = getPrimaryKeys($databases['Name'][$dbid], $_GET['tablename']);
     //eine Select-Box pro Feld anzeigen
     for ($i = 0; $i < $num; $i++) {
         $cl = $i % 2 ? "dbrow" : "dbrow1";
         echo '<tr class="' . $cl . '">';
         echo '<td>';
         echo '<select name="setNewPrimKey' . $i . '">';
         echo '<option value="">---</option>';
         foreach ($feldArray as $feldName => $feldTyp) {
             echo '<option value="' . $feldName . '"';
             //alle Primaerschluessel vorselektieren
             if (isset($primaryKeys[$i]) && $primaryKeys[$i] == $feldName) {
                 echo ' selected="selected"';
             }
             echo '>' . $feldName . ' [' . $feldTyp . ']</option>';
         }
Exemplo n.º 3
0
$dbParams = $config->resources->db->params;
$options = array();
$options['infoSchema'] = Zend_Db::factory('Pdo_Mysql', array('host' => $dbParams->host, 'username' => $dbParams->username, 'password' => $dbParams->password, 'dbname' => 'information_schema'));
$options['schema'] = $dbParams->dbname;
$options['nameFilter'] = new Zend_Filter_Word_UnderscoreToCamelCase();
$options['tableClassPrefix'] = $dbParams->tableNamespace . (substr($dbParams->tableNamespace, -1) == '_' ? '' : '_');
$options['rowClassPrefix'] = $options['tableClassPrefix'] . 'Row_';
$options['baseTableClass'] = $options['tableClassPrefix'] . 'Abstract';
$options['baseRowClass'] = $options['rowClassPrefix'] . 'Abstract';
$db = Zend_Db_Table::getDefaultAdapter();
$tables = $db->listTables();
foreach ($tables as $table) {
    $modelName = ucfirst($options['nameFilter']->filter($table));
    $tableClass = $options['tableClassPrefix'] . $modelName;
    $content = "  protected \$_name         = '{$table}';\n";
    $pk = getPrimaryKeys($table, $options);
    if (count($pk) > 1 || !isSequence($table, $pk[0], $options)) {
        $content .= "  protected \$_sequence     = false;\n";
    }
    $pk = "array('" . implode("','", $pk) . "')";
    $content .= "  protected \$_primary      = {$pk};\n";
    $ok = getOrderKeys($table, $options);
    if (count($ok) > 0) {
        $ok = "array('" . implode("','", $ok) . "')";
        $content .= "  protected \$_defaultOrder = {$ok};\n";
    }
    $rowClass = $options['baseRowClass'];
    $fks = getForeignKeys($table, $options);
    if (count($fks) > 0) {
        $content .= "  protected \$_referenceMap = array(\n";
        foreach ($fks as $fkID => $fk) {