La commande sql ne se termine pas correctement

Signaler
Messages postés
3
Date d'inscription
jeudi 13 décembre 2007
Statut
Membre
Dernière intervention
17 septembre 2008
-
Messages postés
4200
Date d'inscription
samedi 16 octobre 2004
Statut
Modérateur
Dernière intervention
13 juin 2020
-
bonjour
j'ai rencontré ce problème, et je ne sais pas où est l'erreur, malgré j'ai utilisé "clear', voici le code
if(cree=true)thenbeginwith SqlQuery1 dobegin
Close;
with Sql dobegin
Clear;
Add('update commande');
add('set designation='' '+edit2.text+' '' ');
add(',nom_dir ='' '+ComboBox1.Text+' '' ');
add(',type ='' '+Combobox2.Text+' ''');
if edit3.Text=''then add(',dates=NULL ')else add(',dates='' '+edit3.Text+' '' ');
add(',etat='+inttostr(a));
add(',annee='+annee.ComboBox1.Text);
add('set nombre_lot='+inttostr(nbrlot));
add('where numero='' '+edit1.Text+' '' and annee='+annee.ComboBox1.Text);
end;//with sql
execsql;
cree:=false;
end;//with sqlquery1end//if cree=trueelsebeginwith SqlQuery1 dobegin
Close;
with Sql dobegin
Clear;
 
Add('INSERT INTO commande(numero,designation,dates,type,etat,nom_dir,montant,quantite,annee,nombre_lot');
Add('VALUES ('''+edit1.Text+'''');
add(','' '+edit2.text+' '' ');
if edit3.Text=''then add(',dates=NULL ')else add(','' '+edit3.Text+' '' ');
add(','' '+Combobox2.Text+' ''');
add(','+inttostr(a));
add(','' '+ComboBox1.Text+' '' ');
add(','+edit10.Text);
add(','+edit11.Text);
add(','+annee.ComboBox1.Text);
add(','+inttostr(nbrlot)+')');
end; //with sql
execsql;
end; //with sqlquery1end; //if cree=false

<!-- END TEMPLATE: bbcode_code -->et merci d'avance<!-- / message -->

2 réponses

Messages postés
3793
Date d'inscription
samedi 22 décembre 2007
Statut
Membre
Dernière intervention
3 juin 2016
8
Woah, chez moi ça affiche une méga boîte à texte qui affiche toute la ligne ... il faudra que je reporte ce bug si ce n'est déjà fait.

Cordialement, Bacterius !
Messages postés
4200
Date d'inscription
samedi 16 octobre 2004
Statut
Modérateur
Dernière intervention
13 juin 2020
30
const
  _sql_Coma       = #44; // ","
  _sql_DotComa    = #59; // ";"
  _sql_Space      = #32; //
  _sql_Apostrophe = #39; // "'" | #96; // "`"
  _sql_Null       = 'NULL';

//  _sql_BACKUP   = 'BACKUP'+_sql_Space;
//  _sql_CHECK    = 'CHECK'+_sql_Space;
//  _sql_CHECKSUM = 'CHECKSUM'+_sql_Space;
//  _sql_DESCRIBE = 'DESCRIBE'+_sql_Space;
  _sql_INSERT   = 'INSERT'+_sql_Space;
  _sql_INSERTINTO = 'INSERT INTO'+_sql_Space;
//  _sql_REPAIR   = 'REPAIR'+_sql_Space;
//  _sql_RESTORE  = 'RESTORE'+_sql_Space;
  _sql_SELECT   = 'SELECT'+_sql_Space;
  _sql_SELECTALLFROM = 'SELECT * FROM'+_sql_Space;
//  _sql_SHOW     = 'SHOW'+_sql_Space;
  _sql_UPDATE   = 'UPDATE'+_sql_Space;
  _sql_END      = _sql_DotComa;

  _sql_AND      = _sql_Space+'AND'+_sql_Space;
//  _sql_CHANGED  = _sql_Space+'CHANGED'+_sql_Space;
//  _sql_COLUMNS  = _sql_Space+'COLUMNS'+_sql_Space;
//  _sql_DEFAULT  = _sql_Space+'DEFAULT'+_sql_Space;
//  _sql_EXTENDED = _sql_Space+'EXTENDED'+_sql_Space;
//  _sql_FAST     = _sql_Space+'FAST'+_sql_Space;
  _sql_FROM     = _sql_Space+'FROM'+_sql_Space;
//  _sql_FULL     = _sql_Space+'FULL'+_sql_Space;
//  _sql_GLOBAL   = _sql_Space+'GLOBAL'+_sql_Space;
  _sql_INTO     = _sql_Space+'INTO'+_sql_Space;
  _sql_LIMIT    = _sql_Space+'LIMIT'+_sql_Space;
