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


C# FbConnection.CreateCommand方法代码示例

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


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

示例1: CreateDatabase

#pragma warning restore 649

		public override void CreateDatabase(string constr)
		{
			var csb = new FbConnectionStringBuilder(constr) { Pooling = false };

			FbConnection.CreateDatabase(csb.ConnectionString, 16384, false, true);

			using (var con = new FbConnection(csb.ConnectionString))
			using (var cmd = con.CreateCommand())
			{
				con.Open();

				#region bug drug block
				//cmd.CommandText = @"CREATE TABLE crdb (tid INTEGER, name CHAR(120));";
				//cmd.ExecuteScalar();
				//cmd.CommandText = @"DROP TABLE crdb;";
				//cmd.ExecuteScalar();
				#endregion

				#region init actions: register udf functions
				cmd.CommandText =
					@"
					DECLARE EXTERNAL FUNCTION strlen 
						CSTRING(32767)
						RETURNS INTEGER BY VALUE
						ENTRY_POINT 'IB_UDF_strlen' MODULE_NAME 'ib_udf';";
				cmd.ExecuteScalar();
				#endregion
			}
		}
开发者ID:permyakov,项目名称:janus,代码行数:31,代码来源:FBSchemaDriver.cs

示例2: QueryFb

        private List<object[]> QueryFb(string connectionstring, string query)
        {
            try
            {
                using (FbConnection dbConn = new FbConnection(connectionstring))
                {
                    Console.WriteLine("Consultando Control Escolar");

                    dbConn.Open();

                    using (var command = dbConn.CreateCommand())
                    {
                        command.CommandText = query;
                        using (var reader = command.ExecuteReader())
                        {
                            var rows = new List<object[]>();
                            while (reader.Read())
                            {
                                var columns = new object[reader.FieldCount];
                                reader.GetValues(columns);
                                rows.Add(columns);
                            }
                            return rows;
                        }
                    }
                }

            }catch(System.Exception oe)
            {
                throw new Exception(oe.Message);
            }
        }
开发者ID:univermilenium,项目名称:inscriptions,代码行数:32,代码来源:Extraction.cs

示例3: Main

        private static void Main(string[] args)
        {
            if (File.Exists("Data/database.fdb"))
            {
                File.Delete("Data/database.fdb");
            }

            FbConnection.CreateDatabase(GetConnectionString());

            using (var conn = new FbConnection(GetConnectionString()))
            {
                conn.Open();
                if (File.Exists("Data/database.sql"))
                {
                    var file = new FileInfo("Data/database.sql");
                    string script = file.OpenText().ReadToEnd();

                    using (FbCommand createTable = conn.CreateCommand())
                    {
                        createTable.CommandText = script;
                        createTable.ExecuteNonQuery();
                    }
                }
            }
        }
开发者ID:nate0001,项目名称:AIR,代码行数:25,代码来源:Program.cs

示例4: GetJson

        private string GetJson(string CommandText, string ParentNodeName, params FbParameter[] pars)
        {
            FbConnectionStringBuilder connString = TeeboaConnection.ConnectionString;
            using (FbConnection conn = new FbConnection(connString.ToString()))
            {
                using (FbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = CommandText;

                    for (int i = 0; i < pars.Length; i++)
                    {
                        cmd.Parameters.Add(pars[i]);
                    }
                    try
                    {
                        conn.Open();
                        using (FbDataReader dr = cmd.ExecuteReader())
                        {
                            return ParentNodeName == string.Empty ? stringify(dr) : stringify(dr, ParentNodeName);
                        }
                    }
                    catch (Exception ex)
                    {
                        return string.Format("Message: {1}{0}Method: {2}{0}", "<br />", ex.Message, ex.TargetSite);
                    }
                }
            }
        }
开发者ID:dotnetCarpenter,项目名称:teeboa,代码行数:29,代码来源:RoppongiMethods.cs

