Ejemplo n.º 1
0
 void GetColumns(DBTable table)
 {
     foreach (SelectStatementResultRow row in SelectData(new Query(string.Format(CultureInfo.InvariantCulture, "show columns from `{0}`", ComposeSafeTableName(table.Name)))).Rows)
     {
         int    size;
         string rowValue1, rowValue5, rowValue0;
         if (row.Values[1].GetType() == typeof(Byte[]))
         {
             rowValue1 = System.Text.Encoding.Default.GetString((byte[])row.Values[1]);
             rowValue5 = System.Text.Encoding.Default.GetString((byte[])row.Values[5]);
             rowValue0 = System.Text.Encoding.Default.GetString((byte[])row.Values[0]);
         }
         else
         {
             rowValue1 = (string)row.Values[1];
             rowValue5 = (string)row.Values[5];
             rowValue0 = (string)row.Values[0];
         }
         DBColumnType type            = GetTypeFromString(rowValue1, out size);
         bool         isAutoIncrement = false;
         string       extraValue      = rowValue5;
         if (!string.IsNullOrEmpty(extraValue) && extraValue.Contains("auto_increment"))
         {
             isAutoIncrement = true;
         }
         var column = new DBColumn(rowValue0, false, String.Empty, type == DBColumnType.String ? size : 0, type)
         {
             IsIdentity = isAutoIncrement
         };
         table.AddColumn(column);
     }
 }
Ejemplo n.º 2
0
        static Type PropertyType(Type propertyType, DBColumnType dbColumnType)
        {
            var type = dbColumnType.GetType(propertyType);

            Guard.ArgumentNotNull(dbColumnType, dbColumnType.ToString());
            return(propertyType == type ? propertyType : type);
        }
Ejemplo n.º 3
0
 public InputMemberInfo(XPClassInfo owner, string propertyName, DBColumnType dbColumnType, Type propertyType, bool nonPersistent, XPMemberInfo outputMemberInfo, params Attribute[] attributes)
     : base(owner, propertyName, PropertyType(propertyType, dbColumnType), null, nonPersistent, false)
 {
     Guard.ArgumentNotNull(outputMemberInfo, "outputMemberInfo");
     _outputMemberInfo = outputMemberInfo;
     _conversionType   = propertyType;
     AddAttributes(attributes);
     _importValueConverterAttribute = FindAttributeInfo(typeof(ImportValueConverterAttribute)) as ImportValueConverterAttribute;
 }
Ejemplo n.º 4
0
        void CreateCoreMember(string name, Type owner, DBColumnType dataType, params PersistentAttributeInfo[] persistentAttributeInfos) {

            var extendedCoreTypeMemberInfo = new ExtendedCoreTypeMemberInfo(Session) { Name = name, Owner = owner, DataType = dataType };
            if (persistentAttributeInfos != null)
                foreach (var persistentAttributeInfo in persistentAttributeInfos) {
                    extendedCoreTypeMemberInfo.TypeAttributes.Add(persistentAttributeInfo);
                }
            extendedCoreTypeMemberInfo.Save();
            return;
        }
Ejemplo n.º 5
0
        public static Type GetType(this DBColumnType dbColumnType, Type propertyType)
        {
            Type underlyingNullableType = Nullable.GetUnderlyingType(propertyType);

            if ((((underlyingNullableType != null && underlyingNullableType == typeof(TimeSpan) || propertyType == typeof(TimeSpan))) && dbColumnType == DBColumnType.Double))
            {
                return(propertyType);
            }
            if (dbColumnType == DBColumnType.ByteArray)
            {
                return(typeof(byte[]));
            }
            return(Type.GetType(string.Format("System.{0}", dbColumnType)));
        }
