I have made a swift app that logs data into a sqlite file and it consists of 5 txt entry's and when someone enters data into them all and press's save, they will be saved into my sqlite file!
But this issue is when I want to retrieve data! I was following a tutorial on youtube on how to use coredata and save and retrieve inputed data into some text fields. But when he wrote the retrieve code, it only retreived the last known input! But I was wondering if there is anyway I could use only one of the textboxs info to then bring up all the rest of the info in all 5 text fields and Press Retrieve and it will bring it all up! Sort of like a password and then when correct it shows the data that was saved under that password!
Sorry this has been a bit long winded and before you ask, here is the code I used http://pastebin.com/BEq496tY
Thanks,
George Barlow
First, rename your entity from ID to something else, and the attribute id to something else. "ID" is used for so many things, you are likely to run into a problem. I will call your entity Item and the id idNumber.
Second, when saving your object, you take the stuff from the text fields and put it into the appropriate place, e.g.
item.txt1 = textField1.text
item.txt2 = textField2.text
// etc.
Similarly, when retrieving, you should populate all text fields.
textField1.text = item.txt1
textField2.text = item.txt2
// etc.
To have some kind of search functionality you would have to first find out which field is filled with data and then search for that with a predicate, like
NSPredicate(format: "txt1 = %#", textField1.txt)
To create new items you would do something like
let item = NSEntityDescription. insertNewObjectForEntityForName("Item",
inManagedObjectContext:self.managedObjectContext)
// configure item
self.managedObjectContext.save(nil)
That's all there is to it.
Related
I have a process on the beforePageLoads that executes if it is a newDocument. It grabs a profile docuemnt that contains a number of fields that I need to copy into the XPage that is being loaded. I use the following code:
var iCol:Array = pDoc.getItems()
for(var i=0; i<iCol.length; i++){
var item:NotesItem = iCol[i];
var iName:String = item.getName();
if (#Left(iName, 2) == "AC" ){
iCol[i].copyItemToDocument(doc,"");
}
item.recycle()
} // for loop
where pDoc is the profile document and doc is backend document obtained by var doc = document1.getDocument(). I can then use the copyItemTODocument method and this works real well except I need to refresh the dataSource from the backend document. I can do this from a button and do a partial refresh but that is not an option in a production situation. I have tried various refresh options (suggested in this forum) but none of them get the job done. I can copy the values from the profile document fields to a filed in the datasource but this gets really messy because of data types. I believe my refresh problem is related to updating the doc not document1 in my code. Is there a way to refresh document1 from the backend document?
Does this help ..
http://xpagesblog.com/XPagesHome.nsf/Entry.xsp?documentId=84329CA285163DDF852578CB00669143
it hints at two things whcih may be osf use :
"It appears that during the initial PageLoad events the existing data is transferred from the NotesDocument to the NotesXspDocument. Only those fields bound to the NotesXspDocument (on XPage or CC) are transferred. "
and in the comments section:
"Another way of getting data from the XspDocument to the NotesDocument without a save, is to use document1.getDocument(true) which basically re-syncs the data between the two objects.
I don't have time to experiment I'm afraid but it looks like this is along the right lines, espcially the second part.
Doug
I am trying to create a very simple CRUD App and I am unsure what's the best way to update and delete records. I am able to successfully list all records and create a new record. Now I would now like to delete these records through the app and it is not immediately clear on how I should do it.
Let's say I have a Person table with just one field Name like so:
Person
name Text
I have a handler called PersonR that lists all the persons in the table and a form to input a new one. For handling delete and update, I thought I can create a hidden field called personId and then process the form through an InputForm but I couldn't get the ID out easily. I tried unKey personId but it still has PersistInt64 1 so I am presuming this is not the right way to go about it even if I manage to fish the ID out of there.
Another approach I could take is create a new handler (say ListPersons) just to list all persons and then change the Person handler to Person/#personId. I prefer to avoid this if possible and keep all actions related to Person in one place if possible.
Could you please let me know if I am thinking about this right and any suggestions for implementing a basic CRUD App functionality?
Update: I ended up creating a PersonPanel which will handle GET and POST. The Person Handler took care of DELETE and PUT. I ended up putting the 4 Handlers in the same Person handler file so it is not scattered around. Hope this helps others.
Thanks!
How about using toPathPiece in Web.PathPieces.PathPiece class to convert a key to Text, and putting it into a hidden field?
I guess yesod uses this class to convert a key to Text when it encodes the key into a type-safe URL, and vice versa.
Even though you can convert a key to Text in this way, a preferred way would be sending a DELETE request to Person/#personId. You can generate this URL using #{...} in your hamlet template.
Using Firebug I found that the iNotes List View object has a function called "getSelectedData()" delivering something like an array of selected view entries (each one consisting of the item specific row data, like the "ext" element described here by Paul Withers). Thus, using one of List View's internal events (like "onContextMenu"), I can retrive selected data and put them somewhere else. Which is just great!
But, as I'm never content with what I have, now I'm looking for a way to address the List View's object from the outside (e.g. using a button) to access a selected data collection in a similar or even the same way. But no matter what I try, I can't seem to get to the proper object from outside of the List View itself. Using
dojo.byId("#{id:listView1}")
is giving me an object but without any of those specific methods that I need. Neither Google, nor openNtf or the ExtLib book itself has any info on that.
Any hint?
Greets,
Lothar
I guess I solved it. I've been close yesterday, but using dojo.byId instead of dijit.byId prevented it from working:
var grid = dijit.byId("#{id:listView1}");
var sel = grid.getSelectedData();
Result is a named array of row data where each row entry contains all the relevant view entry data for that row.
Works like a charm!
- Lothar
When should one use Fields from the CMS and when to use class properties and database fields?
My scenario:
Created a product content part with fields usage (text) and price (double). Then I have created a contenttype product and added the part.
I could also have created a product record in models and added a product table. And a part with driver etc.
At first glance I dont see difference besides option 2 requiring programming.
However I did encounter a problem:
In option 2 I could use repository and create a lot of items programmatically.
In option 1 I could create product content items but was not able to fill in the fields of the product part (no errors, but fields remained empty)
So when to use option 1 and when option 2?
And is my problem with option 1 related to that option?
EDIT: Clarifiation of problem with option 1
I have created a productpart. To the productpart I have added the field price which is a decimal and I have added a field Usage of product which is a text field.
In the code I have the following:
dynamic item = _cm.New("Product");
item.TitlePart.Title = "Mijn dummy product";
item.BodyPart.Text = "Some dummy text for this product";
item.ProductPart.Price.Value = new decimal(20.5);
item.ProductPart.Usage.Value = "Some dummy usage of this product";
_cm.Create(item);
After running the code, the product is created with the correct title and body text, but Usage and Price come up emtpy.
I also tried it with the item.As<> method. But that does not compile to As since I have not created an object with that name.
A difference is that fields can only be queried against with projections but more generally parts and fields are for different usage: parts are meant to be reusable, not fields. Price for example is going to be a characteristic of any product so it should probably be a part property. Usage, I don't know, it sounds fairly specific to what you're doing and may be better done as a field.
As for your problems with option 1, it's hard to say without seeing your code but chances are you're doing it wrong.
Apparently the item has to be created first before accessing the contentpart and fields. At least it worked for me.
Please verify if my analysis is correct. If so I will mark it an answer, as well as the answer of Bertrand.
The code now looks like this:
var item = _cm.New("Product");
item.As<TitlePart>().Title = "Mijn dummy product";
item.As<BodyPart>().Text = "Some dummy text for this product";
//Create first before accessing the contentparts that are dynamic.
_cm.Create(item);
//And then access the product via dynamic object.
dynamic dyn = item;
item.ProductPart.Price.Value = new decimal(20.5);
item.ProductPart.Usage.Value = "Some dummy usage of this product";
In a non-replicate scenario (or one where we have one write master only), would the following work as quick way to give a doc an auto-increment id to small internal customer datbase.
On inserting a new customer query http://couhdb/mydb to get the metadata
Then add doc_count + doc_deleted_count = autoIncId
Set a property on the doc as .oldDbCompatIdThatClientIsUsedTo = auotIncId
This would mean serialize/sync the process of getting the db metadata and writting the doc but thats not a problem given 20 customers added a day etc..
I can think of a couple of ways of doing this:
Create a view that returns max(id) and just assign max(id) + 1 to the new item (there's some chance of collision here though)
Store another document in the database that isn't a normal record but just contains the sequence value. When you want to do a new insert fetch the current value from this doc, add one, save it back to the doc and then if none of that failed use that id for the new record