Beispiel #1
0
        /// <summary>
        /// Returns the custom property sql table for an SqlTable
        /// </summary>
        /// <returns></returns>
        private static SqlTable GetCustomPropertySqlTableForEntityType(EntityType entityType)
        {
            // mbr - 08-12-2005 - changed...
//			string name = GetExtendedNativeNameForEntityType(entityType).Name;
            NativeName name            = entityType.NativeNameExtended;
            SqlTable   entityTypeTable = new SqlTable(null, entityType);

            SqlTable table = new SqlTable(name.Name);

            // add the standard columns...
            SqlColumn[] columns = new SqlColumn[6];
            columns[0] = new SqlColumn(NameColumnName, NameColumnName, DbType.String, MaxNativeNameLength, EntityFieldFlags.Key);
            columns[1] = new SqlColumn(IntegerColumnName, IntegerColumnName, DbType.Int64, -1, EntityFieldFlags.Nullable);
            columns[2] = new SqlColumn(DecimalColumnName, DecimalColumnName, DbType.Decimal, -1, EntityFieldFlags.Nullable);
            columns[3] = new SqlColumn(DateTimeColumnName, DateTimeColumnName, DbType.DateTime, -1, EntityFieldFlags.Nullable);
            columns[4] = new SqlColumn(StringColumnName, StringColumnName, DbType.String, MaxStringPropertyLength, EntityFieldFlags.Nullable);
            columns[5] = new SqlColumn(BinaryColumnName, BinaryColumnName, DbType.Object, -1, EntityFieldFlags.Nullable | EntityFieldFlags.Large);

            // walk...
            foreach (SqlColumn column in entityTypeTable.GetKeyColumns())
            {
                SqlColumn keyColumn = (SqlColumn)column.Clone();
                if (keyColumn.IsAutoIncrement)
                {
                    keyColumn.Flags ^= EntityFieldFlags.AutoIncrement;
                }

                // add...
                table.Columns.Add(keyColumn);
            }

            // add...
            table.Columns.AddRange(columns);
            return(table);
        }
Beispiel #2
0
        /// <summary>
        /// Returns a boolean determining if the table you requested exists in the SQL Server database
        /// </summary>
        /// <param name="nativeName"></param>
        /// <returns></returns>
        protected override bool DoDoesTableExist(NativeName nativeName)
        {
            // create...
            // mbr - 11-10-2005 - wasn't passing in the dialect...
            SqlStatement  statement = new SqlStatement(this.Dialect);
            StringBuilder builder   = new StringBuilder();

            builder.Append(statement.Dialect.SelectKeyword);
            builder.Append(" count(*) ");
            builder.Append(statement.Dialect.FromKeyword);
            builder.Append(" ");
            builder.Append(statement.Dialect.FormatTableName("sysobjects"));
            builder.Append(" ");
            builder.Append(statement.Dialect.WhereKeyword);
            builder.Append(" ");
            builder.Append(statement.Dialect.FormatColumnName("id"));
            builder.Append(statement.Dialect.GetOperatorKeyword(SqlOperator.EqualTo, DbType.Int64));
            builder.Append("object_id(");
            builder.Append(statement.Dialect.FormatVariableNameForQueryText("nativeName"));
            builder.Append(")");

            statement.CommandText = builder.ToString();

            // params...
            statement.Parameters.Add(new SqlStatementParameter("nativeName", DbType.String, nativeName.Name));

            int count = (int)ExecuteScalar(statement);

            return(count > 0);
        }
        public override string GetExtendedTableName(NativeName name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            // return...
            return(name.Name + "Ex");
        }
        /// <summary>
        /// Mangles the ID column name for use in SQL.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        internal static string MangleIdColumnName(NativeName name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            // return...
            return(MangleIdColumnName(name.Name));
        }
Beispiel #5
0
        private IndexBuilder(NativeName tableOwner, SqlDialect dialect, EntityType et)
        {
            this.EntityType = et;
            this.TableOwner = tableOwner;

            if (dialect != null)
            {
                this.Dialect = dialect;
            }
            else
            {
                this.Dialect = Database.DefaultDialect;
            }

            this.IndexColumns   = new List <string>();
            this.IncludeColumns = new List <string>();
        }
Beispiel #6
0
        protected bool IsTablePopulated(NativeName name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            // check...
            if (Database.DoesTableExist(name))
            {
                // rows...
                SqlStatement sql = new SqlStatement();
                sql.CommandText = string.Format("select top 1 * from {0}", sql.Dialect.FormatTableName(name));

                // get...
                DataTable table = Database.ExecuteDataTable(sql);
                if (table == null)
                {
                    throw new InvalidOperationException("table is null.");
                }

                // rows?
                if (table.Rows.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #7
0
        protected object AddRow(NativeName name, string[] names, params object[] values)
        {
            if (names == null)
            {
                throw new ArgumentNullException("names");
            }
            if (names.Length == 0)
            {
                throw new ArgumentOutOfRangeException("'names' is zero-length.");
            }
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }
            if (names.Length != values.Length)
            {
                throw new InvalidOperationException(string.Format("Length mismatch for 'names' and 'values': {0} cf {1}.", names.Length, values.Length));
            }

            // create...
            SqlStatement sql = new SqlStatement();

            // builder...
            StringBuilder builder = new StringBuilder();

            builder.Append("insert into ");
            builder.Append(sql.Dialect.FormatTableName(name));
            builder.Append(" (");
            for (int index = 0; index < names.Length; index++)
            {
                if (index > 0)
                {
                    builder.Append(", ");
                }
                builder.Append(sql.Dialect.FormatColumnName(names[index]));
            }
            builder.Append(") values (");
            for (int index = 0; index < values.Length; index++)
            {
                if (index > 0)
                {
                    builder.Append(", ");
                }

                // value...
                object value = values[index];
                if (value == null || (value is DateTime && (DateTime)value == DateTime.MinValue))
                {
                    value = DBNull.Value;
                }

                // get it...
                DbType dbType = DbType.String;
                if (!(value is DBNull))
                {
                    dbType = ConversionHelper.GetDBTypeForClrType(value.GetType());
                }

                // value...
                if (value is DBNull)
                {
                    builder.Append("null");
                }
                else
                {
                    // get and add...
                    string paramName = sql.Parameters.GetUniqueParameterName();
                    builder.Append(sql.Dialect.FormatVariableNameForQueryText(paramName));
                    sql.Parameters.Add(paramName, dbType, value);
                }
            }
            builder.Append(")");
            builder.Append(sql.Dialect.StatementSeparator);

            // return...
            builder.Append("select ");
            builder.Append(sql.Dialect.LastInsertedIdVariableName);
            builder.Append(sql.Dialect.StatementSeparator);

            // run...
            sql.CommandText = builder.ToString();
            return(Database.ExecuteScalar(sql));
        }
Beispiel #8
0
 public IndexBuilder(NativeName tableOwner, SqlDialect dialect = null)
     : this(tableOwner, dialect, null)
 {
 }
Beispiel #9
0
 /// <summary>
 /// Gets the extended table name.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public abstract string GetExtendedTableName(NativeName name);