public string columnToString(Column col)
 {
     string cmd = "" + col.Name + " ";
     if (col.AutoIncrement)
     {
         cmd += "serial" + " ";
     }
     else
     {
         cmd += col.Type + " ";
     }
     if (col.PrimaryKey)
         cmd += "PRIMARY KEY ";
     if (col.Unique)
         cmd += "UNIQUE ";
     if (!col.AllowNull)
         cmd += "NOT NULL";
     return cmd;
 }
예제 #2
0
        private void createTable(Type t)
        {
            var tableName = Prefix+t.Name;
            List<Column> collumns = new List<Column>();
            List<Foreign> foreigners = new List<Foreign>();
            var properties = getPropertiesFromClass(t);
            // collumns.Add(new Collumn("id", "INTEGER", true));
            foreach (var p in properties)
            {
                var attr = (DBProperty)p.GetCustomAttribute(typeof(DBProperty));
                var collumn = new Column(p.Name, Helper.getDBType(p.PropertyType), attr.PrimaryKey, attr.AutoIncrement, attr.Unique, attr.AllowNull);
                collumns.Add(collumn);
            }
            var foreignersTypes = getForeignersFromClass(t);
            foreach (var f in foreignersTypes)
            {
                if (tablesCreated.IndexOf(f.PropertyType.GenericTypeArguments[0].Name) < 0)
                    createTable(f.PropertyType.GenericTypeArguments[0]);
                var collumn = new Column("fk_" + f.Name, "INTEGER");
                var foreignKey = new Foreign("fk_" + f.Name, Prefix + f.PropertyType.GenericTypeArguments[0].Name, "id") { Col = collumn };
                collumns.Add(collumn);
                foreigners.Add(foreignKey);
            }
            this.Helper.CreateTable(tableName, collumns, foreigners);

            tablesCreated.Add(t.Name);
        }
 private Foreign getForeginForCollumn(Column c, List<Foreign> foreigners)
 {
     lockIt();
     foreach (var f in foreigners)
     {
         if (f.Col == c)
             return f;
     }
     unlockIt();
     return null;
 }