473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ADODB::RecordCount() crashes with empty recordset

code green
1,726 Expert 1GB
I have been working with a script I have inherited that uses the ADODB class.
I want to run a query that checks a record is unique across the primary key and date field in a MsSql DB before inserting, so I am using this function
Expand|Select|Wrap|Line Numbers
  1. ADODB::Execute() 
to run this query
Expand|Select|Wrap|Line Numbers
  1. SELECT 1 FROM table WHERE pk = 'code' AND eff_date = 'newdate'. 
Which hopefully returns an empty recordset. But when I call
Expand|Select|Wrap|Line Numbers
  1. ADODB::RecordCount() 
to confirm the count is zero the damn thing falls over with 'Fatal error: Call to a non undefined member function RecordCount() on a non object'.
The call works fine if a non empty recordset is returned.
I have written my own DB class because PEAR is awful and so is this idiotic ADODB by the looks of things.
Anybody familiar with this class who can point a way out.
Jun 28 '07 #1
8 19098
Motoma
3,237 Expert 2GB
I have been working with a script I have inherited that uses the ADODB class.
I want to run a query that checks a record is unique across the primary key and date field in a MsSql DB before inserting, so I am using this function
Expand|Select|Wrap|Line Numbers
  1. ADODB::Execute() 
to run this query
Expand|Select|Wrap|Line Numbers
  1. SELECT 1 FROM table WHERE pk = 'code' AND eff_date = 'newdate'. 
Which hopefully returns an empty recordset. But when I call
Expand|Select|Wrap|Line Numbers
  1. ADODB::RecordCount() 
to confirm the count is zero the damn thing falls over with 'Fatal error: Call to a non undefined member function RecordCount() on a non object'.
The call works fine if a non empty recordset is returned.
I have written my own DB class because PEAR is awful and so is this idiotic ADODB by the looks of things.
Anybody familiar with this class who can point a way out.
It may be more useful to us if you posted a small amount of the relevant code for us to look at.
Jun 28 '07 #2
pbmods
5,821 Expert 4TB
Heya, Code Green.

Ok, first off, take a few breaths. Computers aren't supposed to do what we *want* them to do; that's why they're computers!

Now then.

If you're getting this error, then your ADODB include file is probably not found. Try:
Expand|Select|Wrap|Line Numbers
  1. print(str_replace(';', "<br />", ini_get('include_path')));
and make sure that your PEAR directory is included in the list.
Jun 28 '07 #3
code green
1,726 Expert 1GB
Sorry. I was angry with ADODB. Here is the problem block of code, edited to protect the innocent.
[PHP]require_once("adodb/adodb.inc.php");
** This section (removed) opens and reads a CSV file and places the data in $data

$conn = &ADONewConnection("mssql://user:pass@nn.nn.nn.nn/name") or die ("Could not connect to database");

