예제 #1
0
        private void GenerateNull(StringBuilder sbSql, DBFieldInfo dbFieldInfo, string tableAliaName, CompareOperater operater)
        {
            sbSql.Append($"{tableAliaName}.{dbFieldInfo.FieldName}");
            sbSql.Append(DBConstant.BLACK_SPACE);

            CompareOperaterAttribute compareOperaterAttribute = CompareOperaterHelper.GetCompareOperaterAttributeByCompareOperater(operater);

            sbSql.Append(compareOperaterAttribute.OperaterFormat);
        }
예제 #2
0
        /// <summary>
        /// 获取数据库字段值转换对象
        /// </summary>
        /// <param name="fieldInfo">字段信息</param>
        /// <returns>数据库字段值转换对象</returns>
        public IDBFiledValueConverter GetDBFiledValueConverter(DBFieldInfo fieldInfo)
        {
            if (fieldInfo == null)
            {
                throw new ArgumentNullException(nameof(fieldInfo));
            }

            return(this.PrimitiveGetDBFiledValueConverter(fieldInfo.OwerTableName, fieldInfo.FieldName));
        }
예제 #3
0
        /// <summary>
        /// 添加数据库字段值转换对象
        /// </summary>
        /// <param name="fieldInfo">字段信息</param>
        /// <param name="dbFiledValueConverter">数据库字段值转换对象</param>
        public void AddConverter(DBFieldInfo fieldInfo, IDBFiledValueConverter dbFiledValueConverter)
        {
            if (fieldInfo == null)
            {
                throw new ArgumentNullException(nameof(fieldInfo));
            }

            this.PrimitiveAddConverter(fieldInfo.OwerTableName, fieldInfo.FieldName, dbFiledValueConverter);
        }
예제 #4
0
        private string GetFiledClrTypeString(DBFieldInfo fieldInfo)
        {
            string      typeStr;
            DBFieldType dbFieldType = DBHelper.GetDbClrFieldType(fieldInfo.DataType);

            switch (dbFieldType)
            {
            case DBFieldType.Binary:
                typeStr = "byte[]";
                break;

            case DBFieldType.DateTime:
                typeStr = fieldInfo.DataType.Name;
                break;

            case DBFieldType.Number:
                if (fieldInfo.FieldName.EndsWith("ID", StringComparison.OrdinalIgnoreCase) ||
                    fieldInfo.FieldName.EndsWith("no", StringComparison.OrdinalIgnoreCase))
                {
                    typeStr = "long";
                }
                else
                {
                    if (fieldInfo.DataType == ClrSystemType.DecimalType)
                    {
                        typeStr = "double";
                    }
                    else
                    {
                        typeStr = fieldInfo.DataType.Name.ToLower();
                    }
                }
                break;

            case DBFieldType.String:
                typeStr = "string";
                break;

            case DBFieldType.Other:
            default:
                typeStr = fieldInfo.DataType.Name.ToLower();
                break;
            }

            return(typeStr);
        }
예제 #5
0
            private DBTableInfo GetTableInfo(List <List <string> > data, List <List <string> > pkData, string tableName)
            {
                DBTableInfo dbTableInfo = new DBTableInfo()
                {
                    TableName  = tableName,
                    FieldInfos = new List <DBFieldInfo>()
                };


                foreach (var row in data)
                {
                    try
                    {
                        string genetalType = "null";
                        string type        = row.ElementAt(0);

                        switch (type)
                        {
                        case "tinyint(1)":
                            genetalType = "bool";
                            break;

                        case string int_1 when int_1.StartsWith("tinyint"):
                        case string int_2 when int_2.StartsWith("int"):
                        case string int_3 when int_3.StartsWith("bigint"):
                        case string int_4 when int_4.StartsWith("numeric"):
                            genetalType = "int";

                            break;

                        case string string_1 when string_1.StartsWith("varchar"):
                        case string string_2 when string_2.StartsWith("longtext"):
                        case string string_3 when string_3.StartsWith("character"):
                        case string string_4 when string_4.StartsWith("character varying"):
                            genetalType = "string";

                            break;

                        case string dateTime_1 when dateTime_1.StartsWith("datetime"):
                        case string dateTime_2 when dateTime_2.StartsWith("date"):
                            genetalType = "datetime";

                            break;

                        default:
                            break;
                        }

                        bool isPk = false;

                        if (pkData.Any(i => i.ElementAt(0) == row.ElementAt(1)))
                        {
                            isPk = true;
                        }

                        DBFieldInfo field = new DBFieldInfo()
                        {
                            //Id = reader.GetInt32(0),
                            Name        = row.ElementAt(1),
                            Type        = row.ElementAt(0),
                            GeneralType = genetalType,
                            Nullable    = row.ElementAt(2) == "YES",
                            // df value needed?
                            IsPrimaryKey = isPk
                        };


                        dbTableInfo.FieldInfos.Add(field);
                    }
                    catch (Exception ex)
                    {
                        // _logger.LogError(ex, ex.Message);
                    }
                }

                return(dbTableInfo);
            }
예제 #6
0
            private DBTableInfo GetTableInfo(DbCommand command, string tableName)
            {
                DBTableInfo dbTableInfo = new DBTableInfo()
                {
                    TableName  = tableName,
                    FieldInfos = new List <DBFieldInfo>()
                };

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        try
                        {
                            string genetalType = "null";
                            string type        = reader.GetString(1);
                            if (type.Contains("("))
                            {
                                type = type.Substring(0, type.IndexOf('('));
                            }

                            type = type.ToLower();

                            switch (type)
                            {
                            case "tinyint":     // TODO SmallInt 1 is bool
                            case "int":
                            case "bigint":
                            case "smallint":
                                genetalType = "int";
                                break;

                            case "varchar":
                                genetalType = "string";
                                break;

                            case "datetime":
                                genetalType = "datetime";
                                break;

                            default:
                                break;
                            }

                            DBFieldInfo field = new DBFieldInfo()
                            {
                                //Id = reader.GetInt32(0),
                                Name        = reader.GetString(0),
                                Type        = reader.GetString(1),
                                GeneralType = genetalType,
                                Nullable    = reader.GetString(2) == "YES",
                                // df value needed?
                                IsPrimaryKey = reader.GetString(3) == "PRI"
                            };


                            dbTableInfo.FieldInfos.Add(field);
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError(ex, ex.Message);
                        }
                    }
                }

                return(dbTableInfo);
            }