Ejemplo n.º 6
0
        void GetColumns(DBTable table)
        {
            string schema = ComposeSafeSchemaName(table.Name);
            Query  query  = schema == string.Empty ? new Query("select COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @p1",
                                                               new QueryParameterCollection(new OperandValue(ComposeSafeTableName(table.Name))), new[] { "@p1" })
                              : new Query("select COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @p1 and TABLE_SCHEMA = @p2",
                                          new QueryParameterCollection(new OperandValue(ComposeSafeTableName(table.Name)), new OperandValue(schema)), new[] { "@p1", "@p2" });

            foreach (SelectStatementResultRow row in SelectData(query).Rows)
            {
                int          size = row.Values[2] != DBNull.Value ? ((IConvertible)row.Values[2]).ToInt32(CultureInfo.InvariantCulture) : 0;
                DBColumnType type = GetTypeFromString((string)row.Values[1], size);
                table.AddColumn(new DBColumn((string)row.Values[0], false, String.Empty, type == DBColumnType.String ? size : 0, type));
            }
        }
Ejemplo n.º 7
0
 void GetColumns(DBTable table) {
     string schema = ComposeSafeSchemaName(table.Name);
     string safeTableName = ComposeSafeTableName(table.Name);
     Query query = schema == string.Empty ? new Query("SELECT COLUMN_NAME, DATA_TYPE, CHAR_COL_DECL_LENGTH, DATA_PRECISION, DATA_SCALE from USER_TAB_COLUMNS where TABLE_NAME = :p0",
                             new QueryParameterCollection(new OperandValue(safeTableName)), new[] { ":p0" })
                       : new Query("SELECT COLUMN_NAME, DATA_TYPE, CHAR_COL_DECL_LENGTH, DATA_PRECISION, DATA_SCALE from ALL_TAB_COLUMNS where OWNER = :p0 and TABLE_NAME = :p1",
                             new QueryParameterCollection(new OperandValue(schema), new OperandValue(safeTableName)), new[] { ":p0", ":p1" });
     foreach (SelectStatementResultRow row in SelectData(query).Rows) {
         int size = row.Values[2] != DBNull.Value ? ((IConvertible)row.Values[2]).ToInt32(CultureInfo.InvariantCulture) : 0;
         int precision = row.Values[3] != DBNull.Value ? ((IConvertible)row.Values[3]).ToInt32(CultureInfo.InvariantCulture) : 0;
         int scale = row.Values[4] != DBNull.Value ? ((IConvertible)row.Values[4]).ToInt32(CultureInfo.InvariantCulture) : 0;
         DBColumnType type = GetTypeFromString((string)row.Values[1], size, precision, scale);
         table.AddColumn(new DBColumn((string)row.Values[0], false, String.Empty, type == DBColumnType.String ? size : 0, type));
     }
 }
Ejemplo n.º 8
0
        void CreateCoreMember(string name, Type owner, DBColumnType dataType, params PersistentAttributeInfo[] persistentAttributeInfos)
        {
            var extendedCoreTypeMemberInfo = ObjectSpace.CreateObject <ExtendedCoreTypeMemberInfo>();

            extendedCoreTypeMemberInfo.Name     = name;
            extendedCoreTypeMemberInfo.Owner    = owner;
            extendedCoreTypeMemberInfo.DataType = dataType;
            if (persistentAttributeInfos != null)
            {
                foreach (var persistentAttributeInfo in persistentAttributeInfos)
                {
                    extendedCoreTypeMemberInfo.TypeAttributes.Add(persistentAttributeInfo);
                }
            }
            extendedCoreTypeMemberInfo.Save();
        }
Ejemplo n.º 9
0
        private ModificationStatement CreateStatement(XPClassInfo classInfo, object key, DateTime?timestamp, int gcRecord)
        {
            var propertyIndex = 0;

            if (classInfo == null)
            {
                throw new ArgumentNullException(nameof(classInfo));
            }
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            DBColumnType keyType = classInfo.Table.GetColumn(classInfo.Table.PrimaryKey.Columns[0]).ColumnType;

            BinaryOperator critera = new BinaryOperator(new QueryOperand(classInfo.KeyProperty.MappingField, null, keyType), new ParameterValue(propertyIndex++)
            {
                Value = key
            }, BinaryOperatorType.Equal);

            UpdateStatement stm = new UpdateStatement(classInfo.Table, "TheTable")
            {
                Condition = critera
            };

            stm.Operands.Add(new QueryOperand(GCRecordField.StaticName, "N" + propertyIndex++, DBColumnType.Int32));

            if (timestamp != null)
            {
                stm.Operands.Add(new QueryOperand("TimestampColumnName", "N" + propertyIndex++, DBColumnType.DateTime));
            }

            stm.Parameters.Add(new ParameterValue(propertyIndex++)
            {
                Value = gcRecord
            });

            if (timestamp != null)
            {
                stm.Parameters.Add(new ParameterValue(propertyIndex++)
                {
                    Value = timestamp
                });
            }
            Debug.WriteLine(stm);
            return(stm);
        }
