Fix: Pour rendre la fonction last_insert_id compatible enre mysql et pgsql, on rend le paramtre obligatoire.

This commit is contained in:
Laurent Destailleur
2005-03-18 23:56:41 +00:00
parent 1aa43a8dbc
commit 01c84cbb2e
52 changed files with 78 additions and 105 deletions

View File

@@ -97,7 +97,7 @@ class ActionComm
if ($this->db->query($sql) )
{
$idaction = $this->db->last_insert_id();
$idaction = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm");
if ($conf->webcal->enabled) {
if (is_object($webcal))

View File

@@ -301,7 +301,7 @@ class Adherent
if ($result)
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
return $this->update();
}
else

View File

@@ -20,14 +20,14 @@
*
*/
/*! \file htdocs/adherents/adherent_type.class.php
/** \file htdocs/adherents/adherent_type.class.php
\ingroup adherent
\brief Fichier de la classe g<>rant les types d'adh<64>rents
\author Rodolphe Quiedeville
\version $Revision$
*/
/*! \class AdherentType
/** \class AdherentType
\brief Classe g<>rant les types d'adh<64>rents
*/
@@ -43,7 +43,7 @@ class AdherentType
var $commentaire; /**< commentaire */
var $vote; /** droit de vote ? */
/*!
/**
\brief AdherentType
\param DB handler acc<63>s base de donn<6E>es
*/
@@ -54,7 +54,7 @@ class AdherentType
$this->statut = 1;
}
/*!
/**
\brief print_error_list
*/
@@ -67,7 +67,7 @@ class AdherentType
}
}
/*!
/**
\brief fonction qui permet de cr<63>er le status de l'adh<64>rent
\param userid userid de l'adh<64>rent
*/
@@ -85,13 +85,11 @@ class AdherentType
if ($result)
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
return $this->update();
}
else
{
print $this->db->error();
print "<h2><br>$sql<br></h2>";
return 0;
}
}
@@ -123,7 +121,7 @@ class AdherentType
}
}
/*!
/**
\brief fonction qui permet de supprimer le status de l'adh<64>rent
\param rowid
*/
@@ -151,7 +149,7 @@ class AdherentType
}
}
/*!
/**
\brief fonction qui permet de r<>cup<75>rer le status de l'adh<64>rent
\param rowid
*/

View File

