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

Review and improvements in databases drivers MySQLi, Postgre and SQLite: #1335

Merged
merged 3 commits into from
Oct 31, 2018
Merged

Review and improvements in databases drivers MySQLi, Postgre and SQLite: #1335

merged 3 commits into from
Oct 31, 2018

Conversation

fmertins
Copy link
Contributor

  1. Fixed typo method name "escapeLikeStr()" to "escapeLikeString()".
  2. Methods _fieldData(), _indexData() and _foreignKeyData() now return only array and throw DatabaseException (instead of returning false).
    2.1) BaseConnection, added abstract methods() missing because this class relies on all its subclasses having those methods.
  3. BaseBuilder, added TODO about a parameter with default value.
  4. composer.json, added ext-mysqli at require-dev section.

1) Fixed typo method name "escapeLikeStr()" to "escapeLikeString()".
2) Methods _fieldData(), _indexData() and _foreignKeyData() now return only array and throw DatabaseException (instead of returning false).
2.1) BaseConnection, added abstract methods() missing because this class relies on all its subclasses having those methods.
3) BaseBuilder, added TODO about a parameter with default value.
4) composer.json, added ext-mysqli at require-dev section.
Copy link
Member

@lonnieezell lonnieezell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making those to throw exceptions! The biggest thing I commented on here is for you to localize the strings thrown by the exceptions.

All of the other exception files use a different style for throwing exceptions. If you wanted to emulate what those were doing, that would be great, but I won't push that one since I obviously missed the DatabaseException class when I went through and converted those.

composer.json Outdated
@@ -24,7 +24,8 @@
"require-dev": {
"phpunit/phpunit": "^7.0",
"mikey179/vfsStream": "1.6.*",
"codeigniter4/codeigniter4-standard": "^1.0"
"codeigniter4/codeigniter4-standard": "^1.0",
"ext-mysqli": "*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mysql driver is not needed if you plan on using Postgres. Please remove.

{
return FALSE;
throw new DatabaseException('Failed to get field data from MySQL.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a localized string that is added to system/Language/en/Database.php

{
return FALSE;
throw new DatabaseException('Failed to get index data from MySQL.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use localized string here.

@@ -488,7 +494,7 @@ public function _indexData(string $table)
}
else
{
throw new \LogicException('parsing key string failed.');
throw new \LogicException('Parsing key string failed.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wouldn't mind moving this one to the Database lang file too, that would be great!

@@ -521,7 +528,7 @@ public function _foreignKeyData(string $table)

if (($query = $this->query($sql)) === false)
{
return false;
throw new DatabaseException('Failed to get foreign key data from MySQL');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localize this string

@@ -338,7 +341,7 @@ public function _indexData(string $table)

if (($query = $this->query($sql)) === false)
{
return false;
throw new DatabaseException('Failed to get index data from PostgreSQL.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localize this string


if (($query = $this->query($sql)) === false)
{
return false;
throw new DatabaseException('Failed to get foreign key data from PostgreSQL.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localize this string

if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protectIdentifiers($table, true, null,
false).')')) === false)
{
return false;
throw new DatabaseException('Failed to get field data from SQLite.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localize this string

if (($query = $this->query($sql)) === false)
{
return false;
throw new DatabaseException('Failed to get index data from SQLite.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localize this string

@@ -354,7 +353,7 @@ public function _indexData(string $table)
$obj->fields = [];
if (($fields = $this->query('PRAGMA index_info('.$this->escape(strtolower($row->name)).')')) === false)
{
return false;
throw new DatabaseException('Failed to get index_info() from SQLite.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localize this string

@fmertins
Copy link
Contributor Author

Hi Lonnie thank you I'll do these improvements still this week.

@jim-parry jim-parry added the waiting for info Issues or pull requests that need further clarification from the author label Oct 29, 2018
fmertins added 2 commits October 30, 2018 21:51
…ngs.

2) Language/en/Database.php, new entries about exceptions.
3) composer.json, removed ext-mysqli.
@fmertins
Copy link
Contributor Author

Hi there, I've done the modifications, thanks.

@lonnieezell
Copy link
Member

Thanks!

@lonnieezell lonnieezell merged commit 7237d17 into codeigniter4:develop Oct 31, 2018
@fmertins fmertins deleted the database_drivers_improvements branch October 31, 2018 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for info Issues or pull requests that need further clarification from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants