matthiasblaesing commented on code in PR #4945:
URL: https://github.com/apache/netbeans/pull/4945#discussion_r1019590246


##########
ide/db/src/org/netbeans/modules/db/explorer/node/ProcedureNode.java:
##########
@@ -336,39 +336,49 @@ public String getSource() {
             String source = "";
             try {
                 String query = "";
-                String escapedName = "";
+                String escapedName = getName().replace("'", "''"); // NOI18N
                 boolean function = false;
                 switch (getType()) {
                     case Function:
                         function = true;
                     case Procedure:
-                        escapedName = getName().replace("'", "''");
-                        query = "SELECT param_list, returns, body, db FROM 
mysql.proc WHERE name = '"
-                                + escapedName + "';"; // NOI18N
-                        try (Statement stat = 
connection.getJDBCConnection().createStatement();
+                        query = "SELECT 
routine_schema,routine_definition,dtd_identifier,is_deterministic,sql_data_access,routine_comment,"
 // NOI18N
+                              + "(SELECT GROUP_CONCAT(CONCAT(" + (function ? 
"" : "parameter_mode,' ',") + "parameter_name,' ',dtd_identifier))" // NOI18N
+                              + " FROM information_schema.parameters" // NOI18N
+                              + " WHERE specific_name=routine_name AND 
ordinal_position>0 ORDER BY ordinal_position) AS routine_params" // NOI18N

Review Comment:
   ```suggestion
                                 + "IFNULL((SELECT GROUP_CONCAT(CONCAT(" + 
(function ? "" : "parameter_mode,' ',") + "parameter_name,' ',dtd_identifier))" 
// NOI18N
                                 + " FROM information_schema.parameters" // 
NOI18N
                                 + " WHERE specific_name=routine_name AND 
ordinal_position>0 ORDER BY ordinal_position), '') AS routine_params" // NOI18N
   ```
   
   If your procedure or function does not have a parameter the current code 
generates invalid code:
   
   ```
   DELIMITER @@
   DROP PROCEDURE GetAllProducts @@
   CREATE PROCEDURE test.GetAllProducts(null)
   CONTAINS SQL
   NOT DETERMINISTIC
   BEGIN
        SELECT *  FROM t1;
   END @@ 
   DELIMITER ; 
   ```
   
   The `null` in line 3 is the problem.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to