Beispiel #1
0
 /// <summary>
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="listOptions">The list options.</param>
 /// <param name="columnName">Name of the desired column.</param>
 public XElementListMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, string columnName = null, ListOptions listOptions = ListOptions.None)
     : base(commandBuilder, columnName)
 {
     m_ListOptions = listOptions;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataTableMaterializer{TCommand, TParameter}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The associated operation.</param>
 public DataTableMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder)
     : base(commandBuilder)
 {
 }
Beispiel #3
0
        public void BuildCommands()
        {
            var dbFactory    = new DbFactory(SqlClientFactory.Instance);
            var cmdGenerator = new DbCommandBuilder(dbFactory);

            var q = new Query(new QTable("test", "t"));

            q.Condition = createTestQuery();
            q.Fields    = new QField[] { "name", "t.age", new QField("age_months", "t.age*12") };

            // SELECT TEST with prefixes and expressions
            IDbCommand cmd       = cmdGenerator.GetSelectCommand(q);
            string     masterSQL = "SELECT name,(t.age) as age,(t.age*12) as age_months FROM test t WHERE (((name LIKE @p0) Or (NOT(age>=@p1))) And ((weight=@p2) And (type IN (@p3,@p4)))) Or ((name<>@p5) And (type IS NOT NULL))";

            Assert.Equal(masterSQL, cmd.CommandText.Trim());

            // SELECT WITH TABLE ALIAS TEST
            cmd = cmdGenerator.GetSelectCommand(
                new Query("accounts.a",
                          new QConditionNode((QField)"a.id", Conditions.In,
                                             new Query("dbo.accounts.b", (QField)"a.id" != (QField)"b.id"))));
            masterSQL = "SELECT * FROM accounts a WHERE a.id IN (SELECT * FROM dbo.accounts b WHERE a.id<>b.id)";
            Assert.Equal(masterSQL, cmd.CommandText);

            var testData = new Dictionary <string, object> {
                { "name", "Test" },
                { "age", 20 },
                { "weight", 75.6 },
                { "type", "staff" }
            };


            // INSERT TEST
            cmd       = cmdGenerator.GetInsertCommand("test", testData);
            masterSQL = "INSERT INTO test (name,age,weight,type) VALUES (@p0,@p1,@p2,@p3)";

            Assert.Equal(cmd.CommandText, masterSQL);
            Assert.Equal(cmd.Parameters.Count, 4);

            // UPDATE TEST
            cmd       = cmdGenerator.GetUpdateCommand(new Query("test", (QField)"name" == (QConst)"test"), testData);
            masterSQL = "UPDATE test SET name=@p0,age=@p1,weight=@p2,type=@p3 WHERE name=@p4";

            Assert.Equal(cmd.CommandText, masterSQL);
            Assert.Equal(cmd.Parameters.Count, 5);

            // UPDATE TEST (by query)
            var changes = new Dictionary <string, IQueryValue>()
            {
                { "age", (QConst)21 }, { "name", (QConst)"Alexandra" }
            };

            cmd       = cmdGenerator.GetUpdateCommand(new Query("test", (QField)"id" == (QConst)1), changes);
            masterSQL = "UPDATE test SET age=@p0,name=@p1 WHERE id=@p2";

            Assert.Equal(masterSQL, cmd.CommandText);
            Assert.Equal(3, cmd.Parameters.Count);

            // DELETE BY QUERY TEST
            cmd       = cmdGenerator.GetDeleteCommand(new Query("test", (QField)"id" == (QConst)5));
            masterSQL = "DELETE FROM test WHERE id=@p0";

            Assert.Equal(cmd.CommandText, masterSQL);
            Assert.Equal(cmd.Parameters.Count, 1);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BooleanOrNullMaterializer{TCommand, TParameter}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="columnName">Name of the desired column.</param>
 public ByteOrNullMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, string?columnName = null)
     : base(commandBuilder, columnName)
 {
 }
Beispiel #5
0
 public abstract void Build(DbCommandBuilder builder, IServiceProvider serviceProvider);
