[geeklog-hg] geeklog: Added a primary key to the spamx table only on fresh in...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Feb 3 01:00:16 EST 2014
changeset 9474:75c4bd3d6887
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/75c4bd3d6887
user: Kenji ITO <mystralkk at gmail.com>
date: Mon Feb 03 14:58:04 2014 +0900
description:
Added a primary key to the spamx table only on fresh installs
diffstat:
plugins/spamx/BaseAdmin.class.php | 14 ++++++++++++--
plugins/spamx/sql/mssql_install.php | 4 ++++
plugins/spamx/sql/mysql_install.php | 3 ++-
plugins/spamx/sql/pgsql_install.php | 3 ++-
4 files changed, 20 insertions(+), 4 deletions(-)
diffs (64 lines):
diff -r d91ba3ba95dd -r 75c4bd3d6887 plugins/spamx/BaseAdmin.class.php
--- a/plugins/spamx/BaseAdmin.class.php Mon Feb 03 10:00:06 2014 +0900
+++ b/plugins/spamx/BaseAdmin.class.php Mon Feb 03 14:58:04 2014 +0900
@@ -123,8 +123,18 @@
if (!empty($entry)) {
$entry = str_replace(' ', '', $entry);
$entry = DB_escapeString($entry);
- $timestamp = DB_escapeString(date('Y-m-d H:i:s'));
- $retval = DB_query("INSERT INTO {$_TABLES['spamx']} VALUES ('{$this->moduleName}', '{$entry}', 0, '$timestamp')");
+ $count = DB_getItem(
+ $_TABLES['spamx'],
+ "COUNT(*)",
+ "name ='" . DB_escapeString($this->moduleName)
+ . "' AND value = '" . $entry . "'"
+ );
+
+ // Lets the user add a unique record only
+ if ($count == 0) {
+ $timestamp = DB_escapeString(date('Y-m-d H:i:s'));
+ $retval = DB_query("INSERT INTO {$_TABLES['spamx']} VALUES ('{$this->moduleName}', '{$entry}', 0, '$timestamp')");
+ }
}
return $retval;
diff -r d91ba3ba95dd -r 75c4bd3d6887 plugins/spamx/sql/mssql_install.php
--- a/plugins/spamx/sql/mssql_install.php Mon Feb 03 10:00:06 2014 +0900
+++ b/plugins/spamx/sql/mssql_install.php Mon Feb 03 14:58:04 2014 +0900
@@ -40,6 +40,10 @@
) ON [PRIMARY]
";
+$_SQL[] = "
+ALTER TABLE [dbo].[{$_TABLES['spamx']}]
+ADD CONSTRAINT [PK_spamx] PRIMARY KEY CLUSTERED ([name], [value]) ON [PRIMARY]";
+
$DEFVALUES[] = "INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('spamx.counter', '0')";
?>
diff -r d91ba3ba95dd -r 75c4bd3d6887 plugins/spamx/sql/mysql_install.php
--- a/plugins/spamx/sql/mysql_install.php Mon Feb 03 10:00:06 2014 +0900
+++ b/plugins/spamx/sql/mysql_install.php Mon Feb 03 14:58:04 2014 +0900
@@ -36,7 +36,8 @@
value varchar(255) NOT NULL default '',
counter int(11) NOT NULL default '0',
regdate datetime NOT NULL default '0000-00-00 00:00:00',
- INDEX spamx_name(name)
+ INDEX spamx_name(name),
+ PRIMARY KEY (name, value)
) ENGINE=MyISAM
";
diff -r d91ba3ba95dd -r 75c4bd3d6887 plugins/spamx/sql/pgsql_install.php
--- a/plugins/spamx/sql/pgsql_install.php Mon Feb 03 10:00:06 2014 +0900
+++ b/plugins/spamx/sql/pgsql_install.php Mon Feb 03 14:58:04 2014 +0900
@@ -35,7 +35,8 @@
name varchar(20) NOT NULL default '',
value varchar(255) NOT NULL default '',
counter int NOT NULL default 0,
- regdate timestamp NOT NULL default NULL
+ regdate timestamp NOT NULL default NULL,
+ PRIMARY KEY (name, value)
);
CREATE INDEX {$_TABLES['spamx']}_name ON {$_TABLES['spamx']}(name);
";
More information about the geeklog-cvs
mailing list