Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hyee committed Oct 31, 2015
1 parent f567684 commit 2b8d1c0
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 173 deletions.
Binary file modified bin/ConsoleZ/Console.exe
Binary file not shown.
Binary file modified bin/ConsoleZ/ConsoleHook.dll
Binary file not shown.
Binary file added bin/ConsoleZ/console.chm
Binary file not shown.
20 changes: 18 additions & 2 deletions bin/ConsoleZ/console.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
</font>
<window title="ConsoleZ" icon="" use_tab_icon="1" use_console_title="0" show_cmd="1" show_cmd_tabs="1" use_tab_title="1" trim_tab_titles="20" trim_tab_titles_right="0" main_title_format="?U([%u] )?N({%u} )%m?s( - %s)" tab_title_format="?s( %s):( DBCLI - Not Connected)"/>
<controls show_menu="1" show_toolbar="0" show_statusbar="0" show_tabs="1" hide_single_tab="0" show_scrollbars="1" flat_scrollbars="1" tabs_on_bottom="0" hide_tab_icons="1" show_searchbar="1"/>
<styles caption="1" resizable="1" taskbar_button="1" border="0" inside_border="2" tray_icon="1" quake_like="0" jumplist="1" integrated_ime="1" quake_animation_time="300" hide_when_inactive="0">
<styles caption="1" resizable="1" taskbar_button="1" border="0" inside_border="2" tray_icon="1" quake_like="0" jumplist="0" integrated_ime="1" quake_animation_time="300" hide_when_inactive="0">
<selection_color r="128" g="128" b="128"/>
</styles>
<position x="0" y="0" dock="0" snap="-1" z_order="0" save_position="1" w="1514" h="905" save_size="1"/>
<position x="0" y="0" dock="0" snap="-1" z_order="0" save_position="1" w="1518" h="916" save_size="1"/>
<transparency type="0" active_alpha="206" inactive_alpha="255" r="0" g="0" b="0"/>
<fullscreen start_in_fullscreen="0" fullscreen_monitor="0"/>
</appearance>
Expand Down Expand Up @@ -113,6 +113,22 @@
<hotkey ctrl="0" shift="1" alt="0" extended="1" code="45" command="paste"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="paste_selection"/>
<hotkey ctrl="1" shift="0" alt="0" extended="0" code="81" command="stopscroll"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textselleft"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textselright"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textseltop"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textselbottom"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textselhome"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textselend"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textselpageup"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="textselpagedown"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colselleft"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colselright"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colseltop"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colselbottom"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colselhome"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colselend"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colselpageup"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="colselpagedown"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="scrollrowup"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="scrollrowdown"/>
<hotkey ctrl="0" shift="0" alt="0" extended="0" code="0" command="scrollpageup"/>
Expand Down
5 changes: 4 additions & 1 deletion change log.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
2015-10-28: ! public: minor fixes
2015-10-31: ! public: fix "sys cbc" and "sys sqlheaps"
2015-10-29: + oracle: new command "ora redef"
2015-10-29: ! public: fix repository(missing history)
2015-10-28: ! public: minor fixes;rename jsch-0.1.5.3.jar as jsch.jar
2015-09-20: * public: Minor update on JNLua for LuaJit because the author has stopped the maintenance
2015-09-18: ! public: minor fixes
2015-09-15: + oracle: new command "shell asmdu"
Expand Down
8 changes: 4 additions & 4 deletions docs/program_structure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ Loader.class(JVM to load LUA lib)
|-Load intepreter |->event-|-trigger event
| | |-snoop event
Load modules | |-define env
(init.lua) -> |- Bridge JVM(jnula*.*,jvm.dll) |->set-|-set/get env
| |- Load jdbc library | |-list env
(init.lua) -> |- Setup env paths |->set-|-set/get env
| |- Load JDBC library | |-list env
| |- Load common modules | |-connect
| (re,lpeg,misc,set,event,db_core,tester,etc)-|->db_core.lua-|-exec/query/getvalue
| | |-resultset handler
| |
| Load external modules
| (db-specific modules) ->|-> other external modules
| |-> oracle.lua ->|-Load Oracle jdbc driver
| | | |-Load "ora" module -> scan command list("ora" folder)
| | |-Load "ora" module -> scan command list("ora" folder)
| | | |-Load other internal oracle module(dbmsoutput,etc)
| | Load external oracle modules(folder "plugins")
| |
| |
| |-> mysql.lua
| |-> mssql.lua
Expand Down
Binary file modified lib/dbcli.jar.pack.gz
Binary file not shown.
Binary file modified lib/jline.jar.pack.gz
Binary file not shown.
6 changes: 5 additions & 1 deletion lua/env.lua
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ local cache_prompt,fix_prompt
local prompt_stack={_base="SQL"}

