Attempting to retrieve data from firebase database with Swift - iphone

I have a firebase database that contains a location with a name, latitude, and longitude. I want to access all these three values and create a "Cord" object that I need and put it into my array of Cords. At the moment the array stays blank as I print it.
This is the observer for the database
This is the actual database and the values

Your print statement will be running immediately here, before the database has retrieved anything. If you move that line just below the end of your for loop you should see it print the result.

Related

Cloud Firestore and Ionic

How can I get the document id of a collection present in the cloud Firestore?
I tried to get it by using the
firebase.firestore().collection("collectionName").doc().id
but I didn't get the appropriate result.
firebase.firestore().collection("societies").doc().id and it returns a id which is not equivalent to society documentId
That's correct because everytime when you are using the above line of code, you are generating a new document id which will never be the same with one that already exist in your database.
In order to use a new document id, first you need to generate it (as you already do) and then store it in a variable. Having that varaible which holds that id, you can use it to get that particular document from the database by passing this id as an argument to the doc(id) function:
firebase.firestore().collection("societies").doc(this.myId)

update One2many Record using Write function called from Onchange (Odoo10)

I am trying to update my One2many record when Onchange method is called. I am fetching the exact value but its not updating the field. Neither I am getting any error.
class abc_1(models.Model):
_name = 'abc.1'
field_a1 = fields.Many2one('crm.team',required=True)
field_a2 = fields.One2many('abc.2', 'field_b1')
#api.onchange('field_a1')
#api.depends('field_a1')
def get_records(self):
for res in self.field_a1.member_ids:
print res.name
self.write({'field_a2':(0,0,'field_b2':res.name})]})
class abc_2(models.Model):
_name = 'abc.2'
field_b1 = fields.Many2one("abc.1")
field_b2 = fields.Char(string='Sales Person')
I am trying to update records fetched but its not doing anything.
First #api.depends trigger onchange event so you don't need
#api.onchange.
Second don't update the database in onchange event because you will commit
changes to the database what if the user click on cancel button the changes
all ready saved in database.
Third if this code works your querying a lot the database, because any call to write will execute update in database. don't query the database inside a loop only if there is no other solution
Four self.write do not work in #api.onchange because the self is not the record is not the real record it's just a dummy record that holds the data passed from
the client side you can check the id you find is always NewID object even if the record is saved in database. usually you find the real record in self._origin (in new API, or list of ids in old API) in
this you can call write and change the values in database a danger thing to do.
#api.depends('field_a1')
def get_records(self):
# when you use depends, best thing you do is to loop so won't get
# singleton error
for rec in self
# create a list to hold the cammands to create the records
res_ids = []
for res in self.field_a1.member_ids:
# now just add the cammand to the list
res_ids.append((0,0,{
'field_b2':res.name,
})
# if you will affect only one element just
# but if more use rec.update() works like rec.write()
# but with onchange it don't save data in database.
rec.field_a2 = res_ids

Call a WebService if value not found in an XML result

From a MySQL query, I am trying to iterate on every rows to:
Test the existence of an object using a webservice
Then if the object doesn't exist yet, I will add it using another webservice, otherwise I do nothing.
Update in any case a MySQL DB table.
Here is what I've done so far:
First I create the connection
I get the columns I need from my MySQL query
I start iterating
I call my webservice which give me a String holding XML (column name: ResultXML)
I extract from this XML the values I need (column name: ResultExtract)
Then I want to test if one of the values extracted is equal to a specific value (let's say 10).
So from my my tExtractXMLField, I get something like :
150
10
So this would mean that I won't have called the 2nd webservice.
I can't find how to look for my value in the result (the result can also be empty and then no row would come from the tExtractXMLField).
I tried to use a tJava after the tExtractXMLField component to split my result as a List but the tJava component is running before the 1st webservice has finished so I get NULL.
Maybe there is a better way to do what I've already done, and if so, I am also pleased to receive your recommandation.

Oracle Apex page canĀ“t fetch data after navigating to another and returning

So i have a form based on one of my table, in wich the id is generated by a function in the database, the username is get from the user in session using the variable :APP_USER and the date has a default value of to_char(sysdate). But the problem is that if I open the page the first time it does work without any error, when I change pages and return to the form I get the error
ORA-01403: no data found
Error Unable to fetch row.
And I don't know why.
If you use the standard fetching process you can check to see which column it uses to fetch a unique row and the item it will use the value from to do this.
If you get the 1403 error then this probably means you are trying to perform a fetch with the value of this page item set to a value which does not exist in the database.
Are you performing a computation on this item? Run plsql code on it? Change it anywhere?
When you get this error, then you can check the session state of the item by clicking "Session" on the developer toolbar. This will show you the session state values of the items, and thus you can see the value of the PK item on which the fetch will operate. If there is an id in there, you can verify whether this value is correct or not.

restrict duplicate entry,iphone

HI All,
i am inserting , say name to sqlite, than showing it on tableview.
But i want say restrict user to insert duplicate name.
for first time data gets inserted perfectly, but when i insert it on second time, it again get inserted, thats what i want to prevent.
HOw can i check if the value 'name' already exist in sqlite and show alert to tell user that this value already exist.
edited
i have an array abc , having few values., values in array i am adding from another view, now say if abc contains value "a1", now if i again inserting "a1", it should not except "a1", in a way how i can restrict an array to add duplicate value.
regards
Use unique constraint in your SQL database. Here's a link with some basics on it. Here's some specifics on how to create table with unique contraints with SQLite.
To alert users, just capture the error message from your SQL query and then output as needed.
Edited (for new question):
Easiest way is to parse through the array and do duplicate checks. There's logic out there for faster searching but if you have a small array, then all you really need is a for loop that iterates through each array element and checks that the new value you are adding is not already there.