[D2009] Utilisation de paramètres (ou pas) dans une requête SQL Oracle avec DBExpress
Je suis en train de tester Delphi 2009, en vue d'une migration depuis Delphi 6.
Jusqu'à présent, j'utilisais le BDE. Je profite de ce changement, pour passer à DBExpress.
Mon problème :
- 1ere requête avec un paramètre exécutée avec un TSimpleDataSet :
Code:
1 2 3
| QueryTmp.Dataset.CommandText := 'select DESTINATION from DESTINATAIRES where Code_frs=:CodeFrs';
QueryTmp.DataSet.ParamByName('CodeFrs').AsString := codeFrs;
QueryTmp.Open; |
Ok, pas d'erreur.
- 2eme requête sans paramètre :
C'est le même composant QueryTmp, il n'est pas détruit entre temps.
Code:
1 2 3
| QueryTmp.Close;
QueryTmp.DataSet.CommandText := 'select NO_CAMION from CHARGEMENT_PROD';
QueryTmp.Open; |
- Erreur :
Citation:
---------------------------
Notification des exceptions du débogueur
---------------------------
Le projet ProdChrg.exe a déclenché la classe d'exception TDBXError avec le message 'ORA-00904: "CODEFRS" : identificateur non valide'.
---------------------------
Arrêter Continuer Aide
---------------------------
- Extrait du fichier de trace généré : On voit que le paramètre CodeFRS est rajouté à la 2 eme requête.
Citation:
{COMMAND } CommandC1_84.RowSetSize := 20;
{COMMAND } CommandC1_84.CommandType := 'Dbx.SQL';
{COMMAND } CommandC1_84.Text := 'select NULL from HIST_CHARGEMENT_PROD where NO_CAMION=?'#0'oCamion';
{PREPARE } CommandC1_84.Prepare;
{PARAMETER } CommandC1_84.Parameters[0].Value.SetInt32(1);
{COMMAND } ReaderC1_84_1 := CommandC1_84.ExecuteQuery;
{READER } {NULL TDBXTypes.WideString }
{READER } { ReaderC1_84_1 closed. 3 row(s) read }
{READER } FreeAndNil(ReaderC1_84_1);
{COMMAND } FreeAndNil(CommandC1_84);
{METADATA } ConnectionC1.GetDatabaseMetaData;
{METADATA } ConnectionC1.GetDatabaseMetaData;
{COMMAND } CommandC1_85 := ConnectionC1.CreateCommand;
{COMMAND } CommandC1_85.CommandType := 'Dbx.SQL';
{METADATA } ConnectionC1.GetDatabaseMetaData;
{COMMAND } CommandC1_85.RowSetSize := 20;
{COMMAND } CommandC1_85.CommandType := 'Dbx.SQL';
{COMMAND } CommandC1_85.Text := 'select NO_CAMION from CHARGEMENT_PROD where CodeFrs = ?';
{PREPARE } CommandC1_85.Prepare;
{PARAMETER } CommandC1_85.Parameters[0].Value.SetAnsiString('112760');
{COMMAND } ReaderC1_85_1 := CommandC1_85.ExecuteQuery;
{ERR
Est-ce que j'utilise mal ce composant ?
Merci.