 |
Infralution Support Support groups for Infralution products
|
View previous topic :: View next topic |
Author |
Message |
rp Guest
|
Posted: Wed Dec 14, 2005 7:09 pm Post subject: FindUsingPrimaryKey returns -2 |
|
|
I switched the database my program is using from Access to Firebird, and everything has gone fine so far, except when I use the VirtualRecordSet.FindUsingPrimaryKey method it's returning -2.
The docs say it should return "-1" if the record isn't found. However, I've confirmed the record is there -- can you shed any light on this? |
|
Back to top |
|
 |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Dec 14, 2005 10:06 pm Post subject: |
|
|
Below is the code that the FindUsingPrimaryKey method uses to locate the record in the recordset:
Code: |
string criteria = String.Format("{0} = {1}", _primaryKey, GetPrimaryKeyString(primaryKeyValue));
Recordset rs = GetRecordset();
if (rs.RecordCount != 0)
{
rs.MoveFirst();
rs.Find(criteria, 0, SearchDirectionEnum.adSearchForward, Missing.Value);
}
return (rs.EOF) ? -1 : (int) rs.AbsolutePosition - 1;
|
where _primaryKey is the name of the primary key field you provided in the constructor for the recordset and GetPrimaryKeyString simply adds single quotes around text fields.
What is the database field type you have used as a primary key?
The only way I can see this function returning -2 is if the driver returned false for rs.EOF but -1 for rs.AbsolutePosition. This would be an inconsistency in the driver - but in any case would seem to indicate that the Find method did not succeed. You could test this out by connecting directly using ADODB to your firebird database and executing this same logic. _________________ Infralution Support |
|
Back to top |
|
 |
rp Guest
|
Posted: Wed Dec 14, 2005 11:26 pm Post subject: |
|
|
I've tried using INTEGER, BIGINT, and VARCHAR field types as the primary key. It doesn't appear to be the primary key field type causing this issue.
I think I may have found the problem. What cursor types and cursor locations does VDO support?
It appears the default cursor type and location setup for VDO is:
adUseServer
adOpenKeySet
Which the Firebird ODBC driver appears to have forced to:
adUseServer
adForwardOnly
Which in turn caused a freshly created Recordset object to do this:
Recordset.RecordCount returns -1
Recordset.AbsolutePosition returns adPosUnknown (I'm guessing this equals -1)
Recordset.EOF return False
Your code should probably check for this situation, and possibly throw an exception stating "ForwardOnly" cursors aren't supported instead of returning -2.
I think I found a workaround to this by setting the cursor location on the ADODB Connection object to adUseClient, and leaving the cursor type set to the default, adOpenKeyset. RecordCount seems to be returning correct values now.
Thank you for the clues! |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|