Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Databases
»
MSSQL sqoAutoApplyUpdates doesnt work for SP
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
KOL x64
by
Thaddy
[
Today
at 02:06:48 pm]
GTK3 is now the default w...
by
dbannon
[
Today
at 02:02:29 pm]
Install new .deb over exi...
by
dbannon
[
Today
at 01:45:27 pm]
FastCGI vs. CGI
by
egsuh
[
Today
at 12:45:05 pm]
Is this safe, changing fr...
by
Thaddy
[
Today
at 10:29:55 am]
Many recent books on Laza...
by
Thaddy
[
Today
at 08:47:32 am]
Difference between @ and ...
by
DavidTh30
[
Today
at 07:58:00 am]
try/except error
by
Thaddy
[
Today
at 07:23:48 am]
How to connect to MariaDb...
by
Thaddy
[
Today
at 07:18:13 am]
docking IDE
by
kapibara
[
Today
at 04:20:33 am]
Isn’t this funny?
by
Joanna
[
Today
at 12:04:29 am]
Error when opening a proj...
by
Tomu
[July 15, 2026, 09:36:13 pm]
Slow app start on M5 MacB...
by
Thaddy
[July 15, 2026, 03:36:57 pm]
Solpage
by
munair
[July 15, 2026, 01:47:30 pm]
Need help with fphttpserv...
by
Thaddy
[July 15, 2026, 12:58:30 pm]
Freepascal
by
Thaddy
[July 15, 2026, 12:39:23 pm]
Lazarus interface to Rexx...
by
Thaddy
[July 15, 2026, 12:38:10 pm]
Parsing error?
by
Thaddy
[July 15, 2026, 12:02:02 pm]
is there PDS reader/expor...
by
cdbc
[July 15, 2026, 10:55:30 am]
Peculiarities in the EXE ...
by
marcov
[July 15, 2026, 09:57:51 am]
Conscious Artificial Inte...
by
schuler
[July 14, 2026, 11:40:27 pm]
Lazarus Bugfix Release 4....
by
Martin_fr
[July 14, 2026, 10:55:23 pm]
equivalent to C/C++ "offs...
by
Thaddy
[July 14, 2026, 07:37:23 pm]
LazSWatch - a serial port...
by
CM630
[July 14, 2026, 06:11:52 pm]
MarcoV, please contact. ...
by
jbthiel
[July 14, 2026, 05:35:26 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: MSSQL sqoAutoApplyUpdates doesnt work for SP (Read 1210 times)
af0815
Hero Member
Posts: 1409
MSSQL sqoAutoApplyUpdates doesnt work for SP
«
on:
December 14, 2022, 03:57:56 pm »
I have on a MSSQL Server (Linuxbased under Windows the same) a Stored Procedure. This SP rises a Field in a Table by one every execution. If i do it and close the connection all is lost. I have added to the used Query to AutoApplyUpdates and AutoComit. But it doesnt store. If i add a explcit AppyUpdates the Valueas are stored.
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
BuExecuteClick
(
Sender
:
TObject
)
;
var
SQL
:
string
;
begin
Memo1
.
Clear
;
SQL
:
=
''
;
SQL
:
=
'EXECUTE [dbo].[GetNextZaehler] :TagNr,:ProduktNr '
;
Query
.
Active
:
=
false
;
Query
.
Clear
;
Query
.
SQL
.
Text
:
=
SQL
;
Query
.
ParamByName
(
'TagNr'
)
.
AsInteger
:
=
10
;
Query
.
ParamByName
(
'ProduktNr'
)
.
AsInteger
:
=
100
;
Query
.
Options
:
=
[
sqoAutoApplyUpdates
,
sqoAutoCommit
]
;
// <-- AutoApplyUpdates doesnt work !?
try
Query
.
Open
;
if
not
(
Query
.
EOF
and
Query
.
BOF
)
then
begin
Memo1
.
Append
(
'Wert='
+
Query
.
FieldByName
(
'StueckZaehler'
)
.
AsInteger
.
ToString
)
;
end
else
begin
Memo1
.
Append
(
'Kein Wert'
)
;
end
;
//Query.ApplyUpdates; // <-- If i use this it works
Query
.
Close
;
except
on E
:
Exception
do
begin
Memo1
.
Append
(
'BuExecuteClick Exception =>'
+
E
.
Message
)
;
end
;
end
;
end
;
Error in Programmer or FPC ?
Code for the MSSQL DB
Code: Pascal
[Select]
[+]
[-]
USE
[
CounterTestDB
]
GO
SET
ANSI_NULLS ON
GO
SET
QUOTED_IDENTIFIER ON
GO
CREATE TABLE
[
dbo
]
.
[
B_AktStueck
]
(
[
TagNr
]
[
int
]
NOT
NULL
,
[
Produkt
]
[
int
]
NOT
NULL
,
[
Stueckzaehler
]
[
int
]
NOT
NULL
,
CONSTRAINT
[
PK_B_AktStueck
]
PRIMARY KEY CLUSTERED
(
[
TagNr
]
ASC
,
[
Produkt
]
ASC
)
WITH
(
PAD_INDEX
=
OFF
,
STATISTICS_NORECOMPUTE
=
OFF
,
IGNORE_DUP_KEY
=
OFF
,
ALLOW_ROW_LOCKS
=
ON
,
ALLOW_PAGE_LOCKS
=
ON
,
OPTIMIZE_FOR_SEQUENTIAL_KEY
=
OFF
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
]
GO
ALTER TABLE
[
dbo
]
.
[
B_AktStueck
]
ADD CONSTRAINT
[
DF_B_AktStueck_TagNr
]
DEFAULT
(
(
0
)
)
FOR
[
TagNr
]
GO
ALTER TABLE
[
dbo
]
.
[
B_AktStueck
]
ADD CONSTRAINT
[
DF_B_AktStueck_Produkt
]
DEFAULT
(
(
0
)
)
FOR
[
Produkt
]
GO
ALTER TABLE
[
dbo
]
.
[
B_AktStueck
]
ADD CONSTRAINT
[
DF_B_AktStueck_Stueckzaehler
]
DEFAULT
(
(
0
)
)
FOR
[
Stueckzaehler
]
GO
CREATE
PROCEDURE
[
dbo
]
.
[
GetNextZaehler
]
--
Add the parameters
for
the
stored
procedure
here
@
TagNr
integer
,
@
ProduktNr
integer
AS
BEGIN
--
SET
NOCOUNT ON added
to
prevent extra result sets from
--
interfering
with
SELECT statements
.
SET
NOCOUNT ON
;
DECLARE
@
NewCnt
integer
Set
@
NewCnt
=
0
;
BEGIN
TRAN Tran1
SELECT TOP
1
@
NewCnt
=
[
StueckZaehler
]
FROM
[
B_AktStueck
]
WHERE
(
[
TagNr
]
=
@
TagNr
)
AND
(
[
Produkt
]
=
@
ProduktNr
)
ORDER BY
[
TagNr
]
DESC
print
'---- old CounterValue ----'
print
@
NewCnt
if
@
NewCnt
=
0
begin
print
'-- No entry -> created '
INSERT INTO
[
B_AktStueck
]
(
[
TagNr
]
,
[
Produkt
]
,
[
StueckZaehler
]
)
VALUES
(
@
TagNr
,
@
ProduktNr
,
@
NewCnt
)
end
UPDATE
[
B_AktStueck
]
SET
[
StueckZaehler
]
=
[
StueckZaehler
]
+
1
WHERE
(
[
TagNr
]
=
@
TagNr
)
AND
(
[
Produkt
]
=
@
ProduktNr
)
COMMIT TRAN Tran1
SELECT TOP
1
[
StueckZaehler
]
FROM
[
B_AktStueck
]
WHERE
(
[
TagNr
]
=
@
TagNr
)
AND
(
[
Produkt
]
=
@
ProduktNr
)
ORDER BY
[
TagNr
]
DESC
END
GO
Logged
regards
Andreas
Zvoni
Hero Member
Posts: 3440
Re: MSSQL sqoAutoApplyUpdates doesnt work for SP
«
Reply #1 on:
December 14, 2022, 04:09:37 pm »
Just guessing: you start (and commit) a transaction within the SP, which would be isolated from the „outer“ transaction your query-object is a part off
Logged
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Sieben
Sr. Member
Posts: 390
Re: MSSQL sqoAutoApplyUpdates doesnt work for SP
«
Reply #2 on:
December 14, 2022, 04:27:15 pm »
Looking at the sources of TSQLQuery, sqoAutoApplyUpdates needs a Post (or Delete) to be triggered.
Logged
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7
af0815
Hero Member
Posts: 1409
Re: MSSQL sqoAutoApplyUpdates doesnt work for SP
«
Reply #3 on:
December 14, 2022, 05:35:49 pm »
Quote from: Sieben on December 14, 2022, 04:27:15 pm
Looking at the sources of TSQLQuery, sqoAutoApplyUpdates needs a Post (or Delete) to be triggered.
Ok, now i have a startingpoint. i have searches this in the mssqlconnection itself. I have tested this with the the exception handling auto or not, but i have not in focus, that the query need a special setting to make ApplyUpdates automatic.
But it is good to know where the limitations are.
Edit: I have found the places in sqldb.pp and ask o the mailinglist if i should file a bug or is this the expected behavior (and will not fixed).
«
Last Edit: December 15, 2022, 10:21:59 am by af0815
»
Logged
regards
Andreas
af0815
Hero Member
Posts: 1409
Re: MSSQL sqoAutoApplyUpdates doesnt work for SP
«
Reply #4 on:
December 16, 2022, 08:40:11 am »
It is not the sqoApplyUpdates.
The sqoAutoCommit does not work ! You have to close the transaction (implizit created) explicit. The query handle this this not as expected. This was hidden by the ApplyUpdates, because this make a implicit transaction close. MvC brought me in the correct direction.
«
Last Edit: December 16, 2022, 08:43:01 am by af0815
»
Logged
regards
Andreas
Sieben
Sr. Member
Posts: 390
Re: MSSQL sqoAutoApplyUpdates doesnt work for SP
«
Reply #5 on:
December 16, 2022, 03:47:41 pm »
So what does your code look like now...? And if I understand you correctly, the implicit closing of the implicit transaction via ApplyUpdates did work, after all, as well?
Logged
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7
af0815
Hero Member
Posts: 1409
Re: MSSQL sqoAutoApplyUpdates doesnt work for SP
«
Reply #6 on:
December 16, 2022, 05:11:13 pm »
In the place of "//Query.ApplyUpdates" in the first post must be a "Trans1.Commit;" be. The transaction is not visible in the sample, but placed on the Form.
Logged
regards
Andreas
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Databases
»
MSSQL sqoAutoApplyUpdates doesnt work for SP
TinyPortal
© 2005-2018