-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Make JDatabaseDriver::splitSql() handle comments and remove trimSql functions #9369
Merged
wilsonge
merged 8 commits into
joomla:staging
from
richard67:correct-split-sql-in-db-driver
Mar 14, 2016
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3983259
Make JDatabaseDriver::splitSql handle comments
richard67 d2a1ff8
Remove local trimQuery functions
richard67 1b85647
Code style
richard67 199a11c
Show special error message
richard67 46fdca1
Correct again error messages
richard67 3b942a8
Remove handling of c style comments
richard67 d13ad7f
Change back and enhance style comments handling
richard67 02462ed
Optimize code
richard67 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1756,30 +1756,34 @@ private function convertTablesToUtf8mb4() | |
{ | ||
foreach ($queries2 as $query2) | ||
{ | ||
if ($trimmedQuery = $this->trimQuery($query2)) | ||
// Downgrade the query if utf8mb4 isn't supported | ||
if (!$utf8mb4Support) | ||
{ | ||
// Downgrade the query if utf8mb4 isn't supported | ||
if (!$utf8mb4Support) | ||
{ | ||
$trimmedQuery = $this->convertUtf8mb4QueryToUtf8($trimmedQuery); | ||
} | ||
|
||
try | ||
{ | ||
$db->setQuery($trimmedQuery)->execute(); | ||
} | ||
catch (Exception $e) | ||
{ | ||
$converted = 0; | ||
|
||
// Still render the error message from the Exception object | ||
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error'); | ||
} | ||
$query2 = $this->convertUtf8mb4QueryToUtf8($query2); | ||
} | ||
|
||
try | ||
{ | ||
$db->setQuery($query2)->execute(); | ||
} | ||
catch (Exception $e) | ||
{ | ||
$converted = 0; | ||
|
||
// Still render the error message from the Exception object | ||
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error'); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Show if there was some error | ||
if ($converted == 0) | ||
{ | ||
// Show an error message telling to check database problems | ||
JFactory::getApplication()->enqueueMessage(JText::_('JLIB_DATABASE_ERROR_DATABASE_UPGRADE_FAILED'), 'error'); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it here instead, after the loop. |
||
// Set flag in database if the update is done. | ||
$db->setQuery('UPDATE ' . $db->quoteName('#__utf8_conversion') | ||
. ' SET ' . $db->quoteName('converted') . ' = ' . $converted . ';')->execute(); | ||
|
@@ -1865,35 +1869,4 @@ private function convertUtf8mb4QueryToUtf8($query) | |
// Replace utf8mb4 with utf8 | ||
return str_replace('utf8mb4', 'utf8', $query); | ||
} | ||
|
||
/** | ||
* Trim comment and blank lines out of a query string | ||
* | ||
* @param string $query query string to be trimmed | ||
* | ||
* @return string String with leading comment lines removed | ||
* | ||
* @since 3.5 | ||
*/ | ||
private function trimQuery($query) | ||
{ | ||
$query = trim($query); | ||
|
||
while (substr($query, 0, 1) == '#' || substr($query, 0, 2) == '--' || substr($query, 0, 2) == '/*') | ||
{ | ||
$endChars = (substr($query, 0, 1) == '#' || substr($query, 0, 2) == '--') ? "\n" : "*/"; | ||
|
||
if ($position = strpos($query, $endChars)) | ||
{ | ||
$query = trim(substr($query, $position + strlen($endChars))); | ||
} | ||
else | ||
{ | ||
// If no newline, the rest of the file is a comment, so return an empty string. | ||
return ''; | ||
} | ||
} | ||
|
||
return trim($query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the string I added last week here (check the database fixer thing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will not add it in the loop because there it will be repeated. I leave the sql error there for more info, and add the new message below as summary in case if some error happened before in the loop.