function env.set_prompt(class,default,is_default,level)
default=default and default:upper()
if not env._SUBSYSTEM and default then
default=default:upper()
elseif default then
default=default--:gsub(".*[\27\33].-%a","")
end
class=class or "default"
level=level or (class=="default" or default==prompt_stack._base) and 0 or 3
if prompt_stack[class] and prompt_stack[class]>level then prompt_stack[prompt_stack[class]]=nil end
Expand Down
Binary file modified oracle/ojdbc7.jar.pack.gz
Binary file not shown.
163 changes: 157 additions & 6 deletions oracle/ora/redef.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,160 @@
/*[[Generate the script for online-redefintion on target table, no DDL will be taken. Usage: redef [owner.]<table_name>]]*/

/*[[Generate the script for online-redefintion, no DDL will be taken. Usage: redef [owner.]<orig_table_name>[.partition_name] <new_table_name>]]*/
set feed off
ora _find_object &V1

DECLARE
p
BEGIN
usr VARCHAR2(30) := :object_owner;
org_table VARCHAR2(30) := :object_name;
part_name VARCHAR2(30) := '';
new_table VARCHAR2(30) := UPPER('&V2');

END;
v_sql VARCHAR2(32767) := q'{
DECLARE
usr VARCHAR2(30) := '@user'; --Table owner
org_table VARCHAR2(30) := '@org_table'; --Table to be redefined
new_table VARCHAR2(30) := '@new_table'; --The interim table
part_name VARCHAR2(30) := '@part_name'; --Partition name of org_table
parallel_degree PLS_INTEGER := 16;
options_flag PLS_INTEGER;
cnt PLS_INTEGER;
cols VARCHAR2(32767):='@cols';--Can be null if all columns are equal
PROCEDURE pr(p_msg VARCHAR2,p_isshowtime BOOLEAN:=true) IS
BEGIN --you may use pipelined function instead of dbms_output.put_line
dbms_output.put_line(CASE WHEN p_isshowtime THEN to_char(systimestamp,'yyyy-mm-dd hh24:mi:ssxff3: ') END||p_msg);
END;
BEGIN
dbms_output.enable(null);
pr('Removing all constraints from new table...');
FOR r IN (SELECT constraint_name, constraint_type
FROM all_constraints
WHERE owner = usr
AND table_name = new_table) LOOP
EXECUTE IMMEDIATE 'alter table ' || usr || '.' || new_table || ' drop constraint "' || r.constraint_name || '"';
END LOOP;

pr('Removing all indexes/triggers from new table...');
FOR r IN (SELECT 'drop index ' typ, owner, index_name
FROM all_indexes
WHERE table_owner = usr
AND table_name = new_table
UNION ALL
SELECT 'drop trigger ', owner, trigger_name
FROM all_triggers
WHERE table_owner = usr
AND table_name = new_table) LOOP
EXECUTE IMMEDIATE r.typ || r.owner || '."' || r.index_name || '"';
END LOOP;

--Check if can be redef in PK mode
SELECT COUNT(1)
INTO cnt
FROM (SELECT index_name, COUNT(DECODE(nullable, 'Y', 1)) cnt
FROM all_ind_columns NATURAL
JOIN all_indexes
JOIN all_tab_cols
USING (table_name, column_name, owner)
WHERE table_owner = usr
AND table_name = org_table
AND uniqueness = 'UNIQUE'
GROUP BY index_name)
WHERE cnt = 0;

