diff --git a/etemplate/inc/class.soetemplate.inc.php b/etemplate/inc/class.soetemplate.inc.php index e34c8597ea..99ee6cb5e1 100644 --- a/etemplate/inc/class.soetemplate.inc.php +++ b/etemplate/inc/class.soetemplate.inc.php @@ -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); diff --git a/infolog/inc/class.soinfolog.inc.php b/infolog/inc/class.soinfolog.inc.php index ae7b4483b8..57f0abe8b5 100644 --- a/infolog/inc/class.soinfolog.inc.php +++ b/infolog/inc/class.soinfolog.inc.php @@ -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 "

sql='$sql'

\n"; while ($this->db->next_record()) { diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index 378c47e054..53620561df 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -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"; } diff --git a/phpgwapi/inc/class.db.inc.php b/phpgwapi/inc/class.db.inc.php index b84bbd26fb..468b54ba97 100644 --- a/phpgwapi/inc/class.db.inc.php +++ b/phpgwapi/inc/class.db.inc.php @@ -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
".print_r($GLOBALS['phpgw']->ADOdb,True)."
\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("

Database error: %s
\n", $msg); - if ($this->Errno != "0" && $this->Error != "()") + if (($this->Errno || $this->Error) && $this->Error != "()") { printf("$this->Type Error: %s (%s)
\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); } diff --git a/phpgwapi/inc/class.preferences.inc.php b/phpgwapi/inc/class.preferences.inc.php index 2901d1c779..8b17528540 100644 --- a/phpgwapi/inc/class.preferences.inc.php +++ b/phpgwapi/inc/class.preferences.inc.php @@ -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" diff --git a/phpgwapi/inc/class.schema_proc.inc.php b/phpgwapi/inc/class.schema_proc.inc.php index cc30b39d45..964832a690 100644 --- a/phpgwapi/inc/class.schema_proc.inc.php +++ b/phpgwapi/inc/class.schema_proc.inc.php @@ -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'
_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'
_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); diff --git a/phpgwapi/inc/class.schema_proc_mssql.inc.php b/phpgwapi/inc/class.schema_proc_mssql.inc.php index 0ac4b7c079..08a69c08dc 100644 --- a/phpgwapi/inc/class.schema_proc_mssql.inc.php +++ b/phpgwapi/inc/class.schema_proc_mssql.inc.php @@ -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)); } diff --git a/phpgwapi/inc/class.schema_proc_mysql.inc.php b/phpgwapi/inc/class.schema_proc_mysql.inc.php index 0dcb8a990a..a63ac1c847 100644 --- a/phpgwapi/inc/class.schema_proc_mysql.inc.php +++ b/phpgwapi/inc/class.schema_proc_mysql.inc.php @@ -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 */ diff --git a/phpgwapi/inc/class.schema_proc_pgsql.inc.php b/phpgwapi/inc/class.schema_proc_pgsql.inc.php index 28cbedfac0..1c51ec34f1 100644 --- a/phpgwapi/inc/class.schema_proc_pgsql.inc.php +++ b/phpgwapi/inc/class.schema_proc_pgsql.inc.php @@ -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 */ diff --git a/phpgwapi/inc/class.setup.inc.php b/phpgwapi/inc/class.setup.inc.php index a737ce045b..1f4129cb0f 100644 --- a/phpgwapi/inc/class.setup.inc.php +++ b/phpgwapi/inc/class.setup.inc.php @@ -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'] . "," diff --git a/phpgwapi/inc/class.translation_sql.inc.php b/phpgwapi/inc/class.translation_sql.inc.php index 937d4b3b33..e61ce965a1 100644 --- a/phpgwapi/inc/class.translation_sql.inc.php +++ b/phpgwapi/inc/class.translation_sql.inc.php @@ -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; diff --git a/phpgwapi/inc/class.vfs_shared.inc.php b/phpgwapi/inc/class.vfs_shared.inc.php index 787021d3e9..cf86ca79db 100644 --- a/phpgwapi/inc/class.vfs_shared.inc.php +++ b/phpgwapi/inc/class.vfs_shared.inc.php @@ -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; } diff --git a/setup/setup_demo.php b/setup/setup_demo.php index 54cdb0cfe0..e84198cd90 100644 --- a/setup/setup_demo.php +++ b/setup/setup_demo.php @@ -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__); } }