Skip to content

Error on parsing encoded sql field #4

@manuelddahmen

Description

@manuelddahmen

I have a FatalError in parsing SQL:

SELECT sql FROM sqlite_schema WHERE type ='table' AND tbl_name='table_hospitalises';
Fatal error: Uncaught Exception: Expect '(': ' ( chambre integer def...' FROM 'CREATE TABLE table_hospitalises ( chambre integer default 300 primary key , nom varchar(30) default '', prenom varchar(30) default '' , sex varchar(1) default 'M')' in C:\Users\manue\PhpstormProjects\untitled\vendor\maghead\sqlite-parser\src\BaseParser.php:70 Stack trace: #0 C:\Users\manue\PhpstormProjects\untitled\vendor\maghead\sqlite-parser\src\CreateTableParser.php(72): Maghead\SqliteParser\BaseParser->expect() #1 C:\Users\manue\PhpstormProjects\untitled\src\agenda.php(30): Maghead\SqliteParser\CreateTableParser->parse() #2 C:\Users\manue\PhpstormProjects\untitled\src\agenda.php(63): findInfoTable() #3 {main} thrown in C:\Users\manue\PhpstormProjects\untitled\vendor\maghead\sqlite-parser\src\BaseParser.php on line 70

My code:

    global $db;
    $createTableParser = new CreateTableParser();

    $sql = "SELECT sql FROM sqlite_schema WHERE type ='table' AND tbl_name='".$tablename."';";
    echo $sql;
    $parser = new CreateTableParser;
    $stmt = $db->prepare($sql);
    $stmt->execute();
    if($stmt!==false) {

        $results = $stmt->fetchAll(PDO::FETCH_BOTH);
        if($results!==false) {
            $table = $parser->parse($results[0]['sql']);
        } else {
             echo "DEBUG No Lines 1";
        }
    }
    else echo "DEBUG No Lines 2";

    var_dump($table);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions