fixed / added mssql support for egw and fixed some other Windows probs on the way ;-)

- knowledgebase is not working: select distinct is not possible with text-columns
- fudforum is not working: is does not use ADOdb and has no own db-layer for mssql
- other apps seem to work, everthing needs through testing - incl. our "old" db's
This commit is contained in:
Ralf Becker 2004-07-25 01:41:37 +00:00
parent 968f1ccf91
commit c591c2c221
13 changed files with 79 additions and 54 deletions

View File

@ -619,7 +619,7 @@
foreach ($this->db_cols as $db_col => $col)
{
$sql .= $db_col . ',';
$vals .= $db_col == 'et_group' ? intval($data[$col]).',' : "'" . addslashes($data[$col]) . "',";
$vals .= $db_col == 'et_group' ? intval($data[$col]).',' : "'" . $this->db->db_addslashes($data[$col]) . "',";
}
$sql[strlen($sql)-1] = ')';
$sql .= " VALUES ($vals";
@ -688,7 +688,7 @@
$str = '$templ_data[] = array(';
for (reset($this->db_cols); list($db_col,$name) = each($this->db_cols); )
{
$str .= "'$name' => '".addslashes($this->db->f($db_col))."',";
$str .= "'$name' => '".$this->db->db_addslashes($this->db->f($db_col))."',";
}
$str .= ");\n\n";
fwrite($f,$str);

View File

