Tool to log changes to a mysql database - mysql

, I'm trying to achieve the following functionality on one of the applications I'm developing.
1) Both mobile app and browser users access the same database
2) Android users store some of that data locally
Now the tricky part is that data can change and if an android user(s) have previously stored this info locally, what is stored becomes garbage.
So now here comes the question. Is there a tool that can log changes made to a mysql database, possibly into a defined table?
So that if a change is made to data that an android user has, these changes can be made to the local repo as well whenever that user logs in. I've been looking about but I haven't found a simple solution to this so far.
I've seen a few posts on here about this, but I'm hoping something simpler has been developed lately.

Related

How to properly setup a MYSQL database with JAVAFX intellij?

Ok so Im am still very new to javafx and intellij. I am working on a little project of my own right now and all I am trying to build is a simple calendar just like apple's version or google's. I figured this would be a good exercise for me to get to know the Intellij IDE better and JavaFX.
Here is the problem that I seem to be stuck with for a couple days now. In my application, a user has the ability to create a new event which contains many properties such as "event name", "first name", "last name" etc.. Now all the information is stored in a shall we call it "NewEvent" Node. Here lies the problem I am facing. I am trying to save the data locally on the clients computer however I am not sure how to begin. I have browsed around and I have found this thing called MYSQL that is supposed to do just that. I was hoping you guys could help me out here on how I should set this up.
Here is what I've done so far.
Downloaded MYSQL v5.7
Downloaded MYSQLWorkbench
Created a Database called "event" with all the properties contained in the Node
Somehow added the MYSQL database to intellij
Created a dialog where if the user clicks save, all the information is stored in a node.
To my understanding in order to access the data stored in the MYSQL table, shouldnt the "data file" be saved in my project folder? I have no clue where this is located. Also how would I gain access to database in order to edit it dynamically. Like adding a new row to the database.
I have looked up online with many different searches but they all seem to be using NetBeans and they are mostly outdated. I found it really hard to find information from start to finish. All I want to do is to store data locally and to access it. I expect to have a largely populated database, seeing as no one actually deletes an event once its over so what I was told is that MYSQL is capable of handling huge data. Hence my choice to go along with it.
I have done a little Android Application last summer so I am a little familiar with MYSQL, however I remember saving the data onto a table on the clients phone.
MySQL isn't an embedded database. Only the libmysqld is embeddable.
You can integrate JavaFx application with any database. HSQLDB or H2 would be more appropriate, since they do not need an installation on the client machine, and can be configured to save the data file on any location.

Expose "all changes since" via wordpress JSON api

I'm struggling to find a solution to what I thought would be a common requirement so I'm hoping someone can help me with some pointers on what to search for/areas to explore.
Background
I'm building an iOS mobile app. I'm storing data locally using realm.io. The app is preinstalled with a snapshot of the content of a Wordpress mySQL database (it uses custom types). The content of the WP database is only written via the Wordpress install, the mobile app cannot write data.
Objective
So, I want to be able to check for changes since a given date (whenever the local database was last updated) and send the changed records to the mobile app (via the wp JSON api?).
I think I can fetch "posts since a date" but I need a full list of all create, update and delete operations since a given date.
Since the app is read-only I thought this type of one-way sync would be pretty straight forward but I can't find a common solution.
Any ideas to point me in the right direction would be great. Obviously, if anyone has any experience of doing this sort if thing with realm.io then that would be amazing :-)
Realm doesn't support yet any sort of synchronization mechanism across different files. We have an issue about that though, but you're likely searching rather for a solution in the immediate future.
Update: Realm launched the Realm Mobile Platform. This offers synchronization functionalities and would greatly simplify the solution for this use case.
You could use e.g. the server-side Node.js binding to pull new data from your MySQL Wordpress installation and push them to a global Realm served by the Realm Object Server. This can be read-only synchronized from the mobile apps, which would automatically receive the deltas and provide updated data to your users.
Whatever mechanism you come up yourself though in the meantime, it would require that you have read-write access from your iOS application to the realm database, so that you can update it with new data.
Pushing changed records as you describe is likely not going to work.
Apple's Push Notification service (APNS), which is the only back communication channel that works when your app is in the background or suspended, allows you to send very small payloads. You would use that to signalize your iOS app, that something changed on the server-side and there is new data to load. You would then initiate a request to a JSON-based API, wait for the response, map the returned JSON to Realm objects and store them in your database.
You want probably read more in the "Downloading Content in the Background" section of background execution chapter in the official App Programming Guides for iOS.
While pre-seeding the database from the app bundle seems like a nice idea, because the user wouldn't need to wait initially after downloading the app, that will enlarge the app itself with data, which might become in the future completely irrelevant.

Connecting a MySql database to an IOS application

Basically I need to connect a MySql database to an IOS application and save a local copy to the device but i'm confused about which path I should take to do this.
Here is a basic description of the application:
The application is used to replace multiple paper based forms, allowing the user to complete a desired form on an iPad. Once the user has completed the form, the forms data is uploaded to a server.
Some forms have fields where the user is required to 'select' an option (drop down list). These options need to be pulled from a database because the options will be changed regularly.
The application still needs to work if there is no internet connection!
This means that whenever there is a connection the application needs to save a copy of the current database so that any required information to fill out forms is still available even if there is no connection.
In short my question is: What is my best option to save a local copy of a database (or just a few tables) to an IOS application?
You should look into Core Data. If you're trying to keep an updated copy of a couple tables, I would create a Core Data database that contains the information you need for your app and, every time the user uses your app, check to see if there's an internet connection. If there is, use NSURLSession to download the necessary data from the web server, after which you can compare the downloaded data to that which is in your Core Data database. If there are any discrepancies between the two, you can update your Core Data database as needed. This way you will always have a relatively up-to-date copy of your MySQL database.
This is a good tutorial for getting a feel for NSURLSession in case you haven't used it much.
Hope it helps!

