- Patch #10945 by Adrian: more PostgreSQL fixes/updates.
parent
4fe5b52a21
commit
228b3c7cc8
|
@ -162,7 +162,7 @@ CREATE TABLE aggregator_item (
|
|||
|
||||
CREATE TABLE cache (
|
||||
cid varchar(255) NOT NULL default '',
|
||||
data bytea default '',
|
||||
data text default '',
|
||||
expire integer NOT NULL default '0',
|
||||
created integer NOT NULL default '0',
|
||||
headers text default '',
|
||||
|
@ -196,6 +196,20 @@ CREATE TABLE comments (
|
|||
);
|
||||
CREATE INDEX comments_nid_idx ON comments(nid);
|
||||
|
||||
--
|
||||
-- Table structre for table 'node_last_comment'
|
||||
--
|
||||
|
||||
CREATE TABLE node_comment_statistics (
|
||||
nid integer NOT NULL,
|
||||
cid integer NOT NULL default '0',
|
||||
last_comment_timestamp integer NOT NULL default '0',
|
||||
last_comment_name varchar(60) default NULL,
|
||||
last_comment_uid integer NOT NULL default '0',
|
||||
comment_count integer NOT NULL default '0',
|
||||
PRIMARY KEY (nid)
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for directory
|
||||
--
|
||||
|
@ -799,3 +813,15 @@ BEGIN
|
|||
RETURN $1 || $2;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE FUNCTION "if"(integer, text, text) RETURNS text AS '
|
||||
BEGIN
|
||||
IF $1 THEN
|
||||
RETURN $2;
|
||||
END IF;
|
||||
IF NOT $1 THEN
|
||||
RETURN $3;
|
||||
END IF;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
|
||||
|
|
|
@ -1077,10 +1077,19 @@ function update_85() {
|
|||
$ret[] = update_sql("ALTER TABLE {bundle} RENAME TO {aggregator_category}");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_category} DROP attributes");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_category} RENAME bid TO cid");
|
||||
$lastvalue = db_result(db_query('SELECT last_value from {bundle}_bid_seq'));
|
||||
$ret[] = update_sql("CREATE SEQUENCE {aggregator_category}_cid_seq START $lastvalue MINVALUE 0");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_category} ALTER cid SET DEFAULT nextval('public.{aggregator_category}_cid_seq'::text)");
|
||||
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_category} ADD description text");
|
||||
$ret[] = update_sql("UPDATE {aggregator_category} SET description = ''");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_category} ALTER COLUMN description SET NOT NULL");
|
||||
|
||||
$ret[] = update_sql("ALTER TABLE {feed} RENAME TO {aggregator_feed}");
|
||||
$lastvalue = db_result(db_query('SELECT last_value from {feed}_fid_seq'));
|
||||
$ret[] = update_sql("CREATE SEQUENCE {aggregator_feed}_fid_seq START $lastvalue MINVALUE 0");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_feed} ALTER fid SET DEFAULT nextval('public.{aggregator_feed}_fid_seq'::text)");
|
||||
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_feed} DROP attributes");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_feed} ADD block smallint");
|
||||
$ret[] = update_sql("UPDATE {aggregator_feed} SET block = 0");
|
||||
|
@ -1088,7 +1097,12 @@ function update_85() {
|
|||
$ret[] = update_sql("ALTER TABLE {aggregator_category} ADD block smallint");
|
||||
$ret[] = update_sql("UPDATE {aggregator_category} SET block = 0");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_category} ALTER COLUMN block SET NOT NULL");
|
||||
|
||||
$ret[] = update_sql("ALTER TABLE {item} RENAME TO {aggregator_item}");
|
||||
$lastvalue = db_result(db_query('SELECT last_value from {item}_iid_seq'));
|
||||
$ret[] = update_sql("CREATE SEQUENCE {aggregator_item}_iid_seq START $lastvalue MINVALUE 0");
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_item} ALTER iid SET DEFAULT nextval('public.{aggregator_item}_iid_seq'::text)");
|
||||
|
||||
$ret[] = update_sql("ALTER TABLE {aggregator_item} DROP attributes");
|
||||
$ret[] = update_sql("CREATE TABLE {aggregator_category_feed} (
|
||||
fid integer NOT NULL default '0',
|
||||
|
@ -1754,7 +1768,6 @@ function update_104() {
|
|||
}
|
||||
|
||||
function update_105() {
|
||||
// TODO: needs PGSQL equivalent
|
||||
$ret = array();
|
||||
|
||||
$shadowupdates = db_query("SELECT nid,tid FROM {forum} WHERE shadow=0");
|
||||
|
@ -1762,33 +1775,63 @@ function update_105() {
|
|||
db_query("DELETE FROM {term_node} WHERE nid = %d AND tid <> %d", $shadowrecord->nid, $shadowrecord->tid);
|
||||
}
|
||||
|
||||
$ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
|
||||
$ret[] = update_sql('ALTER TABLE {node} ADD INDEX node_status_type (status, type, nid)');
|
||||
if ($GLOBALS['db_type'] == 'mysql') {
|
||||
$ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
|
||||
$ret[] = update_sql('ALTER TABLE {node} ADD INDEX node_status_type (status, type, nid)');
|
||||
|
||||
$ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
|
||||
nid int(10) unsigned NOT NULL auto_increment,
|
||||
cid int(10) unsigned NOT NULL default '0',
|
||||
last_comment_timestamp int(11) NOT NULL default '0',
|
||||
last_comment_name varchar(60) default NULL,
|
||||
last_comment_uid int(10) NOT NULL default '0',
|
||||
comment_count int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (nid),
|
||||
KEY node_comment_timestamp (last_comment_timestamp)
|
||||
) TYPE=MyISAM");
|
||||
$ret[] = update_sql("INSERT INTO {node_comment_statistics} (nid, cid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, 0, n.created, NULL, n.uid, 0 FROM {node} n");
|
||||
$ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
|
||||
nid int(10) unsigned NOT NULL auto_increment,
|
||||
cid int(10) unsigned NOT NULL default '0',
|
||||
last_comment_timestamp int(11) NOT NULL default '0',
|
||||
last_comment_name varchar(60) default NULL,
|
||||
last_comment_uid int(10) NOT NULL default '0',
|
||||
comment_count int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (nid),
|
||||
KEY node_comment_timestamp (last_comment_timestamp)
|
||||
) TYPE=MyISAM");
|
||||
$ret[] = update_sql("INSERT INTO {node_comment_statistics} (nid, cid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, 0, n.created, NULL, n.uid, 0 FROM {node} n");
|
||||
|
||||
$ret[] = update_sql("CREATE TABLE {forum_conv_temp} (
|
||||
nid int(10) unsigned NOT NULL default '0',
|
||||
cid int(10) unsigned NOT NULL default '0',
|
||||
comment_count int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (nid)
|
||||
$ret[] = update_sql("CREATE TABLE {forum_conv_temp} (
|
||||
nid int(10) unsigned NOT NULL default '0',
|
||||
cid int(10) unsigned NOT NULL default '0',
|
||||
comment_count int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (nid)
|
||||
)");
|
||||
|
||||
$ret[] = update_sql('INSERT INTO {forum_conv_temp} SELECT f.nid, MAX(c.cid), COUNT(c.nid) FROM {forum} f INNER JOIN {comments} c ON f.nid = c.nid WHERE c.status = 0 GROUP BY f.nid');
|
||||
|
||||
/* This would be faster but only works with MySQL 4.0.4 or higher
|
||||
$ret[] = update_sql('UPDATE {node_comment_statistics} n, {forum_conv_temp} t, {comments} c SET n.comment_count = t.comment_count, n.last_comment_timestamp = c.timestamp, n.last_comment_name = c.name, n.last_comment_uid = c.uid, n.cid = t.cid WHERE t.cid = c.cid AND n.nid = t.nid');
|
||||
*/
|
||||
}
|
||||
else {
|
||||
// PostgreSQL is incapable of dropping columns in all but the latest versions.
|
||||
$ret[] = update_sql("CREATE INDEX {node}_status_type_idx ON {node} (status, type, nid)");
|
||||
|
||||
|
||||
$ret[] = update_sql("CREATE TABLE {node}_comment_statistics (
|
||||
nid integer NOT NULL,
|
||||
cid integer NOT NULL default '0',
|
||||
last_comment_timestamp integer NOT NULL default '0',
|
||||
last_comment_name varchar(60) default NULL,
|
||||
last_comment_uid integer NOT NULL default '0',
|
||||
comment_count integer NOT NULL default '0',
|
||||
PRIMARY KEY (nid)
|
||||
)");
|
||||
|
||||
$ret[] = update_sql('INSERT INTO {forum_conv_temp} SELECT f.nid, MAX(c.cid), COUNT(c.nid) FROM {forum} f INNER JOIN {comments} c ON f.nid = c.nid WHERE c.status = 0 GROUP BY f.nid');
|
||||
$ret[] = update_sql("SELECT f.nid, MAX(c.cid) as cid, COUNT(c.nid) as comment_count INTO TEMPORARY {forum_conv_temp} FROM {forum} f INNER JOIN {comments} c ON f.nid = c.nid WHERE c.status = 0 GROUP BY f.nid");
|
||||
|
||||
/* This would be faster but only works with MySQL 4.0.4 or higher
|
||||
$ret[] = update_sql('UPDATE {node_comment_statistics} n, {forum_conv_temp} t, {comments} c SET n.comment_count = t.comment_count, n.last_comment_timestamp = c.timestamp, n.last_comment_name = c.name, n.last_comment_uid = c.uid, n.cid = t.cid WHERE t.cid = c.cid AND n.nid = t.nid');
|
||||
*/
|
||||
$ret[] = update_sql("CREATE FUNCTION \"if\"(integer, text, text) RETURNS text AS '
|
||||
BEGIN
|
||||
IF $1 THEN
|
||||
RETURN $2;
|
||||
END IF;
|
||||
IF NOT $1 THEN
|
||||
RETURN $3;
|
||||
END IF;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql'");
|
||||
}
|
||||
|
||||
$commentupdates = db_query("SELECT t.nid, t.cid, t.comment_count, c.timestamp, c.name, c.uid FROM {forum_conv_temp} t INNER JOIN {comments} c ON t.cid = c.cid");
|
||||
while ($commentrecord = db_fetch_object($commentupdates)) {
|
||||
|
@ -1806,7 +1849,7 @@ function update_106() {
|
|||
$ret[] = update_sql('ALTER TABLE {cache} ADD INDEX expire (expire)');
|
||||
}
|
||||
else if ($GLOBALS['db_type'] == 'pgsql') {
|
||||
// TODO: needs PGSQL equivalent.
|
||||
$ret[] = update_sql('CREATE INDEX {cache}_expire_idx ON {cache}(expire)');
|
||||
}
|
||||
|
||||
$ret[] = update_sql('DELETE FROM {cache}');
|
||||
|
|
|
@ -118,7 +118,11 @@ function variable_del($name) {
|
|||
*/
|
||||
function cache_get($key) {
|
||||
$cache = db_fetch_object(db_query("SELECT data, created, headers FROM {cache} WHERE cid = '%s'", $key));
|
||||
return isset($cache->data) ? $cache : 0;
|
||||
if (isset($cache->data)) {
|
||||
$cache->data = db_decode_blob($cache->data);
|
||||
return $cache;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -271,7 +275,7 @@ function drupal_page_header() {
|
|||
header($header);
|
||||
}
|
||||
|
||||
print db_decode_blob($cache->data);
|
||||
print $cache->data;
|
||||
|
||||
// Call all init() and exit() hooks without including all modules.
|
||||
// Only use those hooks for critical operations.
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
function db_connect($url) {
|
||||
$url = parse_url($url);
|
||||
|
||||
$conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'];
|
||||
$conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];
|
||||
$conn_string .= ($url['port']) ? ' port=' . $url['port'] : '';
|
||||
$connection = pg_connect($conn_string) or die(pg_last_error());
|
||||
|
||||
return $connection;
|
||||
|
@ -263,7 +264,7 @@ function db_query_range($query) {
|
|||
* Encoded data.
|
||||
*/
|
||||
function db_encode_blob($data) {
|
||||
return pg_escape_bytea($data);
|
||||
return addcslashes($data, "\0..\37\\");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -693,7 +693,7 @@ function aggregator_get_category($cid) {
|
|||
}
|
||||
|
||||
function aggregator_view() {
|
||||
$result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image ORDER BY f.title');
|
||||
$result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image, f.block ORDER BY f.title');
|
||||
|
||||
$output .= '<h3>'. t('Feed overview') .'</h3>';
|
||||
|
||||
|
@ -704,7 +704,7 @@ function aggregator_view() {
|
|||
}
|
||||
$output .= theme('table', $header, $rows);
|
||||
|
||||
$result = db_query('SELECT c.cid, c.title, count(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid ORDER BY title');
|
||||
$result = db_query('SELECT c.cid, c.title, count(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
|
||||
|
||||
$output .= '<h3>'. t('Category overview') .'</h3>';
|
||||
|
||||
|
|
|
@ -693,7 +693,7 @@ function aggregator_get_category($cid) {
|
|||
}
|
||||
|
||||
function aggregator_view() {
|
||||
$result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image ORDER BY f.title');
|
||||
$result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image, f.block ORDER BY f.title');
|
||||
|
||||
$output .= '<h3>'. t('Feed overview') .'</h3>';
|
||||
|
||||
|
@ -704,7 +704,7 @@ function aggregator_view() {
|
|||
}
|
||||
$output .= theme('table', $header, $rows);
|
||||
|
||||
$result = db_query('SELECT c.cid, c.title, count(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid ORDER BY title');
|
||||
$result = db_query('SELECT c.cid, c.title, count(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
|
||||
|
||||
$output .= '<h3>'. t('Category overview') .'</h3>';
|
||||
|
||||
|
|
Loading…
Reference in New Issue