@ -492,7 +492,12 @@
foreach(explode(',',$query['order']) as $val)
{
$val = trim($val);
$order[] = (substr($val,0,5) != 'info_' ? 'info_' : '').$val;
$val = (substr($val,0,5) != 'info_' ? 'info_' : '').$val;
if ($val == 'info_des' && $this->db->Type == 'mssql')
{
$val = "CAST($val AS varchar)";
}
$order[] = $val;
}
$ordermethod = 'ORDER BY ' . implode(',',$order) . ' ' . $query['sort'];
}
@ -547,14 +552,16 @@
if ($action == '' || $action == 'sp' || count($links))
{
$sql_query = "FROM phpgw_infolog $join WHERE ($filtermethod $pid $sql_query) $link_extra";
$this->db->query($sql='SELECT DISTINCT phpgw_infolog.info_id '.$sql_query,__LINE__,__FILE__);
// mssql cant use DISTICT of text columns (info_des) are involved
$distinct = $this->db->Type != 'mssql' ? 'DISTINCT' : '';
$this->db->query($sql="SELECT $distinct phpgw_infolog.info_id ".$sql_query,__LINE__,__FILE__);
$query['total'] = $this->db->num_rows();
if (!$query['start'] || $query['start'] > $query['total'])
{
$query['start'] = 0;
}
$this->db->limit_query($sql="SELECT DISTINCT phpgw_infolog.* $sql_query $ordermethod",$query['start'],__LINE__,__FILE__);
$this->db->limit_query($sql="SELECT $distinct phpgw_infolog.* $sql_query $ordermethod",$query['start'],__LINE__,__FILE__);
//echo "<p>sql='$sql'</p>\n";
while ($this->db->next_record())
{

View File

@ -161,7 +161,7 @@
$sort = 'ASC';
}
if (!empty($order) && preg_match('/^[a-zA-Z_, ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort)))
if (!empty($order) && preg_match('/^[a-zA-Z_(), ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort)))
{
$ordermethod = " ORDER BY $order $sort";
}

View File

@ -181,6 +181,12 @@
if (!$this->Link_ID)
{
foreach(array('Host','Database','User','Password') as $name)
{
$$name = $this->$name;
}
$type = $this->Type;
switch($this->Type) // convert to ADO db-type-names
{
case 'pgsql':
@ -190,13 +196,12 @@
" user=$this->User".($this->Password ? " password='".addslashes($this->Password)."'" : '');
$User = $Password = $Database = ''; // to indicate $Host is a connection-string
break;
case 'mssql':
if ($this->Port) $Host .= ','.$this->Port;
break;
default:
$Host = $this->Host . ($this->Port ? ':'.$this->Port : '');
foreach(array('Database','User','Password') as $name)
{
$$name = $this->$name;
}
$type = $this->Type;
if ($this->Port) $Host .= ':'.$this->Port;
break;
}
if (!is_object($GLOBALS['phpgw']->ADOdb) || // we have no connection so far
@ -228,6 +233,15 @@
return 0; // in case error-reporting = 'no'
}
//echo "new ADOdb connection<pre>".print_r($GLOBALS['phpgw']->ADOdb,True)."</pre>\n";
if ($this->Type == 'mssql')
{
// this is the format ADOdb expects
$this->Link_ID->Execute('SET DATEFORMAT ymd');
// sets the limit to the maximum
ini_set('mssql.textlimit',2147483647);
ini_set('mssql.sizelimit',2147483647);
}
}
else
{
@ -682,7 +696,7 @@
function haltmsg($msg)
{
printf("<p><b>Database error:</b> %s<br>\n", $msg);
if ($this->Errno != "0" && $this->Error != "()")
if (($this->Errno || $this->Error) && $this->Error != "()")
{
printf("<b>$this->Type Error</b>: %s (%s)<br>\n",$this->Errno,$this->Error);
}
@ -943,6 +957,10 @@
break; // ADOdb has no BlobEncode for mysql and returns an unquoted string !!!
}
return "'" . $this->Link_ID->BlobEncode($value) . "'";
case 'date':
return $this->Link_ID->DBDate($value);
case 'timestamp':
return $this->Link_ID->DBTimeStamp($value);
}
return $this->Link_ID->quote($value);
}

View File

@ -563,7 +563,7 @@
continue;
}
$this->quote($value);
$value = addslashes(serialize($value)); // this addslashes is for the database
$value = $this->db->db_addslashes(serialize($value)); // this addslashes is for the database
$app = $this->db->db_addslashes($app);
$this->db->query($sql = "INSERT INTO phpgw_preferences"

View File

@ -491,20 +491,24 @@
// Translate the type for the DBMS
if($sFieldSQL = $this->m_oTranslator->TranslateType($sType, $iPrecision, $iScale))
{
if(!$bNullable)
if(strpos(strtolower($sFieldSQL),'null')===false)
{
if(strpos(strtolower($sFieldSQL),' not null')===false)
if(!$bNullable)
{
$sFieldSQL .= ' NOT NULL';
}
elseif ($this->m_oTranslator->b_needExplicitNULL)
{
$sFieldSQL .= ' NULL';
}
}
if(isset($aField['default']))
{
if($GLOBALS['DEBUG']) { echo'<br>_GetFieldSQL(): Calling TranslateDefault for "' . $aField['default'] . '"'; }
// Get default DDL - useful for differences in date defaults (eg, now() vs. getdate())
$sTranslatedDefault = $aField['default'] == '0' ? $aField['default'] : $this->m_oTranslator->TranslateDefault($aField['default']);
$sFieldSQL .= " DEFAULT '$sTranslatedDefault'";
$sFieldSQL .= ' DEFAULT ' . (is_numeric($aField['default']) ? $aField['default'] :
$this->m_oTranslator->TranslateDefault($aField['default']));
}
if($GLOBALS['DEBUG']) { echo'<br>_GetFieldSQL(): Outgoing SQL: ' . $sFieldSQL; }
return true;
@ -552,6 +556,7 @@
{
return True;
}
$aIXSQL = array();
foreach($aFields as $mFields)
{
$options = False;
@ -562,6 +567,10 @@
$options = @$mFields['options'][$this->sType]; // db-specific options, eg. index-type
unset($mFields['options']);
}
if ($options === false)
{
continue; // dont create index for that db, eg. cant index text
}
$mFields = implode(',',$mFields);
}
$aIXSQL[] = $this->m_oTranslator->GetIXSQL($mFields,$append,$options,$sTableName);

View File

@ -23,6 +23,7 @@
var $fk = array();
var $ix = array();
var $uc = array();
var $b_needExplicitNULL = true; // no definition means NOT NULL for mssql
function schema_proc_mssql()
{
@ -36,7 +37,7 @@
switch($sType)
{
case 'auto':
$sTranslated = 'int identity(1,1)';
$sTranslated = 'int identity(1,1) NOT NULL';
break;
case 'blob':
$sTranslated = 'image'; /* wonder how well PHP will support this??? */
@ -91,11 +92,11 @@
$sTranslated = 'bit';
break;
case 'varchar':
if ($iPrecision > 0 && $iPrecision < 256)
if ($iPrecision > 0 && $iPrecision <= 256)
{
$sTranslated = sprintf("varchar(%d)", $iPrecision);
}
if ($iPrecision > 255)
if ($iPrecision > 256)
{
$sTranslated = 'text';
}
@ -113,7 +114,7 @@
return 'GetDate()';
}
return $sDefault;
return "'$sDefault'";
}
// Inverse of above, convert sql column types to array info
@ -200,9 +201,12 @@
return "UNIQUE($sFields)";
}
function GetIXSQL($sFields)
function GetIXSQL($sFields,&$append,$options,$sTableName)
{
return "INDEX($sFields)";
$append = True;
$ixFields = str_replace(',','_',$sFields);
$index = $sTableName . '_' . $ixFields . '_idx';
return "CREATE INDEX $index ON $sTableName ($sFields);\n";
}
function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = '')
@ -342,7 +346,15 @@
$oProc->m_odb->query($sSequenceSQL);
}
if($append_ix)
{
$query = "CREATE TABLE $sTableName ($sTableSQL";
}
else
{
$query = "CREATE TABLE $sTableName ($sTableSQL)";
}
return !!($oProc->m_odb->query($query));
}

