惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
Engineering at Meta
Engineering at Meta
Forbes - Security
Forbes - Security
MongoDB | Blog
MongoDB | Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
A
About on SuperTechFans
量子位
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
雷峰网
雷峰网
腾讯CDC
P
Proofpoint News Feed
S
Schneier on Security
S
Secure Thoughts
V
Visual Studio Blog
Help Net Security
Help Net Security
The Hacker News
The Hacker News
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Privacy International News Feed
SecWiki News
SecWiki News
S
SegmentFault 最新的问题
T
Threatpost
小众软件
小众软件
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
T
Tailwind CSS Blog
I
Intezer
C
CERT Recently Published Vulnerability Notes
U
Unit 42
V
V2EX
Cyberwarzone
Cyberwarzone
Recorded Future
Recorded Future
O
OpenAI News
Project Zero
Project Zero
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
Know Your Adversary
Know Your Adversary
C
Cybersecurity and Infrastructure Security Agency CISA
Scott Helme
Scott Helme
V2EX - 技术
V2EX - 技术
博客园 - 叶小钗
S
Securelist
A
Arctic Wolf
The Cloudflare Blog
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
博客园 - Franky

博客园 - y9902

修改系统分区后挂载的问题 - y9902 - 博客园 雅虎存在严重安全漏洞,可以轻松获得账户的控制权 I AM BACK 深入浅出 ck1.in/N.JS 新加了一个友情链接 雅虎书签存在严重安全漏洞,可以轻松获得账户的控制权 Deamhost 的当机页面 一个美丽,智慧,心善的明星:张瑶 Windows的蓝屏秀 c# 时间戳 推荐一个网站 vista 自带的IE7 的 User Agent 国外虚拟主机购买 卡巴斯基互联网安全套装V6.0个人版激活码 域名的巨大潜力 如何修复DNS? GzipStream 相关(操作steam绝对经典) pcc的文件格式面世了 Building XML File in C#
一个操作firebird的helper类
y9902 · 2006-09-10 · via 博客园 - y9902

参照了pet shop以及DAAB,

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using FirebirdSql.Data.FirebirdClient;

namespace ADOHelper
{
    
public class Firebird
    
{
        
private string connStrTemplate = "Server={0};User={1};Password={2};Charser={3};Database={4}";
        
private string connStr;

        
protected char ParameterToken
        
{
            
get return '@'; }
        }


        
//连接字符串
        public string ConnectString
        
{
            
set { connStr = value; }
        }


        
//构造函数
        public Firebird()
        
{

        }


        
//构造函数2
        public Firebird(string host, string user, string password, string charset, string database)
        
{
            connStr 
= String.Format(connStrTemplate, host, user, password, charset, database);
        }


        
/// <summary>
        
/// Open FbConnection
        
/// </summary>
        
/// <remarks>
        
/// e.g.:  
        
///  FbConnection conn = OpenConnection();
        
/// </remarks>
        
/// <returns>an FbConnection</returns>

        public FbConnection OpenConnection()
        
{
            FbConnection connection 
= null;
            
try
            
{
                
try
                
{
                    connection 
= new FbConnection(connStr);
                    connection.Open();
                }

                
catch (Exception e)
                
{
                    
throw e;
                }

            }

            
catch
            
{
                
if (connection != null)
                    connection.Close();
            }

            
return connection;
        }


        
/// <summary>
        
/// Execute a FbCommand (that returns no resultset) using an existing SQL Transaction 
        
/// using the provided parameters.
        
/// </summary>
        
/// <remarks>
        
/// e.g.:  
        
///  int result = ExecuteNonQuery( CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        
/// </remarks>
        
/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        
/// <param name="commandText">the stored procedure name or T-SQL command</param>
        
/// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        
/// <returns>an int representing the number of rows affected by the command</returns>

        public int ExecuteNonQuery(CommandType cmdType, string cmdText, params FbParameter[] commandParameters)
        
{
            FbCommand cmd 
= new FbCommand();
            
using (FbConnection conn = OpenConnection())
            
{

                PrepareCommand(cmd, conn, 
null, cmdType, cmdText, commandParameters);
                
int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                
return val;
            }

        }



        
/// <summary>
        
/// Execute a FbCommand (that returns no resultset) using an existing SQL Transaction 
        
/// using the provided parameters.
        
/// </summary>
        
/// <remarks>
        
/// e.g.:  
        
///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        
/// </remarks>
        
/// <param name="trans">an existing sql transaction</param>
        
/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        
/// <param name="commandText">the stored procedure name or T-SQL command</param>
        
/// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        
/// <returns>an int representing the number of rows affected by the command</returns>

        public int ExecuteNonQuery(FbTransaction trans, CommandType cmdType, string cmdText, params FbParameter[] commandParameters)
        
{
            FbCommand cmd 
= new FbCommand();
            
using (FbConnection conn = OpenConnection())
            
{

                PrepareCommand(cmd, conn, 
null, cmdType, cmdText, commandParameters);
                
int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                
return val;
            }

        }


        
/// <summary>
        
/// Execute a FbCommand that returns a resultset against the database specified in the connection string 
        
/// using the provided parameters.
        
/// </summary>
        
/// <remarks>
        
/// e.g.:  
        
///  SqlDataReader r = ExecuteReader( CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        
/// </remarks>
        
/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        
/// <param name="commandText">the stored procedure name or T-SQL command</param>
        
/// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        
/// <returns>A SqlDataReader containing the results</returns>

