Exemple #1
0
 public Table(Schema schema, String name, Boolean isView)
     : base()
 {
     this.Schema = schema;
     this.Name   = IdentifierHelper.GetStrippedSqlIdentifier(name);
     this.IsView = isView;
 }
Exemple #2
0
 public Table(Schema schema, String name, TableType tableType)
     : base()
 {
     this.Schema    = schema;
     this.Name      = IdentifierHelper.GetStrippedSqlIdentifier(name);
     this.TableType = tableType;
 }
Exemple #3
0
 public Schema(Database database, String name, Boolean isDefaultSchema)
     : base()
 {
     this.Database         = database;
     this.Name             = IdentifierHelper.GetStrippedSqlIdentifier(name);
     this.IsDefaultSchema  = isDefaultSchema;
     this.StoredProcedures = new List <StoredProcedure>();
 }
Exemple #4
0
        public Database(Server server, String name)
            : base()
        {
            this.Server = server;
            this.Name   = IdentifierHelper.GetStrippedSqlIdentifier(name);

            this._connection = this.Server.Configuration.Connection;
        }
        public StoredProcedure(Schema schema, String name, Int32 versionNumber, SqlParameter[] sqlParameters)
            : this()
        {
            this.Schema              = schema;
            this.Name                = IdentifierHelper.GetStrippedSqlIdentifier(name);
            this.VersionNumber       = versionNumber;
            this.SqlParameters       = sqlParameters;
            this.DoesReturnResultSet = true;

            this._configuration = this.Schema.Database.Server.Configuration;
        }
Exemple #6
0
        public StoredProcedure AddStoredProcedure(String name, Int32 versionNumber, params SqlParameter[] sqlParameters)
        {
            name.Name("name").NotNullEmptyOrOnlyWhitespace();
            versionNumber.Name("versionNumber").GreaterThan(0);

            name = IdentifierHelper.GetBracketedSqlIdentifier(name);

            if (name.Contains("."))
            {
                throw new ArgumentExceptionFmt(Properties.Resources.InvalidStoredProcedureNameForSchema, name);
            }

            if (this.StoredProcedures.GetByName(name, versionNumber) == null)
            {
                var sp = new StoredProcedure(this, name, versionNumber, sqlParameters);
                this.StoredProcedures.Add(sp);
                return(sp);
            }
            else
            {
                throw new ExceptionFmt(Properties.Resources.StoredProcedureAlreadyExists, name, versionNumber);
            }
        }
Exemple #7
0
        /// <summary>
        /// Create and add a StoredProcedure instance to this Database.
        /// <para>The name parameter must be a valid one-part or two-part T-SQL identifier.  Square brackets around the name parts are optional.</para>
        /// <para>E.g. "my_stored_proc", "[my_stored_proc]", "my_schema.my_stored_proc", and "[my_schema].[my_stored_proc]" are all valid name identifiers.</para>
        /// <para>Names with more than two parts, or missing parts, are considered errors.</para>
        /// </summary>
        public StoredProcedure AddStoredProcedure(String name, Int32 versionNumber, params SqlParameter[] sqlParameters)
        {
            name.Name("name").NotNullEmptyOrOnlyWhitespace();
            versionNumber.Name("versionNumber").GreaterThan(0);

            name = IdentifierHelper.GetStrippedSqlIdentifier(name);
            var nameParts = name.Split(".".ToCharArray(), StringSplitOptions.None);

            /* It's an error if any of the name parts are empty,
             * and this method only accepts one-part ([object name]) or
             * two-part ([schema name].[object name]) T-SQL identifiers. */
            if (nameParts.Any(s => s.IsEmpty()) || (nameParts.Length > 2))
            {
                throw new ArgumentExceptionFmt(Properties.Resources.InvalidStoredProcedureName, name);
            }

            /* At this point, all of the name parts have been validated for correct form. */

            if (nameParts.Length == 1)
            {
                return(this.Schemas.GetDefaultSchema().AddStoredProcedure(name, versionNumber, sqlParameters));
            }
            else
            {
                var schemaName = nameParts[0];
                var schema     = this.Schemas.GetByName(schemaName);
                if (schema == null)
                {
                    throw new ExceptionFmt(Properties.Resources.SchemaNameNotFound, schemaName);
                }

                var storedProcedureName = nameParts[1];

                return(schema.AddStoredProcedure(storedProcedureName, versionNumber, sqlParameters));
            }
        }
Exemple #8
0
 public Server(Configuration configuration)
     : base()
 {
     IdentifierHelper.Init(configuration);
     this.Configuration = configuration;
 }
        /// <summary>
        /// Return a string that can be used in generated code to represent this column as a target language method parameter.
        /// </summary>
        private String GetTargetLanguageMethodParameterNameAndType(SqlParameter sqlParameter)
        {
            var format = "";

            if (this._configuration.TargetLanguage.IsCSharp())
            {
                format = "{0} {1}";
            }
            else if (this._configuration.TargetLanguage.IsFSharp())
            {
                format = "({1} : {0})";
            }
            else if (this._configuration.TargetLanguage.IsVisualBasic())
            {
                format = "{1} As {0}";
            }
            else
            {
                throw new NotImplementedException(String.Format(Properties.Resources.UnknownTargetLanguageValue, this._configuration.TargetLanguage));
            }

            return(String.Format(format, this.GetClrTypeNameFromSqlDbType(sqlParameter), IdentifierHelper.GetTargetLanguageIdentifier(sqlParameter.ParameterName)).Trim());
        }