I want to check if item has particular column in database. I'm using Parse Dashboard and value in this column is type String and there is not empty string but (undefined). And this is returning null value. So I want to check if actual column does exist.
So I've used ParseObject.containsKey("column_name"), but this is returning false. I know, that value in this column is empty/null, but I want to check not value, but if that column actually exist before I can put something there.
According to documentation, this function should do exactly what I want, but it obviously doesnt work.
I've checked objectId of this item and I've checked this item in database and object with this exact id is in Class table which contains column with exact name.
Documentation:
https://parseplatform.org/Parse-SDK-dotNET/api/html/M_Parse_ParseObject_ContainsKey.htm
The containsKey method on a ParseObject will tell you only if a value has been set for that instance, not if the class can accept that property. What you want to do is inspect the Schema.
Operations on the schema (including reading) require the master key, so it is not appropriate for a client SDK like Android to access the schema directly.
I don't know your use case, as it seems unlikely that your clients would need to know this, but if you wanted a client to know the answer, you'd have to set up a cloud function that could use the master key to inspect the schema.
Related
I would like to perform wildcard queries on a Firebase database,
and do not know whether the libraries support this. - (my guess it does not.)
I want an optimal solution where the network traffic will be as little as possible, assume the dataset is millions of records.
Dataset (using prefix wildcard):
user_id:
id_001123:
name: "java"
id_002124:
name: "objective-c"
id_003125:
name: "swift"
How would the code look like to retrieve the record id_002124 name field using a wildcard, you only have a portion of the id. eg. "%124".
The expected result would be id_002124, and the name being "objective-c"
Any mobile language example code would great.
(Objective-C/Swift/Java)
Firebase Database queries can order/filter data based on the object's keys (e.g. id_001123), their values (doesn't apply in your case), or the value of a child property (e.g. the fact that name = "java").
For each of these Firebase can match items that have a specific value you specify, items starting at a value you specify, or items ending at a value you specify.
So you can create a query matching the item named objective-c with:
ref.child("user_id").orderByChild("name").equalTo("objective-c")
Or you can create a query matching id_001124 and id_001125 with:
ref.child("user_id").orderByKey().startAt("id_001125")
Or simply getting all items starting with id_0011:
ref.child("user_id").orderByKey().startAt("id_0011")
Or you can create a query matching id_001123 and id_001124 with:
ref.child("user_id").orderByKey().endAt("id_001124")
Firebase Database cannot filter based on the end of a value. So there is no way in your current data structure to get all items whose key ends in a 4.
Please read more about Firebase Database queries here: https://firebase.google.com/docs/database/android/lists-of-data#sorting_and_filtering_data
And see some of the many previous questions about searching for FirebaseL
How to perform sql "LIKE" operation on firebase?
Firebase query - Find item with child that contains string
Firebase "like" search on string
I need to change the data type for my SQLite. I am worry that it might effect users who update the App. However, after reading the SQLite document in the following link
https://sqlite.org/datatype3.html
It would seem changing the data type when creating a table column shouldn't break the App. From what I read it seems unlike other SQL database engines, SQLite datatype is associated with the value itself and not the column data type that I initially assigned.
I was going to alter the column data type when user updates the App, but it doesn't seem necessary (nor possible without dropping and recreating table). Am I reading this correctly or am I making a mistake?
The App seems to work well when I test updating, but I want to make sure I am not missing anything. Any feedback is appreciated.
Changing the type name in the column definition can affect the affinity.
This might change the type of some values (for example, attempting to store the string '123' in an INTEGER column will result in the number 123), and might change how comparisons work (WHERE SomeColumn = ? will try to convert the value to the same type as the column's affinity).
So you should change the type name only if you are sure that your app handles the values in this column correctly.
I'm trying to write to a database, in my spec I had to ensure that there are no duplicates for a specific field. Great! I can just make the column unique.
But I have no idea how to deal with that after. If I use the application and accidentally insert a new value which happens to already exist, the app will just crash. How do I check that the value already exists before I try to update the database?
I feel like an if command would work, Buuuuut, How do you scan every value for that column on android anyway?
I assume you propose that we can read all rows in a table, and for each row, check whether the value already exists. If not exist, insert, else, handle conflict.
Another way of doing it is using insertWithOnConflict() method. You can set various conflict resolution strategy such as:
CONFLICT_ABORT
CONFLICT_FAIL
CONFLICT_IGNORE
CONFLICT_NONE
CONFLICT_REPLACE
CONFLICT_ROLLBACK
I don't have any idea on the complexity of this method, but probably it is much better than reading all rows manually and check manually.
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insertWithOnConflict(java.lang.String,%20java.lang.String,%20android.content.ContentValues,%20int)
I have been struggling with the update of only 1 row in an SQlite databasetable.
Although I provided the _id value of the row that I wanted to update in the ContentUris.withAppendedId Uri, I still have to check in the 'WHERE'-part of the update statement whether the id of the record is the same.
When I leave the 'WHERE'-part of the update statement to 'null', the update statement tries to update ALL rows of the table instead of only the row with the id that was provided.
URIs define a resource. They do not define what operations can be made on that resource.
With regards to a ContentProvider (since you've included that in the tags for your question), you need to consider that the app with the ContentProvider and the app that wishes to access or modify its data may not be the same app. If you are implementing a ContentProvider, you would need to recognize URI of the kind you mentioned and adjust the WHERE clause accordingly, assuming you support that operation on that resource.
The other use for this is with insert operations, where the typical thing to return is a URI for the item that was just inserted. E.g. a successful insert on the URI content://authority/directory would return something like content://authority/directory/_id, where _id is the ID of the newly inserted row.
So my fundamentals of creating and manipulating databases are a bit messed up. My aim here is that whenever the app is launched, the user is allowed to specify a table name, and whatever data is then collected is put into that table.
However, I'm confused as to how to do this. Do I simply pass the value of a user entered variable as the table name in my contentprovider class and execute sqlite statements to create it?
I've read/reading the documentation already, so if anyone has any insight or clarity, or even better, code snippets, it would be great.
Why not simply use one table, and create a value that stands for the current app-session, and insert that value with each row. This would make your code simpler, and would still allow you to segregate/filter out the values from a particular app-session. If you want to give the user the ability to enter the value (as you are giving them the ability to choose the table name) you'd just want to check to see if that value had already been used, just as you would have to see if the table-name had already been used.