?
Solved

Problem to write in an Oracle Database

Posted on 2003-03-11
17
Medium Priority
?
261 Views
Last Modified: 2010-04-04
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;
0
Comment
Question by:amidamaru
  • 7
  • 5
  • 4
  • +1
17 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8110137
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 ;-)

0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8110392
Would you please announce some detailed info? such as table structure, detailed error message, etc.
0
 
LVL 2

Expert Comment

by:IPCH
ID: 8110508
After setting parameters you must use QueryNouvelIntervenant.ExecSQL not QueryNouvelIntervenant.Open?

Ivan

P.S. I am only checking. :-)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 8110534
nice check, ivan, and true ;-)
0
 

Author Comment

by:amidamaru
ID: 8117422
@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
 
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8117640
well, ok,
you must define the paramtype of youe second
parameter to a stringtype, guessing the type
is currently unknown.

meikl ;-)
0
 

Author Comment

by:amidamaru
ID: 8117702
@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 ^_^
0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8117759
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?
0
 

Author Comment

by:amidamaru
ID: 8117784
@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 ^_^
0
 

Author Comment

by:amidamaru
ID: 8117810
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;
0
 

Author Comment

by:amidamaru
ID: 8117943
Can it be possible that the driver odbc is not correct ?
I use Microsoft ODBC for Oracle
0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8117994
Please create an ODBC db alias which driver is Oracle ODBC Driver. OK?
0
 

Author Comment

by:amidamaru
ID: 8118038
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 !!!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8118110
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 ;-)
0
 
LVL 1

Accepted Solution

by:
merry_prince earned 300 total points
ID: 8118135
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}
0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8118928
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}
0
 

Author Comment

by:amidamaru
ID: 8134308
Thank you very much for answer so quickly ^_^
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Loops Section Overview
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question