How to synchronize a SQLite Core Data database with a remote MySQL database?

I recently completed work on an iOS app, and everything for the most part is working the way it should with the app. I have managed to create a multi-user app that uses Core Data to persist to a SQLite DB. However, the time has come where the users would like to manage their account from a remote device, i.e. their own phone, or whatever web enabled device their using. With that said, I have done a little google searching and have discovered that I am going to need to create a "web service". Now the caveat is that I already accumulated data in the SQLite DB on the iDevice that is running the app. I would like to push the existing data to a MySQL DB or a remote machine, and have it synchronized. For example when a user updates their account on the iOS device, the change gets pushed to the MySQL DB, and if the user connects to a web service using a standard browser that is updates the SQLite DB on the iOS device.
I started learning rails because I figured it would be a good solution to create a simple web front-end for the user to manage their account with, and it exposes an API for a developer to manipulate data in the database. Basically, I would like to hear some suggestions from the community, or links that could provide a good starting point for what I'm trying to accomplish.
If you're looking at rails, try taking a peek at ActiveAdmin gem. It's what I used on my first iOS and rails project for a client. It gives you an administrative dashboard that'll handle a lot of what you'll be wanting if you can get it set up. It's very confusing at first, but a few weeks will give you a pretty good web solution. In addition, depending on your experience in creating servers, you might want to look at heroku for a low cost host that does all the work for you (if you start needing more processors though, Heroku gets pricy very quickly). From a github project, you can have heroku up and running your rails code in about 5 minutes flat.
As far as synchronizing your database from Server To Phone: You'll want to institute a type of last_updated_at timestamp for your models on the server DB. Now when anything is updated, you'll update the timestamp. Now the iOS app can pass a ?last_updated_at parameter to your server. This will allow your server to figure out everything that has changed since the last time they pinged the server. Then gnab it into your core data db on the phone.
For Syncing Phone to Server:
First make sure the phone is up to date before syncing (using last_updated_at param). If it's clear, then this is where it's hard. You'll need to translate the objects you want to sync from the CoreData db (since it adds it's own columns/tables automatically) and pass them up. Otherwise you can pass up your coreData db and do some kind of conversion on the server.
OR
Do a conversion in your iPhone app with an update to migrate off of CoreData. This will be a pain but it'll help in the long run if you deploy to other OS's. You'll need to create sqlite3 queries to convert the CoreData db into a new SQL DB (we were able to copy 2-3MB of data within 1.2 seconds on an iPhone 5 so it's pretty quick). Then the app will only use SQLite3 so that it can sync up the full DB to the server. Then this will make syncing with the phone easier, where it can just grab the full DB from the server and plug it in.
typedef NS_ENUM(NSInteger, RecordStatus){
RecordStatusUnchanged = 0,
RecordStatusUpdated = 1,
RecordStatusAdded = 2,
RecordStatusRemoved = 3
};
Create a new SQL table named change_record. column like ( item_id, status, category_name)
For Update
change_record table: from the local database, you will get item_id, keep status RecordStatusUpdated, and set the category_name
For Add
change_record table: item_id will empty, keep status RecordStatusAdded
, set the category_name
For Deletion
change_record table: from the local database, you will get item_id, keep status RecordStatusRemoved
, set the category_name empty
Use a background service to check internet connection is available for each n time interval.
if change_record count > 0.
then send all items(using loop) to the server

How does one properly cache/update data-driven iPhone apps that use remote databases?

My app is highly data driven, and needs to be frequently updated. Currently the MySQL database is dumped to an xml file via PHP, and when the app loads it downloads this file. Then it loads all the values in to NSMutableArray's inside of a data manager class which can be accessed anywhere in the app.
Here is the issue, the XML file produced is about 400kb, and this apparently takes several minutes to download on the EDGE network, and even for some people on 3G. So basically I'm looking for options on how to correctly cache or optimize my app's download process.
My current thought is something along the lines of caching the entire XML file on to the iPhone's hard disk, and then just serving that data up as the user navigates the app, and loading the new XML file in the background. The problem with this is that the user is now always going to see the data from the previous run, also it seems wasteful to download the entire XML file every time if only one field was changed.
TLDR: My iPhone app's download of data is slow, how would one properly minimize this effect?
I've had to deal with something like this in an app I developed over the summer.
I what did to solve it was to do an initial download of all the data from the server and place that in a database on the client along with a revision number.
Then each time the user connects again it sends the revision number to the server, if the revision number is smaller than the server revision number it sends across the new data (and only the new data) from the server, if its the same then it does nothing.
It's fairly simple and it seems to work pretty well for me.
This method does have the drawback that your server has to do a little more processing than normal but it's practically nothing and is much better than wasted bandwidth.
My suggestion would be to cache the data to a SQLite database on the iPhone. When the application starts, you sync the SQLite database with your remote database...while letting the user know that you are loading incremental data in the background.
By doing that, you get the following:
Users can use the app immediately with stale data.
You're letting the user know new data is coming.
You're storing the data in a more appropriate format.
And once the most recent data is loaded...the user gets to see it.