View File

@ -114,9 +114,9 @@
{
case 'current_date':
case 'current_timestamp':
return 'now';
$sDefault = 'now';
}
return $sDefault;
return "'$sDefault'";
}
/* Inverse of above, convert sql column types to array info */

View File

@ -93,9 +93,9 @@
{
case 'current_date':
case 'current_timestamp':
return 'now';
$sDefault = 'now';
}
return $sDefault;
return "'$sDefault'";
}
/* Inverse of above, convert sql column types to array info */

View File

@ -393,10 +393,6 @@
else
{
$appstbl = 'phpgw_applications';
if($this->amorethanb($setup_info['phpgwapi']['currentver'],'0.9.13.014'))
{
$use_appid = True;
}
}
if($GLOBALS['DEBUG'])
@ -422,26 +418,9 @@
.$appname."_tables_prefix','".$setup_info[$appname]['tables_prefix']."')";
$this->db->query($sql,__LINE__,__FILE__);
}
if($use_appid)
{
$this->db->query("SELECT MAX(app_id) FROM $appstbl");
$this->db->next_record();
if($this->db->f(0))
{
$app_id = ($this->db->f(0) + 1) . ',';
$app_idstr = 'app_id,';
}
else
{
srand(100000);
$app_id = rand(1,100000) . ',';
$app_idstr = 'app_id,';
}
}
$this->db->query("INSERT INTO $appstbl "
. "($app_idstr app_name,app_enabled,app_order,app_tables,app_version) "
. "(app_name,app_enabled,app_order,app_tables,app_version) "
. "VALUES ("
. $app_id
. "'" . $setup_info[$appname]['name'] . "',"
. $enable . ","
. (int)$setup_info[$appname]['app_order'] . ","

View File

@ -422,7 +422,7 @@
// explode with "\t" and removing "\n" with str_replace, needed to work with mbstring.overload=7
list($message_id,$app_name,,$content) = explode("\t",$line);
$content=str_replace("\n",'',$content);
$content=str_replace(array("\n","\r"),'',$content);
$message_id = substr(strtolower(chop($message_id)),0,MAX_MESSAGE_ID_LENGTH);
$app_name = chop($app_name);
$raw[$app_name][$message_id] = $content;

View File

@ -941,7 +941,7 @@
else
{
$base_sep = $sep;
if (ereg ("^$this->basedir" . $sep, $string))
if (substr($string,0,strlen($this->basedir)+1) == $this->basedir . $sep)
{
$base = $this->basedir . $sep;
}

View File

@ -145,7 +145,7 @@
foreach ($defaultprefs as $app => $prefs)
{
$prefs = addslashes(serialize($prefs));
$prefs = $GLOBALS['phpgw_setup']->db->db_addslashes(serialize($prefs));
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_preferences(preference_owner,preference_app,preference_value) VALUES($accountid,'$app','$prefs')",__FILE__,__LINE__);
}
}