Skip to content

Commit

Permalink
minor fixes and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hyee committed Nov 26, 2015
1 parent f17cd0e commit 9749414
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 29 deletions.
2 changes: 2 additions & 0 deletions change log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2015-11-26: ! public: fix prompt issue
: fix errors of fetching null CLOB
2015-11-20: ! public: fix the issue of 'unpack200.exe'
: fix the issue of SSH failure with shrinked JRE bundle
: fix the issues of subsystem
Expand Down
17 changes: 8 additions & 9 deletions dbcli.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ SET DBCLI_ENCODING=UTF-8
rem read config file
If exist "data\init.cfg" (for /f "eol=# delims=" %%i in (data\init.cfg) do (%%i))

If not exist "%TNS_ADM%\tnsnames.ora" if defined ORACLE_HOME (set TNS_ADM=%ORACLE_HOME%\network\admin)
SET JAVA="%JRE_HOME%\java.exe"
IF not exist %JAVA% (set JAVA="%JRE_HOME%\bin\java.exe" && IF not exist !JAVA! set JAVA=.\jre\bin\java.exe)
SET PATH=!EXT_PATH!;%PATH%

If not exist "%TNS_ADM%\tnsnames.ora" if defined ORACLE_HOME (set TNS_ADM=%ORACLE_HOME%\network\admin )
for %%x in ("%JRE_HOME%") do set JRE_HOME=%%~sx
IF not exist "%JRE_HOME%\java.exe" if exist "%JRE_HOME%\bin\java.exe" (set JRE_HOME=%JRE_HOME%\bin) else (set JRE_HOME=.\jre\bin)
SET PATH=%JRE_HOME%;%EXT_PATH%;%PATH%
if defined ANSICON_CMD (
SET ANSICON_EXC=nvd3d9wrap.dll;nvd3d9wrapx.dll
SET ANSICON_DEF=!CONSOLE_COLOR!
echo %PROCESSOR_ARCHITECTURE%|findstr /i "64" >nul ||(!JAVA! -version 2>&1 |findstr /i "64-bit" >nul)||(set ANSICON_CMD=.\lib\x86\ansicon.exe)
echo %PROCESSOR_ARCHITECTURE%|findstr /i "64" >nul ||(%JRE_HOME%\java.exe -version 2>&1 |findstr /i "64-bit" >nul)||(set ANSICON_CMD=.\lib\x86\ansicon.exe)
)

rem For win10, don't used both JLINE/Ansicon to escape the ANSI codes
Expand All @@ -28,13 +27,13 @@ rem unpack jar files for the first use
for /r %%i in (*.pack.gz) do (
set "var=%%i" &set "str=!var:@=!"
echo Unpacking %%i to jar file for the first use...
.\jre\bin\unpack200 -q -r "%%i" "!str:~0,-8!"
unpack200 -q -r "%%i" "!str:~0,-8!"
)

(%ANSICON_CMD% !JAVA! -noverify -Xmx384M -cp .\lib\*;.\lib\ext\*%OTHER_LIB% ^
(%ANSICON_CMD% "%JRE_HOME%\java.exe" -noverify -Xmx384M -cp .\lib\*;.\lib\ext\*%OTHER_LIB% ^
-XX:NewRatio=50 -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions ^
-XX:+AggressiveOpts -XX:MaxGCPauseMillis=400 -XX:GCPauseIntervalMillis=8000 ^
-Dfile.encoding=%DBCLI_ENCODING% -Dsun.jnu.encoding=%DBCLI_ENCODING% -Dclient.encoding.override=%DBCLI_ENCODING% ^
-Dinput.encoding=%DBCLI_ENCODING% -Duser.language=en -Duser.region=US -Duser.country=US ^
-Doracle.net.tns_admin="!TNS_ADM!" -Djline.terminal=windows org.dbcli.Loader %DBCLI_PARAMS% %*)||pause
-Doracle.net.tns_admin="%TNS_ADM%" -Djline.terminal=windows org.dbcli.Loader %DBCLI_PARAMS% %* )||pause
EndLocal
Binary file modified lib/dbcli.jar
Binary file not shown.
Binary file modified lib/opencsv.jar
Binary file not shown.
17 changes: 10 additions & 7 deletions lua/db_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function db_Types:get(position,typeName,res,conn)

