<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet href="https://dev.horde.org/themes/horde//default/feed-rss.xsl" type="text/xsl"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
 <channel> 
  <title>SQL Error in listBookmarks () When $sortby empty</title> 
  <pubDate>Fri, 10 Apr 2026 19:46:43 +0000</pubDate> 
  <link>https://bugs.horde.org/ticket/12733</link> 
  <atom:link rel="self" type="application/rss+xml" title="SQL Error in listBookmarks () When $sortby empty" href="https://bugs.horde.org/ticket/12733/rss" /> 
  <description>SQL Error in listBookmarks () When $sortby empty</description> 
 
   
   
  <item> 
   <title>We have a debian install with php 5.5.3 and we just updated </title> 
   <description>We have a debian install with php 5.5.3 and we just updated to Horde 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] =&gt;
    [logged] =&gt; 1
    [_logLevel:protected] =&gt; 0
    [message:protected] =&gt; SQLSTATE[42703]: Undefined column: 7 ERROR:  column &quot;bookmark_&quot; does not exist
LINE 4:                 ORDER BY bookmark_ LIMIT 999
                                 ^
    [string:Exception:private] =&gt;
    [code:protected] =&gt; 42703
    [file:protected] =&gt; /usr/share/php/Horde/Db/Adapter/Base.php
    [line:protected] =&gt; 555
    [trace:Exception:private] =&gt; Array
        (
            [0] =&gt; Array
                (
                    [file] =&gt; /usr/share/php/Horde/Db/Adapter/Pdo/Base.php
                    [line] =&gt; 83
                    [function] =&gt; execute
                    [class] =&gt; Horde_Db_Adapter_Base
                    [type] =&gt; -&gt;
                    [args] =&gt; Array
                        (
                            [0] =&gt; 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] =&gt; Array
                                (
                                    [0] =&gt; 1
                                )
                            [2] =&gt;
                        )
                )
            [1] =&gt; Array
                (
                    [file] =&gt; /usr/share/horde/trean/lib/Bookmarks.php
                    [line] =&gt; 63
                    [function] =&gt; selectAll
                    [class] =&gt; Horde_Db_Adapter_Pdo_Base
                    [type] =&gt; -&gt;
                    [args] =&gt; Array
                        (
                            [0] =&gt; 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] =&gt; Array
                                (
                                    [0] =&gt; 1
                                )
                        )
                )
            [2] =&gt; Array
                (
                    [file] =&gt; /usr/share/horde/trean/lib/View/BookmarkList.php
                    [line] =&gt; 148
                    [function] =&gt; listBookmarks
                    [class] =&gt; Trean_Bookmarks
                    [type] =&gt; -&gt;
                    [args] =&gt; Array
                        (
                            [0] =&gt;
                            [1] =&gt;
                            [2] =&gt; 0
                            [3] =&gt; 999
                        )
                )
            [3] =&gt; Array
                (
                    [file] =&gt; /usr/share/horde/trean/lib/View/BookmarkList.php
                    [line] =&gt; 109
                    [function] =&gt; _getBookmarks
                    [class] =&gt; Trean_View_BookmarkList
                    [type] =&gt; -&gt;
                    [args] =&gt; Array
                        (
                        )
                )
            [4] =&gt; Array
                (
                    [file] =&gt; /usr/share/horde/trean/browse.php
                    [line] =&gt; 17
                    [function] =&gt; hasBookmarks
                    [class] =&gt; Trean_View_BookmarkList
                    [type] =&gt; -&gt;
                    [args] =&gt; Array
                        (
                        )
                )
            [5] =&gt; Array
                (
                    [file] =&gt; /usr/share/horde/trean/index.php
                    [line] =&gt; 11
                    [args] =&gt; Array
                        (
                            [0] =&gt; /usr/share/horde/trean/browse.php
                        )
                    [function] =&gt; require
                )
        )
    [previous:Exception:private] =&gt; PDOException Object
        (
            [message:protected] =&gt; SQLSTATE[42703]: Undefined column: 7 ERROR:  column &quot;bookmark_&quot; does not exist
LINE 4:                 ORDER BY bookmark_ LIMIT 999
                                 ^
            [string:Exception:private] =&gt;
            [code:protected] =&gt; 42703
            [file:protected] =&gt; /usr/share/php/Horde/Db/Adapter/Base.php
            [line:protected] =&gt; 551
            [trace:Exception:private] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [file] =&gt; /usr/share/php/Horde/Db/Adapter/Base.php
                            [line] =&gt; 551
                            [function] =&gt; query
                            [class] =&gt; PDO
                            [type] =&gt; -&gt;
                            [args] =&gt; Array
                                (
                                    [0] =&gt; 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] =&gt; Array
                        (
                            [file] =&gt; /usr/share/php/Horde/Db/Adapter/Pdo/Base.php
                            [line] =&gt; 83
                            [function] =&gt; execute
                            [class] =&gt; Horde_Db_Adapter_Base
                            [type] =&gt; -&gt;
                            [args] =&gt; Array
                                (
                                    [0] =&gt; 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] =&gt; Array
                                        (
                                            [0] =&gt; 1
                                        )
                                    [2] =&gt;
                                )
                        )
                    [2] =&gt; Array
                        (
                            [file] =&gt; /usr/share/horde/trean/lib/Bookmarks.php
                            [line] =&gt; 63
                            [function] =&gt; selectAll
                            [class] =&gt; Horde_Db_Adapter_Pdo_Base
                            [type] =&gt; -&gt;
                            [args] =&gt; Array
                                (
                                    [0] =&gt; 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] =&gt; Array
                                        (
                                            [0] =&gt; 1
                                        )
                                )
                        )
                    [3] =&gt; Array
                        (
                            [file] =&gt; /usr/share/horde/trean/lib/View/BookmarkList.php
                            [line] =&gt; 148
                            [function] =&gt; listBookmarks
                            [class] =&gt; Trean_Bookmarks
                            [type] =&gt; -&gt;
                            [args] =&gt; Array
                                (
                                    [0] =&gt;
                                    [1] =&gt;
                                    [2] =&gt; 0
                                    [3] =&gt; 999
                                )
                        )
                    [4] =&gt; Array
                        (
                            [file] =&gt; /usr/share/horde/trean/lib/View/BookmarkList.php
                            [line] =&gt; 109
                            [function] =&gt; _getBookmarks
                            [class] =&gt; Trean_View_BookmarkList
                            [type] =&gt; -&gt;
                            [args] =&gt; Array
                                (
                                )
                        )
                    [5] =&gt; Array
                        (
                            [file] =&gt; /usr/share/horde/trean/browse.php
                            [line] =&gt; 17
                            [function] =&gt; hasBookmarks
                            [class] =&gt; Trean_View_BookmarkList
                            [type] =&gt; -&gt;
                            [args] =&gt; Array
                                (
                                )
                        )
                    [6] =&gt; Array
                        (
                            [file] =&gt; /usr/share/horde/trean/index.php
                            [line] =&gt; 11
                            [args] =&gt; Array
                                (
                                    [0] =&gt; /usr/share/horde/trean/browse.php
                                )
                            [function] =&gt; require
                        )
                )
            [previous:Exception:private] =&gt;
            [errorInfo] =&gt; Array
                (
                    [0] =&gt; 42703
                    [1] =&gt; 7
                    [2] =&gt; ERROR:  column &quot;bookmark_&quot; 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 = &#039;title&#039;, $sortdir = 0, $from = 0, $count = 0)
    {
        $values = array($this-&gt;_userId);

        $sql = &#039;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_&#039; . $sortby . ($sortdir ? &#039; DESC&#039; : &#039;&#039;);

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?

&gt;&gt;                             [args] =&gt; Array
&gt;&gt;                                 (
&gt;&gt;                                     [0] =&gt;
&gt;&gt;                                     [1] =&gt;
&gt;&gt;                                     [2] =&gt; 0
&gt;&gt;                                     [3] =&gt; 999
&gt;&gt;                                 )

I have tested this fix and it is ugly, but it works fine...

     public function listBookmarks($sortby = &#039;title&#039;, $sortdir = 0, $from = 0, $count = 0)
    {
        $values = array($this-&gt;_userId);
        $sql = &#039;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_&#039; . ($sortby ? $sortby : &#039;title&#039;) . ($sortdir ? &#039; DESC&#039; : &#039;&#039;);
        $sql = $GLOBALS[&#039;trean_db&#039;]-&gt;addLimitOffset($sql, array(&#039;limit&#039; =&gt; $count, &#039;offset&#039; =&gt; $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.</description> 
   <pubDate>Thu, 03 Oct 2013 15:18:36 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/12733#t80884</link> 
  </item> 
   
  <item> 
   <title>You have a broken (read empty) &#039;sortby&#039; preference stored.</title> 
   <description>You have a broken (read empty) &#039;sortby&#039; preference stored.</description> 
   <pubDate>Mon, 14 Oct 2013 13:26:58 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/12733#t81026</link> 
  </item> 
   
  <item> 
   <title>&gt; You have a broken (read empty) &#039;sortby&#039; preference stored.</title> 
   <description>&gt; You have a broken (read empty) &#039;sortby&#039; preference stored.

That is interesting.  I had checked Bookmark preferences using the 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.
</description> 
   <pubDate>Mon, 14 Oct 2013 15:28:50 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/12733#t81043</link> 
  </item> 
   
  <item> 
   <title>&gt;&gt; You have a broken (read empty) &#039;sortby&#039; preference stored</title> 
   <description>&gt;&gt; You have a broken (read empty) &#039;sortby&#039; preference stored.
&gt;

And I am sure you are right about that...the question now becomes why 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&#039;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 &quot;trean&quot; prefs in horde_prefs (ie, &quot;SELECT * FROM horde_prefs WHERE pref_scope = &#039;trean&#039; &quot; 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 &quot;sortby&quot; value to be passed.</description> 
   <pubDate>Mon, 14 Oct 2013 16:23:29 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/12733#t81044</link> 
  </item> 
   
  <item> 
   <title>&gt;&gt;&gt; You have a broken (read empty) &#039;sortby&#039; preference store</title> 
   <description>&gt;&gt;&gt; You have a broken (read empty) &#039;sortby&#039; preference stored.
&gt;&gt;
&gt;
&gt; And I am sure you are right about that...the question now becomes why 
&gt; is the /etc/horde/trean/prefs.php not apparently having any effect?

Sounds like your are not using a pristine Horde installation, but some sort of distribution package. That file isn&#039;t anything that Horde natively knows of, so you need to check with your distro.</description> 
   <pubDate>Mon, 14 Oct 2013 16:38:23 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/12733#t81045</link> 
  </item> 
   
  <item> 
   <title>&gt; You have a broken (read empty) &#039;sortby&#039; preference stored.</title> 
   <description>&gt; You have a broken (read empty) &#039;sortby&#039; preference stored.

I discovered the logging config setting and set it to be DEBUG.  Then I watched the logs for anything mentioning &quot;prefs&quot; 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  &#039;andydorman@comehome.net&#039; AND pref_scope = &#039;trean&#039; [pid 19288 on line 558 of &quot;/usr/share/php/Horde/Db/Adapter/Base.php&quot;]

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
</description> 
   <pubDate>Mon, 14 Oct 2013 16:44:09 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/12733#t81046</link> 
  </item> 
   
  <item> 
   <title>&gt;&gt;&gt;&gt; You have a broken (read empty) &#039;sortby&#039; preference stor</title> 
   <description>&gt;&gt;&gt;&gt; You have a broken (read empty) &#039;sortby&#039; preference stored.
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt; And I am sure you are right about that...the question now becomes why
&gt;&gt; is the /etc/horde/trean/prefs.php not apparently having any effect?
&gt;
&gt; Sounds like your are not using a pristine Horde installation, but 
&gt; some sort of distribution package. That file isn&#039;t anything that 
&gt; Horde natively knows of, so you need to check with your distro.

I am using the debian install.
</description> 
   <pubDate>Mon, 14 Oct 2013 16:52:16 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/12733#t81047</link> 
  </item> 
   
   
 
 </channel> 
</rss> 