Ejemplo n.º 10
0
        void CreateCoreMember(string name, Type owner, DBColumnType dataType, params PersistentAttributeInfo[] persistentAttributeInfos)
        {
            var extendedCoreTypeMemberInfo = new ExtendedCoreTypeMemberInfo(Session)
            {
                Name = name, Owner = owner, DataType = dataType
            };

            if (persistentAttributeInfos != null)
            {
                foreach (var persistentAttributeInfo in persistentAttributeInfos)
                {
                    extendedCoreTypeMemberInfo.TypeAttributes.Add(persistentAttributeInfo);
                }
            }
            extendedCoreTypeMemberInfo.Save();
            return;
        }
Ejemplo n.º 11
0
 public void CreateSimpleMembers(DBColumnType xpoDataType, Func <IPersistentClassInfo, IEnumerable <string> > func)
 {
     foreach (var persistentClassInfo in _persistentClassInfos)
     {
         IEnumerable <string> invoke = func.Invoke(persistentClassInfo);
         if (invoke != null)
         {
             foreach (string name in invoke)
             {
                 var persistentCoreTypeMemberInfo = (IPersistentCoreTypeMemberInfo)_objectSpace.CreateObject(WCTypesInfo.Instance.FindBussinessObjectType <IPersistentCoreTypeMemberInfo>());
                 persistentCoreTypeMemberInfo.Name = name;
                 persistentClassInfo.OwnMembers.Add(persistentCoreTypeMemberInfo);
                 persistentCoreTypeMemberInfo.DataType = xpoDataType;
                 persistentCoreTypeMemberInfo.SetDefaultTemplate(TemplateType.XPReadWritePropertyMember);
             }
         }
     }
 }
Ejemplo n.º 12
0
        private ModificationStatement CreateStatement(XPClassInfo classInfo, object key, Dictionary <string, object> values)
        {
            if (classInfo == null)
            {
                throw new ArgumentNullException(nameof(classInfo));
            }

            var PropertyIndex = 0;

            DBColumnType keyType = classInfo.Table.GetColumn(classInfo.Table.PrimaryKey.Columns[0]).ColumnType;

            BinaryOperator critera = new BinaryOperator(new QueryOperand(classInfo.KeyProperty.MappingField, null, keyType), new ParameterValue(PropertyIndex)
            {
                Value = key
            }, BinaryOperatorType.Equal);

            UpdateStatement stm = new UpdateStatement(classInfo.Table, "TheTable")
            {
                Condition = critera
            };

            foreach (var item in values)
            {
                DBColumnType mappingFieldDBType = classInfo.GetPersistentMember(item.Key).MappingFieldDBType;
                stm.Operands.Add(new QueryOperand(item.Key, "N" + PropertyIndex, mappingFieldDBType));
                stm.Parameters.Add(new ParameterValue(PropertyIndex)
                {
                    Value = item.Value, DBType = mappingFieldDBType
                });
                PropertyIndex++;
            }
            Debug.WriteLine(stm.ToString());
            //stm.Operands.Add(new QueryOperand(GCRecordField.StaticName, null, DBColumnType.Int32));

            //if (timestamp != null)
            //    stm.Operands.Add(new QueryOperand(TimestampColumnName, null, DBColumnType.DateTime));

            //stm.Parameters.Add(new ParameterValue(propertyIndex++) { Value = gcRecord });

            //if (timestamp != null)
            //    stm.Parameters.Add(new ParameterValue(propertyIndex++) { Value = timestamp });

            return(stm);
        }
        private SqlDbType GetSqlDBTypeFromColumnType(DBColumnType ColumnType)
        {
            switch (ColumnType)
            {
            case DBColumnType.Integer: return(SqlDbType.Int);

            case DBColumnType.VarChar: return(SqlDbType.VarChar);

            case DBColumnType.Char: return(SqlDbType.Char);

            case DBColumnType.Binary: return(SqlDbType.Binary);

            case DBColumnType.Decimal: return(SqlDbType.Decimal);

            case DBColumnType.Float: return(SqlDbType.Float);

            case DBColumnType.Text: return(SqlDbType.Text);

            case DBColumnType.DateTime: return(SqlDbType.DateTime);

            case DBColumnType.Bit: return(SqlDbType.Bit);

            case DBColumnType.SmallDateTime: return(SqlDbType.SmallDateTime);

            case DBColumnType.Money: return(SqlDbType.Money);

            case DBColumnType.SmallInt: return(SqlDbType.SmallInt);

            case DBColumnType.Numeric: return(SqlDbType.Decimal);

            case DBColumnType.UniqueIdentifier: return(SqlDbType.UniqueIdentifier);

            case DBColumnType.BigInt: return(SqlDbType.BigInt);

            case DBColumnType.TinyInt: return(SqlDbType.TinyInt);

            case DBColumnType.NVarchar: return(SqlDbType.NVarChar);

            case DBColumnType.TimeStamp: return(SqlDbType.Timestamp);

            default: throw new Exception("Tipo de dados não suportado " + ColumnType.ToString());
            }
        }
