1: internal class Int : IDataType
2: {
3: public Int(Attribute Attribute)
4: : base(Attribute)
5: {
6: Type = "Int";
7: if (Attribute.AutoIncrement)
8: Constraints.Add(new AutoIncrement());
9: }
10: }
11:
12: internal class List:IDataType
13: {
14: public List(Attribute Attribute, Class Class, ClassManager Manager)
15: : base(Attribute)
16: {
17: _Class = Class;
18: Type = "List";
19: Name = Class.OriginalType.Name + "_" + Attribute.Name;
20: Type ObjectType = Attribute.Type.GetGenericArguments()[0];
21: Attribute TempAttribute=new Attribute();
22: TempAttribute.AttributeType=AttributeType.Reference;
23: TempAttribute.Length=Attribute.Length;
24: TempAttribute.Name=Attribute.Name;
25: TempAttribute.Type=ObjectType;
26: IDataType DataType = GlobalFunctions.GetSQLType(TempAttribute, Class, Manager);
27: if (DataType != null)
28: {
29: Columns.Add(DataType);
30: }
31: else
32: {
33: //Find matching class and ID
34: }
35: foreach (Property Property in Class.Properties)
36: {
37: if (Property.Attribute.AttributeType == AttributeType.ID)
38: {
39: IDataType IDType = GlobalFunctions.GetSQLType(Property.Attribute, Class, Manager);
40: IDName = IDType.Name;
41: IDType.Constraints.Clear();
42: if (IDType is NVarChar)
43: {
44: IDType.Constraints.Add(new Size(Property.Attribute.Length));
45: }
46: Columns.Add(IDType);
47: }
48: }
49: }
50:
51: private string IDName = "";
52: private List<IDataType> Columns = new List<IDataType>();
53: private Class _Class;
54:
55: public override string ToString()
56: {
57: StringBuilder Builder = new StringBuilder("CREATE TABLE " + Name + "(");
58:
59: string Splitter = "";
60: string PrimaryKey="";
61: foreach (IDataType Column in Columns)
62: {
63: if (Column != null)
64: {
65: PrimaryKey+=Splitter+Column.Name;
66: Builder.Append(Splitter + Column.ToString());
67: Splitter = ",";
68: }
69: }
70: Builder.Append(", PRIMARY KEY(" + PrimaryKey + ")");
71: Builder.Append(", FOREIGN KEY(" + IDName + ") REFERENCES " + _Class.OriginalType.Name + "(" + IDName + ")");
72: Builder.Append(")");
73:
74: return Builder.ToString();
75: }
76: }