Ahora se hace un MAX que implica comparación entre todos los registros, para
obtener el nuevo ID, lo más lógico sería utilizar autoincrement para el id,
y para que la instancia que se está guardando se quede con ese id asignado, se
debería devolver el valor del auto increment.
Esto es en DAL:
public function generateNewId ( $tableName )
{
$q = "SELECT MAX(id) AS max FROM ". $tableName;
$this->db->query( $q );
$row = $this->db->nextRow();
return ($row['max']+1);
}
El problema es que cada DBMS lo hace de forma distinta. Aquí hay algunos
recursos para analizar el problema:
http://pointbeing.net/weblog/2008/03/mysql-versus-postgresql-adding-an-auto-incr
ement-column-to-a-table.html
http://archives.postgresql.org/pgsql-novice/2011-12/msg00114.php
http://stackoverflow.com/questions/787722/postgresql-autoincrement
http://stackoverflow.com/questions/933565/get-auto-increment-value-with-mysql-qu
ery
http://forums.digitalpoint.com/showthread.php?t=159226
http://php.net/manual/en/function.mysql-insert-id.php
Original issue reported on code.google.com by pablo.swp@gmail.com on 13 Apr 2012 at 4:07
Original issue reported on code.google.com by
pablo.swp@gmail.com
on 13 Apr 2012 at 4:07