@@ -65,22 +65,29 @@ public function __construct(mysqli $mysqli)
6565
6666 public function validateQueryString (string $ queryString ): ?Error
6767 {
68- try {
69- $ simulatedQuery = QuerySimulation::simulate ($ queryString );
70- if (null === $ simulatedQuery ) {
71- return null ;
72- }
68+ $ simulatedQuery = QuerySimulation::simulate ($ queryString );
69+ if (null === $ simulatedQuery ) {
70+ return null ;
71+ }
7372
73+ try {
7474 $ this ->db ->query ($ simulatedQuery );
7575
7676 return null ;
7777 } catch (mysqli_sql_exception $ e ) {
7878 if (\in_array ($ e ->getCode (), [self ::MYSQL_SYNTAX_ERROR_CODE , self ::MYSQL_UNKNOWN_COLUMN_IN_FIELDLIST , self ::MYSQL_UNKNOWN_TABLE ], true )) {
79- // make error string consistent across mysql/mariadb
79+
8080 $ message = $ e ->getMessage ();
81+
82+ // make error string consistent across mysql/mariadb
8183 $ message = str_replace (' MySQL server ' , ' MySQL/MariaDB server ' , $ message );
8284 $ message = str_replace (' MariaDB server ' , ' MySQL/MariaDB server ' , $ message );
8385
86+ // to ease debugging, print the error we simulated
87+ if ($ e ->getCode () === self ::MYSQL_SYNTAX_ERROR_CODE && QueryReflection::getRuntimeConfiguration ()->isDebugEnabled ()) {
88+ $ message = $ message ."\n\nSimulated query: " . $ simulatedQuery ;
89+ }
90+
8491 return new Error ($ message , $ e ->getCode ());
8592 }
8693
@@ -93,11 +100,12 @@ public function validateQueryString(string $queryString): ?Error
93100 */
94101 public function getResultType (string $ queryString , int $ fetchType ): ?Type
95102 {
103+ $ simulatedQuery = QuerySimulation::simulate ($ queryString );
104+ if (null === $ simulatedQuery ) {
105+ return null ;
106+ }
107+
96108 try {
97- $ simulatedQuery = QuerySimulation::simulate ($ queryString );
98- if (null === $ simulatedQuery ) {
99- return null ;
100- }
101109 $ result = $ this ->db ->query ($ simulatedQuery );
102110
103111 if (!$ result instanceof mysqli_result) {
0 commit comments