I have requirement to add new column in default contacts table provided by android so can I do that .I just want to add a new value in that column if it is added from my application.So please tell me if it is possible .
Edit:My aim is to add data in defaults contacts table programatically so that it will also be visible when user opens default phonebook.
No. This is not possible.
Though it technically is, the end result will not be desirable:
It would need root obviously. You can't modify the data of other apps without root.
You would need to find where the actual SQLite database file is located, open that, modify it.
Would the contacts app even work after this modification? Doubtful.
Would this modification persist? Doubtful.
Why not make the association some other way? Store whatever value you have with an identifuer from the contacts database.
Related
If I something like the following:
#Relation(parentColumn = "id", entityColumn = "fk_id", entity = User.class)
private List<User> users;
This list is a model which gets updated via LiveData.
But I want to be able to update this when I detect changes to the User table. Right now, it only picks up what exists in the DB, but whenever an update happens to the user table, this list does not get updated. Any suggestions?
You have not been very specific in what you are doing or want (which database you use, who is updating the database...).
But I want to be able to update this when I detect changes to the User
table. Right now, this only picks up what exists in the DB but
whenever an update happens to the user table, this list does not get
updated. Any suggestions?
Option 1
If you are doing the update/insert/delete in the same app as the List users, then you can easily update your List in your code.
Option 2
If another app/service is updating the database, I suggest you use a trigger to update your List.
See http://www.coderconsole.com/2015/02/android-sqlite-trigger-demo.html for an example.
Detecting the change in Java is tricky, see Calling a Java method from a sqlite trigger (android) .
Here is an example where you use a ContentObserver to monitor your Sqlite database (the flat file itself) https://gist.github.com/JBirdVegas/3874450
Option 3
If another app/service is updating the database, you can use a BroadcastReceiver to pick up the changes.
Just started out with my hobby project and now I am here to get help with making the correct database design/query. I have made a simple Java program that loops trough the content of a folder. I want to save this content to a MySQL database, so I added a connector to my database in Java, created a table and the columns "file", "path" and "id, "date" in MySQL.
So now to the important/fun thing, every time I want to add the filenames to the MySQL in Java I do this (when the GUI-button is pressed I call on a method that does):
DELETE all entries with the same file path - this is to ensure that I will get new entries which is exactly the same as the content in the path.
Java-loop: INSERT the file-info into the columns id, path, filename and date when the file was added to the database.
In this way I can always ensure that the filenames that are going to be added into the database always are up to date, it doesn't matter if I rename a file or remve it, it will be up to date since the table will get it's entries deleted and new info will be written. Old info -> DELETE old info - INSERT new info -> Up-to-date.
I know this is probably not the best solution but it works, but now I am stuck on the next thing I want to do. I want to add the difference of the files in order to know which files has been added and deleted between two inserts, and here is my problem, since the entries are deleted before a new INSERT I cannot compare. How would you change the design or the solution? All ideas are welcome and since I am so fresh I would really appreciate if you could show me how the query could look like.
Do not remove all rows first. Remove only the ones that are removed (or event better, just mark them "inactive" as I suggest below). Query your DB first, to see what was there last time.
I would maintain additional column in your table called "inactive". It will be FALSE as default, and TRUE for removed files. Please keep in mind that as your file is uniquely identified by file+path+id renaming any file is indeed an operation of deleting the old one and creating the new one.
Removing things from DB is not a good idea, as you might always remove something by accident (bug in the code) and would not be able to get the data back.
Additional thing to do is adding the hash to your table. This way you will be able to check if the file was really changed. There is no need to re-add the file to the DB is it is not changed. See Getting a File's MD5 Checksum in Java for more info.
One way to achieve this is to implement auditing of your table. A common approach is to create a copy of the table where you are storing the folder contents and name that table using a convention to indicate it is storing audit information (eg. _AUD) . You then add additional columns to the AUD table, like "REV" (revision), "REV_TYPE" (inserted, deleted, modified). Whenever you insert, update or delete any rows from your main table, you insert a row into the AUD table to describe what you've done. Then you can find the operations associated with each revision by looking it up in the AUD table. A java framework that provides this feature is hibernate envers (http://hibernate.org/orm/envers/).
Let's say you have a database table name table1 with columns name and surname. Two different clients open the same view from the java application and get the data for same person at the same time.
1) First client changed the name and pressed save button to update database record.
2) Client2 still sees the old record on the screen and then pressed to save button to change the surname.
It actually overwrite the record by old name. I think to check and get the latest data before updating the database when I click button but I do not like this solution because of making a second query before update.
So how can we solve this problem by using Hibernate and without using Hibarnete. Any idea?
Of course if you do not want that something will be overridden, then you have to check the data before an update. But it will be not always a real query with a good caching strategy. You could also use a timestamp with last update to compare it easier. Another strategy would be to lock the entities when the first user will read them. But that is normally not a good design for web applications or you have to integrate a messaging service, which will all user inform for an update who actually have open that entity. But I think that is not so easy to implement and a more advanced feature.
In short, compare the timestamp of an entity and if already updated, then compare the changes and show them for the user who wanted update that entity.
I have two tables that I'm working with: KINCIDENT and ASSISTANT. The main one is KINCIDENT and the two are linked using an ID. I'm able to add a new row from the application but I want to do this using Java. I tried the following code but did not work:
MboSetRemote assistSet = MXServer.getMXServer().getMboSet("ASSISTANT",userInfo);
MboRemote newAssist = assistSet.add();
newAssist.setValue("LOCATION",x);
newAssist.setValue("INCNUM",y);
assistSet.save();
I checked to see if the row was added but it wasn't and I also didn't find any new entries in the database either. Am I missing something?
As long as your code is running, you should have seen that new record in the assistant table, but you definitely would not have seen that on the screen. To make the record appear on the screen, you have to know Maximo's "cache" system to get and edit the exact instance of the set that backs the screen, instead of just any instance (or a whole new instance like you created there).
I don't know where your Java code is (an app bean, an MBOSet, an MBO, or a field class) and I don't know what event/trigger you are hooking into (adding a new record, saving an existing record or something else), both of which are important to know. I will assume you are in an MBO class of the KINCIDENT object running in the "add()" method; meaning when a new KINCIDENT is created, you want to add a new ASSISTANT record. Running as part of that trigger should mean that you are already hooked into the screen instance of the KINCIDENT object when a user adds a new record. To make your ASSISTANT record appear in the set instance backing the screen, you need to the follow the screen's relationships from KINCIDENT to ASSISTANT. I'm assuming on the screen the ASSISTANT table is set up as a child of the KINCIDENT table using a relationship. In that case you just need to get the ASSISTANT set using that relationship. Assuming your relationship is named the same as the set ("ASSISTANT"), it would look something like this:
MboSetRemote assistSet = getMboSet("ASSISTANT");
MboRemote newAssist = assistSet.add();
newAssist.setValue("LOCATION",x);
newAssist.setValue("INCNUM",y);
This will not save your record yet (persist it to the database), but you want to keep your saves to a minimum. Let the user specify if a record should be saved or not by them hitting the "save"/disk icon in the toolbar.
In my application I have an existing SQLite database attached. On start it's copied to phone and then being used. I know how to check if this database is already copied, but I want to check if database on the phone is the same as stored in APK. Is there any way to compare them? I want to do that programmatically.
Original database is stored in assets folder.
If you have a rooted Phone then you can Watch the Details of It. but if your phone is not rooted then you are won't be able to see it.
Another thing if you have copied the Application in your Phone then it will definitely work.
So Conclusion is that If you have a Rooted Phone then you will be able to See and Compare, if possible try to compare its size or Time on which it is Installed.
If you have attach a DataBase with your APK and you successfully copied to your phone that exactly means that you have your old data base copied.So i think no need to compare.If you want to compare then compare all record in Table.
Second if you want to remember that your data base is already copied then use one flag in share preferences.Save true once copied.Then check its value
Updated
To listing all Table
select name from sqlite_master where type = 'table'
If both data base have same table then compare record of these corresponding Table