我有以下代码:
[Flags()]
public enum Foo
{
Unknown = 0x00,
A = 0x01,
B = 0x02,
C = 0x04,
D = 0x08,
}
public static class Extensions
{
public static List<Foo> AsList(this Foo types)
{
List<Foo> list = new List<Foo>();
foreach(Foo sT in Enum.GetValues(typeof(Foo)))
{
if ((sT & types) == sT) list.Add(sT);
}
return list;
}
}
class Program
{
static void Main(string[] args)
{
Foo foo1 = Foo.A | Foo.B | Foo.C;
Foo foo2 = Foo.C | Foo.B;
Foo firstInfoo1 …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
//Interface defining a Change method
internal interface IChangeBoxedPoint
{
void Change(Int32 x, Int32 y);
}
internal struct Point : IChangeBoxedPoint
{
private Int32 m_x, m_y;
public Point(Int32 x, Int32 y)
{
m_x = x;
m_y = y;
}
public void Change(Int32 x, Int32 y)
{
m_x = x; m_y = y;
}
public override string ToString()
{
return String.Format("({0}, {1})", m_x.ToString(), m_y.ToString());
}
}
public class Program
{
static void Main(string[] args)
{
Point p = new Point(1, 1); …Run Code Online (Sandbox Code Playgroud) 我知道REPLACE并且ON DUPLICATE UPDATE,如果我的员工存在,我想插入的东西,如果确实如此,则根据条件更新一些列.
例如:My Table列
Id(Auto Generated), EmpId, EmpName, Salary, Version
12 ABW72 John 1000 100
Run Code Online (Sandbox Code Playgroud)
EmpId 不是主键,但有一个 Unique Index
现在,如果ABW72不存在,一INSERT会做,UPDATE如果存在EmpId = ABW72,只有当version is > 20.此版本是存储在DB中的版本.如何在MySql中做到这一点.
我们在应用程序方面尝试过这样的事情:
Step 1: Select with a lock on EmpId=ABW72. A lock would be taken if it exists.
Step 2: If Step1 returned 0 records, Insert Ignore OR Insert
Step 2: If Step1 returned 1 record, just update based on the …Run Code Online (Sandbox Code Playgroud)