[Delphi] Multi table update/insert

Pagina: 1
Acties:

  • jelmervos
  • Registratie: Oktober 2000
  • Niet online

jelmervos

Simple user

Topicstarter
Ik heb een n-tier applicatie welke gebruikt maakt van een MSSQL server.

Aan de server kant gebruik ik ADODataSet's en DataSetProvider's. Op de client gebruik ik ClientDataSet's.

Als ik nu een update/insert uitvoer op een ClientDataSet die een query (met INNER JOIN ofzo) heeft open heeft staan die over meedere tabellen rijkt, dan wil dit niet.


Stukje uit de help hierover:

When a dataset provider generates SQL statements that apply updates directly to a database server, it needs the name of the database table that contains the records. This can be handled automatically for many datasets such as table-type datasets or live TQuery components. Automatic updates are a problem however, if the provider must apply updates to the data underlying a stored procedure with a result set or a multi-table query. There is no easy way to obtain the name of the table to which updates should be applied.

If the query or stored procedure is a BDE-enabled dataset (TQuery or TStoredProc) and it has an associated update object, the provider uses the update object. However, if there is no update object, you can supply the table name programmatically in an OnGetTableName event handler. Once an event handler supplies the table name, the provider can generate appropriate SQL statements to apply updates.

Supplying a table name only works if the target of the updates is a single database table (that is, only the records in one table need to be updated). If the update requires making changes to multiple underlying database tables, you must explicitly apply the updates in code using the BeforeUpdateRecord event of the provider. Once this event handler has applied an update, you can set the event handlers Applied parameter to True so that the provider does not generate an error.

Note:If the provider is associated with a BDE-enabled dataset, you can use an update object in the BeforeUpdateRecord event handler to apply updates using customized SQL statements.


Is er een simpele oplossing voor dit probleem?

"The shell stopped unexpectedly and Explorer.exe was restarted."


  • jelmervos
  • Registratie: Oktober 2000
  • Niet online

jelmervos

Simple user

Topicstarter
Overigens is dit een beperking van het SQL-92 standaard.

"The shell stopped unexpectedly and Explorer.exe was restarted."


Verwijderd

Ik weet niet of je dit kan helpen maar bij mij werkt het op deze manier wel.
code:
1
2
3
4
5
6
7
8
9
10
11
12
 quKaarten.SQL.Text:= 'update kaart '+
               'set '+
               'contractid ='       + '''' + (MEdtContractK.Text)+''''+
               ',kaartnummer ='   + '''' + (MEdtKaartK.Text)+''''+
               ',status ='       + '''' + (MEdtStatusK.Text)+''''+
               ',[geldig tot] ='     + '''' + (MedtGeldigTotK.Text)+''''+
               ',geprint ='     + '' + (sGeprintK)+''+
               ',reservewiel ='   + '' + (sResWielK)+''+
               ',kenteken ='         + '''' + (MedtKentekenK.Text)+''''+
               ' where kaart.id= '+
               (edtIDK.text);
       quKaarten.ExecSQL;

  • jelmervos
  • Registratie: Oktober 2000
  • Niet online

jelmervos

Simple user

Topicstarter
Dat werkt ook wel. Maar het probleem is dat we gebruik maken van die DB aware componenten op de client. En bij een JOIN query kan hij deze server side niet naar de database sturen omdat hij niet weet welke tabellen er moeten worden geupdate.

Volgens mij. :)

"The shell stopped unexpectedly and Explorer.exe was restarted."