當前位置: 首頁>>代碼示例>>C#>>正文


C# SqlBuilder.ToString方法代碼示例

本文整理匯總了C#中SqlBuilder.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# SqlBuilder.ToString方法的具體用法?C# SqlBuilder.ToString怎麽用?C# SqlBuilder.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SqlBuilder的用法示例。


在下文中一共展示了SqlBuilder.ToString方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Execute

        public override void Execute(IDatabase database)
        {
            if (!Table.Columns.Any())
            {
                throw new InvalidOperationException("Cannot create a table with no columns.");
            }

            var sql = new SqlBuilder();
            sql.Append("if not ({0}) begin create table {1} (",
                GetTableExistsSql(database, Table.Name),
                database.FormatTableNameAndEscape(Table.Name));

            var i = 0;
            foreach (var column in Table.Columns)
            {
                var sqlBuilder = new SqlBuilder()
                    .Append(i > 0, ",")
                    .Append(database.Escape(column.Name))
                    .Append(GetColumnSqlType(column, i.ToString()));

                sql.Append(sqlBuilder);
                i++;
            }

            sql.Append("); end;");

            database.RawExecute(sql.ToString());
        }
開發者ID:asgerhallas,項目名稱:HybridDb,代碼行數:28,代碼來源:CreateTable.cs

示例2: Execute

        public override void Execute(IDatabase database)
        {
            var sql = new SqlBuilder();
            sql.Append("alter table {0} add {1}", database.FormatTableNameAndEscape(Tablename), database.Escape(Column.Name));
            sql.Append(GetColumnSqlType(Column));

            database.RawExecute(sql.ToString());
        }
開發者ID:dcga,項目名稱:HybridDb,代碼行數:8,代碼來源:AddColumn.cs

示例3: DeleteRecord

        public string DeleteRecord(DatasetInfo table)
        {   
            var sql = new SqlBuilder(adapter);

            sql.Delete(new SchemaObject(table.Name), GetKeyFilter(table));

            return sql.ToString();
        }
開發者ID:carbon,項目名稱:Data,代碼行數:8,代碼來源:SqlGenerator.cs

示例4: InsertRecord

        public string InsertRecord(DatasetInfo table)
        {
            var sql = new SqlBuilder(adapter);

            var insertColumns = table.Members.Where(c => !c.IsGenerated);

            sql.InsertInto(new SchemaObject(table.Name), members: table.Members.Where(c => !c.IsGenerated));

            return sql.ToString();
        }
開發者ID:carbon,項目名稱:Data,代碼行數:10,代碼來源:SqlGenerator.cs

示例5: UpdateRecord

        public string UpdateRecord(DatasetInfo table)
        {
            var updateColumns = table.Members.Where(c => c.IsMutable || c.IsVersion).ToArray();

            var sql = new SqlBuilder(adapter);

            sql.Update(
                table     : new SchemaObject(table.Name), 
                columns   : updateColumns,
                condition : GetKeyFilter(table)
            );

            return sql.ToString();
        }
開發者ID:carbon,項目名稱:Data,代碼行數:14,代碼來源:SqlGenerator.cs

示例6: SqlEquals

 public static bool SqlEquals(SqlSet set, SqlBuilder query)
 {
     return String.Equals(Regex.Replace(set.ToString(), "dbex_set[0-9]+", "_"), query.ToString(), StringComparison.Ordinal);
 }
開發者ID:narmontas,項目名稱:DbExtensions,代碼行數:4,代碼來源:TestUtil.cs

示例7: QueryFirst

        public SqlQuery QueryFirst(DatasetInfo dataset, Expression expression)
        {
            var sql = new SqlBuilder(adapter)
                .Select(dataset.Members)
                .From(dataset.Name)
                .Where(expression)
                .Limit(1);

            return new SqlQuery(sql.ToString(), sql.Parameters);
        }
開發者ID:carbon,項目名稱:Data,代碼行數:10,代碼來源:SqlGenerator.cs

示例8: QueryRecords

        public SqlQuery QueryRecords(DatasetInfo dataset, Expression expression)
        {
            var builder = new SqlBuilder(adapter)
                .Select(dataset.Members)
                .From(dataset.Name)
                .Where(expression);

            return new SqlQuery(builder.ToString(), builder.Parameters);
        }
