Fix strict mode of MySQL.

This commit is contained in:
朱金勇
2023-04-05 02:11:12 +00:00
parent e714c29ea7
commit 0f6b78f264
7 changed files with 836 additions and 711 deletions
+63 -19
View File
@@ -108,10 +108,10 @@ ALTER TABLE `zt_doclib`
CHANGE `product` `product` mediumint unsigned NOT NULL DEFAULT '0',
CHANGE `project` `project` mediumint unsigned NOT NULL DEFAULT '0',
CHANGE `execution` `execution` mediumint unsigned NOT NULL DEFAULT '0',
CHANGE `collector` `collector` text NOT NULL DEFAULT '',
CHANGE `desc` `desc` mediumtext NOT NULL DEFAULT '',
CHANGE `collector` `collector` text NULL,
CHANGE `desc` `desc` mediumtext NULL,
CHANGE `groups` `groups` varchar(255) NOT NULL DEFAULT '',
CHANGE `users` `users` text NOT NULL DEFAULT '',
CHANGE `users` `users` text NULL,
CHANGE `order` `order` tinyint unsigned NOT NULL DEFAULT '0';
ALTER TABLE `zt_domain`
@@ -154,6 +154,50 @@ CHANGE `editedDate` `editedDate` datetime NULL;
ALTER TABLE `zt_image`
CHANGE `restoreDate` `restoreDate` datetime NULL;
ALTER TABLE `zt_im_chat`
CHANGE `avatar` `avatar` text NULL,
CHANGE `pinnedMessages` `pinnedMessages` text NULL,
CHANGE `createdDate` `createdDate` datetime NOT NULL,
CHANGE `editedDate` `editedDate` datetime NULL,
CHANGE `mergedDate` `mergedDate` datetime NULL,
CHANGE `lastActiveTime` `lastActiveTime` datetime NULL,
CHANGE `dismissDate` `dismissDate` datetime NULL,
CHANGE `archiveDate` `archiveDate` datetime NULL;
ALTER TABLE `zt_im_chat_message_index`
CHANGE `startDate` `startDate` datetime NULL,
CHANGE `endDate` `endDate` datetime NULL;
ALTER TABLE `zt_im_chatuser`
CHANGE `join` `join` datetime NULL,
CHANGE `quit` `quit` datetime NULL;
ALTER TABLE `zt_im_conference`
CHANGE `openedDate` `openedDate` datetime NULL;
ALTER TABLE `zt_im_conferenceaction`
CHANGE `data` `data` text NULL,
CHANGE `date` `date` datetime NULL;
ALTER TABLE `zt_im_message`
CHANGE `content` `content` text NULL,
CHANGE `data` `data` text NULL,
CHANGE `date` `date` datetime NULL;
ALTER TABLE `zt_im_message_backup`
CHANGE `data` `data` text NULL,
CHANGE `content` `content` text NULL,
CHANGE `date` `date` datetime NULL;
ALTER TABLE `zt_im_message_index`
CHANGE `startDate` `startDate` datetime NULL,
CHANGE `endDate` `endDate` datetime NULL;
ALTER TABLE `zt_im_userdevice`
CHANGE `validUntil` `validUntil` datetime NULL,
CHANGE `lastLogin` `lastLogin` datetime NULL,
CHANGE `lastLogout` `lastLogout` datetime NULL;
ALTER TABLE `zt_issue`
CHANGE `editedBy` `editedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `editedDate` `editedDate` datetime NULL,
@@ -202,14 +246,14 @@ CHANGE `backDate` `backDate` datetime NULL,
CHANGE `reviewedBy` `reviewedBy` char(30) NOT NULL DEFAULT '',
CHANGE `reviewedDate` `reviewedDate` datetime NULL,
CHANGE `assignedTo` `assignedTo` varchar(30) NOT NULL DEFAULT '',
CHANGE `reviewers` `reviewers` text NOT NULL DEFAULT '',
CHANGE `backReviewers` `backReviewers` text NOT NULL DEFAULT '';
CHANGE `reviewers` `reviewers` text NULL,
CHANGE `backReviewers` `backReviewers` text NULL;
ALTER TABLE `zt_lieu`
CHANGE `reviewedBy` `reviewedBy` char(30) NOT NULL DEFAULT '',
CHANGE `reviewedDate` `reviewedDate` datetime NULL,
CHANGE `assignedTo` `assignedTo` varchar(30) NOT NULL DEFAULT '',
CHANGE `reviewers` `reviewers` text NOT NULL DEFAULT '';
CHANGE `reviewers` `reviewers` text NULL;
ALTER TABLE `zt_measqueue`
CHANGE `updateDate` `updateDate` datetime NULL;
@@ -255,7 +299,7 @@ CHANGE `canceledDate` `canceledDate` datetime NULL,
CHANGE `cancelReason` `cancelReason` char(30) NOT NULL DEFAULT '',
CHANGE `hangupedBy` `hangupedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `hangupedDate` `hangupedDate` datetime NULL,
CHANGE `resolution` `resolution` mediumtext NOT NULL DEFAULT '',
CHANGE `resolution` `resolution` mediumtext NULL,
CHANGE `resolvedBy` `resolvedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `resolvedDate` `resolvedDate` datetime NULL,
CHANGE `lastCheckedBy` `lastCheckedBy` varchar(30) NOT NULL DEFAULT '',
@@ -266,7 +310,7 @@ CHANGE `rejectReason` `rejectReason` varchar(100) NOT NULL DEFAULT '',
CHANGE `reviewedBy` `reviewedBy` char(30) NOT NULL DEFAULT '',
CHANGE `reviewedDate` `reviewedDate` datetime NULL,
CHANGE `assignedTo` `assignedTo` varchar(30) NOT NULL DEFAULT '',
CHANGE `reviewers` `reviewers` text NOT NULL DEFAULT '';
CHANGE `reviewers` `reviewers` text NULL;
ALTER TABLE `zt_pipeline`
CHANGE `editedBy` `editedBy` varchar(30) NOT NULL DEFAULT '',
@@ -282,7 +326,7 @@ ALTER TABLE `zt_product`
CHANGE `code` `code` varchar(45) NOT NULL DEFAULT '',
CHANGE `shadow` `shadow` tinyint unsigned NOT NULL DEFAULT '0',
CHANGE `feedback` `feedback` varchar(30) NOT NULL DEFAULT '',
CHANGE `reviewer` `reviewer` text NOT NULL DEFAULT '',
CHANGE `reviewer` `reviewer` text NULL,
CHANGE `order` `order` mediumint unsigned NOT NULL DEFAULT '0',
CHANGE `ticket` `ticket` varchar(30) NOT NULL DEFAULT '';
@@ -291,7 +335,7 @@ CHANGE `closedReason` `closedReason` varchar(20) NOT NULL DEFAULT '';
ALTER TABLE `zt_project`
CHANGE `model` `model` char(30) NOT NULL DEFAULT '',
CHANGE `output` `output` text NOT NULL DEFAULT '',
CHANGE `output` `output` text NULL,
CHANGE `code` `code` varchar(45) NOT NULL DEFAULT '',
CHANGE `auth` `auth` char(30) NOT NULL DEFAULT '',
CHANGE `path` `path` varchar(255) NOT NULL DEFAULT '',
@@ -299,7 +343,7 @@ CHANGE `grade` `grade` tinyint unsigned NOT NULL DEFAULT '0',
CHANGE `realBegan` `realBegan` date NULL,
CHANGE `realEnd` `realEnd` date NULL,
CHANGE `days` `days` smallint unsigned NOT NULL DEFAULT '0',
CHANGE `desc` `desc` mediumtext NOT NULL DEFAULT '',
CHANGE `desc` `desc` mediumtext NULL,
CHANGE `version` `version` smallint NOT NULL DEFAULT '0',
CHANGE `parentVersion` `parentVersion` smallint NOT NULL DEFAULT '0',
CHANGE `planDuration` `planDuration` int NOT NULL DEFAULT '0',
@@ -310,7 +354,7 @@ CHANGE `closedDate` `closedDate` datetime NULL,
CHANGE `canceledDate` `canceledDate` datetime NULL,
CHANGE `suspendedDate` `suspendedDate` date NULL,
CHANGE `team` `team` varchar(90) NOT NULL DEFAULT '',
CHANGE `whitelist` `whitelist` text NOT NULL DEFAULT '',
CHANGE `whitelist` `whitelist` text NULL,
CHANGE `order` `order` mediumint unsigned NOT NULL DEFAULT '0';
ALTER TABLE `zt_researchplan`
@@ -357,7 +401,7 @@ CHANGE `plannedClosedDate` `plannedClosedDate` date NULL,
CHANGE `actualClosedDate` `actualClosedDate` date NULL,
CHANGE `editedBy` `editedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `editedDate` `editedDate` datetime NULL,
CHANGE `resolution` `resolution` mediumtext NOT NULL DEFAULT '',
CHANGE `resolution` `resolution` mediumtext NULL,
CHANGE `resolvedBy` `resolvedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `activateBy` `activateBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `activateDate` `activateDate` date NULL,
@@ -423,7 +467,7 @@ CHANGE `estStarted` `estStarted` date NULL,
CHANGE `realStarted` `realStarted` datetime NULL,
CHANGE `finishedBy` `finishedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `finishedDate` `finishedDate` datetime NULL,
CHANGE `finishedList` `finishedList` text NOT NULL DEFAULT '',
CHANGE `finishedList` `finishedList` text NULL,
CHANGE `canceledBy` `canceledBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `canceledDate` `canceledDate` datetime NULL,
CHANGE `closedBy` `closedBy` varchar(30) NOT NULL DEFAULT '',
@@ -466,7 +510,7 @@ CHANGE `finishedBy` `finishedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `finishedDate` `finishedDate` datetime NULL,
CHANGE `resolvedBy` `resolvedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `resolvedDate` `resolvedDate` datetime NULL,
CHANGE `resolution` `resolution` varchar(1000) NOT NULL DEFAULT '',
CHANGE `resolution` `resolution` text NULL,
CHANGE `editedBy` `editedBy` varchar(30) NOT NULL DEFAULT '',
CHANGE `editedDate` `editedDate` datetime NULL;
@@ -493,10 +537,10 @@ CHANGE `editedDate` `editedDate` datetime NULL;
ALTER TABLE `zt_user`
CHANGE `company` `company` mediumint unsigned NOT NULL DEFAULT '0',
CHANGE `commiter` `commiter` varchar(100) NOT NULL DEFAULT '',
CHANGE `avatar` `avatar` text NOT NULL DEFAULT '',
CHANGE `nature` `nature` text NOT NULL DEFAULT '',
CHANGE `analysis` `analysis` text NOT NULL DEFAULT '',
CHANGE `strategy` `strategy` text NOT NULL DEFAULT '',
CHANGE `avatar` `avatar` text NULL,
CHANGE `nature` `nature` text NULL,
CHANGE `analysis` `analysis` text NULL,
CHANGE `strategy` `strategy` text NULL,
CHANGE `ldap` `ldap` char(30) NOT NULL DEFAULT '',
CHANGE `resetToken` `resetToken` varchar(50) NOT NULL DEFAULT '',
CHANGE `birthday` `birthday` date NULL,
+678 -678
View File
File diff suppressed because one or more lines are too long
+10 -1
View File
@@ -308,7 +308,16 @@ class baseModel
*/
public function loadDAO()
{
$this->dao = $this->app->loadClass('dao');
global $config;
$driver = $config->db->driver;
if(!class_exists($driver))
{
$classFile = $this->app->coreLibRoot . 'dao' . DS . $driver . '.class.php';
include($classFile);
}
$this->dao = new $driver();
}
/**
+1 -1
View File
@@ -759,7 +759,7 @@ class baseRouter
*/
public function getInstalledVersion()
{
$version = $this->dbh->query("SELECT value FROM " . TABLE_CONFIG . " WHERE `owner` = 'system' AND `key` = 'version' AND `module` = 'common' AND `section` = 'global' LIMIT 1")->fetch();
$version = $this->dbh->query("SELECT `value` FROM " . TABLE_CONFIG . " WHERE `owner` = 'system' AND `key` = 'version' AND `module` = 'common' AND `section` = 'global' LIMIT 1")->fetch();
$version = $version ? $version->value : '0.3.beta'; // No version, set as 0.3.beta.
if($version == '3.0.stable') $version = '3.0'; // convert 3.0.stable to 3.0.
return $version;
+6 -6
View File
@@ -78,7 +78,7 @@ class router extends baseRouter
{
if($this->dbh)
{
$langs = $this->dbh->query('SELECT value FROM' . TABLE_CONFIG . "WHERE `owner`='system' AND `module`='common' AND `section`='global' AND `key`='langs'")->fetch();
$langs = $this->dbh->query('SELECT `value` FROM ' . TABLE_CONFIG . " WHERE `owner`='system' AND `module`='common' AND `section`='global' AND `key`='langs'")->fetch();
$langs = empty($langs) ? array() : json_decode($langs->value, true);
foreach($langs as $langKey => $langData) $this->config->langs[$langKey] = $langData['name'];
}
@@ -171,7 +171,7 @@ class router extends baseRouter
try
{
$commonSettings = $this->dbh->query('SELECT section, `key`, value FROM' . TABLE_CONFIG . "WHERE `owner`='system' AND (`module`='custom' or `module`='common') and `key` in ('sprintConcept', 'hourPoint', 'URSR', 'mode', 'URAndSR', 'scoreStatus', 'disabledFeatures', 'closedFeatures')")->fetchAll();
$commonSettings = $this->dbh->query('SELECT `section`, `key`, `value` FROM' . TABLE_CONFIG . "WHERE `owner`='system' AND (`module`='custom' or `module`='common') and `key` in ('sprintConcept', 'hourPoint', 'URSR', 'mode', 'URAndSR', 'scoreStatus', 'disabledFeatures', 'closedFeatures')")->fetchAll();
}
catch (PDOException $exception)
{
@@ -239,7 +239,7 @@ class router extends baseRouter
{
$sql = new sql();
$account = $sql->quote($account);
$userSetting = $this->dbh->query('SELECT `key`, value FROM' . TABLE_CONFIG . "WHERE `owner`= $account AND `module`='common' and `key` in ('programLink', 'productLink', 'projectLink', 'executionLink', 'URSR')")->fetchAll();
$userSetting = $this->dbh->query('SELECT `key`, `value` FROM ' . TABLE_CONFIG . "WHERE `owner`= $account AND `module`='common' and `key` in ('programLink', 'productLink', 'projectLink', 'executionLink', 'URSR')")->fetchAll();
}
foreach($userSetting as $setting)
@@ -255,7 +255,7 @@ class router extends baseRouter
$lang->SRCommon = '';
if($this->dbh and !empty($this->config->db->name))
{
$productProject = $this->dbh->query('SELECT value FROM' . TABLE_CONFIG . "WHERE `owner`='system' AND `module`='custom' AND `key`='productProject'")->fetch();
$productProject = $this->dbh->query('SELECT `value` FROM ' . TABLE_CONFIG . "WHERE `owner`='system' AND `module`='custom' AND `key`='productProject'")->fetch();
if($productProject)
{
$productProject = $productProject->value;
@@ -267,8 +267,8 @@ class router extends baseRouter
{
/* Get story concept in project and product. */
$clientLang = $this->clientLang == 'zh-tw' ? 'zh-cn' : $this->clientLang;
$URSRList = $this->dbh->query('SELECT `key`, `value` FROM' . TABLE_LANG . "WHERE module = 'custom' and section = 'URSRList' and `lang` = \"{$clientLang}\"")->fetchAll();
if(empty($URSRList)) $URSRList = $this->dbh->query('SELECT `key`, `value` FROM' . TABLE_LANG . "WHERE module = 'custom' and section = 'URSRList' and `key` = \"{$config->URSR}\"")->fetchAll();
$URSRList = $this->dbh->query('SELECT `key`, `value` FROM' . TABLE_LANG . "WHERE `module` = 'custom' and `section` = 'URSRList' and `lang` = '{$clientLang}'")->fetchAll();
if(empty($URSRList)) $URSRList = $this->dbh->query('SELECT `key`, `value` FROM' . TABLE_LANG . "WHERE module = 'custom' and `section` = 'URSRList' and `key` = '{$config->URSR}'")->fetchAll();
/* Get UR pairs and SR pairs. */
$URPairs = array();
+1 -1
View File
@@ -313,7 +313,7 @@ class sql extends baseSQL
public function groupBy($groupBy)
{
if($this->inCondition and !$this->conditionIsTrue) return $this;
if(!preg_match('/^[a-zA-Z0-9_`\.,\s]+$/', $groupBy))
if(!preg_match('/^[a-zA-Z0-9_`\.,\s\"]+$/', $groupBy))
{
$groupBy = htmlspecialchars($groupBy);
die("Group is bad query, The group is $groupBy");
+77 -5
View File
@@ -67,21 +67,33 @@ class dm extends dao
}
else
{
$fieldList[$key] = $this->formatField($field, '');
$fieldList[$key] = $this->formatField($field);
}
}
return parent::select(implode(',', $fieldList));
}
private function formatField($originField, $alias)
/**
* Format field: date => "date", t1.date => t1."date"
*
* @param string $originField
* @param string $alias
* @access private
* @return tring
*/
private function formatField($originField, $alias = '')
{
/* Format originField. */
$replace = array(
'GROUP_CONCAT' => 'WM_CONCAT',
);
if(strcasecmp($originField, 'distinct') !== 0)
if(stripos($originField, 'if(') !== false)
{
$originField = $this->formatIfFunction($originField);
}
elseif(strcasecmp($originField, 'distinct') !== 0)
{
$tableField = explode('.', $originField);
if(count($tableField) == 2 and ctype_alnum($tableField[1]) and $tableField[1] != '*')
@@ -101,6 +113,29 @@ class dm extends dao
return $originField . ' ' . $alias;
}
/**
* Format if function.
*
* @param string $field
* @access private
* @return string
*/
private function formatIfFunction($field)
{
preg_match('/if\(.+\)+/i', $field, $matches);
$if = $matches[0];
if(substr_count($if, '(') == 1)
{
$pos = strpos($if, ')');
$if = substr($if, 0, $pos+1);
}
$parts = explode(',', substr($if, 3, strlen($if)-4)); // remove 'if(' and ')'
$case = 'CASE WHEN ' . implode(',', array_slice($parts, 0, count($parts)-2)) . ' THEN ' . $parts[count($parts)-2] . ' ELSE ' . $parts[count($parts)-1] . ' END';
$field = str_ireplace($if, $case, $field);
return $field;
}
/**
* 创建WHERE部分。
* Create the where part.
@@ -154,14 +189,51 @@ class dm extends dao
if($pos)
{
$originField = substr($condition, 0, $pos);
return $this->formatField($originField, '') . substr($condition, $pos);
return $this->formatField($originField) . substr($condition, $pos);
}
else
{
return $this->formatField($condition, '');
return $this->formatField($condition);
}
}
/**
* 创建GROUP BY部分。
* Create the groupby part.
*
* @param string $groupBy
* @access public
* @return static|sql the sql object.
*/
public function groupBy($groupBy)
{
$groups = preg_split("/,(?![^(]+\))/", $groupBy);
foreach($groups as $key => $group)
{
$groups[$key] = $this->formatField($group);
}
$groupBy = implode(',', $groups);
return parent::groupBy($groupBy);
}
/**
* 创建ON部分。
* Create the on part.
*
* @param string $condition
* @access public
* @return static|sql the sql object.
*/
public function on($condition)
{
$fieldList = explode('=', $condition);
foreach($fieldList as $key => $field) $fieldList[$key] = $this->formatField(trim($field));
$condition = implode(' = ', $fieldList);
return parent::on($condition);
}
public function getPKColumns()
{
$sql = "SELECT A.OWNER, A.TABLE_NAME, WM_CONCAT(B.COLUMN_NAME) PK_COLUMNS FROM ALL_CONSTRAINTS A, ALL_CONS_COLUMNS B where A.CONSTRAINT_type = 'P' AND A.OWNER = '{$this->config->db->user}' AND A.TABLE_NAME = '{$this->table}' AND B.OWNER = A.OWNER AND A.TABLE_NAME = B.TABLE_NAME GROUP BY A.OWNER, A.TABLE_NAME;";