Beispiel #6
0
        public async Task Proxy_UpdateAsync_should_work_identically_to_Update()
        {
            List <TestTable> randomDataSource = RandomDataGenerator.CreateRandomTables(seed: 1234, tableCount: 5, /*allowZeroRowsInTablesByIdx: */ 1, 3);

            // Part 1: Use proxy
            DataSet dataSetFromProxy;
            {
                using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AwaitAsync))
                    using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource))
                    {
                        await connection.OpenAsync();

                        using (BatchingFakeProxiedDbDataAdapter adapter = new BatchingFakeProxiedDbDataAdapter(selectCommand))
                            using (DbCommandBuilder cmdBuilder = await adapter.CreateCommandBuilderAsync().ConfigureAwait(false))
                            {
                                dataSetFromProxy = new DataSet();

                                // `.Fill` returns the number of rows in the first table, not any subsequent tables. Yes, that's silly.
                                Int32 rowsInFirstTable = await adapter.FillAsync(dataSetFromProxy);

                                rowsInFirstTable.ShouldBe(40);

                                //

                                Dictionary <String, Int32> rowsModified = DataTableMethods.MutateDataSet(dataSetFromProxy);

                                //

                                adapter.UpdateCommand = (FakeDbCommand)cmdBuilder.GetUpdateCommand();
                                adapter.UpdateCommand.NonQueryResultRowCountValue = (cmd) => 1; // HACK /* DataTableMethods.GetNonQueryResultRowCountValue( dataSetFromProxy, cmd, rowsModified ); */;

                                //

                                Int32 updatedRows = await adapter.UpdateAsync(dataSetFromProxy); // updatedRows... in first table only?

//                      updatedRows.ShouldBe( rowsModified );
                            }
                    }
            }

            // Part 2: Use real
            DataSet dataSetFromReal;

            {
                using (FakeDbConnection connection = new FakeDbConnection(asyncMode: AsyncMode.AllowSync))
                    using (FakeDbCommand selectCommand = connection.CreateCommand(testTables: randomDataSource))
                    {
                        connection.Open();

                        using (FakeDbDataAdapter adapter = new FakeDbDataAdapter(selectCommand))
                            using (FakeDbCommandBuilder cmdBuilder = adapter.CreateCommandBuilder())
                            {
                                dataSetFromReal = new DataSet();

                                // `.Fill` returns the number of rows in the first table, not any subsequent tables. Yes, that's silly.
                                Int32 rowsInFirstTable = adapter.Fill(dataSetFromReal);
                                rowsInFirstTable.ShouldBe(40);

                                //

                                Dictionary <String, Int32> rowsModified = DataTableMethods.MutateDataSet(dataSetFromReal);

                                //

                                adapter.UpdateCommand = cmdBuilder.GetUpdateCommand();
                                adapter.UpdateCommand.NonQueryResultRowCountValue = (cmd) => 1; // HACK /* DataTableMethods.GetNonQueryResultRowCountValue( dataSetFromProxy, cmd, rowsModified ); */;

                                //

                                Int32 updatedRows = adapter.Update(dataSetFromReal); // updatedRows... in first table only?
//                      updatedRows.ShouldBe( rowsModified );
                            }
                    }
            }

            // Assert equality:
            DataTableMethods.DataSetEquals(dataSetFromProxy, dataSetFromReal, out String diffs).ShouldBeTrue(customMessage: diffs);
        }