示例5: VerificaProprietario

        //1 - exclusivo 0 - compartilhado
        public static void VerificaProprietario(string nomeEntidade, FbConnection conn, ref bool empresa, ref bool filial)
        {
            ConfigurarDicionario();

            if(conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            using(FbCommand comando = conn.CreateCommand())
            {
                string nomeTabela = dicionario[nomeEntidade];

                comando.CommandText = "SELECT ACESSOEMPRESA, ACESSOFILIAL FROM SYS_TABLES WHERE ENTIDADE = @ENTIDADE";
                comando.Parameters.AddWithValue("@ENTIDADE", nomeTabela);

                using (FbDataReader leitor = comando.ExecuteReader())
                {
                    if (leitor.HasRows)
                    {
                        int indexEmpresa = leitor.GetOrdinal("ACESSOEMPRESA");
                        int indexFilial = leitor.GetOrdinal("ACESSOFILIAL");

                        while (leitor.Read())
                        {
                            empresa = Convert.ToBoolean(leitor.GetInt32(indexEmpresa));
                            filial = Convert.ToBoolean(leitor.GetInt32(indexFilial));
                        }   
                    }
                }
            }
        }
开发者ID:PablusVinii,项目名称:OrdemServico,代码行数:33,代码来源:ProprietarioEntidade.cs

示例6: GetColums

        public IEnumerable<ColumInfo> GetColums(FbConnection con)
        {
            using (var command = con.CreateCommand())
            {
                command.CommandText =
                    $"select trim(rf.rdb$field_name) Name, f.rdb$field_type Type, f.rdb$field_sub_type SubType , f.rdb$character_length CharSize, trim(rf.rdb$field_source) FieldSource, rf.rdb$null_flag NullFlag, f.rdb$field_precision FieldPrecision, f.rdb$field_scale FieldScale, f.rdb$field_length FieldLength " +
                        "from rdb$relation_fields rf " +
                        "join rdb$relations r on rf.rdb$relation_name = r.rdb$relation_name " +
                                            "and r.rdb$view_blr is not null " +
                                            "and r.rdb$relation_type = 1 and r.rdb$system_flag = 0 " +
                        "join rdb$fields f on f.rdb$field_name = rf.rdb$field_source " +
                     $"where rf.rdb$relation_name = '{this.ViewName}' " +
                      "order by rf.rdb$field_position; ";
                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    var size = (reader["CharSize"] == DBNull.Value) ? null : (short?)reader["CharSize"];
                    var subType = (reader["SubType"] == DBNull.Value) ? null : (short?)reader["SubType"];
                    var nullFlag = reader["NullFlag"] == DBNull.Value;
                    var precision = (reader["FieldPrecision"] == DBNull.Value) ? null : (short?)reader["FieldPrecision"];
                    var scale = (reader["FieldScale"] == DBNull.Value) ? null : (short?)reader["FieldScale"];
                    var fieldLength = (reader["FieldLength"] == DBNull.Value) ? null : (short?)reader["FieldLength"];
                    var type = new FieldType((short)reader["Type"], subType, size, precision, scale, fieldLength);

                    yield return new ColumInfo((string)reader["Name"], type, null, (string)reader["FieldSource"], nullFlag, true, "");
                }
            }
        }
开发者ID:degarashi0913,项目名称:FAManagementStudio,代码行数:28,代码来源:ViewInfo.cs

示例7: CreateTestTablesFb2

        private void CreateTestTablesFb2(string connectionString)
        {
            using (var con = new FbConnection(connectionString))
            using (var command = con.CreateCommand())
            {
                var sb = new StringBuilder();

                sb.Append("recreate table test(");
                sb.Append("int_test integer default 0 not null primary key,");
                sb.Append("bigint_test bigint,");
                sb.Append("blob_test blob,");
                sb.Append("char_test char(20),");
                sb.Append("date_test date,");
                sb.Append("decimal_test decimal,");
                sb.Append("double_test double precision,");
                sb.Append("float_test float,");
                sb.Append("numeric_test numeric,");
                sb.Append("smallint_test smallint,");
                sb.Append("time_test time,");
                sb.Append("timestamp_test timestamp,");
                sb.Append("varchar_test varchar(100)");
                sb.Append(")");

                command.CommandText = sb.ToString();
                con.Open();
                command.ExecuteNonQuery();
            }
        }
开发者ID:degarashi0913,项目名称:FAManagementStudio,代码行数:28,代码来源:ConnectionTestFb2.cs

