本文整理汇总了PHP中SQLSelect::toCps方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLSelect::toCps方法的具体用法?PHP SQLSelect::toCps怎么用?PHP SQLSelect::toCps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLSelect
的用法示例。
在下文中一共展示了SQLSelect::toCps方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cps4wp_query
function cps4wp_query($sql)
{
global $wpdb;
// echo $sql;
$logto = 'queries';
// The end of the query may be protected against changes
$end = '';
// Remove unusefull spaces
$initial = $sql = trim($sql);
if (0 === strpos($sql, 'SELECT')) {
// clutserpoint doesnot support @ in queries
if (false !== strpos($sql, "@")) {
return false;
}
$logto = 'SELECT';
$s = new SQLSelect($sql);
return $GLOBALS['cps4wp_result'] = $s->toCps();
} elseif (0 === strpos($sql, 'UPDATE')) {
$logto = 'UPDATE';
$s = new SQLUpdate($sql);
return $GLOBALS['cps4wp_result'] = $s->toCps();
} elseif (0 === strpos($sql, 'INSERT')) {
$logto = 'INSERT';
$s = new SQLInsert($sql);
return $GLOBALS['cps4wp_result'] = $s->toCps();
} elseif (0 === strpos($sql, 'DELETE')) {
$logto = 'DELETE';
$s = new SQLDelete($sql);
return $GLOBALS['cps4wp_result'] = $s->toCps();
} elseif (0 === strpos($sql, 'SHOW TABLES')) {
$logto = 'SHOWTABLES';
$o = new SQLAbstract();
return $o->execute('SELECT DISTINCT __table FROM ' . DB_NAME);
} elseif (0 === strpos($sql, 'OPTIMIZE TABLE')) {
$logto = 'OPTIMIZE';
$sql = str_replace('OPTIMIZE TABLE', 'VACUUM', $sql);
} elseif (0 === strpos($sql, 'SET NAMES') && false !== strpos($sql, 'COLLATE')) {
$logto = 'SETNAMES';
$sql = "SET NAMES 'utf8'";
$sql = false;
//cps don't need this now
}
// Load up upgrade and install functions as required
$begin = substr($sql, 0, 3);
$search = array('SHO', 'ALT', 'DES', 'CRE', 'DRO');
if (in_array($begin, $search)) {
require_once CPS4WP_ROOT . '/driver_pgsql_install.php';
$sql = cps4wp_installing($sql, $logto);
}
// WP 2.9.1 uses a comparison where text data is not quoted
$pattern = '/AND meta_value = (-?\\d+)/';
$sql = preg_replace($pattern, 'AND meta_value = \'$1\'', $sql);
// Generic "INTERVAL xx YEAR|MONTH|DAY|HOUR|MINUTE|SECOND" handler
$pattern = '/INTERVAL[ ]+(\\d+)[ ]+(YEAR|MONTH|DAY|HOUR|MINUTE|SECOND)/';
$sql = preg_replace($pattern, "'\$1 \$2'::interval", $sql);
$pattern = '/DATE_SUB[ ]*\\(([^,]+),([^\\)]+)\\)/';
$sql = preg_replace($pattern, '($1::timestamp - $2)', $sql);
// Remove illegal characters
$sql = str_replace('`', '', $sql);
// Field names with CAPITALS need special handling
if (false !== strpos($sql, 'ID')) {
$pattern = '/ID([^ ])/';
$sql = preg_replace($pattern, 'ID $1', $sql);
$pattern = '/ID$/';
$sql = preg_replace($pattern, 'ID ', $sql);
$pattern = '/\\(ID/';
$sql = preg_replace($pattern, '( ID', $sql);
$pattern = '/,ID/';
$sql = preg_replace($pattern, ', ID', $sql);
$pattern = '/[0-9a-zA-Z_]+ID/';
$sql = preg_replace($pattern, '"$0"', $sql);
$pattern = '/\\.ID/';
$sql = preg_replace($pattern, '."ID"', $sql);
$pattern = '/[\\s]ID /';
$sql = preg_replace($pattern, ' "ID" ', $sql);
$pattern = '/"ID "/';
$sql = preg_replace($pattern, ' "ID" ', $sql);
}
// CAPITALS
// Empty "IN" statements are erroneous
$sql = str_replace('IN (\'\')', 'IN (NULL)', $sql);
$sql = str_replace('IN ( \'\' )', 'IN (NULL)', $sql);
$sql = str_replace('IN ()', 'IN (NULL)', $sql);
// Put back the end of the query if it was separated
$sql .= $end;
// For insert ID catching
if ($logto == 'INSERT') {
$pattern = '/INSERT INTO (\\w+)\\s+\\([ a-zA-Z_"]+/';
preg_match($pattern, $sql, $matches);
$GLOBALS['cps4wp_ins_table'] = $matches[1];
$match_list = split(' ', $matches[0]);
if ($GLOBALS['cps4wp_ins_table']) {
$GLOBALS['cps4wp_ins_field'] = trim($match_list[3], ' () ');
if (!$GLOBALS['cps4wp_ins_field']) {
$GLOBALS['cps4wp_ins_field'] = trim($match_list[4], ' () ');
}
}
$GLOBALS['cps4wp_last_insert'] = $sql;
} elseif (isset($GLOBALS['cps4wp_queued_query'])) {
pg_query($GLOBALS['cps4wp_queued_query']);
//.........这里部分代码省略.........