I know this is the wrong way to do it, but maybe someone can tell me the
right way to do it...
I have two different databases that I need to synchronize. The database
doesn't have keys exactly, but it does provide a rowid function.
So, I am storing a dictionary of <string, long>, string being the rowid
and long being a sum of the hash code for each column in the row.
With this dictionary, it is very easy to determine if a row is new, has
changed, or is already in sync with the target system:
* If I have a rowid that doesn't exist in the dictionary, then I know
it is a new row and I can call my insert code.
* If I have a rowid that exists in the dictionary, and the sum of hash
codes is the same as in my dictionary, then I know that the row has not
changed and there is no action to take.
* If I have a rowid that exists in the dictionary, and the sum of hash
codes is not the same as my dictionary, then I know the row of has
changed, and I need to call my update code.
-----
So, my question is, with this situation, how can I get the same results,
but not store GetHashCode(). I need some kind of "stable" hash
calculation. And it needs to take all kinds of objects; string, int,
decimal, double, etc.
I started to think I could just use a hash code on string and call
ToString() on each column, but this looks just as dangerous as trusting
GetHashCode() not to change.
Thanks for any tips...
Brian 3 2023
Brian <no@email.com > wrote:
<snip> So, my question is, with this situation, how can I get the same results, but not store GetHashCode(). I need some kind of "stable" hash calculation. And it needs to take all kinds of objects; string, int, decimal, double, etc.
Use an MD5 hash (or something similar). You'll need to convert each
type into a stable binary representation, but then you can add each
field to the hash as you go.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Let me just add to Jon's reply. Look at the System.Security .Cryptography
classes.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Brian" wrote: I know this is the wrong way to do it, but maybe someone can tell me the right way to do it...
I have two different databases that I need to synchronize. The database doesn't have keys exactly, but it does provide a rowid function.
So, I am storing a dictionary of <string, long>, string being the rowid and long being a sum of the hash code for each column in the row.
With this dictionary, it is very easy to determine if a row is new, has changed, or is already in sync with the target system:
* If I have a rowid that doesn't exist in the dictionary, then I know it is a new row and I can call my insert code.
* If I have a rowid that exists in the dictionary, and the sum of hash codes is the same as in my dictionary, then I know that the row has not changed and there is no action to take.
* If I have a rowid that exists in the dictionary, and the sum of hash codes is not the same as my dictionary, then I know the row of has changed, and I need to call my update code.
-----
So, my question is, with this situation, how can I get the same results, but not store GetHashCode(). I need some kind of "stable" hash calculation. And it needs to take all kinds of objects; string, int, decimal, double, etc.
I started to think I could just use a hash code on string and call ToString() on each column, but this looks just as dangerous as trusting GetHashCode() not to change.
Thanks for any tips... Brian
And to add to my own reply, here's a sample from an application I wrote a few
years ago:
public static byte[] HashBytes512(st ring pw, bool UE)
{
byte[] pwBytes;
if (UE)
{
pwBytes = Encoding.Unicod e.GetBytes(pw);
}
else
{
pwBytes = Encoding.ASCII. GetBytes(pw);
}
SHA512Managed sha = new SHA512Managed() ;
byte[] hashBytes = sha.ComputeHash (pwBytes);
return hashBytes;
}
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Dale" wrote: Let me just add to Jon's reply. Look at the System.Security .Cryptography classes. -- Dale Preston MCAD C# MCSE, MCDBA
"Brian" wrote:
I know this is the wrong way to do it, but maybe someone can tell me the right way to do it...
I have two different databases that I need to synchronize. The database doesn't have keys exactly, but it does provide a rowid function.
So, I am storing a dictionary of <string, long>, string being the rowid and long being a sum of the hash code for each column in the row.
With this dictionary, it is very easy to determine if a row is new, has changed, or is already in sync with the target system:
* If I have a rowid that doesn't exist in the dictionary, then I know it is a new row and I can call my insert code.
* If I have a rowid that exists in the dictionary, and the sum of hash codes is the same as in my dictionary, then I know that the row has not changed and there is no action to take.
* If I have a rowid that exists in the dictionary, and the sum of hash codes is not the same as my dictionary, then I know the row of has changed, and I need to call my update code.
-----
So, my question is, with this situation, how can I get the same results, but not store GetHashCode(). I need some kind of "stable" hash calculation. And it needs to take all kinds of objects; string, int, decimal, double, etc.
I started to think I could just use a hash code on string and call ToString() on each column, but this looks just as dangerous as trusting GetHashCode() not to change.
Thanks for any tips... Brian
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Benoît Dejean |
last post by:
hi. Is the hash() algorithm standard ? Does hash(some_string) will always
return the same hash code on every arch ?
i need to use a ~checksum function, like md5, but i was also thinking
about hash() which is obviously simpler. So i can safely rely on hash()
behaviour so i can use it to generate ~strong and portable
identifier/checksum ?
thank you
|
by: Hale |
last post by:
Hi,
I'm having a problem storing an array inside of a hash. I'm bringing
in a hash via a reference and I want to assign a value to it. This is what
I'm doing:
push (@{$$node->{ELEMENTS}}, "New value");
(I need to use "push" because this is going in a for-loop)
|
by: Thomas Christmann |
last post by:
Hi!
First let me apologize for asking this question when there are so many answers
to it on Google, but most of them are really contradicting, and making what I
want to do very performant is crucial to my project. So, here's what I have:
My C programm connects to a database and gets ca. 50-100K domain name/file path
pairs. Those pairs have to be cached by my application. Building the cache may
take a second or two, but retrieving from...
|
by: Eduardo Pérez Ureta |
last post by:
I was wondering what the best way is to store a file hash (MD5 or SHA1)
and make it primary key indexed.
I have seen some people storing the hexadecimal encoded MD5 in a
CHAR(32) but it may be a better idea to use a CHAR(16) without encoding
the string, but that may cause some problems.
What do you recommend?
Do you have any experiences storing file hashes in a database?
Do you know any good opensource software that stores file hashes...
|
by: mortb |
last post by:
Hi,
How do I write a GenerateHashcode function that will generate guaranteed
unique hashcodes for my classes?
cheers,
mortb
| |
by: rgparkins |
last post by:
Hi
I am creating a sign-up process on a web site much like that of a
wizard form. I have browsed many sites to look for examples of how to
store the entry data, so that the user can go back and forward along
the sign -up process. I am currently trying to use a Session object to
store all these details and get them back out of session as each step
is selected.
My model was a HashTable of NameValueCollection, so I could go to the
hash...
|
by: John Coleman |
last post by:
Greetings,
I am currently trying to learn Python through the excellent
"Learning Python" book. I wrote my first non-trivial program, which
began with several comment lines. One of the comment lines began with
'#hash'. IDLE doesn't colorize it as a comment line but instead colors
the word 'hash' in purple as if it were a key word. Wierd. The behavior
seems easy to trigger: Just open up a new window in IDLE and enter
these two lines:
...
|
by: nasirmajor |
last post by:
dear all;
my simple quetion is that if we have hashed the users passwords and
stored in databases.
then can we use that hash code e.g
D52987198EA2730FD22A38E7976344D843A7FFA0
in query string. the reasion for asking is that: are generated hash
codes are always unique? so that we can use them for page navigation
like in query string.
|
by: per9000 |
last post by:
Hi all,
I want to create an encryption program and started thinking about not
storing sensitive information in the memory since I guess someone
might steal my computer an scan my memory.
So I wrote this method for getting a password from the console and
converting it to an array of bytes for later use in the encryption
algorithm.
The weak point as I see it is the storage of the password - it will be
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |