Package pysql :: Module pysqlshell :: Class PysqlShell
[hide private]
[frames] | no frames]

Class PysqlShell

source code


Main class that handle user interaction

Instance Methods [hide private]
 
__init__(self, completekey='tab', stdin=None, stdout=None, silent=False, argv=[])
Shell initialisation
source code
 
preloop(self)
Prepares shell interactive loop
source code
 
loop(self)
Starts shell interactive loop
source code
 
postloop(self)
End of command loop
source code
 
emptyline(self)
Fetches next result if a request is running or do nothning
source code
 
onecmd(self, line)
This method is subclassed just to be able to encapsulate it with a try/except bloc
source code
 
precmd(self, line)
Hook executed just before any command execution.
source code
 
postcmd(self, stop, line)
Hook executed just after command processing.
source code
 
default(self, arg)
Default method if no command is recognized.
source code
 
do_help(self, arg)
Overload do_help to show help from the command parser if it exists: if there is a parser_foo() method, assume this method returns a PysqlOptionParser for the do_foo() method and show the help of the parser, instead of standard help (do_foo() docstring or help_foo())
source code
 
completenames(self, text, *ignored)
Complete commands names.
source code
 
completedefault(self, text, line, begidx, endidx)
pysql specific completion with self.completeList
source code
 
complete_connect(self, text, line, begidx, endidx)
Completion of SID for connect method
source code
 
complete_desc(self, text, line, begidx, endidx)
Completion for command desc
source code
 
complete_edit(self, text, line, begidx, endidx)
Completion for command edit
source code
 
complete_get(self, text, line, begidx, endidx)
Completion for command get
source code
 
complete_set(self, text, line, begidx, endidx)
Completion for command set
source code
 
complete_library(self, text, line, begidx, endidx)
Completion for library command
source code
 
do_connect(self, arg)
Connect to instance
source code
 
do_disconnect(self, arg)
Disconnect from instance
source code
 
do_showCompletion(self, arg)
Shows completion list
source code
 
do_history(self, arg)
Display shell history
source code
 
do_library(self, arg)
Manage user sql request library
source code
 
do_bg(self, arg)
Manages background queries
source code
 
do_commit(self, arg)
Commits pending transaction
source code
 
do_rollback(self, arg)
Rolls back pending transaction
source code
 
do_startup(self, arg)
Starts database up (Oracle v10R2 or upper required)
source code
 
do_shutdown(self, arg)
Shuts database down (Oracle v10R2 or upper required)
source code
 
do_count(self, arg)
Counts segment lines
source code
 
do_compare(self, arg)
Compares schema or object structure and data
source code
 
parser_describe(self) source code
 
do_describe(self, arg)
Emulates the sqlplus desc function
source code
 
parser_addmrpt(self) source code
 
do_addmrpt(self, arg)
Generates ADDM report
source code
 
parser_awrrpt(self) source code
 
do_awrrpt(self, arg)
Generates AWR report
source code
 
parser_sqltune(self) source code
 
do_sqltune(self, arg)
Generates SQL tuning advice
source code
 
parser_durpt(self) source code
 
do_durpt(self, arg)
Generates disk usage report
source code
 
do_assmrpt(self, arg)
Generates ASSM report
source code
 
parser_datamodel(self) source code
 
do_datamodel(self, arg)
Exports a datamodel as a picture
source code
 
parser_dependencies(self) source code
 
do_dependencies(self, arg)
Exports object dependencies as a picture
source code
 
parser_diskusage(self) source code
 
do_diskusage(self, arg)
Exports disk usage as a picture
source code
 
do_ddl(self, arg)
Prints Oracle object DDL
source code
 
do_edit(self, arg)
Edits properties of an Orale object or last SQL statement
source code
 
do_execute(self, arg)
Emulates sqlplus execute
source code
 
do_explain(self, arg)
Explain SQL exec plan
source code
 
parser_session(self) source code
 
do_session(self, arg)
Display Oracle session
source code
 
parser_kill(self) source code
 
do_kill(self, arg)
Kill sessions
source code
 
do_lock(self, arg)
Display instance lock
source code
 
do_trace(self, sid)
Trace a session
source code
 
do_pkgtree(self, arg)
Display PL/SQL package call tree
source code
 
do_datafile(self, arg)
Display datafile
source code
 
do_directory(self, arg)
Display directories
source code
 
do_function(self, arg)
Display functions
source code
 
do_index(self, arg)
Display indexes
source code
 
do_package(self, arg)
Display PL/SQL packages
source code
 
do_procedure(self, arg)
Display PL/SQL procedures
source code
 
do_segment(self, arg)
Display segments (tables, index)
source code
 
