转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> SyBase >> 正文
修复identity 类型字段数据的跳跃(译)         ★★★★

修复identity 类型字段数据的跳跃(译)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:4388 更新时间:2009/4/22 23:09:38
;Identity Gap = %1!", @maxidgap
   print "                     (""identity burning set factor"" = %1! = %2!%%)", @idburn, @idburnpct
   if @v = 12
   begin
   print "                     (Note: ""identity_gap"" has not been set for this table !)"   
   end
end
print " "

if @p1 = NULL and @p2 = NULL -- retrieve current ID value
begin
   print " "
   print " Reading identity value from OAM page... (traceflag 3604 should be enabled !)"
   print " "
   dbcc object_atts (@p0, 0, get)
   print " "
   print " To decode this hexadecimal value, re-run 'sp_identity' with the hexadecimal"
   print " string as a quoted 2nd parameter (you can leave the spaces in). "
   print " Example:  sp_identity %1!, ""the-hex-string-from-the-above-output"" ", @p0
   print " "
   --
   -- only for 12.0+, dbcc listoam will display the values in the OAM and the DES
   --
   --dbcc listoam(@dbname, @p0_id, @indid)
   --
   return 0
end

if upper(@p1) like "[ 0-9A-F]%" -- entered a hex string, decode it
begin

if @p2 != NULL
begin
   print " Error: When decoding a hex value from the OAM page, parameter 3"
   print " (the new identity value) must be NULL."
   exec sp_identity_help
   return -1
end

select @ib = @idlenb -- counts bytes
select @i  = char_length(@p1) -- counts string
select @n = 0 -- holds result

while 1 = 1
begin
   select @c2 = substring(@p1, (char_length(@p1)-@i)+1, 2)

   --print "Step %1!, [%2!]", @ib, @c2
   if upper(substring(@c2,1,1)) = " " -- ignore single space pasted in by user
   begin
     select @i = @i - 1
 continue
   end

   if (upper(@c2) not like "[0-9A-F][0-9A-F]") 
   begin
     print " Error: Invalid characters (%1!) in hex string", @c2
     break
   end

   -- add this byte to the result
   select @vc50 = @vc50 + @c2
   select @j = power(@n256, (@ib-1))
   select @n = @n + @j * hextoint("0x" + @c2)
   --print "Step %1!, exp= %2!, result = %3!", @ib, @j, @n

   -- next byte
   select @ib = @ib - 1 
   if @ib = 0 break  -- ready

   -- next 2 chars
   select @i = @i - 2
   if @i = 0 
   begin
      -- we shouldn't have got here, error
  print " Error: ID column length and specified hex string do not match !"
      break
   end
end

if @ib = 0
begin
   print " Decoded identity value on OAM page = %1!", @n
   print " (hex= %1!)", @vc50
   print " "
   return 0
end
else
begin
   print " Error: Aborted due to error."
   return -1
end
end

if @p2 != NULL -- entered a new ID value, set it
begin

if @p1 != NULL
begin
   print " Error: When setting a new identity value, parameter 2"
   print " (the hex string from the OAM page) must be NULL."
   exec sp_identity_help
   return -1
end

-- set the new ID value
if @p2 <= 0
begin
   print " Error: The new identity value must be >= 0."
   print " "
   exec sp_identity_help
   return -1
end

if char_length(convert(varchar, @p2)) > @idlen
begin
   select @vc50 = replicate("9", @idlen)
   print " Error: New identity value (%1!) is too large", @p2
   print "        for this identity column. The maximum possible value", @p2
   print "        is %1! (%2! positions).", @vc50, @idlen
   return -1
end

if @lsb = 0
begin
   print " "
   print "Internal error in 'sp_identity':"
   print "Cannot figure out byte order on this platform."
   print "Please send a note to 'rob@sypron.nl' with the text of this"
   print "error and your @@version string."
   return -1
end

-- convert the numeric value to hex
select @ib = @idlenb -- counts bytes
select @i  = 15

select @vc50 = NULL -- holds result
select @vb16 = NULL -- holds result
select @n256 = 256
select @n = @p2
set arithabort numeric_truncation off

while 1 = 1
begin
   select @j = power(@n256, @i)

   select @b = @n / @j
   select @n = @n - (@b * @j)
   select @c2 = right(inttohex(@b),2)
   select @b1 = substring(convert(binary(4), @b), @lsb,1)

   select @vb16 = @vb16 + @b1

   --print "Step %1!, @b=%2!, hex(c2)=%3!, hex(b1)=%5!, result=%4!", @i, @b, @c2, @vb16, @b1

   select @i = @i - 1 
   if @i < 0 break  -- ready
end

if @i < 0
begin
   select @vb16 = substring(@vb16, 16 - (@idlenb) + 1, (@idlenb) ) + substring(@vb16, 1, 16 - 

(@idlenb) )

   -- set the new ID value
   dbcc object_atts(@p0, 0, "put", @vb16)

   print " "
   print " Identity value on OAM page has been set to %1!", @p2
   print " (hex= %1!)", @vb16
   print " "
   select @p2 = @p2 + 1
   print " You should now do a 'shutdown with nowait' immediately."
   print " After restarting the server,

上一页  [1] [2] [3] [4] [5]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台