Summary | SQL Error in listBookmarks () When $sortby empty |
Queue | Trean |
Queue Version | 1.0.3 |
Type | Bug |
State | Not A Bug |
Priority | 1. Low |
Owners | |
Requester | adorman (at) ironicdesign (dot) com |
Created | 10/03/2013 (4294 days ago) |
Due | |
Updated | 10/14/2013 (4283 days ago) |
Assigned | |
Resolved | 10/14/2013 (4283 days ago) |
Github Issue Link | |
Github Pull Request | |
Milestone | |
Patch | No |
I watched the logs for anything mentioning "prefs" and saw this logged
when I logged out and back in.
2013-10-14T11:34:15.170087-05:00 yorick HORDE: [trean] SQL (0.0003s)
#012#011SELECT pref_name, pref_value FROM horde_prefs WHERE pref_uid=#012#011 'andydorman@comehome.net' AND pref_scope = 'trean' [pid
19288 on line 558 of "/usr/share/php/Horde/Db/Adapter/Base.php"]
So Horde is definitely looking in the db for trean preferences, but
since I can not find anywhere to edit trean prefs in neither the Admin
config nor my individual config screens, these prefs are empty.
So it looks like it comes back to the problem reading
/etc/horde/trean/prefs.php. I did not see anything in the logs that
hinted at what is causing that problem.
Any thoughts about what to look for would be welcome.
Andy Dorman
why is the /etc/horde/trean/prefs.php not apparently having any
effect?
sort of distribution package. That file isn't anything that Horde
natively knows of, so you need to check with your distro.
is the /etc/horde/trean/prefs.php not apparently having any effect?
I removed my temporary code fix and the SQL error is back. That, and
the fact that there are no prefs available for Bookmarks/trean in the
Admin Config or Preferences web page, even though they are NOT locked
in prefs.php, seems to indicate that trean's prefs.php is not being
read.
I checked the horde logs and PHP and do not see any indication in the
logs of a problem with reading trean/prefs.php. I also checked the
admin config screen and it indicates Bookmarks (Trean) 1.0.3 is
installed, but there are no prefs to be configured for it. I looked a
the PostgreSQL db and I see two trean tables, trean_schema_info and
trean_bookmarks, but NO "trean" prefs in horde_prefs (ie, "SELECT *
FROM horde_prefs WHERE pref_scope = 'trean' " returns an empty list.)
So at this point I am at a loss for what to check next. Horde seems
to be quietly ignoring /etc/horde/trean/prefs.php which in turn is
causing the empty "sortby" value to be passed.
New Attachment: prefs.php
web-based admin interface and it said there were none to edit. But it
never occurred to me to check the actual prefs.php file on the server.
So I checked and the attached file is (and has been) on the
server...however, up till just now the trean directory (0755) and
files (0644) were owned by root. I have changed the owner to be the
web user.
Now I am going to remove my temporary fix and see what happens.
Priority ⇒ 1. Low
State ⇒ Not A Bug
Priority ⇒ 3. High
Type ⇒ Bug
Summary ⇒ SQL Error in listBookmarks () When $sortby empty
Queue ⇒ Trean
Milestone ⇒
Patch ⇒ No
State ⇒ Unconfirmed
5.1.4, trean 1.0.3-2. I am mainly a perl programmer, but I can find
my way around php fairly well (though I spend a LOT of time at
php.net/manual/ )
One possible fix for this bug is at the end of this report.
While testing the new release we ran into the problem below when going
to bookmarks at /trean/
Horde_Db_Exception Object
(
[details] =>
[logged] => 1
[_logLevel:protected] => 0
[message:protected] => SQLSTATE[42703]: Undefined column: 7
ERROR: column "bookmark_" does not exist
LINE 4: ORDER BY bookmark_ LIMIT 999
^
[string:Exception:private] =>
[code:protected] => 42703
[file:protected] => /usr/share/php/Horde/Db/Adapter/Base.php
[line:protected] => 555
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /usr/share/php/Horde/Db/Adapter/Pdo/Base.php
[line] => 83
[function] => execute
[class] => Horde_Db_Adapter_Base
[type] => ->
[args] => Array
(
[0] => SELECT bookmark_id, user_id,
bookmark_url, bookmark_title, bookmark_description, bookmark_clicks,
bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE user_id = ?
ORDER BY bookmark_ LIMIT 999
[1] => Array
(
[0] => 1
)
[2] =>
)
)
[1] => Array
(
[file] => /usr/share/horde/trean/lib/Bookmarks.php
[line] => 63
[function] => selectAll
[class] => Horde_Db_Adapter_Pdo_Base
[type] => ->
[args] => Array
(
[0] => SELECT bookmark_id, user_id,
bookmark_url, bookmark_title, bookmark_description, bookmark_clicks,
bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE user_id = ?
ORDER BY bookmark_ LIMIT 999
[1] => Array
(
[0] => 1
)
)
)
[2] => Array
(
[file] => /usr/share/horde/trean/lib/View/BookmarkList.php
[line] => 148
[function] => listBookmarks
[class] => Trean_Bookmarks
[type] => ->
[args] => Array
(
[0] =>
[1] =>
[2] => 0
[3] => 999
)
)
[3] => Array
(
[file] => /usr/share/horde/trean/lib/View/BookmarkList.php
[line] => 109
[function] => _getBookmarks
[class] => Trean_View_BookmarkList
[type] => ->
[args] => Array
(
)
)
[4] => Array
(
[file] => /usr/share/horde/trean/browse.php
[line] => 17
[function] => hasBookmarks
[class] => Trean_View_BookmarkList
[type] => ->
[args] => Array
(
)
)
[5] => Array
(
[file] => /usr/share/horde/trean/index.php
[line] => 11
[args] => Array
(
[0] => /usr/share/horde/trean/browse.php
)
[function] => require
)
)
[previous:Exception:private] => PDOException Object
(
[message:protected] => SQLSTATE[42703]: Undefined column:
7 ERROR: column "bookmark_" does not exist
LINE 4: ORDER BY bookmark_ LIMIT 999
^
[string:Exception:private] =>
[code:protected] => 42703
[file:protected] => /usr/share/php/Horde/Db/Adapter/Base.php
[line:protected] => 551
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /usr/share/php/Horde/Db/Adapter/Base.php
[line] => 551
[function] => query
[class] => PDO
[type] => ->
[args] => Array
(
[0] => SELECT bookmark_id,
user_id, bookmark_url, bookmark_title, bookmark_description,
bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE user_id = 1
ORDER BY bookmark_ LIMIT 999
)
)
[1] => Array
(
[file] =>
/usr/share/php/Horde/Db/Adapter/Pdo/Base.php
[line] => 83
[function] => execute
[class] => Horde_Db_Adapter_Base
[type] => ->
[args] => Array
(
[0] => SELECT bookmark_id,
user_id, bookmark_url, bookmark_title, bookmark_description,
bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE user_id = ?
ORDER BY bookmark_ LIMIT 999
[1] => Array
(
[0] => 1
)
[2] =>
)
)
[2] => Array
(
[file] => /usr/share/horde/trean/lib/Bookmarks.php
[line] => 63
[function] => selectAll
[class] => Horde_Db_Adapter_Pdo_Base
[type] => ->
[args] => Array
(
[0] => SELECT bookmark_id,
user_id, bookmark_url, bookmark_title, bookmark_description,
bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE user_id = ?
ORDER BY bookmark_ LIMIT 999
[1] => Array
(
[0] => 1
)
)
)
[3] => Array
(
[file] =>
/usr/share/horde/trean/lib/View/BookmarkList.php
[line] => 148
[function] => listBookmarks
[class] => Trean_Bookmarks
[type] => ->
[args] => Array
(
[0] =>
[1] =>
[2] => 0
[3] => 999
)
)
[4] => Array
(
[file] =>
/usr/share/horde/trean/lib/View/BookmarkList.php
[line] => 109
[function] => _getBookmarks
[class] => Trean_View_BookmarkList
[type] => ->
[args] => Array
(
)
)
[5] => Array
(
[file] => /usr/share/horde/trean/browse.php
[line] => 17
[function] => hasBookmarks
[class] => Trean_View_BookmarkList
[type] => ->
[args] => Array
(
)
)
[6] => Array
(
[file] => /usr/share/horde/trean/index.php
[line] => 11
[args] => Array
(
[0] => /usr/share/horde/trean/browse.php
)
[function] => require
)
)
[previous:Exception:private] =>
[errorInfo] => Array
(
[0] => 42703
[1] => 7
[2] => ERROR: column "bookmark_" does not exist
LINE 4: ORDER BY bookmark_ LIMIT 999
^
)
)
)
I looked at the problem code below and was very surprised that
apparently the default value for $sortby in the function call is not
being applied.
public function listBookmarks($sortby = 'title', $sortdir = 0,
$from = 0, $count = 0)
{
$values = array($this->_userId);
$sql = 'SELECT bookmark_id, user_id, bookmark_url,
bookmark_title, bookmark_description, bookmark_clicks,
bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE user_id = ?
ORDER BY bookmark_' . $sortby . ($sortdir ? ' DESC' : '');
So it appears that if you call listBookmarks with an null value for
sortby as shown in this Array, PHP considers that empty value to be
valid and tries to use it?
(
[0] =>
[1] =>
[2] => 0
[3] => 999
)
public function listBookmarks($sortby = 'title', $sortdir = 0,
$from = 0, $count = 0)
{
$values = array($this->_userId);
$sql = 'SELECT bookmark_id, user_id, bookmark_url,
bookmark_title, bookmark_description, bookmark_clicks,
bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE user_id = ?
ORDER BY bookmark_' . ($sortby ? $sortby : 'title') .
($sortdir ? ' DESC' : '');
$sql = $GLOBALS['trean_db']->addLimitOffset($sql,
array('limit' => $count, 'offset' => $from));
It still seems silly to me that PHP apparently considers the empty
string or whatever is being passed for $sortby to be a valid value and
does not invoke the default for it.