@@ -192,7 +192,7 @@ class Cotisation
if ($result)
{
return $this->db->last_insert_id();
return $this->db->last_insert_id(MAIN_DB_PREFIX."don");
}
else
{

View File

@@ -156,7 +156,7 @@ class BonPrelevement
if ($this->db->query($sql))
{
$ligne_id = $this->db->last_insert_id();
$ligne_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_lignes");
$result = 0;
}
else

View File

@@ -132,7 +132,7 @@ class Bookmark4u
{
if ($this->db->affected_rows())
{
$this->uid = $this->db->last_insert_id();
$this->uid = $this->db->last_insert_id("bookmark4u.bk4u_passwd");
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark4u_login";
$sql .= " (fk_user, bk4u_uid)";

View File

@@ -53,7 +53,7 @@ class Auteur {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."auteur");
if ( $this->update($id, $user) )
{

View File

@@ -41,7 +41,7 @@ class Editeur {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."editeur");
if ( $this->update($id, $user) )
{

View File

@@ -57,7 +57,7 @@ class Livre {
if ($this->db->query($sql) )
{
$idosc = $this->db->last_insert_id();
$idosc = $this->db->last_insert_id(DB_NAME_OSC.".products");
$sql = "INSERT INTO ".DB_NAME_OSC.".products_to_categories (products_id, categories_id) VALUES ($idosc, 0)";
@@ -73,7 +73,7 @@ class Livre {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."livre");
if ( $this->update($id, $user) )
{

View File

@@ -52,7 +52,7 @@ class Newsletter {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."newsletter");
if ( $this->update($id, $user) )
{

View File

@@ -41,7 +41,7 @@ class Editeur {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."editeur");
if ( $this->update($id, $user) )
{

View File

@@ -79,13 +79,13 @@ class PaiementCharge {
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
}
else
{
$sql_err++;
print "Error: $sql : ".$this->db->error();
dolibarr_syslog("chargessociales::create Echec $sql");
}
}

View File

@@ -107,7 +107,7 @@ class Mailing
$result=$this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id($result);
$this->id = $this->db->last_insert_id($this->db_table);
if ($this->update() > 0)
{

View File

@@ -224,7 +224,7 @@ class Commande
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande");
/*
* Insertion des produits dans la base

View File

@@ -88,15 +88,13 @@ class Account
if ($this->db->query($sql))
{
$rowid = $this->db->last_insert_id();
$rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url");
return $rowid;
}
else
{
return '';
print $this->db->error();
print "<br>$sql";
}
}
/*
@@ -165,7 +163,7 @@ class Account
if ($this->db->query($sql))
{
$rowid = $this->db->last_insert_id();
$rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank");
if ($categorie)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES ('$rowid', '$categorie')";
@@ -214,7 +212,7 @@ class Account
{
if ($this->db->affected_rows())
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
if ( $this->update() )
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, label, amount, fk_account,datev,dateo,fk_type,rappro) ";

View File

@@ -78,7 +78,7 @@ class ComptaCompte
$result = $this->db->query($sql);
if ( $result )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."compta_compte_generaux");
if ($id > 0)
{

View File

@@ -47,7 +47,7 @@ class Deplacement
$result = $this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement");
if ( $this->update($user) )
{
return $this->id;

View File

@@ -110,7 +110,7 @@ class ComptaExportPoivre
if ($this->db->query($sql))
{
$ecid = $this->db->last_insert_id();
$ecid = $this->db->last_insert_id(MAIN_DB_PREFIX."export_compta");
}
else
{
@@ -124,7 +124,7 @@ class ComptaExportPoivre
{
dolibarr_syslog("ComptaExportPoivre::Export ref : $ref");
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."export_compta");
$fxname = DOL_DATA_ROOT."/compta/export/".$ref.".xls";

View File

@@ -90,7 +90,7 @@ class FactureRec
$sql .= " VALUES ('$this->titre', '$facsrc->socidp', now(), '$facsrc->amount', '$facsrc->remise', '$facsrc->remise_percent', '$this->note','$user->id', '$facsrc->projetid', '$facsrc->cond_reglement_id')";
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
/*
* Produits

View File

@@ -33,7 +33,7 @@ if ($action == 'add') {
$result = $db->query($sql);
if ($result) {
$rowid = $db->last_insert_id();
$rowid = $db->last_insert_id(MAIN_DB_PREFIX."voyage");
} else {
print $db->error();

View File

@@ -32,7 +32,7 @@ if ($action == 'add') {
$result = $db->query($sql);
if ($result) {
$rowid = $db->last_insert_id();
$rowid = $db->last_insert_id(MAIN_DB_PREFIX."voyage");
} else {
print $db->error();

View File

@@ -77,7 +77,7 @@ class Contact
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
$this->update($id, $user);

View File

@@ -213,7 +213,7 @@ class Contrat
$sql .= ",".$this->db->idate($this->date_contrat) .")";
if ($this->db->query($sql))
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat");
$result = 0 ;
}
else

View File

@@ -24,32 +24,6 @@ require("./pre.inc.php");
llxHeader();
if ($action == 'add') {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."voyage (date_depart, date_arrivee, amount, depart, arrivee, fk_reduc, reduction) ";
$sql .= " VALUES ('$date_depart','$date_arrivee',$amount,'$depart','$arrivee',$reducid, $reduc);";
$result = $db->query($sql);
if ($result) {
$rowid = $db->last_insert_id();
} else {
print $db->error();
print "<p>$sql";
}
}
if ($action == 'del') {
/* $sql = "DELETE FROM ".MAIN_DB_PREFIX."voyage WHERE rowid = $rowid";
*$result = $db->query($sql);
*/
}
if ($vline) {
$viewline = $vline;
} else {
$viewline = 20;
}
print_titre("Noms de domaines internet");

View File

@@ -196,7 +196,7 @@ class Don
if ($result)
{
return $this->db->last_insert_id();
return $this->db->last_insert_id(MAIN_DB_PREFIX."don");
}
else
{

View File

@@ -78,7 +78,7 @@ class Expedition
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition");
/*
*

View File

@@ -52,7 +52,6 @@ class Facture
var $total;
var $note;
var $paye;
var $db_table;
var $propalid;
var $projetid;
var $prefixe_facture;
@@ -68,7 +67,7 @@ class Facture
$this->db = $DB ;
$this->socidp = $soc_idp;
$this->products = array(); // Tableau de lignes de factures
$this->db_table = MAIN_DB_PREFIX."facture";
$this->amount = 0;
$this->remise = 0;
$this->remise_percent = 0;
@@ -172,7 +171,7 @@ class Facture
$tva = tva($totalht);
$total = $totalht + $tva;
$sql = "INSERT INTO $this->db_table (facnumber, fk_soc, datec, amount, remise, remise_percent";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture (facnumber, fk_soc, datec, amount, remise, remise_percent";
$sql .= ", datef, note, fk_user_author,fk_projet";
$sql .= ", fk_cond_reglement, fk_mode_reglement, date_lim_reglement) ";
@@ -182,7 +181,7 @@ class Facture
$sql .= ",".$this->cond_reglement.",".$this->mode_reglement.",".$this->db->idate($datelim).")";
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture");
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET facnumber='(PROV".$this->id.")' WHERE rowid=".$this->id;
$this->db->query($sql);

View File

@@ -110,7 +110,7 @@ class FactureFourn
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
@@ -119,7 +119,7 @@ class FactureFourn
$sql .= " VALUES ($this->id);";
if ($this->db->query($sql) )
{
$idligne = $this->db->last_insert_id();
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn_det");
$this->updateline($idligne,
$this->lignes[$i][0],
@@ -301,7 +301,7 @@ class FactureFourn
$sql .= " VALUES ($this->id);";
if ($this->db->query($sql) )
{
$idligne = $this->db->last_insert_id();
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn_det");
$this->updateline($idligne, $desc, $pu, $tauxtva, $qty);
}

View File

@@ -85,7 +85,7 @@ class Fichinter
$result=$this->db->query($sql);
if ($result)
{
return $this->db->last_insert_id();
return $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
}
else
{

View File

@@ -71,9 +71,9 @@ class PaiementFourn
$result = $this->db->query($sql);
if (isset($result))
if ($result)
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementfourn");
$label = "R<EFBFBD>glement facture $this->facnumber - $this->societe";
@@ -89,7 +89,7 @@ class PaiementFourn
// Mise a jour fk_bank dans llx_paiement_fourn
if ($result)
{
$this->bankid = $this->db->last_insert_id();
$this->bankid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank");
$sql = "UPDATE ".MAIN_DB_PREFIX."paiementfourn SET fk_bank=$this->bankid WHERE rowid=$this->id";
$result = $this->db->query($sql);

View File

@@ -266,7 +266,7 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
if ($this->db->query($sql))

View File

@@ -485,11 +485,12 @@ class DoliDb
}
/**
\brief Obtient l'id gen<65>r<EFBFBD> par le dernier INSERT.
\return id
\brief R<EFBFBD>cup<EFBFBD>re l'id gen<65>r<EFBFBD> par le dernier INSERT.
\param tab Nom de la table concern<72>e par l'insert. Ne sert pas sous MySql mais requis pour compatibilit<69> avec Postgresql
\return int id
*/
function last_insert_id()
function last_insert_id($tab)
{
return mysql_insert_id($this->db);
}

View File

@@ -492,8 +492,9 @@ class DoliDb
}
/**
\brief Obtient l'id gen<65>r<EFBFBD> par le dernier INSERT.
\return id
\brief R<EFBFBD>cup<EFBFBD>re l'id gen<65>r<EFBFBD> par le dernier INSERT.
\param tab Nom de la table concern<72>e par l'insert
\return int id
*/
function last_insert_id($tab)

View File

@@ -155,7 +155,7 @@ class Paiement
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiement");
foreach ($this->amounts as $key => $value)
{

View File

@@ -53,7 +53,7 @@ class Album {
if ($this->db->query($sql) )
{
$idosc = $this->db->last_insert_id();
$idosc = $this->db->last_insert_id(DB_NAME_OSC.".products");
$sql = "INSERT INTO ".DB_NAME_OSC.".products_to_categories (products_id, categories_id) VALUES ($idosc, 0)";
@@ -69,7 +69,7 @@ class Album {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."album");
if ( $this->update($id, $user) )
{

View File

@@ -47,7 +47,7 @@ class Categorie {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."album");
if ( $this->update($id, $user) )
{

View File

@@ -45,7 +45,7 @@ class Concert {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."concert");
if ( $this->update($id, $user) )
{

View File

@@ -45,7 +45,7 @@ class LieuConcert {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."lieu_concert");
if ( $this->update($id, $user) )
{

View File

@@ -46,7 +46,7 @@ class Groupart {
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."groupart");
if ( $this->update($id, $user) )
{

View File

@@ -65,7 +65,7 @@ class Promotion {
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(DB_NAME_OSC.".specials");
return $id;
}

View File

@@ -73,7 +73,7 @@ class Entrepot
if ($this->db->query($sql) )
{
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot");
if ($id > 0)
{
$this->id = $id;

View File

@@ -57,7 +57,7 @@ class Project {
if ($this->db->query($sql) )
{
return $this->db->last_insert_id();
return $this->db->last_insert_id(MAIN_DB_PREFIX."projet");
}
else
{

View File

@@ -246,7 +246,7 @@ class Propal
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal");
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE ref='$this->ref';";
if ( $this->db->query($sql) )

View File

@@ -84,7 +84,7 @@ class Retourbplc
if ($result)
{
return $this->db->last_insert_id();
return $this->db->last_insert_id(MAIN_DB_PREFIX."transaction_bplc");
}
else
{

View File

@@ -52,13 +52,14 @@ class Service {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."service (datec, fk_user_author) VALUES (now(), ".$user->id.")";
if ($this->db->query($sql) ) {
$id = $this->db->last_insert_id();
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."service");
if ( $this->update($id, $user) ) {
return $id;
}
} else {
print $this->db->error() . ' in ' . $sql;
return -1;
}
}

View File

@@ -121,7 +121,7 @@ class Societe {
$result=$this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
$this->creation_bit = 1;

View File

@@ -177,7 +177,7 @@ class LigneTel {
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."telephonie_societe_ligne");
$this->SetRemise($user, $this->remise, 'Remise initiale');

View File

@@ -175,7 +175,7 @@ if (!$error)
if (!$error)
{
$sql = "INSERT INTO llx_telephonie_facture";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " (fk_ligne, ligne, date)";
$sql .= " VALUES (".$ligne->id.",";
@@ -183,7 +183,7 @@ if (!$error)
if ($db->query($sql))
{
$facid = $db->last_insert_id();
$facid = $db->last_insert_id(MAIN_DB_PREFIX."telephonie_facture");
}
else
{

View File

@@ -36,7 +36,7 @@ $sql .= " 'Simulation du $date')";
if ( $db->query($sql) )
{
$simid = $db->last_insert_id();
$simid = $db->last_insert_id(MAIN_DB_PREFIX."telephonie_simul");
}
print "Simulation : $simid\n";
/*******************************************************************************

View File

@@ -60,7 +60,7 @@ class TelephonieContrat {
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."telephonie_contrat");
$sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_contrat";
$sql .= " SET ref='".substr("00000000".$this->id,-8)."'";

View File

@@ -83,7 +83,7 @@ class TelephonieService {
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id();
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."telephonie_service");
return 0;
}
else

View File

@@ -523,7 +523,8 @@ class User
{
if ($this->db->affected_rows())
{
$this->id = $this->db->last_insert_id();
$table = "".MAIN_DB_PREFIX."user";
$this->id = $this->db->last_insert_id($table);
$this->admin = 0;
$this->update();