sqlite step back - iphone

I found that the common way for scrolling forward through a result set is using sqlite3_step():
while (sqlite3_step(statement) == SQLITE_ROW) {
// do something with the row
}
Is there a way to scroll backwards the result set, like going one step back or accessing a previous row using its ROWID?
Somewhere I have read that you can retrieve each record of the result set by its ROWID, but I can't figure out how.
If there is no such way for retrieving arbitrary rows in the result set, I will like to know whether it would be a bad practice or just a technologic limitation the reason for it.

So I was going through the functions in the sqlite3 framework since I couldn't find any documentation online and found this:
sqlite3_reset(statement)
I didn't test, but since it takes a sqlite3_stmt just like sqlite3_step() does I assume it rewinds the result set back to the beginning.

Related

How to tell if a DataRow is dirty

Additional rows appended to a DataTable are returned when the RowStateFilter is DataViewRowState.ModifiedCurrent, even if they have not been edited by the user.
And the DataTable RowChanged event fires when the DataTable is first populated by a select from the database, before any edits have taken place.
Is there any convenient way to tell if a row is actually dirty?
You can keep a copy of the original record to compare against and make the is dirty determination at the point you need to know whether it's dirty.
Check the datarow's rowstate property and if Modified compare the values in the Current and Original DataRowVersions.
See the following stack answer which includes code that may give you some pointers on how to implement this.

store selected rows on PFQueryTableViewController

I have a tableview that is of type PFQueryTableViewController and gets its value from Parse cloud. The tableview works fine but now I need to allow the user to:
Select a row
Record in a column (string array) on Parse-Users table what rows have been selected (need to record on parse that - i will use these values for other things later)
When the user comes back and opens the tableview he can see what rows have been selected last time he was in the app
I am not sure if PFQueryTableViewController has any methods ready for that. Could anyone give me some guidance?
I would prefer to use parse cause there are so much stuff out of the box. But if not, that is fine as well.
Also, code samples from similar solutions would be great. Just need to know the best approach.
The table view controller is there for display, it will tell you about selection, but it won't automatically maintain a record of selected items in the back end. You need to decide on the appropriate way to store the selections (array of pointers is better than an array of strings) and update the store and table display appropriately. There is no standard approach to this.

Code to assign an ID when button is clicked

I have designed a simple database to keep track of company contacts. Now, I am building a form to allow employees to add contacts to the database.
On the form itself, I have all the columns except the primary key (contactID) tied to a text box. I would like the contactID value to be (the total number of entered contacts + 1) when the Add button is clicked. Basically, the first contact entered will have a contactID of 1 (0 + 1 = 1). Maybe the COUNT command factors in?
So, I am looking for assistance with what code I should place in the .Click event. Perhaps it would help to know how similar FoxPro is to SQL.
Thanks
The method you recommend for assigning ContactIDs is not a good idea. If two people are using the application at the same time, they could each create a record with the same ContactID.
My recommendation is that you use VFP's AutoIncrementing Integer capability. That is, set the relevant column to be Integer (AutoInc) in the Table Designer. Then, each new row gets the next available value, but you don't have to do any work to make it happen.
There are various ways to do this. Probably the simplest is to attempt to lock the table with flock() when saving, and if successful do:
calc max id_field to lnMax
Then when inserting your new record use lnMax+1 as the id_field value. Don't forget to
unlock all
... after saving. You'll want to ensure that 'id_field' has an index tag on it, and that you handle the case where someone else might have the table locked.
You can also do it more 'automagically' with a stored procedure.

Retrieve index of selected row in j2me TableItem

I'm using org.netbeans.microedition.lcdui.TableItem for a j2me mobile application and i have trouble on retrieve index of the row "selected" by the user in a TableItem.
I know there is getSelectedCellRow() but if i don't select any row or if i select the first row the method returns always zero so i don't know in which case i'm in.
In which way have you solved ?
Thanks
Actually you need to know that the Tableitem is not a part of standard API. You can check it out here and we implement it like this, class TableItem, as you can see here, getSelectedCellRow() actually returns cursorCellX; and if you go through the implementation you can find yourself the reason for your question,why it returns zero.

Debugging Core Data managed objects with predicates

My application has the data models a little bit complicated. I need to debug a fetch request with different predicates.
Is there any fast way to see different results for different predicates? I am tired with changing only one predicate and I have to start again my navigation application with nearly 10 steps before.
An example of these predicates that I would like to see the results:
item = %#
item = %# AND quantity = %#
item = %# OR (startdate >= %# AND enddate <= %#)
etc...
As using Core Data, I can not see the database with its' values to do some SELECTs.
You can add logic in your code to change the predicate and fetch again (maybe add a temporary button to trigger this and cycle through your various predicates).
You may also be interested in viewing the data in your SQLite file. Check out this answer to How view data stored in Core Data?
I'm not sure if it is any help, but if you want to quickly see the return results, go into gcc command line and write
po <name of array with results>
so if the array is items
po items
Will give all the returned results printed nicely in the console
To view your data inside of SQLite for free, just get FireFox. Then install SQLite Manager.
Cheers.
-RoLYroLLs
http://iphone.rolyrolls.com