Logo Search packages:      
Sourcecode: mysql-connector-java version File versions

java.sql.ResultSet com::mysql::jdbc::DatabaseMetaData::getProcedures ( String  catalog,
String  schemaPattern,
String  procedureNamePattern 
) throws SQLException [inline]

Get a description of stored procedures available in a catalog.

Only procedure descriptions matching the schema and procedure name criteria are returned. They are ordered by PROCEDURE_SCHEM, and PROCEDURE_NAME.

Each procedure description has the the following columns:

  1. PROCEDURE_CAT String => procedure catalog (may be null)
  2. PROCEDURE_SCHEM String => procedure schema (may be null)
  3. PROCEDURE_NAME String => procedure name
  4. reserved for future use
  5. reserved for future use
  6. reserved for future use
  7. REMARKS String => explanatory comment on the procedure
  8. PROCEDURE_TYPE short => kind of procedure:

    • procedureResultUnknown - May return a result
    • procedureNoResult - Does not return a result
    • procedureReturnsResult - Returns a result

Parameters:
catalog a catalog name; "" retrieves those without a catalog
schemaPattern a schema name pattern; "" retrieves those without a schema
procedureNamePattern a procedure name pattern
Returns:
ResultSet each row is a procedure description
Exceptions:
SQLException if a database access error occurs
See also:
getSearchStringEscape

Definition at line 2735 of file DatabaseMetaData.java.

References com::mysql::jdbc::Connection::clientPrepareStatement(), com::mysql::jdbc::ResultSet::close(), com::mysql::jdbc::PreparedStatement::close(), conn, database, com::mysql::jdbc::PreparedStatement::executeQuery(), com::mysql::jdbc::Statement::getMaxRows(), com::mysql::jdbc::ResultSet::getString(), com::mysql::jdbc::ResultSet::next(), s2b(), com::mysql::jdbc::Statement::setMaxRows(), com::mysql::jdbc::PreparedStatement::setNull(), com::mysql::jdbc::PreparedStatement::setString(), supportsStoredProcedures(), and com::mysql::jdbc::Connection::versionMeetsMinimum().

Referenced by getProcedureColumns().

                            {
        if ((procedureNamePattern == null) ||
                (procedureNamePattern.length() == 0)) {
            throw new SQLException("Procedure name pattern can not be NULL or empty.",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }

        Field[] fields = new Field[8];
        fields[0] = new Field("", "PROCEDURE_CAT", Types.CHAR, 0);
        fields[1] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 0);
        fields[2] = new Field("", "PROCEDURE_NAME", Types.CHAR, 0);
        fields[3] = new Field("", "reserved1", Types.CHAR, 0);
        fields[4] = new Field("", "reserved2", Types.CHAR, 0);
        fields[5] = new Field("", "reserved3", Types.CHAR, 0);
        fields[6] = new Field("", "REMARKS", Types.CHAR, 0);
        fields[7] = new Field("", "PROCEDURE_TYPE", Types.SMALLINT, 0);

        ArrayList procedureRows = new ArrayList();

        if (supportsStoredProcedures()) {
            PreparedStatement proceduresStmt = null;
            ResultSet proceduresRs = null;
            boolean needsClientFiltering = true;
            String db = null;
            
            if (catalog == null) {
                  db = this.database;
            } else if (catalog.length() > 0) {
                  db = catalog;
            } else {
                  db = null;
            }
            
            try {
                //proceduresStmt = this.conn.clientPrepareStatement(
                //        "SHOW PROCEDURE STATUS LIKE ?");
                proceduresStmt = this.conn.clientPrepareStatement(
                        "SELECT name FROM mysql.proc WHERE name like ? and db <=> ? ORDER BY name");

                if (db != null) {
                  proceduresStmt.setString(2, db);
                } else {
                  proceduresStmt.setNull(2, Types.VARCHAR);
                }
                
                int nameIndex = 1;

                if (proceduresStmt.getMaxRows() != 0) {
                    proceduresStmt.setMaxRows(0);
                }

                proceduresStmt.setString(1, procedureNamePattern);

                try {
                    proceduresRs = proceduresStmt.executeQuery();
                    needsClientFiltering = false;
                } catch (SQLException sqlEx) {
                    //
                    // Okay, system tables aren't accessible, so use 'SHOW ....'....
                    //
                    proceduresStmt.close();

                    proceduresStmt = this.conn.clientPrepareStatement(
                            "SHOW PROCEDURE STATUS LIKE ?");

                    if (proceduresStmt.getMaxRows() != 0) {
                        proceduresStmt.setMaxRows(0);
                    }

                    proceduresStmt.setString(1, procedureNamePattern);

                    proceduresRs = proceduresStmt.executeQuery();

                    if (this.conn.versionMeetsMinimum(5, 0, 1)) {
                        nameIndex = 2;
                    } else {
                        nameIndex = 1;
                    }
                }

                while (proceduresRs.next()) {
                  boolean shouldAdd = true;
                  
                  if (needsClientFiltering) {
                        shouldAdd = false;
                        
                        String procDb = proceduresRs.getString(1);
                        
                        if (db == null && procDb == null) {
                              shouldAdd = true;
                        } else if (db != null & db.equals(procDb)) {
                              shouldAdd = true;
                        }
                  }
                  
                  if (shouldAdd) {
                          byte[][] rowData = new byte[8][];
                          rowData[0] = null;
                          rowData[1] = null;
                          rowData[2] = s2b(proceduresRs.getString(nameIndex));
                          rowData[3] = null;
                          rowData[4] = null;
                          rowData[5] = null;
                          rowData[6] = null;
                          rowData[7] = s2b(Integer.toString(procedureResultUnknown));
      
                          procedureRows.add(rowData);
                  }
                }
            } finally {
                SQLException rethrowSqlEx = null;

                if (proceduresRs != null) {
                    try {
                        proceduresRs.close();
                    } catch (SQLException sqlEx) {
                        rethrowSqlEx = sqlEx;
                    }
                }

                if (proceduresStmt != null) {
                    try {
                        proceduresStmt.close();
                    } catch (SQLException sqlEx) {
                        rethrowSqlEx = sqlEx;
                    }
                }

                if (rethrowSqlEx != null) {
                    throw rethrowSqlEx;
                }
            }
        }

        return buildResultSet(fields, procedureRows);
    }


Generated by  Doxygen 1.6.0   Back to index