Bug 366219 - Setting up internal mysql database fails [patch]
Summary: Setting up internal mysql database fails [patch]
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Setup-Database (show other bugs)
Version: 5.0.0
Platform: Other Unspecified
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-28 20:56 UTC by Simon
Modified: 2016-07-30 05:48 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.1.0


Attachments
Patch of header file after refactor (2.00 KB, patch)
2016-07-28 21:03 UTC, Simon
Details
Patch of cpp file after refactor (37.81 KB, patch)
2016-07-28 21:04 UTC, Simon
Details
databaseserver.patch (39.72 KB, patch)
2016-07-29 18:59 UTC, Maik Qualmann
Details
minor patch on top of maiks commits (3.61 KB, patch)
2016-07-29 23:22 UTC, Simon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon 2016-07-28 20:56:00 UTC
Details

While trying to setup digiKam with internal mysql database from scratch (no migration), I got the following error:
    digikam.databaseserver: Database initializer:  "mysql_install_db" ("--datadir=/home/simon/Programme/AppDaten/digikam5/.mysql.digikam/db_data")
    digikam.databaseserver: "WARNING: Could not write to config file /usr/my.cnf: Permission denied\n\nFATAL ERROR: Could not chown directory /home/simon/Programme/AppDaten/digikam5/.mysql.digikam/db_data\n"
    digikam.databaseserver: "Could not start database initializer.\nExecutable: mysql_install_db\nArguments: --datadir=/home/simon/Programme/AppDaten/digikam5/.mysql.digikam/db_data\nProcess error: Unknown error"
    digikam.databaseserver: Cannot start internal database server

I investigated the error in databaseserver.cpp/h. I found the error in the arguments to mysql_install_db which missed a "--defaults-file" argument. However new error turned up after. The error/debug messages were not conclusive and the consistet more or less of one very long function riddled with return statements. So I refactored databaseserver.cpp.

I am no c++ dev, so I did quite a bit of learning while writing the code. Therefore the result is certainly not perfect. But it runs without error, gives more information on errors and is in my opinion generally cleaner and more readable.

I will attach patches, but the one for the cpp file is more or less useless, as almost everything is marked as change due to the restructuring.

More detailed information can be derived from my github repository, i.e. the commit messages in the tree intdb_init-redone (https://github.com/imsodin/digiKam/commits/intdb_init-redone). Most of the changes happened in "Split startMYSQLDatabaseProcess into smaller functions". The branch is still compatible with master (at the time of writing), I will try to keep an up-to-date version with master in the branch "intdb_init-redone-current".
Please test it and I hope you have time to look over the code as well. Any feedback is appreciated.


Reproducible: Always

Steps to Reproduce:
1. Start digiKam from scratch (no digikamrc, no database, no configs)
2. choose internal mysql database

Actual Results:  
fails to initialise database (see error in Details)

Expected Results:  
Initialise new database (which works with the patch)
Comment 1 Simon 2016-07-28 21:03:02 UTC
Created attachment 100358 [details]
Patch of header file after refactor
Comment 2 Simon 2016-07-28 21:04:09 UTC
Created attachment 100359 [details]
Patch of cpp file after refactor
Comment 3 caulier.gilles 2016-07-28 21:31:19 UTC
Maik,

Sound like this chnages your last patches in internal server before the 5.0.0 release... Right ?

Gilles
Comment 4 Maik Qualmann 2016-07-29 05:59:53 UTC
Yes, I test the patch tonight and check under Windows.

Maik
Comment 5 Maik Qualmann 2016-07-29 06:12:13 UTC
Simon,

I think the problem was that --defaults-file is unknown under Windows with mysql_install_db.exe from MariaDB. I check it tonight.

Maik
Comment 6 Maik Qualmann 2016-07-29 18:59:45 UTC
Created attachment 100378 [details]
databaseserver.patch

This patch is for commit. Changes:
- fix missing i18n
- fix QString compile error
- remove struct databaseDirs
- fix MySQL init command under Windows
- code polishes

Maik
Comment 7 Maik Qualmann 2016-07-29 19:07:40 UTC
Git commit 5cbda9fcc0d7a6c0c83b1538866e064325270302 by Maik Qualmann.
Committed on 29/07/2016 at 19:02.
Pushed by mqualmann into branch 'master'.

apply patch #100378 from Simon to refactor internal database server code and fix database initializing
FIXED-IN: 5.1.0

M  +2    -1    NEWS
M  +394  -331  libs/database/server/databaseserver.cpp
M  +39   -8    libs/database/server/databaseserver.h

http://commits.kde.org/digikam/5cbda9fcc0d7a6c0c83b1538866e064325270302
Comment 8 Maik Qualmann 2016-07-29 19:10:42 UTC
We also use again ".mysql.digikam" as DB directory. A hidden directory is better if it is in the album root.

Maik
Comment 9 Simon 2016-07-29 23:22:37 UTC
Created attachment 100382 [details]
minor patch on top of maiks commits

Thanks Maik for going over it and improve it. I have some minor points to add (additional.patch):
 - Aren't the i18n calls in the arguments to processErrorLog redundant as this argument is later on passed to i18n again?
- One minor improvement over my own patch: In createMysqlFiles only create initCmdArgs if really necessary.

The following questions are purely out of curiosity/my education, so feel free to ignore it, but I would appreciate a short answer:
- You removed my struct workaround to make the private variables const. Obviously this is because my workaround was ugly and cumbersome. Is there a better way to make them const or is this in any case a useless thing to do?
- Why is the msg argument to processErrorLog declared as a reference?
Comment 10 Maik Qualmann 2016-07-30 05:37:10 UTC
The i18n() call is required, otherwise the message would not be translated.

For example:
i18n("my Text %1", msg);

The translator can only translate the text "my Text %1", the argument is not visible for the translator.

Perhaps this link to reference :
http://stackoverflow.com/questions/2104328/whats-the-best-way-to-send-qstrings-in-a-function-call
Comment 11 Maik Qualmann 2016-07-30 05:42:29 UTC
Git commit 28d594c6537d086c06cc737c26a9512e5d394835 by Maik Qualmann.
Committed on 30/07/2016 at 05:41.
Pushed by mqualmann into branch 'master'.

create initCmdArgs if really necessary

M  +8    -8    libs/database/server/databaseserver.cpp

http://commits.kde.org/digikam/28d594c6537d086c06cc737c26a9512e5d394835
Comment 12 Maik Qualmann 2016-07-30 05:48:47 UTC
Git commit f88ef9d28b55750bed458d0c3308a9d761d62b65 by Maik Qualmann.
Committed on 30/07/2016 at 05:47.
Pushed by mqualmann into branch 'master'.

add debug

M  +1    -0    libs/database/server/databaseserver.cpp

http://commits.kde.org/digikam/f88ef9d28b55750bed458d0c3308a9d761d62b65