if value == nil or res:wasNull() then return nil end
if not self[typeName].handler then return value end
return self[typeName].handler(value,'get',conn)
return self[typeName].handler(value,'get',conn,res)
end

local number_types={
Expand Down Expand Up @@ -75,9 +75,11 @@ function db_Types:load_sql_types(className)
end},

[4]={getter='getClob',setter='setStringForClob',--setString
handler=function(result,action,conn)
handler=function(result,action,conn,res)
if action=="get" then
local str=result:getSubString(1,result:length())
local succ,len=pcall(result.length,result)
if not succ then return nil end
local str=result:getSubString(1,len)
result:free()
return str
end
Expand All @@ -87,10 +89,12 @@ function db_Types:load_sql_types(className)
[5]={getter='getBlob',setter='setBytesForBlob', --setBytes
handler=function(result,action,conn)
if action=="get" then
local str=result:getBytes(1,math.min(255,result:length()))
local succ,len=pcall(result.length,result)
if not succ then return nil end
local str=result:getBytes(1,math.min(255,len))
result:free()
local str1=string.rep('%2X',#str):format(str:byte(1,#str)):gsub(' ','0')
return str1
str=string.rep('%2X',#str):format(str:byte(1,#str)):gsub(' ','0')
return str
else
return java.cast(result,'java.lang.String'):getBytes()
end
Expand Down Expand Up @@ -509,7 +513,6 @@ function db_core:exec(sql,args)
self.current_stmt=nil
--is_query=prep:execute()
local is_output,index,typename=1,2,3

for k,v in pairs(params) do
if type(v) == "table" and v[is_output] == "#" then
if type(v[index]) == "table" then
Expand Down
9 changes: 5 additions & 4 deletions lua/env.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ end
local previous_prompt
function env.set_subsystem(cmd,prompt)
if cmd~=nil then
env.set_prompt(cmd,prompt or cmd,false,9)
env._SUBSYSTEM=cmd
env.set_prompt(cmd,prompt or cmd,false,9)
else
env.set_prompt(cmd,nil,false,9)
env._SUBSYSTEM,_G._SUBSYSTEM=nil,nil
env.set_prompt(cmd,nil,false,9)
end
end

Expand Down Expand Up @@ -475,11 +475,12 @@ function env.set_prompt(class,default,is_default,level)
end
end

if not default:match("[%a] *$") then
env.PRI_PROMPT=default
if env._SUBSYSTEM or (default and not default:match("[%w]%s*$")) then
env.PRI_PROMPT=default
else
env.PRI_PROMPT=(default or "").."> "
end

env.CURRENT_PROMPT,env.MTL_PROMPT=env.PRI_PROMPT,(" "):rep(#env.PRI_PROMPT)
return default
end
Expand Down
7 changes: 5 additions & 2 deletions lua/subsystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ function system:call_process(cmd,is_native)
table.insert(self.startup_cmd,1,os.find_extension(self.name))
if not self.work_dir then self.work_dir=env._CACHE_PATH end
self:set_work_dir(self.work_dir,true)

env.log_debug("sqlplus","Command :" ..table.concat(self.startup_cmd," "))
env.log_debug("sqlplus","Work dir: "..self.work_dir)
env.log_debug("sqlplus","Environment: \n"..table.dump(self.env))
--self.process:wait_async(function(...) print(...);print("Sub-system is terminated") end)
if not is_native then
self.process=self.proc:create(self.idle_pattern,self.work_dir,self.startup_cmd,self.env)
self.msg_stack={}
self:run_command(nil,false)
if not self.process then return end
if self.after_process_created then
self:after_process_created()
end
Expand All @@ -111,7 +114,7 @@ function system:call_process(cmd,is_native)
local help=[[
You are entering '%s' interactive mode, work dir is '%s'.
To switch to the native CLI mode, execute '-n' or '.%s -n'.
Type 'lls' to list the files in current work dir, to change the work dir, execute 'llcd <path>'.
Type 'lls' to list the files in current work dir, to change the work dir, execute 'lcd <path>'.
Type '.<cmd>' to run the root command, 'bye' to leave, or 'exit' to terminate."]]
help=help:format(self.name,self.work_dir,self.name):gsub("%s%s%s+",'\n')
print(env.ansi.mask("PromptColor",help))
Expand Down
2 changes: 1 addition & 1 deletion oracle/dbmsoutput.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ output.stmt=marker..[[/*INTERNAL_DBCLI_CMD*/
function output.getOutput(db,sql)
local isOutput=cfg.get("ServerOutput")
local typ=db.get_command_type(sql)
if typ~='DECLARE' and typ~='BEGIN' and typ~='CALL' and typ~='EXECUTE' then return end
if typ=='SELECT' or typ=='WITH' then return end
if not ((output.prev_sql or ""):find(marker,1,true)) and not sql:find(marker,1,true) and not db:is_internal_call(sql) then
local args={enable=isOutput,buff="#VARCHAR",txn="#VARCHAR",lob="#CLOB"}
if not pcall(db.internal_call,db,output.stmt,args) then return end
Expand Down
2 changes: 1 addition & 1 deletion oracle/ora/actives.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
u={(ROOT_SID =1 OR STATUS='ACTIVE' or sql_text is not null) and schemaname=sys_context('userenv','current_schema')}
}
&tmodel : default={0}, m={1}
@COST : 11.0={COALESCE(1440*(sysdate-SQL_EXEC_START),sql_secs/60)},10.0={nvl(sql_secs/60,wait_secs/60)},9.0={null}
@COST : 11.0={COALESCE(1440*(sysdate-sql_exec_start),sql_secs/60)},10.0={nvl(sql_secs,wait_secs)/60},9.0={null}
@CHECK_ACCESS1: dba_objects={dba_objects},all_objects={all_objects}
@CHECK_ACCESS2: gv$px_session/gv$sql/gv$process={}
--]]
Expand Down
2 changes: 1 addition & 1 deletion oracle/ora/anjul/user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ select
username,
account_status,
profile,
authentication_type,
--authentication_type,
created,
expiry_date,
lock_date,
Expand Down
7 changes: 4 additions & 3 deletions oracle/ora/topseg.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*[[Show top segments, default sort by logical reads. Usage: topseg [-d] [-u|-a|<owner>|<object_name>[.<partition_name>]]] [<sort_by_field>]
Options:
-d : Show the detail segment, instead of grouping by object name
-u : Group the segments by schema
-a : Only show the segment statistics of current schema
-u : Only show the segment statistics of current schema
-a : Group the segments by schema
Tips:
The query is based on GV$SEGMENT_STATISTICS which can be very slow. Use 'set instance' to limit the target instance.
--[[
Expand All @@ -12,7 +12,8 @@
--]]
]]*/
set rownum on sqltimeout 1800
SELECT /*+NO_EXPAND MONITOR*/ min(obj#) obj#,owner, &cols object_type,
SELECT /*+NO_EXPAND MONITOR opt_param('_optimizer_sortmerge_join_enabled','false') */
min(obj#) obj#,owner, &cols object_type,
SUM(DECODE(statistic_name, 'logical reads', VALUE)) logi_reads,
SUM(DECODE(statistic_name, 'physical reads', VALUE)) phy_reads,
SUM(DECODE(statistic_name, 'physical writes', VALUE)) phy_writes,
Expand Down
2 changes: 1 addition & 1 deletion oracle/show/tbs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@CHECK_ACCESS: wmsys.wm_concat={wmsys.wm_concat(DISTINCT regexp_substr(file_name, '\w+'))}, default={null}
--]]
]]*/
SELECT /*+no_merge(d) no_merge(f)*/ D.TABLESPACE_NAME,
SELECT /*+no_merge(d) no_merge(f) opt_param('_optimizer_sortmerge_join_enabled','false')*/ D.TABLESPACE_NAME,
siz "MAX_SIZE(G)",
SPACE "FILE_SIZE(G)",
SPACE - NVL(FREE_SPACE, 0) "USED_SPACE(G)",
Expand Down

0 comments on commit 9749414

Please sign in to comment.