示例8: GetDomain

 public IEnumerable<DomainInfo> GetDomain(FbConnection con)
 {
     using (var command = con.CreateCommand())
     {
         command.CommandText =
              $"select distinct f.rdb$field_type Type, f.rdb$field_sub_type SubType , f.rdb$character_length CharSize, trim(f.rdb$field_name) FieldName, f.rdb$field_precision FieldPrecision, f.rdb$field_scale FieldScale, f.rdb$field_length FieldLength, coalesce(f.rdb$validation_source, '') ValidationSource, coalesce(f.rdb$default_source, '') DefaultSource, f.rdb$null_flag NullFlag " +
               "from rdb$fields f " +
              $"where f.rdb$FIELD_NAME not starting with 'RDB$' and f.rdb$FIELD_NAME not starting with 'MON$' and f.rdb$FIELD_NAME not starting with 'SEC$' " +
               "order by f.rdb$field_name; ";
         var reader = command.ExecuteReader();
         while (reader.Read())
         {
             var name = (string)reader["FieldName"];
             var size = (reader["CharSize"] == DBNull.Value) ? null : (short?)reader["CharSize"];
             var subType = (reader["SubType"] == DBNull.Value) ? null : (short?)reader["SubType"];
             var precision = (reader["FieldPrecision"] == DBNull.Value) ? null : (short?)reader["FieldPrecision"];
             var scale = (reader["FieldScale"] == DBNull.Value) ? null : (short?)reader["FieldScale"];
             var fieldLength = (reader["FieldLength"] == DBNull.Value) ? null : (short?)reader["FieldLength"];
             var type = new FieldType((short)reader["Type"], subType, size, precision, scale, fieldLength);
             var validationSource = (string)reader["ValidationSource"];
             var defaultSource = (string)reader["DefaultSource"];
             var nullFlag = reader["NullFlag"] == DBNull.Value;
             yield return new DomainInfo(name, type, validationSource, defaultSource, nullFlag);
         }
     }
 }
开发者ID:degarashi0913,项目名称:FAManagementStudio,代码行数:26,代码来源:DatabaseInfo.cs

示例9: Main

        static void Main(string[] args)
        {
            var builder = new FbConnectionStringBuilder();
            builder.DataSource = "localhost";
            builder.Database = @"D:\DB\FB3_EXTERNAL_TEST.FDB";
            builder.Charset = FbCharset.Utf8.ToString();
            builder.UserID = "SYSDBA";
            builder.ServerType = FbServerType.Embedded;
            builder.ClientLibrary = @"fb\fbclient.dll";

            //DB作成
            if (!File.Exists(builder.Database))
            {
                FbConnection.CreateDatabase(builder.ConnectionString);
            }

            //create procesure
            var dllPath = new Uri(new Uri(Assembly.GetEntryAssembly().Location), @"../../Fb/plugins/FbExternalSample.dll").LocalPath;
            var createSqls = new FbHelper().GetCreateStatements(dllPath);
            using (var con = new FbConnection(builder.ConnectionString))
            using (var command = con.CreateCommand())
            {
                con.Open();
                foreach (var sql in createSqls)
                {
                    command.CommandText = sql;
                    command.ExecuteNonQuery();
                }
            }

            //実行
            var sqls = new[] { "SELECT * FROM HellowWorld('Taro')", "SELECT * FROM GetNumbers(5)", "SELECT * FROM GetDemo('やったぜ!')" };

            using (var con = new FbConnection(builder.ConnectionString))
            using (var command = con.CreateCommand())
            {
                con.Open();

                foreach (var sql in sqls)
                {
                    Console.WriteLine("- SQL -");
                    Console.WriteLine(sql);
                    Console.WriteLine("- 実行結果 -");
                    command.CommandText = sql;
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        var result = "";
                        for (var i = 0; i < reader.FieldCount; i++)
                        {
                            result += $" {reader[i]}";
                        }
                        Console.WriteLine(result);
                    }
                    Console.WriteLine("------------------------------------");
                }
            }

            Console.Read();
        }
开发者ID:kowill,项目名称:Sample,代码行数:60,代码来源:Program.cs

示例10: GetDefaultCharSet

 public string GetDefaultCharSet(FbConnection con)
 {
     using (var command = con.CreateCommand())
     {
         command.CommandText = @"select RDB$CHARACTER_SET_NAME CharSet from RDB$DATABASE";
         return command.ExecuteScalar() as string ?? "UTF8";
     }
 }
开发者ID:degarashi0913,项目名称:FAManagementStudio,代码行数:8,代码来源:DatabaseInfo.cs