Beispiel #7
0
    public static string GetParameterName(this DbConnection connection, string paramName)
    {
        DbCommandBuilder builder = GetProviderFactory(connection).CreateCommandBuilder();

        return(getParameterName(builder, paramName));
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstructibleMaterializer{TCommand,
 /// TParameter, TResult, TObject}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The associated operation.</param>
 protected ConstructibleMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder) : base(commandBuilder)
 {
 }
Beispiel #9
0
 /// <summary>
 /// </summary>
 /// <param name="commandBuilder">The associated command builder.</param>
 public NonQueryMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder)
     : base(commandBuilder)
 {
 }
        public object Update(string providerName, string connectionString, string dataTableName, string commandText, string commandType, OperationMethod queryMode, string olderSnapshotXml, string newerSnapshotXml, string snapshotEncodingName, Dictionary <string, string[]> primaryKeys, IDictionary <string, IDictionary <string, string> > foreignKeys)
        {
            Result result = new Result();

            DbConnection connection = this.getDbConnection(providerName);

            connection.ConnectionString = connectionString;

            DbDataAdapter adapter = this.getDbDataAdapter(providerName);

            DbCommand selectCommand = connection.CreateCommand();

            selectCommand.CommandText = commandText;
            selectCommand.CommandType = this.getDbCommandType(commandType);

            adapter.SelectCommand = selectCommand;

            DbCommandBuilder commandBuilder = this.getDbCommandBuilder(providerName);

            commandBuilder.DataAdapter = adapter;

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            Encoding snapshotEncoding = String.IsNullOrEmpty(snapshotEncodingName) ? Encoding.Default : Encoding.GetEncoding(snapshotEncodingName);

            DataSet dataSetOlderSnapshot = new DataSet();

            if (!String.IsNullOrEmpty(olderSnapshotXml))
            {
                dataSetOlderSnapshot.ReadXml(new System.IO.MemoryStream(snapshotEncoding.GetBytes(olderSnapshotXml)), XmlReadMode.ReadSchema);
            }

            dataSetOlderSnapshot.AcceptChanges();

            DataSet dataSetNewerSnapshot = new DataSet();

            if (!String.IsNullOrEmpty(newerSnapshotXml))
            {
                dataSetNewerSnapshot.ReadXml(new System.IO.MemoryStream(snapshotEncoding.GetBytes(newerSnapshotXml)), XmlReadMode.ReadSchema);
            }

            dataSetNewerSnapshot.AcceptChanges();

            DataSet dataSetCurrent = new DataSet(); //dataSetNewerSnapshot.Clone();

            adapter.Fill(dataSetCurrent);

            dataSetCurrent.Tables[0].TableName = dataTableName;

            dataSetCurrent.AcceptChanges();

            //Comparison machinism to be implemented below:
            //

            IList <IDictionary <string, object> > snapshotNewer, snapshotOlder;
            IList <IDictionary <string, object> > added, deleted, updated;

            //string dataTableName;

            List <string> primaryKeyNames;

            SnapshotHelper snapshotHelper;

            //DataRow row;

            for (int i = 0; i < dataSetNewerSnapshot.Tables.Count; i++)
            {
                //dataTableName = dataSetNewerSnapshot.Tables[i].TableName;

                if (dataSetNewerSnapshot.Tables[i].TableName.ToLower() == dataTableName.ToLower())
                {
                    primaryKeyNames = new List <string>();

                    for (int j = 0; j < dataSetNewerSnapshot.Tables[i].PrimaryKey.Length; j++)
                    {
                        primaryKeyNames.Add(dataSetNewerSnapshot.Tables[i].PrimaryKey[j].ColumnName);
                    }

                    if ((primaryKeys != null) && (primaryKeys.ContainsKey(dataTableName)))
                    {
                        primaryKeyNames = new List <string>(primaryKeys[dataTableName]);
                    }

                    snapshotNewer = Utility.ConvertDataTableToList(dataSetNewerSnapshot.Tables[dataTableName]);

                    snapshotOlder = Utility.ConvertDataTableToList(dataSetOlderSnapshot.Tables[dataTableName]);

                    snapshotHelper = new Snapshot.SnapshotHelper();

                    snapshotHelper.UniqueIdentifierNames = primaryKeyNames.ToArray();

                    snapshotHelper.SetCurrent(snapshotNewer);

                    snapshotHelper.SetLast(snapshotOlder);

                    if (snapshotHelper.Compare())
                    {
                        added   = snapshotHelper.GetNew();
                        deleted = snapshotHelper.GetDeleted();
                        updated = snapshotHelper.GetUpdated();

                        if ((added != null) && (added.Count > 0))
                        {
                            foreach (IDictionary <string, object> item in added)
                            {
                                DataRow row = dataSetCurrent.Tables[dataTableName].NewRow();

                                foreach (string key in item.Keys)
                                {
                                    row[key] = item[key];
                                }

                                dataSetCurrent.Tables[dataTableName].Rows.Add(row);

                                //row.SetAdded();
                            }

                            //commandBuilder.GetInsertCommand();

                            result.CreationCount = adapter.Update(dataSetCurrent.Tables[dataTableName]);
                        }

                        if ((updated != null) && (updated.Count > 0))
                        {
                            //List<DataRow> rows = new List<DataRow>();

                            foreach (IDictionary <string, object> item in updated)
                            {
                                //DataRow row = dataSetCurrent.Tables[dataTableName].NewRow();

                                //dataSetCurrent.Tables[dataTableName].Rows.Add(row);

                                //DataRow row = this.getFilteredDataRow(item, primaryKeyNames.ToArray(), dataSetOlderSnapshot.Tables[dataTableName]);

                                DataRow row = this.getFilteredDataRow(item, primaryKeyNames.ToArray(), dataSetCurrent.Tables[dataTableName]);

                                //dataSetCurrent.Tables[dataTableName].ImportRow(row);

                                row.AcceptChanges();

                                //row.BeginEdit();

                                foreach (string key in item.Keys)
                                {
                                    if (!primaryKeyNames.Contains(key))
                                    {
                                        row[key] = item[key];
                                    }
                                }

                                //row.EndEdit();

                                //row.SetModified();

                                //rows.Add(row);
                            }

                            //commandBuilder.GetUpdateCommand();

                            result.ModificationCount = adapter.Update(dataSetCurrent.Tables[dataTableName]);

                            //result.ModificationCount = adapter.Update(rows.ToArray());
                        }

                        if ((deleted != null) && (deleted.Count > 0))
                        {
                            //List<DataRow> rows = new List<DataRow>();

                            //Detecting foreign key references:
                            dataSetCurrent.Tables[dataTableName].RowDeleting += (s, e) =>
                            {
                                if (e.Row != null)
                                {
                                    IDictionary <string, string> referencedForeignKeys = foreignKeys[dataTableName];

                                    foreach (string key in referencedForeignKeys.Keys)
                                    {
                                        //this.beginCascadedDeletion(connection, dataTableName, referencedForeignKeys[key], e.Row[referencedForeignKeys[key]], referencedForeignKeys);
                                        this.beginCascadedDeletion(connection, key.Substring(0, key.IndexOf(".")), key.Substring(key.IndexOf(".") + 1), e.Row[referencedForeignKeys[key]], foreignKeys);
                                    }
                                }
                            };

                            foreach (IDictionary <string, object> item in deleted)
                            {
                                //DataRow row = dataSetCurrent.Tables[dataTableName].NewRow();

                                //dataSetCurrent.Tables[dataTableName].Rows.Add(row);

                                //DataRow row = this.getFilteredDataRow(item, primaryKeyNames.ToArray(), dataSetOlderSnapshot.Tables[dataTableName]);

                                DataRow row = this.getFilteredDataRow(item, primaryKeyNames.ToArray(), dataSetCurrent.Tables[dataTableName]);

                                //dataSetCurrent.Tables[dataTableName].ImportRow(row);

                                row.AcceptChanges();

                                //foreach (string key in item.Keys)
                                //{
                                //    row[key] = item[key];
                                //}

                                //row.AcceptChanges();

                                row.Delete();

                                //rows.Add(row);
                            }

                            //commandBuilder.GetDeleteCommand();

                            result.DeletionCount = adapter.Update(dataSetCurrent.Tables[dataTableName]);

                            //result.DeletionCount = adapter.Update(rows.ToArray());
                        }
                    }
                }
            }

            //int result =  adapter.Update(dataSetCurrent);

            if (connection.State != ConnectionState.Closed)
            {
                connection.Close();
            }

            if (this.EnableTracing)
            {
                TracingHelper.Trace(new object[] { connection, adapter, commandText, commandType, queryMode, result }, this.TraceSourceName);
            }

            return(result);
        }