do_sequence(self, arg)
Display sequences
source code
 
do_table(self, arg)
Display tables
source code
 
do_trigger(self, arg)
Display triggers
source code
 
do_view(self, arg)
Display view
source code
 
do_tablespace(self, arg)
Display tablespaces
source code
 
do_user(self, arg)
Display users (aka schema)
source code
 
do_profile(self, arg)
Display profiles
source code
 
do_role(self, arg)
Display roles
source code
 
do_last(self, arg)
Display last lines of query set
source code
 
do_next(self, arg)
Display next lines of query set
source code
 
do_get(self, arg)
Get pysql parameter
source code
 
do_set(self, arg)
Set a pysql parameter
source code
 
do_write(self, arg)
Write configuration to disk
source code
 
do_shell(self, arg)
Execute a shell command or open a shell
source code
 
do_lls(self, arg)
A simple local ls
source code
 
do_lcd(self, arg)
Change local directory
source code
 
do_lpwd(self, arg)
Display current work directory
source code
 
do_script(self, arg)
Execute an external sql file, similar to sql*plus @
source code
 
do_watch(self, arg)
Repeat a command
source code
 
do_csv(self, arg)
Dumps sql request to file
source code
 
do_time(self, arg)
Time request execution time
source code
 
do_show(self, arg)
Show parameters
source code
 
do_exit(self, arg)
Close current connection and exit pysql
source code
 
help_assmrpt(self)
online help
source code
 
help_bg(self)
online help
source code
 
help_compare(self)
online help
source code
 
help_connect(self)
online help
source code
 
help_count(self)
online help
source code
 
help_csv(self)
online help
source code
 
help_datafile(self)
online help
source code
 
help_ddl(self)
online help
source code
 
help_directory(self)
online help
source code
 
help_disconnect(self)
online help
source code
 
help_edit(self)
online help
source code
 
help_exit(self)
online help
source code
 
help_explain(self)
online help
source code
 
help_function(self)
online help
source code
 
help_get(self)
online help
source code
 
help_help(self)
online help
source code
 
help_history(self)
online help
source code
 
help_index(self)
online help
source code
 
help_last(self)
online help
source code
 
help_lcd(self)
online help
source code
 
help_library(self)
online help
source code
 
help_lls(self)
online help
source code
 
help_lock(self)
online help
source code
 
help_lpwd(self)
online help
source code
 
help_next(self)
online help
source code
 
help_package(self)
online help
source code
 
help_procedure(self)
online help
source code
 
help_script(self)
online help
source code
 
help_segment(self)
online help
source code
 
help_sequence(self)
online help
source code
 
help_set(self)
online help
source code
 
help_shell(self)
online help
source code
 
help_show(self)
online help
source code
 
help_commit(self)
online help
source code
 
help_rollback(self)
online help
source code
 
help_shutdown(self)
online help
source code
 
help_startup(self)
online help
source code
 
help_table(self)
online help
source code
 
help_tablespace(self)
online help
source code
 
help_time(self, arg)
online help
source code
 
help_trigger(self)
online help
source code
 
help_user(self)
online help
source code
 
help_view(self)
online help
source code
 
help_watch(self)
online help
source code
 
help_write(self)
online help
source code
 
_help_for_search_method(self, searchObject)
generic online help all object search method
source code
 
__animateCursor(self)
Animate cursor to tell user something is really happening End of animation and output flushing is done automatically in postcmd hook
source code
 
__addToCompleteList(self, wordList, theme="general")
Adds wordList the completion list "theme"
source code
 
__getCompletionItems(self, text, themes=["general"], prefix="")
Returns list of item matching text for lists of theme
source code
 
__connect(self, connectString, mode="")
Calls the PysqlDb class to connect to Oracle
source code
 
__disconnect(self)
Disconnects from Oracle and update prompt
source code
 
__setPrompt(self, blank=False, multiline=False, finishedQuery=False)
Sets the prompt according to the connexion state
source code
 
__searchObjet(self, objectType, objectName)
Searches Oracle object
source code
 
__displayCol(self, listOfString)
Displays on column the list of strings
source code
 
__displayTab(self, array, header=None)
Displays in tabular the array using correct width for each column
source code
 
__checkConnection(self)
Raises an exception is there's no connection defined The test is light (db object defined), no real connection test is done.
source code
 
__checkArg(self, arg, argTest)
Checks if arg respect argTest else raise a PysqlException
source code
 
__executeSQL(self, sql, output="tty", fileName="pysql.csv")
Executes SQL request
source code
 
__toScreen(self, result, moreRows, header=True)
Displays first part of fetch on screen
source code
 