示例11: GetIndex

 public IEnumerable<IndexInfo> GetIndex(FbConnection con)
 {
     using (var command = con.CreateCommand())
     {
         command.CommandText =
             "select trim(idx.rdb$index_name) Name, trim(seg.rdb$field_name) FiledName, rel.rdb$constraint_type ConstraintType, trim(rdb$foreign_key) ForeignKey, trim(ref.rdb$update_rule) UpdateRule, trim(ref.rdb$delete_rule) DeleteRule " +
             "from rdb$indices idx " +
             "left outer join rdb$index_segments seg on idx.rdb$index_name = seg.rdb$index_name " +
             "left outer join rdb$relation_constraints rel on idx.rdb$index_name = rel.rdb$index_name " +
             "left outer join rdb$ref_constraints ref on ref.rdb$constraint_name = rel.rdb$constraint_name " +
             $"where idx.rdb$relation_name = '{this.TableName}' and idx.rdb$system_flag = 0 order by seg.rdb$field_position";
         var reader = command.ExecuteReader();
         var tmpName = "";
         IndexInfo tmpInf = null;
         while (reader.Read())
         {
             if (tmpName == (string)reader["Name"])
             {
                 tmpInf.FieldNames.Add((string)reader["FiledName"]);
             }
             else
             {
                 if (tmpInf != null)
                 {
                     tmpName = "";
                     yield return tmpInf;
                 }
                 tmpInf = new IndexInfo();
                 tmpName = (string)reader["Name"];
                 tmpInf.Name = tmpName;
                 var constraintType = reader["ConstraintType"] == DBNull.Value ? "" : (string)(reader["ConstraintType"]);
                 tmpInf.Kind = GetConstraintType(constraintType);
                 tmpInf.TableName = this.TableName;
                 if (tmpInf.Kind == ConstraintsKind.Foreign)
                 {
                     tmpInf.ForigenKeyName = (string)reader["ForeignKey"];
                     tmpInf.UpdateRule = (string)reader["UpdateRule"] == "RESTRICT" ? "" : (string)reader["UpdateRule"];
                     tmpInf.DeleteRule = (string)reader["DeleteRule"] == "RESTRICT" ? "" : (string)reader["DeleteRule"];
                 }
                 tmpInf.FieldNames.Add((string)reader["FiledName"]);
             }
         }
         if (tmpInf != null)
         {
             yield return tmpInf;
         }
     }
 }
开发者ID:degarashi0913,项目名称:FAManagementStudio,代码行数:48,代码来源:TableInfo.cs

