473,287 Members | 1,419 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,287 software developers and data experts.

how to advance a database resource pointer to the next row in the returned data?

I had some code that worked fine for several weeks, and then yesterday
it stopped working. I'm not sure what I did. Nor can I make out why it
isn't working. I'm running a query that should return 3 items from the
database. I then get a count of the return, which correctly tells me
that I've got 3 items. I then go into a for loop which I expect to
loop 3 times and print out the 3 items. Here is where things get
strange: it loops 3 times and prints out the same item all 3 times.
More so, the 2nd and 3rd time it complains that it is not getting an
array (meaning it should have nothing to print, yet it prints. If
anyone can see the error I've made, I'd be damned grateful
inside a function called listAll, I've got this:

// 12-05-03 - I originally used the "GetAllOfType" query, but now I
realize I only
// need ids, so instead we'll use the GetAllOfTypeJustIds
$selectObject = & $controllerForAll->getObject("McSelect");
$selectObject->setQueryObject("GetAllOfTypeJustIds");
$selectObject->setInfoToBeSought($type);
$selectObject->getInfo();
$howMany = $selectObject->getCountOfReturn();

for ($i=0; $i < $howMany; $i++) {
$row = null;
$row = $selectObject->getRowAsArrayWithStringIndex();
if (is_array($row)) {
extract($row);
$arrangementObject->setControlPanelCbId($cbId);
$controllerForAll->getArrangement($arrangement);
} else {
$r = $i + 1;
$resultsObject->addToErrorResults("In the function listAll(), we
expect to print out $howMany items, yet for some reason on attempt $r
we did not get an array back from the data as an array.");
}
}


Inside of the select object, I've got this:


/**
* 11-04-03 - wrapper of getter
* We take the resource that points to the returned dataset and feed
it into a method of $formatDatastoreResults.
* We are using the resource pointer to the returned dataset to fetch
the next row and return it with a string index
*/
function getRowAsArrayWithStringIndex() {
$row = array();
if (is_resource($this->dsResultPointer)) {
$row = $this->getDataObject->getRowAsArrayWithStringIndex(&$this->dsResultPointer);
if (is_array($row)) {
$className = get_class($this->getDataObject);
$this->resultsObject->debugNotes("In
getRowAsArrayWithStringIndex(), in the class McSelect, we expected the
data object $className to return a row of data to us (as an array),
and it has.");
return $row;
} else {
$className = get_class($this->getDataObject);
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class McSelect, we expected the
data object '$className' to return a row of data to us, but it has
not.");
}
} else {
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class McSelect, we looked for
the object's resource pointer to a database return, but the select
object didn't have one.");
}
}

Inside the getData object, I've got this:


function getRowAsArrayWithStringIndex(&$dsResultPointer) {
$array = $this->getDataObject->getRowAsArrayWithStringIndex(&$dsResultPointer) ;
$className = get_class($this->getDataObject);
if (is_array($array)) {
$this->resultsObject->debugNotes("In
getRowAsArrayWithStringIndex(), in the class McGetDatastoreResults, we
expected the data object '$className' to return a row of data to us as
an array, and it has.");
return $array;
} else {
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class McGetDatastoreResults, we
expected the data object '$className' to return a row of data to us as
an array, but it has not.");
}
}



Inside the get datastore connector object, I've got this:
/**
* 11-04-03 - obviously, this is just a wrapper for a method in the
queryObject
* We take the resource that points to the returned dataset and feed
it into a method of $formatDatastoreResults.
* We are using the resource pointer to the returned dataset to fetch
the next row and return it with a string index
*
* @param - $dsResultPointer - this is a resource pointer, pointing to
the data returned from the last SELECT call
* to the datastore.
*
* returns array - 1 dimensional
*/
function getRowAsArrayWithStringIndex(&$dsResultPointer) {
if (is_resource($dsResultPointer)) {
$oneDimensionalArray =
$this->formatDatastoreResults->dsRowIntoArrayWithStringIndex(&$dsResultPointer );
$className = get_class($this->formatDatastoreResults);
if (is_array($oneDimensionalArray)) {
$this->resultsObject->debugNotes("In
getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResultsMysql, we expected the format object '$className'
to return a row of data as an array, and it did.");
$oneDimensionalArray =
$this->filterDataObject->thisVisitorIsAllowedToViewThisEntry($oneDimension alArray);
$filterName = get_class($this->filterDataObject);
if (is_array($oneDimensionalArray)) {
$this->resultsObject->debugNotes("In
getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResultsMysql, we expect the filter object '$filterName'
to return a row of data as an array, and it has.");
return $oneDimensionalArray;
} else {
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResultsMysql, we expect the filter object '$filterName'
to return a row of data as an array, and it has not.");
}
} else {
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResultsMysql, we expected the format object '$className'
to return a row of data as an array, and it did not.");
}
} else {
$this->resultsObject->addToErrorResults("In the
getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResultsConnectorMySql, we expected to be given a pointer
to data returned from the database during the last SELECT call.
Instead we got: $dsResultPointer ");
}
}

Inside the data format class, I've got this:

/**
* 11-04-03 - it is important that the resource which points to the
returned dataset gets passed into this method
* by reference, not by copy, or else, in the outside code that is
calling this method, the pointer in that resource
* will never advance to the next resource row.
*/
function dsRowIntoArrayWithStringIndex(&$dsResult) {
// 11-04-03 - this first lines test to see if anything came back
from the datastore
if (is_resource($dsResult)) {
$row = mysql_fetch_array($dsResult, MYSQL_ASSOC);
$row = $this->stripslashesFromEntryWithKeyIndex($row);
return $row;
} else {
$this->resultsObject->addToErrorResults("In
dsRowIntoArrayWithStringIndex(), in the class McFormatResultsMySql, we
expected the method to be handed a pointer to a database return
resource, but we were not.");
}
}




and I've also got this:
function stripslashesFromEntryWithKeyIndex($entry) {
if (is_array($entry)) {
while (list($key, $val) = each($entry)) {
$entry[$key] = stripslashes($val);
}
} else {
$this->resultsObject->addToErrorResults("In
stripslashesFromEntryWithKeyIndex(), in the class
McFormatResultsMySql, we expected the method to be handed an array,
but it was not.");
}
return $entry;
}



These are the errors that get printed out on the 2nd and 3rd loop:

In stripslashesFromEntryWithKeyIndex(), in the class
McFormatResultsMySql, we expected the method to be handed an array,
but it was not.
<hr> In getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResultsMysql, we expected the format object
'mcformatresultsmysql' to return a row of data as an array, and it did
not.
<hr> In getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResults, we expected the data object
'mcgetdatastoreresultsmysql' to return a row of data to us as an
array, but it has not.
<hr> In getRowAsArrayWithStringIndex(), in the class McSelect, we
expected the data object 'mcgetdatastoreresults' to return a row of
data to us, but it has not.
<hr> In stripslashesFromEntryWithKeyIndex(), in the class
McFormatResultsMySql, we expected the method to be handed an array,
but it was not.

<hr> In getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResultsMysql, we expected the format object
'mcformatresultsmysql' to return a row of data as an array, and it did
not.
<hr> In getRowAsArrayWithStringIndex(), in the class
McGetDatastoreResults, we expected the data object
'mcgetdatastoreresultsmysql' to return a row of data to us as an
array, but it has not.
<hr> In getRowAsArrayWithStringIndex(), in the class McSelect, we
expected the data object 'mcgetdatastoreresults' to return a row of
data to us, but it has not.



As I say, this was working perfectly for weeks (since November) but
now it is not. I anyone sees what mistake I made, I'd be grateful for
the feedback.
Jul 17 '05 #1
2 2244
I think I came up with this system right after I'd read some of Bitter
Java. The author makes the point about how important "loose coupling"
is. In retrospect, the last part of this system might have been
excessive. It makes sense to me that a Select object should have a
getData object which should then have a getDataMySql object for
connecting to MySql databases or a getDataXml for reading XML streams.
But the last object, the format object, that seems excessive. So I may
redo that. But I still need to know why I seem to be unable to advance
the internal pointer to the next row of the database return. Again,
this code was working till this week, and now I've done something to
break it.
Jul 17 '05 #2
How is this possible? In McSelect, I just noticed that I never had a
class variable established for my database resource pointer. And yet,
when testing is_resource($this->resource) it tested true! How can that
be? If the variable doesn't exist, it should test false, yes? And it
shouldn't be able to move from one method to another, yes?

Look, here are the class vars I have declared:
var $controllerForAll = null;
var $queryObjectName = null;
var $queryObject = null;
var $getDataObject = null;
var $resultsObject = null;


But here are the two methods in question. One gets the database the
results, the other uses it. In the second, shouldn't the results
pointer be failing the first test? I'm shocked PHP didn't give me a
warning on this.


/**
* 11-04-03- this is just a wrapper for the class method "getInfo" in
the query object.
* This method causes the queryObject to get the wanted info from the
database. However, this does
* not return any info. The following methods will return info.
*/
function getInfo() {
$this->dsResultPointer = $this->queryObject->getInfo();
if (is_resource($dsResultPointer)) {
$className = get_class($this->queryObject);
$this->resultsObject->debugNotes("In the method getInfo(), in the
class McSelect, the query object called $className just returned a
pointer to a database resource.");
} else {
$dsConnector = get_class($this->queryObject);
$this->resultsObject->addToErrorResults("In the method getInfo(),
in the class McSelect, we assume we are getting back a database
resource pointer from the query object, which has the name
$dsConnector. However, we are not getting anything back.");
}

}




/**
* 11-04-03 - wrapper of getter
* We take the resource that points to the returned dataset and feed
it into a method of $formatDatastoreResults.
* We are using the resource pointer to the returned dataset to fetch
the next row and return it with a string index
*/
function getRowAsArrayWithStringIndex() {
$row = array();
if (is_resource($this->dsResultPointer)) {
$className = get_class($this->getDataObject);
$row = $this->getDataObject->getRowAsArrayWithStringIndex($this->dsResultPointer);

if (is_array($row)) {
$this->resultsObject->debugNotes("In
getRowAsArrayWithStringIndex(), in the class McSelect, we expected the
data object $className to return a row of data to us (as an array),
and it has.");
return $row;
} else {
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class McSelect, we expected the
data object '$className' to return a row of data to us, but it has
not.");
}

} else {
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class McSelect, we looked for
the object's resource pointer to a database return, but the select
object didn't have one.");
}
}
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
A very strange bug. www.monkeyclaus.org is run by a cms I'm developing. One of types of users we allow is "justTestingTheSite", a type of user I developed to give demo's to prospective clients. The...
5
by: lawrence | last post by:
I posted before, but have now narrowed my problem down to this method. At the start of the method, I test to make sure that I have a resource, a pointer to data returned from a database. This test...
1
by: James | last post by:
Hi, I am currently creating a database which will be stored on a network. Somebody will take this database out on a laptop will they will input new data via a form. Somehow this new version...
6
by: John Ortt | last post by:
I have created an Access Database to store information from my various bank accounts and keep track of my finances. Everything works great, except that I decided not to keep the balance data on...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
8
by: John Dunn | last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++ apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This works perfectly fine with external files...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
3
by: C++Liliput | last post by:
I have a class of the type class A { private: std::string data; ....... public: const char* toString(); };
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.