当前位置: 首页>>代码示例>>C#>>正文


C# IDbConnection.ExecuteSql方法代码示例

本文整理汇总了C#中IDbConnection.ExecuteSql方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.ExecuteSql方法的具体用法?C# IDbConnection.ExecuteSql怎么用?C# IDbConnection.ExecuteSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDbConnection的用法示例。


在下文中一共展示了IDbConnection.ExecuteSql方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Drop

		public override void Drop(IDbConnection connection)
		{
			var sql = new Insight.Database.Schema.AutoProc(Name.Original, new SqlColumnDefinitionProvider(connection), null).DropSql;

			foreach (string s in _goSplit.Split(sql).Where(piece => !String.IsNullOrWhiteSpace(piece)))
				connection.ExecuteSql(s);
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:7,代码来源:AutoProc.cs

示例2: CreateSchemaIfNotExists

 /// <summary>Creates schema if not exists.</summary>
 /// <param name="db">The database.</param>
 private void CreateSchemaIfNotExists(IDbConnection db)
 {
     //in Sql2008, CREATE SCHEMA must be the first statement in a batch
     const string createSchemaSQL = @"IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Security')
                                 BEGIN
                                 EXEC( 'CREATE SCHEMA Security' );
                                 END";
     db.ExecuteSql(createSchemaSQL);
 }
开发者ID:sami1971,项目名称:NServiceKit.OrmLite,代码行数:11,代码来源:SchemaUseCase.cs

示例3: Install

		public override void Install(IDbConnection connection, IEnumerable<SchemaObject> objects)
		{
			// for auto-procs, convert the comment into a list of stored procedures
			var sql = new Insight.Database.Schema.AutoProc(Name.Original, new SqlColumnDefinitionProvider(connection), objects).Sql;
			if (sql.Length == 0)
				return;

			foreach (string s in _goSplit.Split(sql).Where(piece => !String.IsNullOrWhiteSpace(piece)))
				connection.ExecuteSql(s);
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:10,代码来源:AutoProc.cs

示例4: Install

		public virtual void Install(IDbConnection connection, IEnumerable<SchemaObject> objects)
		{
			try
			{
				foreach (string s in _goSplit.Split(Sql).Where(piece => !String.IsNullOrWhiteSpace(piece)))
					connection.ExecuteSql(s);
			}
			catch (Exception e)
			{
				throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot create SQL object {0}: {1}", Name.FullName, e.Message), e);
			}
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:12,代码来源:SchemaImpl.cs

示例5: Drop

		public override void Drop(IDbConnection connection)
		{
			connection.ExecuteSql(String.Format(@"
						-- ALTER TABLE DROP DEFAULT ON COLUMN
						DECLARE @Name[nvarchar](256) 
						SELECT @Name = d.name
							FROM sys.default_constraints d
							JOIN sys.schemas s ON (d.schema_id = s.schema_id)
							JOIN sys.objects o ON (d.parent_object_id = o.object_id)
							JOIN sys.columns c ON (c.object_id = o.object_id AND c.column_id = d.parent_column_id)
							WHERE s.name = '{0}' AND o.name = '{1}' AND c.name = '{2}'
						DECLARE @sql[nvarchar](MAX) = 'ALTER TABLE {3} DROP CONSTRAINT [' + @Name + ']'
						EXEC sp_executesql @sql
					",
				 Name.Schema,
				 Name.Table,
				 Name.Object,
				 Name.SchemaQualifiedTable));
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:19,代码来源:Default.cs

示例6: Drop

		public override void Drop(IDbConnection connection)
		{
			connection.ExecuteSql(String.Format(@"REVOKE {0}", Name.Original));
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:4,代码来源:Permission.cs

示例7: Drop

		public override void Drop(IDbConnection connection)
		{
			connection.ExecuteSql(String.Format(@"DROP BROKER PRIORITY {0}", Name.ObjectFormatted));
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:4,代码来源:BrokerPriority.cs

示例8: Drop

		public override void Drop(IDbConnection connection)
		{
			connection.ExecuteSql(String.Format(@"DROP INDEX {1} ON {0}",
				 Name.SchemaQualifiedTable,
				 Name.ObjectFormatted));
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:6,代码来源:Index.cs

示例9: Drop

		public override void Drop(IDbConnection connection)
		{
			connection.ExecuteSql(String.Format(@"DROP QUEUE {0}", Name.SchemaQualifiedObject));
		}
开发者ID:henkosch,项目名称:Insight.Database.Schema,代码行数:4,代码来源:Queue.cs

示例10: AdjustFileForSpringDst

        private void AdjustFileForSpringDst(AgdFile agdFile, IDbConnection db, DaylightTime daylightTime)
        {
            //see if there's any epochs before DST
            int epochsBeforeSpringDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks < daylightTime.Start.Ticks));
            bool dataBeforeSpringDst = epochsBeforeSpringDst > 0;

            int epochsAfterSpringDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks > daylightTime.Start.Ticks));

            bool dataAfterSpringDst = epochsAfterSpringDst > 0;

            if (!dataBeforeSpringDst && dataAfterSpringDst)
            {
                //no need to do anything
                richTextBox1.AppendText(string.Format("{0}: NOT adjusting file for spring DST\r\n", agdFile));
                return;
            }

            richTextBox1.AppendText(string.Format("{0}: adjusting file for spring DST\r\n", agdFile));

            //adjust timestamps for data after DST by subtracting an hour
            string sql =
                string.Format(
                    "UPDATE data SET dataTimestamp = dataTimestamp + {0} WHERE dataTimestamp >= {1}",
                    daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
            db.ExecuteSql(sql);

            //add the extra hour of data (October 25th 0200)
            var totalEpochsToInsert = daylightTime.Delta.TotalSeconds / agdFile.EpochLengthInSeconds;
            var ticksPerEpoch = TimeSpan.FromSeconds(agdFile.EpochLengthInSeconds).Ticks;
            for (int i = 0; i < totalEpochsToInsert; i++)
            {
                sql = string.Format("insert into data(dataTimestamp) values ({0});",
                    (daylightTime.Start.Ticks + (i * ticksPerEpoch)));
                db.ExecuteSql(sql);
            }

            var columnNames = db.GetColumnNames("data");
            foreach (var columnName in columnNames)
            {
                sql = string.Format("UPDATE data SET {0} = 0 WHERE {0} IS NULL", columnName);
                db.ExecuteSql(sql);
            }
            //adjust WTV
            if (db.TableExists("filters"))
            {
                sql =
                    string.Format(
                        "UPDATE filters SET filterStartTimestamp = filterStartTimestamp + {0} WHERE filterStartTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE filters SET filterStopTimestamp = filterStopTimestamp + {0} WHERE filterStopTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);
            }

            if (db.TableExists("wtvBouts"))
            {
                sql =
                    string.Format(
                        "UPDATE wtvBouts SET startTicks = startTicks + {0} WHERE startTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE wtvBouts SET stopTicks = stopTicks + {0} WHERE stopTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);
            }

            //adjust capsense
            if (db.TableExists("capsense"))
            {
                //adjust timestamps for data after DST by subtracting an hour
                sql = string.Format(
                        "UPDATE capsense SET timeStamp = timeStamp + {0} WHERE timeStamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.Start.Ticks);
                db.ExecuteSql(sql);
            }
        }
开发者ID:DanielWJudge,项目名称:AgdAdjustDaylightSavings,代码行数:91,代码来源:MainWindow.cs

示例11: AdjustFileForFallDst

        private void AdjustFileForFallDst(AgdFile agdFile, IDbConnection db, DaylightTime daylightTime)
        {
            //see if there's any epochs before DST
            int epochsBeforeFallDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks < daylightTime.End.Ticks));
            bool dataBeforeFallDst = epochsBeforeFallDst > 0;

            int epochsAfterFallDst =
                db.Scalar<int>(
                    db.From<AgdTableTimestampAxis1>()
                        .Select(Sql.Count("*"))
                        .Where(q => q.TimestampTicks > daylightTime.End.Ticks));
            bool dataAfterFallDst = epochsAfterFallDst > 0;

            if (dataBeforeFallDst && !dataAfterFallDst)
            {
                //there's only data before
                //no need to do anything
                richTextBox1.AppendText(string.Format("{0}: not adjusting file for fall DST\r\n", agdFile));
                return;
            }

            richTextBox1.AppendText(string.Format("{0}: adjusting file for fall DST\r\n", agdFile));

            //delete the extra hour of data (October 25th 0200)
            string sql = string.Format("DELETE FROM data WHERE dataTimestamp >= {0} AND dataTimeStamp < {1}",
                daylightTime.End.Ticks, daylightTime.End.Add(daylightTime.Delta).Ticks);
            db.ExecuteSql(sql);

            //adjust timestamps for data after DST by subtracting an hour
            sql =
                string.Format(
                    "UPDATE data SET dataTimestamp = dataTimestamp - {0} WHERE dataTimestamp >= {1}",
                    daylightTime.Delta.Ticks, daylightTime.End.Ticks);
            db.ExecuteSql(sql);

            //adjust WTV
            if (db.TableExists("filters"))
            {
                sql =
                    string.Format(
                        "UPDATE filters SET filterStartTimestamp = filterStartTimestamp - {0} WHERE filterStartTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE filters SET filterStopTimestamp = filterStopTimestamp - {0} WHERE filterStopTimestamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);
            }

            if (db.TableExists("wtvBouts"))
            {
                sql =
                    string.Format(
                        "UPDATE wtvBouts SET startTicks = startTicks - {0} WHERE startTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);

                sql =
                    string.Format(
                        "UPDATE wtvBouts SET stopTicks = stopTicks - {0} WHERE stopTicks >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);
            }

            //adjust capsense
            if (db.TableExists("capsense"))
            {
                //delete the extra hour of data (October 25th 0200)
                sql = string.Format("DELETE FROM capsense WHERE timeStamp  >= {0} AND timeStamp < {1}",
                    daylightTime.End.Ticks, daylightTime.End.Add(daylightTime.Delta).Ticks);
                db.ExecuteSql(sql);

                //adjust timestamps for data after DST by subtracting an hour
                sql =
                    string.Format(
                        "UPDATE capsense SET timeStamp = timeStamp - {0} WHERE timeStamp >= {1}",
                        daylightTime.Delta.Ticks, daylightTime.End.Ticks);
                db.ExecuteSql(sql);
            }
        }
开发者ID:DanielWJudge,项目名称:AgdAdjustDaylightSavings,代码行数:86,代码来源:MainWindow.cs


注:本文中的IDbConnection.ExecuteSql方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。