public static String parseDescribeStatement ( String statement ) { Matcher matcher = DescribeToken . matcher ( statement ) ; if ( matcher . matches ( ) ) { String commandWordTerminator = matcher . group ( 1 ) ; if ( OneWhitespace . matcher ( commandWordTerminator ) . matches ( ) ) { String trailings = matcher . group ( 3 ) + ";" + matcher . group ( 4 ) ; // In a valid command, both "trailings" groups should be empty. if ( trailings . equals ( ";" ) ) { // Return the subcommand keyword -- possibly a valid one. return matcher . group ( 2 ) ; } // For an invalid form of the command, // return an approximation of the garbage input. return matcher . group ( 2 ) + " " + trailings ; } if ( commandWordTerminator . equals ( "" ) || commandWordTerminator . equals ( ";" ) ) { return commandWordTerminator ; // EOL or ; reached before subcommand } } return null ; }
Parse DESCRIBE statement for sqlcmd . The result will be if the user just typed DESCRIBE or DESC .