From 042e6134c143e78bc044f7506329c600cb892f62 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 23 Jan 2008 03:55:06 +0100 Subject: [PATCH] OJD db: tree_node_archive.tree_pos references back tree_node.id --- php/ojd_commit.php | 6 +++++- php/ojd_structure.sql | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/php/ojd_commit.php b/php/ojd_commit.php index 8df75db..42969c3 100644 --- a/php/ojd_commit.php +++ b/php/ojd_commit.php @@ -18,6 +18,7 @@ if ($id == 1) { # SGF-ish string, but with no variations and meant for single tree node. Get array of SGF nodes. +# TODO: Perform basic filtering; esp. disallow changes of B[] and W[] during updates! function parse_simple_sgf($str) { $sgf = new SGF("(;".$str.")"); @@ -34,7 +35,7 @@ $sgf_nodes = parse_simple_sgf($_REQUEST['sgf']); mysql_query('START TRANSACTION'); -if (!mysql_query("INSERT INTO tree_node_archive SET author = '".$_SERVER['REMOTE_ADDR']."'")) { +if (!mysql_query("INSERT INTO tree_node_archive SET tree_pos = '".($id?$id:1)."', author = '".$_SERVER['REMOTE_ADDR']."'")) { die("Problem! " . mysql_error()); } $version = mysql_insert_id(); @@ -67,6 +68,9 @@ if ($id) { die("Problem! " . mysql_error()); } $id = mysql_insert_id(); + if (!mysql_query("UPDATE tree_node_archive SET tree_pos = $id WHERE id = $version")) { + die("Problem! " . mysql_error()); + } } mysql_query('COMMIT'); diff --git a/php/ojd_structure.sql b/php/ojd_structure.sql index 3b6a6ba..ddde591 100644 --- a/php/ojd_structure.sql +++ b/php/ojd_structure.sql @@ -11,6 +11,8 @@ DROP TABLE tree_node_archive; CREATE TABLE tree_node_archive ( id INT AUTO_INCREMENT PRIMARY KEY, + tree_pos INT NOT NULL, + FOREIGN KEY (tree_pos) REFERENCES tree_node (id), # Also IPv6 addresses and other junk! author VARCHAR(128) -- 2.11.4.GIT