__toCsv(self, result, fileName, header=True)
Writes query result to a file
source code
 
__fetchNext(self, nbLines=0)
Fetches next result of current cursor
source code
 
__exit(self)
Closes current connection and exits pysql
source code
 
__askForSnapshotId(self, numDays=0, text="")
Prompts user and asks him to choose a snapshot id
source code
 
complete_conn(self, text, line, begidx, endidx)
Completion of SID for connect method
source code
 
complete_lib(self, text, line, begidx, endidx)
Completion for library command
source code

Inherited from cmd.Cmd: cmdloop, columnize, complete, complete_help, get_names, parseline, print_topics

Class Variables [hide private]
  aliases = {"addm": "addmrpt", "awr": "awrrpt", "conn": "connec...

Inherited from cmd.Cmd: doc_header, doc_leader, identchars, intro, lastcmd, misc_header, nohelp, prompt, ruler, undoc_header, use_rawinput

Method Details [hide private]

__init__(self, completekey='tab', stdin=None, stdout=None, silent=False, argv=[])
(Constructor)

source code 

Shell initialisation

Overrides: cmd.Cmd.__init__

preloop(self)

source code 

Prepares shell interactive loop

Overrides: cmd.Cmd.preloop

postloop(self)

source code 

End of command loop

Overrides: cmd.Cmd.postloop

emptyline(self)

source code 

Fetches next result if a request is running or do nothning

Overrides: cmd.Cmd.emptyline

onecmd(self, line)

source code 

This method is subclassed just to be able to encapsulate it with a try/except bloc

Overrides: cmd.Cmd.onecmd

precmd(self, line)

source code 

Hook executed just before any command execution. This is used to parse command and dispatch it to Oracle or internal pysql functions

Overrides: cmd.Cmd.precmd

postcmd(self, stop, line)

source code 

Hook executed just after command processing. Used to notify running and finished background queries

Returns:
stop flag to end loop
Overrides: cmd.Cmd.postcmd

default(self, arg)

source code 

Default method if no command is recognized. We assume it is a pure SQL request

Overrides: cmd.Cmd.default

do_help(self, arg)

source code 

Overload do_help to show help from the command parser if it exists: if there is a parser_foo() method, assume this method returns a PysqlOptionParser for the do_foo() method and show the help of the parser, instead of standard help (do_foo() docstring or help_foo())

Overrides: cmd.Cmd.do_help

completenames(self, text, *ignored)

source code 

Complete commands names. Same as Cmd.cmd one but with support for command aliases

Overrides: cmd.Cmd.completenames

completedefault(self, text, line, begidx, endidx)

source code 

pysql specific completion with self.completeList

Overrides: cmd.Cmd.completedefault

__addToCompleteList(self, wordList, theme="general")

source code 

Adds wordList the completion list "theme"

Parameters:
  • wordList - list of item to completion
  • theme - string theme
Returns:
None

__getCompletionItems(self, text, themes=["general"], prefix="")

source code 

Returns list of item matching text for lists of theme

Parameters:
  • text (string) - word to match for completion
  • themes (list of string) - list of theme of completion to user
  • prefix - text prefix that should be add to completed text
Returns:
list of string

__setPrompt(self, blank=False, multiline=False, finishedQuery=False)

source code 

Sets the prompt according to the connexion state

Parameters:
  • blank (bool) - if true, no prompt is issue (default is False)
  • finishedQuery (bool) - if true mark prompt with a * to notify a query is finished

__checkArg(self, arg, argTest)

source code 

Checks if arg respect argTest else raise a PysqlException

Parameters:
  • arg (str or list of str) - argument to check. Blank is the arg separator
  • argTest (str) - test with syntaxe like: ">2", "==1", "<=3"
Returns:
None

__executeSQL(self, sql, output="tty", fileName="pysql.csv")

source code 

Executes SQL request

Parameters:
  • sql (str) - SQL request to executed
  • output (str (screen, csv, xml or null)) - output type. Only affect select queries. Null means all result are sent to paradise
  • fileName (str) - name of the file for csv and xml extract

__toScreen(self, result, moreRows, header=True)

source code 

Displays first part of fetch on screen

Parameters:
  • result (list of list of str) - array of tabular data
  • moreRows (bool) - indicates if there's more data to fetching
  • header (bool) - indicates if header must be displayed or not

Class Variable Details [hide private]

aliases

Value:
{"addm": "addmrpt", "awr": "awrrpt", "conn": "connect", "dep": "depend\
encies", "desc": "describe", "disc": "disconnect", "du": "diskusage", \
"ed": "edit", "exec": "execute", "h": "history", "lib": "library", "st\
art": "script", "q": "exit", "quit": "exit"}