如何检索插入的相同GUID? [英] How can I retrieve same GUID which is inserted?

查看:63
本文介绍了如何检索插入的相同GUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我在DB中保存GUID(System.Guid)时遇到一个问题。



如果我创建一个命令,将一个guid插入一个带有二进制(16)列的表来保存它,并且当我检索回来时,实际插入到数据库中的值与guid的值不匹配。



如果您使用连接器检索插入的值并将其与原始值进行比较,则它们将不匹配。



我正在使用5.6数据库。



我使用Binary(16)数据类型来保存GUID(MySQL数据库)是受限制的,因为我正在使用第三派对.dll和第三方数据库表使用二进制(16)数据类型。



我认为这是旧数据库中的错误,但我也面临5.6。有没有解决这个问题。



感谢您的支持。

解决方案

可以有很多造成这种情况的原因不同。也许数据被驱动程序或数据库截断或填充,该值被视为文本,应将其视为二进制等等。



既然你'重新使用数据库无法理解的类型(System.Guid)为什么不尝试将其存储在字符字段中,也许使用固定的lentgh(16字节)。我认为重点只是为存储创建一个独特的价值......



另一方面,如果你想让数据库参与价值生成并且从db的角度来创建一个唯一的值,我建议看看 UUID() [ ^ ]


MySql很快与 GUID 你需要在<$ c $中转换它c>选择查询:

 ... 其中 myguid = UNHEX( REPLACE(6264a302-b749-6a40-a3b6-d5accd6695e5,'   - '' '))





< a href =http://stackoverflow.com/questions/12657399/mysq 1-如何-DO-I-搜寻 - A-GUID> http://stackoverflow.com/questions/12657399/mysql-how-do-i-search-for-a-guid [< a href =http://stackoverflow.com/questions/12657399/mysql-how-do-i-search-for-a-guidtarget =_ blanktitle =New Window> ^ ]


Dear All,

I am facing one issue while saving GUID (System.Guid) in DB.

If I create a command to insert a guid into a table with a Binary(16) column to hold it and the value actually inserted into the database does not match the value of the guid when I retrieve back.

If you use the connector to retrieve the inserted value and compare it with the original, they won't match.

I'm using a 5.6 database.

It is restricted for me to use Binary(16) datatype for saving GUID(MySQL Database) as I am using third party .dll and third party database tables which are using Binary(16) datatype.

I think this was bug in old DB but I am facing in 5.6 also. Is there any resolution of this.

Thanks for your support.

解决方案

There can be a lot of different causes for this. Perhaps the data gets truncated or padded by the driver or the db, the value is treated as text where it should be treated as binary and so forth.

Since you're using a type (System.Guid) that is not understood by the database why not try to store it in a character field, perhaps with fixed lentgh (16 bytes). I take it that the point is only to create a unique value for the storage...

On the other hand if you want that the database participates in the value generation and to create a unique value from the db point of view, I suggest having a look at UUID()[^]


MySql is fiddly with GUID's you need to convert it in your select queries :

... where myguid = UNHEX(REPLACE(6264a302-b749-6a40-a3b6-d5accd6695e5,'-',''))



http://stackoverflow.com/questions/12657399/mysql-how-do-i-search-for-a-guid[^]


这篇关于如何检索插入的相同GUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