Пример #1
0
        /// <summary>
        /// Creates a column from the given row.
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private SqlColumn GetSchemaColumn(DataRow row)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            // get...
            string nativeName         = (string)row["column_name"];
            string isNullableAsString = (string)row["is_nullable"];
            string dataTypeAsString   = (string)row["data_type"];

            // mbr - 2008-08-31 - MySQL implementation means this int has to be a long?
            //int length = -1;
            long length = -1;

            if (row.IsNull("character_maximum_length") == false)
            {
                //length = ConversionHelper.ToInt32(row["character_maximum_length"], Cultures.System);
                length = ConversionHelper.ToInt64(row["character_maximum_length"], Cultures.System);
            }

            // get...
            if (Connection == null)
            {
                throw new InvalidOperationException("Connection is null.");
            }

            // nullable?
            EntityFieldFlags flags = EntityFieldFlags.Normal;

            if (string.Compare(isNullableAsString, "yes", true, System.Globalization.CultureInfo.InvariantCulture) == 0)
            {
                flags |= EntityFieldFlags.Nullable;
            }

            // large?
            FieldSpecification specification = this.Connection.GetFieldSpecificationForNativeTypeName(dataTypeAsString);

            if (specification == null)
            {
                throw new InvalidOperationException("specification is null.");
            }
            if (specification.IsLarge)
            {
                flags |= EntityFieldFlags.Large;
            }

            // return...
            return(new SqlColumn(nativeName, specification.DbType, length, flags));
        }
Пример #2
0
        private void ParseProcedureBody(SqlSchema schema, SqlProcedure proc)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (proc == null)
            {
                throw new ArgumentNullException("proc");
            }

            // reset...
            proc.Parameters.Clear();
            if (proc.Body == null || proc.Body.Length == 0)
            {
                return;
            }

            // add the params...
            Match asMatch = AsRegex.Match(proc.Body);

            if (asMatch.Success)
            {
                // header...
                string header = proc.Body.Substring(0, asMatch.Index);

                // get...
                foreach (Match paramMatch in ParamsRegex.Matches(header))
                {
                    string name = paramMatch.Groups["name"].Value;
                    if (name == null)
                    {
                        throw new InvalidOperationException("'name' is null.");
                    }
                    if (name.Length == 0)
                    {
                        throw new InvalidOperationException("'name' is zero-length.");
                    }

                    try
                    {
                        // type...
                        string typeName = paramMatch.Groups["type"].Value;
                        if (typeName == null)
                        {
                            throw new InvalidOperationException("'typeName' is null.");
                        }
                        if (typeName.Length == 0)
                        {
                            throw new InvalidOperationException("'typeName' is zero-length.");
                        }

                        // mbr - 26-02-2007 - is the type name parameterized?
                        typeName = typeName.ToLower();

                        // are we output?
                        const string outputDirective = " output";
                        if (typeName.EndsWith(outputDirective))
                        {
                            typeName = typeName.Substring(typeName.Length - outputDirective.Length).TrimEnd();
                        }

                        // field...
                        FieldSpecification spec = this.Connection.GetFieldSpecificationForNativeTypeName(typeName, false);
                        if (spec != null)
                        {
                            DbType dbType = spec.DbType;

                            // dimension et al...
                            string dimensionAsString    = paramMatch.Groups["dimension"].Value;
                            string defaultValueAsString = paramMatch.Groups["default"].Value;

                            // direction...
                            string             directionAsString = paramMatch.Groups["direction"].Value;
                            ParameterDirection direction         = ParameterDirection.Input;
                            if (directionAsString != null && directionAsString.Length > 0)
                            {
                                directionAsString = directionAsString.ToLower();
                                if (directionAsString.StartsWith("out"))
                                {
                                    direction = ParameterDirection.Output;
                                }
                            }

                            // value...
                            object defaultValue = DBNull.Value;

                            // create...
                            proc.Parameters.Add(new SqlStatementParameter(name, dbType, defaultValue, direction));
                        }
                        else
                        {
                            proc.Parameters.Add(new SqlStatementParameter(name, DbType.Object, DBNull.Value));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException(string.Format("Failed when processing parameter '{0}'\r\nText: {1}", name, paramMatch.Value), ex);
                    }
                }
            }
        }