CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

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

Open renpv opened this issue 1 year ago • 10 comments

add command line message on detect extension sqlite3 not loaded

Description Explain what you have changed, and why.

Checklist:

  • [x] 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

renpv avatar Jul 18 '24 23:07 renpv

What you want to solve? and describe a problem

ddevsr avatar Jul 19 '24 01:07 ddevsr

Why do you need this?

kenjis avatar Jul 19 '24 02:07 kenjis

Com essa extensão desabilitada, se tentar conectar a um banco SQLite o sistema retorna o seguinte erro: [image: c8b6bcc0-391d-443c-97ed-a6b3945161f6.png]

Essa mensagem dificulta a resolução do problema.

Com essa linha de código o sistema vai retornar essa mensagem: [image: image.png]

Estou sugerindo incluir esse código porque não é a primeira vez que eu perco um tempo considerável tentando resolver um problema baseado em uma mensagem errada.

Eu coloquei nesse arquivo porque ele faz algumas validações iniciais relacionadas ao SQLite.

Fico à disposição.

Atenciosamente,

Em qui., 18 de jul. de 2024, 23:53, kenjis @.***> escreveu:

Why do you need this?

— Reply to this email directly, view it on GitHub https://github.com/codeigniter4/CodeIgniter4/pull/9051#issuecomment-2237980646, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGKSQJ2D2MKWLDUPVB3BZTZNB5UBAVCNFSM6AAAAABLDSSJKSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZXHE4DANRUGY . You are receiving this because you authored the thread.Message ID: @.***>

renpv avatar Jul 19 '24 10:07 renpv

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.

renpv avatar Jul 19 '24 19:07 renpv

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

kenjis avatar Jul 19 '24 23:07 kenjis

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

image

renpv avatar Jul 20 '24 00:07 renpv

  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 avatar Jul 20 '24 02:07 kenjis

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
      */

kenjis avatar Jul 20 '24 02:07 kenjis

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 avatar Jul 20 '24 10:07 renpv

I think the same happens with the other drivers

renpv avatar Jul 22 '24 12:07 renpv

@renpv I sent #9160. Check it.

kenjis avatar Aug 30 '24 01:08 kenjis

Closed by #9160

kenjis avatar Sep 05 '24 01:09 kenjis