Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with CSV export #68

Closed

Conversation

sarjona
Copy link

@sarjona sarjona commented Aug 31, 2016

Our databases are Oracle and we've detected this bug in some cases (with MySQL is working properly). We've tried to find a generic solution (in Oracle, converting TO_CHAR the qrX.response field is also working).

Tested in Moodle 3.1.1 with MySQL and Oracle databases.

@danmarsden
Copy link
Contributor

tried this patch but we still get a failure with the date fields when using postgres.

hardcoding this seems to fix it for us: (postgresql specific code though)
if ($field === 'response') {
$extraselect .= "CAST($alias AS TEXT) AS $field";
} else {

here's the error in Postgres

Debug info: ERROR: UNION types text and date cannot be matched
LINE 24: 0 AS choice_id, qrd.response AS response,...
^

SELECT qr.id || '' || 'dropdown' || '' || qrs.id AS id,
qr.submitted, qr.complete, qr.grade, qr.username, u.firstnamephonetic, u.lastnamephonetic, u.middlename, u.alternatename, u.firstname, u.lastname, u.username, u.department, u.institution, u.id as userid, qr.id AS rid, qrs.question_id,
qrs.choice_id, qro.response, 0 AS rank
FROM mdl_questionnaire_response qr
JOIN mdl_questionnaire_resp_single qrs ON qrs.response_id = qr.id

AND qr.survey_id = $1 AND qr.complete = $2
LEFT JOIN mdl_questionnaire_response_other qro ON qro.response_id = qr.id AND qro.choice_id = qrs.choice_id
LEFT JOIN mdl_user u ON u.id = CAST(qr.username AS INT)
WHERE qr.id = $3 UNION ALL
SELECT qr.id || '' || 'textbox' || '' || qrt.id AS id,
qr.submitted, qr.complete, qr.grade, qr.username, u.firstnamephonetic, u.lastnamephonetic, u.middlename, u.alternatename, u.firstname, u.lastname, u.username, u.department, u.institution, u.id as userid, qr.id AS rid, qrt.question_id,
0 AS choice_id, qrt.response AS response, 0 AS rank
FROM mdl_questionnaire_response qr
JOIN mdl_questionnaire_response_text qrt
ON qrt.response_id = qr.id

AND qr.survey_id = $4 AND qr.complete = $5
LEFT JOIN mdl_user u ON u.id = CAST(qr.username AS INT)
WHERE qr.id = $6 UNION ALL
SELECT qr.id || '' || 'date' || '' || qrd.id AS id,
qr.submitted, qr.complete, qr.grade, qr.username, u.firstnamephonetic, u.lastnamephonetic, u.middlename, u.alternatename, u.firstname, u.lastname, u.username, u.department, u.institution, u.id as userid, qr.id AS rid, qrd.question_id,
0 AS choice_id, qrd.response AS response, 0 AS rank
FROM mdl_questionnaire_response qr
JOIN mdl_questionnaire_response_date qrd
ON qrd.response_id = qr.id

AND qr.survey_id = $7 AND qr.complete = $8
LEFT JOIN mdl_user u ON u.id = CAST(qr.username AS INT)
WHERE qr.id = $9 UNION ALL
SELECT qr.id || '' || 'yesno' || '' || qrb.id AS id,
qr.submitted, qr.complete, qr.grade, qr.username, u.firstnamephonetic, u.lastnamephonetic, u.middlename, u.alternatename, u.firstname, u.lastname, u.username, u.department, u.institution, u.id as userid, qr.id AS rid, qrb.question_id,
0 AS choice_id, qrb.choice_id AS response, 0 AS rank
FROM mdl_questionnaire_response qr
JOIN mdl_questionnaire_response_bool qrb ON qrb.response_id = qr.id

AND qr.survey_id = $10 AND qr.complete = $11
LEFT JOIN mdl_user u ON u.id = CAST(qr.username AS INT)
WHERE qr.id = $12 ORDER BY userid, id
[array (
0 => '904',

@mchurchward
Copy link
Contributor

Thanks. I'll look at this later this week.

@mchurchward
Copy link
Contributor

Can one of you explain what the actual issue is? Is there a specific response type that is failing? What is the actual data types of expected type vs. that actual type causing the issue?

@sarjona
Copy link
Author

sarjona commented Oct 7, 2016

In Oracle the problem is because of the CLOB fields (TEXT in Moodle), which have a lot of problems comparing directly and need converting them to varchar or similar.
I'm not sure if this answer all your questions but if I can help you, tell us :-)

@mchurchward
Copy link
Contributor

Hi.
I still don't get what lines like these are intended to do:
"$DB->sql_compare_text($alias . '.' . $field, 1000)."

My understanding of the "sql_compare_text" function is that it is used to return sql that allows comparison of a text field to a varchar field. But, you aren't using it in a compare context. You are using it where the variable is listed in the "SELECT" part. Does that make sense to to? Also, why "1000"?

@sarjona
Copy link
Author

sarjona commented Nov 8, 2016

Replaced sql_compare_text to sql_order_by_text function and opened new PR: #73

@sarjona sarjona closed this Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants