refactor: [db:create] add command line message on detect extension sqlite3 not loaded
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
What you want to solve? and describe a problem
Why do you need this?
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: @.***>
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.
Can you show the exact error message that does not help?
Can you show the exact error message that does not help?
- 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.
- 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
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
*/
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
I think the same happens with the other drivers
@renpv I sent #9160. Check it.
Closed by #9160