Solved

Problem Comparing Values from two Different CRecordsets

Posted on 2004-04-25
2
177 Views
Last Modified: 2013-11-20
I have two tables in Access (and SQL Server - but for this roof of concept, I'm using Access). One table has the fields ipaddress and device name, the other table has locaton information (street, city, state) along with a hostname field that I will use to relate to te previous table via the device name field.

When this utility hits prime time, I will use another search and comparison method (probably), but was trying to whip up a simple proof of concept segment to confirm that I can enter an IP address and return an address. Silly me. I haven't used the CRecordset objects for a while, and am hoping it's something obvious I'm missing.

At any rate, I created a datasource to the database, and then created two CRecordset classes, one to each table. I also created a member variable to each recordset class for easy access. I start by grabbing the IP from the text box, strip off the first three octets, and then check each value in the table that holds the IPs. Initially I started searching for the three octets in a substring, but after that didn't work, I stripped off the first three octets of each value to be tested. Still it doesn't work. I've run it through the debugger, and it appears to function, and I also send each value being tested to a static text box to watch what's going on.

The problem is, it never returns a match, yet if I do a "Find" in Access, or in its previous text version, I find the address. There are over 435,000 records, but I don't think there is a size limit to the recordset because it looks like it cycles through it. So, I wonder why I never find a match.

If anyone has any ideas, I would greatly appreciate them.

Thanks,
Jeff
*************************************************
void CTboxDlg::OnOK()
{
      // TODO: Add extra validation here
      CString                  strAddress;
      CString                  addressBuf;
      CString                  strLocation;
      CString                  locBuf;
      CString                  buf;
      CString                  tempBuf;
      char                  lpBuf[MAX_PATH];
      char                  lpTmp[MAX_PATH];
      char                  szbuf[MAX_PATH];
      char                  szbuffer[MAX_PATH];


      GetDlgItemText (IDC_COMPUTERNAME, strAddress);
      lstrcpy (lpTmp, strAddress);
      addressBuf = SplitIP (lpTmp);
      lstrcpy (szbuf, addressBuf);

      //see if addressBuf is a substring in the Router table
      m_tblRouter.MoveFirst();
      BOOL bFound = FALSE;
      while ((m_tblRouter.IsEOF ()!= TRUE) && (bFound == FALSE))
      {
            buf = m_tblRouter.m_IP;
            tempBuf = SplitIP (lpBuf);
            //if (lpBuf == addressBuf)
            lstrcpy (szbuffer, tempBuf);
            int nComp = lstrcmp (szbuf, szbuffer);
            if (nComp == 0)
            {
                  strLocation = m_tblRouter.m_routerName;
                  AfxMessageBox (strLocation);
                  bFound = TRUE;
            }
            else
            {
                  SetDlgItemText (IDC_STATUS, buf);
                  m_tblRouter.MoveNext();
            }
      }
      
      m_tblLocation.MoveFirst();
      locBuf = m_tblLocation.m_hostname;
      BOOL bDone = FALSE;
      while ((m_tblLocation.IsEOF() != TRUE) && (bDone = TRUE))
      {
            if (locBuf == strLocation)
            {
                  wsprintf (lpBuf, "%s\n", m_tblLocation.m_street);
                  wsprintf (lpBuf, "%s\n", m_tblLocation.m_city);
                  wsprintf (lpBuf, "%s\n", m_tblLocation.m_st);
                  SetDlgItemText (IDC_LOCATION, lpBuf);
                  bDone = TRUE;
            }
            else
            {
                  m_tblLocation.MoveNext();
                  locBuf = m_tblLocation.m_hostname;
            }
      }
      
      //CDialog::OnOK();
}

CString CTboxDlg::SplitIP(char *ip_address)
{
      static char      upper_address[MAX_PATH];
      static char lower_address[MAX_PATH];
      char            *ua = upper_address;
      char            *la = lower_address;
      CString            uAddress("");
      int                  len;
      int                  dotcount;
      LPSTR            lpReturn = NULL;



      FillMemory (upper_address, MAX_PATH, '\0');
      FillMemory (lower_address, MAX_PATH, '\0');

      len = lstrlen (ip_address);
      dotcount = 0;
      for (; *ip_address != '\0'; ip_address++)
      {
            if (*ip_address == '.')
                  dotcount++;
            if (dotcount < 3)
                  *ua++ = *ip_address;
            if (dotcount == 3)
                  *la++ = *ip_address;
      }
      uAddress = upper_address;
      return uAddress;

}
0
Comment
Question by:jpetter
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 10915831
I'd put a breakpoint and single step in your loop.  Check the IP address you have in the edit is the one you are comparing for.


A general point why not construct your SQL statement with the comparison built into that.  Do you know how to make an SQL based on two or more tables and with a comparison clause (WHERE) ?
0
 

Author Comment

by:jpetter
ID: 10931009
I did have a break point set there and didn't notice anything that I didn't anticipate. However, I didn't step through all 400K + records, so I didn't see the comparison I wanted to.

As you suggest, it is a bad design, and a bad idea. I was paged onto a conference bridge Sunday morning and was hit cold with coming up with a proof of concept by noon on Monday. I panicked, and went down what I thought would be a "wham, bam" quick proof of concept, even though it was not based upon a solution we would implement. I did do some searching around on SQL statements, and did the proof that way.

Thanks for your help,
Jeff
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now