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
WIKI Timeout issues
Please read here if you have trouble connecting to the wiki
Recent
ChatGPT and ObjectPascal ...
by
Joanna
[
Today
at 01:13:59 am]
Create a png image from a...
by
TBMan
[
Today
at 12:55:14 am]
Reselect Last Selection
by
440bx
[July 09, 2025, 11:59:04 pm]
Questions about GUID decl...
by
440bx
[July 09, 2025, 11:44:59 pm]
LINUX: My program stops w...
by
n7800
[July 09, 2025, 11:23:20 pm]
controls.lpr(731,15) Erro...
by
Guser979
[July 09, 2025, 11:22:13 pm]
[Solved] Reference to bsS...
by
Wilko500
[July 09, 2025, 11:15:03 pm]
TBufDataset with Invalid ...
by
talisjonatas
[July 09, 2025, 11:06:24 pm]
Synapse TCP/IP client and...
by
rca
[July 09, 2025, 10:46:14 pm]
activex.pp definition pro...
by
gues1
[July 09, 2025, 10:27:36 pm]
Hint windows misplaced an...
by
n7800
[July 09, 2025, 09:59:53 pm]
Input Chinese using Micro...
by
n7800
[July 09, 2025, 09:49:38 pm]
internal Compiler Error
by
marcov
[July 09, 2025, 09:25:27 pm]
Zeromemory vs. Fillchar
by
TBMan
[July 09, 2025, 09:22:44 pm]
Persistent MacOS Arm M ch...
by
Grahame Grieve
[July 09, 2025, 07:56:35 pm]
Flow fields and BFS
by
TBMan
[July 09, 2025, 06:58:22 pm]
Platform eXtended Library...
by
pascalbythree
[July 09, 2025, 05:10:57 pm]
Tangled Line Pattern Make...
by
Boleeman
[July 09, 2025, 04:27:51 pm]
DBF edit & append problem
by
Petrus Vorster
[July 09, 2025, 04:08:21 pm]
[Solved] Can't install mo...
by
lainz
[July 09, 2025, 03:28:41 pm]
[Solved]Open Project fail...
by
cdbc
[July 09, 2025, 03:06:30 pm]
Popup Form to close when ...
by
Thaddy
[July 09, 2025, 02:10:55 pm]
Spikey Splat Creatures fr...
by
Boleeman
[July 09, 2025, 01:19:35 pm]
Amigo programming languag...
by
paxscript
[July 09, 2025, 12:20:33 pm]
Ballet of Lines and Dots ...
by
Boleeman
[July 09, 2025, 09:19:59 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: MSSQL sqoAutoApplyUpdates doesnt work for SP (Read 951 times)
af0815
Hero Member
Posts: 1392
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: 3001
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: 374
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: 1392
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: 1392
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: 374
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: 1392
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