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

refactor: [db:create] add command line message on detect extension sqlite3 not loaded #9051

Closed
wants to merge 1 commit into from

Conversation

renpv
Copy link

@renpv renpv commented Jul 18, 2024

add command line message on detect extension sqlite3 not loaded

Description
Explain what you have changed, and why.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

add command line message on detect extension sqlite3 not loaded
@renpv renpv changed the title Update CreateDatabase.php refactor: add command line message on detect extension sqlite3 not loaded Jul 18, 2024
@ddevsr
Copy link
Collaborator

ddevsr commented Jul 19, 2024

What you want to solve? and describe a problem

Comment on lines +99 to +104
if (!extension_loaded('sqlite3')) {
CLI::error("extension [sqlite3] not loaded. Uncomment it in the php.ini file", 'light_gray', 'red');
CLI::newLine();

return;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't accept this in here. It is only for SQLite3, so it should not in this class.

@kenjis
Copy link
Member

kenjis commented Jul 19, 2024

Why do you need this?

@kenjis kenjis changed the title refactor: add command line message on detect extension sqlite3 not loaded refactor: [db:create] add command line message on detect extension sqlite3 not loaded Jul 19, 2024
@renpv
Copy link
Author

renpv commented Jul 19, 2024 via email

@renpv
Copy link
Author

renpv commented Jul 19, 2024

What you want to solve? and describe a problem

With the extension disabled, when trying to execute a command related to SQLite the system returns an error that does not help with resolution.

I'm including this code because it's not the first time I've spend a specific amount of time trying to solve a problem based on a
wrong message.

@kenjis
Copy link
Member

kenjis commented Jul 19, 2024

Can you show the exact error message that does not help?

@renpv
Copy link
Author

renpv commented Jul 20, 2024

Can you show the exact error message that does not help?

image

@kenjis
Copy link
Member

kenjis commented Jul 20, 2024

  1. We have some commands to use database. All commands would report the same error message Class “SQLite3” not found.
Database
  db:create         Create a new database schema.
  db:seed           Runs the specified seeder to populate known data into the database.
  db:table          Retrieves information on the selected table.
  migrate           Locates and runs all new migrations against the database.
  migrate:refresh   Does a rollback followed by a latest to refresh the current state of the database.
  migrate:rollback  Runs the "down" method for all migrations in the last batch.
  migrate:status    Displays a list of all migrations and whether they've been run or not.
  1. We have some database drivers. The drivers other than SQLite3 would report error messages if the extension is not loaded.
$ php spark db:create report

CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-07-20 02:22:47 UTC+00:00

[CodeIgniter\Database\Exceptions\DatabaseException]
Unable to connect to the database.
Main connection [SQLSRV]: Undefined constant "CodeIgniter\Database\SQLSRV\SQLSRV_ENC_CHAR"
at SYSTEMPATH/Database/BaseConnection.php:467

@kenjis
Copy link
Member

kenjis commented Jul 20, 2024

How about this?

--- a/system/Database/SQLite3/Connection.php
+++ b/system/Database/SQLite3/Connection.php
@@ -55,6 +55,16 @@ class Connection extends BaseConnection
      */
     protected $busyTimeout;
 
+    public function __construct(array $params)
+    {
+        assert(
+            extension_loaded('sqlit3'),
+            'The required PHP extension "sqlit3" is not loaded.'
+        );
+
+        parent::__construct($params);
+    }
+
     /**
      * @return void
      */

@renpv
Copy link
Author

renpv commented Jul 20, 2024

How about this?

--- a/system/Database/SQLite3/Connection.php
+++ b/system/Database/SQLite3/Connection.php
@@ -55,6 +55,16 @@ class Connection extends BaseConnection
      */
     protected $busyTimeout;
 
+    public function __construct(array $params)
+    {
+        assert(
+            extension_loaded('sqlit3'),
+            'The required PHP extension "sqlit3" is not loaded.'
+        );
+
+        parent::__construct($params);
+    }
+
     /**
      * @return void
      */

Great. Much better. But sqlit3 is wrong. Correct sqlite3

@renpv
Copy link
Author

renpv commented Jul 22, 2024

I think the same happens with the other drivers

@kenjis
Copy link
Member

kenjis commented Aug 30, 2024

@renpv I sent #9160. Check it.

@kenjis
Copy link
Member

kenjis commented Sep 5, 2024

Closed by #9160

@kenjis kenjis closed this Sep 5, 2024
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.

3 participants