Using Server Events with Grid-Add and Grid-Edit

Hi,
I want to use Gridadd and Gridedit.
It is generating this error in PHPMaker 2022 and 2023.
The only issue is, that I have in Row_Rendered, Row_Inserted and Row_Updated content.
All other is working as expected but only the gridadd and gridedit not.

API\MySQL\ExceptionConverter.php(86): An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’ at line 1mpol_ch

mpol_ch wrote:

An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near ‘’ at line 1

You might have wrong code in your server events, you should enable Debug and check the actual error in the SQLYou may also read Migrating to v2022 → Database Abstraction Layer (DBAL 3), then review your code accordingly.

Hi,

I do not see any unusual records in Debug lines.
What a I have is a subquery as you can see below in Row_Updated.
Could this be a reason?


  $myResult = ExecuteStatement("UPDATE projekte SET Spenden=(SELECT BBetrag from view_ProjektSpenden WHERE JId =".$rsold['Projekt'].") WHERE JId =".$rsold['Projekt']);

mpol_ch

mpol_ch wrote:

I do not see any unusual records in Debug lines. >

You should, the error clearly said that “You have an error in your SQL syntax”.You should follow enable Debug carefully, enable logging SQL and errors and check the actual error in the log file. Do it slowly and correctly. Post the errors in the log file for discussion.You should also check your SQL (“UPDATE projekte SET Spenden=(SELECT BBetrag from view_ProjektSpenden WHERE JId =”.$rsold[‘Projekt’].“) WHERE JId =”.$rsold[‘Projekt’]) in the Debug panel. For example, if $rsold[‘Projekt’] has no value, it fails.

Hi,

I just found out the the content of Row_Rendered is causing the problem for gridadd and gridedit.
I am using the following code which ist working fine until I want to use the Gridadd or Gridedit.
I tried with this code but no success

$Prolink = ExecuteRow(“SELECT * FROM projekte WHERE JId=”.$Projekt);When use the 150 for where clause then the gridadd and gridedit is working fine:$Prolink = ExecuteRow("SELECT * FROM projekte WHERE JId=150);What should I use instead of “$this->Projekt->CurrentValue” to have Gridadd ?

    if ($this->Projekt->ViewValue <> "") {
        $Prolink = ExecuteRow("SELECT * FROM projekte WHERE JId=".$this->Projekt->CurrentValue); 
       $this->Projekt->ViewValue=$Prolink['Abk'];
       }else
       {$this->Projekt->ViewValue = "";
    }  
    }

mpol_ch

If Grid-Add, there are no rows on load so $this->Projekt->CurrentValue does not have any value. You should check if the property has value before using it in your SQL.

Hi,

here is the entire code.
Everything is working except Gridadd and Gridedit.
The condition is saying that it is for CurrentPageID list, view and preview.
And nothing for gridadd or gridedit.
Am I mistaking?

 // Row Rendered event
 function Row_Rendered()
 {
  // To view properties of field class, use:
  //var_dump($this-><FieldName>);
 if (CurrentPageID() == "list" OR CurrentPageID() == "view" OR CurrentPageID() == "preview") {  
 // Get the Projekt Information
 if ($this->Projekt->ViewValue <> "") {
 $Prolink = ExecuteRow("SELECT * FROM projekte WHERE JId=".$this->Projekt->CurrentValue); 
 $this->Projekt->ViewValue=$Prolink['Abk'];
 }else
 {$this->Projekt->ViewValue = "";
 }  
 }
 }

When you use Grid-Add/Edit, the ViewValue is not used (ViewValue is for showing the field value in List/View page only, not for edit mode), the EditValue is used.

Hi,
I expect the this rule should be applied for gridadd and gridadd because of if condition for CurrentPageID.

When I replace the WHERE JId=“.$this->Projekt->CurrentValue with WHERE JId=150” then it works.
When change the from $this->Projekt->CurrentValue to $this->Projekt->EditValue then even the xxxlist page ist being not generated.

You provided your own value so your SQL works. But as said there is NO value in Grid-Add, your SQL will not work.

As for Grid-Edit,mpol_ch wrote:

When change the from $this->Projekt->CurrentValue to $this->Projekt->EditValue then even the xxxlist page ist being not generated. >

By “not generated” I guessed you meant the page is blank (because there is PHP error).Make sure you configure your php.ini to display ALL errors, read error-reporting and display-errors.arbei wrote:

you should > enable Debug > and check the actual error >

Did you? Do not avoid or skip. You may post the error for discussion.

Hi,

I changed the query to the ExecuteQuery for Select.


        // Row Rendered event
       function Row_Rendered()
       {
       // To view properties of field class, use:
       //var_dump($this-><FieldName>);
      if (CurrentPageID() == "list" OR CurrentPageID() == "view" OR CurrentPageID() == "preview") {  
      // Get the Projekt Information
      if ($this->Projekt->ViewValue <> "") {
      $result = ExecuteQuery("SELECT * FROM projekte WHERE JId=".$this->Projekt->CurrentValue); 
     // $result = ExecuteQuery("SELECT * FROM projekte WHERE JId= 150");  Work fine.
      $this->Projekt->ViewValue=$result['Abk'];
       }else
       {$this->Projekt->ViewValue = "";
     }  
    }
    }



#0 C:\xampp\htdocs\spendenbox\vendor\doctrine\dbal\src\Connection.php(1818): Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert(Object(Doctrine\DBAL\Driver\PDO\Exception), Object(Doctrine\DBAL\Query))
#1 C:\xampp\htdocs\spendenbox\vendor\doctrine\dbal\src\Connection.php(1761): Doctrine\DBAL\Connection->handleDriverException(Object(Doctrine\DBAL\Driver\PDO\Exception), Object(Doctrine\DBAL\Query))
#2 C:\xampp\htdocs\spendenbox\vendor\doctrine\dbal\src\Connection.php(1034): Doctrine\DBAL\Connection->convertExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDO\Exception), 'SELECT * FROM p...', Array, Array)
#3 C:\xampp\htdocs\spendenbox\src\phpfn.php(5139): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM p...')
#4 C:\xampp\htdocs\spendenbox\src\phpfn.php(5335): PHPMaker2022\spendenbox\ExecuteQuery('SELECT * FROM p...', NULL)
#5 C:\xampp\htdocs\spendenbox\src\phpfn.php(5317): PHPMaker2022\spendenbox\ExecuteRowAssociative('SELECT * FROM p...', NULL)
#6 C:\xampp\htdocs\spendenbox\models\Spenden.php(2577): PHPMaker2022\spendenbox\ExecuteRow('SELECT * FROM p...')
#7 C:\xampp\htdocs\spendenbox\models\SpendenList.php(4036): PHPMaker2022\spendenbox\Spenden->rowRendered()
...

thanks.

If you are using ExecuteQuery, then you need to fetch the field value by using the following logic: How to Load Data from Database into Custom Files (v2022) (it should work also for v2023).

arbei wrote:

You may also read > Migrating to v2022 → Database Abstraction Layer (DBAL 3)> , then review your code accordingly.

If you want to get a row, you shold use ExecuteRow().And again, it is no use to set ViewValue if you are trying to preset a field value in Grid-Edit.