Welcome! Log In Create A New Profile

Advanced

WD24 - MSSQL - HReadSeekFirst strange effect

Posted by ArieM 
WD24 - MSSQL - HReadSeekFirst strange effect
December 02, 2021 02:08PM
Hi all,

I encounter timeout problems with this statement
HReadSeekFirst(Tbl_Documents, Tablename_RecordID, ['Tbl_Employees',5] )
Tablename_RecordID is a composite key on 2 fileds: Tablename and RecordID

When using the MSSQL profiler I see that this HReadSeekFirst command is translated into TWO sql-statements, see below.
Both queries are fired at the exact same time by Windev (native sql driver)

I would expect the first one, which does exactly what I want.
The second one however looks quite strange to me. This one gives a timeout, because it returns 100.000+ records. records I don't need.

WHy is that? Afaik HReadSeekFirst is used for exact match records if you don't use the hGeneric option

exec sp_executesql N'SELECT [DocumentID],[CreationUser],[CreationDateTime],[Filename],[File],[Tablename],[RecordID] FROM [Tbl_Documents] WITH (NOLOCK)
WHERE [RecordID]=@P1 AND [Tablename]=@P2
ORDER BY 7,6,1',N'@P1 numeric(10),@P2 nvarchar(4000)',12,N'TBL_EXPORTDEFINITIONS'
go

exec sp_executesql N'SELECT [DocumentID],[CreationUser],[CreationDateTime],[Filename],[File],[Tablename],[RecordID] FROM [Tbl_Documents] WITH (NOLOCK)
WHERE [RecordID]>@P1 OR [RecordID]=@P2 AND [Tablename]>@P3
ORDER BY 7,6,1',N'@P1 numeric(10),@P2 numeric(10),@P3 nvarchar(4000)',12,12,N'TBL_EXPORTDEFINITIONS'
go

Arie
Argus
Re: WD24 - MSSQL - HReadSeekFirst strange effect
December 02, 2021 03:49PM
My understanding is that hreadseekFIRST is used to initiate a LOOP, and should be logically followed by a loop with hreadnext.
This would explain your second query.

What you want to do should be done using hreadseek with the hidentical option.
Re: WD24 - MSSQL - HReadSeekFirst strange effect
December 02, 2021 06:15PM
Hi Arie,
is your composite key Unique?
But definitely this a bug - if you see it with PCSofts MSSQL Driver.

Regards
Steven Sitas
Re: WD24 - MSSQL - HReadSeekFirst strange effect
December 03, 2021 12:21PM
Well I changed to HReadSeek(hIdentical) and now only the SECOND query is fired, but not the first one ??

For the moment I changed my app at this particular point and use a WD-query now. That seems to do the job.

In my opinion using queries is better in the first place, except for situation where we need a complete record from one table (like in an edit-form). All other situations (only a few fields are needed or we need to display data from more than one table) are better for queries.

But I still don't get my head around it, maybe I will send it to PCSoft.

Arie
Re: WD24 - MSSQL - HReadSeekFirst strange effect
December 03, 2021 12:27PM
Steven,

No it's not unique. I can have several records in that document-table for one parent record.

I get the idea about "browsing" and Windev has to ask the qlserver for more data. But the query for that is just not right. It looks like it's still using the generic instead of the unique approach, which is what I would expect.

Arie
Re: WD24 - MSSQL - HReadSeekFirst strange effect
December 03, 2021 08:49PM
Arie,
I only use HReadseekFirst() with Primary Keys and they work fine ...
For everything else, I also use Queries - just make sure it is a simple query with NO "complex" links.

Regards
Steven Sitas
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: