Exemple #1
0
 public static OracleColumn BuildColumnValueColumn(OracleDataType columnType)
 {
     return
         (new OracleColumn
     {
         Name = ColumnNameColumnValue,
         DataType = columnType,
         Nullable = true
     });
 }
Exemple #2
0
		public static OracleColumn BuildColumnValueColumn(OracleDataType columnType)
		{
			return
				new OracleColumn
				{
					Name = ColumnNameColumnValue,
					DataType = columnType,
					Nullable = true
				};
		}
Exemple #3
0
        public static string ResolveFullTypeName(OracleDataType dataType, int?characterSize = null)
        {
            if (!dataType.IsPrimitive)
            {
                return(dataType.FullyQualifiedName.ToString());
            }

            var name          = dataType.FullyQualifiedName.Name.Trim('"');
            var effectiveSize = String.Empty;

            switch (name)
            {
            case TerminalValues.NVarchar2:
            case TerminalValues.NVarchar:
            case TerminalValues.Varchar2:
            case TerminalValues.Varchar:
            case TerminalValues.NChar:
            case TerminalValues.Char:
                var effectiveLength = characterSize ?? dataType.Length;
                if (effectiveLength.HasValue)
                {
                    var unit = dataType.Unit == DataUnit.Byte ? " BYTE" : " CHAR";
                    effectiveSize = $"({effectiveLength}{(dataType.Unit == DataUnit.NotApplicable ? null : unit)})";
                }

                name = $"{name}{effectiveSize}";
                break;

            case TerminalValues.Float:
            case TerminalValues.Number:
                var decimalScale = dataType.Scale > 0 ? $", {dataType.Scale}" : null;
                if (dataType.Precision > 0 || dataType.Scale > 0)
                {
                    name = $"{name}({(dataType.Precision == null ? "*" : Convert.ToString(dataType.Precision))}{decimalScale})";
                }

                break;

            case TerminalValues.Raw:
                name = $"{name}({dataType.Length})";
                break;

            case TerminalValues.Timestamp:
            case OracleDatabaseModelBase.BuiltInDataTypeTimestampWithTimeZone:
                if (dataType.Scale.HasValue)
                {
                    name = name.Replace(TerminalValues.Timestamp, $"{TerminalValues.Timestamp}({dataType.Scale})");
                }

                break;
            }

            return(name);
        }
Exemple #4
0
		public static string ResolveFullTypeName(OracleDataType dataType, int? characterSize = null)
		{
			if (!dataType.IsPrimitive)
			{
				return dataType.FullyQualifiedName.ToString();
			}

			var name = dataType.FullyQualifiedName.Name.Trim('"');
			var effectiveSize = String.Empty;
			switch (name)
			{
				case TerminalValues.NVarchar2:
				case TerminalValues.NVarchar:
				case TerminalValues.Varchar2:
				case TerminalValues.Varchar:
				case TerminalValues.NChar:
				case TerminalValues.Char:
					var effectiveLength = characterSize ?? dataType.Length;
					if (effectiveLength.HasValue)
					{
						var unit = dataType.Unit == DataUnit.Byte ? " BYTE" : " CHAR";
						effectiveSize = $"({effectiveLength}{(dataType.Unit == DataUnit.NotApplicable ? null : unit)})";
					}

					name = $"{name}{effectiveSize}";
					break;
				case TerminalValues.Float:
				case TerminalValues.Number:
					var decimalScale = dataType.Scale > 0 ? $", {dataType.Scale}" : null;
					if (dataType.Precision > 0 || dataType.Scale > 0)
					{
						name = $"{name}({(dataType.Precision == null ? "*" : Convert.ToString(dataType.Precision))}{decimalScale})";
					}
					
					break;
				case TerminalValues.Raw:
					name = $"{name}({dataType.Length})";
					break;
				case TerminalValues.Timestamp:
					if (dataType.Scale.HasValue)
					{
						name = $"{name}({dataType.Scale})";
					}
					
					break;
			}

			return name;
		}
