|
Have you seen this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
Hi
In my MFC application i am reading and MDB file using CCommand as follows:
CDBPropSet cdbPropset;
CCommand <CAccessor<CMyClass>, CRowset> cCommand;
cdbPropset.AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
cCommand.Open(m_pSessionManager->m_Session, csSQLQuery);
hr = cCommand.MoveFirst();
hr = cCommand.MovePrev();
In above code MovePrev() always throwing 265926 error code which is End Of RowsSet.
Can any on let me know whats wrong in my code.? Why record is not moving to previous row?
Thanks for the help.
modified 8-Aug-18 2:40am.
|
|
|
|
|
You call MoveFirst() which sets the pointer to the first record. A following call to MovePrev() will of course fail with DB_S_ENDOFROWSET because the pointer is already at the first position which is the end of the row set for backward scrolling operations.
I can't help further without knowing what you finally want to achieve (why do you want to scroll backwards). But moving backwards when already at the first position makes no sense.
|
|
|
|
|
I am inserting some values in MDB.
Lets say, after inserting 10 values, the pointer will be at 11 row since every time after inserting i will call movenext(). Now while inserting 11th value, i want to go to 10th row and delete the value in 10th row for which i need to call moveprev().
modified 12-Aug-18 7:35am.
|
|
|
|
|
This was not really clear from your question. To know what happens you should at least show some example lines. Note also that the behaviour depends on the used cursor type.
A common method to identify rows that has been inserted is using bookmarks which can be used later to select the row.
Maybe you should also rethink your design because inserting a row and deleting it within the same session makes no sense. Your code should detect that in advance so that there is no need to insert that row at all.
|
|
|
|
|
That was just an example i have given but not the exact requirement. But at any cost i want to perform this MovePrev() operation once at the end for my project requirement. But some how its failing (returning error code) even after setting the property on CBPropSet.
CDBPropSet cdbPropset(DBPROPSET_ROWSET);
cdbPropset.AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
CCommand <CAccessor<CLabelsAccessor>,CRowset> cCommand;
hr = cCommand.Open(m_Session, csSQLQuery, &cdbPropset);
if( SUCCEEDED( hr ) )
{
hr = cCommand.MoveFirst();
for(int i = 0; i < 3; i++)
{
cCommand.m_labelvalueindex = 1;
cCommand.m_labellinenumber = 2;
hr = cCommand.Insert();
hr = cCommand.MoveNext();
}
cCommand.Close();
}
After the for loop i just want to perform Moveprev(). Can you tell me any wrong in above code.?
|
|
|
|
|
As already noted: Use bookmarks (see Using Bookmarks[^]).
Set the bookmark when at the position you want to access later where you can then use MoveToBookmark() .
|
|
|
|
|
Since my command class is CRowSet, there is no SetBookMark() method on it.
|
|
|
|
|
It is a CAccessor member.
|
|
|
|
|
Small correction in my question. The error code is -2147217837.
|
|
|
|
|
Sampath579 wrote: Can you tell me any wrong in above code.? Is there a need to call MoveNext() ? The for() loop is just inserting 3 rows, correct?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
If I don't call the movenext then pointer will be at one row and the data may overwrite.
In my requirement I want to moveprev one step and delete it.
|
|
|
|
|
Sampath579 wrote: If I don't call the movenext then pointer will be at one row and the data may overwrite. How have you verified this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I believe Jochen was spot on with his very first remark. The documentation of CRowset::MoveFirst | Microsoft Docs[^] clearly states that
Quote: Calls IRowset::RestartPosition to reposition the next-fetch location to the initial position (the position that was the next-fetch location when the rowset was created) and retrieves the initial row.
(emphasis mine)
In other words, your next Fetch would return the initial row at that time, no matter how many changes you made to the table in between the Move and the Fetch!
Looks like you should trust your error message and change your code accordingly.
P.S.: I just realized that it may still be considered ambiguous. However, you have to consider if (or why) the insertion of rows should affect the current Fetch position. The Insert command documentation does not indicate that it affects the Fetch position. If it would, shouldn't it say as much?
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
It does not work. Any other way of moving to previous record. MovePrev() throwing -2147217837 error code.
I definitely need to go and get the data from MovePrev().
|
|
|
|
|
My google-fu is lacking this morning.
I'm looking for a simple green/red (pass/fail) led indicator that I can "drop" in a MFC dialog ?
Any suggestion ?
(I could bake one, but feeling lazy, and it might not look as pretty)
I'd rather be phishing!
|
|
|
|
|
Maximilien wrote: I'm looking for a simple green/red (pass/fail) led indicator that I can "drop" in a MFC dialog ?
Any suggestion ?
Just create them both (green/red led indicator icons) in the image editor!
|
|
|
|
|
|
The author's code :
An array consisting of N integers is given. There are several Right Circular Rotations of range[L..R] that we perform. After performing these rotations, we need to find element at a given index.
Quote: Input : arr[] : {1, 2, 3, 4, 5}
ranges[] = { {0, 2}, {0, 3} }
index : 1
Output : 3
Explanation : After first given rotation {0, 2}
arr[] = {3, 1, 2, 4, 5}
After second rotation {0, 3}
arr[] = {4, 3, 1, 2, 5}
After all rotations we have element 3 at given
index 1.
#include <bits/stdc++.h>
using namespace std;
int findElement(int arr[], int ranges[][2],
int rotations, int index)
{
for (int i = rotations - 1; i >= 0; i--) {
int left = ranges[i][0];
int right = ranges[i][1];
if (left <= index && right >= index) {
if (index == left)
index = right;
else
index--;
}
}
return arr[index];
}
int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
int rotations = 2;
int ranges[rotations][2] = { { 0, 2 }, { 0, 3 } };
int index = 1;
cout << findElement(arr, ranges, rotations, index);
return 0;
}
Quote: and the authors logic:
Method : Efficient
We can do offline processing after saving all ranges.
Suppose, our rotate ranges are : [0..2] and [0..3]
We run through these ranges from reverse.
After range [0..3], index 0 will have the element which was on index 3.
So, we can change 0 to 3, i.e. if index = left, index will be changed to right.
After range [0..2], index 3 will remain unaffected.
So, we can make 3 cases :
If index = left, index will be changed to right.
If index is not bounds by the range, no effect of rotation.
If index is in bounds, index will have the element at index-1.
i tried buy brute fore method and it took O(n^2) time complexity. So i want to understand this logic, can someone please explain the logic.
i have edited the information given, and it concludes all the information given by the question. Below is the link to the problem.
Find element at given index after a number of rotations - GeeksforGeeks[^]
Thank you
modified 6-Aug-18 4:19am.
|
|
|
|
|
What is a "range" or a "rotate range?"
When I hear the term rotate, I envision each element in the array could move one position to the left and the element that is in position 0 now moves to the N-1 position in the array. Similarly, each element in the array could move one position to the right and the element that is in position N-1 now moves to position 0 in the array. Am I way off?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
please check the question again i have edited it and also provided with the link to the original problem
|
|
|
|
|
Please elaborate: it is not clear what you are trying to accomplish.
Note: it could be NOT necessary to actually perform the rotations, you could possibly compute the result without actually rotate the array.
|
|
|
|
|
please check again i have elaborated it and have also provided link to the original question
|
|
|
|
|
The logic is there in the code and description, maybe you need to read more of the book you are studying.
|
|
|
|