Database | Proc | Application | Created | Links |
sybsystemprocs | sp_odbc_getversioncolumns | 31 Aug 14 | Defects Dependencies |
1 2 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */ 3 /* 10.0 1.0 9 JUL 93 sproc/src/special_columns */ 4 5 /* 6 ** Messages for "sp_odbc_getversioncolumns" 7 ** 8 ** 17863, "There is no table named %1! in the current database." 9 ** 18039, "Table qualifier must be name of current database." 10 ** 18042, "Illegal value for 'col_type' argument. Legal values are 'V' or 'R'." 11 ** 12 */ 13 14 create procedure sp_odbc_getversioncolumns( 15 @table_name varchar(771), 16 @table_owner varchar(32) = null, 17 @table_qualifier varchar(32) = null, 18 @col_type char(1) = 'R') 19 as 20 declare @indid int 21 declare @table_id int 22 declare @dbname varchar(255) 23 declare @full_table_name varchar(1543) 24 declare @version varchar(32) 25 26 if @@trancount = 0 27 begin 28 set chained off 29 end 30 31 set transaction isolation level 1 32 33 /* get database name */ 34 select @dbname = db_name() 35 36 /* we don't want a temp table unless we're in tempdb */ 37 if (@table_name like "#%" and @dbname != db_name(tempdb_id())) 38 -- if (@table_name like "#%" and @dbname != 'tempdb') -- 12.0 39 -- if @table_name like "#%" and @dbname != db_name(tempdb_id()) -- 12.5 40 41 begin 42 /* 17863, "There is no table named %1! in the current database." */ 43 raiserror 17863, @table_name 44 return (1) 45 end 46 47 if @table_qualifier is not null 48 begin 49 if @dbname != @table_qualifier 50 begin 51 /* 18039, "Table qualifier must be name of current database." */ 52 raiserror 18039 53 return (1) 54 end 55 end 56 57 if @table_owner is null 58 begin /* if unqualified table name */ 59 select @full_table_name = @table_name 60 end 61 else 62 begin /* qualified table name */ 63 select @full_table_name = @table_owner + '.' + @table_name 64 end 65 66 /* get object ID */ 67 select @table_id = object_id(@full_table_name) 68 69 if @col_type = 'V' 70 begin /* if ROWVER, just run that query */ 71 select 72 SCOPE = convert(smallint, 0), 73 COLUMN_NAME = c.name, 74 DATA_TYPE = d.data_type + convert(smallint, 75 isnull(d.aux, 76 ascii(substring("666AAA@@@CB??GG", 77 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 78 - 60)), 79 TYPE_NAME = t.name, 80 COLUMN_SIZE = isnull(d.data_precision, 81 convert(int, c.length)) 82 + isnull(d.aux, convert(int, 83 ascii(substring("???AAAFFFCKFOLS", 84 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 85 - 60)), 86 BUFFER_LENGTH = isnull(d.length, convert(int, c.length)) 87 + convert(int, 88 isnull(d.aux, 89 ascii(substring("AAA<BB<DDDHJSPP", 90 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 91 - 64)), 92 DECIMAL_DIGITS = d.numeric_scale + convert(smallint, 93 isnull(d.aux, 94 ascii(substring("<<<<<<<<<<<<<<?", 95 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 96 - 60)), 97 PSEUDO_COLUMN = convert(smallint, 1) 98 from 99 systypes t, syscolumns c, sybsystemprocs.dbo.spt_datatype_info d 100 where 101 c.id = @table_id 102 and c.type = d.ss_dtype 103 and c.usertype = 80 /* TIMESTAMP */ 104 and t.usertype = 80 /* TIMESTAMP */ 105 106 return (0) 107 end 108 109 if @col_type != 'R' 110 begin 111 /* 18042, "Illegal value for 'col_type' argument. Legal values are 'V' or 'R'." */ 112 113 raiserror 18042 114 return (1) 115 end 116 117 /* An identity column is the most optimal unique identifier */ 118 if exists (select colid from syscolumns 119 where id = @table_id and (status & 128) = 128) 120 begin 121 select 122 SCOPE = convert(smallint, 0), 123 COLUMN_NAME = c.name, 124 DATA_TYPE = d.data_type + convert(smallint, 125 isnull(d.aux, 126 ascii(substring("666AAA@@@CB??GG", 127 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 128 - 60)), 129 TYPE_NAME = rtrim(substring(d.type_name, 130 1 + isnull(d.aux, 131 ascii(substring("III<<<MMMI<<A<A", 132 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 133 - 60), 18)), 134 COLUMN_SIZE = isnull(d.data_precision, convert(int, c.length)) 135 + isnull(d.aux, convert(int, 136 ascii(substring("???AAAFFFCKFOLS", 137 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 138 - 60)), 139 BUFFER_LENGTH = isnull(d.length, convert(int, c.length)) 140 + convert(int, isnull(d.aux, 141 ascii(substring("AAA<BB<DDDHJSPP", 142 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 143 - 64)), 144 DECIMAL_DIGITS = d.numeric_scale + convert(smallint, 145 isnull(d.aux, 146 ascii(substring("<<<<<<<<<<<<<<?", 147 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c.length, 1)) 148 - 60)), 149 PSEUDO_COLUMN = convert(smallint, 1) 150 from 151 syscolumns c, 152 sybsystemprocs.dbo.spt_datatype_info d, 153 systypes t 154 where 155 c.id = @table_id 156 and (c.status & 128) = 128 157 and c.type = d.ss_dtype 158 and c.usertype *= t.usertype 159 160 return (0) 161 end 162 163 /* ROWID, now find the id of the 'best' index for this table */ 164 165 select @indid = ( 166 select min(indid) 167 from sysindexes 168 where 169 status & 2 = 2 /* if unique index */ 170 and id = @table_id 171 and indid > 0) /* eliminate table row */ 172 173 select 174 SCOPE = convert(smallint, 0), 175 COLUMN_NAME = index_col(@full_table_name, indid, c.colid), 176 DATA_TYPE = d.data_type + convert(smallint, 177 isnull(d.aux, 178 ascii(substring("666AAA@@@CB??GG", 179 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c2.length, 1)) 180 - 60)), 181 TYPE_NAME = rtrim(substring(d.type_name, 182 1 + isnull(d.aux, 183 ascii(substring("III<<<MMMI<<A<A", 184 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c2.length, 1)) 185 - 60), 18)), 186 COLUMN_SIZE = isnull(d.data_precision, convert(int, c2.length)) 187 + isnull(d.aux, convert(int, 188 ascii(substring("???AAAFFFCKFOLS", 189 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c2.length, 1)) 190 - 60)), 191 BUFFER_LENGTH = isnull(d.length, convert(int, c2.length)) 192 + convert(int, isnull(d.aux, 193 ascii(substring("AAA<BB<DDDHJSPP", 194 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c2.length, 1)) 195 - 64)), 196 DECIMAL_DIGITS = d.numeric_scale + convert(smallint, 197 isnull(d.aux, 198 ascii(substring("<<<<<<<<<<<<<<?", 199 2 * (d.ss_dtype % 35 + 1) + 2 - 8 / c2.length, 1)) 200 - 60)), 201 PSEUDO_COLUMN = convert(smallint, 1) 202 from 203 sysindexes x, 204 syscolumns c, 205 sybsystemprocs.dbo.spt_datatype_info d, 206 systypes t, 207 syscolumns c2 /* self-join to generate list of index 208 ** columns and to extract datatype names */ 209 where 210 x.id = @table_id 211 and c2.name = index_col(@full_table_name, @indid, c.colid) 212 and c2.id = x.id 213 and c.id = x.id 214 and c.colid < keycnt + (x.status & 16) / 16 215 and x.indid = @indid 216 and c2.type = d.ss_dtype 217 and c2.usertype *= t.usertype 218 219 return (0) 220
exec sp_procxmode 'sp_odbc_getversioncolumns', 'AnyMode' go Grant Execute on sp_odbc_getversioncolumns to public go
RESULT SETS | |
sp_odbc_getversioncolumns_rset_003 | |
sp_odbc_getversioncolumns_rset_002 | |
sp_odbc_getversioncolumns_rset_001 |
DEPENDENCIES |
PROCS AND TABLES USED reads table sybsystemprocs..sysindexes reads table sybsystemprocs..systypes reads table sybsystemprocs..syscolumns reads table sybsystemprocs..spt_datatype_info |