6.0.0-beta1
7/24/25

[#1439] DataTree sql is not Oracle compatible
Summary DataTree sql is not Oracle compatible
Queue Horde Base
Queue Version 3.0.3
Type Bug
State Resolved
Priority 2. Medium
Owners Horde Developers (at) , jan (at) horde (dot) org
Requester selsky (at) columbia (dot) edu
Created 02/25/2005 (7454 days ago)
Due
Updated 03/16/2005 (7435 days ago)
Assigned 03/16/2005 (7435 days ago)
Resolved 03/16/2005 (7435 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
03/16/2005 11:11:45 AM Jan Schneider Comment #22
State ⇒ Resolved
Reply to this comment
The only way to solve this issue seems to be to use a varchar2 column 
for attribute_value in horde_datatree_attributes.



I'll commit the binding changes nonetheless.
03/16/2005 09:28:28 AM Jan Schneider Comment #21 Reply to this comment
No, I tried that too as a hotfix. Integrating this cleanly into the 
query build process would be a nightmare by the way.
03/16/2005 04:21:26 AM Chuck Hagenbuch Comment #20 Reply to this comment
This bit got sort of buried in the ticket:
http://www.techonthenet.com/oracle/functions/to_clob.htm
to_clob() can convert a VARCHAR2 to a CLOB so that the datatypes match.
selsky implied that this could be a solution. That useful at all?
03/16/2005 12:37:53 AM Jan Schneider Comment #19
State ⇒ Feedback
Reply to this comment
I have the code sitting on my box to make all DataTree attribute 
queries using bindings. But this still doesn't fix the issues on 
Oracle, I get the same error message.



I'm having a hard time to find out which column is causing this error. 
I suspected the bitand() operation on the attribute_value column, but 
even wrapping the column in a to_number() function didn't fix it.



Any ideas, anyone?
03/15/2005 04:01:31 PM Jan Schneider Assigned to Jan Schneider
State ⇒ Assigned
 
03/10/2005 08:28:15 PM Chuck Hagenbuch Comment #18 Reply to this comment
by sending patches. outside of this ticket, since this is *way* off 
the original problem by now.
03/10/2005 08:26:04 PM selsky (at) columbia (dot) edu Comment #17 Reply to this comment
I didn't think you were opposed.  I just wanted to document the 
reasons for using bind variables.



I understand it will be a bunch of tricky work and I'm willing ot 
help.  Just let me know the best way to do that.
03/10/2005 08:18:26 PM Chuck Hagenbuch Comment #16 Reply to this comment
I don't think I ever said, and certainly didn't mean to say, that I 
was opposed to using bind variables. It's certainly a good idea. It's 
just going to take a lot of work, and some planning to avoid API 
breakage in places like Horde_SQL.
03/10/2005 06:26:14 PM selsky (at) columbia (dot) edu Comment #15 Reply to this comment
Some notes from my DBA on bind variables:



i do notice one specific problem with the queries.  the application is 
submitting literal sql with hardcoded variables to the server, instead 
of using bind variables.  we have seen this cause problems in the 
past. memory allocated to parsing sql statements is being saturated 
with non-reusable code.



to show you what i mean, the following sql has hardcoded values for 
it's variables (26, 126, 1028, 11206).  this sql must be parsed by the 
server to generate an execution path, then this parsed query is 
remembered in cache for the next time it's executed.   however, the 
next time it's executed the variables change, so the server cannot 
re-use the execution path that it figured out, and must re-parse a new 
query and cache that parsed query also.



[...]



this statement is prepared once, then called repeatedly, replacing all 
the :bind_vars with different values each time.  the query text 
doesn't have any hardcoded variables so the server can reuse this 
parsed code.



[...]



we have seen significant performance improvements from taking these 
steps, and i'd encourage you to ask the vendor to make these changes.


03/07/2005 04:40:17 PM Chuck Hagenbuch Comment #14 Reply to this comment
Sorry, I meant Horde_SQL::buildClause(). The counterpart could be 
Horde_SQL::bindClause().
03/07/2005 06:58:18 AM selsky (at) columbia (dot) edu Comment #13 Reply to this comment
Where is buildTagClause() defined?  I don't see it in Horde CVS...
03/06/2005 03:54:15 AM Chuck Hagenbuch Comment #12 Reply to this comment
Some databases don't suppor them, but there's emulation for that in 
DB. Mostly our code was written before that emulation existed, and no 
one ever did a whole rewrite for it.



An alternate solution is perhaps a bindTagClause() method (like 
buildTagClause()), that takes an additional list of parameters by 
reference, and adds $lhs and/or $rhs to it as many times as necessary.
03/05/2005 07:29:05 AM selsky (at) columbia (dot) edu Comment #11 Reply to this comment
That's what I'm saying.  :-)



Are there a reason we don't use bind parameters in general?  Do some 
databases not support it?
03/05/2005 05:04:18 AM Chuck Hagenbuch Comment #10 Reply to this comment
If you're saying that that way you can avoid having to use bind 
parameters, then yes, that helps, and I think that way makes sense.
03/05/2005 04:40:14 AM selsky (at) columbia (dot) edu Comment #9 Reply to this comment
http://www.techonthenet.com/oracle/functions/to_clob.htm



to_clob() can convert a VARCHAR2 to a CLOB so that the datatypes match.



Does that help?
03/05/2005 04:13:33 AM Chuck Hagenbuch Comment #8 Reply to this comment
Okay, yeah, that's icky. What does to_clob() do/solve?
03/05/2005 02:08:30 AM selsky (at) columbia (dot) edu Comment #7 Reply to this comment
I'm getting a little lost in the code trying to do this without 
messing up other stuff.  For example, when buildClause() does 
something like this:



return sprintf('bitand(%s,%d) = %d', $lhs, (int)$rhs, (int)$rhs);



What is the right way to parameterize that?



return sprintf('bitand(%s,?) = ?', $lhs);



How will the caller know that it needs to pass that parameter twice?



Would it be easier to just add to_clob() around the values (for oracle 
only) to convert the strings to CLOBs?
03/04/2005 05:16:34 PM Chuck Hagenbuch Comment #6 Reply to this comment
Add an option to return a placeholder for $value instead of putting 
$value directly into the clause.
03/04/2005 05:33:13 AM selsky (at) columbia (dot) edu Comment #5 Reply to this comment
buildAttributeQuery() calls _buildAttributeQuery() which calls 
Horde_SQL::buildClause().  That last function is called from a lot of 
places so I'm a little wary of changing the stuff that it returns.



Suggestions?
03/04/2005 12:41:26 AM Chuck Hagenbuch Comment #4 Reply to this comment
probably something like list($query, $params) = buildAttributeQuery(...)?
02/28/2005 07:53:13 PM selsky (at) columbia (dot) edu Comment #3 Reply to this comment
We need to change the following on line 973:



         $rows = $this->_db->getAssoc($query);



to



         $rows = $this->_db->getAssoc($query, false, $params);



And pass the arguments to the query in the $params array instead of 
hard-coding them in the query itself.



buildAttributeQuery() needs to be changed to pass back a query and a 
param list.  What's the best way to do that?
02/26/2005 09:14:35 PM Chuck Hagenbuch Comment #2
State ⇒ Feedback
Reply to this comment
I unfortunately don't have an Oracle instance to test with at the 
moment (despite spending a good part of the last few days attempting 
just that). Can you find a variation of the query that works? The 
error doesn't sound/look to me like it needs to be done with prepare, 
but I could be wrong.
02/25/2005 10:19:15 AM Jan Schneider Assigned to Horde DevelopersHorde Developers
State ⇒ Assigned
 
02/25/2005 08:48:14 AM selsky (at) columbia (dot) edu Comment #1
Priority ⇒ 2. Medium
State ⇒ Unconfirmed
Queue ⇒ Horde Base
Summary ⇒ DataTree sql is not Oracle compatible
Type ⇒ Bug
Reply to this comment
I'm trying to use Kronolith 2.0.2 and when I go to add a new entry, I 
get the following error in horde.log:



Feb 25 03:09:39 HORDE [error] [kronolith] DB Error: unknown error: 
SELECT c.datatree_id, c.datatree_name FROM horde_datatree c LEFT JOIN 
horde_datatree_attributes a1 ON a1.datatree_id = c.datatree_id WHERE 
c.group_uid = 'horde.shares.kronolith' AND ((a1.attribute_name = 
'owner' AND a1.attribute_value = 'user@localhost') OR 
(a1.attribute_name = 'perm_users' AND a1.attribute_key = 
'user@localhost' AND bitand(a1.attribute_value,2) = 2) OR 
(a1.attribute_name = 'perm_creator' AND bitand(a1.attribute_value,2) = 
2) OR (a1.attribute_name = 'perm_default' AND 
bitand(a1.attribute_value,2) = 2))   GROUP BY c.datatree_id, 
c.datatree_name, c.datatree_order ORDER BY c.datatree_order, 
c.datatree_name, c.datatree_id [nativecode=ORA-00932: inconsistent 
datatypes: expected - got CLOB] [on line 975 of 
"/etc/httpd/htdocs/horde/lib/Horde/DataTree/sql.php"]



This sounds like a variation of http://bugs.horde.org/ticket/?id=443

Saved Queries