        public FbDataReader ExecuteReader(CommandType cmdType, string cmdText, params FbParameter[] commandParameters)
        
{
            FbCommand cmd 
= new FbCommand();
            FbConnection conn 
= OpenConnection();

            
// we use a try/catch here because if the method throws an exception we want to 
            
// close the connection throw code, because no datareader will exist, hence the 
            
// commandBehaviour.CloseConnection will not work
            try
            
{
                PrepareCommand(cmd, conn, 
null, cmdType, cmdText, commandParameters);
                FbDataReader rdr 
= cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                
return rdr;
            }

            
catch
            
{
                conn.Close();
                
throw;
            }

        }



        
/// <summary>
        
/// Execute a FbCommand that returns the first column of the first record against an existing database connection 
        
/// using the provided parameters.
        
/// </summary>
        
/// <remarks>
        
/// e.g.:  
        
///  Object obj = ExecuteScalar(CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        
/// </remarks>
        
/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        
/// <param name="commandText">the stored procedure name or T-SQL command</param>
        
/// <param name="commandParameters">an array of FbParameter used to execute the command</param>
        
/// <returns>An object that should be converted to the expected type using Convert.To{Type}</returns>

        public object ExecuteScalar(CommandType cmdType, string cmdText, params FbParameter[] commandParameters)
        
{
            FbCommand cmd 
= new FbCommand();
            
using (FbConnection conn = OpenConnection())
            
{
                PrepareCommand(cmd, conn, 
null, cmdType, cmdText, commandParameters);
                
object val = cmd.ExecuteScalar();
                cmd.Parameters.Clear();
                
return val;
            }

        }


        
/// <summary>
        
/// Return a DataSet
        
/// </summary>
        
/// <param name="cmd">FbCommand object</param>
        
/// <param name="conn">FbConnection object</param>
        
/// <param name="trans">FbTransaction object</param>
        
/// <param name="cmdType">Cmd type e.g. stored procedure or text</param>
        
/// <param name="cmdText">Command text, e.g. Select * from Products</param>
        
/// <param name="cmdParms">FbParameter to use in the command</param>

        public void DoLoadDataSet(DataSet dataSet, string[] tableNames, CommandType cmdType, string cmdText, params FbParameter[] commandParameters)
        
{
            
if (tableNames == nullthrow new ArgumentNullException("tableNames");
            
if (tableNames.Length == 0)
            
{
                
throw new ArgumentNullException("tableNames");
            }

            
for (int i = 0; i < tableNames.Length; i++)
            
{
                
if (string.IsNullOrEmpty(tableNames[i])) throw new ArgumentException(string.Concat("tableNames[", i, "]"));
            }


            
using (FbDataAdapter adapter = GetDataAdapter(UpdateBehavior.Standard))
            
{
                ((IDbDataAdapter)adapter).SelectCommand 
= command;

                
try
                
{
                    DateTime startTime 
= DateTime.Now;
                    
string systemCreatedTableNameRoot = "Table";
                    
for (int i = 0; i < tableNames.Length; i++)
                    
{
                        
string systemCreatedTableName = (i == 0)
                             
? systemCreatedTableNameRoot
                             : systemCreatedTableNameRoot 
+ i;

                        adapter.TableMappings.Add(systemCreatedTableName, tableNames[i]);
                    }


                    adapter.Fill(dataSet);
                    instrumentationProvider.FireCommandExecutedEvent(startTime);
                }

                
catch (Exception e)
                
{
                    instrumentationProvider.FireCommandFailedEvent(command.CommandText, ConnectionStringNoCredentials, e);
                    
throw;
                }

            }


        }


        
/// <summary>
        
/// Prepare a command for execution
        
/// </summary>
        
/// <param name="cmd">FbCommand object</param>
        
/// <param name="conn">FbConnection object</param>
        
/// <param name="trans">FbTransaction object</param>
        
/// <param name="cmdType">Cmd type e.g. stored procedure or text</param>
        
/// <param name="cmdText">Command text, e.g. Select * from Products</param>
        
/// <param name="cmdParms">FbParameter to use in the command</param>

        private void PrepareCommand(FbCommand cmd, FbConnection conn, FbTransaction trans, CommandType cmdType, string cmdText, FbParameter[] cmdParms)
        
{

            
if (conn.State != ConnectionState.Open)
                conn.Open();

            cmd.Connection 
= conn;
            cmd.CommandText 
= cmdText;

            
if (trans != null)
                cmd.Transaction 
= trans;

            cmd.CommandType 
= cmdType;

            
if (cmdParms != null)
            
{
                
foreach (FbParameter parm in cmdParms)
                    cmd.Parameters.Add(parm);
            }

        }






    }

}