How to download only the newer and updated entries, and avoid
downloading same entry once again?
Use a database synchronization tool like SymmetricDS or Daffodil Replicator.
You'd have a central database server, like PostgreSQL, with SymmetricDS running on it.
Each client, such as an Android smartphone, runs SQLite and SymmetricDS.
The SymmetricDS clients and server communicate with each other over HTTP(S), sending changesets back and forth.
How to provide edit entry possibility to db? Is it better to create
new table with proposal entries and after verification, move them to
main table? Or maybe should I create additional columns, which would
be proposals for new values?
I would add an is_approved
or similar column that needs to be true for items to show up to regular users. Editor and admins can see unapproved items.
What if I would get lots of changes proposals? Is it better to store
only the last one? Or maybe block edit possibility if a proposal is
already set?
Use History Tables (copy-on-write to a table similar to your main tables) to capture each change. That way you can rollback to earlier or better versions if you need to. Use Optimistic Concurrency Control to prevent updates if data changed.
How to avoid cheaters and scammers? Some bored people may want to try
make a mess, editing multiple entries with fake data. How to avoid
such kind of events? Grant edit access only to verified people?
Like this site, add "user abilities" after users have proven themselves. Block bad users. Use machine learning to filter spam.
If I would like to store images of items, is it better to store it in
db or use some kind of flicker or instagram instead?
Usually database is better, if you can cache heavily on web server, and can do incremental backup.
Is it better to save new entry in SQLite instant after edit? Or just
post it to MySQL and add it to SQLite only after verification and only
via SQLite and MySQL sync?
Saving to SQLite locally first allows for offline usage, and is probably more responsive. http://offlinefirst.org/
Is it good idea to set key value to EAN code? At least it is constant
and connected to only one product. There will be no items containing
no EAN.
No, I would use a meaningless key for product_id and a unique nullable column for EAN.
To answer the first part of the question, I did the following:
Created two tables:
CREATE TABLE master
(
m_id INTEGER,
m_value VARCHAR(4)
);
CREATE TABLE scheduled
(
key INTEGER,
s_id INTEGER,
s_value VARCHAR(4),
due TIMESTAMP
);
Added some records:
INSERT INTO master VALUES (1, 'Buy');
INSERT INTO master VALUES (2, 'Buy');
INSERT INTO scheduled VALUES (1, 1, 'Sell', '2018-01-01 12:00:00');
INSERT INTO scheduled VALUES (2, 2, 'Sell', '2018-01-01 12:00:01');
INSERT INTO scheduled VALUES (3, 1, 'Buy', '2019-01-01 12:00:00');
Then I ran the following query:
UPDATE master
SET m_value =
(
SELECT s_value
FROM scheduled s
WHERE s_id = m_id
AND due <= CURRENT_DATE
);
The result of SELECT * FROM master
after the UPDATE
:
m_id m_value
1 Sell
2 Sell
You can find all this on the dbfiddle here. Next time you ask a question, you might find it beneficial to set up a dbfiddle for those who are trying to solve your issue - help us to help you!
BTW, SQLite (unlike other systems) doesn't support UPDATE
s with JOIN
s. I'm not sure what the standard says about using these, but here is your example done using a join.
UPDATE master
SET m_value = s.s_value
FROM master m
JOIN scheduled s ON m.m_id = s.s_id
WHERE s.due <= NOW();
To answer the second part of the question, do all the work (two separate statements) in one TRANSACTION
(documentation here, example here). Unfortunately, dbfiddle doesn't appear to support this. BUT, we're in luck, this db-fiddle (note hyphen!) does support TRANSACTION
s - take a look at the complete answer to your question here. If my solution doesn't help you, please let me know.
Best Answer
You can try something like this, this is setting table1's col3 value to table2's col3 value where they match on col1 and col2. You can replace the col3 with your 'some value'.
DB Fiddle