Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 2 Monaten, 2 Wochen
Letzter Beitrag:
vor 2 Monaten, 2 Wochen
Beteiligte Autoren:
Aad Gouka, p44, GuenterP, Peter Muckle, Fabrice Harari, Paulo Oliveira, Erik Schwarz

hModify()

Startbeitrag von Aad Gouka am 05.07.2017 12:09

Hi all,

hModify() updates a record in a file with new fieldvalues. Is there somesort of way to update one field instead of all the fields in a record ?

Best regards,

Aad

Antworten:

Hi, this is standard! If you read a record with HReadSeek... then the buffer of the file is filled with values of the record. You only have to change those fields which have to be altered and then you'd issue HModify(MyFile) that's all.

von GuenterP - am 05.07.2017 12:38
Hi Aad,

to modify a record you have to read that record first after a seek or direct with hreadseek for example. Then the whole record is in a filebuffer. Then you just Need to Change your field (in the file buffer) and do hmodify.

hreadseek (file,...)
file.field = new value
// all other fields Keep their current values
hmodify (...)

What the database Driver is doing then may not be of interest.

Erik

von Erik Schwarz - am 05.07.2017 12:39
i was just about to post the same question.Only diffrence i am going true the wd turtorial and my understanding of databases in general is low.this bit comes from a rad patern,...
so basicly i made a litle data fille (i know it would be a lot easyer just to calculated but this seemed like a good way to experiment with data filles).so



sSEARCHDATE is string
sSEARCHDATE=EDT_NoName1

TABLE_Time..BrowsedItem = time.yearmonthday1..Name
HReadSeekFirst(time, TABLE_Time..BrowsedItem,sSEARCHDATE , hGeneric)
IF HFound(time) THEN
Info(StringBuild("The search has found the following record:",...))
DateToString(time.yearmonthday1,"MM/DD/YYYY"),...
time.name,...
time.amount,...
time.nameamount))

// Display the table from the record found
TableDisplay(TABLE_Time, taCurrentFirst)
END



So days/months/years discription with duplicates
one unique composite key (the compleet date)
i want to add the whole line however it triggers duplicate error.
so is the structure of the db wrong?

von p44 - am 05.07.2017 13:33
Thanks guys,

The reason why I asked is, that hModify() has a potential danger. In a file with many fields it easily happens, that for some reason (planned or unplanned) another field gets a new value. then the one you want. When you are not aware of that, the file will be saved with a new value in that field.
This potential danger would be history if the function hmodify(file.field) would be one of the 922 new features.

Best regards,

Aad

von Aad Gouka - am 05.07.2017 13:47
Hi Aad,

yes, the YearMonthDay1 item is a unique one. A second record for this day will trigger a duplicate!

von GuenterP - am 05.07.2017 14:58
To modify only one field of the file use UPDATE in sql

Create one update query or write the update by hand and run it using hexecutequery or hexecutesqlquery.

With hmodify it's always all the record.

von Paulo Oliveira - am 05.07.2017 15:02
thats just the thing

if i do
time.name=a data file. or control
screen to fille
hmodify()
and the rest of the code above

i get a duplicate error...i dont understand why i get it on description of day month year.
it shouldent trigger , worst case senario the whole line should be modified instead of the strings i passed manueely,how can a duplicate trigger if i am not trying to add new line buth try to modify a line or record

von p44 - am 05.07.2017 15:12
Hello Aad

this is the kind of code I use in a save button (by example):

- read and block record to modify
- set the values of the fields I want to modify (one or many)
- do the hmodify

this way, only the fields I want are modified and I do not overwrite anything

If I don't know which fields will be modified by the user (in a file form, by example), then it's a little more complex:
- when opening the form, read the record and SAVE IT in memory
- when saving the form, read+lock the record again and do a triple compare, ie compare the original/saved values, the form values, and the current record.
- by comparing the saved value vs the form values, I know what the user modified. By comparing the current record value vs the saved values, I know what was modified outside and I can decide what to keep

For another reason (I want to replicate only the modified fields), there is an example in WXReplication on how to find which fields were modified.

Best regards

von Fabrice Harari - am 05.07.2017 15:20
p44

For information, there are some words that are best avoided as field names in databases as they are reserved for other uses. There aren't too many in Windev http://doc.windev.com/en-US/?1511006&name=list_reserved_words but there are a lot more in SQL https://www.drupal.org/docs/develop/coding-standards/list-of-sql-reserved-words .

I noticed that most of your field names are reserved words in SQL, which will catch you out if you use a SQL database in the future.

Pete

von Peter Muckle - am 05.07.2017 15:37
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.