Autor Beitrag
juergen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Di 28.10.03 14:00 
Hallo,

ich möchte eine insert into ... select ... Query durchführen.

Bei MySQLDAC gibts da ein Problem mit query.open bzw query.execsql.
Kennt jemand eine Lösung ?

DANKE

juergen
joerg68
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 116

Win 2000
D5Enterprise
BeitragVerfasst: Di 28.10.03 14:04 
Sorry meine Glaskugel ist zur Zeit leider beschlagen und ich kann deinen Code nicht erkennen :roll:

Poste doch bitte etwas Code

Gruß
Jörg

_________________
Aus den Chaos sprach eine Stimme " Lächele und sei froh denn es könnte schlimmer kommen". Und ich lächelte und ich war froh.
UND ES KAM SCHLIMMER
juergen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Di 28.10.03 14:12 
OK

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
with mysqlquery1 do
begin
  close;
  sql.Clear;
  s:=' insert into tabelle1 select feld1 from tabelle2';
  sql.Add(s);
  execsql;             // <span style="font-style: italic">alternativ</span> open;
end;


Das Problem ist, das laut Hilfedatei für insert ein execsql benutzt werden soll und für select ein open !

ABER DAS IST DOCH SCH...

juergen

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Di 28.10.03 14:57 
Hallo,

Du musst Deinem Insert schon sagen, in welches Feld er den Wert einfügen soll:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
with mysqlquery1 do 
begin 
  close; 
  sql.Text:='insert into tabelle1 (feldxx) select feld1 from tabelle2'; 
  execsql;            
end;


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
juergen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Di 28.10.03 15:18 
smiegel: das ist nicht das problem ! in dieser testtabelle gibts nur eine spalte da brauch nichts angeben.

das problem ist, das in einer query ein select und ein insert steht was mit mysqldac unterschiedlich aufgerufen werdn muß !

juergen
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Di 28.10.03 15:28 
Hallo,

juergen hat folgendes geschrieben:

... in dieser testtabelle gibts nur eine spalte da brauch nichts angeben...


Das stimmt so nicht. In einem Insert-Statement muss immer das Feld angegeben werden, in das die Daten rein sollen.

Folgens ein Ausschnitt aus der MySQL-Hilfe:
Zitat:

6.4.3.1 INSERT ... SELECT Syntax
INSERT [LOW_PRIORITY] [IGNORE] [INTO] tbl_name [(column list)] SELECT ...


With INSERT ... SELECT statement you can quickly insert many rows into a table from one or many tables.

INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID FROM tblTemp1 WHERE tblTemp1.fldOrder_ID > 100;

The following conditions hold for an INSERT ... SELECT statement:

The target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query because it's forbidden
in ANSI SQL to SELECT from the same table into which you are inserting. (The problem is that the SELECT possibly would find records that
were inserted earlier during the same run. When using subselect clauses, the situation could easily be very confusing!)

AUTO_INCREMENT columns work as usual.

You can use the C API function mysql_info() to get information about the query. See section 6.4.3 INSERT Syntax.
To ensure that the update log/binary log can be used to re-create the original tables, MySQL will not allow concurrent inserts during INSERT ... SELECT.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
juergen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Di 28.10.03 17:08 
smiegel: was in den eckigen klammern steht ist optional !!!
(hier: column list)

Zitat:
INSERT [LOW_PRIORITY] [IGNORE] [INTO] tbl_name [(column list)] SELECT ...


aber darum gehts mir ja eigentlich auch nicht

juergen
Andi1982
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 497

WinXP HE
D6 Enterprise
BeitragVerfasst: Mi 29.10.03 09:48 
Ich würde sagen du musst das EXECSQL benutzen da es sich vom Sinn her ja hauptsächlich um einen Insert handelt.

so sollte es eigentlich funktionieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
with mysqlquery1 do 
begin 
  close;
  sql.clear;
  sql.Text:=' insert into tabelle1 select feld1 from tabelle2;';
  execsql;            
end;


Gruss Andi

_________________
Solange die Bombe tickt ist alles in Ordnung, erst wenn sie damit aufhört wird es problematisch...
juergen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Mi 29.10.03 10:38 
Andi

bei execsql gibts zwar keinen Fehler aber es wird auch nichts eingefügt !

ich hab mal ne Mail an den Support von Microolab gesendet.

juergen
mstuebner
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 132

Win2000, XP
D7
BeitragVerfasst: Mi 29.10.03 11:53 
juergen hat folgendes geschrieben:

Das Problem ist, das laut Hilfedatei für insert ein execsql benutzt werden soll und für select ein open !

ABER DAS IST DOCH SCH...

Warum? Bei einem Select handelt es sich um eine Abfrage welche ein Ergebnis zurückliefert, bei Insert nicht. Wenn Dich das stört, dann leite Deine Klasse ab, schreibe eine neue allgemeine Prozedur die das intern entscheidet was auszuführen ist.

_________________
mfg Matthias