開發者ID:carbon,項目名稱:Data,代碼行數:9,代碼來源:SqlGenerator.cs

示例9: QueryVersions

        public SqlQuery QueryVersions(DatasetInfo baseTable, DatasetInfo versionedTable, Expression expression)
        {
            var sql = new SqlBuilder(adapter);

            var v = new SchemaObject(versionedTable.Name, "v");

            var a = new SchemaObject(baseTable.Name, "a");

            sql.Append("SELECT ");

            sql.WriteColumns(versionedTable.Members, prefix: "v"); // mutable values, primary keys, ...

            sql.Append(", ");

            sql.WriteColumns(baseTable.Members.Where(m => !m.IsVersion && !m.IsKey && !m.IsMutable), prefix: "a"); // immutable values from base table

            sql.From(v); // SELECT from v

            var keyName = baseTable.PrimaryKey[0].Name;

            // join the base (immutable) values with the versioned values
            sql.InnerJoin(
                baseTable       : v,        // versioned values
                joinedTable     : a,        // base values
                baseColumn      : keyName, 
                joinedColumn    : keyName
            );

            sql.Where(Expand(expression, baseTable)); 

            return new SqlQuery(sql.ToString(), sql.Parameters);
        }
開發者ID:carbon,項目名稱:Data,代碼行數:32,代碼來源:SqlGenerator.cs

示例10: Execute

        public override void Execute(IDatabase database)
        {
            var builder = new SqlBuilder();
            var formattedAndEscapedTableName = database.FormatTableNameAndEscape(TableName);
            var escapedColumnName = database.Escape(Column.Name);

            //DROP CONSTRAINTS
            foreach (var constraintName in (database is SqlServerUsingTempTables ? tempTablesConstraintQueries : constraintQueries)
                .Select(x => database.RawQuery<string>(x, new { TableName = database.FormatTableName(TableName), ColumnName = Column.Name }))
                .Select(x => x.SingleOrDefault())
                .Where(x => x != null))
            {
                builder.Append("ALTER TABLE {0} DROP CONSTRAINT {1};", formattedAndEscapedTableName, database.Escape(constraintName));
            }

            builder
                //ALTER TABLE
                .Append(GetAlterTableStatement(formattedAndEscapedTableName, escapedColumnName))

                //DEFAULT CONSTRAINT
                .Append(Column.DefaultValue != null, "ALTER TABLE {0} ADD DEFAULT '{1}' FOR {2};", formattedAndEscapedTableName, Column.DefaultValue, escapedColumnName)

                //PRIMAY KEY
                .Append(Column.IsPrimaryKey, @"ALTER TABLE {0} ADD PRIMARY KEY ({1});", formattedAndEscapedTableName, escapedColumnName);

            database.RawExecute(builder.ToString());
        }
開發者ID:asgerhallas,項目名稱:HybridDb,代碼行數:27,代碼來源:ChangeColumnType.cs

示例11: GetAlterTableStatement

        string GetAlterTableStatement(string formattedAndEscapedTableName, string escapedColumnName)
        {
            var builder = new SqlBuilder();
            var sqlColumn = SqlTypeMap.Convert(Column);

            builder
                .Append("ALTER TABLE {0} ALTER COLUMN {1}", formattedAndEscapedTableName, escapedColumnName)
                .Append(new SqlParameter {DbType = sqlColumn.DbType}.SqlDbType.ToString())
                .Append(sqlColumn.Length != null, "(" + sqlColumn.Length + ")")
                .Append(Column.Nullable, "NULL").Or("NOT NULL")
                .Append(";");

            return builder.ToString();
        }
開發者ID:asgerhallas,項目名稱:HybridDb,代碼行數:14,代碼來源:ChangeColumnType.cs

示例12: Execute

 public sealed override void Execute(IDatabase database)
 {
     var sql = new SqlBuilder();
     builder(sql, database);
     database.RawExecute(sql.ToString());
 }
開發者ID:dcga,項目名稱:HybridDb,代碼行數:6,代碼來源:SqlMigrationCommand.cs


注:本文中的SqlBuilder.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。