Exemple #5
0
 private static string GetFunctionParameterTypeName(OracleDataType dataType)
 {
     return(dataType.IsPrimitive ? dataType.FullyQualifiedName.NormalizedName : TypeCodeObject);
 }
Exemple #6
0
 private static OracleObjectIdentifier GetFunctionParameterCustomTypeIdentifier(OracleDataType dataType)
 {
     return(dataType.IsPrimitive ? OracleObjectIdentifier.Empty : dataType.FullyQualifiedName);
 }
Exemple #7
0
        public static bool TryResolveDataTypeFromExpression(StatementGrammarNode expressionNode, OracleColumn column)
        {
            if (expressionNode == null || expressionNode.TerminalCount == 0 || !String.Equals(expressionNode.Id, NonTerminals.Expression))
            {
                return(false);
            }

            expressionNode = expressionNode.UnwrapIfNonChainedExpressionWithinParentheses(out var isChainedExpression);
            if (isChainedExpression)
            {
                return(false);
            }

            var analyzedNode = expressionNode[NonTerminals.CastOrXmlCastFunction, NonTerminals.CastFunctionParameterClause, NonTerminals.AsDataType, NonTerminals.DataType];

            if (analyzedNode != null)
            {
                column.DataType = OracleReferenceBuilder.ResolveDataTypeFromNode(analyzedNode);
                column.Nullable = true;
                return(true);
            }

            if (String.Equals(expressionNode.FirstTerminalNode.Id, Terminals.Collect))
            {
                column.DataType = OracleDataType.DynamicCollectionType;
                column.Nullable = true;
                return(true);
            }

            var    tokenValue = expressionNode.FirstTerminalNode.Token.Value;
            string literalInferredDataTypeName = null;
            var    literalInferredDataType     = new OracleDataType();
            var    nullable = false;

            switch (expressionNode.FirstTerminalNode.Id)
            {
            case Terminals.StringLiteral:
                if (expressionNode.TerminalCount != 1)
                {
                    break;
                }

                if (tokenValue[0] == 'n' || tokenValue[0] == 'N')
                {
                    literalInferredDataTypeName = TerminalValues.NChar;
                }
                else
                {
                    literalInferredDataTypeName = TerminalValues.Char;
                }

                literalInferredDataType.Length = tokenValue.ToPlainString().Length;
                nullable = literalInferredDataType.Length == 0;

                break;

            case Terminals.NumberLiteral:
                if (expressionNode.TerminalCount != 1)
                {
                    break;
                }

                switch (tokenValue[tokenValue.Length - 1])
                {
                case 'f':
                case 'F':
                    literalInferredDataTypeName = TerminalValues.BinaryFloat;
                    break;

                case 'd':
                case 'D':
                    literalInferredDataTypeName = TerminalValues.BinaryDouble;
                    break;

                default:
                    literalInferredDataTypeName = TerminalValues.Number;
                    break;
                }

                /*if (includeLengthPrecisionAndScale)
                 * {
                 *      literalInferredDataType.Precision = GetNumberPrecision(tokenValue);
                 *      int? scale = null;
                 *      if (literalInferredDataType.Precision.HasValue)
                 *      {
                 *              var indexDecimalDigit = tokenValue.IndexOf('.');
                 *              if (indexDecimalDigit != -1)
                 *              {
                 *                      scale = tokenValue.Length - indexDecimalDigit - 1;
                 *              }
                 *      }
                 *
                 *      literalInferredDataType.Scale = scale;
                 * }*/

                break;

            case Terminals.Date:
                if (expressionNode.TerminalCount == 2)
                {
                    literalInferredDataTypeName = TerminalValues.Date;
                }

                break;

            case Terminals.Timestamp:
                if (expressionNode.TerminalCount == 2)
                {
                    var timestampStringValue = expressionNode.LastTerminalNode.Token.Value.ToPlainString();
                    var timeZoneElement      = OracleStatementValidator.TimestampValidator.Match(timestampStringValue).Groups["Timezone"];
                    literalInferredDataTypeName   = timeZoneElement.Success ? OracleDatabaseModelBase.BuiltInDataTypeTimestampWithTimeZone : TerminalValues.Timestamp;
                    literalInferredDataType.Scale = 9;
                }

                break;
            }

            if (literalInferredDataTypeName != null)
            {
                literalInferredDataType.FullyQualifiedName = OracleObjectIdentifier.Create(null, literalInferredDataTypeName);
                column.DataType = literalInferredDataType;
                column.Nullable = nullable;
                return(true);
            }

            return(false);
        }
