matthiasblaesing commented on a change in pull request #3117:
URL: https://github.com/apache/netbeans/pull/3117#discussion_r693178130



##########
File path: 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("'", "''");
                 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) AS routine_params" // NOI18N
+                              + " FROM information_schema.routines" // NOI18N
+                              + " WHERE routine_name='" + escapedName + "';"; 
// NOI18N
+                        try (Statement stat = 
connection.getJDBCConnection().createStatement(); 
                                 ResultSet rs = stat.executeQuery(query);) {
 
                             while (rs.next()) {
-                                String parent = rs.getString("db"); // NOI18N
+                                String parent = 
rs.getString("routine_schema"); // NOI18N
                                 if (parent != null && parent.trim().length() > 
0) {
                                     parent += '.'; //  NOI18N
                                 } else {
                                     parent = "";
                                 }
-                                String params = rs.getString("param_list"); // 
NOI18N
 
-                                String returns = null;
-                                if (function) {
-                                    returns = rs.getString("returns"); // 
NOI18N
-                                }
-                                String body = rs.getString("body"); // NOI18N
-                                source = getTypeName(getType()) + " " + parent
-                                        + getName() + "\n" + // NOI18N
-                                        "(" + params + ")" + "\n"
-                                        + // NOI18N
-                                        (function ? "RETURNS " + returns + 
"\n" : "")
-                                        + // NOI18N                            
       
-                                        body;
+                                //Concatenated list of routine parameters
+                                String params = 
rs.getString("routine_params"); // NOI18N
+
+                                //Data access characteristic: CONTAINS SQL, NO 
SQL, READS SQL DATA, or MODIFIES SQL DATA.
+                                String sql_data_access = 
rs.getString("sql_data_access");
+
+                                //YES or NO, depending on whether the routine 
is defined with the DETERMINISTIC characteristic.
+                                String is_deterministic = 
rs.getString("is_deterministic"); // NOI18N
+
+                                //Routine comment
+                                String comment = 
rs.getString("routine_comment"); // NOI18N
+
+                                source = rs.getString("routine_definition");
+
+                                source = getTypeName(getType()) + " " + parent 
+ getName() + "(" + params + ")" + "\n"
+                                       + (function ? "RETURNS " + 
rs.getString("dtd_identifier") + "\n" : "") // NOI18N
+                                       + sql_data_access + "\n"
+                                       + (is_deterministic == "YES" ? "" : 
"NOT ") + "DETERMINISTIC\n" // NOI18N
+                                       + (comment.length() > 0 ? "COMMENT '" + 
comment +"'\n" : "") // NOI18N
+                                       + rs.getString("routine_definition");

Review comment:
       ```suggestion
                                   source = getTypeName(getType()) + " " + 
parent + getName() + "(" + params + ")" + "\n" // NOI18N
                                          + (function ? "RETURNS " + 
rs.getString("dtd_identifier") + "\n" : "") // NOI18N
                                          + sql_data_access + "\n" // NOI18N
                                          + (is_deterministic == "YES" ? "" : 
"NOT ") + "DETERMINISTIC\n" // NOI18N
                                          + (comment.length() > 0 ? "COMMENT '" 
+ comment +"'\n" : "") // NOI18N
                                          + rs.getString("routine_definition"); 
// NOI18N
   ```

##########
File path: 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("'", "''");
                 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) AS routine_params" // NOI18N

Review comment:
       ```suggestion
                                 + " WHERE specific_name=routine_name AND 
ordinal_position>0 ORDER BY ordinal_position) AS routine_params" // NOI18N
   ```
   
   There is no guarantee that the parameters are returned in the right order, 
so I would add an order so that the parameters are ensured in correct order. 

##########
File path: ide/db/src/org/netbeans/modules/db/explorer/node/ProcedureNode.java
##########
@@ -505,7 +520,7 @@ public String getBody() {
                         }
                         break;
                     default:
-                        assert false : "Unknown type" + getType();
+                        assert false : "Unknown type " + getType();

Review comment:
       ```suggestion
                           assert false : "Unknown type " + getType(); // NOI18N
   ```

##########
File path: ide/db/src/org/netbeans/modules/db/explorer/node/ProcedureNode.java
##########
@@ -415,7 +425,7 @@ public String getSource() {
                         }
                         break;
                     default:
-                        assert false : "Unknown type" + getType();
+                        assert false : "Unknown type " + getType();

Review comment:
       ```suggestion
                           assert false : "Unknown type " + getType(); // NOI18N
   ```

##########
File path: ide/db/src/org/netbeans/modules/db/explorer/node/ProcedureNode.java
##########
@@ -429,16 +439,19 @@ public String getParams() {
             String escapedName = "";
             String query = "";
             try {
+                boolean function = false;
                 switch (getType()) {
                     case Function:
+                        function = true;
                     case Procedure:
                         escapedName = getName().replace("'", "''");
-                        query = "SELECT param_list FROM mysql.proc WHERE name 
= '" // NOI18N
-                                + escapedName + "';"; // NOI18N
-                        try (Statement stat = 
connection.getJDBCConnection().createStatement();
+                        query = "SELECT GROUP_CONCAT(CONCAT(" + (function ? "" 
: "parameter_mode,' ',") + "parameter_name,' ',dtd_identifier)) AS 
routine_params" // NOI18N
+                              + " FROM information_schema.parameters" // NOI18N
+                              + " WHERE ordinal_position>0 AND 
specific_name='" + escapedName + "';"; // NOI18N

Review comment:
       Same comment about order in line 348 applies here too.

##########
File path: 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("'", "''");
                 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) AS routine_params" // NOI18N
+                              + " FROM information_schema.routines" // NOI18N
+                              + " WHERE routine_name='" + escapedName + "';"; 
// NOI18N
+                        try (Statement stat = 
connection.getJDBCConnection().createStatement(); 
                                 ResultSet rs = stat.executeQuery(query);) {
 
                             while (rs.next()) {
-                                String parent = rs.getString("db"); // NOI18N
+                                String parent = 
rs.getString("routine_schema"); // NOI18N
                                 if (parent != null && parent.trim().length() > 
0) {
                                     parent += '.'; //  NOI18N
                                 } else {
                                     parent = "";
                                 }
-                                String params = rs.getString("param_list"); // 
NOI18N
 
-                                String returns = null;
-                                if (function) {
-                                    returns = rs.getString("returns"); // 
NOI18N
-                                }
-                                String body = rs.getString("body"); // NOI18N
-                                source = getTypeName(getType()) + " " + parent
-                                        + getName() + "\n" + // NOI18N
-                                        "(" + params + ")" + "\n"
-                                        + // NOI18N
-                                        (function ? "RETURNS " + returns + 
"\n" : "")
-                                        + // NOI18N                            
       
-                                        body;
+                                //Concatenated list of routine parameters
+                                String params = 
rs.getString("routine_params"); // NOI18N
+
+                                //Data access characteristic: CONTAINS SQL, NO 
SQL, READS SQL DATA, or MODIFIES SQL DATA.
+                                String sql_data_access = 
rs.getString("sql_data_access");

Review comment:
       ```suggestion
                                   String sql_data_access = 
rs.getString("sql_data_access"); // NOI18N
   ```

##########
File path: 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("'", "''");

Review comment:
       ```suggestion
                   String escapedName = getName().replace("'", "''"); // NOI18N
   ```

##########
File path: 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("'", "''");
                 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) AS routine_params" // NOI18N
+                              + " FROM information_schema.routines" // NOI18N
+                              + " WHERE routine_name='" + escapedName + "';"; 
// NOI18N
+                        try (Statement stat = 
connection.getJDBCConnection().createStatement(); 
                                 ResultSet rs = stat.executeQuery(query);) {
 
                             while (rs.next()) {
-                                String parent = rs.getString("db"); // NOI18N
+                                String parent = 
rs.getString("routine_schema"); // NOI18N
                                 if (parent != null && parent.trim().length() > 
0) {
                                     parent += '.'; //  NOI18N
                                 } else {
                                     parent = "";
                                 }
-                                String params = rs.getString("param_list"); // 
NOI18N
 
-                                String returns = null;
-                                if (function) {
-                                    returns = rs.getString("returns"); // 
NOI18N
-                                }
-                                String body = rs.getString("body"); // NOI18N
-                                source = getTypeName(getType()) + " " + parent
-                                        + getName() + "\n" + // NOI18N
-                                        "(" + params + ")" + "\n"
-                                        + // NOI18N
-                                        (function ? "RETURNS " + returns + 
"\n" : "")
-                                        + // NOI18N                            
       
-                                        body;
+                                //Concatenated list of routine parameters
+                                String params = 
rs.getString("routine_params"); // NOI18N
+
+                                //Data access characteristic: CONTAINS SQL, NO 
SQL, READS SQL DATA, or MODIFIES SQL DATA.
+                                String sql_data_access = 
rs.getString("sql_data_access");
+
+                                //YES or NO, depending on whether the routine 
is defined with the DETERMINISTIC characteristic.
+                                String is_deterministic = 
rs.getString("is_deterministic"); // NOI18N
+
+                                //Routine comment
+                                String comment = 
rs.getString("routine_comment"); // NOI18N
+
+                                source = rs.getString("routine_definition");

Review comment:
       ```suggestion
                                   source = rs.getString("routine_definition"); 
// NOI18N
   ```




-- 
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