def HandleSlashCmds(settings, line, query)
status = 1
cmd = unescape(line[1, line.length])
args = cmd.split
case args[0]
when 'a'
settings.opt.align =
toggle(settings, settings.opt.align, "field alignment")
when 'C'
if !args[1]
settings.opt.caption = ""
else
settings.opt.caption = args[1]
end
when 'c', 'connect'
do_connect(settings, args[1])
when 'copy'
do_copy(settings, args[1], args[2], args[3])
when 'd'
if !args[1]
tableList(settings, FALSE, 'b', FALSE)
elsif args[1] == "*"
tableList(settings, FALSE, 'b', FALSE)
tableList(settings, TRUE, 'b', FALSE)
else
tableDesc(settings, args[1])
end
when 'da'
descbuf = "SELECT a.aggname AS aggname, t.typname AS type, "
descbuf += "obj_description (a.oid) as description "
descbuf += "FROM pg_aggregate a, pg_type t "
descbuf += "WHERE a.aggbasetype = t.oid "
if (args[1])
descbuf += "AND a.aggname ~ '^"
descbuf += args[1]
descbuf += "' "
end
descbuf += "UNION SELECT a.aggname AS aggname, "
descbuf += "'all types' as type, obj_description (a.oid) "
descbuf += "as description FROM pg_aggregate a "
descbuf += "WHERE a.aggbasetype = 0"
if (args[1])
descbuf += "AND a.aggname ~ '^"
descbuf += args[1]
descbuf += "' "
end
descbuf += "ORDER BY aggname, type;"
res = SendQuery(settings, descbuf, FALSE, FALSE, 0)
when 'di'
tableList(settings, FALSE, 'i', FALSE)
when 'ds'
tableList(settings, FALSE, 'S', FALSE)
when 'dS'
tableList(settings, FALSE, 'b', TRUE)
when 'dt'
tableList(settings, FALSE, 't', FALSE)
when 'e'
status, query = do_edit(args[1], query)
when 'E'
if args[1]
begin
lastfile = args[1]
File.file?(lastfile) && (mt = File.mtime(lastfile))
editFile(lastfile)
File.file?(lastfile) && (mt2 = File.mtime(lastfile))
fd = File.new(lastfile, "r")
if mt != mt2
MainLoop(settings, fd)
fd.close()
else
if !settings.quiet
printf(STDERR, "warning: %s not modified. query not executed\n", lastfile)
end
fd.close()
end
rescue
end
else
printf(STDERR, "\\r must be followed by a file name initially\n");
end
when 'f'
if args[1]
settings.opt.fieldSep = args[1]
if !settings.quiet
printf(STDERR, "field separater changed to '%s'\n", settings.opt.fieldSep)
end
end
when 'g'
if !args[1]
settings.gfname = nil
else
settings.gfname = args[1]
end
status = 0
when 'h'
if args[2]
args[1] += " " + args[2]
end
do_help(args[1])
when 'i'
if args[1]
begin
fd = File.open(args[1], "r")
MainLoop(settings, fd)
fd.close()
rescue Errno::ENOENT
printf(STDERR, "file named %s could not be opened\n", args[1])
end
else
printf(STDERR, "\\i must be followed by a file name\n")
end
when 'l'
listAllDbs(settings)
when 'H'
settings.opt.html3 =
toggle(settings, settings.opt.html3, "HTML3.0 tabular output")
if settings.opt.html3
settings.opt.standard = FALSE
end
when 'o'
setFout(settings, args[1])
when 'p'
if query
File.print(query)
File.print("\n")
end
when 'q'
status = 2
when 'r'
query = nil
if !settings.quiet
printf(STDERR, "buffer reset(cleared)\n")
end
when 's'
begin
if (args[1])
fd = File.open(args[1], "w")
else
fd = STDOUT
end
Readline::HISTORY.each do |his|
fd.write (his + "\n")
end
if !fd.tty?
begin
fd.close
end
end
rescue
printf(STDERR, "cannot write history \n");
end
when 'm'
settings.opt.standard =
toggle(settings, settings.opt.standard, "standard SQL separaters and padding")
if settings.opt.standard
settings.opt.html3 = FALSE
settings.opt.expanded = FALSE
settings.opt.align = TRUE
settings.opt.header = TRUE
if settings.opt.fieldSep
settings.opt.fieldSep = ""
end
settings.opt.fieldSep = "|"
if !settings.quiet
printf(STDERR, "field separater changed to '%s'\n", settings.opt.fieldSep)
end
else
if settings.opt.fieldSep
settings.opt.fieldSep = ""
end
settings.opt.fieldSep = DEFAULT_FIELD_SEP
if !settings.quiet
printf(STDERR, "field separater changed to '%s'\n", settings.opt.fieldSep)
end
end
when 't'
settings.opt.header =
toggle(settings, settings.opt.header, "output headings and row count")
when 'T'
if !args[1]
settings.opt.tableOpt = nil
else
settings.opt.tableOpt = args[1]
end
when 'x'
settings.opt.expanded =
toggle(settings, settings.opt.expanded, "expanded table representation")
when '!'
do_shell(args[1])
when '?'
slashUsage(settings)
end
return status, query
end