Esempio n. 1
0
        public override string GetColumnSqlType(TableMapping.Column p)
        {
            var clrType = p.ColumnType;

            if (clrType == typeof(Boolean) || clrType == typeof(Byte) || clrType == typeof(UInt16) || clrType == typeof(SByte) || clrType == typeof(Int16) || clrType == typeof(Int32))
            {
                return("integer");
            }
            else if (clrType == typeof(UInt32) || clrType == typeof(Int64))
            {
                return("bigint");
            }
            else if (clrType == typeof(Single) || clrType == typeof(Double) || clrType == typeof(Decimal))
            {
                return("float");
            }
            else if (clrType == typeof(String))
            {
                int len = p.MaxStringLength;
                return("varchar(" + len + ")");
            }
            else if (clrType == typeof(DateTime))
            {
                return("datetime");
            }
            else if (clrType.IsEnum)
            {
                return("integer");
            }
            else
            {
                throw new NotSupportedException("Don't know about " + clrType);
            }
        }
Esempio n. 2
0
        IEnumerable <object> ExecuteQuery(TableMapping map, IDbCommand cmd)
        {
            using (var reader = cmd.ExecuteReader()) {
                var cols = new TableMapping.Column[reader.FieldCount];
                for (int i = 0; i < cols.Length; i++)
                {
                    var name = reader.GetName(i);
                    cols[i] = map.FindColumn(name);
                }

                while (reader.Read())
                {
                    var obj = Activator.CreateInstance(map.MappedType);
                    for (int i = 0; i < cols.Length; i++)
                    {
                        if (cols[i] == null)
                        {
                            continue;
                        }
                        object val = null;
                        if (cols[i].ColumnType.IsEnum)
                        {
                            val = Convert.ChangeType(reader.GetValue(i), typeof(int));
                        }
                        else if (cols[i].ColumnType == typeof(TimeSpan))
                        {
                            val = TimeSpan.FromSeconds(Convert.ToDouble(reader.GetValue(i)));
                        }
                        else if (cols[i].ColumnType == typeof(Guid))
                        {
                            val = reader.GetValue(i);
                            if (val is byte[])
                            {
                                val = new Guid((byte[])val);
                            }
                        }
                        else
                        {
                            val = Convert.ChangeType(reader.GetValue(i), cols[i].ColumnType);
                        }
                        cols[i].SetValue(obj, val);
                    }
                    yield return(obj);
                }
            }
        }
Esempio n. 3
0
        public override string GetColumnDeclSql(TableMapping.Column p)
        {
            string decl = Quote(p.Name) + " " + GetColumnSqlType(p) + " ";

            if (p.IsPK)
            {
                decl += "primary key ";
            }
            if (p.IsAutoInc)
            {
                decl += "autoincrement ";
            }
            if (!p.IsNullable)
            {
                decl += "not null ";
            }

            return(decl);
        }
Esempio n. 4
0
 public abstract string GetColumnSqlType(TableMapping.Column p);
Esempio n. 5
0
 public abstract string GetColumnDeclSql(TableMapping.Column p);