From: Simon H. <sim...@us...> - 2010-09-29 17:02:54
|
Update of /cvsroot/stack/stack-dev/install/update/updates In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv16297/install/update/updates Modified Files: Tag: STACK2_2 TwoPointTwo.php Log Message: Fix for question_line table population. Index: TwoPointTwo.php =================================================================== RCS file: /cvsroot/stack/stack-dev/install/update/updates/Attic/TwoPointTwo.php,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** TwoPointTwo.php 29 Sep 2010 16:37:48 -0000 1.1.2.2 --- TwoPointTwo.php 29 Sep 2010 17:02:46 -0000 1.1.2.3 *************** *** 64,69 **** $conn = new StackDBADOdb(); $conn->connect(); - // hoping this is a platform-agnostic way to modify tables - more knowlegable opinions welcome! - //$conn->query('ALTER TABLE stackquestion ADD COLUMN line I(11) UNSIGNED'); // CANNOT DO THIS! $sqlarray = $dict->AddColumnSQL('stackquestion', 'line I(11) UNSIGNED'); if(!$dict->ExecuteSQLArray($sqlarray)) --- 64,67 ---- *************** *** 74,85 **** // Create new line for each question, i.e. create row in question_lines and set line with that id. $conn->query('SELECT questionID FROM stackquestion'); - for($i = 0; $i < $conn->noRows(); $i++) { //insert line for each question ! $id = $conn->result($i, 'questionID'); ! $conn->query("INSERT INTO question_lines(latestVersion) VALUES($id)"); // shortcut: we know sequence of insert ids will be 1,2,3,... i.e. $i // set line id in each question ! $conn->query("UPDATE stackquestion SET line=$i WHERE questionID=$id"); } --- 72,87 ---- // Create new line for each question, i.e. create row in question_lines and set line with that id. $conn->query('SELECT questionID FROM stackquestion'); + // new queries seem to lose prior result so temporarily saving them + for($i = 0; $i < $conn->noRows(); $i++) { + $qid[] = $conn->result($i, 'questionID'); + } + + for($i = 0; $i < count($qid); $i++) { //insert line for each question ! $conn->query("INSERT INTO question_lines(latestVersion) VALUES(".$qid[$i].")"); // shortcut: we know sequence of insert ids will be 1,2,3,... i.e. $i // set line id in each question ! $conn->query("UPDATE stackquestion SET line=$i WHERE questionID=".$qid[$i]); } |