Page 1 of 1

how to check whether setkey was successful ?

Posted: 15 Sep 2016 08:42
by autocart
obviously setkey is a SC command and has no return value.
Of course I can check with getkey to see if the value is the one desired.
but of course, this takes unreasonable time since the file needs to be accessed again.
would it not be better if setkey was a function and had a return value indicating whether it was successful or not?

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 10:24
by PeterH
I think we had this type of problem long long ago, maybe not in exact the same context.

My current idea for this would be if XY defined a variable like <rc>, containing return code information for the last executed command or function. (This way it also could be used for functions usually returning other information.)

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 11:20
by admin
PeterH wrote:I think we had this type of problem long long ago, maybe not in exact the same context.

My current idea for this would be if XY defined a variable like <rc>, containing return code information for the last executed command or function. (This way it also could be used for functions usually returning other information.)
Good idea, but cannot be done. It would be an incredible amount of work to implement and document it.

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 11:22
by autocart
admin wrote:
PeterH wrote:I think we had this type of problem long long ago, maybe not in exact the same context.

My current idea for this would be if XY defined a variable like <rc>, containing return code information for the last executed command or function. (This way it also could be used for functions usually returning other information.)
Good idea, but cannot be done. It would be an incredible amount of work to implement and document it.
what about only transforming setkey into a function (instead of a command)?

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 11:38
by admin
A troublesome thing to do. I see no compelling reason to go that way.

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 12:17
by autocart
ok, no big issue. was just asking.
there still is the workarund of checking with getkey.

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 12:22
by bdeshi
You could check the file size, modified date etc before and after the setkey cmd.. If they differ, setkey was probably successful.

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 12:33
by highend
Or a hash value (what I do with my files to make sure they weren't modified)...

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 13:18
by bdeshi
That's probably even slower than getkey since hash functions have to read the entire file.

Re: how to check whether setkey was successful ?

Posted: 15 Sep 2016 13:50
by highend
Calculating a sha1 hash 100 times (in a loop) for an .ini file with two sections and 25 key-value pairs takes 47ms. Can't see an issue there.