Exemple #8
0
		private static bool TryResolveDataTypeFromExpression(StatementGrammarNode expressionNode, OracleColumn column)
		{
			if (expressionNode == null || expressionNode.TerminalCount == 0 || !String.Equals(expressionNode.Id, NonTerminals.Expression))
			{
				return false;
			}

			var isChainedExpression = expressionNode[NonTerminals.ExpressionMathOperatorChainedList] != null;
			if (isChainedExpression)
			{
				return false;
			}

			var analyzedNode = expressionNode[NonTerminals.ParenthesisEnclosedExpression, NonTerminals.Expression];
			if (analyzedNode != null)
			{
				return TryResolveDataTypeFromExpression(analyzedNode, column);
			}

			analyzedNode = expressionNode[NonTerminals.CastOrXmlCastFunction, NonTerminals.CastFunctionParameterClause, NonTerminals.AsDataType, NonTerminals.DataType];
			if (analyzedNode != null)
			{
				column.DataType = OracleReferenceBuilder.ResolveDataTypeFromNode(analyzedNode);
				column.Nullable = true;
				return true;
			}

			if (String.Equals(expressionNode.FirstTerminalNode.Id, Terminals.Collect))
			{
				column.DataType = OracleDataType.DynamicCollectionType;
				column.Nullable = true;
				return true;
			}

			var tokenValue = expressionNode.FirstTerminalNode.Token.Value;
			string literalInferredDataTypeName = null;
			var literalInferredDataType = new OracleDataType();
			var nullable = false;
			switch (expressionNode.FirstTerminalNode.Id)
			{
				case Terminals.StringLiteral:
					if (expressionNode.TerminalCount != 1)
					{
						break;
					}

					if (tokenValue[0] == 'n' || tokenValue[0] == 'N')
					{
						literalInferredDataTypeName = TerminalValues.NChar;
					}
					else
					{
						literalInferredDataTypeName = TerminalValues.Char;
					}

					literalInferredDataType.Length = tokenValue.ToPlainString().Length;
					nullable = literalInferredDataType.Length == 0;

					break;
				case Terminals.NumberLiteral:
					if (expressionNode.TerminalCount != 1)
					{
						break;
					}

					literalInferredDataTypeName = TerminalValues.Number;

					/*if (includeLengthPrecisionAndScale)
					{
						literalInferredDataType.Precision = GetNumberPrecision(tokenValue);
						int? scale = null;
						if (literalInferredDataType.Precision.HasValue)
						{
							var indexDecimalDigit = tokenValue.IndexOf('.');
							if (indexDecimalDigit != -1)
							{
								scale = tokenValue.Length - indexDecimalDigit - 1;
							}
						}

						literalInferredDataType.Scale = scale;
					}*/

					break;
				case Terminals.Date:
					if (expressionNode.TerminalCount == 2)
					{
						literalInferredDataTypeName = TerminalValues.Date;
					}

					break;
				case Terminals.Timestamp:
					if (expressionNode.TerminalCount == 2)
					{
						literalInferredDataTypeName = TerminalValues.Timestamp;
						literalInferredDataType.Scale = 9;
					}

					break;
			}

			if (literalInferredDataTypeName != null)
			{
				literalInferredDataType.FullyQualifiedName = OracleObjectIdentifier.Create(null, literalInferredDataTypeName);
				column.DataType = literalInferredDataType;
				column.Nullable = nullable;
				return true;
			}

			return false;
		}