Link to home
Start Free TrialLog in
Avatar of amidamaru
amidamaru

asked on

Problem to write in an Oracle Database

I am using Delphi 5 with an ODBC alias to access an Oracle database. I have no problem to read the informations in a table but the problem is when I want write a number and a name(by parameters), Delphi makes me a DBEngineError. Any ideas?
My Code :
QueryNouvelIntervenant.SQL.Text :=
  'INSERT INTO intervenant VALUES(' +':param_num'+ ',' +':param_nom' + ')';

QueryNouvelIntervenant.ParamByName('param_num').AsInteger := StrToInt(edt_num.Text);
QueryNouvelIntervenant.ParamByName('param_nom').AsString := Edt_nom.Text;
Avatar of kretzschmar
kretzschmar
Flag of Germany image

your text should be

 'INSERT INTO intervenant VALUES(:param_num,:param_nom)';


best would be also to qualify the correspondending fields
like

 'INSERT INTO intervenant (FieldName1, FieldName2) VALUES(:param_num,:param_nom)';

whereas fieldnameX must be replaced with your real fieldnames

meikl ;-)

Avatar of merry_prince
merry_prince

Would you please announce some detailed info? such as table structure, detailed error message, etc.
After setting parameters you must use QueryNouvelIntervenant.ExecSQL not QueryNouvelIntervenant.Open?

Ivan

P.S. I am only checking. :-)
nice check, ivan, and true ;-)
Avatar of amidamaru

ASKER

@kretzschmar : I also tested as you say but that does not change anything

@merry_prince :
Table intervenant :
Num NUMBER(9)
Nom VARCHAR2(20)

I try to translate from French
Error Message : The project AcceBd.exe makes an exception classes EDBEngineError with message 'Nonapplicable operation '.

@IPCH : I use a
QueryNouvelIntervenant.Prepare and after a
QueryNouvelIntervenant.ExecSQL
The exception come from the execsql

it is as if it did not accept the string from the parameter, when I write
'INSERT INTO intervenant VALUES(:param_num,''test'')';
he can write in the table without problems  
It's a nightmare
 
well, ok,
you must define the paramtype of youe second
parameter to a stringtype, guessing the type
is currently unknown.

meikl ;-)
@kretzschmar :
    QueryNouvelIntervenant.SQL.Text :=
      'INSERT INTO intervenant VALUES (:param_num, :param_nom)';
QueryNouvelIntervenant.Params[0].DataType := ftInteger;
QueryNouvelIntervenant.Params[1].DataType := ftString;

I try this but no change always this ****** exception
it makes me crazy ^_^
Can you use another param name instead of param_nom? Please try it.

If still mistake, would you please list the source codes related to database operations?
@kretzschmar :
    QueryNouvelIntervenant.SQL.Text :=
      'INSERT INTO intervenant VALUES (:param_num, :param_nom)';
QueryNouvelIntervenant.Params[0].DataType := ftInteger;
QueryNouvelIntervenant.Params[1].DataType := ftString;

I try this but no change always this ****** exception
it makes me crazy ^_^
Sorry i make a mistake and resend my old message oops !

procedure TForm1.FormCreate(Sender: TObject);
begin
    basename := 'BaseOracle';
    Database1.DatabaseName := basename;
    Database1.Open;

   //requête affichant tous les intervenants
    QueryAfficheIntervenants.DatabaseName := basename;
    QueryAfficheIntervenants.SQL.Text :=
      'SELECT num AS "Numéro",nom FROM intervenant ORDER
BY num';

    QueryNouvelIntervenant.DatabaseName := basename;
    QueryNouvelIntervenant.SQL.Text :=
      'INSERT INTO intervenant VALUES (:param_num, :p_nom)';
    QueryNouvelIntervenant.Params[0].DataType := ftInteger;
    QueryNouvelIntervenant.Params[1].DataType := ftString;

procedure TForm1.Bt_AjoutClick(Sender: TObject);
begin
  QueryNouvelIntervenant.ParamByName ('param_num').AsInteger := StrToInt(edt_num.Text);
  QueryNouvelIntervenant.ParamByName('p_nom').AsString :=  Edt_nom.Text;

  QueryNouvelIntervenant.Prepare;
  QueryNouvelIntervenant.ExecSQL;

  //this quey
  QueryAfficheIntervenants.Close;
  QueryAfficheIntervenants.Open;
Can it be possible that the driver odbc is not correct ?
I use Microsoft ODBC for Oracle
Please create an ODBC db alias which driver is Oracle ODBC Driver. OK?
Wonderfull, it ok, thank you very much ^_^
But I don't understand why it does not work with the driver from microsoft ? It's not normal that they make driver and they don't work !!!
do you know any app from microsoft,
which works properly?

glad you got it work,
never gueesed that there is the problem.

merry_prince should be graded,
good work

meikl ;-)
ASKER CERTIFIED SOLUTION
Avatar of merry_prince
merry_prince

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If my memory isn't wrong. It maybe cause by the old ODBC driver type not support your oracle client program. Microsoft ODBC for Oracle only can support the version less than Oracle8.1.5. If want to support the version high than oracle 8.1.6, you should use Oracle ODBC Driver.

Just suggest you should format the code as below. It's benefit for reading.

procedure TForm1.FormCreate(Sender: TObject);
begin
   basename := 'BaseOracle';
   Database1.DatabaseName := basename;
   Database1.Open;

  //requjte affichant tous les intervenants
  with QueryAfficheIntervenants, SQL do begin
    DatabaseName := basename;
    Add('SELECT num AS "Numiro",nom FROM intervenant ORDER BY num');
  end; {with}

  with QueryNouvelIntervenant, SQL do begin
    DatabaseName := basename;
    Add('INSERT INTO intervenant VALUES (:param_num, :p_nom)');
  end; {with}

procedure TForm1.Bt_AjoutClick(Sender: TObject);
begin
  with QueryNouvelIntervenant do begin
    ParamByName ('param_num').AsInteger := StrToInt(edt_num.Text);
    ParamByName('p_nom').AsString :=  Edt_nom.Text;
    ExecSQL;
  end; {with}

 //this quey
  with QueryAfficheIntervenants do begin
    Close;
    Open;
  end; {with}
Thank you very much for answer so quickly ^_^