IF cnt > 0 THEN
options_flag := sys.dbms_redefinition.cons_use_pk;
pr('Entering mode: dbms_redefinition.cons_use_pk');
ELSE
options_flag := sys.dbms_redefinition.cons_use_rowid;
pr('Entering mode: dbms_redefinition.cons_use_rowid');
END IF;
pr('Verifying the practicability of online redefintion...');
sys.dbms_redefinition.can_redef_table(usr, org_table, options_flag, part_name);
pr('Start online redefintion...');
sys.dbms_redefinition.start_redef_table(uname => usr,
orig_table => org_table,
int_table => new_table,
part_name => part_name,
options_flag => options_flag,
col_mapping => regexp_replace(cols,'[ '||chr(10)||']'),
orderby_cols => NULL);
EXECUTE IMMEDIATE 'alter session force parallel ddl parallel ' || parallel_degree;
EXECUTE IMMEDIATE 'alter session force parallel dml parallel ' || parallel_degree;
BEGIN
sys.dbms_redefinition.copy_table_dependents(usr,org_table,new_table,num_errors => cnt);
pr('Start sync data...');
sys.dbms_redefinition.sync_interim_table(usr, org_table, new_table, part_name);
sys.dbms_redefinition.finish_redef_table(usr, org_table, new_table, part_name);
pr('Completion of online redefintion.');
EXCEPTION
WHEN OTHERS THEN
sys.dbms_redefinition.abort_redef_table(usr, org_table, new_table, part_name);
RAISE;
END;

pr('Validating dependencies after online redefintion...');
FOR r IN (SELECT constraint_name, constraint_type
FROM all_constraints
WHERE owner = usr
AND table_name = org_table
AND validated != 'VALIDATED') LOOP
BEGIN
EXECUTE IMMEDIATE 'alter table '|| usr || '.' || org_table ||' enable validate constraint "' || r.constraint_name || '"';
EXCEPTION WHEN OTHERS THEN NULL;
END;
END LOOP;
---Print dep objects
pr(RPAD('*',85,'*'),false);
pr(RPAD('Type',11)||RPAD('Owner',21)||RPAD('Object Name',31)||'Status',false);
pr(RPAD('-',10,'-')||' '||RPAD('-',20,'-')||' '||RPAD('-',30,'-')||' '||RPAD('-',22,'-'),false);
FOR r IN(SELECT 'Constraint' TYPE, owner, constraint_name||'('||constraint_type||')' object_name, status || ' ' || validated status
FROM all_constraints
WHERE table_name = org_table
AND owner = usr
UNION ALL
SELECT 'Index', owner, index_name, status
FROM all_indexes
WHERE table_name = org_table
AND table_owner = usr
UNION ALL
SELECT 'Trigger', a.owner, trigger_name, b.status||' '||a.status
FROM all_triggers a,all_objects b
WHERE table_name = org_table
AND table_owner = usr
AND a.owner=b.owner
AND a.trigger_name=b.object_name
AND b.object_type='TRIGGER') LOOP
pr(RPAD(r.type,11)||RPAD(r.Owner,21)||RPAD(r.Object_Name,31)||r.Status,false);
END LOOP;
pr(RPAD('*',85,'*'),false);
pr('Done.');
END;}';
cols VARCHAR2(32767);
BEGIN
FOR r IN (SELECT NVL2(b.column_name, b.column_name, 'NULL ' || upper(a.column_name)) col,a.column_id idx
FROM all_tab_columns a, all_tab_cols b
WHERE a.owner = usr
AND b.owner(+) = usr
AND a.table_name = new_table
AND b.table_name(+) = org_table
AND upper(a.column_name) = upper(b.column_name(+))
ORDER BY a.column_id) LOOP
cols := cols || CASE WHEN UPPER(r.col)=r.col THEN r.col ELSE '"'||r.col||'"' END||',';
IF mod(r.idx,10)=0 THEN
cols := cols||chr(10)||RPAD(' ', 8);
END IF;
END LOOP;

