Subscribe

disable the auto increment

  1. 2009-10-13 01:23:42 PDT
    Hi all, I have been having problems with the autincrement number - which is a nice feature for some situations. But I want to revert to the autonncrement of the data when you do an insert. Can this be done - I have had a hunt around but can't find anything yet? Ta Nick
  2. 2009-10-13 03:48:44 PDT
    Ahh, figured some of this out: define('P4A_AUTO_DB_SEQUENCES', false); however this caused problems on some pages - watch out for: I set my data sources to default with a setWhere to a zero result set as otherwise on large tables hit the performce too much. Becuase ot his - when you save teh row on a new item the page would go blank. So i had to do a: $this->source->setWhere("QuoteID = " . GetLastInsertID()) ->firstRow(); I think this is sencable - is this the type of thing I needed to do? Ta Nick
  3. 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
Jump To:
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.