//  _sql_LOCAL    = _sql_Space+'LOCAL'+_sql_Space;
//  _sql_MEDIUM   = _sql_Space+'MEDIUM'+_sql_Space;
  _sql_NOT      = _sql_Space+'NOT'+_sql_Space;
//  _sql_NWTBL    = _sql_Space+'NO_WRITE_TO_BINLOG'+_sql_Space;
  _sql_OR       = _sql_Space+'OR'+_sql_Space;
//  _sql_QUICK    = _sql_Space+'QUICK'+_sql_Space;
//  _sql_SESSION  = _sql_Space+'SESSION'+_sql_Space;
  _sql_SET      = _sql_Space+'SET'+_sql_Space;
//  _sql_TABLE    = _sql_Space+'TABLE'+_sql_Space;
  _sql_TO       = _sql_Space+'TO'+_sql_Space;
//  _sql_USE_FRM  = _sql_Space+'USE_FRM'+_sql_Space;
  _sql_VALUES   = _sql_Space+'VALUES'+_sql_Space;
  _sql_WHERE    = _sql_Space+'WHERE'+_sql_Space;

function _sqlIfThen(const condition: boolean; const OnTrue, OnFalse: string): string;
begin
  case condition of
    false : result := OnFalse;
    true  : result := OnTrue;
  end;
end;

function _sqlProtectFieldData(const FieldData: string): string;
begin
  result := _sql_Apostrophe+FieldData+_sql_Apostrophe;
end;




<hr size="2" width="100%" />


  if cree then
  begin
    SqlQuery1.Close;
    SqlQuery1.SQL.BeginUpdate;
    try
      SqlQuery1.SQL.Clear;
      SqlQuery1.SQL.text :=
      { begin query }

      _sql_UPDATE+ 'commande'+ _sql_SET+
        'designation='+ _sqlProtectFieldData(edit2.text)+
        _sql_Coma+
        'nom_dir='+     _sqlProtectFieldData(ComboBox1.Text)+
        _sql_Coma+
        'type='+        _sqlProtectFieldData(Combobox2.Text)+
        _sql_Coma+
        'dates='+       _sqlIfThen( Edit3.Text = EmptyStr,
                                    _sql_Null, _sqlProtectFieldData(Edit3.Text) )+
        _sql_Coma+
        'etat='+        _sqlProtectFieldData(IntToStr(a))+
        _sql_Coma+
        'annee='+       _sqlProtectFieldData(annee.ComboBox1.Text)+
        _sql_Coma+
        'nombre_lot='+  _sqlProtectFieldData(IntToStr(nbrlot))+

      _sql_WHERE +
        'numero='+ _sqlProtectFieldData(edit1.Text)+
        _sql_AND +
        'annee='+  _sqlProtectFieldData(annee.ComboBox1.Text)+

      _sql_END
      { end query };
    finally
      SqlQuery1.SQL.EndUpdate;
    end;
    SqlQuery1.ExecSQL;
    cree := not cree;
  end
  else
  begin
    SqlQuery1.Close;
    SqlQuery1.SQL.BeginUpdate;
    try
      SqlQuery1.SQL.Clear;
      SqlQuery1.SQL.Text :=
      { begin query }

      _sql_INSERTINTO +
        'commande(numero,designation,dates,type,etat,nom_dir,montant,quantite,annee,nombre_lot)'+

      _sql_VALUES+ '('+
        _sqlProtectFieldData(edit1.Text)+
        _sql_Coma+
        _sqlProtectFieldData(edit2.text)+
        _sql_Coma+
        _sqlIfThen( Edit3.Text = EmptyStr,
                    _sql_Null, _sqlProtectFieldData(Edit3.Text))+
        _sql_Coma+
        _sqlProtectFieldData(Combobox2.Text)+
        _sql_Coma+
        _sqlProtectFieldData(inttostr(a))+
        _sql_Coma+
        _sqlProtectFieldData(ComboBox1.Text)+
        _sql_Coma+
        _sqlProtectFieldData(edit10.Text)+
        _sql_Coma+
        _sqlProtectFieldData(edit11.Text)+
        _sql_Coma+
        _sqlProtectFieldData(annee.ComboBox1.Text)+
        _sql_Coma+
        _sqlProtectFieldData(inttostr(nbrlot))+
        ')'+

      _sql_END
      { end query };
    finally
      SqlQuery1.SQL.EndUpdate;
    end;
    SqlQuery1.ExecSQL;
    cree := not cree;
  end;






<hr size="2" width="100%" />