Beispiel #11
0
        public void Build(DbCommandBuilder builder, IServiceProvider serviceProvider)
        {
            var parameter = builder.AddParameter(Value);

            builder.SqlBuilder.Write(parameter.ParameterName);
        }
        protected override DbDataAdapter GetDataAdapter(string tableName, string schemaName, out DbCommandBuilder builder)
        {
            var adapter = new MySqlDataAdapter(string.Format(CultureInfo.InvariantCulture, "SELECT * FROM \"{0}\"", tableName), ConnectionString);

            builder = new MySqlCommandBuilder(adapter);
            return(adapter);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Materializer{TCommand, TParameter}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The associated command builder.</param>
 /// <exception cref="ArgumentNullException">operation;operation is null.</exception>
 protected Materializer(DbCommandBuilder <TCommand, TParameter> commandBuilder)
 {
     m_CommandBuilder = commandBuilder ?? throw new ArgumentNullException(nameof(commandBuilder), $"{nameof(commandBuilder)} is null.");
 }
            public DbHelper(int tenant, ConnectionStringSettings connectionString)
            {
                this.tenant = tenant;
                factory = connectionString.ProviderName == "System.Data.SQLite" ? GetSQLiteFactory() : GetMySqlFactory();
                builder = factory.CreateCommandBuilder();
                connect = factory.CreateConnection();
                connect.ConnectionString = connectionString.ConnectionString;
                connect.Open();

                if (factory.GetType().Name == "MySqlClientFactory")
                {
                    CreateCommand("set @@session.sql_mode = concat(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO')").ExecuteNonQuery();
                }

                columns = connect.GetSchema("Columns");

                whereExceptions["calendar_calendar_item"] = " where calendar_id in (select id from calendar_calendars where tenant = " + tenant + ") ";
                whereExceptions["calendar_calendar_user"] = "******" + tenant + ") ";
                whereExceptions["calendar_event_item"] = " where event_id in (select id from calendar_events where tenant = " + tenant + ") ";
                whereExceptions["calendar_event_user"] = "******" + tenant + ") ";
                whereExceptions["crm_entity_contact"] = " where contact_id in (select id from crm_contact where tenant_id = " + tenant + ") ";
                whereExceptions["crm_entity_tag"] = " where tag_id in (select id from crm_tag where tenant_id = " + tenant + ") ";
                whereExceptions["files_folder_tree"] = " where folder_id in (select id from files_folder where tenant_id = " + tenant + ") ";
                whereExceptions["forum_answer_variant"] = " where answer_id in (select id from forum_answer where tenantid = " + tenant + ")";
                whereExceptions["forum_topic_tag"] = " where topic_id in (select id from forum_topic where tenantid = " + tenant + ")";
                whereExceptions["forum_variant"] = " where question_id in (select id from forum_question where tenantid = " + tenant + ")";
                whereExceptions["projects_project_participant"] = " where project_id in (select id from projects_projects where tenant_id = " + tenant + ")";
                whereExceptions["projects_following_project_participant"] = " where project_id in (select id from projects_projects where tenant_id = " + tenant + ")";
                whereExceptions["projects_project_tag"] = " where project_id in (select id from projects_projects where tenant_id = " + tenant + ")";
                whereExceptions["projects_project_tag_change_request"] = " where project_id in (select id from projects_projects where tenant_id = " + tenant + ")";
                whereExceptions["tenants_tenants"] = " where id = " + tenant;
                whereExceptions["webstudio_widgetstate"] = " where widgetcontainerid in (select id from webstudio_widgetcontainer where tenantid = " + tenant + ")";
                whereExceptions["core_usersecurity"] = " where userid in (select id from core_user where tenant = " + tenant + ")";
                whereExceptions["core_acl"] = " where tenant = " + tenant + " or tenant = -1";
                whereExceptions["core_subscription"] = " where tenant = " + tenant + " or tenant = -1";
                whereExceptions["core_subscriptionmethod"] = " where tenant = " + tenant + " or tenant = -1";
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataSetMaterializer{TCommand, TParameter}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="tableNames">The table names.</param>
 public DataSetMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, string[] tableNames)
     : base(commandBuilder)
 {
     m_TableNames = tableNames;
 }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListColumnMaterializer{TCommand, TParameter, TResult}" /> class.
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="columnName">Name of the desired column.</param>
 /// <param name="listOptions">The list options.</param>
 protected SetColumnMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, string?columnName, ListOptions listOptions) : base(commandBuilder, columnName, listOptions, false)
 {
 }