IF cols IS NULL THEN
raise_application_error(-20001, 'Cannot find object ' || usr || '.' || new_table || '!');
ELSE
cols := trim(',' from trim(cols));
END IF;

dbms_output.enable(NULL);
v_sql := regexp_replace(v_sql, CHR(10) || RPAD(' ', 8), CHR(10));
v_sql := REPLACE(v_sql, '@user', usr);
v_sql := REPLACE(v_sql, '@org_table', org_table);
v_sql := REPLACE(v_sql, '@new_table', new_table);
v_sql := REPLACE(v_sql, '@part_name', part_name);
v_sql := REPLACE(v_sql, '@cols', cols);
dbms_output.put_line(v_sql);
END;
/
36 changes: 2 additions & 34 deletions oracle/oracle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ function oracle:connect(conn_str)
env.warn(tostring(params))
else
self.props={db_user=params[1],db_version=params[2],db_nls_lang=params[3],service_name=params[7],isdba=params[6]=='TRUE' and true or false}
env._CACHE_PATH=env._CACHE_BASE..self.props.service_name..env.PATH_DEL
os.execute('mkdir "'..env._CACHE_PATH..'" 2> '..(env.OS=="windows" and 'NUL' or "/dev/null"))
prompt=(prompt or self.props.service_name):match("^([^,%.&]+)")
env._CACHE_PATH=env._CACHE_BASE..prompt:lower()..env.PATH_DEL
os.execute('mkdir "'..env._CACHE_PATH..'" 2> '..(env.OS=="windows" and 'NUL' or "/dev/null"))
prompt=('%s%s'):format(prompt:upper(),params[8])
env.set_prompt(nil,prompt)
self.session_title=('%s%s - Instance: %s User: %s SID: %s Version: Oracle(%s)'):format(prompt:upper(),params[8], params[5],params[1],params[4],params[2])
Expand Down Expand Up @@ -368,43 +368,11 @@ function oracle:onload()
set_command(self,"create", default_desc, self.exec ,self.check_completion,1,true)
set_command(self,"alter" , default_desc, self.exec ,true,1,true)

set_command(self,"list_access" , default_desc, self.list_access ,false,1,false)
self.C={}
init.load_modules(module_list,self.C)
env.event.snoop('ON_SQL_ERROR',self.handle_error,self,1)
end

function oracle:list_access()
local dir=io.popen('dir /B/S/A:-D '..env.WORK_DIR..'oracle')
local list={}
for n in dir:lines() do
if not n:match("jar$") then
local f=io.open(n,'r')
local txt=f:read("*a")
f:close()
for m in txt:lower():gmatch("g?v_?%$([%w_%$%d]+)") do
list["v$"..m]=1
end
for m in txt:lower():gmatch("dba_([%w_%$%d]+)") do
list["dba_"..m]=1
end
for m in txt:lower():gmatch("all_([%w_%$%d]+)") do
list["dba_"..m]=1
end
for m in txt:lower():gmatch("(sys%.[%w_%$%d]+)") do
list[m]=1
end
end
end

for k,v in pairs(list) do
local res=pcall(self.get_value,self,'select * from '..k..' where 1=2')
if not res then list[k]=nil end
end

print(table.dump(list))
end

function oracle:onunload()
env.set_title("")
init.unload(module_list,self.C)
Expand Down
2 changes: 1 addition & 1 deletion oracle/sys/cbc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ SELECT /*+ordered use_hash(s b o)*/
decode(bitand(flag, 65536), 0, 'N', 'Y') DIRECT
FROM s, x$bh b, dba_objects o
WHERE HLADDR = p1raw
AND b.obj = in(o.object_id,o.data_object_id)
AND b.obj in(o.object_id,o.data_object_id)
AND s.inst_id=b.inst_id
ORDER BY 1,2,3,5;
Loading

0 comments on commit 2b8d1c0

Please sign in to comment.