2009-10-15 07:59:36 PDT
Thanks for your post! I'll have to look into that setting.
For more info on the sequence table, see:
http://sourceforge.net/projects/p4a/forums/forum/340765/topic/2120817
http://sourceforge.net/forum/forum.php?thread_id=1724958&forum_id=340765
I have a method I use in my masks (actually a subclass of P4A_Mask that I use to build my masks) for resequencing a sequence table. You might find the code helpful. $this->WriteContent($html) is a method for displaying the results.
function ResetSequence($table,$autoincField){
//| Description
//| This is an attempted solution to the autoincrement problem.
//| See
http://sourceforge.net/forum/forum.php?thread_id=1724958&forum_id=340765
$db =& p4a_db::singleton();
$html = "";
//|| generate the content
$html .= "<h3>Reset <i>$table</i> Sequence <i>$autoincField</i></h3>\n";
// get the initial sequence value
$result = $db->queryAll(
"SELECT id FROM {$table}_{$autoincField}_seq
;");
$initialSequence = $result[0]["id"];
$html .= "Initial sequence value: $initialSequence<br>\n";
// get the maximum key value in the table
$result = $db->queryAll(
"SELECT MAX($autoincField) as maxKey FROM $table
;");
$maximumKeyValue = $result[0]["maxKey"];
$html .= "Maximum key value: $maximumKeyValue<br>\n";
// update the table
$sql = "
UPDATE {$table}_{$autoincField}_seq
SET id=(
SELECT MAX($autoincField) FROM $table
);
";
$db->query($sql);
// get the final sequence value (so we can be sure)
$result = $db->queryAll(
"SELECT id FROM {$table}_{$autoincField}_seq
;");
$finalSequence = $result[0]["id"];
$html .= "Final sequence value: $finalSequence<br>\n";
// test and display warning if not set properly
if ($maximumKeyValue<>$finalSequence){
$html .= "<b>ERROR: Values do not match!</b><br>\n";
}
//|| replace the content area
$this->WriteContent($html);
}//| End ResetSequence