2481 lines
61 KiB
PHP
2481 lines
61 KiB
PHP
|
||
/**
|
||
* Class BaseMethod
|
||
* <20>ӿڶ<D3BF><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @auther Ӧ<><D3A6>
|
||
*/
|
||
class BaseMethod
|
||
{
|
||
// raw<61><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ֶ<EFBFBD><D6B6>Ƿ<EFBFBD>ԭʼ<D4AD><CABC><EFBFBD>ݴ<EFBFBD><DDB4>䣬Ϊtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݸ<EFBFBD>pdo
|
||
const PROPERTYNAME_RAW = 'raw';
|
||
// type<70><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
const PROPERTYNAME_TYPE = 'type';
|
||
// value<75><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶε<D6B6>ֵ
|
||
const PROPERTYNAME_VALUE = 'value';
|
||
|
||
// type<70><65><EFBFBD>Կ<EFBFBD>ѡֵ
|
||
const TYPENAME_STRING = 'string'; // <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
const TYPENAME_NUMBER = 'number'; // <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
||
const TYPENAME_DATE = 'date'; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
const TYPENAME_TIMESTAMP = 'timestamp'; // ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
const TYPENAME_LOB = 'lob'; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
const TYPENAME_RAW = 'raw'; // Դ<><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
|
||
// where <20>ֶ<EFBFBD>Ҫ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
||
const CONDITION_NAMES = 'conditions'; // <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
||
const CONDITION_VALUE = 'values'; // <20><><EFBFBD><EFBFBD>ֵ
|
||
|
||
|
||
// <20><>ѯ<EFBFBD>ֶ<EFBFBD>Ҫ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
||
const FIELDNAME_FIELD = 'field'; // Դ<>ֶ<EFBFBD><D6B6><EFBFBD>
|
||
const FIELDNAME_ALIAS = 'alias'; // <20><><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Alias
|
||
|
||
|
||
// sql<71><6C><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
||
const COMMAND_LINE = 'commandline';
|
||
const COMMAND_VARS = 'commandvars';
|
||
|
||
/**
|
||
* @note <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @var int
|
||
* @auther Ӧ<><D3A6>
|
||
*/
|
||
protected $ErrorCode;
|
||
|
||
/**
|
||
* @note <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||
* @var string|mixed
|
||
* @auther Ӧ<><D3A6>
|
||
*/
|
||
protected $ErrorInfo;
|
||
|
||
/**
|
||
* @var DatabaseHelper
|
||
*/
|
||
protected $Database;
|
||
|
||
//private $ReferenceCharacter;
|
||
private $RefCharLeft;
|
||
private $RefCharRight;
|
||
|
||
/**
|
||
* BaseMethod constructor.
|
||
*/
|
||
public function __construct()
|
||
{
|
||
if (0 == strcasecmp('MYSQL', DATABASE_TYPE))
|
||
{
|
||
$p = array(
|
||
PARAMETERNAME_HOSTNAME => DB_HOSTNAME,
|
||
PARAMETERNAME_HOSTPORT => DB_HOSTPORT,
|
||
PARAMETERNAME_DATABASE => DB_DATABASE,
|
||
PARAMETERNAME_USERNAME => DB_USERNAME,
|
||
PARAMETERNAME_PASSWORD => DB_PASSWORD,
|
||
PARAMETERNAME_CHARSET => DB_CHARSET,
|
||
);
|
||
|
||
$this->Database = new MYSQLHelper();
|
||
$this->Database->FetchStyle = PDO::FETCH_ASSOC;
|
||
if (!$this->Database->Connect($p))
|
||
{
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
|
||
$this->Database = null;
|
||
}
|
||
|
||
$this->RefCharLeft = '`';
|
||
$this->RefCharRight = '`';
|
||
}
|
||
elseif (0 == strcasecmp('SQLSRV', DATABASE_TYPE))
|
||
{
|
||
$p = array(
|
||
PARAMETERNAME_HOSTNAME => DB_HOSTNAME,
|
||
PARAMETERNAME_HOSTPORT => DB_HOSTPORT,
|
||
PARAMETERNAME_DATABASE => DB_DATABASE,
|
||
PARAMETERNAME_USERNAME => DB_USERNAME,
|
||
PARAMETERNAME_PASSWORD => DB_PASSWORD,
|
||
);
|
||
|
||
$this->Database = new SQLSRVHelper();
|
||
$this->Database->FetchStyle = PDO::FETCH_ASSOC;
|
||
if (!$this->Database->Connect($p))
|
||
{
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
|
||
$this->Database = null;
|
||
}
|
||
|
||
$this->RefCharLeft = '[';
|
||
$this->RefCharRight = ']';
|
||
}
|
||
elseif (0 == strcasecmp('ORACLE', DATABASE_TYPE))
|
||
{
|
||
$p = array(
|
||
PARAMETERNAME_HOSTNAME => DB_HOSTNAME,
|
||
PARAMETERNAME_HOSTPORT => DB_HOSTPORT,
|
||
PARAMETERNAME_SERVICE => DB_DATABASE,
|
||
PARAMETERNAME_USERNAME => DB_USERNAME,
|
||
PARAMETERNAME_PASSWORD => DB_PASSWORD,
|
||
);
|
||
|
||
$this->Database = new ORACLEHelper();
|
||
$this->Database->FetchStyle = PDO::FETCH_ASSOC;
|
||
if (!$this->Database->Connect($p))
|
||
{
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
|
||
$this->Database = null;
|
||
}
|
||
|
||
$this->RefCharLeft = '';
|
||
$this->RefCharRight = '';
|
||
}
|
||
else
|
||
{
|
||
$this->Database = null;
|
||
$this->ErrorCode = ERRORCODE_BADPARAMETER;
|
||
$this->ErrorInfo = sprintf(ERRORINFO_BADPARAMETER, 'dbtype', DATABASE_TYPE);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* BaseMethod destructor
|
||
*/
|
||
public function __destruct()
|
||
{
|
||
$this->Database = null;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note pdo<64><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>з<EFBFBD><D0B7>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param mixed
|
||
* @return mixed|null
|
||
*/
|
||
protected function PDO_Request()
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
$return = call_user_func_array(array($this->Database, 'Request'), func_get_args());
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
/**
|
||
* @note pdoִ<6F><D6B4><EFBFBD><EFBFBD>䣨<EFBFBD><EFBFBD><DEB7>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param mixed
|
||
* @return mixed|null
|
||
*/
|
||
protected function PDO_Execute()
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return null;
|
||
}
|
||
$return = call_user_func_array(array($this->Database, 'Execute'), func_get_args());
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
/**
|
||
* @note <20><><EFBFBD>һ<EFBFBD><D2BB>ִ<EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><F3A3ACB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>
|
||
* @param string $name
|
||
* @return bool|null|string
|
||
*/
|
||
protected function PDO_LastInsertId($name = null)
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
return $this->Database->LastInsertId($name);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @return bool|null
|
||
*/
|
||
protected function PDO_BeginTransaction()
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
return $this->Database->BeginTransaction();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note <20>ύһ<E1BDBB><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @return bool|null
|
||
*/
|
||
protected function PDO_Commit()
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
return $this->Database->Commit();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note <20>ع<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @return bool|null
|
||
*/
|
||
protected function PDO_Rollback()
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
return $this->Database->Rollback();
|
||
}
|
||
}
|
||
|
||
|
||
protected function GetRandString($prefix = '')
|
||
{
|
||
return (empty($prefix) ? '' : $prefix) . rand(1000, 9999);
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20><><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB6><EFBFBD>
|
||
* @param string $Identifiers Ҫ<><D2AA><EFBFBD><EFBFBD>ı<EFBFBD>ʶ<EFBFBD><CAB6>
|
||
* @param bool $Quoted <20>Ƿ<EFBFBD><C7B7>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param string $SpecialChar Ҫ<>ر<EFBFBD><D8B1><EFBFBD>(<28><><EFBFBD><EFBFBD>)<29><><EFBFBD>ַ<EFBFBD>
|
||
*/
|
||
protected function GetIdentifiers($Identifiers, $Quoted = false, $SpecialChar = null)
|
||
{
|
||
if (is_null($Identifiers) || '' == $Identifiers)
|
||
{
|
||
return '';
|
||
}
|
||
elseif ($Quoted)
|
||
{
|
||
$Length = mb_strlen($Identifiers, USEDCHARSET);
|
||
if ("'" == mb_substr($Identifiers, 0, 1, USEDCHARSET))
|
||
{
|
||
$Length--;
|
||
$Identifiers = mb_substr($Identifiers, 1, $Length, USEDCHARSET);
|
||
}
|
||
if ("'" == mb_substr($Identifiers, $Length - 1, 1, USEDCHARSET))
|
||
{
|
||
$Length--;
|
||
$Identifiers = mb_substr($Identifiers, 0, $Length, USEDCHARSET);
|
||
}
|
||
|
||
return "'" . str_replace("'", "''", $Identifiers) . "'";
|
||
}
|
||
elseif (!empty($SpecialChar) && mb_strstr($Identifiers, $SpecialChar, false, USEDCHARSET))
|
||
{
|
||
$Identifiers = str_replace($SpecialChar, $this->RefCharLeft . $SpecialChar . $this->RefCharRight, $Identifiers);
|
||
return $this->RefCharLeft . $Identifiers . $this->RefCharRight;
|
||
}
|
||
else
|
||
{
|
||
return $this->RefCharLeft . $Identifiers . $this->RefCharRight;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20><>ȡsql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param array|mixed $ands <20><><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array|mixed $ors <20><><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @return array
|
||
*/
|
||
private function GetWheres($ands = null, $ors = null)
|
||
{
|
||
if (is_object($ands))
|
||
{
|
||
$ands = (array)$ands;
|
||
}
|
||
if (is_object($ors))
|
||
{
|
||
$ors = (array)$ors;
|
||
}
|
||
|
||
$result = array(
|
||
Self::CONDITION_NAMES => '',
|
||
Self::CONDITION_VALUE => array(),
|
||
);
|
||
|
||
if (!empty($ands) || !empty($ors))
|
||
{
|
||
// and<6E><64><EFBFBD><EFBFBD>
|
||
$_ands = '1 = 1';
|
||
if (is_array($ands))
|
||
{
|
||
foreach ($ands as $k => $v)
|
||
{
|
||
if (null === $v)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (is_object($v))
|
||
{
|
||
$v = (array)$v;
|
||
}
|
||
|
||
// 2016-12-17<31><37>չ<EFBFBD><D5B9><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>raw<61><77><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>rawΪtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݡ<EFBFBD>
|
||
$raw = isset($v[Self::PROPERTYNAME_RAW]) ? $v[Self::PROPERTYNAME_RAW] : false;
|
||
$type = isset($v[Self::PROPERTYNAME_TYPE]) ? $v[Self::PROPERTYNAME_TYPE] : Self::TYPENAME_RAW;
|
||
// ֵ
|
||
if (is_array($v))
|
||
{
|
||
$v = isset($v[Self::PROPERTYNAME_VALUE]) ? $v[Self::PROPERTYNAME_VALUE] : null;
|
||
}
|
||
|
||
if ($raw)
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $this->Timestamp2DatetimeFormat($v));
|
||
}
|
||
else
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $this->String2DatetimeFormat($v));
|
||
}
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $v);
|
||
}
|
||
else
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $this->Datetime2TimestampFormat($v));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_STRING:
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $this->GetIdentifiers($v, true));
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $v);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $this->Timestamp2DatetimeFormat('?'));
|
||
}
|
||
else
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $this->String2DatetimeFormat('?', false));
|
||
}
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ands .= sprintf(' and %s = ?', $this->GetIdentifiers($k));
|
||
}
|
||
else
|
||
{
|
||
$_ands .= sprintf(' and %s = %s', $this->GetIdentifiers($k), $this->Datetime2TimestampFormat('?', false));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
$_ands .= sprintf(' and %s = ?', $this->GetIdentifiers($k));
|
||
break;
|
||
}
|
||
}
|
||
|
||
array_push($result[Self::CONDITION_VALUE], $v);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$_ands = empty($ands) ? '' : $ands;
|
||
}
|
||
|
||
// or <20><><EFBFBD><EFBFBD>
|
||
$_ors = '';
|
||
if (is_array($ors))
|
||
{
|
||
$_ors = '1 = 0';
|
||
foreach ($ors as $k => $v)
|
||
{
|
||
if (null === $v)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (is_object($v))
|
||
{
|
||
$v = (array)$v;
|
||
}
|
||
|
||
// 2016-12-17<31><37>չ<EFBFBD><D5B9><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>raw<61><77><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>rawΪtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݡ<EFBFBD>
|
||
$raw = isset($v[Self::PROPERTYNAME_RAW]) ? $v[Self::PROPERTYNAME_RAW] : false;
|
||
$type = isset($v[Self::PROPERTYNAME_TYPE]) ? $v[Self::PROPERTYNAME_TYPE] : Self::TYPENAME_RAW;
|
||
// ֵ
|
||
if (is_array($v))
|
||
{
|
||
$v = isset($v[Self::PROPERTYNAME_VALUE]) ? $v[Self::PROPERTYNAME_VALUE] : null;
|
||
}
|
||
|
||
if ($raw)
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $this->Timestamp2DatetimeFormat($v));
|
||
}
|
||
else
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $this->String2DatetimeFormat($v));
|
||
}
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $v);
|
||
}
|
||
else
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $this->Datetime2TimestampFormat($v));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_STRING:
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $this->GetIdentifiers($v, true));
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $v);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $this->Timestamp2DatetimeFormat('?'));
|
||
}
|
||
else
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $this->String2DatetimeFormat('?', false));
|
||
}
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$_ors .= sprintf(' or %s = ?', $this->GetIdentifiers($k));
|
||
}
|
||
else
|
||
{
|
||
$_ors .= sprintf(' or %s = %s', $this->GetIdentifiers($k), $this->Datetime2TimestampFormat('?', false));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
$_ors .= sprintf(' or %s = ?', $this->GetIdentifiers($k));
|
||
break;
|
||
}
|
||
}
|
||
|
||
array_push($result[Self::CONDITION_VALUE], $v);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$_ors = empty($ors) ? '' : $ors;
|
||
}
|
||
|
||
if (empty($_ands) && empty($_ors))
|
||
{
|
||
$result[Self::CONDITION_NAMES] = '';
|
||
}
|
||
elseif (empty($_ands))
|
||
{
|
||
$result[Self::CONDITION_NAMES] = $_ors;
|
||
}
|
||
elseif (empty($_ors))
|
||
{
|
||
$result[Self::CONDITION_NAMES] = $_ands;
|
||
}
|
||
else
|
||
{
|
||
$result[Self::CONDITION_NAMES] = '(' . $_ands . ') and (' . $_ors . ')';
|
||
}
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20><>ȡsql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||
* @param array|mixed $orders <20><><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @return string
|
||
*/
|
||
private function GetOrders($orders = null)
|
||
{
|
||
if (empty($orders))
|
||
{
|
||
return '';
|
||
}
|
||
|
||
if (is_object($orders))
|
||
$orders = (array)$orders;
|
||
|
||
if (is_array($orders))
|
||
{
|
||
$os = '';
|
||
foreach ($orders as $k => $v)
|
||
{
|
||
$os .= sprintf(' %s %s,', $this->GetIdentifiers($k, false, '.'), empty($v) ? 'asc' : $v);
|
||
}
|
||
|
||
$os = mb_substr($os, 0, mb_strlen($os, USEDCHARSET) - 1, USEDCHARSET);
|
||
}
|
||
else
|
||
{
|
||
$os = $orders;
|
||
}
|
||
|
||
return $os;
|
||
}
|
||
|
||
|
||
/**
|
||
* 2017-03-31 <20><><EFBFBD><EFBFBD>
|
||
* @note <20><>ȡsql<71><6C><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||
* @param array|mixed $groups <20><><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @return string
|
||
*/
|
||
private function GetGroups($groups = null)
|
||
{
|
||
if (empty($groups))
|
||
{
|
||
return '';
|
||
}
|
||
|
||
if (is_object($groups))
|
||
$groups = (array)$groups;
|
||
|
||
if (is_array($groups))
|
||
{
|
||
$gs = '';
|
||
foreach ($groups as $k => $v)
|
||
{
|
||
$gs .= sprintf(' %s,', $this->GetIdentifiers($v, false, '.'));
|
||
}
|
||
|
||
$gs = mb_substr($gs, 0, mb_strlen($gs, USEDCHARSET) - 1, USEDCHARSET);
|
||
}
|
||
else
|
||
{
|
||
$gs = $groups;
|
||
}
|
||
|
||
return $gs;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20><>ȡsql<71><6C>ѯ<EFBFBD><D1AF><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>Ϣ<EFBFBD><CFA2>2017-03-03<30><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param array|mixed $tables
|
||
* @return string
|
||
*/
|
||
private function GetSelectTables($tables = null)
|
||
{
|
||
if (is_object($tables))
|
||
{
|
||
$tables = (array)$tables;
|
||
}
|
||
|
||
if (is_array($tables))
|
||
{
|
||
$return = '';
|
||
|
||
foreach($tables as $k => $v)
|
||
{
|
||
// <20><><EFBFBD><EFBFBD>
|
||
if (!empty($k) && !is_numeric($k))
|
||
{
|
||
$return .= ',' . $this->GetIdentifiers($v, false, '.') . ' ' . $this->GetIdentifiers($k);
|
||
}
|
||
else
|
||
{
|
||
$return .= ',' . $this->GetIdentifiers($v, false, '.');
|
||
}
|
||
}
|
||
|
||
$sublen = mb_strlen(',', USEDCHARSET);
|
||
$return = mb_substr($return, $sublen, mb_strlen($return, USEDCHARSET) - $sublen, USEDCHARSET);
|
||
|
||
return $return;
|
||
}
|
||
else
|
||
{
|
||
return $this->GetIdentifiers($tables, false, ',');
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20><>ȡsql<71><6C>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>Ϣ
|
||
* @param array|mixed $fields<64><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=>ԭ<>ֶ<EFBFBD>/<2F><><EFBFBD>ʽ<EFBFBD><CABD>
|
||
* @return array
|
||
*/
|
||
private function GetSelectFields($fields = null)
|
||
{
|
||
$fs = array(
|
||
Self::FIELDNAME_FIELD => '',
|
||
Self::FIELDNAME_ALIAS => '',
|
||
);
|
||
|
||
if (is_object($fields))
|
||
{
|
||
$fields = (array)$fields;
|
||
}
|
||
|
||
if (is_array($fields))
|
||
{
|
||
foreach($fields as $k => $v)
|
||
{
|
||
if (is_object($v) || is_array($v))
|
||
{
|
||
$arr = $this->GetSelectFields($v);
|
||
$fs[Self::FIELDNAME_FIELD] .= ', ' . $arr[Self::FIELDNAME_FIELD];
|
||
$fs[Self::FIELDNAME_ALIAS] .= ', ' . $arr[Self::FIELDNAME_ALIAS];
|
||
continue;
|
||
}
|
||
elseif (null === $v)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
// 2017-03-03<30><33><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD>.<2E>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||
$nv = mb_strstr($v, '.', false, USEDCHARSET);
|
||
if (!empty($nv)) // <20><><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB6><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
$v = $this->GetIdentifiers($v, false, '.');
|
||
|
||
$sublen = mb_strlen('.', USEDCHARSET);
|
||
$nv = $this->GetIdentifiers(mb_substr($nv, $sublen, mb_strlen($nv, USEDCHARSET) - $sublen, USEDCHARSET));
|
||
}
|
||
else
|
||
{
|
||
$v = $this->GetIdentifiers($v);
|
||
$nv = $v;
|
||
}
|
||
|
||
// <20><><EFBFBD><EFBFBD>
|
||
if (!empty($k) && !is_numeric($k))
|
||
{
|
||
$k = $this->GetIdentifiers($k);
|
||
|
||
$fs[Self::FIELDNAME_FIELD] .= ', ' . $v . ' ' . $k;
|
||
$fs[Self::FIELDNAME_ALIAS] .= ', ' . $k;
|
||
}
|
||
else
|
||
{
|
||
$fs[Self::FIELDNAME_FIELD] .= ', ' . $v;
|
||
$fs[Self::FIELDNAME_ALIAS] .= ', ' . $nv;
|
||
}
|
||
}
|
||
|
||
$sublen = mb_strlen(', ', USEDCHARSET);
|
||
|
||
if (!empty($fs[Self::FIELDNAME_FIELD]))
|
||
{
|
||
$fs[Self::FIELDNAME_FIELD] = mb_substr($fs[Self::FIELDNAME_FIELD], $sublen, mb_strlen($fs[Self::FIELDNAME_FIELD], USEDCHARSET) - $sublen, USEDCHARSET);
|
||
}
|
||
|
||
if (!empty($fs[Self::FIELDNAME_ALIAS]))
|
||
{
|
||
$fs[Self::FIELDNAME_ALIAS] = mb_substr($fs[Self::FIELDNAME_ALIAS], $sublen, mb_strlen($fs[Self::FIELDNAME_ALIAS], USEDCHARSET) - $sublen, USEDCHARSET);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$fs[Self::FIELDNAME_FIELD] = $fields;
|
||
$fs[Self::FIELDNAME_ALIAS] = $fields;
|
||
}
|
||
|
||
return $fs;
|
||
}
|
||
|
||
|
||
/**
|
||
* 2016-12-17<31><37>չ<EFBFBD><D5B9><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>raw<61><77><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>rawΪtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݡ<EFBFBD>
|
||
* @note ִ<><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param string $tablename <20><><EFBFBD><EFBFBD>
|
||
* @param array $fields <20>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param bool $replace <20>ǷDz<F1B8B2B8><C7B2><EFBFBD>
|
||
* @param array|string $refer <20><><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8><EFBFBD>ʱ, <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
||
* @return bool|mixed|null
|
||
*/
|
||
protected function PDO_Insert($tablename, $fields, $replace = false, $refer = null)
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return false;
|
||
}
|
||
if (is_object($fields))
|
||
{
|
||
$fields = (array)$fields;
|
||
}
|
||
|
||
$ks = '';
|
||
$kss = '';
|
||
$kst = '';
|
||
$ksv = '';
|
||
$ps = '';
|
||
$ss = '';
|
||
$vs = array();
|
||
foreach ($fields as $k => $v)
|
||
{
|
||
if (null === $v)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (is_object($v))
|
||
{
|
||
$v = (array)$v;
|
||
}
|
||
|
||
// 2016-12-17<31><37>չ<EFBFBD><D5B9><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>raw<61><77><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>rawΪtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݡ<EFBFBD>
|
||
$raw = isset($v[Self::PROPERTYNAME_RAW]) ? $v[Self::PROPERTYNAME_RAW] : false;
|
||
$type = isset($v[Self::PROPERTYNAME_TYPE]) ? $v[Self::PROPERTYNAME_TYPE] : Self::TYPENAME_RAW;
|
||
// ֵ
|
||
if (is_array($v))
|
||
{
|
||
$v = isset($v[Self::PROPERTYNAME_VALUE]) ? $v[Self::PROPERTYNAME_VALUE] : null;
|
||
}
|
||
|
||
/* <20><>ʼƴsql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>ֵ */
|
||
// ԭʼ<D4AD><CABC><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
||
$ks .= sprintf('%s,', $this->GetIdentifiers($k));
|
||
// ԭ<><D4AD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$kss .= sprintf('s.%s,', $this->GetIdentifiers($k));
|
||
// Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$kst .= sprintf('t.%s,', $this->GetIdentifiers($k));
|
||
// <20><>ֵ<EFBFBD><D6B5>ϵ<EFBFBD><CFB5><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>
|
||
$ksv .= sprintf('s.%s = t.%s,', $this->GetIdentifiers($k), $this->GetIdentifiers($k));
|
||
|
||
// 2016-12-17<31><37>չ<EFBFBD><D5B9><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>raw<61><77><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>rawΪtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݡ<EFBFBD>
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||
if ($raw)
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $this->Timestamp2DatetimeFormat($v) . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $this->Timestamp2DatetimeFormat($v), $this->GetIdentifiers($k));
|
||
}
|
||
else
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $this->String2DatetimeFormat($v) . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $this->String2DatetimeFormat($v), $this->GetIdentifiers($k));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $v . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $v, $this->GetIdentifiers($k));
|
||
}
|
||
else
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $this->Datetime2TimestampFormat($v) . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $this->Datetime2TimestampFormat($v), $this->GetIdentifiers($k));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_STRING:
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $this->GetIdentifiers($v, true) . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $this->GetIdentifiers($v, true), $this->GetIdentifiers($k));
|
||
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $v . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $v, $this->GetIdentifiers($k));
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $this->Timestamp2DatetimeFormat('?') . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $this->Timestamp2DatetimeFormat('?'), $this->GetIdentifiers($k));
|
||
}
|
||
else
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $this->String2DatetimeFormat('?', false) . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $this->String2DatetimeFormat('?', false), $this->GetIdentifiers($k));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= '?,';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('? %s,', $this->GetIdentifiers($k));
|
||
}
|
||
else
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= $this->Datetime2TimestampFormat('?', false) . ',';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('%s %s,', $this->Datetime2TimestampFormat('?', false), $this->GetIdentifiers($k));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps .= '?,';
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss .= sprintf('? %s,', $this->GetIdentifiers($k));
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
// <20><><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
|
||
array_push($vs, $v);
|
||
}
|
||
}
|
||
|
||
if (0 == count($vs))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// ԭʼ<D4AD><CABC><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
||
$ks = mb_substr($ks, 0, mb_strlen($ks, USEDCHARSET) - 1, USEDCHARSET);
|
||
// ԭ<><D4AD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$kss = mb_substr($kss, 0, mb_strlen($kss, USEDCHARSET) - 1, USEDCHARSET);
|
||
// Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$kst = mb_substr($kst, 0, mb_strlen($kst, USEDCHARSET) - 1, USEDCHARSET);
|
||
// <20><>ֵ<EFBFBD><D6B5>ϵ<EFBFBD><CFB5><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>
|
||
$ksv = mb_substr($ksv, 0, mb_strlen($ksv, USEDCHARSET) - 1, USEDCHARSET);
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>mask
|
||
$ps = mb_substr($ps, 0, mb_strlen($ps, USEDCHARSET) - 1, USEDCHARSET);
|
||
// <20><>ѯ<EFBFBD><D1AF><EFBFBD>ʱʹ<CAB1>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD>
|
||
$ss = mb_substr($ss, 0, mb_strlen($ss, USEDCHARSET) - 1, USEDCHARSET);
|
||
|
||
$command = '';
|
||
$repcmd = '';
|
||
$inscmd = '';
|
||
$rs = '';
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
$repcmd = sprintf('replace into %s(%s) values (%s)', $this->GetIdentifiers($tablename), $ks, $ps);
|
||
$inscmd = sprintf('insert into %s(%s) values (%s)', $this->GetIdentifiers($tablename), $ks, $ps);
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
if (is_array($refer) && count($refer))
|
||
{
|
||
foreach ($refer as $k => $v)
|
||
{
|
||
$rs .= sprintf(' s.%s = t.%s and', $this->GetIdentifiers($v), $this->GetIdentifiers($v));
|
||
}
|
||
|
||
$rs = mb_substr($rs, 0, mb_strlen($rs, USEDCHARSET) - 3, USEDCHARSET);
|
||
}
|
||
else
|
||
{
|
||
$rs = $refer;
|
||
}
|
||
|
||
if (mb_strlen($rs, USEDCHARSET))
|
||
{
|
||
$command =
|
||
'merge into %s t' . PHP_EOL .
|
||
'using (select %s from dual) s' . PHP_EOL .
|
||
'on %s' . PHP_EOL .
|
||
'when matched then' . PHP_EOL .
|
||
' update set %s' . PHP_EOL .
|
||
'when not matched then' . PHP_EOL .
|
||
' insert' . PHP_EOL .
|
||
' (%s)' . PHP_EOL .
|
||
' values' . PHP_EOL .
|
||
' (%s)';
|
||
|
||
$repcmd = sprintf($command,
|
||
$this->GetIdentifiers($tablename),
|
||
$ss,
|
||
$rs,
|
||
$ksv,
|
||
$kst,
|
||
$kss);
|
||
}
|
||
else
|
||
{
|
||
$repcmd = '';
|
||
}
|
||
|
||
$inscmd = sprintf('insert into %s(%s) values (%s)', $this->GetIdentifiers($tablename), $ks, $ps);
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
if (is_array($refer) && count($refer))
|
||
{
|
||
foreach ($refer as $k => $v)
|
||
{
|
||
$rs .= sprintf(' s.%s = t.%s and', $this->GetIdentifiers($v), $this->GetIdentifiers($v));
|
||
}
|
||
|
||
$rs = mb_substr($rs, 0, mb_strlen($rs, USEDCHARSET) - 3, USEDCHARSET);
|
||
}
|
||
else
|
||
{
|
||
$rs = $refer;
|
||
}
|
||
|
||
if (mb_strlen($rs, USEDCHARSET))
|
||
{
|
||
$command =
|
||
'merge into %s t' . PHP_EOL .
|
||
'using (select %s) s' . PHP_EOL .
|
||
'on %s' . PHP_EOL .
|
||
'when matched then' . PHP_EOL .
|
||
' update set %s' . PHP_EOL .
|
||
'when not matched then' . PHP_EOL .
|
||
' insert' . PHP_EOL .
|
||
' (%s)' . PHP_EOL .
|
||
' values' . PHP_EOL .
|
||
' (%s)';
|
||
|
||
$repcmd = sprintf($command,
|
||
$this->GetIdentifiers($tablename),
|
||
$ss,
|
||
$rs,
|
||
$ksv,
|
||
$kst,
|
||
$kss);
|
||
}
|
||
else
|
||
{
|
||
$repcmd = '';
|
||
}
|
||
|
||
$inscmd = sprintf('insert into %s(%s) values (%s)', $this->GetIdentifiers($tablename), $ks, $ps);
|
||
break;
|
||
|
||
default:
|
||
$this->ErrorCode = ERRORCODE_BADPARAMETER;
|
||
$this->ErrorInfo = sprintf(ERRORINFO_BADPARAMETER, 'dbtype', DATABASE_TYPE);
|
||
return false;
|
||
break;
|
||
}
|
||
|
||
$command = $replace ? $repcmd : $inscmd;
|
||
$return = $this->PDO_Execute($command, $vs);
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
/**
|
||
* 2016-12-17<31><37>չ<EFBFBD><D5B9><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>raw<61><77><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>rawΪtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݡ<EFBFBD>
|
||
* @note ִ<><D6B4>һ<EFBFBD><D2BB><EFBFBD>Ĺ<DEB8><C4B9><EFBFBD>
|
||
* @param string $tablename <20><><EFBFBD><EFBFBD>
|
||
* @param string $fields <20>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $ands <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>and<6E><64><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $ors <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>or<6F><72><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @return bool|mixed|null
|
||
*/
|
||
protected function PDO_Update($tablename, $fields, $ands = null, $ors = null)
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return false;
|
||
}
|
||
if (is_object($fields))
|
||
{
|
||
$fields = (array)$fields;
|
||
}
|
||
|
||
$vs = array();
|
||
|
||
if (is_array($fields))
|
||
{
|
||
$fs = '';
|
||
foreach ($fields as $k => $v)
|
||
{
|
||
if (null === $v)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (is_object($v))
|
||
{
|
||
$v = (array)$v;
|
||
}
|
||
|
||
// 2016-12-17<31><37>չ<EFBFBD><D5B9><EFBFBD>ֶ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>raw<61><77><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>rawΪtrue<75><65><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ݡ<EFBFBD>
|
||
$raw = isset($v[Self::PROPERTYNAME_RAW]) ? $v[Self::PROPERTYNAME_RAW] : false;
|
||
$type = isset($v[Self::PROPERTYNAME_TYPE]) ? $v[Self::PROPERTYNAME_TYPE] : Self::TYPENAME_RAW;
|
||
// ֵ
|
||
if (is_array($v))
|
||
{
|
||
$v = isset($v[Self::PROPERTYNAME_VALUE]) ? $v[Self::PROPERTYNAME_VALUE] : null;
|
||
}
|
||
|
||
if ($raw)
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $this->Timestamp2DatetimeFormat($v));
|
||
}
|
||
else
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $this->String2DatetimeFormat($v));
|
||
}
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $v);
|
||
}
|
||
else
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $this->Datetime2TimestampFormat($v));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_STRING:
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $this->GetIdentifiers($v, true));
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $v);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch ($type)
|
||
{
|
||
case Self::TYPENAME_DATE:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $this->Timestamp2DatetimeFormat('?'));
|
||
}
|
||
else
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $this->String2DatetimeFormat('?', false));
|
||
}
|
||
break;
|
||
}
|
||
|
||
case Self::TYPENAME_TIMESTAMP:
|
||
{
|
||
if (is_numeric($v))
|
||
{
|
||
$fs .= sprintf('%s = ?,', $this->GetIdentifiers($k, false, '.'));
|
||
}
|
||
else
|
||
{
|
||
$fs .= sprintf('%s = %s,', $this->GetIdentifiers($k, false, '.'), $this->Datetime2TimestampFormat('?', false));
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
default:
|
||
{
|
||
$fs .= sprintf('%s = ?,', $this->GetIdentifiers($k, false, '.'));
|
||
break;
|
||
}
|
||
}
|
||
|
||
array_push($vs, $v);
|
||
}
|
||
}
|
||
|
||
if (empty($fs))
|
||
{
|
||
return false;
|
||
}
|
||
$fs = mb_substr($fs, 0, mb_strlen($fs, USEDCHARSET) - 1, USEDCHARSET);
|
||
}
|
||
else
|
||
{
|
||
$fs = $fields;
|
||
}
|
||
|
||
$ws = $this->GetWheres($ands, $ors);
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command = sprintf('update %s set %s', $this->GetIdentifiers($tablename, false, ','), $fs);
|
||
$return = $this->PDO_Execute($command, $vs);
|
||
}
|
||
else
|
||
{
|
||
$command = sprintf('update %s set %s where %s', $this->GetIdentifiers($tablename, false, ','), $fs, $ws[Self::CONDITION_NAMES]);
|
||
$return = $this->PDO_Execute($command, $vs, $ws[Self::CONDITION_VALUE]);
|
||
}
|
||
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
/**
|
||
* @note ִ<><D6B4>һ<EFBFBD><D2BB>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param string $tablename <20><><EFBFBD><EFBFBD>
|
||
* @param array $ands <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>and<6E><64><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $ors <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>or<6F><72><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @return bool|mixed|null
|
||
*/
|
||
protected function PDO_Delete($tablename, $ands = null, $ors = null)
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
$ws = $this->GetWheres($ands, $ors);
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command = sprintf('delete from %s', $this->GetIdentifiers($tablename));
|
||
$return = $this->PDO_Execute($command);
|
||
}
|
||
else
|
||
{
|
||
$command = sprintf('delete from %s where %s', $this->GetIdentifiers($tablename), $ws[Self::CONDITION_NAMES]);
|
||
$return = $this->PDO_Execute($command, $ws[Self::CONDITION_VALUE]);
|
||
}
|
||
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
|
||
/**
|
||
* 2017-03-31 <20><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>֧<EFBFBD><D6A7>
|
||
* @note ִ<><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
|
||
* @param string|array $tables <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2017-03-03<30><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>֣<EFBFBD>
|
||
* @param string|array $fields Ҫ<><D2AA>ѯ<EFBFBD><D1AF><EFBFBD>ֶΣ<D6B6>2016-12-08<30><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>֣<EFBFBD><D6A3><EFBFBD>ʽΪ<CABD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=>ԭ<>ֶ<EFBFBD>/<2F><><EFBFBD>ʽ<EFBFBD><CABD>
|
||
* @param array $ands <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>and<6E><64><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $ors <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>or<6F><72><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $orders <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD>=<3D><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>
|
||
* @param array $groups <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @return bool|mixed|null
|
||
*/
|
||
protected function PDO_Select($tables, $fields, $ands = null, $ors = null, $orders = null, $groups = null)
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
$tables = $this->GetSelectTables($tables);
|
||
$fields = $this->GetSelectFields($fields)[Self::FIELDNAME_FIELD];
|
||
if (empty($tables) || empty($fields))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
$gs = $this->GetGroups($groups);
|
||
if (!empty($gs))
|
||
{
|
||
$gs = ' group by ' . $gs;
|
||
}
|
||
|
||
$os = $this->GetOrders($orders);
|
||
if (!empty($os))
|
||
{
|
||
$os = ' order by ' . $os;
|
||
}
|
||
|
||
$ws = $this->GetWheres($ands, $ors);
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command = sprintf('select %s from %s%s%s', $fields, $tables, $gs, $os);
|
||
$return = $this->PDO_Request($command);
|
||
}
|
||
else
|
||
{
|
||
$command = sprintf('select %s from %s where %s%s%s', $fields, $tables, $ws[Self::CONDITION_NAMES], $gs, $os);
|
||
$return = $this->PDO_Request($command, $ws[Self::CONDITION_VALUE]);
|
||
}
|
||
|
||
//var_dump($command);
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
|
||
/**
|
||
* 2016-08-16<31><36><EFBFBD>ӡ<EFBFBD>2017-03-31<33><31><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>֧<EFBFBD><D6A7>
|
||
* @note ִ<><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD>̣<EFBFBD><CCA3><EFBFBD>ҳ<EFBFBD><D2B3>
|
||
* @param string|array $tables <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2017-03-03<30><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>֣<EFBFBD>
|
||
* @param string|array $fields Ҫ<><D2AA>ѯ<EFBFBD><D1AF><EFBFBD>ֶΣ<D6B6>2016-12-08<30><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>֣<EFBFBD><D6A3><EFBFBD>ʽΪ<CABD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=>ԭ<>ֶ<EFBFBD>/<2F><><EFBFBD>ʽ<EFBFBD><CABD>
|
||
* @param array $ands <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>and<6E><64><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $ors <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>or<6F><72><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $orders <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD>=<3D><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>
|
||
* @param array $groups <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param int $pageindex ҳ<><D2B3>ţ<EFBFBD>1Ϊ<31><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ţ<EFBFBD>
|
||
* @param int $pagesize һҳ<D2BB><D2B3>С
|
||
* @return bool|mixed|null
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
protected function PDO_Select_Page($tables, $fields, $ands = null, $ors = null, $orders = null, $groups = null, $pageindex = 1, $pagesize = 20)
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// <20>ɴ<EFBFBD><C9B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
if (is_numeric($groups))
|
||
{
|
||
$pagesize = $pageindex;
|
||
$pageindex = $groups;
|
||
$groups = null;
|
||
}
|
||
|
||
// <20><>ʼ<EFBFBD><CABC><EFBFBD>
|
||
$start = ($pageindex - 1) * $pagesize + 1;
|
||
// <20><>ֹ<EFBFBD><D6B9><EFBFBD>
|
||
$stop = $pageindex * $pagesize;
|
||
|
||
// <20><>ҳ<EFBFBD>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD>
|
||
$newfieldname = $this->GetIdentifiers($this->GetRandString('nf_'));
|
||
// <20><>ҳ<EFBFBD>õı<C3B5><C4B1><EFBFBD>
|
||
$newtablename = $this->GetIdentifiers($this->GetRandString('nt_'));
|
||
|
||
// Ҫ<><D2AA>ѯ<EFBFBD>ı<EFBFBD>
|
||
$tables = $this->GetSelectTables($tables);
|
||
// Ҫ<><D2AA>ѯ<EFBFBD><D1AF><EFBFBD>ֶ<EFBFBD>
|
||
$fields = $this->GetSelectFields($fields);
|
||
|
||
if (empty($tables) || empty($fields[Self::FIELDNAME_FIELD]) || empty($fields[Self::FIELDNAME_ALIAS]))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
$gs = $this->GetGroups($groups);
|
||
if (!empty($gs))
|
||
{
|
||
$gs = ' group by ' . $gs;
|
||
}
|
||
|
||
$os = $this->GetOrders($orders);
|
||
if (!empty($os))
|
||
{
|
||
$os = ' order by ' . $os;
|
||
}
|
||
|
||
$ws = $this->GetWheres($ands, $ors);
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' @i := @i + 1 %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' (select @i := 0) %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' $s' . PHP_EOL .
|
||
' limit %d' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s >= %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$newfieldname,
|
||
$tables,
|
||
$newtablename,
|
||
$gs,
|
||
$os,
|
||
$stop,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start
|
||
);
|
||
//var_dump($command);
|
||
$return = $this->PDO_Request($command);
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' @i := @i + 1 %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' (select @i := 0) %s' . PHP_EOL .
|
||
' where' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' limit %d' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s >= %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$newfieldname,
|
||
$tables,
|
||
$newtablename,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$os,
|
||
$stop,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start
|
||
);
|
||
//var_dump($command);
|
||
$return = $this->PDO_Request($command, $ws[Self::CONDITION_VALUE]);
|
||
}
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
//' where' . PHP_EOL .
|
||
//' rownum <= %d' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
$tables,
|
||
//$stop,
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
//var_dump($command);
|
||
$return = $this->PDO_Request($command);
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' where' . PHP_EOL .
|
||
//' rownum <= %d and' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
$tables,
|
||
//$stop,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
//var_dump($command);
|
||
$return = $this->PDO_Request($command, $ws[Self::CONDITION_VALUE]);
|
||
}
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
//' top %d' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
//$stop,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
$tables,
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
//var_dump($command);
|
||
$return = $this->PDO_Request($command);
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
//' top %d' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' where' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
//$stop,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
$tables,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
//var_dump($command);
|
||
$return = $this->PDO_Request($command, $ws[Self::CONDITION_VALUE]);
|
||
}
|
||
break;
|
||
|
||
default:
|
||
$this->ErrorCode = ERRORCODE_BADPARAMETER;
|
||
$this->ErrorInfo = sprintf(ERRORINFO_BADPARAMETER, 'dbtype', DATABASE_TYPE);
|
||
return false;
|
||
break;
|
||
}
|
||
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
/**
|
||
* 2017-02-17<31><37><EFBFBD>ӡ<EFBFBD>2017-03-31<33><31><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>֧<EFBFBD><D6A7>
|
||
* @note <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD>Ӧ<EFBFBD><D3A6>sql<71><6C>䡣
|
||
* @param string $request <20>Ӳ<EFBFBD>ѯ<EFBFBD><D1AF>
|
||
* @param string|array $tablename <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param bool $ispage <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA>ҳ<EFBFBD><D2B3>
|
||
* @param string $fields Ҫ<><D2AA>ѯ<EFBFBD><D1AF><EFBFBD>ֶΣ<D6B6><CEA3><EFBFBD><EFBFBD><EFBFBD>=>ԭ<>ֶ<EFBFBD>/<2F><><EFBFBD>ʽ<EFBFBD><CABD>
|
||
* @param array $ands <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>and<6E><64><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $ors <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>or<6F><72><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $orders <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD>=<3D><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>
|
||
* @param array $groups <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param int $pageindex ҳ<><D2B3>ţ<EFBFBD>1Ϊ<31><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ţ<EFBFBD>
|
||
* @param int $pagesize һҳ<D2BB><D2B3>С
|
||
* @return bool|mixed|null
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
private function GetSelectPageCommand($request, $tablename, $ispage, $fields, $ands = null, $ors = null, $orders = null, $groups = null, $pageindex = 1, $pagesize = 20)
|
||
{
|
||
$return = array(
|
||
Self::COMMAND_LINE => '',
|
||
Self::COMMAND_VARS => array(),
|
||
);
|
||
|
||
// <20><>ҳ<EFBFBD>õ<EFBFBD><C3B5>ֶ<EFBFBD><D6B6><EFBFBD>
|
||
$newfieldname = $this->GetIdentifiers($this->GetRandString('nf_'));
|
||
// <20><>ҳ<EFBFBD>õı<C3B5><C4B1><EFBFBD>
|
||
$newtablename = $this->GetIdentifiers($this->GetRandString('nt_'));
|
||
// <20>Ӳ<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
|
||
$newrequest = $this->GetIdentifiers($this->GetRandString('nr_'));
|
||
|
||
// <20><><EFBFBD><EFBFBD>
|
||
$tablename = $this->GetSelectTables($tablename);
|
||
// <20>ֶ<EFBFBD><D6B6><EFBFBD>
|
||
$fields = $this->GetSelectFields($fields);
|
||
if (empty($tablename) || empty($fields[Self::FIELDNAME_FIELD]) || empty($fields[Self::FIELDNAME_ALIAS]))
|
||
{
|
||
return $return;
|
||
}
|
||
|
||
$gs = $this->GetGroups($groups);
|
||
if (!empty($gs))
|
||
{
|
||
$gs = ' group by ' . $gs;
|
||
}
|
||
|
||
$os = $this->GetOrders($orders);
|
||
if (!empty($os))
|
||
{
|
||
$os = ' order by ' . $os;
|
||
}
|
||
|
||
if ($ispage)
|
||
{
|
||
// <20><>ʼ<EFBFBD><CABC><EFBFBD>
|
||
$start = ($pageindex - 1) * $pagesize + 1;
|
||
// <20><>ֹ<EFBFBD><D6B9><EFBFBD>
|
||
$stop = $pageindex * $pagesize;
|
||
|
||
$ws = $this->GetWheres($ands, $ors);
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' @i := @i + 1 %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
'%s' .
|
||
' %s,' . PHP_EOL .
|
||
' (select @i := 0) %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' limit %d' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s >= %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$newfieldname,
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$newtablename,
|
||
$gs,
|
||
$os,
|
||
$stop,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = array();
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' @i := @i + 1 %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
'%s' .
|
||
' %s,' . PHP_EOL .
|
||
' (select @i := 0) %s' . PHP_EOL .
|
||
' where' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' limit %d' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s >= %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$newfieldname,
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$newtablename,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$os,
|
||
$stop,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = $ws[Self::CONDITION_VALUE];
|
||
}
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
//' where' . PHP_EOL .
|
||
//' rownum <= %d' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
//$stop,
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = array();
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
' where' . PHP_EOL .
|
||
//' rownum <= %d and' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
//$stop,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = $ws[Self::CONDITION_VALUE];
|
||
}
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
//' top %d' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
//$stop,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = array();
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
' (' . PHP_EOL .
|
||
' select' . PHP_EOL .
|
||
//' top %d' . PHP_EOL .
|
||
' %s,' . PHP_EOL .
|
||
' row_number() over(%s) %s' . PHP_EOL .
|
||
' from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
' where' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' ) %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s between %d and %d';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_ALIAS],
|
||
//$stop,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
$os,
|
||
$newfieldname,
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$newtablename,
|
||
$newfieldname,
|
||
$start,
|
||
$stop
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = $ws[Self::CONDITION_VALUE];
|
||
}
|
||
break;
|
||
|
||
}
|
||
|
||
return $return;
|
||
}
|
||
else
|
||
{
|
||
$ws = $this->GetWheres($ands, $ors);
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$gs,
|
||
$os
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = array();
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$os
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = $ws[Self::CONDITION_VALUE];
|
||
}
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$gs,
|
||
$os
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = array();
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$os
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = $ws[Self::CONDITION_VALUE];
|
||
}
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
if (empty($ws[Self::CONDITION_NAMES]))
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$gs,
|
||
$os
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = array();
|
||
}
|
||
else
|
||
{
|
||
$command =
|
||
'select' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
'from' . PHP_EOL .
|
||
'%s' .
|
||
' %s' . PHP_EOL .
|
||
'where' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s' . PHP_EOL .
|
||
' %s';
|
||
$command = sprintf($command,
|
||
$fields[Self::FIELDNAME_FIELD],
|
||
empty($request) ? '' : ' (' . $request . ') ' . $newrequest . ',' . PHP_EOL,
|
||
$tablename,
|
||
$ws[Self::CONDITION_NAMES],
|
||
$gs,
|
||
$os
|
||
);
|
||
|
||
$return[Self::COMMAND_LINE] = $command;
|
||
$return[Self::COMMAND_VARS] = $ws[Self::CONDITION_VALUE];
|
||
}
|
||
break;
|
||
|
||
}
|
||
|
||
return $return;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 2017-02-17<31><37><EFBFBD><EFBFBD>
|
||
* @note ִ<><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD>̣<EFBFBD><CCA3><EFBFBD>ҳ<EFBFBD><D2B3>
|
||
* <20><><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><CABD>ѯ<EFBFBD><D1AF><EFBFBD>ݡ<EFBFBD>oracle<6C><65>sqlserver<65><72><EFBFBD>Ҫʹ<D2AA><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD>Ҫ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD>ֶε<D6B6><CEB5><EFBFBD><EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><CABD>
|
||
* <20><><EFBFBD><EFBFBD>
|
||
* oracle<6C>У<EFBFBD> <20><>1.<2E>ֶ<EFBFBD>1 = <20><>2.<2E>ֶ<EFBFBD>2(+) <20>ȼ<EFBFBD> <20><>1 left join <20><>2 on <20><>1.<2E>ֶ<EFBFBD>1 = <20><>2.<2E>ֶ<EFBFBD>2
|
||
* sqlserver<65>У<EFBFBD> <20><>1.<2E>ֶ<EFBFBD>1 *= <20><>2.<2E>ֶ<EFBFBD>2 <20>ȼ<EFBFBD> <20><>1 left join <20><>2 on <20><>1.<2E>ֶ<EFBFBD>1 = <20><>2.<2E>ֶ<EFBFBD>2
|
||
* @param array $tables <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
||
* @param string $pagetable Ҫ<><D2AA>ҳ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>б<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||
* @param string $fields Ҫ<><D2AA>ѯ<EFBFBD><D1AF><EFBFBD>ֶΣ<D6B6><CEA3><EFBFBD><EFBFBD><EFBFBD>=>ԭ<>ֶ<EFBFBD>/<2F><><EFBFBD>ʽ<EFBFBD><CABD>
|
||
* @param array $ands <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>and<6E><64><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $ors <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>or<6F><72><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>=<3D>ֶ<EFBFBD>ֵ<EFBFBD><D6B5>
|
||
* @param array $orders <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD>=<3D><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>
|
||
* @param array $groups <20><><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param int $pageindex ҳ<><D2B3>ţ<EFBFBD>1Ϊ<31><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ţ<EFBFBD>
|
||
* @param int $pagesize һҳ<D2BB><D2B3>С
|
||
* @return bool|mixed|null
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
protected function PDO_Select_Page_2($tables, $pagetable, $fields, $ands = null, $ors = null, $orders = null, $groups = null, $pageindex = 1, $pagesize = 20)
|
||
{
|
||
if (null == $this->Database)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// <20>ɴ<EFBFBD><C9B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
if (is_numeric($groups))
|
||
{
|
||
$pagesize = $pageindex;
|
||
$pageindex = $groups;
|
||
$groups = null;
|
||
}
|
||
|
||
$fields = array_values((array)$fields);
|
||
$ands = array_values((array)$ands);
|
||
$ors = array_values((array)$ors);
|
||
|
||
$commandline = '';
|
||
$commandvars = array();
|
||
$commandfield = array();
|
||
$index = 0;
|
||
|
||
foreach ($tables as $tablealias => $tablename)
|
||
{
|
||
$t = $commandfield;
|
||
$commandfield = array();
|
||
foreach ($t as $k => $v)
|
||
{
|
||
array_push($commandfield, (is_numeric($k) || empty($k) ? $v : $k));
|
||
}
|
||
|
||
$fields[$index] = isset($fields[$index]) ? (array)$fields[$index] : array();
|
||
if (!empty($fields[$index]))
|
||
{
|
||
foreach ($fields[$index] as $k => $v)
|
||
{
|
||
if (is_numeric($k) || empty($k))
|
||
array_push($commandfield, $v);
|
||
else
|
||
$commandfield[$k] = $v;
|
||
}
|
||
}
|
||
|
||
$command = $this->GetSelectPageCommand($commandline,
|
||
array($tablealias => $tablename),
|
||
strcasecmp($tablename, $pagetable) == 0,
|
||
$commandfield,
|
||
isset($ands[$index]) ? $ands[$index] : null,
|
||
isset($ors[$index]) ? $ors[$index] : null,
|
||
empty($orders) ? null : $orders[$index],
|
||
empty($groups) ? null : $groups[$index],
|
||
$pageindex,
|
||
$pagesize
|
||
);
|
||
|
||
$commandline = $command[Self::COMMAND_LINE];
|
||
$commandvars += $command[Self::COMMAND_VARS];
|
||
|
||
$index++;
|
||
}
|
||
//OutputDebugMessage($commandline);
|
||
//var_dump($commandline);
|
||
//var_dump($commandvars);
|
||
$return = $this->PDO_Request($commandline, $commandvars);
|
||
$this->ErrorCode = $this->Database->GetErrorCode();
|
||
$this->ErrorInfo = $this->Database->GetErrorInfo();
|
||
return $return;
|
||
}
|
||
|
||
|
||
/**
|
||
* 2016-12-08<30><38><EFBFBD><EFBFBD>
|
||
* @note <20>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>͵ı<CDB5><C4B1>ʽ
|
||
* @param string $st Ҫת<D2AA><D7AA><EFBFBD><EFBFBD><EFBFBD>ֶλ<D6B6><CEBB><EFBFBD>ʽ
|
||
* @param bool $quoted <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>
|
||
* @return string
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
protected function String2DatetimeFormat($st, $quoted = true)
|
||
{
|
||
if ($quoted)
|
||
{
|
||
$st = $this->GetIdentifiers($st, true);
|
||
}
|
||
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
return "(STR_TO_DATE({$st}, '%Y-%m-%d %H:%i:%s'))";
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
return "(to_date({$st}, 'yyyy-mm-dd hh24:mi:ss'))";
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
return "(convert(datetime, {$st}, 120))";
|
||
break;
|
||
|
||
default:
|
||
return "";
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 2016-12-08<30><38><EFBFBD><EFBFBD>
|
||
* @note <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>͵ı<CDB5><C4B1>ʽ
|
||
* @param string $dt Ҫת<D2AA><D7AA><EFBFBD><EFBFBD><EFBFBD>ֶλ<D6B6><CEBB><EFBFBD>ʽ
|
||
* @param bool $quoted <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>
|
||
* @return string
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
protected function Datetime2StringFormat($dt, $quoted = true)
|
||
{
|
||
if ($quoted)
|
||
{
|
||
$dt = $this->GetIdentifiers($dt, true);
|
||
}
|
||
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
return "(DATE_FORMAT({$dt}, '%Y-%m-%d %H:%i:%s'))";
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
return "(to_char({$dt}, 'yyyy-mm-dd hh24:mi:ss'))";
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
return "(convert(varchar, {$dt}, 120))";
|
||
break;
|
||
|
||
default:
|
||
return "";
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 2016-12-08<30><38><EFBFBD><EFBFBD>
|
||
* @note ʱ<><CAB1><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>͵ı<CDB5><C4B1>ʽ
|
||
* @param string $ts Ҫת<D2AA><D7AA><EFBFBD><EFBFBD><EFBFBD>ֶλ<D6B6><CEBB><EFBFBD>ʽ
|
||
* @return string
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
protected function Timestamp2DatetimeFormat($ts)
|
||
{
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
return "(FROM_UNIXTIME({$ts}))";
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
return "(to_date('19700101', 'yyyymmdd') + {$ts} / 86400 + to_number(substr(tz_offset(sessiontimezone), 1, 3)) / 24)";
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
return "(dateadd(S, {$ts} + 8 * 3600, '1970-01-01 00:00:00'))";
|
||
break;
|
||
|
||
default:
|
||
return "";
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 2016-12-08<30><38><EFBFBD><EFBFBD>
|
||
* @note <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊʱ<CEAA><CAB1><EFBFBD><EFBFBD>͵ı<CDB5><C4B1>ʽ
|
||
* @param string $ds Ҫת<D2AA><D7AA><EFBFBD><EFBFBD><EFBFBD>ֶλ<D6B6><CEBB><EFBFBD>ʽ
|
||
* @param bool $quoted <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>
|
||
* @return string
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
protected function Datetime2TimestampFormat($ds, $quoted = true)
|
||
{
|
||
if ($quoted)
|
||
{
|
||
$ds = $this->GetIdentifiers($ds, true);
|
||
}
|
||
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
return "(UNIX_TIMESTAMP({$ds}))";
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
return "((to_date({$ds}, 'yyyy-mm-dd hh24:mi:ss') - to_date('19700101', 'yyyymmdd')) * 86400 - to_number(substr(tz_offset(sessiontimezone), 1, 3)) * 3600)";
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
return "(datediff(S, '1970-01-01 00:00:00', {$ds}) - 8 * 3600)";
|
||
break;
|
||
|
||
default:
|
||
return "";
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 2016-12-08<30><38><EFBFBD><EFBFBD>
|
||
* @note <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>͵ı<CDB5><C4B1>ʽ
|
||
* @param string $f Ҫת<D2AA><D7AA><EFBFBD><EFBFBD><EFBFBD>ֶλ<D6B6><CEBB><EFBFBD>ʽ
|
||
* @return string
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
protected function Float2StringFormat($f)
|
||
{
|
||
switch (DATABASE_TYPE)
|
||
{
|
||
case 'MYSQL':
|
||
return "(cast(convert({$f}, decimal(18, 2)) as char))";
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
return "(to_char({$f}, 'fm99999990.00'))";
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
return "(cast(convert(decimal(18, 2), {$f}) as char))";
|
||
break;
|
||
|
||
default:
|
||
return "";
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 2016-01-16<31><36><EFBFBD><EFBFBD>
|
||
* @note <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳʱ<CDB3><CAB1>(<28><><EFBFBD><EFBFBD>ʽ)
|
||
* @param bool $raw <20>Ƿ<C7B7><F1B7B5BB><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>ʽ
|
||
* @return string
|
||
* @note Ӧ<><D3A6>
|
||
*/
|
||
public function GetSystemTime($raw = false)
|
||
{
|
||
if ($raw) {
|
||
switch (DATABASE_TYPE) {
|
||
case 'MYSQL':
|
||
return 'now()';
|
||
break;
|
||
|
||
case 'ORACLE':
|
||
return 'sysdate';
|
||
break;
|
||
|
||
case 'SQLSRV':
|
||
return 'getdate()';
|
||
break;
|
||
|
||
default:
|
||
return '';
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
return date('Y-m-d H:i:s');
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @note <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֵ
|
||
* @param bool $always_local
|
||
* @return int
|
||
*/
|
||
public function GetErrorCode($always_local = false)
|
||
{
|
||
if ($always_local || null == $this->Database)
|
||
{
|
||
return $this->ErrorCode;
|
||
}
|
||
else
|
||
{
|
||
return $this->Database->GetErrorCode();
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||
* @param bool $always_local
|
||
* @return mixed|string
|
||
*/
|
||
public function GetErrorInfo($always_local = false)
|
||
{
|
||
if ($always_local || null == $this->Database)
|
||
{
|
||
return $this->ErrorInfo;
|
||
}
|
||
else
|
||
{
|
||
return $this->Database->GetErrorInfo();
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20>û<EFBFBD><C3BB><EFBFBD>Ȩ<EFBFBD><C8A8>Ϣת<CFA2>û<EFBFBD><C3BB>루<EFBFBD>û<EFBFBD>id<69><64>
|
||
* @param string $user_auth_token
|
||
* @return string
|
||
*/
|
||
protected function UserAuthTokenToUserCode($user_auth_token)
|
||
{
|
||
return $user_auth_token;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>µ<EFBFBD>id
|
||
* @param string $prefix
|
||
* @return string
|
||
*/
|
||
protected function CreateNewIdent($prefix = '', $md5 = false)
|
||
{
|
||
if (empty($prefix))
|
||
{
|
||
$prefix = 'NEW';
|
||
}
|
||
|
||
if ($md5)
|
||
{
|
||
return $prefix . md5(date('YmdHis') . rand(1000, 9999));
|
||
}
|
||
else
|
||
{
|
||
return $prefix . date('YmdHis') . rand(1000, 9999);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @note <20>ж<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>¼
|
||
* @param string $tablename
|
||
* @param string|array $wheres
|
||
* @return bool
|
||
* @auther Ӧ<><D3A6>
|
||
*/
|
||
// DataExists('ims_bigmarket_market', array('app_id' => 123, 'market_id' => 123));
|
||
protected function DataExists($tablename, $wheres)
|
||
{
|
||
$result = $this->PDO_Select($tablename, 'count(1) c', $wheres);
|
||
if (!$result)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
return 0 != $result[0]['c'];
|
||
}
|
||
}
|