n76e003和啥单片机可互换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了n76e003和啥单片机可互换相关的知识,希望对你有一定的参考价值。

参考技术A 新唐n76e003与STM8S003完全兼容,可以互换。

如何表示可互换的列

【中文标题】如何表示可互换的列【英文标题】:How to represent interchangeable columns 【发布时间】:2013-02-15 03:00:17 【问题描述】:

我不太清楚如何表达,但是有没有一种好方法来实现一个列本质上可以互换的表格?

示例:您有一个用户模型并希望允许两个用户成为“朋友”。对我来说,显而易见的方法是创建一个包含两列(“friend1”和“friend2”)的表,每列都包含用户的密钥。这使得说“是 user1 和 user2 的朋友”之类的话很尴尬,因为您必须检查“(friend1=user1 ANDfriend2=user2) OR (friend1=user2 ANDfriend2=user1)”。它会起作用,但对我来说似乎很尴尬,每次您想从该表中获取某些内容时,您都在查看两列。有没有更优雅的方式来做到这一点?

【问题讨论】:

对不起,我错了——它不能很好地工作(寻找友谊的查询是错误的)。我会删除我的答案。 【参考方案1】:

建立友谊关系时的一个关键选择是确定它是否是双向的。 Twitter 以下是单向友谊和 Facebook 友谊是双向的示例。听起来您致力于双向,所以您有两个选择:

1) 检查两个方向

select *
from friendships 
where (friend1 = 123 and friend2 = 456) OR (friend2 = 123 and friend1 = 456)

2) 总是把较低的user_id 放入friend1,较高的user_id 放入friend2,那么你的测试只需要检查一个方向。这有点难以维护,所以我只是出于性能原因才这样做。

【讨论】:

双向友谊是我想要的,谢谢。即使使用第二个选项,仍然会有一些尴尬的查询(例如,要列出 user1 的朋友,您必须 (select friend1 from friends where friend2=user1) union (select friend2 from friends where friend1=user1)【参考方案2】:

实现这一点的方式可能看起来有点尴尬。这个想法是在一个有两列的表中有一个“friendshipId”:friendshipId 和 user。现在用户可以互换了。

判断 user1 和 user2 是否为好友:

select friendshipId
from friends
group by friendshipId
having sum(case when name = user1 then 1 else 0 end) > 0 and
       sum(case when name = user2 then 1 else 0 end) > 0

明智地使用约束、触发器和存储过程将确保朋友关系只有两个用户,某人不能成为自己的朋友,等等。

【讨论】:

这是一种在数据库级别以最直接的方式表示关系性质的好方法。事实上,在应用层有几个域和独特的约束和一个简单的辅助函数,这可以在没有粗糙的触发器或繁琐的存储过程的情况下完成。例如,您可以将Position 列添加到朋友表(> 0,friendshipID 唯一)。要启动,必要时手动插入数据仍然是微不足道的。不过,我可能会使用自联接而不是 having 子句来查询朋友表。【参考方案3】:

您可以通过 has_many 或 has_and_belongs_to_many 进行 http://guides.rubyonrails.org/association_basics.html

任何您想要链接用户模型的连接表的方式。

例如

class User < ActiveRecord::Base
  has_many :followings
  has_many :followers, :through => :followings, :class_name => "User"
  has_many :followees, :through => :followings, :class_name => "User"
end


class Following < ActiveRecord::Base 
  # fields: follower_id followee_id (person being followed)
  belongs_to :follower, :class_name => "User"
  belongs_to :followee, :class_name => "User"
end

同user has many :users, or must I use another way for a friend based social network?

【讨论】:

以上是关于n76e003和啥单片机可互换的主要内容,如果未能解决你的问题,请参考以下文章

新唐 N76E003单片机里的程序能不能读出?

为啥新唐N76E003单片机用串口烧录不了

单片机成长之路(51基础篇) - 023 N76e003 系统时钟切换到外部时钟

单片机成长之路(51基础篇) - 022 N76e003 APROM模拟EEPROM驱动

新塘 N76E003 单片机在 Keil 中下载程序以及下载引脚复用

为啥新唐N76E003 ISP可以烧录但要勾jump to aprom程序才能运行。重新上电复位都不运行,停在BootLoader