Recent

Author Topic: tSQLQuery.UpdateSQL with params  (Read 3302 times)

JRBleau

  • Newbie
  • Posts: 5
tSQLQuery.UpdateSQL with params
« on: July 15, 2025, 07:15:19 pm »
I’d like a basic understanding of how to properly use UpdateSQL with params. I’ve had no problems using SQL with params, but UpdateSQL with params is driving me around the bend.

Table “Players”:
Id, integer; primary index
Nm: 25-char string
Rtg: Integer

tSQLQuery sqlPlayers:
SQL is: Select * From players
updateSQL is: (the params have been defined):
UPDATE players SET Nm = :Nm
WHERE Id = :OLD_Id   

tDatasource dsPlayers: its dataset is the above query
Form: tdbText field for Id; and tdbEdit fields for Nm and Rtg. There’s also a navbar and a grid. Their datasource is all dsPlayers

Here are my questions:
- Can the updateSQL be triggered implicitly? sqlPlayers.update mode is set to upWhereChanged, but this hasn’t worked for me.
- How about explicitly, for example with code in the navbar’s nbPost event? I have tried this, and the posted changes don’t seem to stick.
- Are there recommended triggers, such as sqlPlayers.beforePost or sqlPlayers.afterPost? (I’ve tried various permutations, and I’d get stack overflows).
- Do I have to explicitly close the query and then re-open it?
- Does this require a tSQLTransaction object, with params defined in the tSQLQuery's Transaction.Params list?

Many thanks in advance to anyone who can clear this up.
« Last Edit: July 15, 2025, 07:47:40 pm by JRBleau »

JRBleau

  • Newbie
  • Posts: 5
Re: tSQLQuery.UpdateSQL with params
« Reply #1 on: July 17, 2025, 09:18:11 pm »
The above set-up is good. I do need a tSQLTransaction object ("sqlTr") set to the same database, and the tSQLQuery.Transaction set to sqlTr.

The code in tSQLQuery.AfterPost is simply sqlPlayers.ApplyUpdates;

One of the reasons I couldn't validate various efforts is that the changes wouldn't be reflected in design mode, even if I reconnected, nor in the MySQL Workbench, even after refreshing the tables.

This thread was viewed over 600 times, presumably because others wanted the same answers. If anyone has any Qs, just post them here.

dseligo

  • Hero Member
  • *****
  • Posts: 1671
Re: tSQLQuery.UpdateSQL with params
« Reply #2 on: July 18, 2025, 12:13:24 pm »
Maybe someone can help you from what you wrote, but lack of any answer for 3 days now suggests otherwise.

My suggestion is that you make small project in which you demonstrate your problem. It would be best if you also include 'create table...' to create table and insert some test data.
Then it would be much easier for someone to look at what are you doing and what is wrong with with your code (or your approach).

JRBleau

  • Newbie
  • Posts: 5
Re: tSQLQuery.UpdateSQL with params
« Reply #3 on: July 19, 2025, 04:21:39 am »
Thanks; my second post might not have made it clear but I have solved the problem.

 

TinyPortal © 2005-2018