-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsqshrc
241 lines (217 loc) · 5.44 KB
/
sqshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
\set semicolon_hack=on
\set banner=Off
\set bcp_colsep='#'
\set bcp_rowsep=''
\set bcp_trim=Off
#\set charset='iso_1'
\set charset='iso_8859-1'
\set datetime='%Y %b %e %H:%M:%S'
\set encryption=On
\set history='$HOME/.sqsh/sqshhist_$DSQUERY'
\set histsize=200
\set hostname=`hostname`
\set keyword_completion=exact
\set readline_histsize=200
#\set xgeom=100x30
\set with=255
#
# Version dependent variable settings.
#
\if [ "$version" = "sqsh-2.1.7" -a "$TERM" != "linux" -a "$TERM" != "console" ]
\set term_title='$DSQUERY ($hostname)'
\fi
\if [ "$version" = "sqsh-2.1.7" ]
\set histunique=On
\set hist_auto_save=10
\set ignoreeof=On
\set keyword_file='$HOME/.sqsh/sqsh_words'
\set login_timeout=60
\set readline_history='$HOME/.sqsh/sqshread_$DSQUERY'
\set session='$HOME/.sqsh/.sqsh_session'
\set tmp_dir='$HOME/tmp'
\set xwin_title='$DSQUERY result $histnum'
\fi
#
# Set a color prompt
#
# Color codes are presented in a string between {}. If sqsh encounters a {
# in the prompt string it will assume a colorcode is supplied and will act
# as such. The color definition consists of three values separated by ;
# The last colorcode for the background may be ommitted.
#
# Color definitions byte 1,2,3
# The first code defines the Color Attribute Code with possible values:
# 0=none 1=bold
# The second value defines the Text Color Code:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# The third value defines the Background Color Code:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#
# Example:
# Cyan text in white background "{0;36;47}"
# Bold yellow text "{1;33}"
#
# sqsh will translate the colorcodes to an actual colorcode string that
# is presented to readline: for example "\001\033[0;36;47m\002"
#
# Note that if you want to use curly brackets in your prompt, you have to
# escape colorization by specifying a double brace, like {{...}}.
# Using color codes is only usefull if readline support is compiled in sqsh.
#
\if [ "$version" = "sqsh-2.1.7" -o "$version" = "sqsh-2.1.6" ]
\set prompt_color='{0;36;47}'
\set text_color='{0;37}'
\set prompt='$prompt_color[$histnum] $DSQUERY.$username.$database.$lineno>$text_color '
\set prompt2='$prompt_color[sqsh]-->$text_color '
\fi
#
# cd <database>
#
# Replacement for issuing a 'use <db>' with the following
# exceptions:
# o There is no need to issue a 'go' (that is done for you)
# o Issuing a 'cd -' will return you to the previous
# database you were using (provided that you switched to
# this database using cd as well).
# o Just 'cd' will return you to the master database.
#
\func -x cd
\if [ $# -gt 1 ]
\echo "usage: cd [ db | - ]"
\return 1
\fi
\if [ $# -eq 1 ]
\set parm=${1}
\else
\set parm=master
\fi
\if [ "${parm}" = "-" ]
\set db=${prev_db}
\else
\set db=${parm}
\fi
\if [ -z "${db}" ]
\set db=master
\fi
\set cur_db=$database
use $db
go
\if [ $? -eq 0 ]
\set prev_db=$cur_db
\fi
\done
#
# \db
#
# Lists the names of all databases in the system.
#
\func -x \db
select name = convert(varchar(30),name)
from master..sysdatabases
order by name
go -f
\done
#
# \logins
#
# Show logins
#
\func -x \logins
declare @allauth int
select @allauth = low
from master.dbo.spt_values
where type="ua" and upper(name) = 'ANY'
select "Suid" = l.suid
,"Name" = convert(varchar(25),l.name)
,"Pwdate" = l.pwdate
,"Auth mech" = convert(char(12), isnull(v.name,'NONE'))
,"Default database" = convert(varchar(30),l.dbname)
from master.dbo.spt_values v
,master.dbo.syslogins l
where v.low =* (l.status & @allauth)
and v.type ="ua"
order by l.suid
go
\done
#
# \obj <type>
#
# Where <type> is a valid type as defined in the type column
# of sysobjects. This function will list the name of all
# objects matching that type.
#
\func -x \obj
\if [ $# -ne 1 ]
\echo "use: \obj [U|V|S|TR|P|...]"
\return 1
\fi
set quoted_identifier off
select name = convert(varchar(30),name)
from sysobjects
where type = "${1}"
order by name
go
\done
#
# \rc
#
# Generate sp_dbcc_runcheck statements for all databases configured in dbccdb.
#
\func -x \rc
select distinct "exec sp_dbcc_runcheck " + db_name(dbid) as "DBCC checkstorage/checkverify"
from dbccdb..dbcc_config
where dbid > 0
order by dbid
go -f
\done
#
# \switch
#
# Reconnect to another server using the same username and password as the
# current connection and take care of the history buffers of the old and new
# server.
#
\func -x \switch
\if [ $# -ne 1 ]
\echo "Use: \switch server_name"
\return 1
\fi
\hist-save
\set history=""
\buf-del 1-$histnum
\echo "Switch connection to server ${1}"
\reconnect -S${1}
\if [ "${DSQUERY}" != "${1}" ]
\echo "Switch to server ${1} failed"
\fi
\set history='$HOME/.sqsh/sqshhist_$DSQUERY'
\hist-load
\done
#
# \v
#
# Show the ASE version string.
#
\func -x \v
print @@version
go -h -f
\done
#
# Set shortcut \h to display all history buffers
# Set shortcut \hi to display last 20 history buffers with extended info
#
\alias \h='\history'
\if [ "$version" = "sqsh-2.1.7" ]
\alias \hi='\history -i -x20'
\fi
#
# Start a bash login shell from sqsh
#
\alias \s='\shell bash -l'
#
# Set short aliases for style
#
\alias \hori='\set style=horizontal'
\alias \vert='\set style=vertical'
\alias \pretty='\set style=pretty'
\alias \csv='\set style=csv'