Beispiel #17
0
        // Fields
        //private static SqlIdentifier instance;

        private MsSqlIdentifier(DbCommandBuilder builder)
            : base(builder)
        {
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SingleColumnMaterializer{TCommand, TParameter, TResult}" /> class.
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="columnName">Name of the desired column.</param>
 protected SingleColumnMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, string columnName)
     : base(commandBuilder)
 {
     m_DesiredColumn = columnName;
 }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Materializer{TCommand, TParameter, TResult}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The associated operation.</param>
 protected Materializer(DbCommandBuilder <TCommand, TParameter> commandBuilder) : base(commandBuilder)
 {
 }
Beispiel #20
0
 public override void Build(DbCommandBuilder builder, IServiceProvider serviceProvider)
 {
     serviceProvider.GetRequiredService <ColumnFragmentBuilder>()
     .Build((ITableSource)properties["Table"], (string)properties["Name"], builder, serviceProvider);
 }
Beispiel #21
0
        public void CreateCommandBuilder()
        {
            DbCommandBuilder actual = TestSubject.CreateCommandBuilder();

            Assert.IsInstanceOfType(typeof(HsqlCommandBuilder), actual);
        }
 public override void Build(DbCommandBuilder builder, IServiceProvider serviceProvider)
 {
     DbFunction.Build(functionName, arguments, builder, serviceProvider);
 }