Ejemplo n.º 14
0
        public static XPClassInfo AddClass(XPDictionary dict, DBTable table)
        {
            if (table.PrimaryKey.Columns.Count > 1)
            {
                throw new NotSupportedException("Compound primary keys are not supported");
            }
            XPClassInfo classInfo = dict.CreateClass(dict.GetClassInfo(typeof(BasePersistentClass)), table.Name.Replace('.', '_'));

            classInfo.AddAttribute(new PersistentAttribute(table.Name));
            DBColumnType primaryColumnType = table.GetColumn(table.PrimaryKey.Columns[0]).ColumnType;

            classInfo.CreateMember(table.PrimaryKey.Columns[0], DBColumn.GetType(primaryColumnType),
                                   new KeyAttribute(IsAutoGenerationSupported(primaryColumnType)));
            foreach (DBColumn col in table.Columns)
            {
                if (!col.IsKey && col.ColumnType != DBColumnType.Unknown)
                {
                    classInfo.CreateMember(col.Name, DBColumn.GetType(col.ColumnType));
                }
            }
            return(classInfo);
        }
Ejemplo n.º 15
0
 public InputMemberInfo(XPClassInfo owner, string propertyName, DBColumnType dbColumnType, Type propertyType, bool nonPersistent, XPMemberInfo outputMemberInfo, params Attribute[] attributes)
     : base(owner, propertyName, PropertyType(propertyType, dbColumnType), null, nonPersistent, false) {
     Guard.ArgumentNotNull(outputMemberInfo, "outputMemberInfo");
     _outputMemberInfo = outputMemberInfo;
     _conversionType = propertyType;
     AddAttributes(attributes);
 }
Ejemplo n.º 16
0
 static bool IsAutoGenerationSupported(DBColumnType type)
 {
     return(type == DBColumnType.Guid || type == DBColumnType.Int16 || type == DBColumnType.Int32);
 }
Ejemplo n.º 17
0
 static Type PropertyType(Type propertyType, DBColumnType dbColumnType) {
     var type = dbColumnType.GetType(propertyType);
     Guard.ArgumentNotNull(dbColumnType, dbColumnType.ToString());
     return propertyType == type ? propertyType : type;
 }
Ejemplo n.º 18
0
 public ColumnInfo(string name, DBColumnType columnType)
 {
     Name       = name;
     ColumnType = columnType;
 }
