Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
6
Erster Beitrag:
vor 2 Jahren, 4 Monaten
Letzter Beitrag:
vor 2 Jahren, 4 Monaten
Beteiligte Autoren:
Jacek, Peter Holemans, Piet van Zanten

[WD14] HReadSeekFirst() in a class method

Startbeitrag von Jacek am 29.09.2015 17:16

Hello,
I am trying to move the interface between tables and application to class methods. The data are held in an object and then moved to a table with Create or Update methods.
It's all about the Update method. To be able to use HModify() I had to get a position in a table (or a file, if you prefere). I thought that HReadSekFirst would do the trick. Actually it does but only half-way. The method looks like this:

PROCEDURE Update()

{:ProperTabelName_STR,indFile}..Connection = gDict_cnConnection

HReadSeekFirst( :ProperTabelName_STR, SpedKsw_CR, :SpedKsw_CR )

MemoryToFile( object, :ProperTabelName_STR )

IF NOT HModify( :ProperTabelName_STR ) THEN
Error( "CL_Forwarder::Update(): HModify( spedytorzy )", HErrorInfo() )
RETURN
END

where:
:ProperTableName_STR is a string attribute that holds the name of the table in this case it is "spedytorzy"
:SpedKsw_CR is a string attribute that holds the value of the SpedKsw_CR column in spedytorzy table. spedytorzy.SpedKsw_CR is a primary key and there is an index on this column.
gDict_cnConnection is a connection to my MySQL database.

Now when I run this method I get an error:

Error at line 17 of Method Update process.
HReadSeekFirst function called.
No item found in file.

Technical Information
Project : wdWS50_DictSQL
Dump error of module .
- WL Call:
Processing , line , thread
Function , syntax #
- Level: fatal error (EL_FATAL)
- Error Code: 70202
- WD55 Error Code: 202
- No system error code
- No system error message
- What happened?
No item found in file.
- Debug Information:
IEWDHF=27001
Module=
Version=
Fonction (7,12)
- Attached Information:
EIT_LOGICALTABLENAME :
EIT_PILEWL :
Method Update (CL_Spedytor.Update), line 17
Click BTN_SaveAndExit (WIN_AddOrModifyForwarder.BTN_SaveAndExit), line 3
Click Modify (WIN_CarriersDict.Modify), line 7
EIT_COMPOSANT :
EIT_DATEHEURE : 29/09/2015 19:00:21
- Identifier in .err: 71036
Help
- Check that the Item is properly described in the file.

Very well. But if I change the table name in HReadSeekFirst() from :ProperTabelName_STR to spedytorzy, the method behaves and pls note that MemoryToFile() and HModify() don't mind the :ProperTabelName_STR.

I am not noticing something pretty obvious but it's the second day I am playing with the problem and I'll probably use HExecuteSQLQuery() and rewrite the method.
But if you see what my blind eye is missing, pls write.
All the best

Antworten:

Hi Jacek,

This is how it looks in my save method (which will determine if it will call the Add or Update method.:

// Create the db context for update
HReadSeekFirst(:dsTableName,:fnTablePUKName,{:fnTablePUKName,indVariable})
IF NOT HFound(:dsTableName) THEN
AddMode = True
ELSE
AddMode = False
END


As you see you should use indirection to pass the value of your key search value...

If you don't want to go through the hassle of writing your own OO framework you can use mine.
You can download this full working OO framework written in WX19 (but with some components dating back to WX12) for free from: http://repository.windev.com/resource.awp?file_id=91;wxframework-open-source-oop-multiplatform-framework-allows-rapid-development-wdwb-and-later

If you don't have WX19 I can send you a PDF with the source code...
There's also been a webinar on this framework you can view at: WXLive.US: Webinar 129 or Google Hangouts - Webinar 129

This should get you going.

Cheers,

Peter Holemans

von Peter Holemans - am 30.09.2015 07:21
Peter, thanks a lot.

Unfortunately this indirection hasn't worked for me. This time I got an error:

'500001' element unknown.


The string value '500001' was the value that HReadSeekFirst was to look for (sought value).
I shall go around the problem with the HExecSQLQuery(). I did exercise the problem but haven't got more time to play with it.

I shall be very greatful for the PDF, as (for now) I'm working with WD14.

All the best
/Jacek

von Jacek - am 03.10.2015 15:02

Re: [WD14] HReadSeekFirst() in a class method - SOLVED (?)

OK. I have made it work.


HReadSeekFirst( :ProperTabelName_STR, "SpedKsw_CR", :SpedKsw_CR )


This are the only parameters formats that works in the body of a class method, at least for me. Outside the method (in a procedure, widow or whatever) HReadSeekFirst() behaves as in help.

Thanks all. All the best
Over and out.
/Jacek

von Jacek - am 04.10.2015 17:33

Re: [WD14] HReadSeekFirst() in a class method - SOLVED (?)

Hi,

Both Peter and Jacek are using the same variable name for the key name and the search value.
I find this very confusing, makes code hard to read and also prone to errors.
Why not use :fnTablePUKName_Key and :fnTablePUKName_SearchValue.
In Janeks case Windev obviously used the searchvalue to be the key name.

Regards,
Piet

von Piet van Zanten - am 05.10.2015 08:45

Re: [WD14] HReadSeekFirst() in a class method - SOLVED (?)

Hi Piet,

As this is reusable generic code that serves on any db table there is no other way.
If you look at my code you see that I use it differently using indirection...

HReadSeekFirst(:dsTableName,:fnTablePUKName,{:fnTablePUKName,indVariable})


There is the:
- :fnTablePUKName member that contains -> FieldName -> E.g. CustomerID
- {:fnTablePUKName,indVariable} -> The value held in the member field CustomerID -> E.g. 12345

Compare it to C (or W-Language) where VariableX refers to the variable value and &VariableX refers to the memory address.

So :fnTablePUKName contains the name of the primary key field (e.g. CustomerID) and {:fnTablePUKName,indVariable} refers to the value that is held in the CustomerID member (e.g. 12345).

I hope this clears it out.

If you want separate names, then you can create another member called :fnTablePUKNameValue like you suggest that is being assigned by {:fnTablePUKName,indVariable}. But as this is another assignement that needs to be in synced all the time with what is in {:fnTablePUKName,indVariable} it is a potential source of bugs as well... That's why I prefer the above initial method.

Just my 2 cents...

Cheers,

Peter H.

von Peter Holemans - am 05.10.2015 11:01
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.