}
}
+ /**synchronize all sequences with current data*/
+ public function syncSequences()
+ {
+ global $dbScheme;
+ foreach($dbScheme->tableNames() as $table)
+ if($dbScheme->hasSequence($table)!==false)
+ $this->syncSequence($table);
+ }
+
+ /**synchronize the sequence of one database table; overwrite to actually do something*/
+ public function syncSequence($table){}
+
/**helper: inserts data from backup*/
private function backupInsert($table,$data,$overwrite)
{
/*currently ignored, maybe we do something with it later*/
break;
case "endofbackup":
+ $this->syncSequences();
print("Reached End of Backup.<br>\n");
break 2;
case "table":
private $dbhdl=false;
private $charset="UTF8";
private $intrans=false;
- //used for table creation to work around mysql bugs
- private $tableappend;
+ private $do_debug=false;
/**initialize driver*/
public function __construct($connstring)
else return false;
}
+ /**synchronize the sequence of one database table*/
+ public function syncSequence($table)
+ {
+ $tab=$this->tableName($table);
+ global $dbScheme;
+ $col=$dbScheme->hasSequence($table);
+ if($col===false)return;
+ $seq=$tab."_".$col."_seq";
+ $q="select setval('".$seq."',(select max(".$col.") from ".$tab."))";
+// print($q."<br/>\n");
+ $res=@pg_query($this->dbhdl,$q);
+ if($res===false){
+ $this->db_debug_error("sequence sync");
+ return false;
+ }
+ pg_free_result($res);
+ return true;
+ }
+
+ /**development helper: activate debug mode*/
+ public function setDebugMode($b=true)
+ {
+ $this->do_debug=$b;
+ }
+
/**internal helper: print debug message as XML comment, if activated*/
private function db_debug_error($what)
{
//change this to if(1) if you want debug messages
- if(0)
+ if($this->do_debug)
print("<!-- Error while doing '".$what."' on DB: ".xq($this->lastError())." -->\n");
}
};