Ejemplo n.º 19
0
        static string GetCorePropertyTypeCode(IPersistentMemberInfo persistentMemberInfo)
        {
            DBColumnType dbColumnType = ((IPersistentCoreTypeMemberInfo)persistentMemberInfo).DataType;

            switch (dbColumnType)
            {
            case DBColumnType.Boolean:
                return("bool");

            case DBColumnType.Byte:
                return("byte");

            case DBColumnType.SByte:
                return("sbyte");

            case DBColumnType.Char:
                return("char");

            case DBColumnType.Decimal:
                return("decimal");

            case DBColumnType.Single:
                return("float");

            case DBColumnType.Double:
                return("double");

            case DBColumnType.Int32:
                return("int");

            case DBColumnType.UInt32:
                return("uint");

            case DBColumnType.Int16:
                return("short");

            case DBColumnType.UInt16:
                return("ushort");

            case DBColumnType.Int64:
                return("long");

            case DBColumnType.UInt64:
                return("ulong");

            case DBColumnType.String:
                return("string");

            case DBColumnType.DateTime:
                return("DateTime");

            case DBColumnType.Guid:
                return("Guid");

            case DBColumnType.TimeSpan:
                return("TimeSpan");

            case DBColumnType.ByteArray:
                return("byte[]");

            default:
                return(dbColumnType.ToString());
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// 注意,使用了反射以后,name和type理应不需要从attribute传进来才对,
 /// 构造函数里面只需要传进“额外”的信息,比如主键、外键这些。
 /// 后面FKClass这些信息用
 /// [FKColumn("deptId", DBType.String, false, true, FKClass = "com.SLS_Survey.Model.T_Dept", FKTable = "T_Dept", FKColumn = "id", FKText = "name")]
 /// 这种方式写入
 /// </summary>
 public DBColumn(DBColumnType dbColumnType, String FKTable = null, String FKText = null)
 {
     this.dbColumnType = dbColumnType;
     this.FKTable      = FKTable;
     this.FKText       = FKText;
 }
Ejemplo n.º 21
0
 public ColumnMetadata(string columnName, DBColumnType columnType, string stringFileName)
 {
     ColumnName     = columnName;
     ColumnType     = columnType;
     StringFileName = stringFileName;
 }
Ejemplo n.º 22
0
 public ColumnMetadata(string columnName, DBColumnType columnType)
 {
     ColumnName = columnName;
     ColumnType = columnType;
 }
Ejemplo n.º 23
0
 public QueryOperand(string fColumnName, DBColumnType fColumnType, string fNodeAlias)
 {
     ColumnName = fColumnName;
     ColumnType = fColumnType;
     NodeAlias  = fNodeAlias;
 }
Ejemplo n.º 24
0
 static Type PropertyType(Type propertyType, DBColumnType dbColumnType) {
     var type = GetType(dbColumnType, propertyType);
     Guard.ArgumentNotNull(dbColumnType, dbColumnType.ToString());
     if (propertyType == type)
         return propertyType;
     return type;
 }
Ejemplo n.º 25
0
        public static IPersistentCoreTypeMemberInfo CreateSimpleMember(this IPersistentClassInfo classInfo, DBColumnType dataType, string name)
        {
            var memberInfo = classInfo.CreateMember <IPersistentCoreTypeMemberInfo>(name);

            memberInfo.DataType = dataType;
            return(memberInfo);
        }
Ejemplo n.º 26
0
 static Type GetType(DBColumnType dbColumnType, Type propertyType) {
     Type underlyingNullableType = Nullable.GetUnderlyingType(propertyType);
     if ((((underlyingNullableType != null && underlyingNullableType == typeof(TimeSpan) || propertyType == typeof(TimeSpan))) && dbColumnType == DBColumnType.Double))
         return propertyType;
     if (dbColumnType == DBColumnType.ByteArray)
         return typeof(byte[]);
     return Type.GetType(string.Format("System.{0}", dbColumnType));
 }
Ejemplo n.º 27
0
 public ColumnInfo(string name, DBColumnType columnType) {
     Name = name;
     ColumnType = columnType;
 }