From fbcccbd286fc73dd3571ca0b22d54e0615b600fb Mon Sep 17 00:00:00 2001 From: wainstead Date: Tue, 20 Jun 2000 04:50:57 +0000 Subject: [PATCH] InsertPage() and RetrievePage() now work mostly. I noticed during testing that I cannot create new pages, which looks like a small bug somewhere. But I was able to repeatedly: drop all tables, reload them with the schema file, and then load a new Wiki via wiki_setup.php3. It worked nicely. The solution was in hard-coding the data structure in the pg functions. It should still be maintainable. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@78 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- wiki_pgsql.php3 | 68 ++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/wiki_pgsql.php3 b/wiki_pgsql.php3 index 71c7bb038..c1a7f5145 100644 --- a/wiki_pgsql.php3 +++ b/wiki_pgsql.php3 @@ -1,4 +1,4 @@ - + dbi after open: '$dbi' '$dbi[table]' '$dbi[dbc]'

\n"; +// echo "

dbi after open: '$dbi' '$dbi[table]' '$dbi[dbc]'

\n"; return $dbi; } @@ -58,10 +58,10 @@ $pagehash[$key] = $val; } - // don't forget to unserialize the references - if ($pagehash['refs']) { - $pagehash['refs'] = unserialize($pagehash['refs']); - } + // unserialize/explode content + $pagehash['refs'] = unserialize($pagehash['refs']); + $pagehash['content'] = explode("\n", $pagehash['content']); + return $pagehash; } } @@ -74,40 +74,52 @@ // Either insert or replace a key/value (a page) function InsertPage($dbi, $pagename, $pagehash) { $pagename = addslashes($pagename); - echo "

dbi in InsertPage: '$dbi' '$dbi[table]' '$dbi[dbc]'

"; - reset($pagehash); +// echo "

dbi in InsertPage: '$dbi' '$dbi[table]' '$dbi[dbc]'

"; + + // prepare the content for storage + $pagehash["author"] = addslashes($pagehash["author"]); + $pagehash["content"] = implode("\n", $pagehash["content"]); + $pagehash["content"] = addslashes($pagehash["content"]); + $pagehash["pagename"] = addslashes($pagehash["pagename"]); + $pagehash["refs"] = serialize($pagehash["refs"]); + + // temporary hack until the time stuff is brought up to date + $pagehash["created"] = time(); + $pagehash["lastmodified"] = time(); if (IsWikiPage($dbi, $pagename)) { - // do an update - list($key, $val) = each($pagehash); - $PAIRS = "$key='" . addslashes($val) . "'"; - while (list($key, $val) = each($pagehash)) { - $PAIRS .= ",$key='" . addslashes($val) . "'"; - } + + $PAIRS = "author='$pagehash[author]'," . + "content='$pagehash[content]'," . + "created=$pagehash[created]," . + "flags=$pagehash[flags]," . + "lastmodified=$pagehash[lastmodified]," . + "pagename='$pagehash[pagename]'," . + "refs='$pagehash[refs]'," . + "version=$pagehash[version]"; $query = "UPDATE $dbi[table] SET $PAIRS WHERE pagename='$pagename'"; } else { // do an insert // build up the column names and values for the query - list($key, $val) = each($pagehash); - $COLUMNS = "$key"; - $VALUES = "'" . addslashes($val) . "'"; - while (list($key, $val) = each($pagehash)) { - $COLUMNS .= ",$key"; - $VALUES .= ",'" . addslashes($val) . "'"; - } + $COLUMNS = "author, content, created, flags, " . + "lastmodified, pagename, refs, version"; + + $VALUES = "'$pagehash[author]', '$pagehash[content]', " . + "$pagehash[created], $pagehash[flags], " . + "$pagehash[lastmodified], '$pagehash[pagename]', " . + "'$pagehash[refs]', $pagehash[version]"; + $query = "INSERT INTO $dbi[table] ($COLUMNS) VALUES($VALUES)"; } - echo "

Query: $query

\n"; - -// if (!mysql_query("replace into $dbi[table] (page, hash) values ('$pagename', '$pagedata')", $dbi['dbc'])) { -// echo "error writing value"; -// exit(); -// } +// echo "

Query: $query

\n"; + $retval = pg_exec($dbi['dbc'], $query); + if ($retval == false) + echo "Insert/update failed: " . pg_errormessage($dbi['dbc']); } @@ -116,9 +128,7 @@ function IsWikiPage($dbi, $pagename) { $pagename = addslashes($pagename); $query = "select count(*) from $dbi[table] where pagename='$pagename'"; - echo "

IsWikiPage query: $query

\n"; $res = pg_exec($query); - //return(pg_numrows($res)); $array = pg_fetch_array($res, 0); return $array[0]; } -- 2.45.0