Skip to content

Bug: spark db:table causes an error with table name including special chars #6765

Open
@kenjis

Description

@kenjis

PHP Version

8.1

CodeIgniter4 Version

develop (30258d5)

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

macOS

Which server did you use?

cli

Database

MySQL 5.7

What happened?

$ php spark db:table

CodeIgniter v4.2.7 Command Line Tool - Server Time: 2022-10-26 20:54:55 UTC-05:00

Here is the list of your database tables:
  [0]  , CONCAT('',`password`) AS `email`
  [1]  migrations
  [2]  zip_address

Which table do you want to see? [0, 1, 2]: 0

Data of Table ", CONCAT('',`password`) AS `email`":


[mysqli_sql_exception]

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' CONCAT('',`password`) AS `email`' at line 1

at SYSTEMPATH/Database/MySQLi/Connection.php:292

Backtrace:
  1    SYSTEMPATH/Database/MySQLi/Connection.php:292
       mysqli()->query('SHOW COLUMNS FROM , CONCAT(\'\',`password`) AS `email`', 0)

  2    SYSTEMPATH/Database/BaseConnection.php:666
       CodeIgniter\Database\MySQLi\Connection()->execute('SHOW COLUMNS FROM , CONCAT(\'\',`password`) AS `email`')

  3    SYSTEMPATH/Database/BaseConnection.php:593
       CodeIgniter\Database\BaseConnection()->simpleQuery('SHOW COLUMNS FROM , CONCAT(\'\',`password`) AS `email`')

  4    SYSTEMPATH/Database/BaseConnection.php:1451
       CodeIgniter\Database\BaseConnection()->query('SHOW COLUMNS FROM , CONCAT(\'\',`password`) AS `email`')

  5    SYSTEMPATH/Commands/Database/ShowTableInfo.php:162
       CodeIgniter\Database\BaseConnection()->getFieldNames(', CONCAT(\'\',`password`) AS `email`')

  6    SYSTEMPATH/Commands/Database/ShowTableInfo.php:143
       CodeIgniter\Commands\Database\ShowTableInfo()->showDataOfTable(', CONCAT(\'\',`password`) AS `email`', 10, 15)

  7    SYSTEMPATH/CLI/Commands.php:63
       CodeIgniter\Commands\Database\ShowTableInfo()->run([])

  8    SYSTEMPATH/CLI/CommandRunner.php:65
       CodeIgniter\CLI\Commands()->run('db:table', [])

  9    SYSTEMPATH/CLI/CommandRunner.php:51
       CodeIgniter\CLI\CommandRunner()->index([])

 10    SYSTEMPATH/CodeIgniter.php:920
       CodeIgniter\CLI\CommandRunner()->_remap('index', [...])

 11    SYSTEMPATH/CodeIgniter.php:482
       CodeIgniter\CodeIgniter()->runController(Object(CodeIgniter\CLI\CommandRunner))

 12    SYSTEMPATH/CodeIgniter.php:347
       CodeIgniter\CodeIgniter()->handleRequest(null, Object(Config\Cache), false)

 13    SYSTEMPATH/CLI/Console.php:48
       CodeIgniter\CodeIgniter()->run()

 14    ROOTPATH/spark:98
       CodeIgniter\CLI\Console()->run()

Steps to Reproduce

Create a table named

, CONCAT('',`password`) AS `email`
create table `, CONCAT('',``password``) AS ``email``` (id int, name varchar(10));

Run php spark db:table.

Expected Output

No error.

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix themdatabaseIssues or pull requests that affect the database layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions