Bugs item #2861084, was opened at 2009-09-17 18:26
Message generated for change (Tracker Item Submitted) made by kkheller
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=462816&aid=2861084&group_id=51305
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: Subversion TRUNK
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Kelly Heller (kkheller)
Assigned to: Nobody/Anonymous (nobody)
Summary: [DatabaseLayer] type-related errors are ignored in mysql
Initial Comment:
I just submitted a diff/patch that helps clarify what I am talking about in this bug report. Please view the patch before reading this. The patch is here:
https://sourceforge.net/tracker/?func=detail&aid=2861075&group_id=51305&atid=462818
I have some fairly involved SQL queries that I use in my application. They go beyond a simple "select x from y where z = w".
I am using many functions and features of SQL, but I believe the reason that I came across what I call "silent failures" inside the code for MysqlPreparedStatementResultSet is that I am using the "IF" function and the "MAX" aggregate function.
One of my queries looks like this:
SELECT
IF ( kp.client_date > some_boundary_date1, IF ( kp.client_date < some_boundary_date2, kp.client_date , some_special_date ), some_special_date)
as result_field1,
XXXXX as result_field2,
YYYYY as result_field3
FROM
.......
I had thought that "result_field1" would be returned as a date. I thought it would be a date because all of the columns and values involved within the nested "if" clauses are all of type DATETIME.
So, it turns out that I thought wrong about that.
But when I called the function DatabaseResultSet::GetResultDate I would have expected to have at least received a warning, an assert, something.
What the code actually did inside MysqlPreparedStatementResultSet::GetResultDate was to just go ahead and cast the result buffer to a (MYSQL_TIME*). It does not seem safe to just perform this C-style cast to (MYSQL_TIME*) unequivocally, especially since it is easy to quickly verify the type of the buffer. (Refer to the patch I submitted at https://sourceforge.net/tracker/?func=detail&aid=2861075&group_id=51305&atid=462818 )
Something similar happened to a query I am using that calls the Aggregate Function MAX. I am applying MAX to a column that is of type integer, and the column is also non-nullable, so I know that the MAX function is operating purely on integer values. Therefore, I thought the returned value would be an integer, and so I called DatabaseResultSet::GetResultInt.
However, inside MysqlPreparedStatementResultSet::GetResultInt , the buffer type returned from mysql was **not** MYSQL_TYPE_LONG (or anything else that is listed in the switch statement). The buffer type is MYSQL_TYPE_NEWDECIMAL.
Because MYSQL_TYPE_NEWDECIMAL is not handled in the switch statement inside MysqlPreparedStatementResultSet::GetResultInt, the function returned 0 to me as the result of GetResultInt.
I think that it should at least throw an assert when the buffer is type MYSQL_TYPE_NEWDECIMAL. The fact that it returns 0 without indicating any error or any anomaly is very misleading. It would seem that the query simply returned 0.
I have been a heavy user of "wxWidgets Proper" for a couple years. (what I mean by "wxWidgets Proper" is to clarify that I am talking about what is on wxwidgets.org and not anything on wxcode.sourceforge.net.) A couple patches of mine have even been accepted into wxWidgets Proper.
However, I am completely new to wxCode. So far, DatabaseLayer is the first of any of the wxCode components that I have interacted with.
Perhaps wxCode developers have a different practice in regards to using wxFAIL and wxASSERT ? Maybe there is a reason why I do not see any usage of wxFAIL or wxASSERT inside DatabaseLayer? Is anything preventing your developers from enabling debug-only assertion code?
The wxWidgets book recommends using wxASSERT in Chapter 15: Memory Management, Debugging, and Error Checking.
wxWidgets Proper uses assert messages quite heavily, and I have found their assert messages to be VERY helpful ! I would love to see more assertions inside of DatabaseLayer. Is this possible?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=462816&aid=2861084&group_id=51305
|