SearchRecord Problem

tnottage

Member
I'm using SearchRecord to find a particular row in a table. When the SearchRecord method is executed, an exception is generated, with the message:

"number of fields and values do not match"

The table that causes the exception has two primary keys. I've traced the code and I am, I think, setting up the SearchRecord function correctly. The FieldNames parameter has two fields, seperated by the semicolon and the creation of the FieldValues variant array did work under BDE.

Modified example code is below. fieldList is a semicolon seperated list of the primary keys of the table. pValueList is a list of the primary key values. Yes, I've checked that this list contains the correct number of items.

Code:
void findRecord(TOracleDataSet * pTable, const AnsiString &fieldList, TStringList *pValueList)
{
if(pValueList->Count > 0)
{
  Variant vaValues;
  // If there is only one value, just assign the variant to it,
  // else create an array to hold the values.
  if(pValueList->Count == 1)
  {
    vaValues = pValueList->Strings[0];
  }
  else
  {
    //int Bounds[2] = {0, pValueList->Count};
    //vaValues = VarArrayCreate(Bounds, 1, varString);
    vaValues = VarArrayCreate(OPENARRAY(int, (0, pValueList->Count)), varOleStr);
    for(int i = 0; i < pValueList->Count; i++)
    {
      vaValues.PutElement(pValueList->Strings[i].c_str(), i);
    }
  }
  TSearchRecordOptions Opts;
  Opts.Clear();
  Opts << srFromBeginning << srForward;
  try
  {
    if(pTable->SearchRecord(fieldList, vaValues, Opts))
    {
       // do something
    }
  }
  catch(Exception &err)
  {
    // display message
  }
}
}

Can anyone see what I may be doing wrong?
Thanks in advance.

Oracle version: 8.1.7
OS: win2000
compiler: C++ Builder 4
DOA version: 3.4.6.1
 
It seems to me that your local array is one element too large:

OPENARRAY(int, (0, pValueList->Count)

Should be:

OPENARRAY(int, (0, pValueList->Count - 1)

I haven't tested this though.

------------------
Marco Kalter
Allround Automations
 
Back
Top