示例12: ListBlockchains

        public IEnumerable<Tuple<BlockchainKey, BlockchainMetadata>> ListBlockchains()
        {
            CheckDatabaseFolder();

            foreach (var file in Directory.EnumerateFiles(this.dbFolderPath, "Blockchain_*.fdb"))
            {
                var results = new List<Tuple<BlockchainKey, BlockchainMetadata>>();
                try
                {
                    var connString = @"ServerType=1; DataSource=localhost; Database={0}; Pooling=false; User=SYSDBA; Password=NA;".Format2(file);
                    using (var conn = new FbConnection(connString))
                    {
                        conn.Open();

                        using (var cmd = conn.CreateCommand())
                        {
                            cmd.CommandText = @"
                            SELECT Guid, RootBlockHash, TotalWork
                            FROM BlockchainMetadata
                            WHERE IsComplete = 1";

                            using (var reader = cmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    var guid = new Guid(reader.GetCharBytes(0));
                                    var rootBlockHash = reader.GetUInt256(1);
                                    var totalWork = reader.GetBigInteger(2);

                                    results.Add(Tuple.Create(new BlockchainKey(guid, rootBlockHash), new BlockchainMetadata(guid, rootBlockHash, totalWork)));
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error reading blockchain database: {0}: {1}".Format2(Path.GetFileName(file), e.Message));
                }

                foreach (var result in results)
                    yield return result;
            }
        }
开发者ID:holinov,项目名称:BitSharp,代码行数:44,代码来源:BlockchainStorage.cs

示例13: GetColums

        public IEnumerable<ColumInfo> GetColums(FbConnection con)
        {
            var constraints = GetConstrains(con);

            using (var command = con.CreateCommand())
            {
                command.CommandText =
                    $"select trim(rf.rdb$field_name) Name, f.rdb$field_type Type, f.rdb$field_sub_type SubType , f.rdb$character_length CharSize, trim(rf.rdb$field_source) FieldSource, rf.rdb$null_flag NullFlag, f.rdb$null_flag fieldNullFlag, f.rdb$field_precision FieldPrecision, f.rdb$field_scale FieldScale, f.rdb$field_length FieldLength, coalesce(rf.rdb$default_source, '') DefaultSource " +
                        "from rdb$relation_fields rf " +
                        "join rdb$relations r on rf.rdb$relation_name = r.rdb$relation_name " +
                                            "and r.rdb$view_blr is null " +
                                            $"and r.rdb$relation_type = 0 and r.rdb$system_flag = {SystemFlag} " +
                        "join rdb$fields f on f.rdb$field_name = rf.rdb$field_source " +
                    $"where rf.rdb$relation_name = '{this.TableName}' " +
                     "order by rf.rdb$field_position; ";
                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    var name = (string)reader["Name"];
                    var size = (reader["CharSize"] == DBNull.Value) ? null : (short?)reader["CharSize"];
                    var subType = (reader["SubType"] == DBNull.Value) ? null : (short?)reader["SubType"];
                    var nullFlag = reader["NullFlag"] == DBNull.Value;
                    var fieldNullFlag = reader["FieldNullFlag"] == DBNull.Value;
                    var precision = (reader["FieldPrecision"] == DBNull.Value) ? null : (short?)reader["FieldPrecision"];
                    var scale = (reader["FieldScale"] == DBNull.Value) ? null : (short?)reader["FieldScale"];
                    var fieldLength = (reader["FieldLength"] == DBNull.Value) ? null : (short?)reader["FieldLength"];
                    var type = new FieldType((short)reader["Type"], subType, size, precision, scale, fieldLength);
                    var defaultSource = (string)reader["DefaultSource"];

                    var constraintInfo = new ColumConstraintsInfo();
                    if (constraints.ContainsKey(name))
                    {
                        constraintInfo = constraints[name];
                    }

                    yield return new ColumInfo(name, type, constraintInfo, (string)reader["FieldSource"], nullFlag, fieldNullFlag, defaultSource);
                }
            }
        }
开发者ID:degarashi0913,项目名称:FAManagementStudio,代码行数:39,代码来源:TableInfo.cs

示例14: IsInDatabase

 protected static bool IsInDatabase(Action<FbCommand> adjustCommand)
 {
     var result = false;
     using (var connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString))
     {
         connection.Open();
         using (var tx = connection.BeginTransaction())
         {
             using (var cmd = connection.CreateCommand())
             {
                 cmd.Transaction = tx;
                 adjustCommand(cmd);
                 using (var reader = cmd.ExecuteReader())
                 {
                     result = reader.Read();
                 }
             }
             tx.Commit();
         }
         connection.Close();
     }
     return result;
 }
开发者ID:eloekset,项目名称:fluentmigrator,代码行数:23,代码来源:FbEndToEndFixture.cs

示例15: ForeignKeyExists

        private bool ForeignKeyExists(string connectionString, string withName)
        {
            using (var connection = new FbConnection(connectionString))
            {
                connection.Open();
                var keyQuery = String.Format(@"
SELECT rc.RDB$CONSTRAINT_NAME AS constraint_name,
i.RDB$RELATION_NAME AS table_name,
s.RDB$FIELD_NAME AS field_name,
i.RDB$DESCRIPTION AS description,
rc.RDB$DEFERRABLE AS is_deferrable,
rc.RDB$INITIALLY_DEFERRED AS is_deferred,
refc.RDB$UPDATE_RULE AS on_update,
refc.RDB$DELETE_RULE AS on_delete,
refc.RDB$MATCH_OPTION AS match_type,
i2.RDB$RELATION_NAME AS references_table,
s2.RDB$FIELD_NAME AS references_field,
(s.RDB$FIELD_POSITION + 1) AS field_position
FROM RDB$INDEX_SEGMENTS s
LEFT JOIN RDB$INDICES i ON i.RDB$INDEX_NAME = s.RDB$INDEX_NAME
LEFT JOIN RDB$RELATION_CONSTRAINTS rc ON rc.RDB$INDEX_NAME = s.RDB$INDEX_NAME
LEFT JOIN RDB$REF_CONSTRAINTS refc ON rc.RDB$CONSTRAINT_NAME = refc.RDB$CONSTRAINT_NAME
LEFT JOIN RDB$RELATION_CONSTRAINTS rc2 ON rc2.RDB$CONSTRAINT_NAME = refc.RDB$CONST_NAME_UQ
LEFT JOIN RDB$INDICES i2 ON i2.RDB$INDEX_NAME = rc2.RDB$INDEX_NAME
LEFT JOIN RDB$INDEX_SEGMENTS s2 ON i2.RDB$INDEX_NAME = s2.RDB$INDEX_NAME
WHERE rc.RDB$CONSTRAINT_TYPE = 'FOREIGN KEY'
ORDER BY s.RDB$FIELD_POSITION", MigrationWhichCreatesTwoRelatedTables.ForeignKeyName);
                var cmd = connection.CreateCommand();
                cmd.CommandText = keyQuery;
                var result = false;
                using (var rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        try
                        {
                            var constraintName = rdr["CONSTRAINT_NAME"];
                            if (constraintName == null) continue;
                            if (constraintName is DBNull) continue;
                            if (constraintName.ToString().Trim() == withName)
                            {
                                result = true;
                                break;
                            }
                        }
                        catch { }
                    }
                }
                connection.Close();
                FbConnection.ClearPool(connection);
                return result;
            }
        }
开发者ID:BhuvanB,项目名称:fluentmigrator,代码行数:53,代码来源:FirebirdEmbeddedTableTests.cs


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