minor formatting

This commit is contained in:
Miles Lott 2001-09-12 13:45:58 +00:00
parent e191362086
commit 61c105e352
3 changed files with 112 additions and 112 deletions

View File

@ -40,10 +40,10 @@
$this->m_aTables = $aTables; $this->m_aTables = $aTables;
reset($this->m_aTables); reset($this->m_aTables);
$sAllTableSQL = ""; $sAllTableSQL = '';
while (list($sTableName, $aTableDef) = each($this->m_aTables)) while (list($sTableName, $aTableDef) = each($this->m_aTables))
{ {
$sSequenceSQL = ""; $sSequenceSQL = '';
if ($this->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL)) if ($this->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL))
{ {
$sTableSQL = "CREATE TABLE $sTableName (\n$sTableSQL\n)" $sTableSQL = "CREATE TABLE $sTableName (\n$sTableSQL\n)"
@ -268,7 +268,7 @@
reset($aTableDef['fd']); reset($aTableDef['fd']);
while (list($sFieldName, $aFieldAttr) = each($aTableDef['fd'])) while (list($sFieldName, $aFieldAttr) = each($aTableDef['fd']))
{ {
$sFieldSQL = ""; $sFieldSQL = '';
if ($this->_GetFieldSQL($aFieldAttr, $sFieldSQL)) if ($this->_GetFieldSQL($aFieldAttr, $sFieldSQL))
{ {
if ($sTableSQL != '') if ($sTableSQL != '')
@ -281,7 +281,7 @@
if ($aFieldAttr['type'] == 'auto') if ($aFieldAttr['type'] == 'auto')
{ {
$this->m_oTranslator->GetSequenceSQL($sTableName, $sSequenceSQL); $this->m_oTranslator->GetSequenceSQL($sTableName, $sSequenceSQL);
if ($sSequenceSQL != "") if ($sSequenceSQL != '')
{ {
$sTableSQL .= sprintf(" DEFAULT nextval('seq_%s')", $sTableName); $sTableSQL .= sprintf(" DEFAULT nextval('seq_%s')", $sTableName);
} }
@ -294,8 +294,8 @@
} }
} }
$sUCSQL = ""; $sUCSQL = '';
$sPKSQL = ""; $sPKSQL = '';
if (count($aTableDef['pk']) > 0) if (count($aTableDef['pk']) > 0)
{ {

View File

@ -23,79 +23,79 @@
function schema_proc_mysql() function schema_proc_mysql()
{ {
$this->m_sStatementTerminator = ";"; $this->m_sStatementTerminator = ';';
} }
// Return a type suitable for DDL // Return a type suitable for DDL
function TranslateType($sType, $iPrecision = 0, $iScale = 0, &$sTranslated) function TranslateType($sType, $iPrecision = 0, $iScale = 0, &$sTranslated)
{ {
$sTranslated = ""; $sTranslated = '';
switch($sType) switch($sType)
{ {
case "auto": case 'auto':
$sTranslated = "int(11) auto_increment"; $sTranslated = 'int(11) auto_increment';
break; break;
case "blob": case 'blob':
$sTranslated = "blob"; $sTranslated = 'blob';
break; break;
case "char": case 'char':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = sprintf("char(%d)", $iPrecision); $sTranslated = sprintf("char(%d)", $iPrecision);
} }
if ($iPrecision > 255) if ($iPrecision > 255)
{ {
$sTranslated = "text"; $sTranslated = 'text';
} }
break; break;
case "date": case 'date':
$sTranslated = "date"; $sTranslated = 'date';
break; break;
case "decimal": case 'decimal':
$sTranslated = sprintf("decimal(%d,%d)", $iPrecision, $iScale); $sTranslated = sprintf("decimal(%d,%d)", $iPrecision, $iScale);
break; break;
case "float": case 'float':
switch ($iPrecision) switch ($iPrecision)
{ {
case 4: case 4:
$sTranslated = "float"; $sTranslated = 'float';
break; break;
case 8: case 8:
$sTranslated = "double"; $sTranslated = 'double';
break; break;
} }
break; break;
case "int": case 'int':
switch ($iPrecision) switch ($iPrecision)
{ {
case 2: case 2:
$sTranslated = "smallint"; $sTranslated = 'smallint';
break; break;
case 4: case 4:
$sTranslated = "int"; $sTranslated = 'int';
break; break;
case 8: case 8:
$sTranslated = "bigint"; $sTranslated = 'bigint';
break; break;
} }
break; break;
case "longtext": case 'longtext':
$sTranslated = "longtext"; $sTranslated = 'longtext';
break; break;
case "text": case 'text':
$sTranslated = "text"; $sTranslated = 'text';
break; break;
case "timestamp": case 'timestamp':
$sTranslated = "datetime"; $sTranslated = 'datetime';
break; break;
case "varchar": case 'varchar':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = sprintf("varchar(%d)", $iPrecision); $sTranslated = sprintf("varchar(%d)", $iPrecision);
} }
if ($iPrecision > 255) if ($iPrecision > 255)
{ {
$sTranslated = "text"; $sTranslated = 'text';
} }
break; break;
} }
@ -107,9 +107,9 @@
{ {
switch ($sDefault) switch ($sDefault)
{ {
case "current_date": case 'current_date':
case "current_timestamp": case 'current_timestamp':
return "now"; return 'now';
} }
return $sDefault; return $sDefault;
@ -136,16 +136,16 @@
} }
switch($sType) switch($sType)
{ {
case "tinyint": case 'tinyint':
case "smallint": case 'smallint':
$sTranslated = "'type' => 'int', 'precision' => 2"; $sTranslated = "'type' => 'int', 'precision' => 2";
break; break;
case "int": case 'int':
$sTranslated = "'type' => 'int', 'precision' => 4"; $sTranslated = "'type' => 'int', 'precision' => 4";
break; break;
case "bigint": case 'bigint':
$sTranslated = "'type' => 'int', 'precision' => 8"; $sTranslated = "'type' => 'int', 'precision' => 8";
case "char": case 'char':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = "'type' => 'char', 'precision' => $iPrecision"; $sTranslated = "'type' => 'char', 'precision' => $iPrecision";
@ -155,21 +155,21 @@
$sTranslated = "'type' => 'text'"; $sTranslated = "'type' => 'text'";
} }
break; break;
case "decimal": case 'decimal':
$sTranslated = "'type' => 'decimal', 'precision' => $iPrecision, 'scale' => $iScale"; $sTranslated = "'type' => 'decimal', 'precision' => $iPrecision, 'scale' => $iScale";
break; break;
case "float": case 'float':
case "double": case 'double':
$sTranslated = "'type' => 'float', 'precision' => $iPrecision"; $sTranslated = "'type' => 'float', 'precision' => $iPrecision";
break; break;
case "datetime": case 'datetime':
$sTranslated = "'type' => 'timestamp'"; $sTranslated = "'type' => 'timestamp'";
break; break;
case "enum": case 'enum':
// Here comes a nasty assumption // Here comes a nasty assumption
$sTranslated = "'type' => 'varchar', 'precision' => 255"; $sTranslated = "'type' => 'varchar', 'precision' => 255";
break; break;
case "varchar": case 'varchar':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = "'type' => 'varchar', 'precision' => $iPrecision"; $sTranslated = "'type' => 'varchar', 'precision' => $iPrecision";
@ -179,10 +179,10 @@
$sTranslated = "'type' => 'text'"; $sTranslated = "'type' => 'text'";
} }
break; break;
case "longtext": case 'longtext':
case "text": case 'text':
case "blob": case 'blob':
case "date": case 'date':
$sTranslated = "'type' => '$sType'"; $sTranslated = "'type' => '$sType'";
break; break;
} }
@ -200,9 +200,9 @@
return "UNIQUE($sFields)"; return "UNIQUE($sFields)";
} }
function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = "") function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = '')
{ {
$sColumns = ""; $sColumns = '';
$this->pk = array(); $this->pk = array();
$this->fk = array(); $this->fk = array();
$this->ix = array(); $this->ix = array();
@ -213,9 +213,9 @@
while ($oProc->m_odb->next_record()) while ($oProc->m_odb->next_record())
{ {
$type = $default = $null = $nullcomma = $prec = $scale = $ret = $colinfo = $scales = ''; $type = $default = $null = $nullcomma = $prec = $scale = $ret = $colinfo = $scales = '';
if ($sColumns != "") if ($sColumns != '')
{ {
$sColumns .= ","; $sColumns .= ',';
} }
$sColumns .= $oProc->m_odb->f(0); $sColumns .= $oProc->m_odb->f(0);
@ -324,7 +324,7 @@
function GetSequenceSQL($sTableName, &$sSequenceSQL) function GetSequenceSQL($sTableName, &$sSequenceSQL)
{ {
$sSequenceSQL = ""; $sSequenceSQL = '';
return true; return true;
} }
@ -333,7 +333,7 @@
if ($oProc->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL)) if ($oProc->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL))
{ {
// create sequence first since it will be needed for default // create sequence first since it will be needed for default
if ($sSequenceSQL != "") if ($sSequenceSQL != '')
{ {
$oProc->m_odb->query($sSequenceSQL); $oProc->m_odb->query($sSequenceSQL);
} }

View File

@ -27,7 +27,7 @@
function schema_proc_pgsql() function schema_proc_pgsql()
{ {
$this->m_sStatementTerminator = ";"; $this->m_sStatementTerminator = ';';
} }
// Return a type suitable for DDL // Return a type suitable for DDL
@ -35,57 +35,57 @@
{ {
switch($sType) switch($sType)
{ {
case "auto": case 'auto':
$sTranslated = "int4"; $sTranslated = 'int4';
break; break;
case "blob": case 'blob':
$sTranslated = "text"; $sTranslated = 'text';
break; break;
case "char": case 'char':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = sprintf("char(%d)", $iPrecision); $sTranslated = sprintf("char(%d)", $iPrecision);
} }
if ($iPrecision > 255) if ($iPrecision > 255)
{ {
$sTranslated = "text"; $sTranslated = 'text';
} }
break; break;
case "date": case 'date':
$sTranslated = "date"; $sTranslated = 'date';
break; break;
case "decimal": case 'decimal':
$sTranslated = sprintf("decimal(%d,%d)", $iPrecision, $iScale); $sTranslated = sprintf("decimal(%d,%d)", $iPrecision, $iScale);
break; break;
case "float": case 'float':
if ($iPrecision == 4 || $iPrecision == 8) if ($iPrecision == 4 || $iPrecision == 8)
{ {
$sTranslated = sprintf("float%d", $iPrecision); $sTranslated = sprintf("float%d", $iPrecision);
} }
break; break;
case "int": case 'int':
if ($iPrecision == 2 || $iPrecision == 4 || $iPrecision == 8) if ($iPrecision == 2 || $iPrecision == 4 || $iPrecision == 8)
{ {
$sTranslated = sprintf("int%d", $iPrecision); $sTranslated = sprintf("int%d", $iPrecision);
} }
break; break;
case "longtext": case 'longtext':
$sTranslated = "text"; $sTranslated = 'text';
break; break;
case "text": case 'text':
$sTranslated = "text"; $sTranslated = 'text';
break; break;
case "timestamp": case 'timestamp':
$sTranslated = "timestamp"; $sTranslated = 'timestamp';
break; break;
case "varchar": case 'varchar':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = sprintf("varchar(%d)", $iPrecision); $sTranslated = sprintf("varchar(%d)", $iPrecision);
} }
if ($iPrecision > 255) if ($iPrecision > 255)
{ {
$sTranslated = "text"; $sTranslated = 'text';
} }
break; break;
} }
@ -97,9 +97,9 @@
{ {
switch ($sDefault) switch ($sDefault)
{ {
case "current_date": case 'current_date':
case "current_timestamp": case 'current_timestamp':
return "now"; return 'now';
} }
return $sDefault; return $sDefault;
@ -108,23 +108,23 @@
// Inverse of above, convert sql column types to array info // Inverse of above, convert sql column types to array info
function rTranslateType($sType, $iPrecision = 0, $iScale = 0, &$sTranslated) function rTranslateType($sType, $iPrecision = 0, $iScale = 0, &$sTranslated)
{ {
$sTranslated = ""; $sTranslated = '';
switch($sType) switch($sType)
{ {
case "serial": case 'serial':
$sTranslated = "'type' => 'auto'"; $sTranslated = "'type' => 'auto'";
break; break;
case "int2": case 'int2':
$sTranslated = "'type' => 'int', 'precision' => 2"; $sTranslated = "'type' => 'int', 'precision' => 2";
break; break;
case "int4": case 'int4':
$sTranslated = "'type' => 'int', 'precision' => 4"; $sTranslated = "'type' => 'int', 'precision' => 4";
break; break;
case "int8": case 'int8':
$sTranslated = "'type' => 'int', 'precision' => 8"; $sTranslated = "'type' => 'int', 'precision' => 8";
break; break;
case "bpchar": case 'bpchar':
case "char": case 'char':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = "'type' => 'char', 'precision' => $iPrecision"; $sTranslated = "'type' => 'char', 'precision' => $iPrecision";
@ -134,22 +134,22 @@
$sTranslated = "'type' => 'text'"; $sTranslated = "'type' => 'text'";
} }
break; break;
case "numeric": case 'numeric':
/* Borrowed from phpPgAdmin */ /* Borrowed from phpPgAdmin */
$iPrecision = ($iScale >> 16) & 0xffff; $iPrecision = ($iScale >> 16) & 0xffff;
$iScale = ($iScale - 4) & 0xffff; $iScale = ($iScale - 4) & 0xffff;
$sTranslated = "'type' => 'decimal', 'precision' => $iPrecision, 'scale' => $iScale"; $sTranslated = "'type' => 'decimal', 'precision' => $iPrecision, 'scale' => $iScale";
break; break;
case "float": case 'float':
case "float4": case 'float4':
case "float8": case 'float8':
case "double": case 'double':
$sTranslated = "'type' => 'float', 'precision' => $iPrecision"; $sTranslated = "'type' => 'float', 'precision' => $iPrecision";
break; break;
case "datetime": case 'datetime':
$sTranslated = "'type' => 'timestamp'"; $sTranslated = "'type' => 'timestamp'";
break; break;
case "varchar": case 'varchar':
if ($iPrecision > 0 && $iPrecision < 256) if ($iPrecision > 0 && $iPrecision < 256)
{ {
$sTranslated = "'type' => 'varchar', 'precision' => $iPrecision"; $sTranslated = "'type' => 'varchar', 'precision' => $iPrecision";
@ -159,9 +159,9 @@
$sTranslated = "'type' => 'text'"; $sTranslated = "'type' => 'text'";
} }
break; break;
case "text": case 'text':
case "blob": case 'blob':
case "date": case 'date':
$sTranslated = "'type' => '$sType'"; $sTranslated = "'type' => '$sType'";
break; break;
} }
@ -184,7 +184,7 @@
$sdb = $oProc->m_odb; $sdb = $oProc->m_odb;
$sdc = $oProc->m_odb; $sdc = $oProc->m_odb;
$sColumns = ""; $sColumns = '';
$this->pk = array(); $this->pk = array();
$this->fk = array(); $this->fk = array();
$this->ix = array(); $this->ix = array();
@ -192,18 +192,18 @@
$query = "SELECT a.attname,a.attnum FROM pg_attribute a,pg_class b WHERE "; $query = "SELECT a.attname,a.attnum FROM pg_attribute a,pg_class b WHERE ";
$query .= "b.oid=a.attrelid AND a.attnum>0 and b.relname='$sTableName'"; $query .= "b.oid=a.attrelid AND a.attnum>0 and b.relname='$sTableName'";
if ($sDropColumn != "") if ($sDropColumn != '')
{ {
$query .= " AND a.attname != '$sDropColumn'"; $query .= " AND a.attname != '$sDropColumn'";
} }
$query .= " ORDER BY a.attnum"; $query .= ' ORDER BY a.attnum';
$oProc->m_odb->query($query); $oProc->m_odb->query($query);
while ($oProc->m_odb->next_record()) while ($oProc->m_odb->next_record())
{ {
if ($sColumns != "") if ($sColumns != '')
{ {
$sColumns .= ","; $sColumns .= ',';
} }
$sFieldName = $oProc->m_odb->f(0); $sFieldName = $oProc->m_odb->f(0);
@ -379,12 +379,12 @@
{ {
switch ($arraydef['type']) switch ($arraydef['type'])
{ {
case "blob": case 'blob':
case "char": case 'char':
case "date": case 'date':
case "text": case 'text':
case "timestamp": case 'timestamp':
case "varchar": case 'varchar':
$sSQL .= "'" . $oProc->m_odb->f($i) . "'"; $sSQL .= "'" . $oProc->m_odb->f($i) . "'";
break; break;
default: default:
@ -473,10 +473,10 @@
} }
$oProc->m_odb->query($query); $oProc->m_odb->query($query);
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns, $sColumnName); $this->_GetColumns($oProc, $sTableName . '_tmp', $sColumns, $sColumnName);
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp"; $query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . '_tmp';
$bRet = !!($oProc->m_odb->query($query)); $bRet = !!($oProc->m_odb->query($query));
return ($bRet && $this->DropTable($oProc, $aTables, $sTableName . "_tmp")); return ($bRet && $this->DropTable($oProc, $aTables, $sTableName . '_tmp'));
} }
function RenameTable($oProc, &$aTables, $sOldTableName, $sNewTableName) function RenameTable($oProc, &$aTables, $sOldTableName, $sNewTableName)
@ -584,7 +584,7 @@
if ($oProc->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL)) if ($oProc->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL))
{ {
// create sequence first since it will be needed for default // create sequence first since it will be needed for default
if ($bCreateSequence && $sSequenceSQL != "") if ($bCreateSequence && $sSequenceSQL != '')
{ {
if ($DEBUG) { echo '<br>Making sequence using: ' . $sSequenceSQL; } if ($DEBUG) { echo '<br>Making sequence using: ' . $sSequenceSQL; }
$oProc->m_odb->query($sSequenceSQL); $oProc->m_odb->query($sSequenceSQL);
@ -596,6 +596,6 @@
} }
return false; return false;
} }
} }
?> ?>