foreach ($data as $k=>&$line) {
// Loop over all records, checking for validity.

$partcode = trim($line['part']);
$effdate = trim($line['eff_date']);
$cost = trim($line['cost']);

(strlen($partcode) != 0) or die("<br>Part code missing at line <b>$k</b>");
(strlen($effdate) != 0) or die("<br>Effective date missing at line <b>$k</b>");

//Now check the part exists before attemptng an UPDATE
$checkQuery = 'SELECT 1 FROM part WHERE part LIKE '.$conn->Quote($partcode);

$recordset = $conn->Execute($checkQuery);
if($recordset->RecordCount())
{
//Now check the part and effective date are not being duplicated
$checkQuery = 'SELECT 1 FROM part_cost,part_ccel
WHERE part LIKE '.$conn->Quote($partcode) 'AND eff_date LIKE '.$conn->Quote($effdate);
$recordset = $conn->Execute($checkQuery);
if(!$recordset->RecordCount())
{
**Fails here**[/PHP]
The first query executes OK and the first call to RecordCount() works fine.
The second query executes fine but the call to RecordCount() produces this error.
Expand|Select|Wrap|Line Numbers
  1. 'Fatal error: Call to a member function RecordCount() on a non object'. 
I've looked at the ADODB manual, which says -1 may be returned from RecordCount "if the number of rows returned cannot be determined"
This could be the problem, although the error indicates something else.
Thanks in advance for help.
Jun 29 '07 #4
pbmods
5,821 Expert 4TB
Heya, Code Green.

I've looked at the ADODB manual, which says -1 may be returned from RecordCount "if the number of rows returned cannot be determined"
This could be the problem, although the error indicates something else.
Okiedokie. Here's what might be happening:
  • $conn->execute() runs, but there were no matching rows, so it returns -1;
  • $recordset gets set to -1 instead of a resultset object.
  • Your script attempts to call -1->RecordCount(), which... well, doesn't work so well.

The solution would be to check to make sure that $recordset has the proper type before calling $recordset->RecordCount().

You could use either is_object(), or for better robustness, use the instanceof operator.
Jun 29 '07 #5
ronnil
134 Expert 100+
$checkQuery = 'SELECT 1 FROM part_cost,part_ccel WHERE part LIKE '.$conn->Quote($partcode) 'AND eff_date LIKE '.$conn->Quote($effdate);

Don't know much about the ADODB, but looking at this line there's a syntax error... I don't know if this comes from you modification, cause php should make a fatal error when a string is not concenated properly (i should mean)

(there's a '.' (dot) missing before 'AND eff_date ....
Jun 29 '07 #6
Motoma
3,237 Expert 2GB
If you read through the ADODB documentation, you will see that the execute function will return false if there was an error executing your query. I assume that this is the case you are running in to.

You can use short circuit evaluation in your if statement to get rid of this error:

if($recordset && $recordset->RecordCount() == 0) should do just fine.


With this in mind, I would suggest you correct the other conditionals that try and use your record set without checking its existence.


P.S. Looking at the responses in this thread makes me tingly inside.
Jun 29 '07 #7
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. (there's a '.' (dot) missing before 'AND eff_date ....
Sorry that was just a typo from editing directly in the post
Your script attempts to call -1->RecordCount(),
The solution would be to check to make sure that $recordset has the proper type before calling $recordset->RecordCount().
Yep. That makes a lot of sense.
But I am running this test hoping that no records are returned, that is, there should be no duplicates.
Sooo, obviously these are not the functions to use. I will have to go back to the manual and try and find another method. Thanks for the help.
Jun 29 '07 #8
pbmods
5,821 Expert 4TB
Heya, Code Green.

How about this:

Expand|Select|Wrap|Line Numbers
  1. $checkQuery = "SELECT IF(EXISTS(SELECT * FROM `part_cost` INNER JOIN `part_ccel` WHERE `part` = '{$conn->Quote($partcode)}' AND `eff_date` = '{$conn->Quote($effdate)}'), 1, 0)";
  2.  
Jun 29 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kevin Shea | last post by:
I'm currently running into a problem with ie6 on a windows 2000 machine. I've developed a web application where the client, using JavaScript, opens up an ADODB.Recordset recordset and then reads...
3
by: Marty | last post by:
Hi, What is the VB.NET equivalent of the VB6 ADODB.Connector and ADODB.Recordset? Thanks Marty
5
by: Simone | last post by:
Hello I hope you guys can help me. I am very new to ADO... I am creating a ADODB connection in a module and trying to access it from a command button in a form. Function fxEIDAssgn(plngEID As...
3
by: | last post by:
Hello ppl, I have snippet that works fine udner ADODB with VB6, but something wrong with it in Vb.NET. Anyone can help? Recordset1 (ADODB.Recordset) Error: Arguments are of the wrong type, are...
0
by: sonasiva | last post by:
hai Iam creating website using ASP i wnts my clients to register first to vist site using username and password,,this i need to do iam getting error like this ADODB.Recordset (0x800A0BB9)...
0
by: PCroser | last post by:
I have encountered a problem when querying a table. The query passed data into a recordset which should have resulted in many records but has returned EOF. After debugging the code the only...
1
by: sphinney | last post by:
All, I have a ADODB.Recordset in my Access 2002 project. I've been able to successfully add fields to the record set. According the the MS Access help files, I now must update the recordset to...
1
by: sanika1507 | last post by:
Hi .Actually I want to count the number of records in a recordset. So I m using the ADODB.Recordset. I just want some one to correct me. Set Cmd = Server.CreateObject("ADODB.Recordset") ...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.