[aur-dev] [PATCH] Fix DB.class.php to match config
In commit baf8a220, conf/config.proto was changed so that dsn_prefix
was changed to backend and this fixes this in web/lib/DB.class.php.
Signed-off-by: Mark Weiman
On Wed, 09 Nov 2016 at 04:23:22, Mark Weiman wrote:
In commit baf8a220, conf/config.proto was changed so that dsn_prefix was changed to backend and this fixes this in web/lib/DB.class.php.
Signed-off-by: Mark Weiman
--- web/lib/DB.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Good catch. The dsn_prefix parameter was indeed replaced by the backend parameter in commit baf8a22 (git-interface: Support SQLite as database backend, 2016-08-03). However, it is more than a simple rename. The new parameter allows for using SQLite instead of MySQL and I doubt that this actually works after your patch; especially since host, socket, user and password can be unset if SQLite is used. So instead of pretending that the variable was renamed, we should either add SQLite support to DB.class.php or simply check whether backend is something other than "mysql" and bail out. Since the main reason for adding SQLite was making the test suite simpler and faster, I am fine with the second option. Opinions?
diff --git a/web/lib/DB.class.php b/web/lib/DB.class.php index b538e0d..f6fd7ad 100644 --- a/web/lib/DB.class.php +++ b/web/lib/DB.class.php @@ -17,14 +17,14 @@ class DB { public static function connect() { if (self::$dbh === null) { try { - $dsn_prefix = config_get('database', 'dsn_prefix'); + $backend = config_get('database', 'backend'); $host = config_get('database', 'host'); $socket = config_get('database', 'socket'); $name = config_get('database', 'name'); $user = config_get('database', 'user'); $password = config_get('database', 'password');
- $dsn = $dsn_prefix . + $dsn = $backend . ':host=' . $host . ';unix_socket=' . $socket . ';dbname=' . $name; -- 2.10.2
On Wed, 2016-11-09 at 19:56 +0100, Lukas Fleischer wrote:
Good catch. The dsn_prefix parameter was indeed replaced by the backend parameter in commit baf8a22 (git-interface: Support SQLite as database backend, 2016-08-03). However, it is more than a simple rename. The new parameter allows for using SQLite instead of MySQL and I doubt that this actually works after your patch; especially since host, socket, user and password can be unset if SQLite is used.
So instead of pretending that the variable was renamed, we should either add SQLite support to DB.class.php or simply check whether backend is something other than "mysql" and bail out. Since the main reason for adding SQLite was making the test suite simpler and faster, I am fine with the second option. Opinions?
Adding support to DB.class.php to work with sqlite shouldn't be too difficult to implement. The only thing that would need to be decided is where in the config should the location of the database be. Perhaps if backend is set to sqlite, have it look for a location setting and ignore the rest? Having this support sqlite would be very convenient as it means when working on the aurweb web interface, I wouldn't need to start a mysql service and could take the sqlite file around with me to make setting up a new instance easier.
On Wed, 09 Nov 2016 at 20:32:18, Mark Weiman wrote:
Adding support to DB.class.php to work with sqlite shouldn't be too difficult to implement. The only thing that would need to be decided is where in the config should the location of the database be. Perhaps if backend is set to sqlite, have it look for a location setting and ignore the rest?
It should be consistent with the way it is implemented in aurweb/db.py, i.e. only the name parameter should matter if backend is "sqlite".
Having this support sqlite would be very convenient as it means when working on the aurweb web interface, I wouldn't need to start a mysql service and could take the sqlite file around with me to make setting up a new instance easier.
Sounds good to me. Thanks for working on this!
UNIX_TIMESTAMP is not part of the SQL standard. Instead, all usage in
the web interface is changed to use PHP's time() function.
Signed-off-by: Mark Weiman
In commit baf8a22 (git-interface: Support SQLite as database backend,
2016-08-03), conf/config.proto was changed so that dsn_prefix was
changed to backend and this fixes this in web/lib/DB.class.php.
Since SQLite's dsn is different, this adds a check of which backend is
desired and will quit if MySQL or SQLite are not the backend selected.
SQLite2 may be supported, but is untested and will trigger an error if
used.
Signed-off-by: Mark Weiman
On Thu, 10 Nov 2016 at 00:54:38, Mark Weiman wrote:
In commit baf8a22 (git-interface: Support SQLite as database backend, 2016-08-03), conf/config.proto was changed so that dsn_prefix was changed to backend and this fixes this in web/lib/DB.class.php.
Since SQLite's dsn is different, this adds a check of which backend is desired and will quit if MySQL or SQLite are not the backend selected. SQLite2 may be supported, but is untested and will trigger an error if used.
Signed-off-by: Mark Weiman
--- web/lib/DB.class.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) [...]
Great! I merged this one, as well as the preparatory patch and the quote fix into pu!
participants (2)
-
Lukas Fleischer
-
Mark Weiman