Autor Beitrag
SmileySN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 297

WinXP, Win7
Delphi 2010 Professional
BeitragVerfasst: So 18.06.06 21:36 
Wäre dies hier so richtig ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
CREATE PROCEDURE INSERTFIRMA (
    NAME VARCHAR(40),
    STRASSE VARCHAR(40))
RETURNS (
    ID INTEGER)
AS
begin
  ID=GEN_ID(GEN_FIRMA_ID,1);
  INSERT INTO FIRMA (ID,NAME,STRASSE) values(:ID,:NAME,:STRASSE);
  suspend;
end
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 21:40 
Müsste so gehen.

_________________
Markus Kinzler.
SmileySN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 297

WinXP, Win7
Delphi 2010 Professional
BeitragVerfasst: So 18.06.06 22:57 
Ich hab die StoredProcedure jetzt in der Datenbank drin, übergebe keine Werte und bekomme nur ID zurück.
Kannst Du mir noch mal helfen, wie ich die Procedure INSERT_FIRMA aufrufe und die ID damit zurückbekomme ??
Ich weiß nicht wie man eine SP von Delphi aus anspricht und den Parameter übergibt.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 22:59 
ausblenden SQL-Anweisung
1:
Select ID from INSERTFIRMA( <Name>, <Strasse>);					

_________________
Markus Kinzler.
SmileySN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 297

WinXP, Win7
Delphi 2010 Professional
BeitragVerfasst: So 18.06.06 23:12 
Das Select... ist doch sicher ein SQL-Befehl und muss so auch übergeben werden z.B.

ausblenden Delphi-Quelltext
1:
2:
3:
  DM.QFirma.SQL.Clear;
  DM.QFirma.SQL.Add('Select ID from INSERT_FIRMA()');
  DM.QFirma.Open;


Wie kann ich jetzt den Wert ID auslesen ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 23:17 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
DM.QFirma.SQL.Clear;
DM.QFirma.SQL.Add('Select ID from INSERT_FIRMA( <Name>, <strasse>)');
DM.QFirma.Open;
ID :=  DM.QFirma.FieldByName('ID').Value;

_________________
Markus Kinzler.
SmileySN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 297

WinXP, Win7
Delphi 2010 Professional
BeitragVerfasst: So 18.06.06 23:31 
So hab ichs hinbekommen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  DM.QFirma.SQL.Clear;
  DM.QFirma.SQL.Add('Select ID From INSERT_FIRMA');
  DM.QFirma.Open;

  AktFirmaID:= DM.QFirma.FieldByName('ID').AsInteger;


Danke für die Kompetente Hilfe
SmileySN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 297

WinXP, Win7
Delphi 2010 Professional
BeitragVerfasst: So 18.06.06 23:48 
Leider doch noch ein Problem:
ausblenden Delphi-Quelltext
1:
 AktFirmaID:= DM.QFirma.FieldByName('ID').AsInteger;					

Hier bekomme ich immer nur 0 zurück
ausblenden Delphi-Quelltext
1:
 AktFirmaID:= DM.QFirma.FieldByName('ID').Value;					

Hier bekomme ich die Meldung:
Variante des Typs (Null) konnte nicht in Typ (Integer) konvertiert werden
SmileySN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 297

WinXP, Win7
Delphi 2010 Professional
BeitragVerfasst: So 18.06.06 23:49 
So sieht meine SP jetzt in der dB aus

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
CREATE PROCEDURE INSERT_FIRMA 
RETURNS (
    ID INTEGER)
AS
begin
  ID=GEN_ID(GEN_FIRMA_ID,1);
  INSERT INTO FIRMA (FIRMAID) values(:ID);
end^

SET TERM ; ^

GRANT INSERT ON FIRMA TO PROCEDURE INSERT_FIRMA;


Den Trigger musste ich rausnehmen, da er mir sonst noch einen leeren Datensatz zusätzlich angefügt hat.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 23:55 
Zitat:
Den Trigger musste ich rausnehmen, da er mir sonst noch einen leeren Datensatz zusätzlich angefügt hat.
Ich hatte ja geschrieben anstatt des Triggers.

Es fehlt nun das SUSPEND; welches die aktuellen werte der Out-Parameter ( in deinem Fall nur ID) in den Cursor schreibt.

_________________
Markus Kinzler.
SmileySN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 297

WinXP, Win7
Delphi 2010 Professional
BeitragVerfasst: Mo 19.06.06 00:02 
Unglaublich, es funktioniert wirklich.
Jetzt weiß ich auch wozu das suspend gut ist.

Danke Du bist großartig.