Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccessTableOrView" /> class.
 /// </summary>
 /// <param name="dataSource">The data source.</param>
 /// <param name="tableOrViewName">Name of the table or view.</param>
 /// <param name="filterValue">The filter value.</param>
 /// <param name="filterOptions">The filter options.</param>
 public AccessTableOrView(AccessDataSourceBase dataSource, AccessObjectName tableOrViewName, object filterValue, FilterOptions filterOptions) :
     base(dataSource)
 {
     m_FilterValue   = filterValue;
     m_Table         = ((AccessDataSourceBase)DataSource).DatabaseMetadata.GetTableOrView(tableOrViewName);
     m_FilterOptions = filterOptions;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccessTableOrView" /> class.
 /// </summary>
 /// <param name="dataSource"></param>
 /// <param name="tableOrViewName"></param>
 /// <param name="whereClause"></param>
 /// <param name="argumentValue"></param>
 public AccessTableOrView(AccessDataSourceBase dataSource, AccessObjectName tableOrViewName, string whereClause, object argumentValue) :
     base(dataSource)
 {
     m_ArgumentValue = argumentValue;
     m_WhereClause   = whereClause;
     m_Table         = ((AccessDataSourceBase)DataSource).DatabaseMetadata.GetTableOrView(tableOrViewName);
 }
Ejemplo n.º 3
0
 public SqlServerInsertBatchTable(SqlServerDataSourceBase dataSource, SqlServerObjectName tableName, DbDataReader dataReader, SqlServerObjectName tableTypeName, InsertOptions options) : base(dataSource)
 {
     m_Source    = dataReader;
     m_Options   = options;
     m_Table     = dataSource.DatabaseMetadata.GetTableOrView(tableName);
     m_TableType = dataSource.DatabaseMetadata.GetUserDefinedTableType(tableTypeName);
 }
Ejemplo n.º 4
0
        //public object MetadataCache { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="SQLiteTableOrView" /> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="tableOrViewName">Name of the table or view.</param>
        /// <param name="filterValue">The filter value.</param>
        /// <param name="filterOptions">The filter options.</param>
        public SQLiteTableOrView(SQLiteDataSourceBase dataSource, SQLiteObjectName tableOrViewName, object filterValue, FilterOptions filterOptions = FilterOptions.None) :
            base(dataSource)
        {
            m_FilterValue   = filterValue;
            m_FilterOptions = filterOptions;
            m_Table         = dataSource.DatabaseMetadata.GetTableOrView(tableOrViewName);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SQLiteTableOrView" /> class.
 /// </summary>
 /// <param name="dataSource"></param>
 /// <param name="tableOrViewName"></param>
 /// <param name="whereClause"></param>
 /// <param name="argumentValue"></param>
 public SQLiteTableOrView(SQLiteDataSourceBase dataSource, SQLiteObjectName tableOrViewName, string whereClause, object argumentValue) :
     base(dataSource)
 {
     m_ArgumentValue = argumentValue;
     m_WhereClause   = whereClause;
     m_Table         = dataSource.DatabaseMetadata.GetTableOrView(tableOrViewName);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectDataReader{TObject}" /> class.
        /// </summary>
        /// <param name="tableOrView">The table or view.</param>
        /// <param name="source">The source.</param>
        /// <param name="operationType">Type of the operation being performed.</param>
        public ObjectDataReader(TableOrViewMetadata tableOrView, IEnumerable <TObject> source, OperationTypes operationType = OperationTypes.None)
        {
            if (tableOrView == null)
            {
                throw new ArgumentNullException(nameof(tableOrView), $"{nameof(tableOrView)} is null.");
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source), $"{nameof(source)} is null.");
            }


            //Don't use IEnumerable<T>.Count(), as we don't want to preemptively materialize a lazy collection
            if (source is ICollection)
            {
                m_RecordCount = ((ICollection)source).Count;
            }

            m_Source = source.GetEnumerator();
            var metadata = BuildStructure(tableOrView.Name, tableOrView.Columns, false, operationType);

            m_Schema         = metadata.Schema;
            m_PropertyList   = metadata.Properties;
            m_PropertyLookup = metadata.PropertyLookup;
        }
Ejemplo n.º 7
0
 public ViewVM(TableOrViewMetadata view)
 {
     if (view.IsTable)
     {
         throw new ArgumentException($"{view.Name} is not a view.", nameof(view));
     }
     m_View = view;
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Initializes a new instance of the <see cref="MySqlDeleteSet" /> class.
    /// </summary>
    /// <param name="dataSource">The data source.</param>
    /// <param name="tableName">Name of the table.</param>
    /// <param name="whereClause">The where clause.</param>
    /// <param name="parameters">The parameters.</param>
    /// <param name="expectedRowCount">The expected row count.</param>
    /// <param name="options">The options.</param>
    public MySqlDeleteSet(MySqlDataSourceBase dataSource, MySqlObjectName tableName, string whereClause, IEnumerable <MySqlParameter> parameters, int?expectedRowCount, DeleteOptions options) : base(dataSource, whereClause, parameters, expectedRowCount, options)
    {
        if (options.HasFlag(DeleteOptions.UseKeyAttribute))
        {
            throw new NotSupportedException("Cannot use Key attributes with this operation.");
        }

        m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName);
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlTableOrView" /> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="tableOrViewName">Name of the table or view.</param>
        /// <exception cref="ArgumentException"></exception>
        public PostgreSqlTableOrView(PostgreSqlDataSourceBase dataSource, PostgreSqlObjectName tableOrViewName) :
            base(dataSource)
        {
            if (tableOrViewName == PostgreSqlObjectName.Empty)
            {
                throw new ArgumentException($"{nameof(tableOrViewName)} is empty", nameof(tableOrViewName));
            }

            m_Table = DataSource.DatabaseMetadata.GetTableOrView(tableOrViewName);
        }
Ejemplo n.º 10
0
    /// <summary>
    /// Initializes a new instance of the <see cref="OleDbSqlServerTableOrView{TObject}"/> class.
    /// </summary>
    /// <param name="dataSource">The data source.</param>
    /// <param name="tableOrViewName">Name of the table or view.</param>
    /// <param name="whereClause">The where clause.</param>
    /// <param name="argumentValue">The argument value.</param>
    public OleDbSqlServerTableOrView(OleDbSqlServerDataSourceBase dataSource, SqlServerObjectName tableOrViewName, string?whereClause, object?argumentValue) : base(dataSource)
    {
        if (tableOrViewName == SqlServerObjectName.Empty)
        {
            throw new ArgumentException($"{nameof(tableOrViewName)} is empty", nameof(tableOrViewName));
        }

        m_ArgumentValue = argumentValue;
        m_WhereClause   = whereClause;
        m_Table         = DataSource.DatabaseMetadata.GetTableOrView(tableOrViewName);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Initializes a new instance of the <see cref="OleDbSqlServerTableOrView{TObject}" /> class.
    /// </summary>
    /// <param name="dataSource">The data source.</param>
    /// <param name="tableOrViewName">Name of the table or view.</param>
    /// <param name="filterValue">The filter value.</param>
    /// <param name="filterOptions">The filter options.</param>
    /// <exception cref="System.ArgumentException"></exception>
    public OleDbSqlServerTableOrView(OleDbSqlServerDataSourceBase dataSource, SqlServerObjectName tableOrViewName, object filterValue, FilterOptions filterOptions = FilterOptions.None) : base(dataSource)
    {
        if (tableOrViewName == SqlServerObjectName.Empty)
        {
            throw new ArgumentException($"{nameof(tableOrViewName)} is empty", nameof(tableOrViewName));
        }

        m_FilterValue   = filterValue;
        m_FilterOptions = filterOptions;
        m_Table         = DataSource.DatabaseMetadata.GetTableOrView(tableOrViewName);
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Initializes a new instance of the <see cref="MySqlUpdateSet" /> class.
    /// </summary>
    /// <param name="dataSource">The data source.</param>
    /// <param name="tableName">Name of the table.</param>
    /// <param name="newValues">The new values.</param>
    /// <param name="options">The options.</param>
    /// <exception cref="System.NotSupportedException">Cannot use Key attributes with this operation.</exception>
    public MySqlUpdateSet(MySqlDataSourceBase dataSource, MySqlObjectName tableName, object?newValues, UpdateOptions options) : base(dataSource)
    {
        if (options.HasFlag(UpdateOptions.UseKeyAttribute))
        {
            throw new NotSupportedException("Cannot use Key attributes with this operation.");
        }

        m_Table     = dataSource.DatabaseMetadata.GetTableOrView(tableName);
        m_NewValues = newValues;
        m_Options   = options;
    }
Ejemplo n.º 13
0
 public SqlServerInsertBatch(SqlServerDataSourceBase dataSource, SqlServerObjectName tableName, DbDataReader dataReader, SqlServerObjectName tableTypeName, InsertOptions options) : base(dataSource)
 {
     m_Source    = dataReader;
     m_Options   = options;
     m_Table     = dataSource.DatabaseMetadata.GetTableOrView(tableName);
     m_TableType = dataSource.DatabaseMetadata.GetUserDefinedType(tableTypeName);
     if (!m_TableType.IsTableType)
     {
         throw new MappingException($"{m_TableType.Name} is not a user defined table type");
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MySqlDeleteMany" /> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="whereClause">The where clause.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        public MySqlDeleteMany(MySqlDataSourceBase dataSource, MySqlObjectName tableName, string whereClause, IEnumerable <MySqlParameter> parameters, DeleteOptions options) : base(dataSource)
        {
            if (options.HasFlag(DeleteOptions.UseKeyAttribute))
            {
                throw new NotSupportedException("Cannot use Key attributes with this operation.");
            }

            m_Table       = dataSource.DatabaseMetadata.GetTableOrView(tableName);
            m_WhereClause = whereClause;
            m_Parameters  = parameters;
        }
Ejemplo n.º 15
0
    /// <summary>
    /// Initializes a new instance of the <see cref="MySqlUpdateSet" /> class.
    /// </summary>
    /// <param name="dataSource">The data source.</param>
    /// <param name="tableName">Name of the table.</param>
    /// <param name="updateExpression">The update expression.</param>
    /// <param name="updateArgumentValue">The update argument value.</param>
    /// <param name="options">The options.</param>
    /// <exception cref="System.NotSupportedException">Cannot use Key attributes with this operation.</exception>
    public MySqlUpdateSet(MySqlDataSourceBase dataSource, MySqlObjectName tableName, string updateExpression, object?updateArgumentValue, UpdateOptions options) : base(dataSource)
    {
        if (options.HasFlag(UpdateOptions.UseKeyAttribute))
        {
            throw new NotSupportedException("Cannot use Key attributes with this operation.");
        }

        m_Table               = dataSource.DatabaseMetadata.GetTableOrView(tableName);
        m_UpdateExpression    = updateExpression;
        m_Options             = options;
        m_UpdateArgumentValue = updateArgumentValue;
    }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlTableOrView"/> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="tableOrViewName">Name of the table or view.</param>
        /// <param name="whereClause">The where clause.</param>
        /// <param name="argumentValue">The argument value.</param>
        /// <exception cref="ArgumentException"></exception>
        public PostgreSqlTableOrView(PostgreSqlDataSourceBase dataSource, PostgreSqlObjectName tableOrViewName, string whereClause, object argumentValue)
            : base(dataSource)
        {
            if (tableOrViewName == PostgreSqlObjectName.Empty)
            {
                throw new ArgumentException($"{nameof(tableOrViewName)} is empty", nameof(tableOrViewName));
            }

            m_WhereClause   = whereClause;
            m_ArgumentValue = argumentValue;
            m_Table         = DataSource.DatabaseMetadata.GetTableOrView(tableOrViewName);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccessDeleteMany" /> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="whereClause">The where clause.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="expectedRowCount">The expected row count.</param>
        /// <param name="options">The options.</param>
        public AccessDeleteMany(AccessDataSourceBase dataSource, AccessObjectName tableName, string whereClause, IEnumerable <OleDbParameter> parameters, int?expectedRowCount, DeleteOptions options) : base(dataSource)
        {
            if (options.HasFlag(DeleteOptions.UseKeyAttribute))
            {
                throw new NotSupportedException("Cannot use Key attributes with this operation.");
            }

            m_Table            = dataSource.DatabaseMetadata.GetTableOrView(tableName);
            m_WhereClause      = whereClause;
            m_Parameters       = parameters;
            m_Options          = options;
            m_ExpectedRowCount = expectedRowCount;
        }
Ejemplo n.º 18
0
    /// <summary>
    /// Initializes a new instance of the <see cref="MySqlUpdateSet" /> class.
    /// </summary>
    /// <param name="dataSource">The data source.</param>
    /// <param name="tableName">Name of the table.</param>
    /// <param name="newValues">The new values.</param>
    /// <param name="whereClause">The where clause.</param>
    /// <param name="parameters">The parameters.</param>
    /// <param name="expectedRowCount">The expected row count.</param>
    /// <param name="options">The options.</param>
    public MySqlUpdateSet(MySqlDataSourceBase dataSource, MySqlObjectName tableName, object?newValues, string whereClause, IEnumerable <MySqlParameter> parameters, int?expectedRowCount, UpdateOptions options) : base(dataSource)
    {
        if (options.HasFlag(UpdateOptions.UseKeyAttribute))
        {
            throw new NotSupportedException("Cannot use Key attributes with this operation.");
        }

        m_Table            = dataSource.DatabaseMetadata.GetTableOrView(tableName);
        m_NewValues        = newValues;
        m_WhereClause      = whereClause;
        m_ExpectedRowCount = expectedRowCount;
        m_Options          = options;
        m_Parameters       = parameters;
    }
Ejemplo n.º 19
0
 void PreloadViews(DataTable columnsDataTable)
 {
     using (var connection = new OleDbConnection(m_ConnectionBuilder.ConnectionString))
     {
         connection.Open();
         var dtViews = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Views, null);
         foreach (DataRow row in dtViews.Rows)
         {
             var name    = row["TABLE_NAME"].ToString() !;
             var columns = GetColumns(name, columnsDataTable, null);
             m_Tables[name] = new TableOrViewMetadata <AccessObjectName, OleDbType>(this, name, false, columns);
         }
     }
 }
Ejemplo n.º 20
0
        public PostgreSqlInsertBatch(PostgreSqlDataSourceBase dataSource, PostgreSqlObjectName tableName, IEnumerable <TObject> objects, InsertOptions options) : base(dataSource)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException(nameof(dataSource), $"{nameof(dataSource)} is null.");
            }

            var sourceList = objects.AsReadOnlyList();

            if (sourceList == null || sourceList.Count == 0)
            {
                throw new ArgumentException($"{nameof(objects)} is null or empty.", nameof(objects));
            }

            m_SourceList = sourceList;
            m_Options    = options;
            m_Table      = dataSource.DatabaseMetadata.GetTableOrView(tableName);
        }
Ejemplo n.º 21
0
    internal MySqlInsertBulk(MySqlDataSourceBase dataSource, MySqlObjectName tableName, DataTable dataTable) : base(dataSource)
    {
        if (dataSource == null)
        {
            throw new ArgumentNullException(nameof(dataSource), $"{nameof(dataSource)} is null.");
        }
        if (dataTable == null)
        {
            throw new ArgumentNullException(nameof(dataTable), $"{nameof(dataTable)} is null.");
        }

        m_DataSource = dataSource;
        m_Source     = dataTable.CreateDataReader();
        m_Table      = dataSource.DatabaseMetadata.GetTableOrView(tableName);
        if (!m_Table.IsTable)
        {
            throw new MappingException($"Cannot perform a bulk insert into the view {m_Table.Name}");
        }
    }
Ejemplo n.º 22
0
        void PreloadTables(DataTable columnsDataTable, DataTable primaryKeys)
        {
            using (var connection = new OleDbConnection(m_ConnectionBuilder.ConnectionString))
            {
                connection.Open();
                var dtTables = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                foreach (DataRow row in dtTables.Rows)
                {
                    if (row["TABLE_TYPE"].ToString() != "TABLE")
                    {
                        continue;
                    }

                    var name    = row["TABLE_NAME"].ToString() !;
                    var columns = GetColumns(name, columnsDataTable, primaryKeys);
                    m_Tables[name] = new TableOrViewMetadata <AccessObjectName, OleDbType>(this, name, true, columns);
                }
            }
        }
Ejemplo n.º 23
0
    internal SqlServerInsertBulk(SqlServerDataSourceBase dataSource, SqlServerObjectName tableName, IDataReader dataReader) : base(dataSource)
    {
        if (dataSource == null)
        {
            throw new ArgumentNullException(nameof(dataSource), $"{nameof(dataSource)} is null.");
        }
        if (dataReader == null)
        {
            throw new ArgumentNullException(nameof(dataReader), $"{nameof(dataReader)} is null.");
        }

        m_DataSource = dataSource;
        m_Source     = dataReader;
        m_Table      = dataSource.DatabaseMetadata.GetTableOrView(tableName);
        if (!m_Table.IsTable)
        {
            throw new MappingException($"Cannot perform a bulk insert into the view {m_Table.Name}");
        }
    }
Ejemplo n.º 24
0
        public SqlServerInsertBatch(SqlServerDataSourceBase dataSource, SqlServerObjectName tableName, IEnumerable <TObject> objects, InsertOptions options) : base(dataSource)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException(nameof(dataSource), $"{nameof(dataSource)} is null.");
            }

            var sourceList = objects.AsReadOnlyList();

            if (sourceList == null || sourceList.Count == 0)
            {
                throw new ArgumentException($"{nameof(objects)} is null or empty.", nameof(objects));
            }

            if (sourceList.Count > 1000)
            {
                throw new ArgumentException($"{nameof(objects)}.Count exceeds SQL Server's row count limit of 1000. Supply a table type, break the call into batches of 1000, use InsertMultipleBatch, or use BulkInsert.", nameof(objects));
            }

            m_SourceList = sourceList;
            m_Options    = options;
            m_Table      = dataSource.DatabaseMetadata.GetTableOrView(tableName);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MySqlDeleteSet"/> class.
 /// </summary>
 /// <param name="dataSource">The data source.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="whereClause">The where clause.</param>
 /// <param name="argumentValue">The argument value.</param>
 public MySqlDeleteSet(MySqlDataSourceBase dataSource, MySqlObjectName tableName, string whereClause, object?argumentValue) : base(dataSource, whereClause, argumentValue)
 {
     m_Table = dataSource.DatabaseMetadata.GetTableOrView(tableName);
 }
Ejemplo n.º 26
0
 public SQLiteTableVM(IClass1DataSource dataSource, TableOrViewMetadata <SQLiteObjectName, DbType> table) : base(dataSource, table)
 {
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Indicates whether or not a soft delete should be performed.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <returns></returns>
 public bool UseSoftDelete(TableOrViewMetadata table)
 {
     return(m_List.Where(r => r.AppliesWhen.HasFlag(OperationTypes.Delete)).OfType <SoftDeleteRule>().Any(r => table.Columns.Any(c => c.SqlName.Equals(r.ColumnName, StringComparison.OrdinalIgnoreCase))));
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MySqlDeleteMany"/> class.
 /// </summary>
 /// <param name="dataSource">The data source.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="filterValue">The filter value.</param>
 /// <param name="filterOptions">The options.</param>
 public MySqlDeleteMany(MySqlDataSourceBase dataSource, MySqlObjectName tableName, object filterValue, FilterOptions filterOptions) : base(dataSource)
 {
     m_Table         = dataSource.DatabaseMetadata.GetTableOrView(tableName);
     m_FilterValue   = filterValue;
     m_FilterOptions = filterOptions;
 }
Ejemplo n.º 29
0
 public AccessTableVM(IClass1DataSource dataSource, TableOrViewMetadata <AccessObjectName, OleDbType> table) : base(dataSource, table)
 {
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccessDeleteMany"/> class.
 /// </summary>
 /// <param name="dataSource">The data source.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="whereClause">The where clause.</param>
 /// <param name="argumentValue">The argument value.</param>
 public AccessDeleteMany(AccessDataSourceBase dataSource, AccessObjectName tableName, string whereClause, object?argumentValue) : base(dataSource)
 {
     m_Table         = dataSource.DatabaseMetadata.GetTableOrView(tableName);
     m_WhereClause   = whereClause;
     m_ArgumentValue = argumentValue;
 }