Beispiel #23
0
 protected void Save(DbCommandBuilder commandBuilder, ObjectID id)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 public override void Build(DbCommandBuilder builder, IServiceProvider serviceProvider)
 {
     dbFragment.Build(builder, serviceProvider);
 }
Beispiel #25
0
 public override void Build(DbCommandBuilder builder, IServiceProvider serviceProvider)
 {
     new CastFunction(lhs, columnType).Build(builder, serviceProvider);
 }
 /// <summary>Initializes a new instance of the <see cref="Tortuga.Chain.Materializers.DataRowMaterializer{TCommand, TParameter}"/> class.</summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="rowOptions">The row options.</param>
 public DataRowOrNullMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, RowOptions rowOptions)
     : base(commandBuilder)
 {
     m_RowOptions = rowOptions;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionSetMaterializer{TCommand, TParameter, T1, T2}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 public CollectionSetMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder)
     : base(commandBuilder)
 {
 }
Beispiel #28
0
 /// <summary>
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="listOptions">The list options.</param>
 /// <param name="columnName">Name of the desired column.</param>
 public GuidListMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, string?columnName = null, ListOptions listOptions = ListOptions.None)
     : base(commandBuilder, columnName, listOptions)
 {
 }
 /// <summary>
 /// </summary>
 /// <param name="commandBuilder">The command builder.</param>
 /// <param name="columnName">Name of the desired column.</param>
 public Int16Materializer(DbCommandBuilder <TCommand, TParameter> commandBuilder, string columnName = null)
     : base(commandBuilder, columnName)
 {
 }
Beispiel #30
0
 //要在C#中使用引用参数 ,必须在函数声明以及函数调用中都明确地使用关键字ref
 public static void createDbConnection(DbName dbName, DbType dbType, ref IDbDataAdapter ada, ref DbCommandBuilder cb, string sql)
 {
     String connStr = getConnStr(dbName, dbType);
     Dictionary<string, string> ht = splitConnectionString(connStr);
     if (dbName == DbName.Oracle)
     {
         string cnStr = "password="******"password"] + ";data source=" + ht["data source"] + ";user id=" + ht["user id"];
         ada = new OracleDataAdapter(sql, cnStr);//构造查询(select)适配器
         cb = new OracleCommandBuilder((OracleDataAdapter)ada);//该对象在adapter执行update的时候,自动生成insert,update,delete语句。
     }
     else if (dbName == DbName.MSSql)
     {
         string cnStr = "Server=" + ht["data source"] + ";DataBase=" + ht["initial catalog"] + ";Uid=" + ht["user id"] + ";pwd=" + ht["password"];
         ada = new SqlDataAdapter(sql, cnStr);
         cb = new SqlCommandBuilder((SqlDataAdapter)ada);
     }
     else if (dbName == DbName.MySql)
     {
         string cnStr = "Database=" + ht["initial catalog"] + ";Data Source=" + ht["ip"] + ";User Id=" + ht["user id"] + ";Password="******"password"];
         ada = new MySqlDataAdapter(sql, cnStr);
         cb = new MySqlCommandBuilder((MySqlDataAdapter)ada);
     }
     else if (dbName == DbName.WinCE)
     {
         ada = new SqlCeDataAdapter(sql, connStr);
         cb = new SqlCeCommandBuilder((SqlCeDataAdapter)ada);
     }
 }
Beispiel #31
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="commandBuilder"></param>
 public PgSqlLanguage(DbCommandBuilder commandBuilder)
 {
     cb = commandBuilder;
 }
 protected override DbDataAdapter GetDataAdapter(string tableName, out DbCommandBuilder builder)
 {
     var adapter = new MySqlDataAdapter(string.Format(CultureInfo.InvariantCulture, "SELECT * FROM \"{0}\"", tableName), ConnectionString);
     builder = new MySqlCommandBuilder(adapter);
     return adapter;
 }
Beispiel #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnSelectingMaterializer{TCommand, TParameter, TResult}"/> class.
 /// </summary>
 /// <param name="commandBuilder">The associated operation.</param>
 protected ColumnSelectingMaterializer(DbCommandBuilder <TCommand, TParameter> commandBuilder) : base(commandBuilder)
 {
 }